[pango/visible-things: 13/35] Add a utility function for ignorables



commit 61b1faff10ce14c969ca8cb1c0ca8a8edeb69d32
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jul 7 13:55:41 2019 -0400

    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.

 pango/pango-impl-utils.h | 69 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
---
diff --git a/pango/pango-impl-utils.h b/pango/pango-impl-utils.h
index 9570da80..fc82165b 100644
--- a/pango/pango-impl-utils.h
+++ b/pango/pango-impl-utils.h
@@ -128,6 +128,75 @@ 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 */
+  { 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
 


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]