[API] Change signature of get_contour_point and get_kerning ffuncs
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 11 May 2011 04:24:34 +0000 (00:24 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 11 May 2011 04:38:22 +0000 (00:38 -0400)
get_contour_point now takes glyph id before point_index.

get_kerning now takes a vector to fill-in.

src/hb-font.cc
src/hb-font.h
src/hb-ft.cc
src/hb-ot-layout-gdef-private.hh
src/hb-ot-layout-gpos-private.hh
src/hb-ot-shape.cc

index 280b27a..6cd436d 100644 (file)
@@ -44,16 +44,16 @@ HB_BEGIN_DECLS
 static hb_bool_t
 hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED,
                               const void *font_data HB_UNUSED,
-                              unsigned int point_index HB_UNUSED,
-                              hb_codepoint_t glyph HB_UNUSED,
-                              hb_position_t *x HB_UNUSED,
-                              hb_position_t *y HB_UNUSED,
+                              hb_codepoint_t glyph,
+                              unsigned int point_index,
+                              hb_position_t *x,
+                              hb_position_t *y,
                               const void *user_data HB_UNUSED)
 {
   if (font->parent) {
     hb_bool_t ret;
     ret = hb_font_get_contour_point (font->parent,
-                                    point_index, glyph,
+                                    glyph, point_index,
                                     x, y);
     font->parent_scale_position (x, y);
     return ret;
@@ -67,9 +67,9 @@ hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED,
 static void
 hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED,
                               const void *font_data HB_UNUSED,
-                              hb_codepoint_t glyph HB_UNUSED,
-                              hb_position_t *x_advance HB_UNUSED,
-                              hb_position_t *y_advance HB_UNUSED,
+                              hb_codepoint_t glyph,
+                              hb_position_t *x_advance,
+                              hb_position_t *y_advance,
                               const void *user_data HB_UNUSED)
 {
   if (font->parent) {
@@ -84,8 +84,8 @@ hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED,
 static void
 hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
                               const void *font_data HB_UNUSED,
-                              hb_codepoint_t glyph HB_UNUSED,
-                              hb_glyph_extents_t *extents HB_UNUSED,
+                              hb_codepoint_t glyph,
+                              hb_glyph_extents_t *extents,
                               const void *user_data HB_UNUSED)
 {
   if (font->parent) {
@@ -102,8 +102,8 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
 static hb_codepoint_t
 hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
                       const void *font_data HB_UNUSED,
-                      hb_codepoint_t unicode HB_UNUSED,
-                      hb_codepoint_t variation_selector HB_UNUSED,
+                      hb_codepoint_t unicode,
+                      hb_codepoint_t variation_selector,
                       const void *user_data HB_UNUSED)
 {
   if (font->parent)
@@ -112,21 +112,22 @@ hb_font_get_glyph_nil (hb_font_t *font HB_UNUSED,
   return 0;
 }
 
-static hb_position_t
+static void
 hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED,
                         const void *font_data HB_UNUSED,
-                        hb_codepoint_t first_glyph HB_UNUSED,
-                        hb_codepoint_t second_glyph HB_UNUSED,
+                        hb_codepoint_t first_glyph,
+                        hb_codepoint_t second_glyph,
+                        hb_position_t *x_kern,
+                        hb_position_t *y_kern,
                         const void *user_data HB_UNUSED)
 {
   if (font->parent) {
-    hb_position_t ret;
-    ret = hb_font_get_kerning (font->parent, first_glyph, second_glyph);
-    ret = font->parent_scale_x_distance (ret);
-    return ret;
+    hb_font_get_kerning (font->parent, first_glyph, second_glyph, x_kern, y_kern);
+    font->parent_scale_distance (x_kern, y_kern);
+    return;
   }
 
-  return 0;
+  *x_kern = *y_kern = 0;
 }
 
 
@@ -249,13 +250,13 @@ IMPLEMENT (kerning);
 
 hb_bool_t
 hb_font_get_contour_point (hb_font_t *font,
-                          unsigned int point_index,
-                          hb_codepoint_t glyph, hb_position_t *x, hb_position_t *y)
+                          hb_codepoint_t glyph, unsigned int point_index,
+                          hb_position_t *x, hb_position_t *y)
 {
   *x = 0; *y = 0;
   return font->klass->get.contour_point (font, font->user_data,
-                                        point_index,
-                                        glyph, x, y,
+                                        glyph, point_index,
+                                        x, y,
                                         font->klass->user_data.contour_point);
 }
 
@@ -289,12 +290,15 @@ hb_font_get_glyph (hb_font_t *font,
                                 font->klass->user_data.glyph);
 }
 
-hb_position_t
+void
 hb_font_get_kerning (hb_font_t *font,
-                    hb_codepoint_t first_glyph, hb_codepoint_t second_glyph)
+                    hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+                    hb_position_t *x_kern, hb_position_t *y_kern)
 {
+  *x_kern = *y_kern = 0;
   return font->klass->get.kerning (font, font->user_data,
                                   first_glyph, second_glyph,
+                                  x_kern, y_kern,
                                   font->klass->user_data.kerning);
 }
 
index d4a5441..ce81985 100644 (file)
@@ -123,7 +123,7 @@ typedef struct _hb_glyph_extents_t
 
 
 typedef hb_bool_t (*hb_font_get_contour_point_func_t) (hb_font_t *font, const void *font_data,
-                                                      unsigned int point_index, hb_codepoint_t glyph,
+                                                      hb_codepoint_t glyph, unsigned int point_index,
                                                       hb_position_t *x, hb_position_t *y,
                                                       const void *user_data);
 typedef void (*hb_font_get_glyph_advance_func_t) (hb_font_t *font, const void *font_data,
@@ -137,9 +137,10 @@ typedef void (*hb_font_get_glyph_extents_func_t) (hb_font_t *font, const void *f
 typedef hb_codepoint_t (*hb_font_get_glyph_func_t) (hb_font_t *font, const void *font_data,
                                                    hb_codepoint_t unicode, hb_codepoint_t variation_selector,
                                                    const void *user_data);
-typedef hb_position_t (*hb_font_get_kerning_func_t) (hb_font_t *font, const void *font_data,
-                                                    hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
-                                                    const void *user_data);
+typedef void (*hb_font_get_kerning_func_t) (hb_font_t *font, const void *font_data,
+                                           hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+                                           hb_position_t *x_kern, hb_position_t *y_kern,
+                                           const void *user_data);
 
 
 void
@@ -170,7 +171,7 @@ hb_font_funcs_set_kerning_func (hb_font_funcs_t *ffuncs,
 
 hb_bool_t
 hb_font_get_contour_point (hb_font_t *font,
-                          unsigned int point_index, hb_codepoint_t glyph,
+                          hb_codepoint_t glyph, unsigned int point_index,
                           hb_position_t *x, hb_position_t *y);
 
 void
@@ -187,9 +188,10 @@ hb_codepoint_t
 hb_font_get_glyph (hb_font_t *font,
                   hb_codepoint_t unicode, hb_codepoint_t variation_selector);
 
-hb_position_t
+void
 hb_font_get_kerning (hb_font_t *font,
-                    hb_codepoint_t first_glyph, hb_codepoint_t second_glyph);
+                    hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
+                    hb_position_t *x_kern, hb_position_t *y_kern);
 
 
 /*
index 50ab09f..2566c05 100644 (file)
@@ -39,8 +39,8 @@ HB_BEGIN_DECLS
 static hb_bool_t
 hb_ft_get_contour_point (hb_font_t *font HB_UNUSED,
                         const void *font_data,
-                        unsigned int point_index,
                         hb_codepoint_t glyph,
+                        unsigned int point_index,
                         hb_position_t *x,
                         hb_position_t *y,
                         const void *user_data HB_UNUSED)
@@ -128,11 +128,13 @@ hb_ft_get_glyph (hb_font_t *font HB_UNUSED,
   return FT_Get_Char_Index (ft_face, unicode);
 }
 
-static hb_position_t
+static void
 hb_ft_get_kerning (hb_font_t *font HB_UNUSED,
                   const void *font_data,
                   hb_codepoint_t first_glyph,
                   hb_codepoint_t second_glyph,
+                  hb_position_t *x_kern,
+                  hb_position_t *y_kern,
                   const void *user_data HB_UNUSED)
 {
   FT_Face ft_face = (FT_Face) font_data;
@@ -140,9 +142,10 @@ hb_ft_get_kerning (hb_font_t *font HB_UNUSED,
 
   /* TODO: Kern type? */
   if (FT_Get_Kerning (ft_face, first_glyph, second_glyph, FT_KERNING_DEFAULT, &kerning))
-      return 0;
+    return;
 
-  return kerning.x;
+  *x_kern = kerning.x;
+  *y_kern = kerning.y;
 }
 
 static hb_font_funcs_t ft_ffuncs = {
index 910f32d..d06d7c2 100644 (file)
@@ -121,7 +121,7 @@ struct CaretValueFormat2
   inline int get_caret_value (hb_font_t *font, hb_direction_t direction, hb_codepoint_t glyph_id) const
   {
     hb_position_t x, y;
-    if (hb_font_get_contour_point (font, caretValuePoint, glyph_id, &x, &y))
+    if (hb_font_get_contour_point (font, glyph_id, caretValuePoint, &x, &y))
       return HB_DIRECTION_IS_HORIZONTAL (direction) ? x : y;
     else
       return 0;
index 21c6241..100be67 100644 (file)
@@ -243,7 +243,7 @@ struct AnchorFormat2
       hb_bool_t ret = false;
 
       if (x_ppem || y_ppem)
-       ret = hb_font_get_contour_point (font, anchorPoint, glyph_id, &cx, &cy);
+       ret = hb_font_get_contour_point (font, glyph_id, anchorPoint, &cx, &cy);
       *x = x_ppem && ret ? cx : font->em_scale_x (xCoordinate);
       *y = y_ppem && ret ? cy : font->em_scale_y (yCoordinate);
   }
index 306bb41..4f90027 100644 (file)
@@ -271,13 +271,20 @@ hb_truetype_kern (hb_ot_shape_context_t *c)
   /* TODO Check for kern=0 */
   unsigned int count = c->buffer->len;
   for (unsigned int i = 1; i < count; i++) {
-    hb_position_t kern, kern1, kern2;
-    kern = hb_font_get_kerning (c->font, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint);
-    kern1 = kern >> 1;
-    kern2 = kern - kern1;
+    hb_position_t x_kern, y_kern, kern1, kern2;
+    hb_font_get_kerning (c->font, c->buffer->info[i - 1].codepoint, c->buffer->info[i].codepoint, &x_kern, &y_kern);
+
+    kern1 = x_kern >> 1;
+    kern2 = x_kern - kern1;
     c->buffer->pos[i - 1].x_advance += kern1;
     c->buffer->pos[i].x_advance += kern2;
     c->buffer->pos[i].x_offset += kern2;
+
+    kern1 = y_kern >> 1;
+    kern2 = y_kern - kern1;
+    c->buffer->pos[i - 1].y_advance += kern1;
+    c->buffer->pos[i].y_advance += kern2;
+    c->buffer->pos[i].y_offset += kern2;
   }
 }