Imported Upstream version 0.9.12
[platform/upstream/harfbuzz.git] / src / hb-coretext.cc
index 4152a39..8f94795 100644 (file)
 #define HB_SHAPER coretext
 #include "hb-shaper-impl-private.hh"
 
-#define GlyphID GlyphID_mac
-#include <ApplicationServices/ApplicationServices.h>
-#undef GlyphID
-
 #include "hb-coretext.h"
 
 
@@ -95,6 +91,14 @@ _hb_coretext_shaper_face_data_destroy (hb_coretext_shaper_face_data_t *data)
   free (data);
 }
 
+CGFontRef
+hb_coretext_face_get_cg_font (hb_face_t *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->cg_font;
+}
+
 
 /*
  * shaper font data
@@ -153,19 +157,19 @@ _hb_coretext_shaper_shape_plan_data_destroy (hb_coretext_shaper_shape_plan_data_
 {
 }
 
-
-/*
- * shaper
- */
-
 CTFontRef
 hb_coretext_font_get_ct_font (hb_font_t *font)
 {
-  if (unlikely (!hb_coretext_shaper_font_data_ensure (font))) return 0;
+  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;
 }
 
+
+/*
+ * shaper
+ */
+
 hb_bool_t
 _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
                    hb_font_t          *font,
@@ -212,26 +216,22 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
   CFDictionaryRef attrs = CFDictionaryCreate (kCFAllocatorDefault,
                                               (const void**) &kCTFontAttributeName,
                                               (const void**) &font_data->ct_font,
-                                              1, // count of attributes
+                                              1, /* count of attributes */
                                               &kCFTypeDictionaryKeyCallBacks,
                                               &kCFTypeDictionaryValueCallBacks);
 
-  // TODO: support features
+  /* TODO: support features */
 
-  // Now we can create an attributed string
   CFAttributedStringRef attr_string = CFAttributedStringCreate (kCFAllocatorDefault, string_ref, attrs);
   CFRelease (string_ref);
   CFRelease (attrs);
 
-  // Create the CoreText line from our string, then we're done with it
   CTLineRef line = CTLineCreateWithAttributedString (attr_string);
   CFRelease (attr_string);
 
-  // and finally retrieve the glyph data and store into the gfxTextRun
   CFArrayRef glyph_runs = CTLineGetGlyphRuns (line);
   unsigned int num_runs = CFArrayGetCount (glyph_runs);
 
-  // Iterate through the glyph runs.
   bool success = true;
   buffer->len = 0;
 
@@ -246,11 +246,9 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
 
     buffer->ensure (buffer->len + num_glyphs);
 
-    // retrieve the laid-out glyph data from the CTRun
-
-    // Testing indicates that CTRunGetGlyphsPtr (almost?) always succeeds,
-    // and so copying data to our own buffer with CTRunGetGlyphs will be
-    // extremely rare.
+    /* Testing indicates that CTRunGetGlyphsPtr (almost?) always succeeds,
+     * and so copying data to our own buffer with CTRunGetGlyphs will be
+     * extremely rare. */
 
     unsigned int scratch_size;
     char *scratch = (char *) buffer->get_scratch_buffer (&scratch_size);
@@ -294,7 +292,7 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
       info->codepoint = glyphs[j];
       info->cluster = string_indices[j];
 
-      // currently, we do all x-positioning by setting the advance, we never use x-offset
+      /* 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;
@@ -316,12 +314,13 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
     pos->y_offset = info->var2.u32;
   }
 
-  // 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.
-  // This does *not* mean we'll form the same clusters as Uniscribe
-  // or the native OT backend, only that the cluster indices will be
-  // non-decreasing in the output buffer.
+  /* 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.
+   *
+   * 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 (HB_DIRECTION_IS_FORWARD (buffer->props.direction)) {
     unsigned int prev_cluster = 0;
     for (unsigned int i = 0; i < count; i++) {
@@ -337,7 +336,6 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
       prev_cluster = curr_cluster;
     }
   } else {
-    // For RTL runs, we make them non-increasing instead.
     unsigned int prev_cluster = (unsigned int)-1;
     for (unsigned int i = 0; i < count; i++) {
       unsigned int curr_cluster = buffer->info[i].cluster;