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

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Feb 22 06:56:34 UTC 2016


 src/hb-coretext.cc |  176 ++++++++++++++++++++++++++++-------------------------
 1 file changed, 93 insertions(+), 83 deletions(-)

New commits:
commit 15063b12f7619d4f44981248e28f38c172d12e1f
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Feb 22 15:56:29 2016 +0900

    [coretext] Move CTFont construction to face_data

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 7e59765..04c5c5c 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -166,6 +166,7 @@ create_ct_font (CGFontRef cg_font, CGFloat font_size)
 
 struct hb_coretext_shaper_face_data_t {
   CGFontRef cg_font;
+  CTFontRef ct_font;
 };
 
 hb_coretext_shaper_face_data_t *
@@ -178,7 +179,23 @@ _hb_coretext_shaper_face_data_create (hb_face_t *face)
   data->cg_font = create_cg_font (face);
   if (unlikely (!data->cg_font))
   {
-    DEBUG_MSG (CORETEXT, face, "Failed creating CGFont.");
+    DEBUG_MSG (CORETEXT, face, "CGFont creation failed..");
+    free (data);
+    return NULL;
+  }
+
+  /* We use 36pt size instead of UPEM, because CoreText implements the 'trak' table,
+   * which can make the font too tight at large sizes.  36pt should be a good semi-neutral
+   * size.
+   *
+   * Since we always create CTFont at a fixed size, our CTFont lives in face_data
+   * instead of font_data.  Which is good, because when people change scale on
+   * hb_font_t, we won't need to update our CTFont. */
+  data->ct_font = create_ct_font (data->cg_font, 36.);
+  if (unlikely (!data->ct_font))
+  {
+    DEBUG_MSG (CORETEXT, face, "CTFont creation failed.");
+    CFRelease (data->cg_font);
     free (data);
     return NULL;
   }
@@ -189,6 +206,7 @@ _hb_coretext_shaper_face_data_create (hb_face_t *face)
 void
 _hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data)
 {
+  CFRelease (data->ct_font);
   CFRelease (data->cg_font);
   free (data);
 }
@@ -209,41 +227,17 @@ hb_coretext_face_get_cg_font (hb_face_t *face)
  * shaper font data
  */
 
-struct hb_coretext_shaper_font_data_t {
-  CTFontRef ct_font;
-};
+struct hb_coretext_shaper_font_data_t {};
 
 hb_coretext_shaper_font_data_t *
 _hb_coretext_shaper_font_data_create (hb_font_t *font)
 {
-  if (unlikely (!hb_coretext_shaper_face_data_ensure (font->face))) return NULL;
-
-  hb_coretext_shaper_font_data_t *data = (hb_coretext_shaper_font_data_t *) calloc (1, sizeof (hb_coretext_shaper_font_data_t));
-  if (unlikely (!data))
-    return NULL;
-
-  hb_face_t *face = font->face;
-  hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
-
-  /* We use 36pt size instead of UPEM, because CoreText implements the 'trak' table,
-   * which can make the font too tight at large sizes.  36pt should be a good semi-neutral
-   * size. */
-  data->ct_font = create_ct_font (face_data->cg_font, 36.);
-  if (unlikely (!data->ct_font))
-  {
-    DEBUG_MSG (CORETEXT, font, "CTFont creation failed");
-    free (data);
-    return NULL;
-  }
-
-  return data;
+  return (hb_coretext_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED;
 }
 
 void
 _hb_coretext_shaper_font_data_destroy (hb_coretext_shaper_font_data_t *data)
 {
-  CFRelease (data->ct_font);
-  free (data);
 }
 
 
@@ -269,9 +263,10 @@ _hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shaper_shape_plan_data_
 CTFontRef
 hb_coretext_font_get_ct_font (hb_font_t *font)
 {
-  if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return NULL;
-  hb_coretext_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
-  return font_data->ct_font;
+  hb_face_t *face = font->face;
+  if (unlikely (!hb_coretext_shaper_face_data_ensure (face))) return NULL;
+  hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
+  return face_data->ct_font;
 }
 
 
@@ -504,9 +499,8 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
 {
   hb_face_t *face = font->face;
   hb_coretext_shaper_face_data_t *face_data = HB_SHAPER_DATA_GET (face);
-  hb_coretext_shaper_font_data_t *font_data = HB_SHAPER_DATA_GET (font);
 
-  CGFloat ct_font_size = CTFontGetSize (font_data->ct_font);
+  CGFloat ct_font_size = CTFontGetSize (face_data->ct_font);
   CGFloat x_mult = (CGFloat) font->x_scale / ct_font_size;
   CGFloat y_mult = (CGFloat) font->y_scale / ct_font_size;
 
@@ -640,7 +634,7 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
 	  CTFontDescriptorRef font_desc = CTFontDescriptorCreateWithAttributes (attributes);
 	  CFRelease (attributes);
 
-	  range->font = CTFontCreateCopyWithAttributes (font_data->ct_font, 0.0, NULL, font_desc);
+	  range->font = CTFontCreateCopyWithAttributes (face_data->ct_font, 0.0, NULL, font_desc);
 	  CFRelease (font_desc);
 	}
 	else
@@ -797,7 +791,7 @@ resize_and_retry:
 	CFRelease (lang);
       }
       CFAttributedStringSetAttribute (attr_string, CFRangeMake (0, chars_len),
-				      kCTFontAttributeName, font_data->ct_font);
+				      kCTFontAttributeName, face_data->ct_font);
 
       if (num_features)
       {
@@ -890,7 +884,7 @@ resize_and_retry:
        */
       CFDictionaryRef attributes = CTRunGetAttributes (run);
       CTFontRef run_ct_font = static_cast<CTFontRef>(CFDictionaryGetValue (attributes, kCTFontAttributeName));
-      if (!CFEqual (run_ct_font, font_data->ct_font))
+      if (!CFEqual (run_ct_font, face_data->ct_font))
       {
 	/* The run doesn't use our main font instance.  We have to figure out
 	 * whether font fallback happened, or this is just CoreText giving us
@@ -936,7 +930,7 @@ resize_and_retry:
 	}
 	if (!matched)
 	{
-	  CFStringRef font_ps_name = CTFontCopyName (font_data->ct_font, kCTFontPostScriptNameKey);
+	  CFStringRef font_ps_name = CTFontCopyName (face_data->ct_font, kCTFontPostScriptNameKey);
 	  CFStringRef run_ps_name = CTFontCopyName (run_ct_font, kCTFontPostScriptNameKey);
 	  CFComparisonResult result = CFStringCompare (run_ps_name, font_ps_name, 0);
 	  CFRelease (run_ps_name);
commit ba3d49d9a56932d341bf1916a30f322be665e3a6
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Feb 22 15:50:12 2016 +0900

    [coretext] Move code around

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 52ddc92..7e59765 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -100,6 +100,43 @@ get_last_resort_font_desc (void)
   return font_desc;
 }
 
+static void
+release_data (void *info, const void *data, size_t size)
+{
+  assert (hb_blob_get_length ((hb_blob_t *) info) == size &&
+          hb_blob_get_data ((hb_blob_t *) info, NULL) == data);
+
+  hb_blob_destroy ((hb_blob_t *) info);
+}
+
+static CGFontRef
+create_cg_font (hb_face_t *face)
+{
+  CGFontRef cg_font = NULL;
+  if (face->destroy == (hb_destroy_func_t) CGFontRelease)
+  {
+    cg_font = CGFontRetain ((CGFontRef) face->user_data);
+  }
+  else
+  {
+    hb_blob_t *blob = hb_face_reference_blob (face);
+    unsigned int blob_length;
+    const char *blob_data = hb_blob_get_data (blob, &blob_length);
+    if (unlikely (!blob_length))
+      DEBUG_MSG (CORETEXT, face, "Face has empty blob");
+
+    CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data);
+    if (likely (provider))
+    {
+      cg_font = CGFontCreateWithDataProvider (provider);
+      if (unlikely (!cg_font))
+	DEBUG_MSG (CORETEXT, face, "Face CGFontCreateWithDataProvider() failed");
+      CGDataProviderRelease (provider);
+    }
+  }
+  return cg_font;
+}
+
 static CTFontRef
 create_ct_font (CGFontRef cg_font, CGFloat font_size)
 {
@@ -127,15 +164,6 @@ create_ct_font (CGFontRef cg_font, CGFloat font_size)
  return ct_font;
 }
 
-static void
-release_data (void *info, const void *data, size_t size)
-{
-  assert (hb_blob_get_length ((hb_blob_t *) info) == size &&
-          hb_blob_get_data ((hb_blob_t *) info, NULL) == data);
-
-  hb_blob_destroy ((hb_blob_t *) info);
-}
-
 struct hb_coretext_shaper_face_data_t {
   CGFontRef cg_font;
 };
@@ -147,28 +175,10 @@ _hb_coretext_shaper_face_data_create (hb_face_t *face)
   if (unlikely (!data))
     return NULL;
 
-  if (face->destroy == (hb_destroy_func_t) CGFontRelease)
-  {
-    data->cg_font = CGFontRetain ((CGFontRef) face->user_data);
-  }
-  else
+  data->cg_font = create_cg_font (face);
+  if (unlikely (!data->cg_font))
   {
-    hb_blob_t *blob = hb_face_reference_blob (face);
-    unsigned int blob_length;
-    const char *blob_data = hb_blob_get_data (blob, &blob_length);
-    if (unlikely (!blob_length))
-      DEBUG_MSG (CORETEXT, face, "Face has empty blob");
-
-    CGDataProviderRef provider = CGDataProviderCreateWithData (blob, blob_data, blob_length, &release_data);
-    if (likely (provider))
-    {
-      data->cg_font = CGFontCreateWithDataProvider (provider);
-      CGDataProviderRelease (provider);
-    }
-  }
-
-  if (unlikely (!data->cg_font)) {
-    DEBUG_MSG (CORETEXT, face, "Face CGFontCreateWithDataProvider() failed");
+    DEBUG_MSG (CORETEXT, face, "Failed creating CGFont.");
     free (data);
     return NULL;
   }
commit 90194efb8480d58c55b7a19962624c7aadbdca63
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Feb 22 15:42:53 2016 +0900

    [coretext] Move code around

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 0988a59..52ddc92 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -77,6 +77,29 @@ HB_SHAPER_DATA_ENSURE_DECLARE(coretext, font)
  * shaper face data
  */
 
+static CTFontDescriptorRef
+get_last_resort_font_desc (void)
+{
+  // TODO Handle allocation failures?
+  CTFontDescriptorRef last_resort = CTFontDescriptorCreateWithNameAndSize (CFSTR("LastResort"), 0);
+  CFArrayRef cascade_list = CFArrayCreate (kCFAllocatorDefault,
+					   (const void **) &last_resort,
+					   1,
+					   &kCFTypeArrayCallBacks);
+  CFRelease (last_resort);
+  CFDictionaryRef attributes = CFDictionaryCreate (kCFAllocatorDefault,
+						   (const void **) &kCTFontCascadeListAttribute,
+						   (const void **) &cascade_list,
+						   1,
+						   &kCFTypeDictionaryKeyCallBacks,
+						   &kCFTypeDictionaryValueCallBacks);
+  CFRelease (cascade_list);
+
+  CTFontDescriptorRef font_desc = CTFontDescriptorCreateWithAttributes (attributes);
+  CFRelease (attributes);
+  return font_desc;
+}
+
 static CTFontRef
 create_ct_font (CGFontRef cg_font, CGFloat font_size)
 {
@@ -89,26 +112,9 @@ create_ct_font (CGFontRef cg_font, CGFloat font_size)
   /* Create font copy with cascade list that has LastResort first; this speeds up CoreText
    * font fallback which we don't need anyway. */
   {
-    // TODO Handle allocation failures?
-    CTFontDescriptorRef last_resort = CTFontDescriptorCreateWithNameAndSize(CFSTR("LastResort"), 0);
-    CFArrayRef cascade_list = CFArrayCreate (kCFAllocatorDefault,
-					     (const void **) &last_resort,
-					     1,
-					     &kCFTypeArrayCallBacks);
-    CFRelease (last_resort);
-    CFDictionaryRef attributes = CFDictionaryCreate (kCFAllocatorDefault,
-						     (const void **) &kCTFontCascadeListAttribute,
-						     (const void **) &cascade_list,
-						     1,
-						     &kCFTypeDictionaryKeyCallBacks,
-						     &kCFTypeDictionaryValueCallBacks);
-    CFRelease (cascade_list);
-
-    CTFontDescriptorRef new_font_desc = CTFontDescriptorCreateWithAttributes (attributes);
-    CFRelease (attributes);
-
-    CTFontRef new_ct_font = CTFontCreateCopyWithAttributes (ct_font, 0.0, NULL, new_font_desc);
-    CFRelease (new_font_desc);
+    CTFontDescriptorRef last_resort_font_desc = get_last_resort_font_desc ();
+    CTFontRef new_ct_font = CTFontCreateCopyWithAttributes (ct_font, 0.0, NULL, last_resort_font_desc);
+    CFRelease (last_resort_font_desc);
     if (new_ct_font)
     {
       CFRelease (ct_font);


More information about the HarfBuzz mailing list