From 4acce77db7dd588ba277779c4997b0256ebe426e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 11 Aug 2014 17:46:50 -0400 Subject: [PATCH] [coretext] Pass buffer direction to CoreText Have to use a CTTypesetter for this. --- src/hb-coretext.cc | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/hb-coretext.cc b/src/hb-coretext.cc index 309e6214b..f4fa74447 100644 --- a/src/hb-coretext.cc +++ b/src/hb-coretext.cc @@ -713,12 +713,28 @@ retry: kCTFontAttributeName, last_range->font); } - line = CTLineCreateWithAttributedString (attr_string); - CFRelease (attr_string); - } + int level = HB_DIRECTION_IS_FORWARD (buffer->props.direction) ? 0 : 1; + CFNumberRef level_number = CFNumberCreate (kCFAllocatorDefault, kCFNumberIntType, &level); + CFDictionaryRef options = CFDictionaryCreate (kCFAllocatorDefault, + (const void **) &kCTTypesetterOptionForcedEmbeddingLevel, + (const void **) &level_number, + 1, + &kCFTypeDictionaryKeyCallBacks, + &kCFTypeDictionaryValueCallBacks); + if (unlikely (!options)) + FAIL ("CFDictionaryCreate failed"); - if (unlikely (!line)) - FAIL ("CFLineCreateWithAttributedString failed"); + CTTypesetterRef typesetter = CTTypesetterCreateWithAttributedStringAndOptions (attr_string, options); + CFRelease (options); + CFRelease (attr_string); + if (unlikely (!typesetter)) + FAIL ("CTTypesetterCreateWithAttributedStringAndOptions failed"); + + line = CTTypesetterCreateLine (typesetter, CFRangeMake(0, 0)); + CFRelease (typesetter); + if (unlikely (!line)) + FAIL ("CTTypesetterCreateLine failed"); + } CFArrayRef glyph_runs = CTLineGetGlyphRuns (line); unsigned int num_runs = CFArrayGetCount (glyph_runs); @@ -891,6 +907,8 @@ retry: } } +#undef FAIL + fail: if (string_ref) CFRelease (string_ref);