More vertical
authorBehdad Esfahbod <behdad@behdad.org>
Thu, 19 May 2011 17:08:00 +0000 (13:08 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Thu, 19 May 2011 17:08:00 +0000 (13:08 -0400)
Starting to get there, but not without yet another round of changes.

I think I know wheere to go now.

src/hb-font.cc
src/hb-font.h
src/hb-ft.cc
src/hb-ot-shape.cc

index c2fbb94..e223a68 100644 (file)
@@ -472,6 +472,34 @@ hb_font_get_glyph_origin_for_direction (hb_font_t *font,
 }
 
 void
+hb_font_add_glyph_origin_for_direction (hb_font_t *font,
+                                       hb_codepoint_t glyph,
+                                       hb_direction_t direction,
+                                       hb_position_t *x, hb_position_t *y)
+{
+  hb_position_t origin_x, origin_y;
+
+  hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y);
+
+  *x += origin_x;
+  *y += origin_y;
+}
+
+void
+hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
+                                            hb_codepoint_t glyph,
+                                            hb_direction_t direction,
+                                            hb_position_t *x, hb_position_t *y)
+{
+  hb_position_t origin_x, origin_y;
+
+  hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y);
+
+  *x -= origin_x;
+  *y -= origin_y;
+}
+
+void
 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
                                         hb_codepoint_t first_glyph, hb_codepoint_t second_glyph,
                                         hb_direction_t direction,
@@ -502,12 +530,8 @@ hb_font_get_glyph_extents_for_direction (hb_font_t *font,
 {
   hb_bool_t ret = hb_font_get_glyph_extents (font, glyph, extents);
 
-  if (ret) {
-    hb_position_t origin_x, origin_y;
-    hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y);
-    extents->x_bearing += origin_x;
-    extents->y_bearing += origin_y;
-  }
+  if (ret)
+    hb_font_subtract_glyph_origin_for_direction (font, glyph, direction, &extents->x_bearing, &extents->y_bearing);
 }
 
 hb_bool_t
@@ -518,12 +542,8 @@ hb_font_get_glyph_contour_point_for_direction (hb_font_t *font,
 {
   hb_bool_t ret = hb_font_get_glyph_contour_point (font, glyph, point_index, x, y);
 
-  if (ret) {
-    hb_position_t origin_x, origin_y;
-    hb_font_get_glyph_origin_for_direction (font, glyph, direction, &origin_x, &origin_y);
-    *x += origin_x;
-    *y += origin_y;
-  }
+  if (ret)
+    hb_font_subtract_glyph_origin_for_direction (font, glyph, direction, x, y);
 
   return ret;
 }
index a73b8d1..3c181f0 100644 (file)
@@ -275,6 +275,16 @@ hb_font_get_glyph_origin_for_direction (hb_font_t *font,
                                        hb_codepoint_t glyph,
                                        hb_direction_t direction,
                                        hb_position_t *x, hb_position_t *y);
+void
+hb_font_add_glyph_origin_for_direction (hb_font_t *font,
+                                       hb_codepoint_t glyph,
+                                       hb_direction_t direction,
+                                       hb_position_t *x, hb_position_t *y);
+void
+hb_font_subtract_glyph_origin_for_direction (hb_font_t *font,
+                                            hb_codepoint_t glyph,
+                                            hb_direction_t direction,
+                                            hb_position_t *x, hb_position_t *y);
 
 void
 hb_font_get_glyph_kerning_for_direction (hb_font_t *font,
index c545d24..f6a62cf 100644 (file)
@@ -110,6 +110,8 @@ hb_ft_get_glyph_v_advance (hb_font_t *font HB_UNUSED,
   if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
     return FALSE;
 
+  /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
+   * have a Y growing upward.  Hence the extra negation. */
   *y = -ft_face->glyph->metrics.vertAdvance;
   return TRUE;
 }
@@ -140,7 +142,16 @@ hb_ft_get_glyph_v_origin (hb_font_t *font HB_UNUSED,
   if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
     return FALSE;
 
-  /* XXX */*y = ft_face->glyph->metrics.vertAdvance;
+  /* Note: FreeType's vertical metrics grows downward while other FreeType coordinates
+   * have a Y growing upward.  Hence the extra negation. */
+  *x = ft_face->glyph->metrics.horiBearingX -   ft_face->glyph->metrics.vertBearingX;
+  *y = ft_face->glyph->metrics.horiBearingY - (-ft_face->glyph->metrics.vertBearingY);
+
+  /* TODO ??
+  if (glyph->format == FT_GLYPH_FORMAT_OUTLINE)
+    FT_Vector_Transform (&vector, &scaled_font->unscaled->Current_Shape);
+   */
+
   return TRUE;
 }
 
@@ -190,7 +201,6 @@ hb_ft_get_glyph_extents (hb_font_t *font HB_UNUSED,
   if (unlikely (FT_Load_Glyph (ft_face, glyph, load_flags)))
     return FALSE;
 
-  /* XXX: A few negations should be in order here, not sure. */
   extents->x_bearing = ft_face->glyph->metrics.horiBearingX;
   extents->y_bearing = ft_face->glyph->metrics.horiBearingY;
   extents->width = ft_face->glyph->metrics.width;
index 8823f5a..f9c05ec 100644 (file)
@@ -262,6 +262,10 @@ hb_position_default (hb_ot_shape_context_t *c)
                                             c->buffer->props.direction,
                                             &c->buffer->pos[i].x_advance,
                                             &c->buffer->pos[i].y_advance);
+    hb_font_subtract_glyph_origin_for_direction (c->font, c->buffer->info[i].codepoint,
+                                                c->buffer->props.direction,
+                                                &c->buffer->pos[i].x_offset,
+                                                &c->buffer->pos[i].y_offset);
   }
 }