[font] Do user-space conversion when chaining up to parent font
authorBehdad Esfahbod <behdad@behdad.org>
Wed, 11 May 2011 04:15:37 +0000 (00:15 -0400)
committerBehdad Esfahbod <behdad@behdad.org>
Wed, 11 May 2011 04:15:37 +0000 (00:15 -0400)
src/hb-font-private.hh
src/hb-font.cc

index 203cd23..f60ce97 100644 (file)
@@ -118,6 +118,34 @@ struct _hb_font_t {
   inline hb_position_t em_scale_x (int16_t v) { return em_scale (v, this->x_scale); }
   inline hb_position_t em_scale_y (int16_t v) { return em_scale (v, this->y_scale); }
 
+  /* Convert from parent-font user-space to our user-space */
+  inline hb_position_t parent_scale_x_distance (hb_position_t v) {
+    if (unlikely (parent && parent->x_scale != x_scale))
+      return v * (int64_t) this->x_scale / this->parent->x_scale;
+    return v;
+  }
+  inline hb_position_t parent_scale_y_distance (hb_position_t v) {
+    if (unlikely (parent && parent->y_scale != y_scale))
+      return v * (int64_t) this->y_scale / this->parent->y_scale;
+    return v;
+  }
+  inline hb_position_t parent_scale_x_position (hb_position_t v) {
+    return parent_scale_x_distance (v); /* We don't have translation right now */
+  }
+  inline hb_position_t parent_scale_y_position (hb_position_t v) {
+    return parent_scale_y_distance (v); /* We don't have translation right now */
+  }
+
+  inline void parent_scale_distance (hb_position_t *x, hb_position_t *y) {
+    *x = parent_scale_x_distance (*x);
+    *y = parent_scale_y_distance (*y);
+  }
+  inline void parent_scale_position (hb_position_t *x, hb_position_t *y) {
+    *x = parent_scale_x_position (*x);
+    *y = parent_scale_y_position (*y);
+  }
+
+
   private:
   inline hb_position_t em_scale (int16_t v, int scale) { return v * (int64_t) scale / this->face->upem; }
 };
index 3dcc417..280b27a 100644 (file)
@@ -50,10 +50,14 @@ hb_font_get_contour_point_nil (hb_font_t *font HB_UNUSED,
                               hb_position_t *y HB_UNUSED,
                               const void *user_data HB_UNUSED)
 {
-  if (font->parent)
-    return hb_font_get_contour_point (font->parent,
-                                     point_index, glyph,
-                                     x, y);
+  if (font->parent) {
+    hb_bool_t ret;
+    ret = hb_font_get_contour_point (font->parent,
+                                    point_index, glyph,
+                                    x, y);
+    font->parent_scale_position (x, y);
+    return ret;
+  }
 
   *x = *y = 0;
 
@@ -70,6 +74,7 @@ hb_font_get_glyph_advance_nil (hb_font_t *font HB_UNUSED,
 {
   if (font->parent) {
     hb_font_get_glyph_advance (font->parent, glyph, x_advance, y_advance);
+    font->parent_scale_distance (x_advance, y_advance);
     return;
   }
 
@@ -85,6 +90,8 @@ hb_font_get_glyph_extents_nil (hb_font_t *font HB_UNUSED,
 {
   if (font->parent) {
     hb_font_get_glyph_extents (font->parent, glyph, extents);
+    font->parent_scale_position (&extents->x_bearing, &extents->y_bearing);
+    font->parent_scale_distance (&extents->width, &extents->height);
     return;
   }
 
@@ -112,8 +119,12 @@ hb_font_get_kerning_nil (hb_font_t *font HB_UNUSED,
                         hb_codepoint_t second_glyph HB_UNUSED,
                         const void *user_data HB_UNUSED)
 {
-  if (font->parent)
-    return hb_font_get_kerning (font->parent, first_glyph, second_glyph);
+  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;
+  }
 
   return 0;
 }