@@ -146,6 +146,26 @@ static void dump(CFDictionaryRef d) {
146146 }
147147}
148148
149+ static CTFontRef create_ctfont_from_font (const SkFont& font) {
150+ auto typeface = font.getTypefaceOrDefault ();
151+ auto ctfont = SkTypeface_GetCTFontRef (typeface);
152+ return CTFontCreateCopyWithAttributes (ctfont, font.getSize (), nullptr , nullptr );
153+ }
154+
155+ static SkFont run_to_font (CTRunRef run, const SkFont& orig) {
156+ CFDictionaryRef attr = CTRunGetAttributes (run);
157+ CTFontRef ct = (CTFontRef)CFDictionaryGetValue (attr, kCTFontAttributeName );
158+ if (!ct) {
159+ SkDebugf (" no ctfont in Run Attributes\n " );
160+ dump (attr);
161+ return orig;
162+ }
163+ // Do I need to add a local cache, or allow the caller to manage this lookup?
164+ SkFont font (orig);
165+ font.setTypeface (SkMakeTypefaceFromCTFont (ct));
166+ return font;
167+ }
168+
149169// kCTTrackingAttributeName not available until 10.12
150170const CFStringRef kCTTracking_AttributeName = CFSTR(" CTTracking" );
151171
@@ -167,16 +187,13 @@ void SkShaper_CoreText::shape(const char* utf8, size_t utf8Bytes,
167187 AutoCF<CFStringRef> textString = CFStringCreateWithBytes (nullptr , (const uint8_t *)utf8, utf8Bytes,
168188 kCFStringEncodingUTF8 , false );
169189
170- auto typeface = font.getTypefaceOrDefault ();
171- auto ctfont = SkTypeface_GetCTFontRef (typeface);
172- AutoCF<CTFontRef> ctfont2 = CTFontCreateCopyWithAttributes (ctfont, font.getSize (),
173- nullptr , nullptr );
190+ AutoCF<CTFontRef> ctfont = create_ctfont_from_font (font);
174191
175192 AutoCF<CFMutableDictionaryRef> attr =
176193 CFDictionaryCreateMutable (kCFAllocatorDefault , 0 ,
177194 &kCFTypeDictionaryKeyCallBacks ,
178195 &kCFTypeDictionaryValueCallBacks );
179- CFDictionaryAddValue (attr.get (), kCTFontAttributeName , ctfont2 .get ());
196+ CFDictionaryAddValue (attr.get (), kCTFontAttributeName , ctfont .get ());
180197 if (false ) {
181198 // trying to see what these affect
182199 dict_add_double (attr.get (), kCTTracking_AttributeName , 1 );
@@ -207,10 +224,6 @@ void SkShaper_CoreText::shape(const char* utf8, size_t utf8Bytes,
207224 for (CFIndex j = 0 ; j < runCount; ++j) {
208225 CTRunRef run = (CTRunRef)CFArrayGetValueAtIndex (run_array, j);
209226 CFIndex runGlyphs = CTRunGetGlyphCount (run);
210- CFDictionaryRef runAttr = CTRunGetAttributes (run);
211- if (false ) {
212- dump (runAttr);
213- }
214227
215228 SkASSERT (sizeof (CGGlyph) == sizeof (uint16_t ));
216229
@@ -224,8 +237,9 @@ void SkShaper_CoreText::shape(const char* utf8, size_t utf8Bytes,
224237
225238 CFRange range = CTRunGetStringRange (run);
226239
240+ SkFont run_font = run_to_font (run, font);
227241 infos.push_back ({
228- font, // need resolved font
242+ run_font,
229243 0 , // need fBidiLevel
230244 {adv, 0 },
231245 (size_t )runGlyphs,
0 commit comments