Changeset 200094 in webkit


Ignore:
Timestamp:
Apr 26, 2016 10:20:29 AM (8 years ago)
Author:
mmaxfield@apple.com
Message:

Make FontPlatformData immutable
https://bugs.webkit.org/show_bug.cgi?id=157024

Reviewed by Darin Adler.

This patch deletes all functions which modify a FontPlatformData once
it has been created. This makes for a cleaner design.

No new tests because there is no behavior change.

  • platform/graphics/Font.cpp:

(WebCore::Font::verticalRightOrientationFont):
(WebCore::Font::nonSyntheticItalicFont):

  • platform/graphics/FontPlatformData.cpp:

(WebCore::FontPlatformData::FontPlatformData):
(WebCore::FontPlatformData::cloneWithOrientation):
(WebCore::FontPlatformData::cloneWithSyntheticOblique):

  • platform/graphics/FontPlatformData.h:

(WebCore::FontPlatformData::setIsSystemFont): Deleted.
(WebCore::FontPlatformData::setSize): Deleted.
(WebCore::FontPlatformData::setOrientation): Deleted.
(WebCore::FontPlatformData::setSyntheticOblique): Deleted.

  • platform/graphics/cocoa/FontCacheCoreText.cpp:

(WebCore::FontCache::systemFallbackForCharacters):

  • platform/graphics/cocoa/FontCascadeCocoa.mm:

(WebCore::FontCascade::drawGlyphs):

  • platform/graphics/cocoa/FontCocoa.mm:

(WebCore::Font::platformInit):
(WebCore::Font::platformCharWidthInit):
(WebCore::createDerivativeFont):
(WebCore::Font::createFontWithoutSynthesizableFeatures):
(WebCore::Font::platformCreateScaledFont):
(WebCore::Font::platformWidthForGlyph):

  • platform/graphics/cocoa/FontPlatformDataCocoa.mm:

(WebCore::FontPlatformData::openTypeTable):

  • platform/graphics/win/FontPlatformDataCairoWin.cpp:

(WebCore::FontPlatformData::platformDataInit):

Location:
trunk/Source/WebCore
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebCore/ChangeLog

    r200093 r200094  
     12016-04-26  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        Make FontPlatformData immutable
     4        https://bugs.webkit.org/show_bug.cgi?id=157024
     5
     6        Reviewed by Darin Adler.
     7
     8        This patch deletes all functions which modify a FontPlatformData once
     9        it has been created. This makes for a cleaner design.
     10
     11        No new tests because there is no behavior change.
     12
     13        * platform/graphics/Font.cpp:
     14        (WebCore::Font::verticalRightOrientationFont):
     15        (WebCore::Font::nonSyntheticItalicFont):
     16        * platform/graphics/FontPlatformData.cpp:
     17        (WebCore::FontPlatformData::FontPlatformData):
     18        (WebCore::FontPlatformData::cloneWithOrientation):
     19        (WebCore::FontPlatformData::cloneWithSyntheticOblique):
     20        * platform/graphics/FontPlatformData.h:
     21        (WebCore::FontPlatformData::setIsSystemFont): Deleted.
     22        (WebCore::FontPlatformData::setSize): Deleted.
     23        (WebCore::FontPlatformData::setOrientation): Deleted.
     24        (WebCore::FontPlatformData::setSyntheticOblique): Deleted.
     25        * platform/graphics/cocoa/FontCacheCoreText.cpp:
     26        (WebCore::FontCache::systemFallbackForCharacters):
     27        * platform/graphics/cocoa/FontCascadeCocoa.mm:
     28        (WebCore::FontCascade::drawGlyphs):
     29        * platform/graphics/cocoa/FontCocoa.mm:
     30        (WebCore::Font::platformInit):
     31        (WebCore::Font::platformCharWidthInit):
     32        (WebCore::createDerivativeFont):
     33        (WebCore::Font::createFontWithoutSynthesizableFeatures):
     34        (WebCore::Font::platformCreateScaledFont):
     35        (WebCore::Font::platformWidthForGlyph):
     36        * platform/graphics/cocoa/FontPlatformDataCocoa.mm:
     37        (WebCore::FontPlatformData::openTypeTable):
     38        * platform/graphics/win/FontPlatformDataCairoWin.cpp:
     39        (WebCore::FontPlatformData::platformDataInit):
     40
    1412016-04-26  Ryan Haddad  <ryanhaddad@apple.com>
    242
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r198074 r200094  
    254254        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
    255255    if (!m_derivedFontData->verticalRightOrientation) {
    256         FontPlatformData verticalRightPlatformData(m_platformData);
    257         verticalRightPlatformData.setOrientation(Horizontal);
     256        auto verticalRightPlatformData = FontPlatformData::cloneWithOrientation(m_platformData, Horizontal);
    258257        m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, isCustomFont(), false, true);
    259258    }
     
    321320        m_derivedFontData = std::make_unique<DerivedFontData>(isCustomFont());
    322321    if (!m_derivedFontData->nonSyntheticItalic) {
     322#if PLATFORM(COCOA) || USE(CAIRO)
     323        FontPlatformData nonSyntheticItalicFontPlatformData = FontPlatformData::cloneWithSyntheticOblique(m_platformData, false);
     324#else
    323325        FontPlatformData nonSyntheticItalicFontPlatformData(m_platformData);
    324 #if PLATFORM(COCOA) || USE(CAIRO)
    325         nonSyntheticItalicFontPlatformData.setSyntheticOblique(false);
    326326#endif
    327327        m_derivedFontData->nonSyntheticItalic = create(nonSyntheticItalicFontPlatformData, isCustomFont());
  • trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp

    r200070 r200094  
    4545
    4646FontPlatformData::FontPlatformData(float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
    47     : m_syntheticBold(syntheticBold)
    48     , m_syntheticOblique(syntheticOblique)
     47    : m_size(size)
    4948    , m_orientation(orientation)
    50     , m_size(size)
    5149    , m_widthVariant(widthVariant)
    5250    , m_textRenderingMode(textRenderingMode)
     51    , m_syntheticBold(syntheticBold)
     52    , m_syntheticOblique(syntheticOblique)
    5353{
    5454}
     
    7070    m_isSystemFont = source.m_isSystemFont;
    7171    platformDataInit(source);
     72}
     73
     74FontPlatformData FontPlatformData::cloneWithOrientation(const FontPlatformData& source, FontOrientation orientation)
     75{
     76    FontPlatformData copy(source);
     77    copy.m_orientation = orientation;
     78    return copy;
     79}
     80
     81FontPlatformData FontPlatformData::cloneWithSyntheticOblique(const FontPlatformData& source, bool syntheticOblique)
     82{
     83    FontPlatformData copy(source);
     84    copy.m_syntheticOblique = syntheticOblique;
     85    return copy;
     86}
     87
     88FontPlatformData FontPlatformData::cloneWithSize(const FontPlatformData& source, float size)
     89{
     90    FontPlatformData copy(source);
     91    copy.m_size = size;
     92    return copy;
    7293}
    7394
  • trunk/Source/WebCore/platform/graphics/FontPlatformData.h

    r200070 r200094  
    7575class SharedBuffer;
    7676
     77// This class is conceptually immutable. Once created, no instances should ever change (in an observable way).
    7778class FontPlatformData {
    7879    WTF_MAKE_FAST_ALLOCATED;
     
    8889#endif
    8990
     91    static FontPlatformData cloneWithOrientation(const FontPlatformData&, FontOrientation);
     92    static FontPlatformData cloneWithSyntheticOblique(const FontPlatformData&, bool);
     93    static FontPlatformData cloneWithSize(const FontPlatformData&, float);
     94
    9095#if USE(CG)
    9196    FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant, TextRenderingMode);
     
    125130#if PLATFORM(WIN) || PLATFORM(COCOA)
    126131    bool isSystemFont() const { return m_isSystemFont; }
    127     void setIsSystemFont(bool isSystemFont) { m_isSystemFont = isSystemFont; }
    128132#endif
    129133
     
    134138    bool isFixedPitch() const;
    135139    float size() const { return m_size; }
    136     void setSize(float size) { m_size = size; }
    137140    bool syntheticBold() const { return m_syntheticBold; }
    138141    bool syntheticOblique() const { return m_syntheticOblique; }
     
    142145    TextRenderingMode textRenderingMode() const { return m_textRenderingMode; }
    143146    bool isForTextCombine() const { return widthVariant() != RegularWidth; } // Keep in sync with callers of FontDescription::setWidthVariant().
    144 
    145     void setOrientation(FontOrientation orientation) { m_orientation = orientation; }
    146     void setSyntheticOblique(bool syntheticOblique) { m_syntheticOblique = syntheticOblique; }
    147147
    148148#if USE(CAIRO)
     
    198198
    199199#if PLATFORM(COCOA) || PLATFORM(WIN)
    200     PassRefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
     200    RefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
    201201#endif
    202202
     
    216216#endif
    217217
    218 public:
    219     bool m_syntheticBold { false };
    220     bool m_syntheticOblique { false };
    221     FontOrientation m_orientation { Horizontal };
    222     float m_size { 0 };
    223     FontWidthVariant m_widthVariant { RegularWidth };
    224     TextRenderingMode m_textRenderingMode { AutoTextRendering };
    225 
    226 private:
    227218#if PLATFORM(COCOA)
    228219    // FIXME: Get rid of one of these. These two fonts are subtly different, and it is not obvious which one to use where.
     
    240231#endif
    241232
     233    // The values below are common to all ports
     234    // FIXME: If they're common to all ports, they should move to Font
     235    float m_size { 0 };
     236
     237    FontOrientation m_orientation { Horizontal };
     238    FontWidthVariant m_widthVariant { RegularWidth };
     239    TextRenderingMode m_textRenderingMode { AutoTextRendering };
     240
     241    bool m_syntheticBold { false };
     242    bool m_syntheticOblique { false };
    242243    bool m_isColorBitmapFont { false };
    243244    bool m_isHashTableDeletedValue { false };
    244245    bool m_isSystemFont { false };
     246    // The values above are common to all ports
     247
    245248#if PLATFORM(IOS)
    246249    bool m_isEmoji { false };
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp

    r196969 r200094  
    792792    std::tie(syntheticBold, syntheticOblique) = computeNecessarySynthesis(substituteFont, description, isPlatformFont).boldObliquePair();
    793793
    794     FontPlatformData alternateFont(substituteFont, platformData.size(), syntheticBold, syntheticOblique, platformData.m_orientation, platformData.m_widthVariant, platformData.m_textRenderingMode);
     794    FontPlatformData alternateFont(substituteFont, platformData.size(), syntheticBold, syntheticOblique, platformData.orientation(), platformData.widthVariant(), platformData.textRenderingMode());
    795795
    796796    return fontForPlatformData(alternateFont);
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCascadeCocoa.mm

    r198074 r200094  
    281281    matrix.b = -matrix.b;
    282282    matrix.d = -matrix.d;
    283     if (platformData.m_syntheticOblique) {
     283    if (platformData.syntheticOblique()) {
    284284        static float obliqueSkew = tanf(SYNTHETIC_OBLIQUE_ANGLE * piFloat / 180);
    285285        if (platformData.orientation() == Vertical)
  • trunk/Source/WebCore/platform/graphics/cocoa/FontCocoa.mm

    r199890 r200094  
    9797    // FIXME: Unify these two codepaths
    9898#if USE(APPKIT)
    99     m_syntheticBoldOffset = m_platformData.m_syntheticBold ? 1.0f : 0.f;
     99    m_syntheticBoldOffset = m_platformData.syntheticBold() ? 1.0f : 0.f;
    100100
    101101#if PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101100
     
    110110    // Some fonts erroneously specify a positive descender value. We follow Core Text in assuming that
    111111    // such fonts meant the same distance, but in the reverse direction.
    112     float pointSize = m_platformData.m_size;
     112    float pointSize = m_platformData.size();
    113113    float ascent = scaleEmToUnits(CGFontGetAscent(m_platformData.cgFont()), unitsPerEm) * pointSize;
    114114    float descent = -scaleEmToUnits(-abs(CGFontGetDescent(m_platformData.cgFont())), unitsPerEm) * pointSize;
     
    175175#else
    176176
    177     m_syntheticBoldOffset = m_platformData.m_syntheticBold ? ceilf(m_platformData.size()  / 24.0f) : 0.f;
     177    m_syntheticBoldOffset = m_platformData.syntheticBold() ? ceilf(m_platformData.size()  / 24.0f) : 0.f;
    178178
    179179    CTFontRef ctFont = m_platformData.font();
     
    203203        const UInt8* os2 = CFDataGetBytePtr(os2Table.get());
    204204        SInt16 os2AvgCharWidth = os2[2] * 256 + os2[3];
    205         m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.m_size;
     205        m_avgCharWidth = scaleEmToUnits(os2AvgCharWidth, m_fontMetrics.unitsPerEm()) * m_platformData.size();
    206206    }
    207207
     
    214214        SInt16 xMax = static_cast<SInt16>(uxMax);
    215215        float diff = static_cast<float>(xMax - xMin);
    216         m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData.m_size;
     216        m_maxCharWidth = scaleEmToUnits(diff, m_fontMetrics.unitsPerEm()) * m_platformData.size();
    217217    }
    218218#endif
     
    364364        return nullptr;
    365365
    366     FontPlatformData scaledFontData(font, size, false, false, orientation);
    367 
    368366    if (syntheticBold)
    369367        fontTraits |= kCTFontBoldTrait;
     
    371369        fontTraits |= kCTFontItalicTrait;
    372370
    373     CTFontSymbolicTraits scaledFontTraits = CTFontGetSymbolicTraits(scaledFontData.font());
    374     scaledFontData.m_syntheticBold = (fontTraits & kCTFontBoldTrait) && !(scaledFontTraits & kCTFontTraitBold);
    375     scaledFontData.m_syntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic);
     371    CTFontSymbolicTraits scaledFontTraits = CTFontGetSymbolicTraits(font);
     372
     373    bool usedSyntheticBold = (fontTraits & kCTFontBoldTrait) && !(scaledFontTraits & kCTFontTraitBold);
     374    bool usedSyntheticOblique = (fontTraits & kCTFontItalicTrait) && !(scaledFontTraits & kCTFontTraitItalic);
     375    FontPlatformData scaledFontData(font, size, usedSyntheticBold, usedSyntheticOblique, orientation);
    376376
    377377    return Font::create(scaledFontData);
     
    513513    CTFontSymbolicTraits fontTraits = CTFontGetSymbolicTraits(m_platformData.font());
    514514    RetainPtr<CTFontRef> ctFont = createCTFontWithoutSynthesizableFeatures(m_platformData.font());
    515     return createDerivativeFont(ctFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.m_syntheticBold, m_platformData.m_syntheticOblique);
     515    return createDerivativeFont(ctFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.syntheticBold(), m_platformData.syntheticOblique());
    516516}
    517517
     
    523523    RetainPtr<CTFontRef> scaledFont = adoptCF(CTFontCreateWithFontDescriptor(fontDescriptor.get(), size, nullptr));
    524524
    525     return createDerivativeFont(scaledFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.m_syntheticBold, m_platformData.m_syntheticOblique);
     525    return createDerivativeFont(scaledFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.syntheticBold(), m_platformData.syntheticOblique());
    526526}
    527527
     
    629629    bool populatedAdvance = false;
    630630    if ((horizontal || m_isBrokenIdeographFallback) && canUseFastGlyphAdvanceGetter(this->platformData(), glyph, advance, populatedAdvance)) {
    631         float pointSize = platformData().m_size;
     631        float pointSize = platformData().size();
    632632        CGAffineTransform m = CGAffineTransformMakeScale(pointSize, pointSize);
    633633        if (!CGFontGetGlyphAdvancesForStyle(platformData().cgFont(), &m, renderingStyle(platformData()), &glyph, 1, &advance)) {
     
    636636            advance.width = 0;
    637637        }
    638     } else if (!populatedAdvance && platformData().m_size)
     638    } else if (!populatedAdvance && platformData().size())
    639639        CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), horizontal ? kCTFontOrientationHorizontal : kCTFontOrientationVertical, &glyph, &advance, 1);
    640640
  • trunk/Source/WebCore/platform/graphics/cocoa/FontPlatformDataCocoa.mm

    r200070 r200094  
    189189}
    190190
    191 PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
     191RefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
    192192{
    193193    if (RetainPtr<CFDataRef> data = adoptCF(CGFontCopyTableForTag(cgFont(), table)))
  • trunk/Source/WebCore/platform/graphics/freetype/FontPlatformData.h

    r199890 r200094  
    6969    FontPlatformData(const FontPlatformData&, float size);
    7070
     71    static FontPlatformData cloneWithOrientation(const FontPlatformData&, FontOrientation);
     72    static FontPlatformData cloneWithSyntheticOblique(const FontPlatformData&, bool);
     73    static FontPlatformData cloneWithSize(const FontPlatformData&, float);
     74
    7175    ~FontPlatformData();
    7276
  • trunk/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp

    r199890 r200094  
    266266}
    267267
     268FontPlatformData FontPlatformData::cloneWithOrientation(const FontPlatformData& source, FontOrientation orientation)
     269{
     270    FontPlatformData copy(source);
     271    copy.m_orientation = orientation;
     272    return copy;
     273}
     274
     275FontPlatformData FontPlatformData::cloneWithSyntheticOblique(const FontPlatformData& source, bool syntheticOblique)
     276{
     277    FontPlatformData copy(source);
     278    copy.m_syntheticOblique = syntheticOblique;
     279    return copy;
     280}
     281
     282FontPlatformData FontPlatformData::cloneWithSize(const FontPlatformData& source, float size)
     283{
     284    FontPlatformData copy(source);
     285    copy.m_size = size;
     286    return copy;
     287}
     288
    268289HarfBuzzFace* FontPlatformData::harfBuzzFace() const
    269290{
  • trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCairoWin.cpp

    r199890 r200094  
    4747    cairo_matrix_init_scale(&sizeMatrix, size, size);
    4848
    49     static cairo_font_options_t* fontOptions = 0;
     49    static cairo_font_options_t* fontOptions = nullptr;
    5050    if (!fontOptions) {
    5151       fontOptions = cairo_font_options_create();
     
    102102    m_font = source.m_font;
    103103    m_useGDI = source.m_useGDI;
    104     m_scaledFont = 0;
     104    m_scaledFont = nullptr;
    105105
    106106    if (source.m_scaledFont)
  • trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp

    r194496 r200094  
    7575}
    7676
    77 PassRefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
     77RefPtr<SharedBuffer> FontPlatformData::openTypeTable(uint32_t table) const
    7878{
    7979    HWndDC hdc(0);
  • trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp

    r194496 r200094  
    136136{
    137137    float scaledSize = scaleFactor * m_platformData.size();
    138     if (isCustomFont()) {
    139         FontPlatformData scaledFont(m_platformData);
    140         scaledFont.setSize(scaledSize);
    141         return Font::create(scaledFont, true, false);
    142     }
     138    if (isCustomFont())
     139        return Font::create(FontPlatformData::cloneWithSize(m_platformData, scaledSize), true, false);
    143140
    144141    LOGFONT winfont;
Note: See TracChangeset for help on using the changeset viewer.