[HarfBuzz] harfbuzz: Branch 'master' - 2 commits

Behdad Esfahbod behdad at kemper.freedesktop.org
Wed Jan 21 18:51:45 PST 2015


 src/hb-coretext.cc |   33 +++++++++++++++++++++++++--------
 1 file changed, 25 insertions(+), 8 deletions(-)

New commits:
commit 70622e5089c01ea16fd9deed11cb39d43145c121
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Jan 21 18:50:57 2015 -0800

    [coretext] Fix scaling
    
    Before we were not accounting for possible differences in x_scale and
    y_scale, as well as the signs of those.  All should be in good shape
    now.

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 64ceb44..b22c46f 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -140,6 +140,7 @@ hb_coretext_face_get_cg_font (hb_face_t *face)
 
 struct hb_coretext_shaper_font_data_t {
   CTFontRef ct_font;
+  CGFloat x_mult, y_mult; /* From CT space to HB space. */
 };
 
 hb_coretext_shaper_font_data_t *
@@ -154,7 +155,17 @@ _hb_coretext_shaper_font_data_create (hb_font_t *font)
   hb_face_t *face = font->face;
   hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
 
-  data->ct_font = CTFontCreateWithGraphicsFont (face_data, font->y_scale, NULL, NULL);
+  /* Choose a CoreText font size and calculate multipliers to convert to HarfBuzz space. */
+  CGFloat font_size = 36.; /* Default... */
+  /* No idea if the following is even a good idea. */
+  if (font->y_ppem)
+    font_size = font->y_ppem;
+
+  if (font_size < 0)
+    font_size = -font_size;
+  data->x_mult = (CGFloat) font->x_scale / font_size;
+  data->y_mult = (CGFloat) font->y_scale / font_size;
+  data->ct_font = CTFontCreateWithGraphicsFont (face_data, font_size, NULL, NULL);
   if (unlikely (!data->ct_font)) {
     DEBUG_MSG (CORETEXT, font, "Font CTFontCreateWithGraphicsFont() failed");
     free (data);
@@ -956,14 +967,15 @@ retry:
 	double run_advance = CTRunGetTypographicBounds (run, range_all, NULL, NULL, NULL);
 	DEBUG_MSG (CORETEXT, run, "Run advance: %g", run_advance);
 	hb_glyph_info_t *info = run_info;
+	CGFloat x_mult = font_data->x_mult, y_mult = font_data->y_mult;
 	if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction))
 	{
 	  for (unsigned int j = 0; j < num_glyphs; j++)
 	  {
 	    double advance = (j + 1 < num_glyphs ? positions[j + 1].x : positions[0].x + run_advance) - positions[j].x;
-	    info->mask = advance;
-	    info->var1.u32 = positions[0].x; /* Yes, zero. */
-	    info->var2.u32 = positions[j].y;
+	    info->mask = advance * x_mult;
+	    info->var1.u32 = positions[0].x * x_mult; /* Yes, zero. */
+	    info->var2.u32 = positions[j].y * y_mult;
 	    info++;
 	  }
 	}
@@ -973,9 +985,9 @@ retry:
 	  for (unsigned int j = 0; j < num_glyphs; j++)
 	  {
 	    double advance = (j + 1 < num_glyphs ? positions[j + 1].y : positions[0].y + run_advance) - positions[j].y;
-	    info->mask = advance;
-	    info->var1.u32 = positions[j].x;
-	    info->var2.u32 = positions[0].y; /* Yes, zero. */
+	    info->mask = advance * y_mult;
+	    info->var1.u32 = positions[j].x * x_mult;
+	    info->var2.u32 = positions[0].y * y_mult; /* Yes, zero. */
 	    info++;
 	  }
 	}
commit 221ba02b0816584a02471037edae7cec9c1b8acc
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Wed Jan 21 16:42:09 2015 -0800

    [coretext] Use vertical advance for notdef in vertical direction

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 11629cc..64ceb44 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -861,7 +861,12 @@ retry:
 	  hb_glyph_info_t *info = buffer->info + buffer->len;
 
 	  CGGlyph notdef = 0;
-	  double advance = CTFontGetAdvancesForGlyphs (font_data->ct_font, kCTFontHorizontalOrientation, &notdef, NULL, 1);
+	  double advance = CTFontGetAdvancesForGlyphs (font_data->ct_font,
+						       HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction) ?
+						       kCTFontHorizontalOrientation :
+						       kCTFontVerticalOrientation,
+						       &notdef, NULL, 1);
+	  /* XXX adjust sign / scale of advance. */
 
 	  unsigned int old_len = buffer->len;
 	  for (CFIndex j = range.location; j < range.location + range.length; j++)


More information about the HarfBuzz mailing list