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

Behdad Esfahbod behdad at kemper.freedesktop.org
Mon Aug 11 20:48:27 PDT 2014


 src/hb-coretext.cc |  152 ++++++++++++++++++++++++++++++++++-------------------
 1 file changed, 100 insertions(+), 52 deletions(-)

New commits:
commit 5a0eed3b50629be4826e4e9428f2c3255195395d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 11 23:47:16 2014 -0400

    [coretext] Implement vertical shaping
    
    Currently doesn't work though, we detect font fallback.  Apparently
    matching on ct_font is not safe for this.  Looks like commit
    25f4fb9b56bb3f8bec821571c78f8829e40daa54 wasn't enough after all.

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index ee6745b..fc21809 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -685,6 +685,10 @@ retry:
 	FAIL ("CFAttributedStringCreateMutable failed");
       CFAttributedStringReplaceString (attr_string, CFRangeMake (0, 0), string_ref);
       CFAttributedStringSetAttribute (attr_string, CFRangeMake (0, chars_len),
+				      kCTVerticalFormsAttributeName,
+				      HB_DIRECTION_IS_VERTICAL (buffer->props.direction) ?
+				      kCFBooleanTrue : kCFBooleanFalse);
+      CFAttributedStringSetAttribute (attr_string, CFRangeMake (0, chars_len),
 				      kCTFontAttributeName, font_data->ct_font);
 
       if (num_features)
@@ -739,6 +743,7 @@ retry:
 
     CFArrayRef glyph_runs = CTLineGetGlyphRuns (line);
     unsigned int num_runs = CFArrayGetCount (glyph_runs);
+    DEBUG_MSG (CORETEXT, NULL, "Num runs: %d", num_runs);
 
     buffer->len = 0;
     uint32_t status_and = ~0, status_or = 0;
@@ -778,6 +783,8 @@ retry:
 	if (!matched)
 	{
 	  CFRange range = CTRunGetStringRange (run);
+          DEBUG_MSG (CORETEXT, run, "Run used fallback font: %ld..%ld",
+		     range.location, range.location + range.length);
 	  if (!buffer->ensure_inplace (buffer->len + range.length))
 	    goto resize_and_retry;
 	  hb_glyph_info_t *info = buffer->info + buffer->len;
@@ -818,54 +825,73 @@ retry:
       if (!buffer->ensure (buffer->len + num_glyphs))
 	goto resize_and_retry;
 
+      hb_glyph_info_t *run_info = buffer->info + buffer->len;
+
       /* Testing used to indicate that CTRunGetGlyphsPtr, etc (almost?) always
        * succeed, and so copying data to our own buffer will be rare.  Reports
        * have it that this changed in OS X 10.10 Yosemite, and NULL is returned
        * frequently.  At any rate, we can test that codepath by setting USE_PTR
        * to false. */
 #define USE_PTR true
-
-      const CGGlyph* glyphs = USE_PTR ? CTRunGetGlyphsPtr (run) : NULL;
-      if (!glyphs) {
-	ALLOCATE_ARRAY (CGGlyph, glyph_buf, num_glyphs, goto resize_and_retry);
-	CTRunGetGlyphs (run, range_all, glyph_buf);
-	glyphs = glyph_buf;
-      }
-
-      const CGPoint* positions = USE_PTR ? CTRunGetPositionsPtr (run) : NULL;
-      if (!positions) {
-	ALLOCATE_ARRAY (CGPoint, position_buf, num_glyphs, goto resize_and_retry);
-	CTRunGetPositions (run, range_all, position_buf);
-	positions = position_buf;
+      {
+	const CGGlyph* glyphs = USE_PTR ? CTRunGetGlyphsPtr (run) : NULL;
+	if (!glyphs) {
+	  ALLOCATE_ARRAY (CGGlyph, glyph_buf, num_glyphs, goto resize_and_retry);
+	  CTRunGetGlyphs (run, range_all, glyph_buf);
+	  glyphs = glyph_buf;
+	}
+	const CFIndex* string_indices = USE_PTR ? CTRunGetStringIndicesPtr (run) : NULL;
+	if (!string_indices) {
+	  ALLOCATE_ARRAY (CFIndex, index_buf, num_glyphs, goto resize_and_retry);
+	  CTRunGetStringIndices (run, range_all, index_buf);
+	  string_indices = index_buf;
+	}
+	hb_glyph_info_t *info = run_info;
+	for (unsigned int j = 0; j < num_glyphs; j++)
+	{
+	  info->codepoint = glyphs[j];
+	  info->cluster = log_clusters[string_indices[j]];
+	  info++;
+	}
       }
-
-      const CFIndex* string_indices = USE_PTR ? CTRunGetStringIndicesPtr (run) : NULL;
-      if (!string_indices) {
-	ALLOCATE_ARRAY (CFIndex, index_buf, num_glyphs, goto resize_and_retry);
-	CTRunGetStringIndices (run, range_all, index_buf);
-	string_indices = index_buf;
+      {
+	const CGPoint* positions = USE_PTR ? CTRunGetPositionsPtr (run) : NULL;
+	if (!positions) {
+	  ALLOCATE_ARRAY (CGPoint, position_buf, num_glyphs, goto resize_and_retry);
+	  CTRunGetPositions (run, range_all, position_buf);
+	  positions = position_buf;
+	}
+	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;
+	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++;
+	  }
+	}
+	else
+	{
+	  run_advance = -run_advance;
+	  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++;
+	  }
+	}
       }
-
 #undef USE_PTR
 #undef ALLOCATE_ARRAY
 
-      double run_width = CTRunGetTypographicBounds (run, range_all, NULL, NULL, NULL);
-
-      for (unsigned int j = 0; j < num_glyphs; j++) {
-	double advance = (j + 1 < num_glyphs ? positions[j + 1].x : positions[0].x + run_width) - positions[j].x;
-
-	hb_glyph_info_t *info = &buffer->info[buffer->len];
-
-	info->codepoint = glyphs[j];
-	info->cluster = log_clusters[string_indices[j]];
-
-	/* Currently, we do all x-positioning by setting the advance, we never use x-offset. */
-	info->mask = advance;
-	info->var1.u32 = 0;
-	info->var2.u32 = positions[j].y;
-
-	buffer->len++;
-      }
+      buffer->len += num_glyphs;
     }
 
     /* Make sure all runs had the expected direction. */
@@ -876,15 +902,24 @@ retry:
     buffer->clear_positions ();
 
     unsigned int count = buffer->len;
-    for (unsigned int i = 0; i < count; ++i) {
-      hb_glyph_info_t *info = &buffer->info[i];
-      hb_glyph_position_t *pos = &buffer->pos[i];
-
-      /* TODO vertical */
-      pos->x_advance = info->mask;
-      pos->x_offset = info->var1.u32;
-      pos->y_offset = info->var2.u32;
-    }
+    hb_glyph_info_t *info = buffer->info;
+    hb_glyph_position_t *pos = buffer->pos;
+    if (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction))
+      for (unsigned int i = 0; i < count; i++)
+      {
+	pos->x_advance = info->mask;
+	pos->x_offset = info->var1.u32;
+	pos->y_offset = info->var2.u32;
+	info++, pos++;
+      }
+    else
+      for (unsigned int i = 0; i < count; i++)
+      {
+	pos->y_advance = info->mask;
+	pos->x_offset = info->var1.u32;
+	pos->y_offset = info->var2.u32;
+	info++, pos++;
+      }
 
     /* Fix up clusters so that we never return out-of-order indices;
      * if core text has reordered glyphs, we'll merge them to the
commit 1b55077f03758e49f93b8bc1de678e96ea58718c
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 11 20:45:12 2014 -0400

    [coretext] Remove unnecessary alt_size
    
    Wasn't needed after a6b8dc87421de33746b0b14d86d2d1532aec02af.

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 8caff48..ee6745b 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -650,6 +650,7 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
   if (0)
   {
 resize_and_retry:
+    DEBUG_MSG (CORETEXT, buffer, "Buffer resize");
     /* string_ref uses the scratch-buffer for backing store, and line references
      * string_ref (via attr_string).  We must release those before resizing buffer. */
     assert (string_ref);
@@ -814,8 +815,7 @@ retry:
       if (num_glyphs == 0)
 	continue;
 
-      unsigned int alt_size = (sizeof (CGGlyph) + sizeof (CGPoint) + sizeof (CFIndex)) / sizeof (hb_glyph_info_t) + 2;
-      if (!buffer->ensure (MAX (buffer->len + num_glyphs, alt_size)))
+      if (!buffer->ensure (buffer->len + num_glyphs))
 	goto resize_and_retry;
 
       /* Testing used to indicate that CTRunGetGlyphsPtr, etc (almost?) always
commit 10b1104d791a0b0103c6bbb083b5819f2b7d328d
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 11 20:02:45 2014 -0400

    [coretext] Use CFRunStatus
    
    Assert that all runs had expected direction, and take hint for
    non-monotone clusters.

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 8081bfc..8caff48 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -740,12 +740,17 @@ retry:
     unsigned int num_runs = CFArrayGetCount (glyph_runs);
 
     buffer->len = 0;
+    uint32_t status_and = ~0, status_or = 0;
 
     const CFRange range_all = CFRangeMake (0, 0);
 
     for (unsigned int i = 0; i < num_runs; i++)
     {
       CTRunRef run = static_cast<CTRunRef>(CFArrayGetValueAtIndex (glyph_runs, i));
+      CTRunStatus run_status = CTRunGetStatus (run);
+      status_or  |= run_status;
+      status_and &= run_status;
+      DEBUG_MSG (CORETEXT, run, "CTRunStatus: %x", run_status);
 
       /* CoreText does automatic font fallback (AKA "cascading") for  characters
        * not supported by the requested font, and provides no way to turn it off,
@@ -863,6 +868,11 @@ retry:
       }
     }
 
+    /* Make sure all runs had the expected direction. */
+    bool backward = HB_DIRECTION_IS_BACKWARD (buffer->props.direction);
+    assert (bool (status_and & kCTRunStatusRightToLeft) == backward);
+    assert (bool (status_or  & kCTRunStatusRightToLeft) == backward);
+
     buffer->clear_positions ();
 
     unsigned int count = buffer->len;
@@ -878,12 +888,15 @@ retry:
 
     /* Fix up clusters so that we never return out-of-order indices;
      * if core text has reordered glyphs, we'll merge them to the
-     * beginning of the reordered cluster.
+     * beginning of the reordered cluster.  CoreText is nice enough
+     * to tell us whenever it has produced nonmonotonic results...
+     * Note that we assume the input clusters were nonmonotonic to
+     * begin with.
      *
      * This does *not* mean we'll form the same clusters as Uniscribe
      * or the native OT backend, only that the cluster indices will be
      * monotonic in the output buffer. */
-    if (count > 1)
+    if (count > 1 && (status_or & kCTRunStatusNonMonotonic))
     {
       hb_glyph_info_t *info = buffer->info;
       if (HB_DIRECTION_IS_FORWARD (buffer->props.direction))
commit fd1a6aa8d029c701b1532efa59ce901109cfc216
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 11 20:01:37 2014 -0400

    [coretext] Minor

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index 6aab1d8..8081bfc 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -678,7 +678,8 @@ retry:
 
     /* Create an attributed string, populate it, and create a line from it, then release attributed string. */
     {
-      CFMutableAttributedStringRef attr_string = CFAttributedStringCreateMutable (NULL, chars_len);
+      CFMutableAttributedStringRef attr_string = CFAttributedStringCreateMutable (kCFAllocatorDefault,
+										  chars_len);
       if (unlikely (!attr_string))
 	FAIL ("CFAttributedStringCreateMutable failed");
       CFAttributedStringReplaceString (attr_string, CFRangeMake (0, 0), string_ref);
commit 130856c705641aa681307b5b51b5fb84e295f382
Author: Behdad Esfahbod <behdad at behdad.org>
Date:   Mon Aug 11 19:16:26 2014 -0400

    [coretext] Remove debug printf!

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index f4fa744..6aab1d8 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -650,7 +650,6 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
   if (0)
   {
 resize_and_retry:
-   printf ("HERE");
     /* string_ref uses the scratch-buffer for backing store, and line references
      * string_ref (via attr_string).  We must release those before resizing buffer. */
     assert (string_ref);


More information about the HarfBuzz mailing list