Changeset 31620 in webkit


Ignore:
Timestamp:
Apr 3, 2008 8:46:59 PM (16 years ago)
Author:
mitz@apple.com
Message:

WebCore:

2008-04-03 Nicholas Shanks <webkit@nickshanks.com>

Updated by Dan Bernstein. Reviewed by Dave Hyatt.

Tests to come: <http://bugs.webkit.org/show_bug.cgi?id=18306>

Build fixes for platforms other than Mac and Windows to come.

  • WebCore.vcproj/WebCore.vcproj: Added FontDescription.cpp.
  • WebCore.xcodeproj/project.pbxproj: Ditto.
  • css/CSSComputedStyleDeclaration.cpp: (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Changed to return additional weight value keywords 100, 200, 300, 500, 600, 800 and 900.
  • css/CSSFontSelector.cpp: (WebCore::hashForFont): Changed the bold parameter into a weight parameter and added the weight to the string to be hashed. (WebCore::CSSFontSelector::addFontFaceRule): Changed to apply all CSS weight values to the font description. (WebCore::CSSFontSelector::getFontData): Updated the fallback logic to go through all weights equal or lighter from the desired weight. For SVG, to also consider heavier weights.
  • css/CSSParser.cpp: (WebCore::CSSParser::parseValue): Cleaned up parsing of the font-weight property.
  • css/CSSStyleSelector.cpp: (WebCore::CSSStyleSelector::applyProperty): Changed to apply all CSS weight values to the font description.
  • platform/graphics/Font.h: (WebCore::Font::weight): Updated for the change to FontDescription::weight().
  • platform/graphics/FontCache.cpp: (WebCore::FontPlatformDataCacheKey::FontPlatformDataCacheKey): Replaced the bold component of the key with a weight component. (WebCore::FontPlatformDataCacheKey::operator==): Updated for the above. (WebCore::computeHash): Ditto. (WebCore::FontPlatformDataCacheKeyTraits::deletedValue): Removed unnecessary parameters. (WebCore::FontPlatformDataCacheKeyTraits::emptyValue): Ditto. (WebCore::FontCache::getCachedFontPlatformData): Updated for the change in FontPlatformDataCacheKey.
  • platform/graphics/FontDescription.cpp: Added. (WebCore::FontDescription::lighterWeight): Added. Returns a lighter CSS font-weight value if there is one, or the lightest value. (WebCore::FontDescription::bolderWeight): Added. Returns a heavier CSS font-weight value if there is one, or the heaviest value.
  • platform/graphics/FontDescription.h: (WebCore::FontWeight): Added this enumeration. (WebCore::FontDescription::FontDescription): (WebCore::FontDescription::bold): Removed. (WebCore::FontDescription::weight): Changed to return a FontWeight. (WebCore::FontDescription::setBold): Removed. (WebCore::FontDescription::setWeight): Changed to take a FontWeight.
  • platform/graphics/mac/FontCacheMac.mm: (WebCore::toAppKitFontWeight): Added. Maps a FontWeight to the AppKit font weight scale of 0-15. (WebCore::isAppKitFontWeightBold): Added. (WebCore::FontCache::getFontDataForCharacters): Changed to use a weight instead of the bold trait for custom fonts, and to decide whether to synthesize bold based on the weights rather than the bold trait. (WebCore::FontCache::fontExists): Updated for the change in WebFontCache . (WebCore::FontCache::createFontPlatformData): Ditto. Also changed to decide whether to synthesize bold based on the weights rather than on the bold trait.
  • platform/graphics/win/FontCacheWin.cpp: (WebCore::toGDIFontWeight): Added. Maps a FontWeight to a GDI font weight constant. (WebCore::isGDIFontWeightBold): Added. (WebCore::adjustedGDIFontWeight): Added. (WebCore::MatchImprovingProcData::MatchImprovingProcData): Added this data structure for use by the following callback. (WebCore::matchImprovingEnumProc): Added. The logic of this method is a simplification of the betterChoice() predicate in WebFontCache.mm, which considers only the italic trait and the weight. (WebCore::createGDIFont): Added. Similarly to +[WebFontCache fontWithFamily:traits:weight:size:], this function finds the closest match in the family for the desired italic bit and weight. (WebCore::FontCache::fontExists): Changed to call createGDIFont(). (WebCore::FontCache::createFontPlatformData): Ditto. Also changed to compute the synthetic bold and synthetic italic flags based on weights and italic bits and pass them to the FontPlatformData constructor.
  • platform/graphics/win/FontPlatformDataWin.cpp: (WebCore::FontPlatformData::FontPlatformData): Changed the bold and oblique parameters to mean whether these should be synthesized and removed the font enumeration code that used to decide that.
  • platform/graphics/win/SimpleFontDataWin.cpp: (WebCore::SimpleFontData::smallCapsFontData): Changed to pass the synthetic bold and oblique flags from the full-size FontPlatformData to the FontPlatformData constructor for the small caps font.
  • platform/mac/WebCoreTextRenderer.h:
  • platform/mac/WebCoreTextRenderer.mm: (WebCoreFindFont): Added a weight parameter, which is passed to +[WebFontCache fontWithFamily:traits:weight:size:].
  • platform/mac/WebFontCache.h:
  • platform/mac/WebFontCache.mm: (acceptableChoice): (betterChoice): Changed to ignore the bold trait. Changed the logic for deciding based on weights to prefer the font whose weight is closer to the desired one, or, if both candidates' weights are the same distance from the desired weight, the one that is more "off-center". (+[WebFontCache internalFontWithFamily:traits:weight:size:]): Changed to check for weight when matching by full name. Changed to pass the actual desired weight instead of the constant 5 to acceptableChoice() and betterChoice(). Changed to use weights to decide whether to synthesize bold. (+[WebFontCache fontWithFamily:traits:weight:size:]): Added a weight parameter, which is passed to the internal method.
  • platform/win/PopupMenuWin.cpp: (WebCore::PopupMenu::paint): Updated for the change to FontDescription.
  • rendering/RenderListBox.cpp: (WebCore::RenderListBox::updateFromElement): Ditto. (WebCore::RenderListBox::paintItemForeground): Ditto.
  • rendering/RenderThemeMac.mm: (WebCore::toFontWeight): Added. Maps the AppKit font weight range of 0-15 to the FontWeight range. (WebCore::RenderThemeMac::systemFont): Updated for the change to FontDescription.
  • rendering/RenderThemeSafari.cpp: (WebCore::RenderThemeSafari::systemFont): Ditto.

WebKit/mac:

2008-04-03 Nicholas Shanks <webkit@nickshanks.com>

Updated by Dan Bernstein. Reviewed by Dave Hyatt.

  • WebView/WebHTMLView.mm: (-[WebHTMLView _styleFromFontAttributes:]): (-[WebHTMLView _originalFontB]): (-[WebHTMLView _addToStyle:fontA:fontB:]):

WebKit/win:

2008-04-03 Dan Bernstein <mitz@apple.com>

Reviewed by Dave Hyatt.

  • DOMCoreClasses.cpp: (DOMElement::font): Updated for the change to FontDescription.
  • WebCoreSupport/WebDragClient.cpp: (dragLabelFont): Ditto.
  • WebKitGraphics.cpp: (makeFont): Ditto.
  • WebKitGraphics.h: Added a FIXME.
Location:
trunk
Files:
1 added
29 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r31619 r31620  
     12008-04-03  Nicholas Shanks  <webkit@nickshanks.com>
     2
     3        Updated by Dan Bernstein. Reviewed by Dave Hyatt.
     4
     5        - WebCore part of fixing http://bugs.webkit.org/show_bug.cgi?id=6484
     6          font-weight does not properly support graded weights
     7
     8        Tests to come: <http://bugs.webkit.org/show_bug.cgi?id=18306>
     9
     10        Build fixes for platforms other than Mac and Windows to come.
     11
     12        * WebCore.vcproj/WebCore.vcproj: Added FontDescription.cpp.
     13
     14        * WebCore.xcodeproj/project.pbxproj: Ditto.
     15
     16        * css/CSSComputedStyleDeclaration.cpp:
     17        (WebCore::CSSComputedStyleDeclaration::getPropertyCSSValue): Changed to
     18        return additional weight value keywords 100, 200, 300, 500, 600, 800
     19        and 900.
     20
     21        * css/CSSFontSelector.cpp:
     22        (WebCore::hashForFont): Changed the bold parameter into a weight
     23        parameter and added the weight to the string to be hashed.
     24        (WebCore::CSSFontSelector::addFontFaceRule): Changed to apply all CSS
     25        weight values to the font description.
     26        (WebCore::CSSFontSelector::getFontData): Updated the fallback logic to
     27        go through all weights equal or lighter from the desired weight. For
     28        SVG, to also consider heavier weights.
     29
     30        * css/CSSParser.cpp:
     31        (WebCore::CSSParser::parseValue): Cleaned up parsing of the font-weight
     32        property.
     33
     34        * css/CSSStyleSelector.cpp:
     35        (WebCore::CSSStyleSelector::applyProperty): Changed to apply all CSS
     36        weight values to the font description.
     37
     38        * platform/graphics/Font.h:
     39        (WebCore::Font::weight): Updated for the change to
     40        FontDescription::weight().
     41
     42        * platform/graphics/FontCache.cpp:
     43        (WebCore::FontPlatformDataCacheKey::FontPlatformDataCacheKey): Replaced
     44        the bold component of the key with a weight component.
     45        (WebCore::FontPlatformDataCacheKey::operator==): Updated for the above.
     46        (WebCore::computeHash): Ditto.
     47        (WebCore::FontPlatformDataCacheKeyTraits::deletedValue): Removed
     48        unnecessary parameters.
     49        (WebCore::FontPlatformDataCacheKeyTraits::emptyValue): Ditto.
     50        (WebCore::FontCache::getCachedFontPlatformData): Updated for the change
     51        in FontPlatformDataCacheKey.
     52
     53        * platform/graphics/FontDescription.cpp: Added.
     54        (WebCore::FontDescription::lighterWeight): Added. Returns a lighter CSS
     55        font-weight value if there is one, or the lightest value.
     56        (WebCore::FontDescription::bolderWeight): Added. Returns a heavier CSS
     57        font-weight value if there is one, or the heaviest value.
     58
     59        * platform/graphics/FontDescription.h:
     60        (WebCore::FontWeight): Added this enumeration.
     61        (WebCore::FontDescription::FontDescription):
     62        (WebCore::FontDescription::bold): Removed.
     63        (WebCore::FontDescription::weight): Changed to return a FontWeight.
     64        (WebCore::FontDescription::setBold): Removed.
     65        (WebCore::FontDescription::setWeight): Changed to take a FontWeight.
     66
     67        * platform/graphics/mac/FontCacheMac.mm:
     68        (WebCore::toAppKitFontWeight): Added. Maps a FontWeight to the AppKit
     69        font weight scale of 0-15.
     70        (WebCore::isAppKitFontWeightBold): Added.
     71        (WebCore::FontCache::getFontDataForCharacters): Changed to use a weight
     72        instead of the bold trait for custom fonts, and to decide whether to
     73        synthesize bold based on the weights rather than the bold trait.
     74        (WebCore::FontCache::fontExists): Updated for the change in
     75        WebFontCache .
     76        (WebCore::FontCache::createFontPlatformData): Ditto. Also changed to
     77        decide whether to synthesize bold based on the weights rather than on
     78        the bold trait.
     79
     80        * platform/graphics/win/FontCacheWin.cpp:
     81        (WebCore::toGDIFontWeight): Added. Maps a FontWeight to a GDI font
     82        weight constant.
     83        (WebCore::isGDIFontWeightBold): Added.
     84        (WebCore::adjustedGDIFontWeight): Added.
     85        (WebCore::MatchImprovingProcData::MatchImprovingProcData): Added this
     86        data structure for use by the following callback.
     87        (WebCore::matchImprovingEnumProc): Added. The logic of this method is a
     88        simplification of the betterChoice() predicate in WebFontCache.mm, which
     89        considers only the italic trait and the weight.
     90        (WebCore::createGDIFont): Added. Similarly to
     91        +[WebFontCache fontWithFamily:traits:weight:size:], this function
     92        finds the closest match in the family for the desired italic bit and
     93        weight.
     94        (WebCore::FontCache::fontExists): Changed to call createGDIFont().
     95        (WebCore::FontCache::createFontPlatformData): Ditto. Also changed to
     96        compute the synthetic bold and synthetic italic flags based on weights
     97        and italic bits and pass them to the FontPlatformData constructor.
     98
     99        * platform/graphics/win/FontPlatformDataWin.cpp:
     100        (WebCore::FontPlatformData::FontPlatformData): Changed the bold and
     101        oblique parameters to mean whether these should be synthesized and
     102        removed the font enumeration code that used to decide that.
     103
     104        * platform/graphics/win/SimpleFontDataWin.cpp:
     105        (WebCore::SimpleFontData::smallCapsFontData): Changed to pass the
     106        synthetic bold and oblique flags from the full-size FontPlatformData to
     107        the FontPlatformData constructor for the small caps font.
     108
     109        * platform/mac/WebCoreTextRenderer.h:
     110        * platform/mac/WebCoreTextRenderer.mm:
     111        (WebCoreFindFont): Added a weight parameter, which is passed to
     112        +[WebFontCache fontWithFamily:traits:weight:size:].
     113
     114        * platform/mac/WebFontCache.h:
     115        * platform/mac/WebFontCache.mm:
     116        (acceptableChoice):
     117        (betterChoice): Changed to ignore the bold trait. Changed the logic for
     118        deciding based on weights to prefer the font whose weight is closer to
     119        the desired one, or, if both candidates' weights are the same distance
     120        from the desired weight, the one that is more "off-center".
     121        (+[WebFontCache internalFontWithFamily:traits:weight:size:]): Changed to
     122        check for weight when matching by full name. Changed to pass
     123        the actual desired weight instead of the constant 5 to
     124        acceptableChoice() and betterChoice(). Changed to use weights to decide
     125        whether to synthesize bold.
     126        (+[WebFontCache fontWithFamily:traits:weight:size:]): Added a weight
     127        parameter, which is passed to the internal method.
     128
     129        * platform/win/PopupMenuWin.cpp:
     130        (WebCore::PopupMenu::paint): Updated for the change to FontDescription.
     131
     132        * rendering/RenderListBox.cpp:
     133        (WebCore::RenderListBox::updateFromElement): Ditto.
     134        (WebCore::RenderListBox::paintItemForeground): Ditto.
     135
     136        * rendering/RenderThemeMac.mm:
     137        (WebCore::toFontWeight): Added. Maps the AppKit font weight range of
     138        0-15 to the FontWeight range.
     139        (WebCore::RenderThemeMac::systemFont): Updated for the change to
     140        FontDescription.
     141
     142        * rendering/RenderThemeSafari.cpp:
     143        (WebCore::RenderThemeSafari::systemFont): Ditto.
     144
    11452008-04-03  Dan Bernstein  <mitz@apple.com>
    2146
  • trunk/WebCore/WebCore.vcproj/WebCore.vcproj

    r31609 r31620  
    46564656                                </File>
    46574657                                <File
     4658                                        RelativePath="..\platform\graphics\FontDescription.cpp"
     4659                                        >
     4660                                </File>
     4661                                <File
    46584662                                        RelativePath="..\platform\graphics\FontDescription.h"
    46594663                                        >
  • trunk/WebCore/WebCore.xcodeproj/project.pbxproj

    r31608 r31620  
    366366                37919C240B7D188600A56998 /* PositionIterator.h in Headers */ = {isa = PBXBuildFile; fileRef = 37919C220B7D188600A56998 /* PositionIterator.h */; settings = {ATTRIBUTES = (); }; };
    367367                37ACCE420DA2980F0089E602 /* FontRenderingMode.h in Headers */ = {isa = PBXBuildFile; fileRef = 37ACCE410DA2980F0089E602 /* FontRenderingMode.h */; settings = {ATTRIBUTES = (Private, ); }; };
     368                37ACCF690DA414E70089E602 /* FontDescription.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 37ACCE620DA2AA960089E602 /* FontDescription.cpp */; };
    368369                37F818FD0D657606005E1F05 /* WebCoreURLResponse.h in Headers */ = {isa = PBXBuildFile; fileRef = 37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */; settings = {ATTRIBUTES = (Private, ); }; };
    369370                37F818FE0D657606005E1F05 /* WebCoreURLResponse.mm in Sources */ = {isa = PBXBuildFile; fileRef = 37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */; };
     
    47504751                37919C220B7D188600A56998 /* PositionIterator.h */ = {isa = PBXFileReference; fileEncoding = 30; lastKnownFileType = sourcecode.c.h; path = PositionIterator.h; sourceTree = "<group>"; };
    47514752                37ACCE410DA2980F0089E602 /* FontRenderingMode.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = FontRenderingMode.h; sourceTree = "<group>"; };
     4753                37ACCE620DA2AA960089E602 /* FontDescription.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = FontDescription.cpp; sourceTree = "<group>"; };
    47524754                37F818FB0D657606005E1F05 /* WebCoreURLResponse.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WebCoreURLResponse.h; sourceTree = "<group>"; };
    47534755                37F818FC0D657606005E1F05 /* WebCoreURLResponse.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WebCoreURLResponse.mm; sourceTree = "<group>"; };
     
    1165811660                                371F4F3F0D25B9AF00ECE0D5 /* FontData.cpp */,
    1165911661                                371F4F3E0D25B9AF00ECE0D5 /* FontData.h */,
     11662                                37ACCE620DA2AA960089E602 /* FontDescription.cpp */,
    1166011663                                B2C3DA550D006CD600EF6F26 /* FontDescription.h */,
    1166111664                                B2C3DA560D006CD600EF6F26 /* FontFallbackList.cpp */,
     
    1634516348                                BCE1C43B0D9830D3003B02F2 /* JSLocation.cpp in Sources */,
    1634616349                                BCE1C4400D9830F4003B02F2 /* JSLocationCustom.cpp in Sources */,
     16350                                37ACCF690DA414E70089E602 /* FontDescription.cpp in Sources */,
    1634716351                                BC53C6080DA56C570021EB5D /* Gradient.cpp in Sources */,
    1634816352                                BC53C60B0DA56CF10021EB5D /* GradientCG.cpp in Sources */,
  • trunk/WebCore/css/CSSComputedStyleDeclaration.cpp

    r31160 r31620  
    44 * Copyright (C) 2004, 2005, 2006, 2007 Apple Inc. All rights reserved.
    55 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
     6 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    67 *
    78 * This library is free software; you can redistribute it and/or
     
    520521            return new CSSPrimitiveValue(CSSValueNormal);
    521522        case CSSPropertyFontWeight:
    522             // FIXME: this does not reflect the full range of weights
    523             // that can be expressed with CSS
    524             if (style->fontDescription().weight() == cBoldWeight)
    525                 return new CSSPrimitiveValue(CSSValueBold);
     523            switch (style->fontDescription().weight()) {
     524                case FontWeight100:
     525                    return new CSSPrimitiveValue(CSSValue100);
     526                case FontWeight200:
     527                    return new CSSPrimitiveValue(CSSValue200);
     528                case FontWeight300:
     529                    return new CSSPrimitiveValue(CSSValue300);
     530                case FontWeightNormal:
     531                    return new CSSPrimitiveValue(CSSValueNormal);
     532                case FontWeight500:
     533                    return new CSSPrimitiveValue(CSSValue500);
     534                case FontWeight600:
     535                    return new CSSPrimitiveValue(CSSValue600);
     536                case FontWeightBold:
     537                    return new CSSPrimitiveValue(CSSValueBold);
     538                case FontWeight800:
     539                    return new CSSPrimitiveValue(CSSValue800);
     540                case FontWeight900:
     541                    return new CSSPrimitiveValue(CSSValue900);
     542            }
     543            ASSERT_NOT_REACHED();
    526544            return new CSSPrimitiveValue(CSSValueNormal);
    527545        case CSSPropertyHeight:
  • trunk/WebCore/css/CSSFontSelector.cpp

    r31309 r31620  
    7777}
    7878
    79 static String hashForFont(const String& familyName, bool bold, bool italic)
     79static String hashForFont(const String& familyName, FontWeight weight, bool italic)
    8080{
    8181    String familyHash(familyName);
    82     if (bold)
    83         familyHash += "-webkit-bold";
     82    familyHash += "-webkit-weight-";
     83    familyHash += String::number(weight);
    8484    if (italic)
    8585        familyHash += "-webkit-italic";
     
    114114
    115115    if (RefPtr<CSSValue> fontWeight = style->getPropertyCSSValue(CSSPropertyFontWeight)) {
    116         // FIXME: Need to support weights for real, since we're effectively limiting the number of supported weights to two.
    117         // This behavior could also result in the "last kinda bold variant" described winning even if it isn't the best match for bold.
    118116        switch (static_cast<CSSPrimitiveValue*>(fontWeight.get())->getIdent()) {
     117            case CSSValueBolder:
    119118            case CSSValueBold:
    120             case CSSValueBolder:
     119            case CSSValue700:
     120                fontDescription.setWeight(FontWeightBold);
     121                break;
     122            case CSSValueNormal:
     123            case CSSValue400:
     124                fontDescription.setWeight(FontWeightNormal);
     125                break;
     126            case CSSValue900:
     127                fontDescription.setWeight(FontWeight900);
     128                break;
     129            case CSSValue800:
     130                fontDescription.setWeight(FontWeight800);
     131                break;
    121132            case CSSValue600:
    122             case CSSValue700:
    123             case CSSValue800:
    124             case CSSValue900:
    125                 fontDescription.setWeight(cBoldWeight);
     133                fontDescription.setWeight(FontWeight600);
     134                break;
     135            case CSSValue500:
     136                fontDescription.setWeight(FontWeight500);
     137                break;
     138            case CSSValue300:
     139                fontDescription.setWeight(FontWeight300);
     140                break;
     141            case CSSValueLighter:
     142            case CSSValue200:
     143                fontDescription.setWeight(FontWeight200);
     144                break;
     145            case CSSValue100:
     146                fontDescription.setWeight(FontWeight100);
     147                break;
    126148            default:
    127149                break;
     
    243265#endif
    244266
    245         String hash = hashForFont(familyName.lower(), fontDescription.bold(), fontDescription.italic());
     267        String hash = hashForFont(familyName.lower(), fontDescription.weight(), fontDescription.italic());
    246268        CSSSegmentedFontFace* segmentedFontFace = m_fonts.get(hash).get();
    247269        if (!segmentedFontFace) {
     
    282304        return 0;
    283305   
    284     bool bold = fontDescription.bold();
     306    FontWeight weight = fontDescription.weight();
    285307    bool italic = fontDescription.italic();
    286308   
     
    290312    String family = familyName.string().lower();
    291313
    292 #if ENABLE(SVG_FONTS)
    293314    RefPtr<CSSSegmentedFontFace> face;
    294315
    295     if (fontDescription.smallCaps()) {
    296         String testFamily = family + "-webkit-svg-small-caps";
    297         face = m_fonts.get(hashForFont(testFamily, bold, italic));
    298     } else
    299         face = m_fonts.get(hashForFont(family, bold, italic));
    300 #else
    301     RefPtr<CSSSegmentedFontFace> face = m_fonts.get(hashForFont(family, bold, italic));
    302 #endif
    303 
    304     // If we don't find a face, and if bold/italic are set, we should try other variants.
    305     // Bold/italic should try bold first, then italic, then normal (on the assumption that we are better at synthesizing italic than we are
    306     // at synthesizing bold).
    307     if (!face) {
    308         if (bold && italic) {
    309             syntheticItalic = true;
    310             face = m_fonts.get(hashForFont(family, bold, false));
    311             if (!face) {
    312                 syntheticBold = true;
    313                 face = m_fonts.get(hashForFont(family, false, italic));
    314             }
    315         }
    316        
    317         // Bold should try normal.
    318         // Italic should try normal.
    319         if (!face && (bold || italic)) {
    320             syntheticBold = bold;
    321             syntheticItalic = italic;
    322             face = m_fonts.get(hashForFont(family, false, false));
    323         }
     316#if ENABLE(SVG_FONTS)
     317    if (fontDescription.smallCaps())
     318        family += "-webkit-svg-small-caps";
     319#endif
     320
     321    // If we don't find a face, we should try synthesizing it from another variant. We are presumably better at synthesizing italic than
     322    // synthesizing bold, and we cannot synthesize a lighter face at all.
     323    int attemptedWeight = weight;
     324    while (!face) {
     325        face = m_fonts.get(hashForFont(family, static_cast<FontWeight>(attemptedWeight), italic));
     326        if (face)
     327            break;
     328        if (italic) {
     329            face = m_fonts.get(hashForFont(family, static_cast<FontWeight>(attemptedWeight), false));
     330            if (face) {
     331                syntheticItalic = true;
     332                break;
     333            }
     334        }
     335        if (attemptedWeight == FontWeight100)
     336            break;
     337        attemptedWeight--;
     338        syntheticBold = true;
    324339    }
    325340
     
    329344    // And the font-family requested is non-bold & non-italic. For SVG Fonts we still
    330345    // have to return the defined font, and not fallback to the system default.
    331     if (!face && !bold)
    332         face = m_fonts.get(hashForFont(family, true, italic));
    333 
    334     if (!face && !italic)
    335         face = m_fonts.get(hashForFont(family, bold, true));
    336 
    337     if (!face && !bold && !italic)
    338         face = m_fonts.get(hashForFont(family, true, true));
     346    if (!face) {
     347        syntheticBold = false;
     348        // Try all heavier weights
     349        for (attemptedWeight = weight + 1; !face && attemptedWeight <= FontWeight900; ++attemptedWeight)
     350            face = m_fonts.get(hashForFont(family, static_cast<FontWeight>(attemptedWeight), italic));
     351
     352        // Try italics with all weights
     353        if (!face && !italic) {
     354            for (attemptedWeight = weight; !face && attemptedWeight >= FontWeight100; --attemptedWeight)
     355                face = m_fonts.get(hashForFont(family, static_cast<FontWeight>(attemptedWeight), true));
     356
     357            for (attemptedWeight = weight + 1; !face && attemptedWeight <= FontWeight900; ++attemptedWeight)
     358                face = m_fonts.get(hashForFont(family, static_cast<FontWeight>(attemptedWeight), true));
     359        }
     360    }
    339361#endif
    340362
  • trunk/WebCore/css/CSSParser.cpp

    r31453 r31620  
    33 * Copyright (C) 2005 Allan Sandfeld Jensen (kde@carewolf.com)
    44 * Copyright (C) 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
     5 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    56 *
    67 * This library is free software; you can redistribute it and/or
     
    729730        break;
    730731
    731     case CSSPropertyFontWeight:  // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 |
    732         // 500 | 600 | 700 | 800 | 900 | inherit
     732    case CSSPropertyFontWeight:  // normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900 | inherit
    733733        if (id >= CSSValueNormal && id <= CSSValue900) {
    734             // Allready correct id
    735             valid_primitive = true;
    736         } else if (validUnit(value, FInteger|FNonNeg, false)) {
    737             int weight = (int)value->fValue;
    738             if ((weight % 100))
     734            // Valid weight keyword
     735            valid_primitive = true;
     736        } else if (validUnit(value, FInteger | FNonNeg, false)) {
     737            int weight = static_cast<int>(value->fValue);
     738            if (weight % 100)
    739739                break;
    740740            weight /= 100;
  • trunk/WebCore/css/CSSStyleSelector.cpp

    r31530 r31620  
    22 * Copyright (C) 1999 Lars Knoll (knoll@kde.org)
    33 *           (C) 2004-2005 Allan Sandfeld Jensen (kde@carewolf.com)
    4  *           (C) 2006 Nicholas Shanks (webkit@nickshanks.com)
     4 * Copyright (C) 2006, 2007 Nicholas Shanks (webkit@nickshanks.com)
    55 * Copyright (C) 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
    66 * Copyright (C) 2007 Alexey Proskuryakov <ap@webkit.org>
     
    24292429            fontDescription.setWeight(m_parentStyle->fontDescription().weight());
    24302430        else if (isInitial)
    2431             fontDescription.setWeight(cNormalWeight);
     2431            fontDescription.setWeight(FontWeightNormal);
    24322432        else {
    24332433            if (!primitiveValue)
     
    24352435            if (primitiveValue->getIdent()) {
    24362436                switch (primitiveValue->getIdent()) {
    2437                     // FIXME: We aren't genuinely supporting specific weight values.
     2437                    case CSSValueBolder:
     2438                        fontDescription.setWeight(fontDescription.bolderWeight());
     2439                        break;
     2440                    case CSSValueLighter:
     2441                        fontDescription.setWeight(fontDescription.lighterWeight());
     2442                        break;
    24382443                    case CSSValueBold:
    2439                     case CSSValueBolder:
    2440                     case CSSValue600:
    24412444                    case CSSValue700:
    2442                     case CSSValue800:
    2443                     case CSSValue900:
    2444                         fontDescription.setWeight(cBoldWeight);
     2445                        fontDescription.setWeight(FontWeightBold);
    24452446                        break;
    24462447                    case CSSValueNormal:
    2447                     case CSSValueLighter:
     2448                    case CSSValue400:
     2449                        fontDescription.setWeight(FontWeightNormal);
     2450                        break;
     2451                    case CSSValue900:
     2452                        fontDescription.setWeight(FontWeight900);
     2453                        break;
     2454                    case CSSValue800:
     2455                        fontDescription.setWeight(FontWeight800);
     2456                        break;
     2457                    case CSSValue600:
     2458                        fontDescription.setWeight(FontWeight600);
     2459                        break;
     2460                    case CSSValue500:
     2461                        fontDescription.setWeight(FontWeight500);
     2462                        break;
     2463                    case CSSValue300:
     2464                        fontDescription.setWeight(FontWeight300);
     2465                        break;
     2466                    case CSSValue200:
     2467                        fontDescription.setWeight(FontWeight200);
     2468                        break;
    24482469                    case CSSValue100:
    2449                     case CSSValue200:
    2450                     case CSSValue300:
    2451                     case CSSValue400:
    2452                     case CSSValue500:
    2453                         fontDescription.setWeight(cNormalWeight);
     2470                        fontDescription.setWeight(FontWeight100);
    24542471                        break;
    24552472                    default:
    24562473                        return;
    24572474                }
    2458             }
    2459             else
    2460             {
    2461                 // ### fix parsing of 100-900 values in parser, apply them here
    2462             }
     2475            } else
     2476                ASSERT_NOT_REACHED();
    24632477        }
    24642478        if (m_style->setFontDescription(fontDescription))
  • trunk/WebCore/platform/graphics/Font.h

    r31342 r31620  
    197197
    198198    bool italic() const { return m_fontDescription.italic(); }
    199     unsigned weight() const { return m_fontDescription.weight(); }
    200     bool bold() const { return m_fontDescription.bold(); }
     199    FontWeight weight() const { return m_fontDescription.weight(); }
    201200
    202201#if !PLATFORM(QT)
  • trunk/WebCore/platform/graphics/FontCache.cpp

    r29663 r31620  
    11/*
    2  * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
     2 * Copyright (C) 2006 Apple Computer, Inc. All rights reserved.
     3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    4041
    4142struct FontPlatformDataCacheKey {
    42     FontPlatformDataCacheKey(const AtomicString& family = AtomicString(), unsigned size = 0, bool bold = false, bool italic = false,
     43    FontPlatformDataCacheKey(const AtomicString& family = AtomicString(), unsigned size = 0, unsigned weight = 0, bool italic = false,
    4344                             bool isPrinterFont = false, FontRenderingMode renderingMode = NormalRenderingMode)
    4445        : m_family(family)
    4546        , m_size(size)
    46         , m_bold(bold)
     47        , m_weight(weight)
    4748        , m_italic(italic)
    4849        , m_printerFont(isPrinterFont)
     
    5455    {
    5556        return equalIgnoringCase(m_family, other.m_family) && m_size == other.m_size &&
    56                m_bold == other.m_bold && m_italic == other.m_italic && m_printerFont == other.m_printerFont &&
     57               m_weight == other.m_weight && m_italic == other.m_italic && m_printerFont == other.m_printerFont &&
    5758               m_renderingMode == other.m_renderingMode;
    5859    }
     
    6061    AtomicString m_family;
    6162    unsigned m_size;
    62     bool m_bold;
     63    unsigned m_weight;
    6364    bool m_italic;
    6465    bool m_printerFont;
     
    7172        CaseFoldingHash::hash(fontKey.m_family),
    7273        fontKey.m_size,
    73         static_cast<unsigned>(fontKey.m_bold) << 3 | static_cast<unsigned>(fontKey.m_italic) << 2 | static_cast<unsigned>(fontKey.m_printerFont) << 1 |
    74         static_cast<unsigned>(fontKey.m_renderingMode)
     74        fontKey.m_weight,
     75        static_cast<unsigned>(fontKey.m_italic) << 2 | static_cast<unsigned>(fontKey.m_printerFont) << 1 | static_cast<unsigned>(fontKey.m_renderingMode)
    7576    };
    76     return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), 4 * sizeof(unsigned) / sizeof(UChar));
     77    return StringImpl::computeHash(reinterpret_cast<UChar*>(hashCodes), sizeof(hashCodes) / sizeof(UChar));
    7778}
    7879
     
    9697    static const FontPlatformDataCacheKey& deletedValue()
    9798    {
    98         static FontPlatformDataCacheKey key(nullAtom, 0xFFFFFFFFU, false, false);
     99        static FontPlatformDataCacheKey key(nullAtom, 0xFFFFFFFFU);
    99100        return key;
    100101    }
    101102    static const FontPlatformDataCacheKey& emptyValue()
    102103    {
    103         static FontPlatformDataCacheKey key(nullAtom, 0, false, false);
     104        static FontPlatformDataCacheKey key(nullAtom);
    104105        return key;
    105106    }
     
    145146    }
    146147
    147     FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.bold(), fontDescription.italic(),
     148    FontPlatformDataCacheKey key(familyName, fontDescription.computedPixelSize(), fontDescription.weight(), fontDescription.italic(),
    148149                                 fontDescription.usePrinterFont(), fontDescription.renderingMode());
    149150    FontPlatformData* result = 0;
  • trunk/WebCore/platform/graphics/FontDescription.h

    r31531 r31620  
    44 *           (C) 2000 Dirk Mueller (mueller@kde.org)
    55 * Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008 Apple Inc. All rights reserved.
     6 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    67 *
    78 * This library is free software; you can redistribute it and/or
     
    3031namespace WebCore {
    3132
    32 const unsigned cNormalWeight = 50;
    33 const unsigned cBoldWeight = 63;
     33enum FontWeight {
     34    FontWeight100,
     35    FontWeight200,
     36    FontWeight300,
     37    FontWeight400,
     38    FontWeight500,
     39    FontWeight600,
     40    FontWeight700,
     41    FontWeight800,
     42    FontWeight900,
     43    FontWeightNormal = FontWeight400,
     44    FontWeightBold = FontWeight700
     45};
    3446
    3547class FontDescription {
     
    3951
    4052    FontDescription()
    41         : m_specifiedSize(0), m_computedSize(0),
    42           m_italic(false), m_smallCaps(false), m_isAbsoluteSize(false), m_weight(cNormalWeight),
    43           m_genericFamily(NoFamily), m_usePrinterFont(false), m_renderingMode(NormalRenderingMode), m_keywordSize(0)
    44           {}
    45    
     53        : m_specifiedSize(0)
     54        , m_computedSize(0)
     55        , m_italic(false)
     56        , m_smallCaps(false)
     57        , m_isAbsoluteSize(false)
     58        , m_weight(FontWeightNormal)
     59        , m_genericFamily(NoFamily)
     60        , m_usePrinterFont(false)
     61        , m_renderingMode(NormalRenderingMode)
     62        , m_keywordSize(0)
     63    {
     64    }
     65
    4666    bool operator==(const FontDescription&) const;
    4767    bool operator!=(const FontDescription& other) const { return !(*this == other); }
     
    5272    float computedSize() const { return m_computedSize; }
    5373    bool italic() const { return m_italic; }
    54     bool bold() const { return weight() == cBoldWeight; }
    5574    int computedPixelSize() const { return int(m_computedSize + 0.5f); }
    5675    bool smallCaps() const { return m_smallCaps; }
    5776    bool isAbsoluteSize() const { return m_isAbsoluteSize; }
    58     unsigned weight() const { return m_weight; }
     77    FontWeight weight() const { return static_cast<FontWeight>(m_weight); }
     78    FontWeight lighterWeight() const;
     79    FontWeight bolderWeight() const;
    5980    GenericFamilyType genericFamily() const { return static_cast<GenericFamilyType>(m_genericFamily); }
    6081    bool usePrinterFont() const { return m_usePrinterFont; }
     
    6687    void setSpecifiedSize(float s) { m_specifiedSize = s; }
    6788    void setItalic(bool i) { m_italic = i; }
    68     void setBold(bool b) { m_weight = (b ? cBoldWeight : cNormalWeight); }
    6989    void setSmallCaps(bool c) { m_smallCaps = c; }
    7090    void setIsAbsoluteSize(bool s) { m_isAbsoluteSize = s; }
    71     void setWeight(unsigned w) { m_weight = w; }
     91    void setWeight(FontWeight w) { m_weight = w; }
    7292    void setGenericFamily(GenericFamilyType genericFamily) { m_genericFamily = genericFamily; }
    7393    void setUsePrinterFont(bool p) { m_usePrinterFont = p; }
     
    86106    bool m_isAbsoluteSize : 1;   // Whether or not CSS specified an explicit size
    87107                                 // (logical sizes like "medium" don't count).
    88     unsigned m_weight : 8;
     108    unsigned m_weight : 8; // FontWeight
    89109    unsigned m_genericFamily : 3; // GenericFamilyType
    90110    bool m_usePrinterFont : 1;
  • trunk/WebCore/platform/graphics/mac/FontCacheMac.mm

    r29663 r31620  
    11/*
    22 * Copyright (C) 2006, 2007, 2008 Apple Inc. All rights reserved.
     3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    122123}
    123124
     125static int toAppKitFontWeight(FontWeight fontWeight)
     126{
     127    static int appKitFontWeights[] = {
     128        1,  // FontWeight100
     129        2,  // FontWeight200
     130        3,  // FontWeight300
     131        5,  // FontWeight400
     132        6,  // FontWeight500
     133        7,  // FontWeight600
     134        9,  // FontWeight700
     135        10, // FontWeight800
     136        12, // FontWeight900
     137    };
     138    return appKitFontWeights[fontWeight];
     139}
     140
     141static inline bool isAppKitFontWeightBold(NSInteger appKitFontWeight)
     142{
     143    return appKitFontWeight >= 7;
     144}
     145
    124146const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
    125147{
     
    127149    NSFont *nsFont = platformData.font();
    128150
    129     NSString *string = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(characters)
    130         length:length freeWhenDone:NO];
     151    NSString *string = [[NSString alloc] initWithCharactersNoCopy:const_cast<UChar*>(characters) length:length freeWhenDone:NO];
    131152    NSFont *substituteFont = wkGetFontInLanguageForRange(nsFont, string, NSMakeRange(0, length));
    132153    [string release];
     
    136157    if (!substituteFont)
    137158        return 0;
    138    
     159
    139160    // Use the family name from the AppKit-supplied substitute font, requesting the
    140161    // traits, weight, and size we want. One way this does better than the original
     
    143164    // doesn't actually cover the characters we need.
    144165
    145     NSFontManager *manager = [NSFontManager sharedFontManager];
     166    NSFontManager *fontManager = [NSFontManager sharedFontManager];
    146167
    147168    NSFontTraitMask traits;
     
    150171
    151172    if (nsFont) {
    152         traits = [manager traitsOfFont:nsFont];
     173        traits = [fontManager traitsOfFont:nsFont];
    153174        if (platformData.m_syntheticBold)
    154175            traits |= NSBoldFontMask;
    155176        if (platformData.m_syntheticOblique)
    156             traits |= NSItalicFontMask;
    157         weight = [manager weightOfFont:nsFont];
     177            traits |= NSFontItalicTrait;
     178        weight = [fontManager weightOfFont:nsFont];
    158179        size = [nsFont pointSize];
    159180    } else {
    160181        // For custom fonts nsFont is nil.
    161         traits = (font.bold() ? NSBoldFontMask : 0) | (font.italic() ? NSItalicFontMask : 0);
    162         weight = 5;
     182        traits = font.italic() ? NSFontItalicTrait : 0;
     183        weight = toAppKitFontWeight(font.weight());
    163184        size = font.pixelSize();
    164185    }
    165186
    166     NSFont *bestVariation = [manager fontWithFamily:[substituteFont familyName]
    167         traits:traits
    168         weight:weight
    169         size:size];
    170     if (bestVariation)
     187    if (NSFont *bestVariation = [fontManager fontWithFamily:[substituteFont familyName] traits:traits weight:weight size:size])
    171188        substituteFont = bestVariation;
    172189
    173     substituteFont = font.fontDescription().usePrinterFont()
    174         ? [substituteFont printerFont] : [substituteFont screenFont];
    175 
    176     NSFontTraitMask substituteFontTraits = [manager traitsOfFont:substituteFont];
     190    substituteFont = font.fontDescription().usePrinterFont() ? [substituteFont printerFont] : [substituteFont screenFont];
     191
     192    NSFontTraitMask substituteFontTraits = [fontManager traitsOfFont:substituteFont];
     193    NSInteger substituteFontWeight = [fontManager weightOfFont:substituteFont];
    177194
    178195    FontPlatformData alternateFont(substituteFont,
    179         !font.isPlatformFont() && (traits & NSBoldFontMask) && !(substituteFontTraits & NSBoldFontMask),
    180         !font.isPlatformFont() && (traits & NSItalicFontMask) && !(substituteFontTraits & NSItalicFontMask));
     196        !font.isPlatformFont() && isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(substituteFontWeight),
     197        !font.isPlatformFont() && (traits & NSFontItalicTrait) && !(substituteFontTraits & NSFontItalicTrait));
    181198    return getCachedFontData(&alternateFont);
    182199}
     
    223240bool FontCache::fontExists(const FontDescription& fontDescription, const AtomicString& family)
    224241{
    225     NSFontTraitMask traits = 0;
    226     if (fontDescription.italic())
    227         traits |= NSItalicFontMask;
    228     if (fontDescription.bold())
    229         traits |= NSBoldFontMask;
     242    NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
     243    int weight = toAppKitFontWeight(fontDescription.weight());
    230244    float size = fontDescription.computedPixelSize();
    231    
    232     NSFont* nsFont = [WebFontCache fontWithFamily:family traits:traits size:size];
    233     return nsFont != 0;
     245
     246    return [WebFontCache fontWithFamily:family traits:traits weight:weight size:size];
    234247}
    235248
    236249FontPlatformData* FontCache::createFontPlatformData(const FontDescription& fontDescription, const AtomicString& family)
    237250{
    238     NSFontTraitMask traits = 0;
    239     if (fontDescription.italic())
    240         traits |= NSItalicFontMask;
    241     if (fontDescription.bold())
    242         traits |= NSBoldFontMask;
     251    NSFontTraitMask traits = fontDescription.italic() ? NSFontItalicTrait : 0;
     252    NSInteger weight = toAppKitFontWeight(fontDescription.weight());
    243253    float size = fontDescription.computedPixelSize();
    244    
    245     NSFont* nsFont = [WebFontCache fontWithFamily:family traits:traits size:size];
     254
     255    NSFont *nsFont = [WebFontCache fontWithFamily:family traits:traits weight:weight size:size];
    246256    if (!nsFont)
    247257        return 0;
    248258
     259    NSFontManager *fontManager = [NSFontManager sharedFontManager];
    249260    NSFontTraitMask actualTraits = 0;
    250     if (fontDescription.bold() || fontDescription.italic())
    251         actualTraits = [[NSFontManager sharedFontManager] traitsOfFont:nsFont];
    252    
     261    if (fontDescription.italic())
     262        actualTraits = [fontManager traitsOfFont:nsFont];
     263    NSInteger actualWeight = [fontManager weightOfFont:nsFont];
     264
    253265    FontPlatformData* result = new FontPlatformData;
    254    
     266
    255267    // Use the correct font for print vs. screen.
    256268    result->setFont(fontDescription.usePrinterFont() ? [nsFont printerFont] : [nsFont screenFont]);
    257     result->m_syntheticBold = (traits & NSBoldFontMask) && !(actualTraits & NSBoldFontMask);
    258     result->m_syntheticOblique = (traits & NSItalicFontMask) && !(actualTraits & NSItalicFontMask);
     269    result->m_syntheticBold = isAppKitFontWeightBold(weight) && !isAppKitFontWeightBold(actualWeight);
     270    result->m_syntheticOblique = (traits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
    259271    return result;
    260272}
  • trunk/WebCore/platform/graphics/win/FontCacheWin.cpp

    r31507 r31620  
    309309}
    310310
     311static LONG toGDIFontWeight(FontWeight fontWeight)
     312{
     313    static LONG gdiFontWeights[] = {
     314        FW_THIN,        // FontWeight100
     315        FW_EXTRALIGHT,  // FontWeight200
     316        FW_LIGHT,       // FontWeight300
     317        FW_NORMAL,      // FontWeight400
     318        FW_MEDIUM,      // FontWeight500
     319        FW_SEMIBOLD,    // FontWeight600
     320        FW_BOLD,        // FontWeight700
     321        FW_EXTRABOLD,   // FontWeight800
     322        FW_HEAVY        // FontWeight900
     323    };
     324    return gdiFontWeights[fontWeight];
     325}
     326
     327static inline bool isGDIFontWeightBold(LONG gdiFontWeight)
     328{
     329    return gdiFontWeight >= FW_SEMIBOLD;
     330}
     331
     332static LONG adjustedGDIFontWeight(LONG gdiFontWeight, const String& family)
     333{
     334    static AtomicString lucidaStr("Lucida Grande");
     335    if (equalIgnoringCase(family, lucidaStr)) {
     336        if (gdiFontWeight == FW_NORMAL)
     337            return FW_MEDIUM;
     338        if (gdiFontWeight == FW_BOLD)
     339            return FW_SEMIBOLD;
     340    }
     341    return gdiFontWeight;
     342}
     343
     344struct MatchImprovingProcData {
     345    MatchImprovingProcData(LONG desiredWeight, bool desiredItalic)
     346        : m_desiredWeight(desiredWeight)
     347        , m_desiredItalic(desiredItalic)
     348        , m_hasMatched(false)
     349    {
     350    }
     351
     352    LONG m_desiredWeight;
     353    bool m_desiredItalic;
     354    bool m_hasMatched;
     355    LOGFONT m_chosen;
     356};
     357
     358static int CALLBACK matchImprovingEnumProc(CONST LOGFONT* candidate, CONST TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam)
     359{
     360    MatchImprovingProcData* matchData = reinterpret_cast<MatchImprovingProcData*>(lParam);
     361
     362    if (!matchData->m_hasMatched) {
     363        matchData->m_hasMatched = true;
     364        matchData->m_chosen = *candidate;
     365        return 1;
     366    }
     367
     368    if (!matchData->m_desiredItalic)
     369        // Prefer the candidate if it helps us lose undesired italics.
     370        if (matchData->m_chosen.lfItalic && !candidate->lfItalic) {
     371            matchData->m_chosen = *candidate;
     372            return 1;
     373        }
     374        // Reject the candidate if it adds undesired italics.
     375        if (candidate->lfItalic && !matchData->m_chosed.lfItalic)
     376            return 1;
     377    }
     378
     379    unsigned chosenWeightDeltaMagnitude = abs(matchData->m_chosen.lfWeight - matchData->m_desiredWeight);
     380    unsigned candidateWeightDeltaMagnitude = abs(candidate->lfWeight - matchData->m_desiredWeight);
     381
     382    // If both are the same distance from the desired weight, prefer the candidate if it is further from regular.
     383    if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude && abs(candidate->lfWeight - FW_NORMAL) > abs(matchData->m_chosen.lfWeight - FW_NORMAL)) {
     384        matchData->m_chosen = *candidate;
     385        return 1;
     386    }
     387
     388    // Otherwise, prefer the one closer to the desired weight.
     389    if (candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude)
     390        matchData->m_chosen = *candidate;
     391
     392    return 1;
     393}
     394
     395static HFONT createGDIFont(const AtomicString& family, LONG desiredWeight, bool desiredItalic, int size)
     396{
     397    HDC hdc = GetDC(0);
     398
     399    LOGFONT logFont;
     400    logFont.lfCharSet = DEFAULT_CHARSET;
     401    unsigned familyLength = min(family.length(), static_cast<unsigned>(LF_FACESIZE - 1));
     402    memcpy(logFont.lfFaceName, family.characters(), familyLength * sizeof(UChar));
     403    logFont.lfFaceName[familyLength] = 0;
     404    logFont.lfPitchAndFamily = 0;
     405
     406    MatchImprovingProcData matchData(desiredWeight, desiredItalic);
     407    EnumFontFamiliesEx(hdc, &logFont, matchImprovingEnumProc, reinterpret_cast<LPARAM>(&matchData), 0);
     408
     409    ReleaseDC(0, hdc);
     410
     411    if (!matchData.m_hasMatched)
     412        return 0;
     413
     414    matchData.m_chosen.lfHeight = -size;
     415    matchData.m_chosen.lfUnderline = false;
     416    matchData.m_chosen.lfStrikeOut = false;
     417#if PLATFORM(CG)
     418    matchData.m_chosen.lfOutPrecision = OUT_TT_ONLY_PRECIS;
     419#else
     420    matchData.m_chosen.lfOutPrecision = OUT_TT_PRECIS;
     421#endif
     422    matchData.m_chosen.lfQuality = CLEARTYPE_QUALITY;
     423
     424    return CreateFontIndirect(&matchData.m_chosen);
     425}
     426
    311427bool FontCache::fontExists(const FontDescription& fontDescription, const AtomicString& family)
    312428{
    313     LOGFONT winfont;
    314 
    315     // The size here looks unusual.  The negative number is intentional.  The logical size constant is 32.
    316     winfont.lfHeight = -fontDescription.computedPixelSize() * 32;
    317     winfont.lfWidth = 0;
    318     winfont.lfEscapement = 0;
    319     winfont.lfOrientation = 0;
    320     winfont.lfUnderline = false;
    321     winfont.lfStrikeOut = false;
    322     winfont.lfCharSet = DEFAULT_CHARSET;
    323 #if PLATFORM(CG)
    324     winfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
    325 #else
    326     winfont.lfOutPrecision = OUT_TT_PRECIS;
    327 #endif
    328     winfont.lfQuality = CLEARTYPE_QUALITY;
    329     winfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    330     winfont.lfItalic = fontDescription.italic();
    331 
    332     // FIXME: Support weights for real.  Do our own enumeration of the available weights.
    333     // We can't rely on Windows here, since we need to follow the CSS2 algorithm for how to fill in
    334     // gaps in the weight list.
    335     // FIXME: Hardcoding Lucida Grande for now.  It uses different weights than typical Win32 fonts
    336     // (500/600 instead of 400/700).
    337     static AtomicString lucidaStr("Lucida Grande");
    338     if (equalIgnoringCase(family, lucidaStr))
    339         winfont.lfWeight = fontDescription.bold() ? 600 : 500;
    340     else
    341         winfont.lfWeight = fontDescription.bold() ? 700 : 400;
    342     int len = min(family.length(), (unsigned int)LF_FACESIZE - 1);
    343     memcpy(winfont.lfFaceName, family.characters(), len * sizeof(WORD));
    344     winfont.lfFaceName[len] = '\0';
    345 
    346     HFONT hfont = CreateFontIndirect(&winfont);
    347     // Windows will always give us a valid pointer here, even if the face name is non-existent.  We have to double-check
    348     // and see if the family name was really used.
    349     HDC dc = GetDC(0);
    350     SaveDC(dc);
    351     SelectObject(dc, hfont);
    352     WCHAR name[LF_FACESIZE];
    353     GetTextFace(dc, LF_FACESIZE, name);
    354     RestoreDC(dc, -1);
    355     ReleaseDC(0, dc);
    356 
     429    HFONT hfont = createGDIFont(family, adjustedGDIFontWeight(toGDIFontWeight(fontDescription.weight()), family),
     430                                fontDescription.italic(), fontDescription.computedPixelSize());
     431
     432    bool result = hfont;
    357433    DeleteObject(hfont);
    358434
    359     return !wcsicmp(winfont.lfFaceName, name);
     435    return result;
    360436}
    361437
     
    369445    bool useGDI = fontDescription.renderingMode() == AlternateRenderingMode && !isLucidaGrande;
    370446
    371     LOGFONT winfont;
    372 
    373     // The size here looks unusual.  The negative number is intentional.  The logical size constant is 32. We do this
    374     // for subpixel precision when rendering using Uniscribe.  This masks rounding errors related to the HFONT metrics being
    375     // different from the CGFont metrics.
    376     // FIXME: We will eventually want subpixel precision for GDI mode, but the scaled rendering doesn't look as nice.  That may be solvable though.
    377     winfont.lfHeight = -fontDescription.computedPixelSize() * (useGDI ? 1 : 32);
    378     winfont.lfWidth = 0;
    379     winfont.lfEscapement = 0;
    380     winfont.lfOrientation = 0;
    381     winfont.lfUnderline = false;
    382     winfont.lfStrikeOut = false;
    383     winfont.lfCharSet = DEFAULT_CHARSET;
    384     winfont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
    385     winfont.lfQuality = DEFAULT_QUALITY;
    386     winfont.lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    387     winfont.lfItalic = fontDescription.italic();
    388 
    389     // FIXME: Support weights for real.  Do our own enumeration of the available weights.
    390     // We can't rely on Windows here, since we need to follow the CSS2 algorithm for how to fill in
    391     // gaps in the weight list.
    392     // FIXME: Hardcoding Lucida Grande for now.  It uses different weights than typical Win32 fonts
    393     // (500/600 instead of 400/700).
    394     if (isLucidaGrande) {
    395         winfont.lfWeight = fontDescription.bold() ? 600 : 500;
     447    // The logical size constant is 32. We do this for subpixel precision when rendering using Uniscribe.
     448    // This masks rounding errors related to the HFONT metrics being  different from the CGFont metrics.
     449    // FIXME: We will eventually want subpixel precision for GDI mode, but the scaled rendering doesn't
     450    // look as nice. That may be solvable though.
     451    LONG weight = adjustedGDIFontWeight(toGDIFontWeight(fontDescription.weight()), family);
     452    HFONT hfont = createGDIFont(family, weight, fontDescription.italic(), fontDescription.computedPixelSize() * (useGDI ? 1 : 32));
     453
     454    if (!hfont)
     455        return 0;
     456
     457    if (isLucidaGrande)
    396458        useGDI = false; // Never use GDI for Lucida Grande.
    397     } else
    398         winfont.lfWeight = fontDescription.bold() ? 700 : 400;
    399     int len = min(family.length(), (unsigned int)LF_FACESIZE - 1);
    400     memcpy(winfont.lfFaceName, family.characters(), len * sizeof(WORD));
    401     winfont.lfFaceName[len] = '\0';
    402 
    403     HFONT hfont = CreateFontIndirect(&winfont);
    404     // Windows will always give us a valid pointer here, even if the face name is non-existent.  We have to double-check
    405     // and see if the family name was really used.
    406     HDC dc = GetDC(0);
    407     SaveDC(dc);
    408     SelectObject(dc, hfont);
    409     WCHAR name[LF_FACESIZE];
    410     GetTextFace(dc, LF_FACESIZE, name);
    411     RestoreDC(dc, -1);
    412     ReleaseDC(0, dc);
    413 
    414     if (_wcsicmp(winfont.lfFaceName, name)) {
    415         DeleteObject(hfont);
    416         return 0;
    417     }
    418    
    419     FontPlatformData* result = new FontPlatformData(hfont, fontDescription.computedPixelSize(),
    420                                                     fontDescription.bold(), fontDescription.italic(), useGDI);
     459
     460    LOGFONT logFont;
     461    GetObject(hfont, sizeof(LOGFONT), &logFont);
     462
     463    bool synthesizeBold = isGDIFontWeightBold(weight) && !isGDIFontWeightBold(logFont.lfWeight);
     464    bool synthesizeItalic = fontDescription.italic() && !logFont.lfItalic;
     465
     466    FontPlatformData* result = new FontPlatformData(hfont, fontDescription.computedPixelSize(), synthesizeBold, synthesizeItalic, useGDI);
    421467
    422468#if PLATFORM(CG)
  • trunk/WebCore/platform/graphics/win/FontPlatformDataWin.cpp

    r31507 r31620  
    3636namespace WebCore {
    3737
    38 static const int Bold = (1 << 0);
    39 static const int Italic = (1 << 1);
    40 static const int BoldOblique = (1 << 2);
    41 
    42 static int CALLBACK enumStylesCallback(const LOGFONT* logFont, const TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam)
    43 {
    44     int *style = reinterpret_cast<int*>(lParam);
    45 
    46     // FIXME: In order to accommodate Lucida we go ahead and consider a weight of 600 to be bold.
    47     // This does mean we'll consider demibold and semibold fonts on windows to also be bold.  This
    48     // is rare enough that it seems like an ok hack for now.
    49     if (logFont->lfWeight >= 600) {
    50         if (logFont->lfItalic)
    51             *style |= BoldOblique;
    52         else
    53             *style |= Bold;
    54     } else if (logFont->lfItalic)
    55         *style |= Italic;
    56 
    57     return 1;
    58 }
    59 
    6038FontPlatformData::FontPlatformData(HFONT font, float size, bool bold, bool oblique, bool useGDI)
    6139    : m_font(RefCountedHFONT::create(font))
     
    6745    , m_scaledFont(0)
    6846#endif
    69     , m_syntheticBold(false)
    70     , m_syntheticOblique(false)
     47    , m_syntheticBold(bold)
     48    , m_syntheticOblique(oblique)
    7149    , m_useGDI(useGDI)
    7250{
     
    8462        GetOutlineTextMetricsW(hdc, bufferSize, metrics);
    8563        WCHAR* faceName = (WCHAR*)((uintptr_t)metrics + (uintptr_t)metrics->otmpFaceName);
    86 
    87         if (!useGDI && (bold || oblique)) {
    88             LOGFONT logFont;
    89 
    90             int len = min((int)wcslen(faceName), LF_FACESIZE - 1);
    91             memcpy(logFont.lfFaceName, faceName, len * sizeof(WORD));
    92             logFont.lfFaceName[len] = '\0';
    93             logFont.lfCharSet = metrics->otmTextMetrics.tmCharSet;
    94             logFont.lfPitchAndFamily = 0;
    95 
    96             int styles = 0;
    97             EnumFontFamiliesEx(hdc, &logFont, enumStylesCallback, reinterpret_cast<LPARAM>(&styles), 0);
    98 
    99             // Check if we need to synthesize bold or oblique. The rule that complicates things here
    100             // is that if the requested font is bold and oblique, and both a bold font and an oblique font
    101             // exist, the bold font should be used, and oblique synthesized.
    102             if (bold && oblique) {
    103                 if (styles == 0) {
    104                     m_syntheticBold = true;
    105                     m_syntheticOblique = true;
    106                 } else if (styles & Bold)
    107                     m_syntheticOblique = true;
    108                 else if (styles & Italic)
    109                     m_syntheticBold = true;
    110             } else if (bold && (!(styles & Bold)))
    111                     m_syntheticBold = true;
    112               else if (oblique && !(styles & Italic))
    113                     m_syntheticOblique = true;
    114         }
    11564
    11665        platformDataInit(font, size, hdc, faceName);
  • trunk/WebCore/platform/graphics/win/SimpleFontDataWin.cpp

    r30441 r31620  
    110110            winfont.lfHeight = -lroundf(smallCapsHeight * (m_font.useGDI() ? 1 : 32));
    111111            HFONT hfont = CreateFontIndirect(&winfont);
    112             m_smallCapsFontData = new SimpleFontData(FontPlatformData(hfont, smallCapsHeight, fontDescription.bold(), fontDescription.italic(), m_font.useGDI()));
     112            m_smallCapsFontData = new SimpleFontData(FontPlatformData(hfont, smallCapsHeight, m_font.syntheticBold(), m_font.syntheticOblique(), m_font.useGDI()));
    113113        }
    114114    }
  • trunk/WebCore/platform/mac/WebCoreTextRenderer.h

    r15438 r31620  
    3333extern bool WebCoreShouldUseFontSmoothing();
    3434extern void WebCoreSetAlwaysUseATSU(bool);
    35 extern NSFont* WebCoreFindFont(NSString* familyName, NSFontTraitMask, int size);
     35extern NSFont* WebCoreFindFont(NSString* familyName, NSFontTraitMask, int weight, int size);
    3636
    3737#ifdef __cplusplus
  • trunk/WebCore/platform/mac/WebCoreTextRenderer.mm

    r29663 r31620  
    8383}
    8484
    85 NSFont* WebCoreFindFont(NSString* familyName, NSFontTraitMask traits, int size)
     85NSFont* WebCoreFindFont(NSString* familyName, NSFontTraitMask traits, int weight, int size)
    8686{
    87     return [WebFontCache fontWithFamily:familyName traits:traits size:size];
     87    return [WebFontCache fontWithFamily:familyName traits:traits weight:weight size:size];
    8888}
  • trunk/WebCore/platform/mac/WebFontCache.h

    r29663 r31620  
    11/*
    22 * Copyright (C) 2006 Apple Computer, Inc.  All rights reserved.
     3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    2627// This interface exists so that third party products (like Silk) can patch in to an Obj-C method to manipulate WebKit's font caching/substitution.
    2728@interface WebFontCache : NSObject
    28 + (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits size:(float)size;
     29+ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size;
    2930@end
  • trunk/WebCore/platform/mac/WebFontCache.mm

    r30066 r31620  
    11/*
    22 * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.
     3 * Copyright (C) 2007 Nicholas Shanks <webkit@nickshanks.com>
    34 *
    45 * Redistribution and use in source and binary forms, with or without
     
    3536
    3637#define IMPORTANT_FONT_TRAITS (0 \
    37     | NSBoldFontMask \
    3838    | NSCompressedFontMask \
    3939    | NSCondensedFontMask \
     
    4545)
    4646
    47 #define DESIRED_WEIGHT 5
    48 
    49 static BOOL acceptableChoice(NSFontTraitMask desiredTraits, int desiredWeight,
    50     NSFontTraitMask candidateTraits, int candidateWeight)
     47static BOOL acceptableChoice(NSFontTraitMask desiredTraits, int desiredWeight, NSFontTraitMask candidateTraits, int candidateWeight)
    5148{
    5249    desiredTraits &= ~SYNTHESIZED_FONT_TRAITS;
     
    5855    NSFontTraitMask candidateTraits, int candidateWeight)
    5956{
    60     if (!acceptableChoice(desiredTraits, desiredWeight, candidateTraits, candidateWeight)) {
     57    if (!acceptableChoice(desiredTraits, desiredWeight, candidateTraits, candidateWeight))
    6158        return NO;
    62     }
    63    
     59
    6460    // A list of the traits we care about.
    6561    // The top item in the list is the worst trait to mismatch; if a font has this
     
    7369        NSExpandedFontMask,
    7470        NSNarrowFontMask,
    75         NSBoldFontMask,
    76         0 };
     71        0
     72    };
     73
    7774    int i = 0;
    7875    NSFontTraitMask mask;
     
    8683            return NO;
    8784    }
    88    
    89     int chosenWeightDelta = chosenWeight - desiredWeight;
    90     int candidateWeightDelta = candidateWeight - desiredWeight;
    91    
    92     int chosenWeightDeltaMagnitude = abs(chosenWeightDelta);
    93     int candidateWeightDeltaMagnitude = abs(candidateWeightDelta);
    94    
    95     // Smaller magnitude wins.
    96     // If both have same magnitude, tie breaker is that the smaller weight wins.
    97     // Otherwise, first font in the array wins (should almost never happen).
    98     if (candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude) {
    99         return YES;
    100     }
    101     if (candidateWeightDeltaMagnitude == chosenWeightDeltaMagnitude && candidateWeight < chosenWeight) {
    102         return YES;
    103     }
    104    
    105     return NO;
     85
     86    int chosenWeightDeltaMagnitude = abs(chosenWeight - desiredWeight);
     87    int candidateWeightDeltaMagnitude = abs(candidateWeight - desiredWeight);
     88
     89    // If both are the same distance from the desired weight, prefer the candidate if it is further from regular.
     90    if (chosenWeightDeltaMagnitude == candidateWeightDeltaMagnitude)
     91        return abs(candidateWeight - 5) > abs(chosenWeight - 5);
     92
     93    // Otherwise, prefer the one closer to the desired weight.
     94    return candidateWeightDeltaMagnitude < chosenWeightDeltaMagnitude;
     95}
     96
     97// Workaround for <rdar://problem/5781372>.
     98static inline void fixUpWeight(NSInteger& weight, NSString *fontName)
     99{
     100    if (weight == 3 && [fontName rangeOfString:@"ultralight" options:NSCaseInsensitiveSearch | NSBackwardsSearch | NSLiteralSearch].location != NSNotFound)
     101        weight = 2;
    106102}
    107103
     
    111107// comparing the desiredFamily to the PostScript name of the installed fonts.  If that fails
    112108// we then do a search based on the family names of the installed fonts.
    113 + (NSFont *)internalFontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits size:(float)size
     109+ (NSFont *)internalFontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size
    114110{
    115111    NSFontManager *fontManager = [NSFontManager sharedFontManager];
     
    129125
    130126            NSFontTraitMask traits = [fontManager traitsOfFont:nameMatchedFont];
    131             if ((traits & desiredTraits) == desiredTraits)
     127            NSInteger weight = [fontManager weightOfFont:nameMatchedFont];
     128            fixUpWeight(weight, availableFont);
     129
     130            if ((traits & desiredTraits) == desiredTraits && weight == desiredWeight)
    132131                return [fontManager convertFont:nameMatchedFont toHaveTrait:desiredTraits];
    133132            break;
     
    152151    int chosenWeight = 0;
    153152    NSFontTraitMask chosenTraits = 0;
     153    NSString *chosenFullName = 0;
    154154
    155155    NSArray *fonts = [fontManager availableMembersOfFontFamily:availableFamily];   
     
    160160
    161161        // Array indices must be hard coded because of lame AppKit API.
     162        NSString *fontFullName = [fontInfo objectAtIndex:0];
    162163        int fontWeight = [[fontInfo objectAtIndex:2] intValue];
     164        fixUpWeight(fontWeight, fontFullName);
     165
    163166        NSFontTraitMask fontTraits = [[fontInfo objectAtIndex:3] unsignedIntValue];
    164167
    165168        BOOL newWinner;
    166169        if (!choseFont)
    167             newWinner = acceptableChoice(desiredTraits, DESIRED_WEIGHT, fontTraits, fontWeight);
     170            newWinner = acceptableChoice(desiredTraits, desiredWeight, fontTraits, fontWeight);
    168171        else
    169             newWinner = betterChoice(desiredTraits, DESIRED_WEIGHT, chosenTraits, chosenWeight, fontTraits, fontWeight);
     172            newWinner = betterChoice(desiredTraits, desiredWeight, chosenTraits, chosenWeight, fontTraits, fontWeight);
    170173
    171174        if (newWinner) {
     
    173176            chosenWeight = fontWeight;
    174177            chosenTraits = fontTraits;
    175 
    176             if (chosenWeight == DESIRED_WEIGHT && (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS))
     178            chosenFullName = fontFullName;
     179
     180            if (chosenWeight == desiredWeight && (chosenTraits & IMPORTANT_FONT_TRAITS) == (desiredTraits & IMPORTANT_FONT_TRAITS))
    177181                break;
    178182        }
     
    182186        return nil;
    183187
    184     NSFont *font = [fontManager fontWithFamily:availableFamily traits:chosenTraits weight:chosenWeight size:size];
     188    NSFont *font = [NSFont fontWithName:chosenFullName size:size];
    185189
    186190    if (!font)
     
    188192
    189193    NSFontTraitMask actualTraits = 0;
    190     if (desiredTraits & (NSItalicFontMask | NSBoldFontMask))
    191         actualTraits = [[NSFontManager sharedFontManager] traitsOfFont:font];
    192 
    193     bool syntheticBold = (desiredTraits & NSBoldFontMask) && !(actualTraits & NSBoldFontMask);
    194     bool syntheticOblique = (desiredTraits & NSItalicFontMask) && !(actualTraits & NSItalicFontMask);
     194    if (desiredTraits & NSFontItalicTrait)
     195        actualTraits = [fontManager traitsOfFont:font];
     196    int actualWeight = [fontManager weightOfFont:font];
     197
     198    bool syntheticBold = desiredWeight >= 7 && actualWeight < 7;
     199    bool syntheticOblique = (desiredTraits & NSFontItalicTrait) && !(actualTraits & NSFontItalicTrait);
    195200
    196201    // There are some malformed fonts that will be correctly returned by -fontWithFamily:traits:weight:size: as a match for a particular trait,
     
    216221}
    217222
    218 + (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits size:(float)size
     223+ (NSFont *)fontWithFamily:(NSString *)desiredFamily traits:(NSFontTraitMask)desiredTraits weight:(int)desiredWeight size:(float)size
    219224{
    220225#ifndef BUILDING_ON_TIGER
    221     NSFont *font = [self internalFontWithFamily:desiredFamily traits:desiredTraits size:size];
     226    NSFont *font = [self internalFontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size];
    222227    if (font)
    223228        return font;
     
    228233#endif
    229234
    230     return [self internalFontWithFamily:desiredFamily traits:desiredTraits size:size];
     235    return [self internalFontWithFamily:desiredFamily traits:desiredTraits weight:desiredWeight size:size];
    231236}
    232237
  • trunk/WebCore/platform/win/PopupMenuWin.cpp

    r30135 r31620  
    518518        if (client()->itemIsLabel(index)) {
    519519            FontDescription d = itemFont.fontDescription();
    520             d.setBold(true);
     520            d.setWeight(d.bolderWeight());
    521521            itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
    522522            itemFont.update(m_popupClient->fontSelector());
  • trunk/WebCore/rendering/RenderListBox.cpp

    r29663 r31620  
    113113                text = static_cast<HTMLOptGroupElement*>(element)->groupLabelText();
    114114                FontDescription d = itemFont.fontDescription();
    115                 d.setBold(true);
     115                d.setWeight(d.bolderWeight());
    116116                itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
    117117                itemFont.update(document()->styleSelector()->fontSelector());
     
    332332    if (element->hasTagName(optgroupTag)) {
    333333        FontDescription d = itemFont.fontDescription();
    334         d.setBold(true);
     334        d.setWeight(d.bolderWeight());
    335335        itemFont = Font(d, itemFont.letterSpacing(), itemFont.wordSpacing());
    336336        itemFont.update(document()->styleSelector()->fontSelector());
  • trunk/WebCore/rendering/RenderThemeMac.mm

    r31160 r31620  
    139139}
    140140
     141static FontWeight toFontWeight(NSInteger appKitFontWeight)
     142{
     143    ASSERT(appKitFontWeight > 0 && appKitFontWeight < 15);
     144    if (appKitFontWeight > 14)
     145        appKitFontWeight = 14;
     146    else if (appKitFontWeight < 1)
     147        appKitFontWeight = 1;
     148
     149    static FontWeight fontWeights[] = {
     150        FontWeight100,
     151        FontWeight100,
     152        FontWeight200,
     153        FontWeight300,
     154        FontWeight400,
     155        FontWeight500,
     156        FontWeight600,
     157        FontWeight600,
     158        FontWeight700,
     159        FontWeight800,
     160        FontWeight800,
     161        FontWeight900,
     162        FontWeight900,
     163        FontWeight900
     164    };
     165    return fontWeights[appKitFontWeight - 1];
     166}
     167
    141168void RenderThemeMac::systemFont(int cssValueId, FontDescription& fontDescription) const
    142169{
     
    189216
    190217    if (font) {
     218        NSFontManager *fontManager = [NSFontManager sharedFontManager];
    191219        cachedDesc->setIsAbsoluteSize(true);
    192220        cachedDesc->setGenericFamily(FontDescription::NoFamily);
    193221        cachedDesc->firstFamily().setFamily([font familyName]);
    194222        cachedDesc->setSpecifiedSize([font pointSize]);
    195         NSFontTraitMask traits = [[NSFontManager sharedFontManager] traitsOfFont:font];
    196         cachedDesc->setBold(traits & NSBoldFontMask);
    197         cachedDesc->setItalic(traits & NSItalicFontMask);
     223        cachedDesc->setWeight(toFontWeight([fontManager weightOfFont:font]));
     224        cachedDesc->setItalic([fontManager traitsOfFont:font] & NSItalicFontMask);
    198225    }
    199226    fontDescription = *cachedDesc;
  • trunk/WebCore/rendering/RenderThemeSafari.cpp

    r31160 r31620  
    193193        cachedDesc->firstFamily().setFamily("Lucida Grande");
    194194        cachedDesc->setSpecifiedSize(fontSize);
    195         cachedDesc->setBold(false);
     195        cachedDesc->setWeight(FontWeightNormal);
    196196        cachedDesc->setItalic(false);
    197197    }
  • trunk/WebKit/mac/ChangeLog

    r31577 r31620  
     12008-04-03  Nicholas Shanks  <webkit@nickshanks.com>
     2
     3        Updated by Dan Bernstein. Reviewed by Dave Hyatt.
     4
     5        - WebKit part of fixing http://bugs.webkit.org/show_bug.cgi?id=6484
     6          font-weight does not properly support graded weights
     7
     8        * WebView/WebHTMLView.mm:
     9        (-[WebHTMLView _styleFromFontAttributes:]):
     10        (-[WebHTMLView _originalFontB]):
     11        (-[WebHTMLView _addToStyle:fontA:fontB:]):
     12
    1132008-04-02  Mark Rowe  <mrowe@apple.com>
    214
  • trunk/WebKit/mac/WebView/WebHTMLView.mm

    r31423 r31620  
    254254
    255255#define STANDARD_WEIGHT 5
    256 #define MIN_BOLD_WEIGHT 9
    257 #define STANDARD_BOLD_WEIGHT 10
     256#define MIN_BOLD_WEIGHT 7
     257#define STANDARD_BOLD_WEIGHT 9
    258258
    259259// Fake URL scheme.
     
    37143714
    37153715    NSFont *font = [dictionary objectForKey:NSFontAttributeName];
    3716     if (font == nil) {
     3716    if (!font) {
    37173717        [style setFontFamily:@"Helvetica"];
    37183718        [style setFontSize:@"12px"];
     
    37253725        [style setFontFamily:[NSString stringWithFormat:@"'%@'", [font familyName]]];
    37263726        [style setFontSize:[NSString stringWithFormat:@"%0.fpx", [font pointSize]]];
     3727        // FIXME: Map to the entire range of CSS weight values.
    37273728        if ([fm weightOfFont:font] >= MIN_BOLD_WEIGHT)
    37283729            [style setFontWeight:@"bold"];
    37293730        else
    37303731            [style setFontWeight:@"normal"];
    3731         if (([fm traitsOfFont:font] & NSItalicFontMask) != 0)
     3732        if ([fm traitsOfFont:font] & NSItalicFontMask)
    37323733            [style setFontStyle:@"italic"];
    37333734        else
     
    38643865- (NSFont *)_originalFontB
    38653866{
    3866     return [[NSFontManager sharedFontManager] fontWithFamily:@"Times" traits:(NSBoldFontMask | NSItalicFontMask) weight:STANDARD_BOLD_WEIGHT size:12.0f];
     3867    return [[NSFontManager sharedFontManager] fontWithFamily:@"Times" traits:NSFontItalicTrait weight:STANDARD_BOLD_WEIGHT size:12.0f];
    38673868}
    38683869
     
    38893890    int aWeight = [fm weightOfFont:a];
    38903891    int bWeight = [fm weightOfFont:b];
    3891 
    3892     BOOL aIsBold = aWeight >= MIN_BOLD_WEIGHT;
    38933892
    38943893    BOOL aIsItalic = ([fm traitsOfFont:a] & NSItalicFontMask) != 0;
     
    39033902       
    39043903        // Find the font the same way the rendering code would later if it encountered this CSS.
    3905         NSFontTraitMask traits = 0;
    3906         if (aIsBold)
    3907             traits |= NSBoldFontMask;
    3908         if (aIsItalic)
    3909             traits |= NSItalicFontMask;
    3910         NSFont *foundFont = WebCoreFindFont(aFamilyName, traits, aPointSize);
     3904        NSFontTraitMask traits = aIsItalic ? NSFontItalicTrait : 0;
     3905        NSFont *foundFont = WebCoreFindFont(aFamilyName, traits, aWeight, aPointSize);
    39113906
    39123907        // If we don't find a font with the same Postscript name, then we'll have to use the
    39133908        // Postscript name to make the CSS specific enough.
    3914         if (![[foundFont fontName] isEqualToString:[a fontName]]) {
     3909        if (![[foundFont fontName] isEqualToString:[a fontName]])
    39153910            familyNameForCSS = [a fontName];
    3916         }
    39173911
    39183912        // FIXME: Need more sophisticated escaping code if we want to handle family names
     
    39303924
    39313925    if (aWeight == bWeight)
    3932         [style setFontWeight:aIsBold ? @"bold" : @"normal"];
     3926        [style setFontWeight:aWeight > MIN_BOLD_WEIGHT ? @"bold" : @"normal"];
    39333927
    39343928    if (aIsItalic == bIsItalic)
  • trunk/WebKit/win/ChangeLog

    r31611 r31620  
     12008-04-03  Dan Bernstein  <mitz@apple.com>
     2
     3        Reviewed by Dave Hyatt.
     4
     5        - WebKit part of fixing http://bugs.webkit.org/show_bug.cgi?id=6484
     6          font-weight does not properly support graded weights
     7
     8        * DOMCoreClasses.cpp:
     9        (DOMElement::font): Updated for the change to FontDescription.
     10        * WebCoreSupport/WebDragClient.cpp:
     11        (dragLabelFont): Ditto.
     12        * WebKitGraphics.cpp:
     13        (makeFont): Ditto.
     14        * WebKitGraphics.h: Added a FIXME.
     15
    1162008-04-03  Steve Falkenburg  <sfalken@apple.com>
    217
  • trunk/WebKit/win/DOMCoreClasses.cpp

    r31596 r31620  
    10621062    webFontDescription->familyLength = family.length();
    10631063    webFontDescription->size = fontDescription.computedSize();
    1064     webFontDescription->bold = fontDescription.bold();
     1064    webFontDescription->bold = fontDescription.weight() >= FontWeight600;
    10651065    webFontDescription->italic = fontDescription.italic();
    10661066
  • trunk/WebKit/win/WebCoreSupport/WebDragClient.cpp

    r30477 r31620  
    161161{
    162162    FontDescription desc;
    163     desc.setBold(bold);
     163    desc.setWeight(bold ? FontWeightBold : FontWeightNormal);
    164164    FontFamily family;
    165165    family.setFamily("Lucida Grande");
  • trunk/WebKit/win/WebKitGraphics.cpp

    r28067 r31620  
    6262    f.setComputedSize(description.size);
    6363    f.setItalic(description.italic);
    64     f.setBold(description.bold);
     64    f.setWeight(description.bold ? FontWeightBold : FontWeightNormal);
    6565    f.setIsAbsoluteSize(true);
    6666
  • trunk/WebKit/win/WebKitGraphics.h

    r24553 r31620  
    4040    unsigned familyLength;
    4141    float size;
     42    // FIXME: Change to weight.
    4243    bool bold;
    4344    bool italic;
Note: See TracChangeset for help on using the changeset viewer.