|
Lines 264-270
static Optional<NSFont*> fontWithFamilySpecialCase(const AtomicString& family, F
a/Source/WebCore/platform/graphics/mac/FontCacheMac.mm_sec1
|
| 264 |
// Family name is somewhat of a misnomer here. We first attempt to find an exact match |
264 |
// Family name is somewhat of a misnomer here. We first attempt to find an exact match |
| 265 |
// comparing the desiredFamily to the PostScript name of the installed fonts. If that fails |
265 |
// comparing the desiredFamily to the PostScript name of the installed fonts. If that fails |
| 266 |
// we then do a search based on the family names of the installed fonts. |
266 |
// we then do a search based on the family names of the installed fonts. |
| 267 |
static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, float size) |
267 |
static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, const FontFeatureSettings* features, float size) |
| 268 |
{ |
268 |
{ |
| 269 |
if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, desiredTraits, size)) |
269 |
if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, desiredTraits, size)) |
| 270 |
return specialCase.value(); |
270 |
return specialCase.value(); |
|
Lines 286-292
static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desire
a/Source/WebCore/platform/graphics/mac/FontCacheMac.mm_sec2
|
| 286 |
requestedTraits |= kCTFontBoldTrait; |
286 |
requestedTraits |= kCTFontBoldTrait; |
| 287 |
|
287 |
|
| 288 |
NSString *desiredFamily = family; |
288 |
NSString *desiredFamily = family; |
| 289 |
font = CFBridgingRelease(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size)); |
289 |
RetainPtr<CTFontRef> foundFont = adoptCF(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size)); |
|
|
290 |
if (foundFont && features && features->size()) { |
| 291 |
RetainPtr<CFMutableArrayRef> featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features->size(), &kCFTypeArrayCallBacks)); |
| 292 |
CFStringRef featureDictionaryKeys[] = {kCTFontOpenTypeFeatureTag, kCTFontOpenTypeFeatureValue}; |
| 293 |
for (size_t i = 0; i < features->size(); ++i) { |
| 294 |
const auto& feature = (*features)[i]; |
| 295 |
RetainPtr<CFStringRef> featureKey = feature.tag().string().createCFString(); |
| 296 |
int rawFeatureValue = feature.value(); |
| 297 |
RetainPtr<CFNumberRef> featureValue = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &rawFeatureValue)); |
| 298 |
CFTypeRef featureDictionaryValues[] = {featureKey.get(), featureValue.get()}; |
| 299 |
RetainPtr<CFDictionaryRef> featureDictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, (const void**)featureDictionaryKeys, featureDictionaryValues, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); |
| 300 |
CFArrayAppendValue(featureArray.get(), featureDictionary.get()); |
| 301 |
} |
| 302 |
CFArrayRef featureArrayPtr = featureArray.get(); |
| 303 |
RetainPtr<CFDictionaryRef> dictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, (const void**)&kCTFontFeatureSettingsAttribute, (const void**)&featureArrayPtr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); |
| 304 |
RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(dictionary.get())); |
| 305 |
foundFont = adoptCF(CTFontCreateCopyWithAttributes(foundFont.get(), size, nullptr, descriptor.get())); |
| 306 |
} |
| 307 |
font = CFBridgingRelease(CFRetain(foundFont.get())); |
| 290 |
availableFamily = [font familyName]; |
308 |
availableFamily = [font familyName]; |
| 291 |
chosenWeight = [fontManager weightOfFont:font]; |
309 |
chosenWeight = [fontManager weightOfFont:font]; |
| 292 |
|
310 |
|
|
Lines 664-670
std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
a/Source/WebCore/platform/graphics/mac/FontCacheMac.mm_sec3
|
| 664 |
NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0; |
682 |
NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0; |
| 665 |
float size = fontDescription.computedPixelSize(); |
683 |
float size = fontDescription.computedPixelSize(); |
| 666 |
|
684 |
|
| 667 |
NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), size); |
685 |
NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size); |
| 668 |
if (!nsFont) { |
686 |
if (!nsFont) { |
| 669 |
if (!shouldAutoActivateFontIfNeeded(family)) |
687 |
if (!shouldAutoActivateFontIfNeeded(family)) |
| 670 |
return nullptr; |
688 |
return nullptr; |
|
Lines 673-679
std::unique_ptr<FontPlatformData> FontCache::createFontPlatformData(const FontDe
a/Source/WebCore/platform/graphics/mac/FontCacheMac.mm_sec4
|
| 673 |
// Ignore the result because we want to use our own algorithm to actually find the font. |
691 |
// Ignore the result because we want to use our own algorithm to actually find the font. |
| 674 |
[NSFont fontWithName:family size:size]; |
692 |
[NSFont fontWithName:family size:size]; |
| 675 |
|
693 |
|
| 676 |
nsFont = fontWithFamily(family, traits, fontDescription.weight(), size); |
694 |
nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size); |
| 677 |
if (!nsFont) |
695 |
if (!nsFont) |
| 678 |
return nullptr; |
696 |
return nullptr; |
| 679 |
} |
697 |
} |