Changeset 19350 in webkit
- Timestamp:
- Feb 1, 2007 11:43:25 PM (17 years ago)
- Location:
- trunk
- Files:
-
- 4 added
- 13 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/LayoutTests/ChangeLog
r19348 r19350 1 2007-02-01 Nicholas Shanks <webkit@nickshanks.com> 2 3 Reviewed by Mark. 4 5 CSS2 font-stretch property; uses American Typewriter and Helvetica Neue fonts, 6 requiring Regular, Condensed, Bold and Bold Condensed faces. 7 8 * fast/css/computed-style-expected.txt: Updated. 9 * fast/css/font-stretch-expected.checksum: Added. 10 * fast/css/font-stretch-expected.png: Added. 11 * fast/css/font-stretch-expected.txt: Added. 12 * fast/css/font-stretch.html: Added. 13 1 14 2007-02-01 Alexey Proskuryakov <ap@webkit.org> 2 15 -
trunk/LayoutTests/fast/css/computed-style-expected.txt
r19175 r19350 32 32 font-family: Times; 33 33 font-size: 16px; 34 font-stretch: normal; 34 35 font-style: normal; 35 36 font-variant: normal; -
trunk/WebCore/ChangeLog
r19349 r19350 1 2007-02-01 Nicholas Shanks <webkit@nickshanks.com> 2 3 Reviewed by Mark. 4 5 Add support for CSS2 font-stretch property. 6 7 * css/CSSComputedStyleDeclaration.cpp: 8 (WebCore::): 9 (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): 10 * css/cssparser.cpp: 11 (WebCore::CSSParser::parseValue): 12 * css/cssstyleselector.cpp: 13 (WebCore::CSSStyleSelector::applyDeclarations): 14 (WebCore::CSSStyleSelector::applyProperty): 15 * platform/FontCache.cpp: 16 (WebCore::FontPlatformDataCacheKey::FontPlatformDataCacheKey): 17 (WebCore::FontPlatformDataCacheKey::operator==): 18 (WebCore::computeHash): 19 (WebCore::FontPlatformDataCacheKeyTraits::deletedValue): 20 (WebCore::FontPlatformDataCacheKeyTraits::emptyValue): 21 (WebCore::FontCache::getCachedFontPlatformData): 22 * platform/FontDescription.h: 23 (WebCore::): 24 (WebCore::FontDescription::FontDescription): 25 (WebCore::FontDescription::stretch): 26 (WebCore::FontDescription::narrowerStretch): 27 (WebCore::FontDescription::widerStretch): 28 (WebCore::FontDescription::setStretch): 29 (WebCore::FontDescription::operator==): 30 * platform/mac/FontCacheMac.mm: 31 (WebCore::FontCache::createFontPlatformData): 32 * platform/mac/WebFontCache.mm: 33 (acceptableChoice): 34 (betterChoice): 35 (+[WebFontCache fontWithFamily:traits:size:]): 36 1 37 2007-02-01 Timothy Hatcher <timothy@apple.com> 2 38 -
trunk/WebCore/css/CSSComputedStyleDeclaration.cpp
r19176 r19350 71 71 CSS_PROP_FONT_FAMILY, 72 72 CSS_PROP_FONT_SIZE, 73 CSS_PROP_FONT_STRETCH, 73 74 CSS_PROP_FONT_STYLE, 74 75 CSS_PROP_FONT_VARIANT, … … 963 964 case CSS_PROP__WEBKIT_BINDING: 964 965 break; 966 case CSS_PROP_FONT_STRETCH: 967 if (style->fontDescription().stretch() == FontStretchCondensed) 968 return new CSSPrimitiveValue(CSS_VAL_CONDENSED); 969 if (style->fontDescription().stretch() == FontStretchExpanded) 970 return new CSSPrimitiveValue(CSS_VAL_EXPANDED); 971 return new CSSPrimitiveValue(CSS_VAL_NORMAL); 965 972 case CSS_PROP_FONT_STYLE: 966 973 if (style->fontDescription().italic()) … … 1542 1549 case CSS_PROP_COUNTER_RESET: 1543 1550 case CSS_PROP_FONT: 1544 case CSS_PROP_FONT_STRETCH:1545 1551 case CSS_PROP_LIST_STYLE: 1546 1552 case CSS_PROP_MARGIN: … … 1654 1660 CSS_PROP_FONT_FAMILY, 1655 1661 CSS_PROP_FONT_SIZE, 1662 CSS_PROP_FONT_STRETCH, 1656 1663 CSS_PROP_FONT_STYLE, 1657 1664 CSS_PROP_FONT_VARIANT, -
trunk/WebCore/css/cssparser.cpp
r19176 r19350 715 715 } 716 716 } 717 break; 718 719 case CSS_PROP_FONT_STRETCH: // normal | wider | narrower | ultra-condensed | extra-condensed | condensed | semi-condensed | semi-expanded | expanded | extra-expanded | ultra-expanded | inherit 720 if (id == CSS_VAL_NORMAL || (id >= CSS_VAL_WIDER && id <= CSS_VAL_ULTRA_EXPANDED)) 721 valid_primitive = true; 717 722 break; 718 723 … … 1472 1477 case CSS_PROP_INVALID: 1473 1478 return false; 1474 case CSS_PROP_FONT_STRETCH:1475 1479 case CSS_PROP_PAGE: 1476 1480 case CSS_PROP_TEXT_LINE_THROUGH: -
trunk/WebCore/css/cssstyleselector.cpp
r19276 r19350 1822 1822 case CSS_PROP_FONT_FAMILY: 1823 1823 case CSS_PROP_FONT_WEIGHT: 1824 case CSS_PROP_FONT_STRETCH: 1825 case CSS_PROP_FONT_VARIANT: 1824 1826 case CSS_PROP__WEBKIT_TEXT_SIZE_ADJUST: 1825 case CSS_PROP_FONT_VARIANT:1826 1827 // these have to be applied first, because other properties use the computed 1827 1828 // values of these porperties. … … 2149 2150 } 2150 2151 2152 case CSS_PROP_FONT_STRETCH: { 2153 FontDescription fontDescription = style->fontDescription(); 2154 if (isInherit) 2155 fontDescription.setStretch(parentStyle->fontDescription().stretch()); 2156 else if (isInitial) 2157 fontDescription.setStretch(FontStretchNormal); 2158 else { 2159 if (!primitiveValue || !primitiveValue->getIdent()) 2160 return; 2161 switch (primitiveValue->getIdent()) { 2162 case CSS_VAL_WIDER: 2163 fontDescription.setStretch(fontDescription.widerStretch()); 2164 break; 2165 case CSS_VAL_NARROWER: 2166 fontDescription.setStretch(fontDescription.narrowerStretch()); 2167 break; 2168 case CSS_VAL_NORMAL: 2169 fontDescription.setStretch(FontStretchNormal); 2170 break; 2171 case CSS_VAL_SEMI_EXPANDED: 2172 case CSS_VAL_EXPANDED: 2173 case CSS_VAL_EXTRA_EXPANDED: 2174 case CSS_VAL_ULTRA_EXPANDED: 2175 fontDescription.setStretch(FontStretchExpanded); 2176 break; 2177 case CSS_VAL_ULTRA_CONDENSED: 2178 case CSS_VAL_EXTRA_CONDENSED: 2179 case CSS_VAL_CONDENSED: 2180 case CSS_VAL_SEMI_CONDENSED: 2181 fontDescription.setStretch(FontStretchCondensed); 2182 break; 2183 default: 2184 return; 2185 } 2186 } 2187 if (style->setFontDescription(fontDescription)) 2188 fontDirty = true; 2189 return; 2190 } 2191 2151 2192 case CSS_PROP_LIST_STYLE_POSITION: 2152 2193 { … … 4372 4413 case CSS_PROP_INVALID: 4373 4414 return; 4374 case CSS_PROP_FONT_STRETCH:4375 4415 case CSS_PROP_PAGE: 4376 4416 case CSS_PROP_QUOTES: -
trunk/WebCore/platform/FontCache.cpp
r17144 r19350 39 39 40 40 struct FontPlatformDataCacheKey { 41 FontPlatformDataCacheKey(const AtomicString& family = AtomicString(), unsigned size = 0, bool bold = false, bool italic = false)41 FontPlatformDataCacheKey(const AtomicString& family = AtomicString(), unsigned size = 0, bool bold = false, unsigned stretch = 5, bool italic = false) 42 42 : m_family(family) 43 43 , m_size(size) 44 44 , m_bold(bold) 45 , m_stretch(stretch) 45 46 , m_italic(italic) 46 47 { … … 49 50 bool operator==(const FontPlatformDataCacheKey& other) const 50 51 { 51 return equalIgnoringCase(m_family, other.m_family) && m_size == other.m_size && m_bold == other.m_bold && m_ italic == other.m_italic;52 return equalIgnoringCase(m_family, other.m_family) && m_size == other.m_size && m_bold == other.m_bold && m_stretch == other.m_stretch && m_italic == other.m_italic; 52 53 } 53 54 … … 55 56 unsigned m_size; 56 57 bool m_bold; 58 unsigned m_stretch; 57 59 bool m_italic; 58 60 }; … … 60 62 inline unsigned computeHash(const FontPlatformDataCacheKey& fontKey) 61 63 { 62 unsigned hashCodes[ 3] = {64 unsigned hashCodes[4] = { 63 65 CaseInsensitiveHash<String>::hash(fontKey.m_family), 64 66 fontKey.m_size, 67 fontKey.m_stretch, 65 68 static_cast<unsigned>(fontKey.m_bold) << 1 | static_cast<unsigned>(fontKey.m_italic) 66 69 }; 67 return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), 3* sizeof(unsigned) / sizeof(UChar));70 return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), 4 * sizeof(unsigned) / sizeof(UChar)); 68 71 } 69 72 … … 85 88 static const FontPlatformDataCacheKey& deletedValue() 86 89 { 87 static FontPlatformDataCacheKey key(nullAtom, 0xFFFFFFFFU, false, false);90 static FontPlatformDataCacheKey key(nullAtom, 0xFFFFFFFFU, false, 0, false); 88 91 return key; 89 92 } 90 93 static const FontPlatformDataCacheKey& emptyValue() 91 94 { 92 static FontPlatformDataCacheKey key(nullAtom, 0, false, false);95 static FontPlatformDataCacheKey key(nullAtom, 0, false, 0, false); 93 96 return key; 94 97 } … … 134 137 } 135 138 136 FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), fontDescription.italic());139 FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), static_cast<unsigned>(fontDescription.stretch()), fontDescription.italic()); 137 140 FontPlatformData* result = 0; 138 141 bool foundResult; -
trunk/WebCore/platform/FontDescription.h
r18874 r19350 32 32 const unsigned cBoldWeight = 63; 33 33 34 enum FontStretch { 35 FontStretchCondensed = 3, 36 FontStretchNormal = 5, 37 FontStretchExpanded = 7 38 }; 39 34 40 class FontDescription { 35 41 public: … … 40 46 : m_specifiedSize(0), m_computedSize(0), 41 47 m_italic(false), m_smallCaps(false), m_isAbsoluteSize(false), m_weight(cNormalWeight), 42 m_ genericFamily(NoFamily), m_usePrinterFont(false), m_keywordSize(0)48 m_stretch(FontStretchNormal), m_genericFamily(NoFamily), m_usePrinterFont(false), m_keywordSize(0) 43 49 {} 44 50 … … 56 62 bool isAbsoluteSize() const { return m_isAbsoluteSize; } 57 63 unsigned weight() const { return m_weight; } 64 FontStretch stretch() const { return static_cast<FontStretch>(m_stretch); } 65 FontStretch narrowerStretch() const { return (m_stretch == FontStretchExpanded) ? FontStretchNormal : FontStretchCondensed; } 66 FontStretch widerStretch() const { return (m_stretch == FontStretchCondensed) ? FontStretchNormal : FontStretchExpanded; } 58 67 GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); } 59 68 bool usePrinterFont() const { return m_usePrinterFont; } … … 68 77 void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; } 69 78 void setWeight(unsigned w) { m_weight = w; } 79 void setStretch(FontStretch s) { m_stretch = s; } 70 80 void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; } 71 81 void setUsePrinterFont(bool p) { m_usePrinterFont = p; } … … 84 94 // (logical sizes like "medium" don't count). 85 95 unsigned m_weight : 8; 96 unsigned m_stretch : 4; // FontStretch 86 97 unsigned m_genericFamily : 3; // GenericFamilyType 87 98 bool m_usePrinterFont : 1; … … 101 112 && m_isAbsoluteSize == other.m_isAbsoluteSize 102 113 && m_weight == other.m_weight 114 && m_stretch == other.m_stretch 103 115 && m_genericFamily == other.m_genericFamily 104 116 && m_usePrinterFont == other.m_usePrinterFont -
trunk/WebCore/platform/mac/FontCacheMac.mm
r17585 r19350 204 204 if (fontDescription.bold()) 205 205 traits |= NSBoldFontMask; 206 switch (fontDescription.stretch()) { 207 case FontStretchCondensed: 208 traits |= NSFontCondensedTrait; 209 break; 210 case FontStretchExpanded: 211 traits |= NSFontExpandedTrait; 212 break; 213 case FontStretchNormal: 214 break; 215 } 206 216 float size = fontDescription.computedPixelSize(); 207 217 … … 211 221 212 222 NSFontTraitMask actualTraits = 0; 213 if ( fontDescription.bold() || fontDescription.italic())223 if ((traits & NSFontBoldTrait) || (traits & NSFontItalicTrait)) 214 224 actualTraits = [[NSFontManager sharedFontManager] traitsOfFont:nsFont]; 215 225 -
trunk/WebCore/platform/mac/WebFontCache.mm
r19349 r19350 29 29 #import "config.h" 30 30 #import "WebFontCache.h" 31 #import "FontDescription.h" 31 32 32 33 #import <math.h> 33 34 34 35 #define SYNTHESIZED_FONT_TRAITS (NSBoldFontMask | NSItalicFontMask) 35 36 #define ACCEPTABLE_FONT_TRAITS (NSFontCondensedTrait | NSFontExpandedTrait) 36 37 #define IMPORTANT_FONT_TRAITS (0 \ 37 38 | NSBoldFontMask \ … … 45 46 ) 46 47 47 #define DESIRED_WEIGHT 548 49 48 static BOOL acceptableChoice(NSFontTraitMask desiredTraits, int desiredWeight, 50 49 NSFontTraitMask candidateTraits, int candidateWeight) 51 50 { 52 51 desiredTraits &= ~SYNTHESIZED_FONT_TRAITS; 52 desiredTraits &= ~ACCEPTABLE_FONT_TRAITS; 53 53 return (candidateTraits & desiredTraits) == desiredTraits; 54 54 } … … 58 58 NSFontTraitMask candidateTraits, int candidateWeight) 59 59 { 60 if (!acceptableChoice(desiredTraits, desiredWeight, candidateTraits, candidateWeight)) {60 if (!acceptableChoice(desiredTraits, desiredWeight, candidateTraits, candidateWeight)) 61 61 return NO; 62 } 62 63 unsigned chosenWeightDelta = abs(chosenWeight - desiredWeight); 64 unsigned candidateWeightDelta = abs(candidateWeight - desiredWeight); 65 66 // prefer a closer weight regardless of traits 67 if (candidateWeightDelta < chosenWeightDelta) 68 return YES; 69 if (candidateWeightDelta > chosenWeightDelta) 70 return NO; 63 71 64 72 // A list of the traits we care about. … … 87 95 } 88 96 89 int chosenWeightDelta = chosenWeight - desiredWeight;90 int candidateWeightDelta = candidateWeight - desiredWeight;91 92 int chosenWeightDeltaMagnitude = abs(chosenWeightDelta);93 int candidateWeightDeltaMagnitude = abs(candidateWeightDelta);94 95 97 // Smaller magnitude wins. 96 98 // If both have same magnitude, tie breaker is that the smaller weight wins. 97 99 // Otherwise, first font in the array wins (should almost never happen). 98 if (candidateWeightDelta Magnitude < chosenWeightDeltaMagnitude) {100 if (candidateWeightDelta < chosenWeightDelta) 99 101 return YES; 100 } 101 if (candidateWeightDeltaMagnitude == chosenWeightDeltaMagnitude && candidateWeight < chosenWeight) { 102 if (candidateWeightDelta == chosenWeightDelta && candidateWeight < chosenWeight) 102 103 return YES; 103 }104 104 105 105 return NO; … … 114 114 { 115 115 NSFontManager *fontManager = [NSFontManager sharedFontManager]; 116 int desiredWeight = (desiredTraits & NSFontBoldTrait)? 9 : 5; 116 117 117 118 // Look for an exact match first. … … 172 173 BOOL newWinner; 173 174 if (!choseFont) 174 newWinner = acceptableChoice(desiredTraits, DESIRED_WEIGHT, fontTraits, fontWeight);175 newWinner = acceptableChoice(desiredTraits, desiredWeight, fontTraits, fontWeight); 175 176 else 176 newWinner = betterChoice(desiredTraits, DESIRED_WEIGHT, chosenTraits, chosenWeight, fontTraits, fontWeight);177 newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight); 177 178 178 179 if (newWinner) { … … 181 182 chosenTraits = fontTraits; 182 183 183 if (chosenWeight == DESIRED_WEIGHT&& (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS))184 if (chosenWeight == desiredWeight && (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS)) 184 185 break; 185 186 } -
trunk/WebKit/ChangeLog
r19337 r19350 1 2007-02-01 Nicholas Shanks <webkit@nickshanks.com> 2 3 Reviewed by Mark. 4 5 Add support for CSS2 font-stretch property. 6 7 * WebInspector/webInspector/inspector.js: 8 * WebView/WebHTMLView.mm: 9 (-[WebHTMLView _addToStyle:fontA:fontB:]): 10 1 11 2007-02-01 Maciej Stachowiak <mjs@apple.com> 2 12 -
trunk/WebKit/WebInspector/webInspector/inspector.js
r19175 r19350 107 107 "empty-cells": "show", 108 108 "float": "none", 109 "font-stretch": "normal", 109 110 "font-style": "normal", 110 111 "font-variant": "normal", -
trunk/WebKit/WebView/WebHTMLView.mm
r19327 r19350 3998 3998 BOOL aIsBold = aWeight >= MIN_BOLD_WEIGHT; 3999 3999 4000 BOOL aIsItalic = ([fm traitsOfFont:a] & NSItalicFontMask) != 0;4001 BOOL bIsItalic = ([fm traitsOfFont:b] & NSItalicFontMask) != 0;4000 unsigned aTraits = [fm traitsOfFont:a]; 4001 unsigned bTraits = [fm traitsOfFont:b]; 4002 4002 4003 4003 if ([aFamilyName isEqualToString:bFamilyName]) { … … 4012 4012 if (aIsBold) 4013 4013 traits |= NSBoldFontMask; 4014 if (aIsItalic) 4015 traits |= NSItalicFontMask; 4014 traits |= (aTraits & NSFontItalicTrait); 4015 traits |= (aTraits & NSFontCondensedTrait); 4016 traits |= (aTraits & NSFontExpandedTrait); 4016 4017 NSFont *foundFont = WebCoreFindFont(aFamilyName, traits, aPointSize); 4017 4018 … … 4023 4024 4024 4025 // FIXME: Need more sophisticated escaping code if we want to handle family names 4025 // with characters like single quote or backslash in their names.4026 // with characters like apostrophe or backslash in their names. 4026 4027 [style setFontFamily:[NSString stringWithFormat:@"'%@'", familyNameForCSS]]; 4027 4028 } … … 4038 4039 [style setFontWeight:aIsBold ? @"bold" : @"normal"]; 4039 4040 4040 if (aIsItalic == bIsItalic) 4041 [style setFontStyle:aIsItalic ? @"italic" : @"normal"]; 4041 if ((aTraits & NSFontItalicTrait) == (bTraits & NSFontItalicTrait)) 4042 [style setFontStyle:(aTraits & NSFontItalicTrait) ? @"italic" : @"normal"]; 4043 if ((aTraits & NSFontCondensedTrait) == (bTraits & NSFontCondensedTrait)) 4044 [style setFontStretch:(aTraits & NSFontCondensedTrait) ? @"condensed" : @"normal"]; 4045 else if ((aTraits & NSFontExpandedTrait) == (bTraits & NSFontExpandedTrait)) 4046 [style setFontStretch:(aTraits & NSFontExpandedTrait) ? @"extended" : @"normal"]; 4042 4047 } 4043 4048
Note: See TracChangeset
for help on using the changeset viewer.