We should compare the CGFont's then. Updated patch attached.

Regards,
Khaled

On Fri, Nov 29, 2013 at 03:13:19PM -0500, Behdad Esfahbod wrote:
> Your patch doesn't work with user features.  For each user feature we use a
> sub-font of ct_font:
> 
>   range->font = CTFontCreateCopyWithAttributes (font_data->ct_font, 0.0, NULL,
> font_desc);
> 
> 
> On 13-11-25 08:42 AM, Khaled Hosny wrote:
> > Resending a patch that actually applies!
> > 
> > 
> > 
> > _______________________________________________
> > HarfBuzz mailing list
> > [email protected]
> > http://lists.freedesktop.org/mailman/listinfo/harfbuzz
> > 
> 
> -- 
> behdad
> http://behdad.org/
>From 2dff34041c42608d8a50b7afe0d04e0132d75857 Mon Sep 17 00:00:00 2001
From: Khaled Hosny <[email protected]>
Date: Mon, 25 Nov 2013 15:28:10 +0200
Subject: [PATCH] Avoid font fallback with CoreText shaper

CoreText does automatic font fallback (AKA "cascading") for  characters
not supported by the requested font, and provides no way to turn it off,
so detect if the returned run uses a font other than the requested one
and fill in the buffer with .notdef glyphs instead of random indices
glyph from a different font.
---
 src/hb-coretext.cc | 29 +++++++++++++++++++++++++++++
 1 file changed, 29 insertions(+)

diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc
index ba80136..a0633ee 100644
--- a/src/hb-coretext.cc
+++ b/src/hb-coretext.cc
@@ -685,6 +685,35 @@ _hb_coretext_shape (hb_shape_plan_t    *shape_plan,
 
 #undef ALLOCATE_ARRAY
 
+    /* CoreText does automatic font fallback (AKA "cascading") for  characters
+     * not supported by the requested font, and provides no way to turn it off,
+     * so we detect if the returned run uses a font other than the requested
+     * one and fill in the buffer with .notdef glyphs instead of random glyph
+     * indices from a different font.
+     */
+    CFDictionaryRef attributes = CTRunGetAttributes (run);
+    CTFontRef run_ct_font = static_cast<CTFontRef>(CFDictionaryGetValue (attributes, kCTFontAttributeName));
+    CGFontRef run_cg_font = CTFontCopyGraphicsFont (run_ct_font, 0);
+    CGFontRef cg_font = CTFontCopyGraphicsFont (font_data->ct_font, 0);
+    if (!CFEqual (run_cg_font, cg_font)) {
+        for (unsigned int j = 0; j < num_glyphs; j++) {
+            CGGlyph notdef = 0;
+            double advance = CTFontGetAdvancesForGlyphs (font_data->ct_font, kCTFontHorizontalOrientation, &notdef, NULL, 1);
+
+            hb_glyph_info_t *info = &buffer->info[buffer->len];
+
+            info->codepoint = notdef;
+            info->cluster = string_indices[0] + j;
+
+            info->mask = advance;
+            info->var1.u32 = 0;
+            info->var2.u32 = 0;
+
+            buffer->len++;
+        }
+        continue;
+    }
+
     double run_width = CTRunGetTypographicBounds (run, range_all, NULL, NULL, NULL);
 
     for (unsigned int j = 0; j < num_glyphs; j++) {
-- 
1.8.4.1

_______________________________________________
HarfBuzz mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/harfbuzz

Reply via email to