Changeset 188591 in webkit
- Timestamp:
- Aug 18, 2015 12:19:49 PM (9 years ago)
- Location:
- trunk
- Files:
-
- 3 added
- 14 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r188590 r188591 1 2015-08-18 Myles C. Maxfield <mmaxfield@apple.com> 2 3 [Cocoa] Honor the 'trak' table by opting in via text-rendering: optimizeLegibility 4 https://bugs.webkit.org/show_bug.cgi?id=148119 5 <rdar://problem/22291561> 6 7 Reviewed by Tim Horton. 8 9 This test will fail until we stop mocking the system font on El Capitan. Until then, 10 this patch will commit the test failure as an expected result. 11 12 * fast/text/trak-optimizeLegibility-expected.html: Added 13 * fast/text/trak-optimizeLegibility.html: Added 14 1 15 2015-08-18 Chris Dumez <cdumez@apple.com> 2 16 -
trunk/LayoutTests/platform/mac/TestExpectations
r188515 r188591 1297 1297 # Started to fail after r188390 1298 1298 webkit.org/b/148042 http/tests/media/video-buffered-range-contains-currentTime.html [ Pass Failure ] 1299 1300 # This test tests a particular system font, which is only on iOS and El Capitan. 1301 webkit.org/b/148119 [ Mavericks Yosemite ] fast/text/trak-optimizeLegibility.html [ Failure ] -
trunk/Source/WebCore/ChangeLog
r188590 r188591 1 2015-08-18 Myles C. Maxfield <mmaxfield@apple.com> 2 3 [Cocoa] Honor the 'trak' table by opting in via text-rendering: optimizeLegibility 4 https://bugs.webkit.org/show_bug.cgi?id=148119 5 <rdar://problem/22291561> 6 7 Reviewed by Tim Horton. 8 9 When the author has opted in by specifying "text-rendering: optimizeLegibility;", we should 10 honor the font's 'trak' table. We do this by specifying kCTFontOpticalSizeAttribute at font 11 creation time, and by using CTFontGetAdvancesForGlyphs() instead of 12 CGFontGetGlyphAdvancesForStyle(). 13 14 Test: fast/text/trak-optimizeLegibility.html 15 16 * platform/graphics/FontCache.h: 17 (WebCore::FontDescriptionKey::makeFlagKey): Make our caches sensitive to TextRenderingMode. 18 * platform/graphics/FontPlatformData.cpp: 19 (WebCore::FontPlatformData::FontPlatformData): Add a TextRenderingMode member variable. 20 (WebCore::FontPlatformData::operator=): Update to consult with the new member. 21 * platform/graphics/FontPlatformData.h: 22 (WebCore::FontPlatformData::textRenderingMode): Getter. 23 * platform/graphics/cocoa/FontCacheCoreText.cpp: 24 (WebCore::preparePlatformFont): Specify kCTFontOpticalSizeAttribute. 25 (WebCore::applyFontFeatureSettings): Deleted. 26 * platform/graphics/cocoa/FontCocoa.mm: 27 (WebCore::canUseFastGlyphAdvanceGetter): Use CTFontGetAdvancesForGlyphs() if we are 28 optimizeLegibility. 29 * platform/graphics/cocoa/FontPlatformDataCocoa.mm: 30 (WebCore::FontPlatformData::FontPlatformData): Pass the TextRenderingMode around. 31 * platform/graphics/ios/FontCacheIOS.mm: 32 (WebCore::FontCache::getSystemFontFallbackForCharacters): Update to call renamed function. 33 (WebCore::FontCache::createFontPlatformData): Ditto. 34 * platform/graphics/mac/FontCacheMac.mm: 35 (WebCore::fontWithFamily): Ditto. 36 (WebCore::FontCache::systemFallbackForCharacters): Ditto. 37 (WebCore::FontCache::createFontPlatformData): Ditto. 38 * platform/graphics/mac/FontCustomPlatformData.cpp: 39 (WebCore::FontCustomPlatformData::fontPlatformData): Ditto. 40 * platform/spi/cocoa/CoreTextSPI.h: 41 * rendering/RenderThemeIOS.mm: 42 (WebCore::RenderThemeIOS::updateCachedSystemFontDescription): Ditto. 43 1 44 2015-08-18 Chris Dumez <cdumez@apple.com> 2 45 -
trunk/Source/WebCore/platform/graphics/FontCache.h
r188168 r188591 106 106 { 107 107 static_assert(USCRIPT_CODE_LIMIT < 0x1000, "Script code must fit in an unsigned along with the other flags"); 108 return static_cast<unsigned>(description.script()) << 9 108 return static_cast<unsigned>(description.script()) << 11 109 | static_cast<unsigned>(description.textRenderingMode()) << 9 109 110 | static_cast<unsigned>(description.smallCaps()) << 8 110 111 | static_cast<unsigned>(description.fontSynthesis()) << 6 … … 216 217 217 218 #if PLATFORM(COCOA) 218 RetainPtr<CTFontRef> applyFontFeatureSettings(CTFontRef, const FontFeatureSettings*);219 RetainPtr<CTFontRef> preparePlatformFont(CTFontRef, TextRenderingMode, const FontFeatureSettings*); 219 220 #endif 220 221 -
trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp
r188566 r188591 44 44 } 45 45 46 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant )46 FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode) 47 47 : m_syntheticBold(syntheticBold) 48 48 , m_syntheticOblique(syntheticOblique) … … 50 50 , m_size(size) 51 51 , m_widthVariant(widthVariant) 52 , m_textRenderingMode(textRenderingMode) 52 53 { 53 54 } 54 55 55 56 #if USE(CG) 56 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant )57 : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant )57 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode) 58 : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode) 58 59 { 59 60 m_cgFont = cgFont; … … 62 63 63 64 FontPlatformData::FontPlatformData(const FontPlatformData& source) 64 : FontPlatformData(source.m_size, source.m_syntheticBold, source.m_syntheticOblique, source.m_orientation, source.m_widthVariant )65 : FontPlatformData(source.m_size, source.m_syntheticBold, source.m_syntheticOblique, source.m_orientation, source.m_widthVariant, source.m_textRenderingMode) 65 66 { 66 67 m_isHashTableDeletedValue = source.m_isHashTableDeletedValue; … … 82 83 m_widthVariant = other.m_widthVariant; 83 84 m_isColorBitmapFont = other.m_isColorBitmapFont; 85 m_textRenderingMode = other.m_textRenderingMode; 84 86 85 87 return platformDataAssign(other); -
trunk/Source/WebCore/platform/graphics/FontPlatformData.h
r188575 r188591 82 82 FontPlatformData(const FontPlatformData&); 83 83 FontPlatformData(const FontDescription&, const AtomicString& family); 84 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth );85 86 #if PLATFORM(COCOA) 87 WEBCORE_EXPORT FontPlatformData(CTFontRef, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, FontWidthVariant = RegularWidth );88 #endif 89 90 #if USE(CG) 91 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant );84 FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, TextRenderingMode = AutoTextRendering); 85 86 #if PLATFORM(COCOA) 87 WEBCORE_EXPORT FontPlatformData(CTFontRef, float size, bool syntheticBold = false, bool syntheticOblique = false, FontOrientation = Horizontal, FontWidthVariant = RegularWidth, TextRenderingMode = AutoTextRendering); 88 #endif 89 90 #if USE(CG) 91 FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant, TextRenderingMode); 92 92 #endif 93 93 … … 137 137 FontOrientation orientation() const { return m_orientation; } 138 138 FontWidthVariant widthVariant() const { return m_widthVariant; } 139 TextRenderingMode textRenderingMode() const { return m_textRenderingMode; } 139 140 bool isForTextCombine() const { return widthVariant() != RegularWidth; } // Keep in sync with callers of FontDescription::setWidthVariant(). 140 141 … … 152 153 #elif OS(DARWIN) 153 154 ASSERT(m_font || !m_cgFont || isEmoji()); 154 uintptr_t flags = static_cast<uintptr_t>(m_isHashTableDeletedValue << 4 | isEmoji() << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique);155 uintptr_t flags = static_cast<uintptr_t>(m_isHashTableDeletedValue << 6 | m_textRenderingMode << 4 | isEmoji() << 3 | m_orientation << 2 | m_syntheticBold << 1 | m_syntheticOblique); 155 156 #if USE(APPKIT) 156 157 uintptr_t fontHash = (uintptr_t)m_font.get(); … … 176 177 && m_isColorBitmapFont == other.m_isColorBitmapFont 177 178 && m_orientation == other.m_orientation 178 && m_widthVariant == other.m_widthVariant; 179 && m_widthVariant == other.m_widthVariant 180 && m_textRenderingMode == other.m_textRenderingMode; 179 181 } 180 182 … … 217 219 float m_size { 0 }; 218 220 FontWidthVariant m_widthVariant { RegularWidth }; 221 TextRenderingMode m_textRenderingMode { AutoTextRendering }; 219 222 220 223 private: -
trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
r188319 r188591 27 27 #include "FontCache.h" 28 28 29 #include "CoreTextSPI.h" 29 30 #include <CoreText/SFNTLayoutTypes.h> 30 31 … … 138 139 } 139 140 140 RetainPtr<CTFontRef> applyFontFeatureSettings(CTFontRef originalFont, const FontFeatureSettings* features)141 RetainPtr<CTFontRef> preparePlatformFont(CTFontRef originalFont, TextRenderingMode textRenderingMode, const FontFeatureSettings* features) 141 142 { 142 if (!originalFont || !features || !features->size())143 if (!originalFont || ((!features || !features->size()) && (textRenderingMode != OptimizeLegibility))) 143 144 return originalFont; 144 145 145 RetainPtr<CFMutableArrayRef> featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features->size(), &kCFTypeArrayCallBacks)); 146 for (size_t i = 0; i < features->size(); ++i) { 147 appendTrueTypeFeature(featureArray.get(), features->at(i)); 148 appendOpenTypeFeature(featureArray.get(), features->at(i)); 146 RetainPtr<CFMutableDictionaryRef> attributes = adoptCF(CFDictionaryCreateMutable(kCFAllocatorDefault, 2, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 147 if (features && features->size()) { 148 RetainPtr<CFMutableArrayRef> featureArray = adoptCF(CFArrayCreateMutable(kCFAllocatorDefault, features->size(), &kCFTypeArrayCallBacks)); 149 for (size_t i = 0; i < features->size(); ++i) { 150 appendTrueTypeFeature(featureArray.get(), features->at(i)); 151 appendOpenTypeFeature(featureArray.get(), features->at(i)); 152 } 153 CFDictionaryAddValue(attributes.get(), kCTFontFeatureSettingsAttribute, featureArray.get()); 149 154 } 150 CFArrayRef featureArrayPtr = featureArray.get(); 151 RetainPtr<CFDictionaryRef> dictionary = adoptCF(CFDictionaryCreate(kCFAllocatorDefault, (const void**)&kCTFontFeatureSettingsAttribute, (const void**)&featureArrayPtr, 1, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks)); 152 RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(dictionary.get())); 155 if (textRenderingMode == OptimizeLegibility) { 156 CGFloat size = CTFontGetSize(originalFont); 157 RetainPtr<CFNumberRef> sizeNumber = adoptCF(CFNumberCreate(kCFAllocatorDefault, kCFNumberCGFloatType, &size)); 158 CFDictionaryAddValue(attributes.get(), kCTFontOpticalSizeAttribute, sizeNumber.get()); 159 } 160 RetainPtr<CTFontDescriptorRef> descriptor = adoptCF(CTFontDescriptorCreateWithAttributes(attributes.get())); 153 161 return adoptCF(CTFontCreateCopyWithAttributes(originalFont, CTFontGetSize(originalFont), nullptr, descriptor.get())); 154 162 } -
trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
r188575 r188591 458 458 { 459 459 const FontPlatformData& platformData = font.platformData(); 460 // Fast getter doesn't take custom tracking into account461 if (font.hasCustomTracking() )460 // Fast getter doesn't doesn't work for emoji, bitmap fonts, or take custom tracking into account 461 if (font.hasCustomTracking() || platformData.isEmoji() || platformData.textRenderingMode() == OptimizeLegibility) 462 462 return false; 463 // Fast getter doesn't work for emoji464 if (platformData.isEmoji())465 return false;466 // ... or for any bitmap fonts in general467 463 if (advanceForColorBitmapFont(platformData, glyph, advance)) { 468 464 populatedAdvance = true; -
trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm
r188566 r188591 42 42 enum TextSpacingCTFeatureSelector { TextSpacingProportional, TextSpacingFullWidth, TextSpacingHalfWidth, TextSpacingThirdWidth, TextSpacingQuarterWidth }; 43 43 44 FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant )45 : FontPlatformData(adoptCF(CTFontCopyGraphicsFont(font, NULL)).get(), size, syntheticBold, syntheticOblique, orientation, widthVariant )44 FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode) 45 : FontPlatformData(adoptCF(CTFontCopyGraphicsFont(font, NULL)).get(), size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode) 46 46 { 47 47 ASSERT_ARG(font, font); -
trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm
r188227 r188591 93 93 return nullptr; 94 94 95 substituteFont = applyFontFeatureSettings(substituteFont.get(), description.featureSettings());95 substituteFont = preparePlatformFont(substituteFont.get(), description.textRenderingMode(), description.featureSettings()); 96 96 97 97 CTFontSymbolicTraits originalTraits = CTFontGetSymbolicTraits(ctFont); … … 719 719 return nullptr; 720 720 721 ctFont = applyFontFeatureSettings(ctFont.get(), fontDescription.featureSettings());721 ctFont = preparePlatformFont(ctFont.get(), fontDescription.textRenderingMode(), fontDescription.featureSettings()); 722 722 723 723 CTFontSymbolicTraits actualTraits = 0; … … 730 730 bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & kCTFontTraitItalic) && !(actualTraits & kCTFontTraitItalic) && !isAppleColorEmoji; 731 731 732 auto result = std::make_unique<FontPlatformData>(ctFont.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant() );732 auto result = std::make_unique<FontPlatformData>(ctFont.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode()); 733 733 if (isAppleColorEmoji) 734 734 result->setIsEmoji(true); -
trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm
r188575 r188591 265 265 // comparing the desiredFamily to the PostScript name of the installed fonts. If that fails 266 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, const FontFeatureSettings* featureSettings, float size)267 static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, const FontFeatureSettings* featureSettings, TextRenderingMode textRenderingMode, float size) 268 268 { 269 269 if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, desiredTraits, size)) … … 288 288 NSString *desiredFamily = family; 289 289 RetainPtr<CTFontRef> foundFont = adoptCF(CTFontCreateForCSS((CFStringRef)desiredFamily, toCoreTextFontWeight(weight), requestedTraits, size)); 290 foundFont = applyFontFeatureSettings(foundFont.get(), featureSettings);290 foundFont = preparePlatformFont(foundFont.get(), textRenderingMode, featureSettings); 291 291 if (!foundFont) 292 292 return nil; … … 298 298 299 299 UNUSED_PARAM(featureSettings); 300 UNUSED_PARAM(textRenderingMode); 300 301 301 302 NSFontTraitMask desiredTraitsForNameMatch = desiredTraits | (weight >= FontWeight600 ? NSBoldFontMask : 0); … … 521 522 NSFont *nsFont = platformData.nsFont(); 522 523 RetainPtr<CTFontRef> result = lookupCTFont(platformData.font(), platformData.size(), description.locale(), characters, length); 523 result = applyFontFeatureSettings(result.get(), description.featureSettings());524 result = preparePlatformFont(result.get(), description.textRenderingMode(), description.featureSettings()); 524 525 if (!result) 525 526 return nullptr; … … 680 681 float size = fontDescription.computedPixelSize(); 681 682 682 NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size);683 NSFont *nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), fontDescription.textRenderingMode(), size); 683 684 if (!nsFont) { 684 685 if (!shouldAutoActivateFontIfNeeded(family)) … … 689 690 [NSFont fontWithName:family size:size]; 690 691 691 nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), size);692 nsFont = fontWithFamily(family, traits, fontDescription.weight(), fontDescription.featureSettings(), fontDescription.textRenderingMode(), size); 692 693 if (!nsFont) 693 694 return nullptr; … … 704 705 bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait); 705 706 706 return std::make_unique<FontPlatformData>(toCTFont(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant() );707 return std::make_unique<FontPlatformData>(toCTFont(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode()); 707 708 } 708 709 -
trunk/Source/WebCore/platform/graphics/mac/FontCustomPlatformData.cpp
r188168 r188591 42 42 #if CORETEXT_WEB_FONTS 43 43 RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr)); 44 font = applyFontFeatureSettings(font.get(), fontDescription.featureSettings());45 return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant );44 font = preparePlatformFont(font.get(), fontDescription.textRenderingMode(), fontDescription.featureSettings()); 45 return FontPlatformData(font.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode()); 46 46 #else 47 return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant );47 return FontPlatformData(m_cgFont.get(), size, bold, italic, orientation, widthVariant, fontDescription.textRenderingMode()); 48 48 #endif 49 49 } -
trunk/Source/WebCore/platform/spi/cocoa/CoreTextSPI.h
r188559 r188591 50 50 51 51 extern const CFStringRef kCTFontReferenceURLAttribute; 52 extern const CFStringRef kCTFontOpticalSizeAttribute; 52 53 53 54 #if PLATFORM(COCOA) -
trunk/Source/WebCore/rendering/RenderThemeIOS.mm
r188183 r188591 1262 1262 ASSERT(fontDescriptor); 1263 1263 RetainPtr<CTFontRef> font = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), 0, nullptr)); 1264 font = applyFontFeatureSettings(font.get(), fontDescription.featureSettings());1264 font = preparePlatformFont(font.get(), fontDescription.textRenderingMode(), fontDescription.featureSettings()); 1265 1265 fontDescription.setIsAbsoluteSize(true); 1266 1266 fontDescription.setOneFamily(textStyle);
Note: See TracChangeset
for help on using the changeset viewer.