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

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed May 25 08:38:58 PDT 2011


 TODO                             |   14 ++-
 src/hb-font.cc                   |  107 ++++++++----------------
 src/hb-font.h                    |   50 +++++------
 src/hb-ft.cc                     |   26 ++----
 src/hb-ot-layout-gpos-private.hh |  167 ++++++++++++++++++++++-----------------
 src/hb-ot-shape.cc               |    9 +-
 test/test-font.c                 |   73 ++++++-----------
 test/test-shape.c                |   40 ++++-----
 8 files changed, 229 insertions(+), 257 deletions(-)

New commits:
commit 2d8ebcb9d089c2cfbefac71ca6350e2703ab13e3
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 25 11:27:33 2011 -0400

    [API] One last font-funcs API change
    
    Now that vertical text works correctly, I'm doing a last round
    modification of the font-funcs API to simplify.  Expect no more
    changes around here.

diff --git a/src/hb-font.cc b/src/hb-font.cc
index ae2910c..27ec005 100644
--- a/src/hb-font.cc
+++ b/src/hb-font.cc
@@ -56,40 +56,28 @@ hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
   return FALSE;
 }
 
-static void
+static hb_position_t
 hb_font_get_glyph_h_advance_nil (hb_font_t *font HB_UNUSED,
 				 void *font_data HB_UNUSED,
 				 hb_codepoint_t glyph,
-				 hb_position_t *advance,
 				 void *user_data HB_UNUSED)
 {
-  if (font->parent) {
-    hb_font_get_glyph_h_advance (font->parent,
-				 glyph,
-				 advance);
-    *advance = font->parent_scale_x_distance (*advance);
-    return;
-  }
+  if (font->parent)
+    return font->parent_scale_x_distance (hb_font_get_glyph_h_advance (font->parent, glyph));
 
-  *advance = font->x_scale;
+  return font->x_scale;
 }
 
-static void
+static hb_position_t
 hb_font_get_glyph_v_advance_nil (hb_font_t *font HB_UNUSED,
 				 void *font_data HB_UNUSED,
 				 hb_codepoint_t glyph,
-				 hb_position_t *advance,
 				 void *user_data HB_UNUSED)
 {
-  if (font->parent) {
-    hb_font_get_glyph_v_advance (font->parent,
-				 glyph,
-				 advance);
-    *advance = font->parent_scale_y_distance (*advance);
-    return;
-  }
+  if (font->parent)
+    return font->parent_scale_y_distance (hb_font_get_glyph_v_advance (font->parent, glyph));
 
-  *advance = font->y_scale;
+  return font->y_scale;
 }
 
 static hb_bool_t
@@ -134,42 +122,30 @@ hb_font_get_glyph_v_origin_nil (hb_font_t *font HB_UNUSED,
   return FALSE;
 }
 
-static void
+static hb_position_t
 hb_font_get_glyph_h_kerning_nil (hb_font_t *font HB_UNUSED,
 				 void *font_data HB_UNUSED,
 				 hb_codepoint_t left_glyph,
 				 hb_codepoint_t right_glyph,
-				 hb_position_t *kerning,
 				 void *user_data HB_UNUSED)
 {
-  if (font->parent) {
-    hb_font_get_glyph_h_kerning (font->parent,
-				 left_glyph, right_glyph,
-				 kerning);
-    *kerning = font->parent_scale_x_distance (*kerning);
-    return;
-  }
+  if (font->parent)
+    return font->parent_scale_x_distance (hb_font_get_glyph_h_kerning (font->parent, left_glyph, right_glyph));
 
-  *kerning = 0;
+  return 0;
 }
 
-static void
+static hb_position_t
 hb_font_get_glyph_v_kerning_nil (hb_font_t *font HB_UNUSED,
 				 void *font_data HB_UNUSED,
 				 hb_codepoint_t top_glyph,
 				 hb_codepoint_t bottom_glyph,
-				 hb_position_t *kerning,
 				 void *user_data HB_UNUSED)
 {
-  if (font->parent) {
-    hb_font_get_glyph_v_kerning (font->parent,
-				 top_glyph, bottom_glyph,
-				 kerning);
-    *kerning = font->parent_scale_y_distance (*kerning);
-    return;
-  }
+  if (font->parent)
+    return font->parent_scale_y_distance (hb_font_get_glyph_v_kerning (font->parent, top_glyph, bottom_glyph));
 
-  *kerning = 0;
+  return 0;
 }
 
 static hb_bool_t
@@ -340,26 +316,22 @@ hb_font_get_glyph (hb_font_t *font,
 				 font->klass->user_data.glyph);
 }
 
-void
+hb_position_t
 hb_font_get_glyph_h_advance (hb_font_t *font,
-			     hb_codepoint_t glyph,
-			     hb_position_t *advance)
+			     hb_codepoint_t glyph)
 {
-  *advance = 0;
-  font->klass->get.glyph_h_advance (font, font->user_data,
-				    glyph, advance,
-				    font->klass->user_data.glyph_h_advance);
+  return font->klass->get.glyph_h_advance (font, font->user_data,
+					   glyph,
+					   font->klass->user_data.glyph_h_advance);
 }
 
-void
+hb_position_t
 hb_font_get_glyph_v_advance (hb_font_t *font,
-			     hb_codepoint_t glyph,
-			     hb_position_t *advance)
+			     hb_codepoint_t glyph)
 {
-  *advance = 0;
-  font->klass->get.glyph_v_advance (font, font->user_data,
-				    glyph, advance,
-				    font->klass->user_data.glyph_v_advance);
+  return font->klass->get.glyph_v_advance (font, font->user_data,
+					   glyph,
+					   font->klass->user_data.glyph_v_advance);
 }
 
 hb_bool_t
@@ -384,27 +356,21 @@ hb_font_get_glyph_v_origin (hb_font_t *font,
 					   font->klass->user_data.glyph_v_origin);
 }
 
-void
+hb_position_t
 hb_font_get_glyph_h_kerning (hb_font_t *font,
-			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
-			     hb_position_t *kerning)
+			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
 {
-  *kerning = 0;
   return font->klass->get.glyph_h_kerning (font, font->user_data,
 					   left_glyph, right_glyph,
-					   kerning,
 					   font->klass->user_data.glyph_h_kerning);
 }
 
-void
+hb_position_t
 hb_font_get_glyph_v_kerning (hb_font_t *font,
-			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
-			     hb_position_t *kerning)
+			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph)
 {
-  *kerning = 0;
   return font->klass->get.glyph_v_kerning (font, font->user_data,
 				     left_glyph, right_glyph,
-				     kerning,
 				     font->klass->user_data.glyph_v_kerning);
 }
 
@@ -442,11 +408,11 @@ hb_font_get_glyph_advance_for_direction (hb_font_t *font,
 					 hb_position_t *x, hb_position_t *y)
 {
   if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) {
+    *x = hb_font_get_glyph_h_advance (font, glyph);
     *y = 0;
-    hb_font_get_glyph_h_advance (font, glyph, x);
   } else {
     *x = 0;
-    hb_font_get_glyph_v_advance (font, glyph, y);
+    *y = hb_font_get_glyph_v_advance (font, glyph);
   }
 }
 
@@ -455,10 +421,7 @@ guess_v_origin_minus_h_origin (hb_font_t *font,
 			       hb_codepoint_t glyph,
 			       hb_position_t *x, hb_position_t *y)
 {
-  *x = *y = 0;
-
-  hb_font_get_glyph_h_advance (font, glyph, x);
-  *x /= 2;
+  *x = hb_font_get_glyph_h_advance (font, glyph) / 2;
 
   /* TODO use font_metics.ascent */
   *y = font->y_scale;
@@ -523,11 +486,11 @@ hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
 					 hb_position_t *x, hb_position_t *y)
 {
   if (likely (HB_DIRECTION_IS_HORIZONTAL (direction))) {
+    *x = hb_font_get_glyph_h_kerning (font, first_glyph, second_glyph);
     *y = 0;
-     hb_font_get_glyph_h_kerning (font, first_glyph, second_glyph, x);
   } else {
     *x = 0;
-     hb_font_get_glyph_v_kerning (font, first_glyph, second_glyph, y);
+    *y = hb_font_get_glyph_v_kerning (font, first_glyph, second_glyph);
   }
 }
 
diff --git a/src/hb-font.h b/src/hb-font.h
index 22384ac..37d36b4 100644
--- a/src/hb-font.h
+++ b/src/hb-font.h
@@ -142,10 +142,9 @@ typedef hb_bool_t (*hb_font_get_glyph_func_t) (hb_font_t *font, void *font_data,
 					       void *user_data);
 
 
-typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
-						  hb_codepoint_t glyph,
-						  hb_position_t *advance,
-						  void *user_data);
+typedef hb_position_t (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, void *font_data,
+							   hb_codepoint_t glyph,
+							   void *user_data);
 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_h_advance_func_t;
 typedef hb_font_get_glyph_advance_func_t hb_font_get_glyph_v_advance_func_t;
 
@@ -156,10 +155,9 @@ typedef hb_bool_t (*hb_font_get_glyph_origin_func_t) (hb_font_t *font, void *fon
 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_h_origin_func_t;
 typedef hb_font_get_glyph_origin_func_t hb_font_get_glyph_v_origin_func_t;
 
-typedef void (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data,
-						  hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
-						  hb_position_t *kerning,
-						  void *user_data);
+typedef hb_position_t (*hb_font_get_glyph_kerning_func_t) (hb_font_t *font, void *font_data,
+							   hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+							   void *user_data);
 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_h_kerning_func_t;
 typedef hb_font_get_glyph_kerning_func_t hb_font_get_glyph_v_kerning_func_t;
 
@@ -183,38 +181,38 @@ hb_font_funcs_set_glyph_func (hb_font_funcs_t *ffuncs,
 
 void
 hb_font_funcs_set_glyph_h_advance_func (hb_font_funcs_t *ffuncs,
-					hb_font_get_glyph_h_advance_func_t glyph_advance_func,
+					hb_font_get_glyph_h_advance_func_t func,
 					void *user_data, hb_destroy_func_t destroy);
 void
 hb_font_funcs_set_glyph_v_advance_func (hb_font_funcs_t *ffuncs,
-					hb_font_get_glyph_v_advance_func_t glyph_advance_func,
+					hb_font_get_glyph_v_advance_func_t func,
 					void *user_data, hb_destroy_func_t destroy);
 
 void
 hb_font_funcs_set_glyph_h_origin_func (hb_font_funcs_t *ffuncs,
-				       hb_font_get_glyph_h_origin_func_t glyph_advance_func,
+				       hb_font_get_glyph_h_origin_func_t func,
 				       void *user_data, hb_destroy_func_t destroy);
 void
 hb_font_funcs_set_glyph_v_origin_func (hb_font_funcs_t *ffuncs,
-				       hb_font_get_glyph_v_origin_func_t glyph_advance_func,
+				       hb_font_get_glyph_v_origin_func_t func,
 				       void *user_data, hb_destroy_func_t destroy);
 
 void
 hb_font_funcs_set_glyph_h_kerning_func (hb_font_funcs_t *ffuncs,
-					hb_font_get_glyph_h_kerning_func_t kerning_func,
+					hb_font_get_glyph_h_kerning_func_t func,
 					void *user_data, hb_destroy_func_t destroy);
 void
 hb_font_funcs_set_glyph_v_kerning_func (hb_font_funcs_t *ffuncs,
-					hb_font_get_glyph_v_kerning_func_t kerning_func,
+					hb_font_get_glyph_v_kerning_func_t func,
 					void *user_data, hb_destroy_func_t destroy);
 
 void
 hb_font_funcs_set_glyph_extents_func (hb_font_funcs_t *ffuncs,
-				      hb_font_get_glyph_extents_func_t glyph_extents_func,
+				      hb_font_get_glyph_extents_func_t func,
 				      void *user_data, hb_destroy_func_t destroy);
 void
 hb_font_funcs_set_glyph_contour_point_func (hb_font_funcs_t *ffuncs,
-					    hb_font_get_glyph_contour_point_func_t glyph_contour_point_func,
+					    hb_font_get_glyph_contour_point_func_t func,
 					    void *user_data, hb_destroy_func_t destroy);
 
 
@@ -225,14 +223,12 @@ hb_font_get_glyph (hb_font_t *font,
 		   hb_codepoint_t unicode, hb_codepoint_t variation_selector,
 		   hb_codepoint_t *glyph);
 
-void
+hb_position_t
 hb_font_get_glyph_h_advance (hb_font_t *font,
-			     hb_codepoint_t glyph,
-			     hb_position_t *advance);
-void
+			     hb_codepoint_t glyph);
+hb_position_t
 hb_font_get_glyph_v_advance (hb_font_t *font,
-			     hb_codepoint_t glyph,
-			     hb_position_t *advance);
+			     hb_codepoint_t glyph);
 
 hb_bool_t
 hb_font_get_glyph_h_origin (hb_font_t *font,
@@ -243,14 +239,12 @@ hb_font_get_glyph_v_origin (hb_font_t *font,
 			    hb_codepoint_t glyph,
 			    hb_position_t *x, hb_position_t *y);
 
-void
+hb_position_t
 hb_font_get_glyph_h_kerning (hb_font_t *font,
-			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph,
-			     hb_position_t *kerning);
-void
+			     hb_codepoint_t left_glyph, hb_codepoint_t right_glyph);
+hb_position_t
 hb_font_get_glyph_v_kerning (hb_font_t *font,
-			     hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph,
-			     hb_position_t *kerning);
+			     hb_codepoint_t top_glyph, hb_codepoint_t bottom_glyph);
 
 hb_bool_t
 hb_font_get_glyph_extents (hb_font_t *font,
diff --git a/src/hb-ft.cc b/src/hb-ft.cc
index feaf9aa..4a180ee 100644
--- a/src/hb-ft.cc
+++ b/src/hb-ft.cc
@@ -78,38 +78,36 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
   return *glyph != 0;
 }
 
-static void
+static hb_position_t
 hb_ft_get_glyph_h_advance (hb_font_t *font HB_UNUSED,
 			   void *font_data,
 			   hb_codepoint_t glyph,
-			   hb_position_t *advance,
 			   void *user_data HB_UNUSED)
 {
   FT_Face ft_face = (FT_Face) font_data;
   int load_flags = FT_LOAD_DEFAULT;
 
   if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
-    return;
+    return 0;
 
-  *advance = ft_face->glyph->metrics.horiAdvance;
+  return ft_face->glyph->metrics.horiAdvance;
 }
 
-static void
+static hb_position_t
 hb_ft_get_glyph_v_advance (hb_font_t *font HB_UNUSED,
 			   void *font_data,
 			   hb_codepoint_t glyph,
-			   hb_position_t *advance,
 			   void *user_data HB_UNUSED)
 {
   FT_Face ft_face = (FT_Face) font_data;
   int load_flags = FT_LOAD_DEFAULT;
 
   if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
-    return;
+    return 0;
 
   /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
    * have a Y growing upward.  Hence the extra negation. */
-  *advance = -ft_face->glyph->metrics.vertAdvance;
+  return -ft_face->glyph->metrics.vertAdvance;
 }
 
 static hb_bool_t
@@ -146,33 +144,31 @@ hb_ft_get_glyph_v_origin (hb_font_t *font HB_UNUSED,
   return TRUE;
 }
 
-static void
+static hb_position_t
 hb_ft_get_glyph_h_kerning (hb_font_t *font HB_UNUSED,
 			   void *font_data,
 			   hb_codepoint_t left_glyph,
 			   hb_codepoint_t right_glyph,
-			   hb_position_t *kerning,
 			   void *user_data HB_UNUSED)
 {
   FT_Face ft_face = (FT_Face) font_data;
   FT_Vector kerningv;
 
   if (FT_Get_Kerning (ft_face, left_glyph, right_glyph, FT_KERNING_DEFAULT, &kerningv))
-    return;
+    return 0;
 
-  *kerning = kerningv.x;
+  return kerningv.x;
 }
 
-static void
+static hb_position_t
 hb_ft_get_glyph_v_kerning (hb_font_t *font HB_UNUSED,
 			   void *font_data HB_UNUSED,
 			   hb_codepoint_t top_glyph HB_UNUSED,
 			   hb_codepoint_t bottom_glyph HB_UNUSED,
-			   hb_position_t *kerning HB_UNUSED,
 			   void *user_data HB_UNUSED)
 {
   /* FreeType API doesn't support vertical kerning */
-  return;
+  return 0;
 }
 
 static hb_bool_t
diff --git a/test/test-font.c b/test/test-font.c
index 2bf5224..40540c4 100644
--- a/test/test-font.c
+++ b/test/test-font.c
@@ -121,8 +121,7 @@ _test_font_nil_funcs (hb_font_t *font)
   g_assert_cmpint (x, ==, 0);
   g_assert_cmpint (y, ==, 0);
 
-  x = 13;
-  hb_font_get_glyph_h_advance (font, 17, &x);
+  x = hb_font_get_glyph_h_advance (font, 17);
   g_assert_cmpint (x, ==, 0);
 
   extents.x_bearing = extents.y_bearing = 13;
@@ -138,7 +137,7 @@ _test_font_nil_funcs (hb_font_t *font)
   g_assert_cmpint (glyph, ==, 0);
 
   x = 13;
-  hb_font_get_glyph_h_kerning (font, 17, 19, &x);
+  x = hb_font_get_glyph_h_kerning (font, 17, 19);
   g_assert_cmpint (x, ==, 0);
 }
 
@@ -236,15 +235,15 @@ contour_point_func2 (hb_font_t *font, void *font_data,
 					  glyph, point_index, x, y);
 }
 
-static void
+static hb_position_t
 glyph_h_advance_func1 (hb_font_t *font, void *font_data,
 		       hb_codepoint_t glyph,
-		       hb_position_t *advance,
 		       void *user_data)
 {
-  if (glyph == 1) {
-    *advance = 8;
-  }
+  if (glyph == 1)
+    return 8;
+
+  return 0;
 }
 
 static void
@@ -287,9 +286,9 @@ test_fontfuncs_subclassing (void)
   g_assert (!hb_font_get_glyph_contour_point_for_origin (font1, 3, 7, HB_DIRECTION_RTL, &x, &y));
   g_assert_cmpint (x, ==, 0);
   g_assert_cmpint (y, ==, 0);
-  hb_font_get_glyph_h_advance (font1, 1, &x);
+  x = hb_font_get_glyph_h_advance (font1, 1);
   g_assert_cmpint (x, ==, 8);
-  hb_font_get_glyph_h_advance (font1, 2, &x);
+  x = hb_font_get_glyph_h_advance (font1, 2);
   g_assert_cmpint (x, ==, 0);
 
 
@@ -313,9 +312,9 @@ test_fontfuncs_subclassing (void)
   g_assert (!hb_font_get_glyph_contour_point_for_origin (font2, 3, 7, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 0);
   g_assert_cmpint (y, ==, 0);
-  hb_font_get_glyph_h_advance (font2, 1, &x);
+  x = hb_font_get_glyph_h_advance (font2, 1);
   g_assert_cmpint (x, ==, 8);
-  hb_font_get_glyph_h_advance (font2, 2, &x);
+  x = hb_font_get_glyph_h_advance (font2, 2);
   g_assert_cmpint (x, ==, 0);
 
 
@@ -336,9 +335,9 @@ test_fontfuncs_subclassing (void)
   g_assert (!hb_font_get_glyph_contour_point_for_origin (font3, 3, 7, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 0*2);
   g_assert_cmpint (y, ==, 0*3);
-  hb_font_get_glyph_h_advance (font3, 1, &x);
+  x = hb_font_get_glyph_h_advance (font3, 1);
   g_assert_cmpint (x, ==, 8*2);
-  hb_font_get_glyph_h_advance (font3, 2, &x);
+  x = hb_font_get_glyph_h_advance (font3, 2);
   g_assert_cmpint (x, ==, 0*2);
 
 
diff --git a/test/test-shape.c b/test/test-shape.c
index 64594b2..c8017bf 100644
--- a/test/test-shape.c
+++ b/test/test-shape.c
@@ -37,17 +37,17 @@
 
 static const char test_data[] = "test\0data";
 
-static void
+static hb_position_t
 glyph_h_advance_func (hb_font_t *font, void *font_data,
 		      hb_codepoint_t glyph,
-		      hb_position_t *advance,
 		      void *user_data)
 {
   switch (glyph) {
-  case 1: *advance = 10; return;
-  case 2: *advance =  6; return;
-  case 3: *advance =  5; return;
+  case 1: return 10;
+  case 2: return 6;
+  case 3: return 5;
   }
+  return 0;
 }
 
 static hb_bool_t
@@ -61,19 +61,18 @@ glyph_func (hb_font_t *font, void *font_data,
   case 'e': *glyph = 2; return TRUE;
   case 's': *glyph = 3; return TRUE;
   }
-
   return FALSE;
 }
 
-static void
+static hb_position_t
 glyph_h_kerning_func (hb_font_t *font, void *font_data,
 		      hb_codepoint_t left, hb_codepoint_t right,
-		      hb_position_t *kerning,
 		      void *user_data)
 {
-  if (left == 1 && right == 2) {
-    *kerning = -2;
-  }
+  if (left == 1 && right == 2)
+    return -2;
+
+  return 0;
 }
 
 static const char TesT[] = "TesT";
commit d31691296f7d3051fcd345bf1325d17835484b50
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 25 11:01:32 2011 -0400

    [test] Update to API changes

diff --git a/test/test-font.c b/test/test-font.c
index 0e81b0e..2bf5224 100644
--- a/test/test-font.c
+++ b/test/test-font.c
@@ -117,18 +117,17 @@ _test_font_nil_funcs (hb_font_t *font)
   hb_glyph_extents_t extents;
 
   x = y = 13;
-  g_assert (!hb_font_get_contour_point (font, 17, 2, HB_DIRECTION_LTR, &x, &y));
+  g_assert (!hb_font_get_glyph_contour_point (font, 17, 2, &x, &y));
   g_assert_cmpint (x, ==, 0);
   g_assert_cmpint (y, ==, 0);
 
-  x = y = 13;
-  hb_font_get_glyph_h_advance (font, 17, &x, &y);
+  x = 13;
+  hb_font_get_glyph_h_advance (font, 17, &x);
   g_assert_cmpint (x, ==, 0);
-  g_assert_cmpint (y, ==, 0);
 
   extents.x_bearing = extents.y_bearing = 13;
   extents.width = extents.height = 15;
-  hb_font_get_glyph_extents (font, 17, HB_DIRECTION_LTR, &extents);
+  hb_font_get_glyph_extents (font, 17, &extents);
   g_assert_cmpint (extents.x_bearing, ==, 0);
   g_assert_cmpint (extents.y_bearing, ==, 0);
   g_assert_cmpint (extents.width, ==, 0);
@@ -138,10 +137,9 @@ _test_font_nil_funcs (hb_font_t *font)
   g_assert (!hb_font_get_glyph (font, 17, 2, &glyph));
   g_assert_cmpint (glyph, ==, 0);
 
-  x = y = 13;
-  hb_font_get_h_kerning (font, 17, 19, &x, &y);
+  x = 13;
+  hb_font_get_glyph_h_kerning (font, 17, 19, &x);
   g_assert_cmpint (x, ==, 0);
-  g_assert_cmpint (y, ==, 0);
 }
 
 static void
@@ -205,12 +203,9 @@ test_fontfuncs_nil (void)
 static hb_bool_t
 contour_point_func1 (hb_font_t *font, void *font_data,
 		     hb_codepoint_t glyph, unsigned int point_index,
-		     hb_bool_t *vertical,
 		     hb_position_t *x, hb_position_t *y,
 		     void *user_data)
 {
-  *vertical = FALSE;
-
   if (glyph == 1) {
     *x = 2;
     *y = 3;
@@ -228,7 +223,6 @@ contour_point_func1 (hb_font_t *font, void *font_data,
 static hb_bool_t
 contour_point_func2 (hb_font_t *font, void *font_data,
 		     hb_codepoint_t glyph, unsigned int point_index,
-		     hb_bool_t *vertical,
 		     hb_position_t *x, hb_position_t *y,
 		     void *user_data)
 {
@@ -238,23 +232,19 @@ contour_point_func2 (hb_font_t *font, void *font_data,
     return TRUE;
   }
 
-  return hb_font_get_contour_point (hb_font_get_parent (font),
-				    glyph, point_index, vertical, x, y);
+  return hb_font_get_glyph_contour_point (hb_font_get_parent (font),
+					  glyph, point_index, x, y);
 }
 
-static hb_bool_t
+static void
 glyph_h_advance_func1 (hb_font_t *font, void *font_data,
 		       hb_codepoint_t glyph,
-		       hb_position_t *x_advance, hb_position_t *y_advance,
+		       hb_position_t *advance,
 		       void *user_data)
 {
   if (glyph == 1) {
-    *x_advance = 8;
-    *y_advance = 9;
-    return TRUE;
+    *advance = 8;
   }
-
-  return FALSE;
 }
 
 static void
@@ -282,27 +272,25 @@ test_fontfuncs_subclassing (void)
 
   /* setup font1 */
   ffuncs1 = hb_font_funcs_create ();
-  hb_font_funcs_set_contour_point_func (ffuncs1, contour_point_func1, NULL, NULL);
+  hb_font_funcs_set_glyph_contour_point_func (ffuncs1, contour_point_func1, NULL, NULL);
   hb_font_funcs_set_glyph_h_advance_func (ffuncs1, glyph_h_advance_func1, NULL, NULL);
   hb_font_set_funcs (font1, ffuncs1, NULL, NULL);
   hb_font_funcs_destroy (ffuncs1);
 
   x = y = 1;
-  g_assert (hb_font_get_contour_point_for_direction (font1, 1, 2, HB_DIRECTION_LTR, &x, &y));
+  g_assert (hb_font_get_glyph_contour_point_for_origin (font1, 1, 2, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 2);
   g_assert_cmpint (y, ==, 3);
-  g_assert (hb_font_get_contour_point_for_direction (font1, 2, 5, HB_DIRECTION_LTR, &x, &y));
+  g_assert (hb_font_get_glyph_contour_point_for_origin (font1, 2, 5, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 4);
   g_assert_cmpint (y, ==, 5);
-  g_assert (!hb_font_get_contour_point_for_direction (font1, 3, 7, HB_DIRECTION_RTL, &x, &y));
+  g_assert (!hb_font_get_glyph_contour_point_for_origin (font1, 3, 7, HB_DIRECTION_RTL, &x, &y));
   g_assert_cmpint (x, ==, 0);
   g_assert_cmpint (y, ==, 0);
-  hb_font_get_glyph_h_advance (font1, 1, &x, &y);
+  hb_font_get_glyph_h_advance (font1, 1, &x);
   g_assert_cmpint (x, ==, 8);
-  g_assert_cmpint (y, ==, 9);
-  hb_font_get_glyph_h_advance (font1, 2, &x, &y);
+  hb_font_get_glyph_h_advance (font1, 2, &x);
   g_assert_cmpint (x, ==, 0);
-  g_assert_cmpint (y, ==, 0);
 
 
   font2 = hb_font_create_sub_font (font1);
@@ -311,26 +299,24 @@ test_fontfuncs_subclassing (void)
 
   /* setup font2 to override some funcs */
   ffuncs2 = hb_font_funcs_create ();
-  hb_font_funcs_set_contour_point_func (ffuncs2, contour_point_func2, NULL, NULL);
+  hb_font_funcs_set_glyph_contour_point_func (ffuncs2, contour_point_func2, NULL, NULL);
   hb_font_set_funcs (font2, ffuncs2, NULL, NULL);
   hb_font_funcs_destroy (ffuncs2);
 
   x = y = 1;
-  g_assert (hb_font_get_contour_point_for_direction (font2, 1, 2, HB_DIRECTION_LTR, &x, &y));
+  g_assert (hb_font_get_glyph_contour_point_for_origin (font2, 1, 2, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 6);
   g_assert_cmpint (y, ==, 7);
-  g_assert (hb_font_get_contour_point_for_direction (font2, 2, 5, HB_DIRECTION_RTL, &x, &y));
+  g_assert (hb_font_get_glyph_contour_point_for_origin (font2, 2, 5, HB_DIRECTION_RTL, &x, &y));
   g_assert_cmpint (x, ==, 4);
   g_assert_cmpint (y, ==, 5);
-  g_assert (!hb_font_get_contour_point_for_direction (font2, 3, 7, HB_DIRECTION_LTR, &x, &y));
+  g_assert (!hb_font_get_glyph_contour_point_for_origin (font2, 3, 7, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 0);
   g_assert_cmpint (y, ==, 0);
-  hb_font_get_glyph_h_advance (font2, 1, &x, &y);
+  hb_font_get_glyph_h_advance (font2, 1, &x);
   g_assert_cmpint (x, ==, 8);
-  g_assert_cmpint (y, ==, 9);
-  hb_font_get_glyph_h_advance (font2, 2, &x, &y);
+  hb_font_get_glyph_h_advance (font2, 2, &x);
   g_assert_cmpint (x, ==, 0);
-  g_assert_cmpint (y, ==, 0);
 
 
   font3 = hb_font_create_sub_font (font2);
@@ -341,21 +327,19 @@ test_fontfuncs_subclassing (void)
   hb_font_set_scale (font3, 20, 30);
 
   x = y = 1;
-  g_assert (hb_font_get_contour_point_for_direction (font3, 1, 2, HB_DIRECTION_RTL, &x, &y));
+  g_assert (hb_font_get_glyph_contour_point_for_origin (font3, 1, 2, HB_DIRECTION_RTL, &x, &y));
   g_assert_cmpint (x, ==, 6*2);
   g_assert_cmpint (y, ==, 7*3);
-  g_assert (hb_font_get_contour_point_for_direction (font3, 2, 5, HB_DIRECTION_LTR, &x, &y));
+  g_assert (hb_font_get_glyph_contour_point_for_origin (font3, 2, 5, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 4*2);
   g_assert_cmpint (y, ==, 5*3);
-  g_assert (!hb_font_get_contour_point_for_direction (font3, 3, 7, HB_DIRECTION_LTR, &x, &y));
+  g_assert (!hb_font_get_glyph_contour_point_for_origin (font3, 3, 7, HB_DIRECTION_LTR, &x, &y));
   g_assert_cmpint (x, ==, 0*2);
   g_assert_cmpint (y, ==, 0*3);
-  hb_font_get_glyph_h_advance (font3, 1, &x, &y);
+  hb_font_get_glyph_h_advance (font3, 1, &x);
   g_assert_cmpint (x, ==, 8*2);
-  g_assert_cmpint (y, ==, 9*3);
-  hb_font_get_glyph_h_advance (font3, 2, &x, &y);
+  hb_font_get_glyph_h_advance (font3, 2, &x);
   g_assert_cmpint (x, ==, 0*2);
-  g_assert_cmpint (y, ==, 0*3);
 
 
   hb_font_destroy (font3);
diff --git a/test/test-shape.c b/test/test-shape.c
index 531f721..64594b2 100644
--- a/test/test-shape.c
+++ b/test/test-shape.c
@@ -37,18 +37,17 @@
 
 static const char test_data[] = "test\0data";
 
-static hb_bool_t
-glyph_advance_func (hb_font_t *font, void *font_data,
-		    hb_codepoint_t glyph,
-		    hb_position_t *x_advance, hb_position_t *y_advance,
-		    void *user_data)
+static void
+glyph_h_advance_func (hb_font_t *font, void *font_data,
+		      hb_codepoint_t glyph,
+		      hb_position_t *advance,
+		      void *user_data)
 {
   switch (glyph) {
-  case 1: *x_advance = 10; return TRUE;
-  case 2: *x_advance =  6; return TRUE;
-  case 3: *x_advance =  5; return TRUE;
+  case 1: *advance = 10; return;
+  case 2: *advance =  6; return;
+  case 3: *advance =  5; return;
   }
-  return FALSE;
 }
 
 static hb_bool_t
@@ -66,17 +65,15 @@ glyph_func (hb_font_t *font, void *font_data,
   return FALSE;
 }
 
-static hb_bool_t
-kerning_func (hb_font_t *font, void *font_data,
-	      hb_codepoint_t left, hb_codepoint_t right,
-	      hb_position_t *x_kern, hb_position_t *y_kern,
-	      void *user_data)
+static void
+glyph_h_kerning_func (hb_font_t *font, void *font_data,
+		      hb_codepoint_t left, hb_codepoint_t right,
+		      hb_position_t *kerning,
+		      void *user_data)
 {
   if (left == 1 && right == 2) {
-    *x_kern = -2;
-    return TRUE;
+    *kerning = -2;
   }
-  return FALSE;
 }
 
 static const char TesT[] = "TesT";
@@ -101,9 +98,9 @@ test_shape (void)
   hb_font_set_scale (font, 10, 10);
 
   ffuncs = hb_font_funcs_create ();
-  hb_font_funcs_set_glyph_h_advance_func (ffuncs, glyph_advance_func, NULL, NULL);
+  hb_font_funcs_set_glyph_h_advance_func (ffuncs, glyph_h_advance_func, NULL, NULL);
   hb_font_funcs_set_glyph_func (ffuncs, glyph_func, NULL, NULL);
-  hb_font_funcs_set_h_kerning_func (ffuncs, kerning_func, NULL, NULL);
+  hb_font_funcs_set_glyph_h_kerning_func (ffuncs, glyph_h_kerning_func, NULL, NULL);
   hb_font_set_funcs (font, ffuncs, NULL, NULL);
   hb_font_funcs_destroy (ffuncs);
 
commit 7403e055cd1463f38215ad9faedd61c3e1b66ac5
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Tue May 24 21:04:15 2011 -0400

    [Vertical] fix vertical gpos
    
    Wow, it took me a few days to find the right fix!
    
    We now set the advance for attached marks to zero, but we
    do this in the _finish() state of gpos, so it shouldn't
    regress with fonts like DejaVuSansMono that explicitly
    decrease the mark advance width to set it to zero.

diff --git a/src/hb-ot-layout-gpos-private.hh b/src/hb-ot-layout-gpos-private.hh
index 87e25ff..d51a2b0 100644
--- a/src/hb-ot-layout-gpos-private.hh
+++ b/src/hb-ot-layout-gpos-private.hh
@@ -873,38 +873,57 @@ struct CursivePosFormat1
     (this+this_record.exitAnchor).get_anchor (c->font, c->buffer->info[i].codepoint, &exit_x, &exit_y);
     (this+next_record.entryAnchor).get_anchor (c->font, c->buffer->info[j].codepoint, &entry_x, &entry_y);
 
-    /* Align the exit anchor of the left/top glyph with the entry anchor of the right/bottom glyph
-     * by adjusting advance of the left/top glyph. */
-    if (HB_DIRECTION_IS_BACKWARD (c->direction))
-    {
-      if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction)))
-	c->buffer->pos[j].x_advance = c->buffer->pos[j].x_offset + entry_x - exit_x;
-      else
-	c->buffer->pos[j].y_advance = c->buffer->pos[j].y_offset + entry_y - exit_y;
-    }
-    else
-    {
-      if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction)))
-	c->buffer->pos[i].x_advance = c->buffer->pos[i].x_offset + exit_x - entry_x;
-      else
-	c->buffer->pos[i].y_advance = c->buffer->pos[i].y_offset + exit_y - entry_y;
+    hb_glyph_position_t *pos = c->buffer->pos;
+
+    hb_position_t d;
+    /* Main-direction adjustment */
+    switch (c->direction) {
+      case HB_DIRECTION_LTR:
+	pos[i].x_advance  =  exit_x + pos[i].x_offset;
+
+	d = entry_x + pos[j].x_offset;
+	pos[j].x_advance -= d;
+	pos[j].x_offset  -= d;
+	break;
+      case HB_DIRECTION_RTL:
+	d = exit_x + pos[i].x_offset;
+	pos[i].x_advance -= d;
+	pos[i].x_offset  -= d;
+
+	pos[j].x_advance  =  entry_x + pos[j].x_offset;
+	break;
+      case HB_DIRECTION_TTB:
+	pos[i].y_advance  =  exit_y + pos[i].y_offset;
+
+	d = entry_y + pos[j].y_offset;
+	pos[j].y_advance -= d;
+	pos[j].y_offset  -= d;
+	break;
+      case HB_DIRECTION_BTT:
+	d = exit_y + pos[i].y_offset;
+	pos[i].y_advance -= d;
+	pos[i].y_offset  -= d;
+
+	pos[j].y_advance  =  entry_y;
+	break;
+      case HB_DIRECTION_INVALID:
+      default:
+	break;
     }
 
-    if  (c->lookup_props & LookupFlag::RightToLeft)
-    {
-      c->buffer->pos[i].cursive_chain() = j - i;
+    /* Cross-direction adjustment */
+    if  (c->lookup_props & LookupFlag::RightToLeft) {
+      pos[i].cursive_chain() = j - i;
       if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction)))
-	c->buffer->pos[i].y_offset = entry_y - exit_y;
+	pos[i].y_offset = entry_y - exit_y;
       else
-	c->buffer->pos[i].x_offset = entry_x - exit_x;
-    }
-    else
-    {
-      c->buffer->pos[j].cursive_chain() = i - j;
+	pos[i].x_offset = entry_x - exit_x;
+    } else {
+      pos[j].cursive_chain() = i - j;
       if (likely (HB_DIRECTION_IS_HORIZONTAL (c->direction)))
-	c->buffer->pos[j].y_offset = exit_y - entry_y;
+	pos[j].y_offset = exit_y - entry_y;
       else
-	c->buffer->pos[j].x_offset = exit_x - entry_x;
+	pos[j].x_offset = exit_x - entry_x;
     }
 
     c->buffer->i = j;
@@ -1500,61 +1519,69 @@ struct GPOS : GSUBGPOS
   DEFINE_SIZE_STATIC (10);
 };
 
+
+static void
+fix_cursive_minor_offset (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction)
+{
+    unsigned int j = pos[i].cursive_chain();
+    if (likely (!j))
+      return;
+
+    j += i;
+
+    pos[i].cursive_chain() = 0;
+
+    fix_cursive_minor_offset (pos, j, direction);
+
+    if (HB_DIRECTION_IS_HORIZONTAL (direction))
+      pos[i].y_offset += pos[j].y_offset;
+    else
+      pos[i].x_offset += pos[j].x_offset;
+}
+
+static void
+fix_mark_attachment (hb_glyph_position_t *pos, unsigned int i, hb_direction_t direction)
+{
+  if (likely (!(pos[i].attach_lookback())))
+    return;
+
+  unsigned int j = i - pos[i].attach_lookback();
+
+  pos[i].x_advance = 0;
+  pos[i].y_advance = 0;
+  pos[i].x_offset += pos[j].x_offset;
+  pos[i].y_offset += pos[j].y_offset;
+
+  if (HB_DIRECTION_IS_FORWARD (direction))
+    for (unsigned int k = j; k < i; j++) {
+      pos[i].x_offset -= pos[k].x_advance;
+      pos[i].y_offset -= pos[k].y_advance;
+    }
+  else
+    for (unsigned int k = j + 1; k < i + 1; j++) {
+      pos[i].x_offset += pos[k].x_advance;
+      pos[i].y_offset += pos[k].y_advance;
+    }
+}
+
 void
 GPOS::position_finish (hb_buffer_t *buffer)
 {
-  unsigned int i, j;
   unsigned int len;
   hb_glyph_position_t *pos = hb_buffer_get_glyph_positions (buffer, &len);
   hb_direction_t direction = buffer->props.direction;
 
-  /* Handle cursive connections:
-   * First handle all chain-back connections, then handle all chain-forward connections. */
-  if (likely (HB_DIRECTION_IS_HORIZONTAL (direction)))
+  /* Handle cursive connections */
+  for (unsigned int i = 0; i < len; i++)
   {
-    for (j = 0; j < len; j++) {
-      if (pos[j].cursive_chain() < 0)
-	pos[j].y_offset += pos[j + pos[j].cursive_chain()].y_offset;
-    }
-    for (i = len; i > 0; i--) {
-      j = i - 1;
-      if (pos[j].cursive_chain() > 0)
-	pos[j].y_offset += pos[j + pos[j].cursive_chain()].y_offset;
-    }
+    fix_cursive_minor_offset (pos, i, direction);
   }
-  else
-  {
-    for (j = 0; j < len; j++) {
-      if (pos[j].cursive_chain() < 0)
-	pos[j].x_offset += pos[j + pos[j].cursive_chain()].x_offset;
-    }
-    for (i = len; i > 0; i--) {
-      j = i - 1;
-      if (pos[j].cursive_chain() > 0)
-	pos[j].x_offset += pos[j + pos[j].cursive_chain()].x_offset;
-    }
-  }
-
 
   /* Handle attachments */
-  for (i = 0; i < len; i++)
-    if (pos[i].attach_lookback())
-    {
-      unsigned int back = i - pos[i].attach_lookback();
-      pos[i].x_offset += pos[back].x_offset;
-      pos[i].y_offset += pos[back].y_offset;
-
-      if (HB_DIRECTION_IS_BACKWARD (buffer->props.direction))
-	for (j = back + 1; j < i + 1; j++) {
-	  pos[i].x_offset += pos[j].x_advance;
-	  pos[i].y_offset += pos[j].y_advance;
-	}
-      else
-	for (j = back; j < i; j++) {
-	  pos[i].x_offset -= pos[j].x_advance;
-	  pos[i].y_offset -= pos[j].y_advance;
-	}
-    }
+  for (unsigned int i = 0; i < len; i++)
+  {
+    fix_mark_attachment (pos, i, direction);
+  }
 }
 
 
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index d8970a1..f78c29b 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -184,9 +184,12 @@ hb_ensure_native_direction (hb_ot_shape_context_t *c)
 {
   hb_direction_t direction = c->buffer->props.direction;
 
-  /* XXX vertical */
-  if (HB_DIRECTION_IS_HORIZONTAL (direction) &&
-      direction != hb_script_get_horizontal_direction (c->buffer->props.script))
+  /* TODO vertical:
+   * The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
+   * Ogham fonts are supposed to be implemented BTT or not.  Need to research that
+   * first. */
+  if ((HB_DIRECTION_IS_HORIZONTAL (direction) && direction != hb_script_get_horizontal_direction (c->buffer->props.script)) ||
+      (HB_DIRECTION_IS_VERTICAL   (direction) && direction != HB_DIRECTION_TTB))
   {
     hb_buffer_reverse_clusters (c->buffer);
     c->buffer->props.direction = HB_DIRECTION_REVERSE (c->buffer->props.direction);
commit ff7cbd0219a7c260612c53b3bed343747d79ec4e
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed May 25 09:56:06 2011 -0400

    [TODO] Update

diff --git a/TODO b/TODO
index ad13350..d512b28 100644
--- a/TODO
+++ b/TODO
@@ -7,10 +7,18 @@ General fixes:
 - Right now, BTW, for non-native direction runs, we get the cluster wrong...
   Should do min(input-glyphs.cluster)
 
-- Fix tt kern on/off and GPOS interaction
+- Fix TT 'kern' on/off and GPOS interaction (move kerning before GPOS)
 
 - Do proper rounding when scaling from font space?
 
+- Adjust default features for vertical text:
+
+  * vrt2 preferred over vert; but if user selects vert, turn vrt2 off?
+  * vkrn (enables vpal?  vpal anyone???);
+  * valt: "This feature is mutually exclusive with all other glyph-height features (e.g. vhal and vpal),
+          which should be turned off when it's applied. It deactivates the kern."
+
+
 API issues to fix before 1.0:
 ============================
 
@@ -18,7 +26,9 @@ API issues to fix before 1.0:
 
 - Add hb-cairo glue
 
-- Add sanitize API
+- Add sanitize API (and a cached version, that saves result on blob user-data)
+
+- hb_shape() currently does a bit more than hb_ot_shape().  Shouldn't.
 
 - Add glib GBoxedType stuff and introspection
 



More information about the HarfBuzz mailing list