Changeset 19350 in webkit


Ignore:
Timestamp:
Feb 1, 2007 11:43:25 PM (17 years ago)
Author:
bdash
Message:

2007-02-01 Nicholas Shanks <webkit@nickshanks.com>

Reviewed by Mark.

Add support for CSS2 font-stretch property.

  • css/CSSComputedStyleDeclaration.cpp: (WebCore::): (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue):
  • css/cssparser.cpp: (WebCore::CSSParser::parseValue):
  • css/cssstyleselector.cpp: (WebCore::CSSStyleSelector::applyDeclarations): (WebCore::CSSStyleSelector::applyProperty):
  • platform/FontCache.cpp: (WebCore::FontPlatformDataCacheKey::FontPlatformDataCacheKey): (WebCore::FontPlatformDataCacheKey::operator==): (WebCore::computeHash): (WebCore::FontPlatformDataCacheKeyTraits::deletedValue): (WebCore::FontPlatformDataCacheKeyTraits::emptyValue): (WebCore::FontCache::getCachedFontPlatformData):
  • platform/FontDescription.h: (WebCore::): (WebCore::FontDescription::FontDescription): (WebCore::FontDescription::stretch): (WebCore::FontDescription::narrowerStretch): (WebCore::FontDescription::widerStretch): (WebCore::FontDescription::setStretch): (WebCore::FontDescription::operator==):
  • platform/mac/FontCacheMac.mm: (WebCore::FontCache::createFontPlatformData):
  • platform/mac/WebFontCache.mm: (acceptableChoice): (betterChoice): (+[WebFontCache fontWithFamily:traits:size:]):

2007-02-01 Nicholas Shanks <webkit@nickshanks.com>

Reviewed by Mark.

CSS2 font-stretch property; uses American Typewriter and Helvetica Neue fonts,
requiring Regular, Condensed, Bold and Bold Condensed faces.

  • fast/css/computed-style-expected.txt: Updated.
  • fast/css/font-stretch-expected.checksum: Added.
  • fast/css/font-stretch-expected.png: Added.
  • fast/css/font-stretch-expected.txt: Added.
  • fast/css/font-stretch.html: Added.

2007-02-01 Nicholas Shanks <webkit@nickshanks.com>

Reviewed by Mark.

Add support for CSS2 font-stretch property.

  • WebInspector/webInspector/inspector.js:
  • WebView/WebHTMLView.mm: (-[WebHTMLView _addToStyle:fontA:fontB:]):
Location:
trunk
Files:
4 added
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r19348 r19350  
     12007-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
    1142007-02-01  Alexey Proskuryakov  <ap@webkit.org>
    215
  • trunk/LayoutTests/fast/css/computed-style-expected.txt

    r19175 r19350  
    3232font-family: Times;
    3333font-size: 16px;
     34font-stretch: normal;
    3435font-style: normal;
    3536font-variant: normal;
  • trunk/WebCore/ChangeLog

    r19349 r19350  
     12007-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
    1372007-02-01  Timothy Hatcher  <timothy@apple.com>
    238
  • trunk/WebCore/css/CSSComputedStyleDeclaration.cpp

    r19176 r19350  
    7171    CSS_PROP_FONT_FAMILY,
    7272    CSS_PROP_FONT_SIZE,
     73    CSS_PROP_FONT_STRETCH,
    7374    CSS_PROP_FONT_STYLE,
    7475    CSS_PROP_FONT_VARIANT,
     
    963964        case CSS_PROP__WEBKIT_BINDING:
    964965            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);
    965972        case CSS_PROP_FONT_STYLE:
    966973            if (style->fontDescription().italic())
     
    15421549        case CSS_PROP_COUNTER_RESET:
    15431550        case CSS_PROP_FONT:
    1544         case CSS_PROP_FONT_STRETCH:
    15451551        case CSS_PROP_LIST_STYLE:
    15461552        case CSS_PROP_MARGIN:
     
    16541660    CSS_PROP_FONT_FAMILY,
    16551661    CSS_PROP_FONT_SIZE,
     1662    CSS_PROP_FONT_STRETCH,
    16561663    CSS_PROP_FONT_STYLE,
    16571664    CSS_PROP_FONT_VARIANT,
  • trunk/WebCore/css/cssparser.cpp

    r19176 r19350  
    715715            }
    716716        }
     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;
    717722        break;
    718723
     
    14721477    case CSS_PROP_INVALID:
    14731478        return false;
    1474     case CSS_PROP_FONT_STRETCH:
    14751479    case CSS_PROP_PAGE:
    14761480    case CSS_PROP_TEXT_LINE_THROUGH:
  • trunk/WebCore/css/cssstyleselector.cpp

    r19276 r19350  
    18221822                    case CSS_PROP_FONT_FAMILY:
    18231823                    case CSS_PROP_FONT_WEIGHT:
     1824                    case CSS_PROP_FONT_STRETCH:
     1825                    case CSS_PROP_FONT_VARIANT:
    18241826                    case CSS_PROP__WEBKIT_TEXT_SIZE_ADJUST:
    1825                     case CSS_PROP_FONT_VARIANT:
    18261827                        // these have to be applied first, because other properties use the computed
    18271828                        // values of these porperties.
     
    21492150    }
    21502151       
     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   
    21512192    case CSS_PROP_LIST_STYLE_POSITION:
    21522193    {
     
    43724413    case CSS_PROP_INVALID:
    43734414        return;
    4374     case CSS_PROP_FONT_STRETCH:
    43754415    case CSS_PROP_PAGE:
    43764416    case CSS_PROP_QUOTES:
  • trunk/WebCore/platform/FontCache.cpp

    r17144 r19350  
    3939
    4040struct 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)
    4242        : m_family(family)
    4343        , m_size(size)
    4444        , m_bold(bold)
     45        , m_stretch(stretch)
    4546        , m_italic(italic)
    4647    {
     
    4950    bool operator==(const FontPlatformDataCacheKey& other) const
    5051    {
    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;
    5253    }
    5354   
     
    5556    unsigned m_size;
    5657    bool m_bold;
     58    unsigned m_stretch;
    5759    bool m_italic;
    5860};
     
    6062inline unsigned computeHash(const FontPlatformDataCacheKey& fontKey)
    6163{
    62     unsigned hashCodes[3] = {
     64    unsigned hashCodes[4] = {
    6365        CaseInsensitiveHash<String>::hash(fontKey.m_family),
    6466        fontKey.m_size,
     67        fontKey.m_stretch,
    6568        static_cast<unsigned>(fontKey.m_bold) << 1 | static_cast<unsigned>(fontKey.m_italic)
    6669    };
    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));
    6871}
    6972
     
    8588    static const FontPlatformDataCacheKey& deletedValue()
    8689    {
    87         static FontPlatformDataCacheKey key(nullAtom, 0xFFFFFFFFU, false, false);
     90        static FontPlatformDataCacheKey key(nullAtom, 0xFFFFFFFFU, false, 0, false);
    8891        return key;
    8992    }
    9093    static const FontPlatformDataCacheKey& emptyValue()
    9194    {
    92         static FontPlatformDataCacheKey key(nullAtom, 0, false, false);
     95        static FontPlatformDataCacheKey key(nullAtom, 0, false, 0, false);
    9396        return key;
    9497    }
     
    134137    }
    135138
    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());
    137140    FontPlatformData* result = 0;
    138141    bool foundResult;
  • trunk/WebCore/platform/FontDescription.h

    r18874 r19350  
    3232const unsigned cBoldWeight = 63;
    3333
     34enum FontStretch {
     35    FontStretchCondensed = 3,
     36    FontStretchNormal = 5,
     37    FontStretchExpanded = 7
     38};
     39
    3440class FontDescription {
    3541public:
     
    4046        : m_specifiedSize(0), m_computedSize(0),
    4147          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)
    4349          {}
    4450   
     
    5662    bool isAbsoluteSize() const { return m_isAbsoluteSize; }
    5763    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; }
    5867    GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
    5968    bool usePrinterFont() const { return m_usePrinterFont; }
     
    6877    void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
    6978    void setWeight(unsigned w) { m_weight = w; }
     79    void setStretch(FontStretch s) { m_stretch = s; }
    7080    void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; }
    7181    void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
     
    8494                                 // (logical sizes like "medium" don't count).
    8595    unsigned m_weight : 8;
     96    unsigned m_stretch : 4;       // FontStretch
    8697    unsigned m_genericFamily : 3; // GenericFamilyType
    8798    bool m_usePrinterFont : 1;
     
    101112        && m_isAbsoluteSize == other.m_isAbsoluteSize
    102113        && m_weight == other.m_weight
     114        && m_stretch == other.m_stretch
    103115        && m_genericFamily == other.m_genericFamily
    104116        && m_usePrinterFont == other.m_usePrinterFont
  • trunk/WebCore/platform/mac/FontCacheMac.mm

    r17585 r19350  
    204204    if (fontDescription.bold())
    205205        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    }
    206216    float size = fontDescription.computedPixelSize();
    207217   
     
    211221
    212222    NSFontTraitMask actualTraits = 0;
    213     if (fontDescription.bold() || fontDescription.italic())
     223    if ((traits & NSFontBoldTrait) || (traits & NSFontItalicTrait))
    214224        actualTraits = [[NSFontManager sharedFontManager] traitsOfFont:nsFont];
    215225   
  • trunk/WebCore/platform/mac/WebFontCache.mm

    r19349 r19350  
    2929#import "config.h"
    3030#import "WebFontCache.h"
     31#import "FontDescription.h"
    3132
    3233#import <math.h>
    3334
    3435#define SYNTHESIZED_FONT_TRAITS (NSBoldFontMask | NSItalicFontMask)
    35 
     36#define ACCEPTABLE_FONT_TRAITS (NSFontCondensedTrait | NSFontExpandedTrait)
    3637#define IMPORTANT_FONT_TRAITS (0 \
    3738    | NSBoldFontMask \
     
    4546)
    4647
    47 #define DESIRED_WEIGHT 5
    48 
    4948static BOOL acceptableChoice(NSFontTraitMask desiredTraits, int desiredWeight,
    5049    NSFontTraitMask candidateTraits, int candidateWeight)
    5150{
    5251    desiredTraits &= ~SYNTHESIZED_FONT_TRAITS;
     52    desiredTraits &= ~ACCEPTABLE_FONT_TRAITS;
    5353    return (candidateTraits & desiredTraits) == desiredTraits;
    5454}
     
    5858    NSFontTraitMask candidateTraits, int candidateWeight)
    5959{
    60     if (!acceptableChoice(desiredTraits, desiredWeight, candidateTraits, candidateWeight)) {
     60    if (!acceptableChoice(desiredTraits, desiredWeight, candidateTraits, candidateWeight))
    6161        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;
    6371   
    6472    // A list of the traits we care about.
     
    8795    }
    8896   
    89     int chosenWeightDelta = chosenWeight - desiredWeight;
    90     int candidateWeightDelta = candidateWeight - desiredWeight;
    91    
    92     int chosenWeightDeltaMagnitude = abs(chosenWeightDelta);
    93     int candidateWeightDeltaMagnitude = abs(candidateWeightDelta);
    94    
    9597    // Smaller magnitude wins.
    9698    // If both have same magnitude, tie breaker is that the smaller weight wins.
    9799    // Otherwise, first font in the array wins (should almost never happen).
    98     if (candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude) {
     100    if (candidateWeightDelta < chosenWeightDelta)
    99101        return YES;
    100     }
    101     if (candidateWeightDeltaMagnitude == chosenWeightDeltaMagnitude && candidateWeight < chosenWeight) {
     102    if (candidateWeightDelta == chosenWeightDelta && candidateWeight < chosenWeight)
    102103        return YES;
    103     }
    104104   
    105105    return NO;
     
    114114{
    115115    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     116    int desiredWeight = (desiredTraits & NSFontBoldTrait)? 9 : 5;
    116117
    117118    // Look for an exact match first.
     
    172173        BOOL newWinner;
    173174        if (!choseFont)
    174             newWinner = acceptableChoice(desiredTraits, DESIRED_WEIGHT, fontTraits, fontWeight);
     175            newWinner = acceptableChoice(desiredTraits, desiredWeight, fontTraits, fontWeight);
    175176        else
    176             newWinner = betterChoice(desiredTraits, DESIRED_WEIGHT, chosenTraits, chosenWeight, fontTraits, fontWeight);
     177            newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight);
    177178
    178179        if (newWinner) {
     
    181182            chosenTraits = fontTraits;
    182183
    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))
    184185                break;
    185186        }
  • trunk/WebKit/ChangeLog

    r19337 r19350  
     12007-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
    1112007-02-01  Maciej Stachowiak  <mjs@apple.com>
    212
  • trunk/WebKit/WebInspector/webInspector/inspector.js

    r19175 r19350  
    107107    "empty-cells": "show",
    108108    "float": "none",
     109    "font-stretch": "normal",
    109110    "font-style": "normal",
    110111    "font-variant": "normal",
  • trunk/WebKit/WebView/WebHTMLView.mm

    r19327 r19350  
    39983998    BOOL aIsBold = aWeight >= MIN_BOLD_WEIGHT;
    39993999
    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];
    40024002
    40034003    if ([aFamilyName isEqualToString:bFamilyName]) {
     
    40124012        if (aIsBold)
    40134013            traits |= NSBoldFontMask;
    4014         if (aIsItalic)
    4015             traits |= NSItalicFontMask;
     4014        traits |= (aTraits & NSFontItalicTrait);
     4015        traits |= (aTraits & NSFontCondensedTrait);
     4016        traits |= (aTraits & NSFontExpandedTrait);
    40164017        NSFont *foundFont = WebCoreFindFont(aFamilyName, traits, aPointSize);
    40174018
     
    40234024
    40244025        // 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.
    40264027        [style setFontFamily:[NSString stringWithFormat:@"'%@'", familyNameForCSS]];
    40274028    }
     
    40384039        [style setFontWeight:aIsBold ? @"bold" : @"normal"];
    40394040
    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"];
    40424047}
    40434048
Note: See TracChangeset for help on using the changeset viewer.