[HarfBuzz] harfbuzz-ng: Branch 'master' - 6 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Apr 16 15:08:48 PDT 2012


 src/hb-ot-shape.cc                                                                     |    2 
 src/hb-private.hh                                                                      |    8 +
 test/shaping/texts/in-tree/shaper-default/MANIFEST                                     |    1 
 test/shaping/texts/in-tree/shaper-default/script-japanese/MANIFEST                     |    1 
 test/shaping/texts/in-tree/shaper-default/script-japanese/misc/MANIFEST                |    2 
 test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga-lines.txt |    8 +
 test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga.txt       |   53 ++++++++++
 util/hb-shape.cc                                                                       |    8 -
 util/hb-view.hh                                                                        |    2 
 util/helper-cairo.cc                                                                   |   22 +++-
 util/helper-cairo.hh                                                                   |    3 
 util/options.cc                                                                        |   19 ++-
 util/options.hh                                                                        |   26 +++-
 util/view-cairo.cc                                                                     |   15 +-
 util/view-cairo.hh                                                                     |    3 
 15 files changed, 139 insertions(+), 34 deletions(-)

New commits:
commit 95cefdf96efe43a44133aa8a186155cf4e63e2b7
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Apr 16 18:08:20 2012 -0400

    Add --utf8-clusters
    
    Also fix cairo cluster generation.

diff --git a/util/hb-shape.cc b/util/hb-shape.cc
index a76a778..b22bc1f 100644
--- a/util/hb-shape.cc
+++ b/util/hb-shape.cc
@@ -36,7 +36,8 @@ struct output_buffer_t : output_options_t, format_options_t
   void init (const font_options_t *font_opts);
   void consume_line (hb_buffer_t  *buffer,
 		     const char   *text,
-		     unsigned int  text_len);
+		     unsigned int  text_len,
+		     hb_bool_t     utf8_clusters);
   void finish (const font_options_t *font_opts);
 
   protected:
@@ -57,11 +58,12 @@ output_buffer_t::init (const font_options_t *font_opts)
 void
 output_buffer_t::consume_line (hb_buffer_t  *buffer,
 			       const char   *text,
-			       unsigned int  text_len)
+			       unsigned int  text_len,
+			       hb_bool_t     utf8_clusters)
 {
   line_no++;
   g_string_set_size (gs, 0);
-  serialize_line (buffer, line_no, text, text_len, font, gs);
+  serialize_line (buffer, line_no, text, text_len, font, utf8_clusters, gs);
   fprintf (fp, "%s", gs->str);
 }
 
diff --git a/util/hb-view.hh b/util/hb-view.hh
index 68a5dd8..66d955b 100644
--- a/util/hb-view.hh
+++ b/util/hb-view.hh
@@ -65,7 +65,7 @@ struct hb_view_t
 			 buffer))
 	fail (FALSE, "All shapers failed");
 
-      output.consume_line (buffer, text, text_len);
+      output.consume_line (buffer, text, text_len, shaper.utf8_clusters);
     }
     hb_buffer_destroy (buffer);
 
diff --git a/util/helper-cairo.cc b/util/helper-cairo.cc
index abb8c15..9374d9e 100644
--- a/util/helper-cairo.cc
+++ b/util/helper-cairo.cc
@@ -301,7 +301,8 @@ helper_cairo_line_from_buffer (helper_cairo_line_t *l,
 			       hb_buffer_t         *buffer,
 			       const char          *text,
 			       unsigned int         text_len,
-			       double               scale)
+			       double               scale,
+			       hb_bool_t            utf8_clusters)
 {
   memset (l, 0, sizeof (*l));
 
@@ -349,27 +350,38 @@ helper_cairo_line_from_buffer (helper_cairo_line_t *l,
     hb_bool_t backward = HB_DIRECTION_IS_BACKWARD (hb_buffer_get_direction (buffer));
     l->cluster_flags = backward ? CAIRO_TEXT_CLUSTER_FLAG_BACKWARD : (cairo_text_cluster_flags_t) 0;
     unsigned int cluster = 0;
+    const char *start = l->utf8, *end = start;
     l->clusters[cluster].num_glyphs++;
     if (backward) {
       for (i = l->num_glyphs - 2; i >= 0; i--) {
 	if (hb_glyph[i].cluster != hb_glyph[i+1].cluster) {
 	  g_assert (hb_glyph[i].cluster > hb_glyph[i+1].cluster);
-	  l->clusters[cluster].num_bytes += hb_glyph[i].cluster - hb_glyph[i+1].cluster;
+	  if (utf8_clusters)
+	    end = start + hb_glyph[i].cluster - hb_glyph[i+1].cluster;
+	  else
+	    end = g_utf8_offset_to_pointer (start, hb_glyph[i].cluster - hb_glyph[i+1].cluster);
+	  l->clusters[cluster].num_bytes = end - start;
+	  start = end;
 	  cluster++;
 	}
 	l->clusters[cluster].num_glyphs++;
       }
-      l->clusters[cluster].num_bytes += text_len - hb_glyph[0].cluster;
+      l->clusters[cluster].num_bytes = l->utf8 + text_len - start;
     } else {
       for (i = 1; i < (int) l->num_glyphs; i++) {
 	if (hb_glyph[i].cluster != hb_glyph[i-1].cluster) {
 	  g_assert (hb_glyph[i].cluster > hb_glyph[i-1].cluster);
-	  l->clusters[cluster].num_bytes += hb_glyph[i].cluster - hb_glyph[i-1].cluster;
+	  if (utf8_clusters)
+	    end = start + hb_glyph[i].cluster - hb_glyph[i-1].cluster;
+	  else
+	    end = g_utf8_offset_to_pointer (start, hb_glyph[i].cluster - hb_glyph[i-1].cluster);
+	  l->clusters[cluster].num_bytes = end - start;
+	  start = end;
 	  cluster++;
 	}
 	l->clusters[cluster].num_glyphs++;
       }
-      l->clusters[cluster].num_bytes += text_len - hb_glyph[i - 1].cluster;
+      l->clusters[cluster].num_bytes = l->utf8 + text_len - start;
     }
   }
 }
diff --git a/util/helper-cairo.hh b/util/helper-cairo.hh
index bc3fe1d..2f2c9d4 100644
--- a/util/helper-cairo.hh
+++ b/util/helper-cairo.hh
@@ -75,6 +75,7 @@ helper_cairo_line_from_buffer (helper_cairo_line_t *l,
 			       hb_buffer_t         *buffer,
 			       const char          *text,
 			       unsigned int         text_len,
-			       double               scale);
+			       double               scale,
+			       hb_bool_t            utf8_clusters);
 
 #endif
diff --git a/util/options.cc b/util/options.cc
index e5e76c9..e24a026 100644
--- a/util/options.cc
+++ b/util/options.cc
@@ -391,6 +391,7 @@ shape_options_t::add_options (option_parser_t *parser)
     {"direction",	0, 0, G_OPTION_ARG_STRING,	&this->direction,		"Set text direction (default: auto)",	"ltr/rtl/ttb/btt"},
     {"language",	0, 0, G_OPTION_ARG_STRING,	&this->language,		"Set text language (default: $LANG)",	"langstr"},
     {"script",		0, 0, G_OPTION_ARG_STRING,	&this->script,			"Set text script (default: auto)",	"ISO-15924 tag"},
+    {"utf8-clusters",	0, 0, G_OPTION_ARG_NONE,	&this->utf8_clusters,		"Use UTF-8 byte indices, not char indices",	NULL},
     {NULL}
   };
   parser->add_group (entries,
@@ -404,9 +405,12 @@ shape_options_t::add_options (option_parser_t *parser)
     "    Comma-separated list of font features to apply to text\n"
     "\n"
     "    Features can be enabled or disabled, either globally or limited to\n"
-    "    specific character ranges.  The range indices refer to the positions\n"
-    "    between Unicode characters.  The position before the first character\n"
-    "    is 0, and the position after the first character is 1, and so on.\n"
+    "    specific character ranges.\n"
+    "\n"
+    "    The range indices refer to the positions between Unicode characters,\n"
+    "    unless the --utf8-clusters is provided, in which case range indices\n"
+    "    refer to UTF-8 byte indices. The position before the first character\n"
+    "    is always 0.\n"
     "\n"
     "    The format is Python-esque.  Here is how it all works:\n"
     "\n"
@@ -716,6 +720,7 @@ format_options_t::serialize_unicode (hb_buffer_t *buffer,
 void
 format_options_t::serialize_glyphs (hb_buffer_t *buffer,
 				    hb_font_t   *font,
+				    hb_bool_t    utf8_clusters,
 				    GString     *gs)
 {
   FT_Face ft_face = show_glyph_names ? hb_ft_font_get_face (font) : NULL;
@@ -739,8 +744,11 @@ format_options_t::serialize_glyphs (hb_buffer_t *buffer,
     } else
       g_string_append_printf (gs, "%u", info->codepoint);
 
-    if (show_clusters)
+    if (show_clusters) {
       g_string_append_printf (gs, "=%u", info->cluster);
+      if (utf8_clusters)
+	g_string_append (gs, "u8");
+    }
 
     if (show_positions && (pos->x_offset || pos->y_offset)) {
       g_string_append_c (gs, '@');
@@ -771,6 +779,7 @@ format_options_t::serialize_line (hb_buffer_t  *buffer,
 				  const char   *text,
 				  unsigned int  text_len,
 				  hb_font_t    *font,
+				  hb_bool_t     utf8_clusters,
 				  GString      *gs)
 {
   if (show_text) {
@@ -790,6 +799,6 @@ format_options_t::serialize_line (hb_buffer_t  *buffer,
   }
 
   serialize_line_no (line_no, gs);
-  serialize_glyphs (buffer, font, gs);
+  serialize_glyphs (buffer, font, utf8_clusters, gs);
   g_string_append_c (gs, '\n');
 }
diff --git a/util/options.hh b/util/options.hh
index da95017..15d9402 100644
--- a/util/options.hh
+++ b/util/options.hh
@@ -140,6 +140,7 @@ struct shape_options_t : option_group_t
     features = NULL;
     num_features = 0;
     shapers = NULL;
+    utf8_clusters = false;
 
     add_options (parser);
   }
@@ -161,15 +162,16 @@ struct shape_options_t : option_group_t
     hb_buffer_reset (buffer);
     hb_buffer_add_utf8 (buffer, text, text_len, 0, text_len);
 
-    /* Reset cluster values to refer to Unicode character index
-     * instead of UTF-8 index.
-     * TODO: Add an option for this. */
-    unsigned int num_glyphs = hb_buffer_get_length (buffer);
-    hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL);
-    for (unsigned int i = 0; i < num_glyphs; i++)
-    {
-      info->cluster = i;
-      info++;
+    if (!utf8_clusters) {
+      /* Reset cluster values to refer to Unicode character index
+       * instead of UTF-8 index. */
+      unsigned int num_glyphs = hb_buffer_get_length (buffer);
+      hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, NULL);
+      for (unsigned int i = 0; i < num_glyphs; i++)
+      {
+	info->cluster = i;
+	info++;
+      }
     }
 
     setup_buffer (buffer);
@@ -182,6 +184,7 @@ struct shape_options_t : option_group_t
   hb_feature_t *features;
   unsigned int num_features;
   char **shapers;
+  hb_bool_t utf8_clusters;
 };
 
 
@@ -285,7 +288,8 @@ struct output_options_t : option_group_t
   virtual void init (const font_options_t *font_opts) = 0;
   virtual void consume_line (hb_buffer_t  *buffer,
 			     const char   *text,
-			     unsigned int  text_len) = 0;
+			     unsigned int  text_len,
+			     hb_bool_t     utf8_clusters) = 0;
   virtual void finish (const font_options_t *font_opts) = 0;
 
   const char *output_file;
@@ -319,6 +323,7 @@ struct format_options_t : option_group_t
 			  GString      *gs);
   void serialize_glyphs (hb_buffer_t  *buffer,
 			 hb_font_t    *font,
+			 hb_bool_t    utf8_clusters,
 			 GString      *gs);
   void serialize_line_no (unsigned int  line_no,
 			  GString      *gs);
@@ -327,6 +332,7 @@ struct format_options_t : option_group_t
 		       const char   *text,
 		       unsigned int  text_len,
 		       hb_font_t    *font,
+		       hb_bool_t     utf8_clusters,
 		       GString      *gs);
 
 
diff --git a/util/view-cairo.cc b/util/view-cairo.cc
index a03c555..5d8ead7 100644
--- a/util/view-cairo.cc
+++ b/util/view-cairo.cc
@@ -36,11 +36,12 @@ view_cairo_t::init (const font_options_t *font_opts)
 void
 view_cairo_t::consume_line (hb_buffer_t  *buffer,
 			    const char   *text,
-			    unsigned int  text_len)
+			    unsigned int  text_len,
+			    hb_bool_t     utf8_clusters)
 {
   direction = hb_buffer_get_direction (buffer);
   helper_cairo_line_t l;
-  helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale);
+  helper_cairo_line_from_buffer (&l, buffer, text, text_len, scale, utf8_clusters);
   g_array_append_val (lines, l);
 }
 
diff --git a/util/view-cairo.hh b/util/view-cairo.hh
index 0f4fe94..eec90ea 100644
--- a/util/view-cairo.hh
+++ b/util/view-cairo.hh
@@ -43,7 +43,8 @@ struct view_cairo_t : output_options_t, view_options_t {
   void init (const font_options_t *font_opts);
   void consume_line (hb_buffer_t  *buffer,
 		     const char   *text,
-		     unsigned int  text_len);
+		     unsigned int  text_len,
+		     hb_bool_t     utf8_clusters);
   void finish (const font_options_t *font_opts);
 
   protected:
commit effb42e5c520128bdc2e29398ed801730c5c0f52
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Apr 16 16:04:07 2012 -0400

    Always use cairo_show_text_glyphs()
    
    Better catches cluster errors.

diff --git a/util/view-cairo.cc b/util/view-cairo.cc
index 6b5b3f1..a03c555 100644
--- a/util/view-cairo.cc
+++ b/util/view-cairo.cc
@@ -138,7 +138,7 @@ view_cairo_t::draw (cairo_t *cr)
       cairo_restore (cr);
     }
 
-    if (cairo_surface_get_type (cairo_get_target (cr)) == CAIRO_SURFACE_TYPE_IMAGE) {
+    if (0 && cairo_surface_get_type (cairo_get_target (cr)) == CAIRO_SURFACE_TYPE_IMAGE) {
       /* cairo_show_glyphs() doesn't support subpixel positioning */
       cairo_glyph_path (cr, l.glyphs, l.num_glyphs);
       cairo_fill (cr);
commit 799cfdd15ab369580b2283200c3aca6866214b59
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Apr 16 16:00:36 2012 -0400

    Make page progression be right to left for vertical text

diff --git a/util/view-cairo.cc b/util/view-cairo.cc
index ce578ed..6b5b3f1 100644
--- a/util/view-cairo.cc
+++ b/util/view-cairo.cc
@@ -109,18 +109,18 @@ view_cairo_t::draw (cairo_t *cr)
   cairo_translate (cr, margin.l, margin.t);
   double descent;
   if (vertical)
-    descent = font_extents.height * .5;
+    descent = font_extents.height * (lines->len + .5);
   else
     descent = font_extents.height - font_extents.ascent;
-  cairo_translate (cr, v * -descent, h * -descent);
+  cairo_translate (cr, v * descent, h * -descent);
   for (unsigned int i = 0; i < lines->len; i++)
   {
     helper_cairo_line_t &l = g_array_index (lines, helper_cairo_line_t, i);
 
     if (i)
-      cairo_translate (cr, v * line_space, h * line_space);
+      cairo_translate (cr, v * -line_space, h * line_space);
 
-    cairo_translate (cr, v * font_extents.height, h * font_extents.height);
+    cairo_translate (cr, v * -font_extents.height, h * font_extents.height);
 
     if (annotate) {
       cairo_save (cr);
commit a5f1834f57ea3fb254f5c7d372747de316fcc8f1
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Apr 16 15:55:13 2012 -0400

    Apply 'liga' for vertical writing mode too
    
    Apparently that's what Kazuraki uses to form vertical ligatures,
    which suggests that it's what Adobe does.

diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index d21559c..66b1461 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -35,6 +35,7 @@
 
 hb_tag_t common_features[] = {
   HB_TAG('c','c','m','p'),
+  HB_TAG('l','i','g','a'),
   HB_TAG('l','o','c','l'),
   HB_TAG('m','a','r','k'),
   HB_TAG('m','k','m','k'),
@@ -46,7 +47,6 @@ hb_tag_t horizontal_features[] = {
   HB_TAG('c','l','i','g'),
   HB_TAG('c','u','r','s'),
   HB_TAG('k','e','r','n'),
-  HB_TAG('l','i','g','a'),
 };
 
 /* Note:
commit 4d85252bda25cddd1fbdd744687e449888f0b5fa
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Apr 16 15:54:26 2012 -0400

    Add Japanese test data from Adobe's Kazuraki font ligatures

diff --git a/test/shaping/texts/in-tree/shaper-default/MANIFEST b/test/shaping/texts/in-tree/shaper-default/MANIFEST
index 5139532..0e08c0b 100644
--- a/test/shaping/texts/in-tree/shaper-default/MANIFEST
+++ b/test/shaping/texts/in-tree/shaper-default/MANIFEST
@@ -1,2 +1,3 @@
 script-hebrew
+script-japanese
 script-linear-b
diff --git a/test/shaping/texts/in-tree/shaper-default/script-japanese/MANIFEST b/test/shaping/texts/in-tree/shaper-default/script-japanese/MANIFEST
new file mode 100644
index 0000000..b8752e7
--- /dev/null
+++ b/test/shaping/texts/in-tree/shaper-default/script-japanese/MANIFEST
@@ -0,0 +1 @@
+misc
diff --git a/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/MANIFEST b/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/MANIFEST
new file mode 100644
index 0000000..4d2d52c
--- /dev/null
+++ b/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/MANIFEST
@@ -0,0 +1,2 @@
+kazuraki-liga-lines.txt
+kazuraki-liga.txt
diff --git a/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga-lines.txt b/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga-lines.txt
new file mode 100644
index 0000000..5bc2d00
--- /dev/null
+++ b/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga-lines.txt
@@ -0,0 +1,8 @@
+ありあるあれいているべきいろうれし
+うれしくかしこかとがとうくもこと
+こともことをこのこれこれもされ
+しかししてするせんたしたのちる
+とけとしとしてとのともかくとを
+なくなどなどのなるひさひとふるほど
+ますむとめてもしろものをやるゆる
+られるとるものれる〳〵〴〵
diff --git a/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga.txt b/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga.txt
new file mode 100644
index 0000000..e043e17
--- /dev/null
+++ b/test/shaping/texts/in-tree/shaper-default/script-japanese/misc/kazuraki-liga.txt
@@ -0,0 +1,53 @@
+あり
+ある
+あれ
+いて
+いるべき
+いろ
+うれし
+うれしく
+かしこ
+かと
+がとう
+くも
+こと
+ことも
+ことを
+この
+これ
+これも
+され
+しかし
+して
+する
+せん
+たし
+たの
+ちる
+とけ
+とし
+として
+との
+ともかく
+とを
+なく
+など
+などの
+なる
+ひさ
+ひと
+ふる
+ほど
+ます
+むと
+めて
+もしろ
+ものを
+ã‚„ã‚‹
+ゆる
+られ
+ると
+るもの
+れる
+〳〵
+〴〵
commit e74616b8898b5f18d9bf82b9e81aefad056c1e36
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Sun Apr 15 14:12:13 2012 -0400

    Add comment

diff --git a/src/hb-private.hh b/src/hb-private.hh
index f561260..64cb3c8 100644
--- a/src/hb-private.hh
+++ b/src/hb-private.hh
@@ -440,6 +440,14 @@ static inline uint16_t hb_be_uint16 (const uint16_t v)
   return (uint16_t) (V[0] << 8) + V[1];
 }
 
+/* Note, of the following macros, uint16_get is the one called many many times.
+ * If there is any optimizations to be done, it's in that macro.  However, I
+ * already confirmed that on my T400 ThinkPad at least, using bswap_16(), which
+ * results in a single ror instruction, does NOT speed this up.  In fact, it
+ * resulted in a minor slowdown.  At any rate, note that v may not be correctly
+ * aligned, so I think the current implementation is optimal.
+ */
+
 #define hb_be_uint16_put(v,V)	HB_STMT_START { v[0] = (V>>8); v[1] = (V); } HB_STMT_END
 #define hb_be_uint16_get(v)	(uint16_t) ((v[0] << 8) + v[1])
 #define hb_be_uint16_eq(a,b)	(a[0] == b[0] && a[1] == b[1])



More information about the HarfBuzz mailing list