Changeset 183494 in webkit
- Timestamp:
- Apr 28, 2015 11:36:59 AM (9 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 18 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r183493 r183494 1 2015-04-27 Myles C. Maxfield <mmaxfield@apple.com> 2 3 Implement font-synthesis CSS property 4 https://bugs.webkit.org/show_bug.cgi?id=144305 5 6 Reviewed by Andreas Kling. 7 8 Test all combinations of font-weight, font-style, and font-synthesis. 9 10 * fast/css3-text/font-synthesis-expected.html: Added. 11 * fast/css3-text/font-synthesis.html: Added. 12 1 13 2015-04-28 Brent Fulgham <bfulgham@apple.com> 2 14 -
trunk/LayoutTests/fast/css3-text/font-synthesis-parse-expected.txt
r183348 r183494 2 2 PASS declaration.length is 0 3 3 PASS declaration.getPropertyValue('font-synthesis') is null 4 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is " none"4 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight" 5 5 PASS cssRule.type is cssRule.STYLE_RULE 6 6 PASS declaration.length is 1 … … 34 34 PASS declaration.length is 0 35 35 PASS declaration.getPropertyValue('font-synthesis') is null 36 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is " none"36 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight" 37 37 PASS cssRule.type is cssRule.STYLE_RULE 38 38 PASS declaration.length is 0 39 39 PASS declaration.getPropertyValue('font-synthesis') is null 40 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is " none"40 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight" 41 41 PASS cssRule.type is cssRule.STYLE_RULE 42 42 PASS declaration.length is 0 43 43 PASS declaration.getPropertyValue('font-synthesis') is null 44 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is " none"44 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight" 45 45 PASS cssRule.type is cssRule.STYLE_RULE 46 46 PASS declaration.length is 0 47 47 PASS declaration.getPropertyValue('font-synthesis') is null 48 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is " none"48 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight" 49 49 PASS cssRule.type is cssRule.STYLE_RULE 50 50 PASS declaration.length is 0 51 51 PASS declaration.getPropertyValue('font-synthesis') is null 52 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is " none"52 PASS computedStyle.getPropertyCSSValue('font-synthesis').cssText is "style weight" 53 53 PASS successfullyParsed is true 54 54 -
trunk/LayoutTests/fast/css3-text/font-synthesis-parse.html
r183348 r183494 8 8 <div id="q"><div id="r"></div></div> 9 9 <script type="text/javascript"> 10 function testEmptyIs None(stylesheet, target) {10 function testEmptyIsBoth(stylesheet, target) { 11 11 cssRule = stylesheet.cssRules.item(0); 12 12 shouldBe("cssRule.type", "cssRule.STYLE_RULE"); … … 15 15 shouldBe("declaration.getPropertyValue('font-synthesis')", "null"); 16 16 computedStyle = window.getComputedStyle(target, null); 17 shouldBeEqualToString("computedStyle.getPropertyCSSValue('font-synthesis').cssText", " none");17 shouldBeEqualToString("computedStyle.getPropertyCSSValue('font-synthesis').cssText", "style weight"); 18 18 stylesheet.deleteRule(0); 19 19 } … … 80 80 81 81 stylesheet.insertRule("#p { }", 0); 82 testEmptyIs None(stylesheet, target);82 testEmptyIsBoth(stylesheet, target); 83 83 84 84 stylesheet.insertRule("#p { font-synthesis: initial; }", 0); … … 104 104 105 105 stylesheet.insertRule("#p { font-synthesis: garbage style }", 0); 106 testEmptyIs None(stylesheet, target);106 testEmptyIsBoth(stylesheet, target); 107 107 108 108 stylesheet.insertRule("#p { font-synthesis: style garbage }", 0); 109 testEmptyIs None(stylesheet, target);109 testEmptyIsBoth(stylesheet, target); 110 110 111 111 stylesheet.insertRule("#p { font-synthesis: garbage style garbage }", 0); 112 testEmptyIs None(stylesheet, target);112 testEmptyIsBoth(stylesheet, target); 113 113 114 114 stylesheet.insertRule("#p { font-synthesis: style garbage style }", 0); 115 testEmptyIs None(stylesheet, target);115 testEmptyIsBoth(stylesheet, target); 116 116 117 117 stylesheet.insertRule("#p { font-synthesis: weight garbage }", 0); 118 testEmptyIs None(stylesheet, target);118 testEmptyIsBoth(stylesheet, target); 119 119 120 120 </script> -
trunk/Source/WebCore/ChangeLog
r183489 r183494 1 2015-04-27 Myles C. Maxfield <mmaxfield@apple.com> 2 3 [Mac] [iOS] Implement font-synthesis CSS property 4 https://bugs.webkit.org/show_bug.cgi?id=144305 5 6 Reviewed by Andreas Kling. 7 8 This patch is fairly straightforward, though there are some particular pieces to the patch listed below. 9 10 The implementation of this font-synthesis CSS property lives inside FontCacheIOS and FontCacheMac. We already 11 determine if we should synthesize bold and italics, this CSS property simply guards that decision. 12 13 Because FontCache interacts with FontDescriptions and not RenderStyles, this patch moves the source of truth 14 regarding font-synthesis into FontDescription (from RenderStyle). 15 16 Test: fast/css3-text/font-synthesis.html 17 18 * css/CSSPropertyNames.in: Mark font-synthesis as a FontProperty, which means that the relevant state is kept 19 inside FontDescription. This also means that the property must be marked as a "high priority" property, which 20 is enforced by it existing at the top of CSSPropertyNames.in. The move to FontDescription must be done so that 21 FontCacheIOS and FontCacheMac have access to the saved state. 22 * css/CSSComputedStyleDeclaration.cpp: 23 (WebCore::fontSynthesisFromStyle): Update to look for state in FontDescription instead of RenderStyle. 24 * css/CSSSegmentedFontFace.cpp: 25 (WebCore::CSSSegmentedFontFace::fontRanges): Guard the synthetic bold and synthic italic decision on the new 26 FontSynthesis state inside FontDescription. 27 * css/StyleBuilderConverter.h: 28 (WebCore::StyleBuilderConverter::convertFontSynthesis): Moved from 29 StyleBuilderCustom::applyValueFontSynthesis(). This is because of the updated options inside of 30 CSSPropertyNames.in 31 * css/StyleBuilderCustom.h: 32 (WebCore::StyleBuilderCustom::applyValueFontSynthesis): Deleted. 33 * platform/graphics/FontDescription.h: 34 (WebCore::FontDescription::FontDescription): Moved from RenderStyle. 35 (WebCore::FontDescription::fontSynthesis): Ditto. 36 (WebCore::FontDescription::setFontSynthesis): Ditto. 37 (WebCore::FontDescription::initialFontSynthesis): Ditto. 38 (WebCore::FontDescription::operator==): Update to include new state. 39 * platform/graphics/FontCache.h: 40 (WebCore::FontDescriptionFontDataCacheKey::makeFlagKey): Make FontDescription hashes sensitive to the new 41 state inside FontDescription. 42 * platform/graphics/ios/FontCacheIOS.mm: 43 (WebCore::FontCache::createFontPlatformData): Guard the synthetic bold and synthetic italic decision on the 44 new FontSynthesis state inside FontDescription. 45 * platform/graphics/mac/FontCacheMac.mm: 46 (WebCore::FontCache::createFontPlatformData): Ditto. 47 * platform/text/TextFlags.h: Move FontSynthesis type from RenderStyleConstants. 48 * rendering/style/RenderStyle.h: 49 (WebCore::RenderStyle::fontSynthesis): Moved to FontDescription. 50 (WebCore::RenderStyle::setFontSynthesis): Ditto. 51 (WebCore::RenderStyle::initialFontSynthesis): Ditto. 52 * rendering/style/RenderStyleConstants.h: Moved FontSynthesis type to TextFlags. 53 * rendering/style/StyleRareInheritedData.h: Remove state regarding font synthesis (moved to FontDescription) 54 1 55 2015-04-28 Youenn Fablet <youenn.fablet@crf.canon.fr> 2 56 -
trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp
r183314 r183494 1614 1614 static Ref<CSSValue> fontSynthesisFromStyle(RenderStyle& style) 1615 1615 { 1616 if (style.font Synthesis() == FontSynthesisNone)1616 if (style.fontDescription().fontSynthesis() == FontSynthesisNone) 1617 1617 return cssValuePool().createIdentifierValue(CSSValueNone); 1618 1618 1619 1619 auto list = CSSValueList::createSpaceSeparated(); 1620 if (style.font Synthesis() & FontSynthesisStyle)1620 if (style.fontDescription().fontSynthesis() & FontSynthesisStyle) 1621 1621 list.get().append(cssValuePool().createIdentifierValue(CSSValueStyle)); 1622 if (style.font Synthesis() & FontSynthesisWeight)1622 if (style.fontDescription().fontSynthesis() & FontSynthesisWeight) 1623 1623 list.get().append(cssValuePool().createIdentifierValue(CSSValueWeight)); 1624 1624 return Ref<CSSValue>(list.get()); -
trunk/Source/WebCore/css/CSSPropertyNames.in
r183304 r183494 119 119 -epub-writing-mode = -webkit-writing-mode 120 120 zoom [Custom=All] 121 font-synthesis [Inherited, FontProperty, Converter=FontSynthesis] 121 122 122 123 // Keep this in between the highest priority props and the lower ones. … … 224 225 font [Inherited, Longhands=font-family|font-size|font-style|font-variant|font-weight|line-height] 225 226 font-stretch [SkipBuilder] 226 font-synthesis [Inherited, Custom=Value]227 227 glyph-orientation-horizontal [Inherited, SVG, Converter=GlyphOrientation] 228 228 glyph-orientation-vertical [Inherited, SVG, Converter=GlyphOrientationOrAuto] -
trunk/Source/WebCore/css/CSSSegmentedFontFace.cpp
r178940 r183494 114 114 115 115 FontTraitsMask desiredTraitsMask = fontDescription.traitsMask(); 116 unsigned hashKey = ((fontDescription.computedPixelSize() + 1) << (FontTraitsMaskWidth + FontWidthVariantWidth + 1)) 116 // FIXME: Unify this function with FontDescriptionFontDataCacheKey in FontCache.h (Or just use the regular FontCache instead of this) 117 unsigned hashKey = ((fontDescription.computedPixelSize() + 1) << (FontTraitsMaskWidth + FontWidthVariantWidth + FontSynthesisWidth + 1)) 118 | (fontDescription.fontSynthesis() << (FontTraitsMaskWidth + FontWidthVariantWidth + 1)) 117 119 | ((fontDescription.orientation() == Vertical ? 1 : 0) << (FontTraitsMaskWidth + FontWidthVariantWidth)) 118 120 | fontDescription.widthVariant() << FontTraitsMaskWidth … … 126 128 if (!face->isValid()) 127 129 continue; 130 128 131 FontTraitsMask traitsMask = face->traitsMask(); 129 bool syntheticBold = !(traitsMask & (FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)) && (desiredTraitsMask & (FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)); 130 bool syntheticItalic = !(traitsMask & FontStyleItalicMask) && (desiredTraitsMask & FontStyleItalicMask); 132 bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && !(traitsMask & (FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)) && (desiredTraitsMask & (FontWeight600Mask | FontWeight700Mask | FontWeight800Mask | FontWeight900Mask)); 133 bool syntheticItalic = (fontDescription.fontSynthesis() & FontSynthesisStyle) && !(traitsMask & FontStyleItalicMask) && (desiredTraitsMask & FontStyleItalicMask); 134 131 135 if (RefPtr<Font> faceFont = face->font(fontDescription, syntheticBold, syntheticItalic)) 132 136 appendFontWithInvalidUnicodeRangeIfLoading(fontRanges, faceFont.releaseNonNull(), face->ranges()); -
trunk/Source/WebCore/css/StyleBuilderConverter.h
r181352 r183494 125 125 static EGlyphOrientation convertGlyphOrientationOrAuto(StyleResolver&, CSSValue&); 126 126 static Optional<Length> convertLineHeight(StyleResolver&, CSSValue&, float multiplier = 1.f); 127 static FontSynthesis convertFontSynthesis(StyleResolver&, CSSValue&); 127 128 128 129 private: … … 1212 1213 } 1213 1214 1215 FontSynthesis StyleBuilderConverter::convertFontSynthesis(StyleResolver&, CSSValue& value) 1216 { 1217 if (is<CSSPrimitiveValue>(value)) { 1218 ASSERT(downcast<CSSPrimitiveValue>(value).getValueID() == CSSValueNone); 1219 return FontSynthesisNone; 1220 } 1221 1222 FontSynthesis result = FontSynthesisNone; 1223 ASSERT(is<CSSValueList>(value)); 1224 for (CSSValue& v : downcast<CSSValueList>(value)) { 1225 switch (downcast<CSSPrimitiveValue>(v).getValueID()) { 1226 case CSSValueWeight: 1227 result |= FontSynthesisWeight; 1228 break; 1229 case CSSValueStyle: 1230 result |= FontSynthesisStyle; 1231 break; 1232 default: 1233 ASSERT_NOT_REACHED(); 1234 break; 1235 } 1236 } 1237 1238 return result; 1239 } 1240 1214 1241 } // namespace WebCore 1215 1242 -
trunk/Source/WebCore/css/StyleBuilderCustom.h
r183304 r183494 77 77 DECLARE_PROPERTY_CUSTOM_HANDLERS(FontSize); 78 78 DECLARE_PROPERTY_CUSTOM_HANDLERS(FontWeight); 79 DECLARE_PROPERTY_CUSTOM_HANDLERS(FontSynthesis);80 79 #if ENABLE(CSS_IMAGE_RESOLUTION) 81 80 DECLARE_PROPERTY_CUSTOM_HANDLERS(ImageResolution); … … 1377 1376 } 1378 1377 1379 inline void StyleBuilderCustom::applyValueFontSynthesis(StyleResolver& styleResolver, CSSValue& value)1380 {1381 if (is<CSSPrimitiveValue>(value)) {1382 ASSERT(downcast<CSSPrimitiveValue>(value).getValueID() == CSSValueNone);1383 styleResolver.style()->setFontSynthesis(FontSynthesisNone);1384 }1385 1386 FontSynthesis result = FontSynthesisNone;1387 ASSERT(is<CSSValueList>(value));1388 for (CSSValue& i : downcast<CSSValueList>(value)) {1389 switch (downcast<CSSPrimitiveValue>(i).getValueID()) {1390 case CSSValueWeight:1391 result |= FontSynthesisWeight;1392 break;1393 case CSSValueStyle:1394 result |= FontSynthesisStyle;1395 break;1396 default:1397 ASSERT_NOT_REACHED();1398 break;1399 }1400 }1401 1402 styleResolver.style()->setFontSynthesis(result);1403 }1404 1405 1378 inline void StyleBuilderCustom::applyInitialColumnGap(StyleResolver& styleResolver) 1406 1379 { -
trunk/Source/WebCore/css/StyleResolver.cpp
r182613 r183494 169 169 using namespace HTMLNames; 170 170 171 static const CSSPropertyID lastHighPriorityProperty = CSSProperty Zoom;171 static const CSSPropertyID lastHighPriorityProperty = CSSPropertyFontSynthesis; 172 172 static const CSSPropertyID firstLowPriorityProperty = static_cast<CSSPropertyID>(lastHighPriorityProperty + 1); 173 173 -
trunk/Source/WebCore/platform/graphics/FontCache.h
r181348 r183494 80 80 static unsigned makeFlagKey(const FontDescription& description) 81 81 { 82 return static_cast<unsigned>(description.widthVariant()) << 4 82 return static_cast<unsigned>(description.fontSynthesis()) << 6 83 | static_cast<unsigned>(description.widthVariant()) << 4 83 84 | static_cast<unsigned>(description.nonCJKGlyphOrientation()) << 3 84 85 | static_cast<unsigned>(description.orientation()) << 2 -
trunk/Source/WebCore/platform/graphics/FontDescription.h
r183442 r183494 66 66 , m_isSpecifiedFont(false) 67 67 , m_script(USCRIPT_COMMON) 68 , m_fontSynthesis(initialFontSynthesis()) 68 69 { 69 70 } … … 110 111 FontWidthVariant widthVariant() const { return static_cast<FontWidthVariant>(m_widthVariant); } 111 112 FontFeatureSettings* featureSettings() const { return m_featureSettings.get(); } 113 FontSynthesis fontSynthesis() const { return static_cast<FontSynthesis>(m_fontSynthesis); } 112 114 113 115 void setOneFamily(const AtomicString& family) { ASSERT(m_families.size() == 1); m_families[0] = family; } … … 148 150 void setScript(UScriptCode s) { m_script = s; } 149 151 void setFeatureSettings(PassRefPtr<FontFeatureSettings> settings) { m_featureSettings = settings; } 152 void setFontSynthesis(FontSynthesis fontSynthesis) { m_fontSynthesis = fontSynthesis; } 150 153 151 154 #if ENABLE(IOS_TEXT_AUTOSIZING) … … 167 170 static FontSmoothingMode initialFontSmoothing() { return AutoSmoothing; } 168 171 static TextRenderingMode initialTextRenderingMode() { return AutoTextRendering; } 172 static FontSynthesis initialFontSynthesis() { return FontSynthesisWeight | FontSynthesisStyle; } 169 173 170 174 private: … … 202 206 unsigned m_isSpecifiedFont : 1; // True if a web page specifies a non-generic font family as the first font family. 203 207 unsigned m_script : 7; // Used to help choose an appropriate font for generic font families. 208 unsigned m_fontSynthesis : 2; // FontSynthesis type 204 209 }; 205 210 … … 226 231 && m_widthVariant == other.m_widthVariant 227 232 && m_script == other.m_script 228 && m_featureSettings == other.m_featureSettings; 233 && m_featureSettings == other.m_featureSettings 234 && m_fontSynthesis == other.m_fontSynthesis; 229 235 } 230 236 -
trunk/Source/WebCore/platform/graphics/ios/FontCacheIOS.mm
r182894 r183494 695 695 bool isAppleColorEmoji = CTFontIsAppleColorEmoji(ctFont.get()); 696 696 697 bool syntheticBold = ( traits & kCTFontTraitBold) && !(actualTraits & kCTFontTraitBold) && !isAppleColorEmoji;698 bool syntheticOblique = ( traits & kCTFontTraitItalic) && !(actualTraits & kCTFontTraitItalic) && !isAppleColorEmoji;697 bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && (traits & kCTFontTraitBold) && !(actualTraits & kCTFontTraitBold) && !isAppleColorEmoji; 698 bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & kCTFontTraitItalic) && !(actualTraits & kCTFontTraitItalic) && !isAppleColorEmoji; 699 699 700 700 auto result = std::make_unique<FontPlatformData>(ctFont.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant()); -
trunk/Source/WebCore/platform/graphics/mac/FontCacheMac.mm
r183269 r183494 510 510 511 511 NSFont *platformFont = [nsFont printerFont]; 512 bool syntheticBold = isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight);513 bool syntheticOblique = ( traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);512 bool syntheticBold = (fontDescription.fontSynthesis() & FontSynthesisWeight) && isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight); 513 bool syntheticOblique = (fontDescription.fontSynthesis() & FontSynthesisStyle) && (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait); 514 514 515 515 return std::make_unique<FontPlatformData>(reinterpret_cast<CTFontRef>(platformFont), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant()); -
trunk/Source/WebCore/platform/text/TextFlags.h
r183442 r183494 59 59 }; 60 60 typedef unsigned ExpansionBehavior; 61 62 enum FontSynthesisValues { 63 FontSynthesisNone = 0x0, 64 FontSynthesisWeight = 0x1, 65 FontSynthesisStyle = 0x2 66 }; 67 typedef unsigned FontSynthesis; 68 const unsigned FontSynthesisWidth = 2; 61 69 62 70 enum FontWidthVariant { -
trunk/Source/WebCore/rendering/style/RenderStyle.h
r183454 r183494 1025 1025 1026 1026 TextOrientation textOrientation() const { return static_cast<TextOrientation>(rareInheritedData->m_textOrientation); } 1027 1028 FontSynthesis fontSynthesis() const { return static_cast<FontSynthesis>(rareInheritedData->fontSynthesis); }1029 1027 1030 1028 ObjectFit objectFit() const { return static_cast<ObjectFit>(rareNonInheritedData->m_objectFit); } … … 1542 1540 void setWordBreak(EWordBreak b) { SET_VAR(rareInheritedData, wordBreak, b); } 1543 1541 void setOverflowWrap(EOverflowWrap b) { SET_VAR(rareInheritedData, overflowWrap, b); } 1544 void setFontSynthesis(FontSynthesis synthesis) { SET_VAR(rareInheritedData, fontSynthesis, synthesis); }1545 1542 void setNBSPMode(ENBSPMode b) { SET_VAR(rareInheritedData, nbspMode, b); } 1546 1543 void setLineBreak(LineBreak b) { SET_VAR(rareInheritedData, lineBreak, b); } … … 2071 2068 static Isolation initialIsolation() { return IsolationAuto; } 2072 2069 #endif 2073 static FontSynthesis initialFontSynthesis() { return FontSynthesisStyle | FontSynthesisWeight; }2074 2070 2075 2071 static ptrdiff_t noninheritedFlagsMemoryOffset() { return OBJECT_OFFSETOF(RenderStyle, noninherited_flags); } -
trunk/Source/WebCore/rendering/style/RenderStyleConstants.h
r183454 r183494 418 418 }; 419 419 420 enum FontSynthesisValues {421 FontSynthesisNone = 0x0,422 FontSynthesisWeight = 0x1,423 FontSynthesisStyle = 0x2424 };425 typedef unsigned FontSynthesis;426 427 420 #if ENABLE(LETTERPRESS) 428 421 static const size_t TextDecorationBits = 5; -
trunk/Source/WebCore/rendering/style/StyleRareInheritedData.h
r183304 r183494 134 134 #endif 135 135 136 unsigned fontSynthesis : 2;137 138 136 AtomicString hyphenationString; 139 137 short hyphenationLimitBefore;
Note: See TracChangeset
for help on using the changeset viewer.