summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-07-07 13:55:41 -0400
committerMatthias Clasen <mclasen@redhat.com>2019-07-12 18:23:03 -0400
commit42d661839c2effdfb40c8021b899167479009fa5 (patch)
tree6396be533e05f3785331cbb600061fe3151659ed
parent66797ab77a48414f7f719bd37da4f3565670ce34 (diff)
downloadpango-42d661839c2effdfb40c8021b899167479009fa5.tar.gz
Add a utility function for ignorables
This returns nicknames and formatting information for default ignorable characters. This will be used to render customized hex boxes for these characters.
-rw-r--r--pango/pango-impl-utils.h70
1 files changed, 70 insertions, 0 deletions
diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h
index 9570da80..378f14a1 100644
--- a/pango/pango-impl-utils.h
+++ b/pango/pango-impl-utils.h
@@ -128,6 +128,76 @@ pango_glyph_string_reverse_range (PangoGlyphString *glyphs,
}
}
+/* The cairo hexbox drawing code assumes
+ * that these nicks are 1-6 ASCII chars
+ */
+static struct {
+ gunichar ch;
+ const char *nick;
+} ignorables[] = {
+ { 0x00ad, "SHY" }, /* SOFT HYPHEN */
+ { 0x034f, "CGJ" }, /* COMBINING GRAPHEME JOINER */
+ { 0x200b, "ZWS" }, /* ZERO WIDTH SPACE */
+ { 0x200c, "ZWNJ" }, /* ZERO WIDTH NON-JOINER */
+ { 0x200d, "ZWJ" }, /* ZERO WIDTH JOINER */
+ { 0x200e, "LRM" }, /* LEFT-TO-RIGHT MARK */
+ { 0x200f, "RLM" }, /* RIGHT-TO-LEFT MARK */
+ { 0x2028, "LS" }, /* LINE SEPARATOR */
+ { 0x2029, "PS" }, /* PARAGRAPH SEPARATOR */
+ { 0x202a, "LRE" }, /* LEFT-TO-RIGHT EMBEDDING */
+ { 0x202b, "RLE" }, /* RIGHT-TO-LEFT EMBEDDING */
+ { 0x202c, "PDF" }, /* POP DIRECTIONAL FORMATTING */
+ { 0x202d, "LRO" }, /* LEFT-TO-RIGHT OVERRIDE */
+ { 0x202e, "RLO" }, /* RIGHT-TO-LEFT OVERRIDE */
+ { 0x2060, "WJ" }, /* WORD JOINER */
+ { 0x2061, "FA" }, /* FUNCTION APPLICATION */
+ { 0x2062, "IT" }, /* INVISIBLE TIMES */
+ { 0x2063, "IS" }, /* INVISIBLE SEPARATOR */
+ { 0xfeff, "ZWNBS" }, /* ZERO WIDTH NO-BREAK SPACE */
+};
+
+static inline G_GNUC_UNUSED const char *
+pango_get_ignorable (gunichar ch)
+{
+ for (int i = 0; i < G_N_ELEMENTS (ignorables); i++)
+ {
+ if (ch == ignorables[i].ch)
+ return ignorables[i].nick;
+ }
+ return NULL;
+}
+
+static inline G_GNUC_UNUSED const char *
+pango_get_ignorable_size (gunichar ch,
+ int *rows,
+ int *cols)
+{
+ const char *nick;
+ int len;
+
+ nick = pango_get_ignorable (ch);
+ if (nick)
+ {
+ len = strlen (nick);
+ if (len < 4)
+ {
+ *rows = 1;
+ *cols = len;
+ }
+ else if (len > 4)
+ {
+ *rows = 2;
+ *cols = 3;
+ }
+ else
+ {
+ *rows = 2;
+ *cols = 2;
+ }
+ }
+
+ return nick;
+}
G_END_DECLS