Changeset 73425 in webkit


Ignore:
Timestamp:
Dec 6, 2010 9:05:12 PM (13 years ago)
Author:
commit-queue@webkit.org
Message:

2010-12-06 Hironori Bono <hbono@chromium.org>

Reviewed by David Levin.

[Chromium] Refactor FontCacheChromiumWin.cpp
https://bugs.webkit.org/show_bug.cgi?id=50611

This change just moved the helper functions for the WebCore::FontCache class to the beginning of ths file.

No new tests are added since this is a refactoring.

  • platform/graphics/chromium/FontCacheChromiumWin.cpp: (WebCore::fontDataFromDescriptionAndLogFont): Moved to the beginning of the file. (WebCore::toGDIFontWeight): Moved to the beginning of the file. (WebCore::FillLogFont): Moved to the beginning of the file. (WebCore::TraitsInFamilyProcData::TraitsInFamilyProcData): Moved to the beginning of the file. (WebCore::traitsInFamilyEnumProc): Moved to the beginning of the file. (WebCore::FontCache::platformInit): Moved after the static functions.
Location:
trunk/WebCore
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/WebCore/ChangeLog

    r73424 r73425  
     12010-12-06  Hironori Bono  <hbono@chromium.org>
     2
     3        Reviewed by David Levin.
     4
     5        [Chromium] Refactor FontCacheChromiumWin.cpp
     6        https://bugs.webkit.org/show_bug.cgi?id=50611
     7       
     8        This change just moved the helper functions for the WebCore::FontCache class to the beginning of ths file.
     9
     10        No new tests are added since this is a refactoring.
     11
     12        * platform/graphics/chromium/FontCacheChromiumWin.cpp:
     13        (WebCore::fontDataFromDescriptionAndLogFont): Moved to the beginning of the file.
     14        (WebCore::toGDIFontWeight): Moved to the beginning of the file.
     15        (WebCore::FillLogFont): Moved to the beginning of the file.
     16        (WebCore::TraitsInFamilyProcData::TraitsInFamilyProcData): Moved to the beginning of the file.
     17        (WebCore::traitsInFamilyEnumProc): Moved to the beginning of the file.
     18        (WebCore::FontCache::platformInit): Moved after the static functions.
     19
    1202010-12-06  Alexey Marinichev  <amarinichev@chromium.org>
    221
  • trunk/WebCore/platform/graphics/chromium/FontCacheChromiumWin.cpp

    r73116 r73425  
    5050namespace WebCore
    5151{
    52 
    53 void FontCache::platformInit()
    54 {
    55     // Not needed on Windows.
    56 }
    5752
    5853// FIXME: consider adding to WebKit String class
     
    330325}
    331326
     327// Tries the given font and save it |outFontFamilyName| if it succeeds.
     328static SimpleFontData* fontDataFromDescriptionAndLogFont(FontCache* fontCache, const FontDescription& fontDescription, const LOGFONT& font, wchar_t* outFontFamilyName)
     329{
     330    SimpleFontData* fontData = fontCache->getCachedFontData(fontDescription, font.lfFaceName);
     331    if (fontData)
     332        memcpy(outFontFamilyName, font.lfFaceName, sizeof(font.lfFaceName));
     333    return fontData;
     334}
     335
     336static LONG toGDIFontWeight(FontWeight fontWeight)
     337{
     338    static LONG gdiFontWeights[] = {
     339        FW_THIN, // FontWeight100
     340        FW_EXTRALIGHT, // FontWeight200
     341        FW_LIGHT, // FontWeight300
     342        FW_NORMAL, // FontWeight400
     343        FW_MEDIUM, // FontWeight500
     344        FW_SEMIBOLD, // FontWeight600
     345        FW_BOLD, // FontWeight700
     346        FW_EXTRABOLD, // FontWeight800
     347        FW_HEAVY // FontWeight900
     348    };
     349    return gdiFontWeights[fontWeight];
     350}
     351
     352static void FillLogFont(const FontDescription& fontDescription, LOGFONT* winfont)
     353{
     354    // The size here looks unusual.  The negative number is intentional.
     355    // Unlike WebKit trunk, we don't multiply the size by 32.  That seems to be
     356    // some kind of artifact of their CG backend, or something.
     357    winfont->lfHeight = -fontDescription.computedPixelSize();
     358    winfont->lfWidth = 0;
     359    winfont->lfEscapement = 0;
     360    winfont->lfOrientation = 0;
     361    winfont->lfUnderline = false;
     362    winfont->lfStrikeOut = false;
     363    winfont->lfCharSet = DEFAULT_CHARSET;
     364    winfont->lfOutPrecision = OUT_TT_ONLY_PRECIS;
     365    winfont->lfQuality = ChromiumBridge::layoutTestMode() ? NONANTIALIASED_QUALITY : DEFAULT_QUALITY; // Honor user's desktop settings.
     366    winfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
     367    winfont->lfItalic = fontDescription.italic();
     368    winfont->lfWeight = toGDIFontWeight(fontDescription.weight());
     369}
     370
     371struct TraitsInFamilyProcData {
     372    TraitsInFamilyProcData(const AtomicString& familyName)
     373        : m_familyName(familyName)
     374    {
     375    }
     376
     377    const AtomicString& m_familyName;
     378    HashSet<unsigned> m_traitsMasks;
     379};
     380
     381static int CALLBACK traitsInFamilyEnumProc(CONST LOGFONT* logFont, CONST TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam)
     382{
     383    TraitsInFamilyProcData* procData = reinterpret_cast<TraitsInFamilyProcData*>(lParam);
     384
     385    unsigned traitsMask = 0;
     386    traitsMask |= logFont->lfItalic ? FontStyleItalicMask : FontStyleNormalMask;
     387    traitsMask |= FontVariantNormalMask;
     388    LONG weight = logFont->lfWeight;
     389    traitsMask |= weight == FW_THIN ? FontWeight100Mask :
     390        weight == FW_EXTRALIGHT ? FontWeight200Mask :
     391        weight == FW_LIGHT ? FontWeight300Mask :
     392        weight == FW_NORMAL ? FontWeight400Mask :
     393        weight == FW_MEDIUM ? FontWeight500Mask :
     394        weight == FW_SEMIBOLD ? FontWeight600Mask :
     395        weight == FW_BOLD ? FontWeight700Mask :
     396        weight == FW_EXTRABOLD ? FontWeight800Mask :
     397                                 FontWeight900Mask;
     398    procData->m_traitsMasks.add(traitsMask);
     399    return 1;
     400}
     401
     402void FontCache::platformInit()
     403{
     404    // Not needed on Windows.
     405}
     406
    332407// Given the desired base font, this will create a SimpleFontData for a specific
    333408// font that can be used to render the given range of characters.
     
    422497}
    423498
    424 // Tries the given font and save it |outFontFamilyName| if it succeeds.
    425 static SimpleFontData* fontDataFromDescriptionAndLogFont(FontCache* fontCache, const FontDescription& fontDescription, const LOGFONT& font, wchar_t* outFontFamilyName)
    426 {
    427     SimpleFontData* fontData = fontCache->getCachedFontData(fontDescription, font.lfFaceName);
    428     if (fontData)
    429         memcpy(outFontFamilyName, font.lfFaceName, sizeof(font.lfFaceName));
    430     return fontData;
    431 }
    432 
    433499SimpleFontData* FontCache::getLastResortFallbackFont(const FontDescription& description)
    434500{
     
    485551    ASSERT_NOT_REACHED();
    486552    return 0;
    487 }
    488 
    489 static LONG toGDIFontWeight(FontWeight fontWeight)
    490 {
    491     static LONG gdiFontWeights[] = {
    492         FW_THIN,        // FontWeight100
    493         FW_EXTRALIGHT,  // FontWeight200
    494         FW_LIGHT,       // FontWeight300
    495         FW_NORMAL,      // FontWeight400
    496         FW_MEDIUM,      // FontWeight500
    497         FW_SEMIBOLD,    // FontWeight600
    498         FW_BOLD,        // FontWeight700
    499         FW_EXTRABOLD,   // FontWeight800
    500         FW_HEAVY        // FontWeight900
    501     };
    502     return gdiFontWeights[fontWeight];
    503 }
    504 
    505 static void FillLogFont(const FontDescription& fontDescription, LOGFONT* winfont)
    506 {
    507     // The size here looks unusual.  The negative number is intentional.
    508     // Unlike WebKit trunk, we don't multiply the size by 32.  That seems to be
    509     // some kind of artifact of their CG backend, or something.
    510     winfont->lfHeight = -fontDescription.computedPixelSize();
    511     winfont->lfWidth = 0;
    512     winfont->lfEscapement = 0;
    513     winfont->lfOrientation = 0;
    514     winfont->lfUnderline = false;
    515     winfont->lfStrikeOut = false;
    516     winfont->lfCharSet = DEFAULT_CHARSET;
    517     winfont->lfOutPrecision = OUT_TT_ONLY_PRECIS;
    518     winfont->lfQuality = ChromiumBridge::layoutTestMode() ? NONANTIALIASED_QUALITY : DEFAULT_QUALITY; // Honor user's desktop settings.
    519     winfont->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
    520     winfont->lfItalic = fontDescription.italic();
    521     winfont->lfWeight = toGDIFontWeight(fontDescription.weight());
    522 }
    523 
    524 struct TraitsInFamilyProcData {
    525     TraitsInFamilyProcData(const AtomicString& familyName)
    526         : m_familyName(familyName)
    527     {
    528     }
    529 
    530     const AtomicString& m_familyName;
    531     HashSet<unsigned> m_traitsMasks;
    532 };
    533 
    534 static int CALLBACK traitsInFamilyEnumProc(CONST LOGFONT* logFont, CONST TEXTMETRIC* metrics, DWORD fontType, LPARAM lParam)
    535 {
    536     TraitsInFamilyProcData* procData = reinterpret_cast<TraitsInFamilyProcData*>(lParam);
    537 
    538     unsigned traitsMask = 0;
    539     traitsMask |= logFont->lfItalic ? FontStyleItalicMask : FontStyleNormalMask;
    540     traitsMask |= FontVariantNormalMask;
    541     LONG weight = logFont->lfWeight;
    542     traitsMask |= weight == FW_THIN ? FontWeight100Mask :
    543         weight == FW_EXTRALIGHT ? FontWeight200Mask :
    544         weight == FW_LIGHT ? FontWeight300Mask :
    545         weight == FW_NORMAL ? FontWeight400Mask :
    546         weight == FW_MEDIUM ? FontWeight500Mask :
    547         weight == FW_SEMIBOLD ? FontWeight600Mask :
    548         weight == FW_BOLD ? FontWeight700Mask :
    549         weight == FW_EXTRABOLD ? FontWeight800Mask :
    550                                  FontWeight900Mask;
    551     procData->m_traitsMasks.add(traitsMask);
    552     return 1;
    553553}
    554554
Note: See TracChangeset for help on using the changeset viewer.