Migrate Font constructor from bools to enums
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2017 01:37:43 +0000 (01:37 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 16 May 2017 01:37:43 +0000 (01:37 +0000)
https://bugs.webkit.org/show_bug.cgi?id=172140

Reviewed by Tim Horton.

In https://bugs.webkit.org/show_bug.cgi?id=168487, I'm adding a new flag to Font. We can't
keep having just a pile of bools in this class. Instead, we should be using enums.

No new tests because there is no behavior change.

* css/CSSFontFace.cpp:
(WebCore::CSSFontFace::font):
* css/CSSFontFaceSource.cpp:
(WebCore::CSSFontFaceSource::font):
* css/CSSSegmentedFontFace.cpp:
* loader/cache/CachedFont.cpp:
(WebCore::CachedFont::createFont):
* platform/graphics/Font.cpp:
(WebCore::Font::Font):
(WebCore::Font::verticalRightOrientationFont):
(WebCore::Font::uprightOrientationFont):
(WebCore::Font::brokenIdeographFont):
(WebCore::Font::description):
(WebCore::Font::mathData):
* platform/graphics/Font.h:
(WebCore::Font::create):
(WebCore::Font::origin):
(WebCore::Font::isInterstitial):
(WebCore::Font::widthForGlyph):
(WebCore::Font::isCustomFont): Deleted.
(WebCore::Font::isLoading): Deleted.
* platform/graphics/FontRanges.cpp:
* platform/graphics/cocoa/FontCocoa.mm:
(WebCore::Font::platformInit):
* platform/graphics/freetype/SimpleFontDataFreeType.cpp:
(WebCore::Font::platformCreateScaledFont):
* platform/graphics/win/SimpleFontDataCGWin.cpp:
(WebCore::Font::platformInit):
* platform/graphics/win/SimpleFontDataDirect2D.cpp:
(WebCore::Font::platformInit):
* platform/graphics/win/SimpleFontDataWin.cpp:
(WebCore::Font::platformCreateScaledFont):
(WebCore::Font::determinePitch):
* rendering/SimpleLineLayout.cpp:
(WebCore::SimpleLineLayout::canUseForFontAndText):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@216896 268f45cc-cd09-0410-ab3c-d52691b4dbfc

14 files changed:
Source/WebCore/ChangeLog
Source/WebCore/css/CSSFontFace.cpp
Source/WebCore/css/CSSFontFaceSource.cpp
Source/WebCore/css/CSSSegmentedFontFace.cpp
Source/WebCore/loader/cache/CachedFont.cpp
Source/WebCore/platform/graphics/Font.cpp
Source/WebCore/platform/graphics/Font.h
Source/WebCore/platform/graphics/FontRanges.cpp
Source/WebCore/platform/graphics/cocoa/FontCocoa.mm
Source/WebCore/platform/graphics/freetype/SimpleFontDataFreeType.cpp
Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp
Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp
Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
Source/WebCore/rendering/SimpleLineLayout.cpp

index 34c4c34..6558dd6 100644 (file)
@@ -1,3 +1,51 @@
+2017-05-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Migrate Font constructor from bools to enums
+        https://bugs.webkit.org/show_bug.cgi?id=172140
+
+        Reviewed by Tim Horton.
+
+        In https://bugs.webkit.org/show_bug.cgi?id=168487, I'm adding a new flag to Font. We can't
+        keep having just a pile of bools in this class. Instead, we should be using enums.
+
+        No new tests because there is no behavior change.
+
+        * css/CSSFontFace.cpp:
+        (WebCore::CSSFontFace::font):
+        * css/CSSFontFaceSource.cpp:
+        (WebCore::CSSFontFaceSource::font):
+        * css/CSSSegmentedFontFace.cpp:
+        * loader/cache/CachedFont.cpp:
+        (WebCore::CachedFont::createFont):
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::Font):
+        (WebCore::Font::verticalRightOrientationFont):
+        (WebCore::Font::uprightOrientationFont):
+        (WebCore::Font::brokenIdeographFont):
+        (WebCore::Font::description):
+        (WebCore::Font::mathData):
+        * platform/graphics/Font.h:
+        (WebCore::Font::create):
+        (WebCore::Font::origin):
+        (WebCore::Font::isInterstitial):
+        (WebCore::Font::widthForGlyph):
+        (WebCore::Font::isCustomFont): Deleted.
+        (WebCore::Font::isLoading): Deleted.
+        * platform/graphics/FontRanges.cpp:
+        * platform/graphics/cocoa/FontCocoa.mm:
+        (WebCore::Font::platformInit):
+        * platform/graphics/freetype/SimpleFontDataFreeType.cpp:
+        (WebCore::Font::platformCreateScaledFont):
+        * platform/graphics/win/SimpleFontDataCGWin.cpp:
+        (WebCore::Font::platformInit):
+        * platform/graphics/win/SimpleFontDataDirect2D.cpp:
+        (WebCore::Font::platformInit):
+        * platform/graphics/win/SimpleFontDataWin.cpp:
+        (WebCore::Font::platformCreateScaledFont):
+        (WebCore::Font::determinePitch):
+        * rendering/SimpleLineLayout.cpp:
+        (WebCore::SimpleLineLayout::canUseForFontAndText):
+
 2017-05-15  Youenn Fablet  <youenn@apple.com>
 
         WebRTC outgoing muted video sources should send black frames
index 7a99d7c..f185e90 100644 (file)
@@ -625,7 +625,7 @@ RefPtr<Font> CSSFontFace::font(const FontDescription& fontDescription, bool synt
             fontIsLoading = true;
             if (status() == Status::TimedOut)
                 continue;
-            return Font::create(FontCache::singleton().lastResortFallbackFontForEveryCharacter(fontDescription)->platformData(), true, true);
+            return Font::create(FontCache::singleton().lastResortFallbackFontForEveryCharacter(fontDescription)->platformData(), Font::Origin::Remote, Font::Interstitial::Yes);
         case CSSFontFaceSource::Status::Success:
             if (RefPtr<Font> result = source->font(fontDescription, syntheticBold, syntheticItalic, m_featureSettings, m_variantSettings, m_fontSelectionCapabilities))
                 return result;
index 20b5811..082cb44 100644 (file)
@@ -181,7 +181,7 @@ RefPtr<Font> CSSFontFaceSource::font(const FontDescription& fontDescription, boo
         if (m_immediateSource) {
             if (!m_immediateFontCustomPlatformData)
                 return nullptr;
-            return Font::create(CachedFont::platformDataFromCustomData(*m_immediateFontCustomPlatformData, fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities), true);
+            return Font::create(CachedFont::platformDataFromCustomData(*m_immediateFontCustomPlatformData, fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities), Font::Origin::Remote);
         }
 
         // We're local. Just return a Font from the normal cache.
@@ -206,9 +206,9 @@ RefPtr<Font> CSSFontFaceSource::font(const FontDescription& fontDescription, boo
     if (!m_inDocumentCustomPlatformData)
         return nullptr;
 #if PLATFORM(COCOA)
-    return Font::create(m_inDocumentCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities), true);
+    return Font::create(m_inDocumentCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities), Font::Origin::Remote);
 #else
-    return Font::create(m_inDocumentCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic), true);
+    return Font::create(m_inDocumentCustomPlatformData->fontPlatformData(fontDescription, syntheticBold, syntheticItalic), Font::Origin::Remote);
 #endif
 #endif
 
index dcffc12..6a3ddab 100644 (file)
@@ -84,7 +84,7 @@ private:
 
     bool isLoading() const final
     {
-        return m_result && m_result.value() && m_result.value()->isLoading();
+        return m_result && m_result.value() && m_result.value()->isInterstitial();
     }
 
     mutable std::optional<RefPtr<Font>> m_result; // Caches nullptr too
index b9fd16e..d90567c 100644 (file)
@@ -124,7 +124,7 @@ std::unique_ptr<FontCustomPlatformData> CachedFont::createCustomFontData(SharedB
 
 RefPtr<Font> CachedFont::createFont(const FontDescription& fontDescription, const AtomicString&, bool syntheticBold, bool syntheticItalic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities)
 {
-    return Font::create(platformDataFromCustomData(fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities), true);
+    return Font::create(platformDataFromCustomData(fontDescription, syntheticBold, syntheticItalic, fontFaceFeatures, fontFaceVariantSettings, fontFaceCapabilities), Font::Origin::Remote);
 }
 
 FontPlatformData CachedFont::platformDataFromCustomData(const FontDescription& fontDescription, bool bold, bool italic, const FontFeatureSettings& fontFaceFeatures, const FontVariantSettings& fontFaceVariantSettings, FontSelectionSpecifiedCapabilities fontFaceCapabilities)
index bc9650c..293d07e 100644 (file)
@@ -55,15 +55,15 @@ unsigned GlyphPage::s_count = 0;
 const float smallCapsFontSizeMultiplier = 0.7f;
 const float emphasisMarkFontSizeMultiplier = 0.5f;
 
-Font::Font(const FontPlatformData& platformData, bool isCustomFont, bool isLoading, bool isTextOrientationFallback)
+Font::Font(const FontPlatformData& platformData, Origin origin, Interstitial interstitial, OrientationFallback orientationFallback)
     : m_maxCharWidth(-1)
     , m_avgCharWidth(-1)
     , m_platformData(platformData)
     , m_mathData(nullptr)
     , m_treatAsFixedPitch(false)
-    , m_isCustomFont(isCustomFont)
-    , m_isLoading(isLoading)
-    , m_isTextOrientationFallback(isTextOrientationFallback)
+    , m_origin(origin == Origin::Remote)
+    , m_isInterstitial(interstitial == Interstitial::Yes)
+    , m_isTextOrientationFallback(orientationFallback == OrientationFallback::Fallback)
     , m_isBrokenIdeographFallback(false)
     , m_hasVerticalGlyphs(false)
     , m_isUsedInSystemFallbackCache(false)
@@ -75,7 +75,7 @@ Font::Font(const FontPlatformData& platformData, bool isCustomFont, bool isLoadi
     platformGlyphInit();
     platformCharWidthInit();
 #if ENABLE(OPENTYPE_VERTICAL)
-    if (platformData.orientation() == Vertical && !isTextOrientationFallback) {
+    if (platformData.orientation() == Vertical && orientationFallback == OrientationFallback::NoFallback) {
         m_verticalData = FontCache::singleton().verticalData(platformData);
         m_hasVerticalGlyphs = m_verticalData.get() && m_verticalData->hasVerticalMetrics();
     }
@@ -266,7 +266,7 @@ const Font& Font::verticalRightOrientationFont() const
         m_derivedFontData = std::make_unique<DerivedFonts>();
     if (!m_derivedFontData->verticalRightOrientation) {
         auto verticalRightPlatformData = FontPlatformData::cloneWithOrientation(m_platformData, Horizontal);
-        m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, isCustomFont(), false, true);
+        m_derivedFontData->verticalRightOrientation = create(verticalRightPlatformData, origin(), Interstitial::No, OrientationFallback::Fallback);
     }
     ASSERT(m_derivedFontData->verticalRightOrientation != this);
     return *m_derivedFontData->verticalRightOrientation;
@@ -277,7 +277,7 @@ const Font& Font::uprightOrientationFont() const
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFonts>();
     if (!m_derivedFontData->uprightOrientation)
-        m_derivedFontData->uprightOrientation = create(m_platformData, isCustomFont(), false, true);
+        m_derivedFontData->uprightOrientation = create(m_platformData, origin(), Interstitial::No, OrientationFallback::Fallback);
     ASSERT(m_derivedFontData->uprightOrientation != this);
     return *m_derivedFontData->uprightOrientation;
 }
@@ -321,7 +321,7 @@ const Font& Font::brokenIdeographFont() const
     if (!m_derivedFontData)
         m_derivedFontData = std::make_unique<DerivedFonts>();
     if (!m_derivedFontData->brokenIdeograph) {
-        m_derivedFontData->brokenIdeograph = create(m_platformData, isCustomFont(), false);
+        m_derivedFontData->brokenIdeograph = create(m_platformData, origin(), Interstitial::No);
         m_derivedFontData->brokenIdeograph->m_isBrokenIdeographFallback = true;
     }
     ASSERT(m_derivedFontData->brokenIdeograph != this);
@@ -331,7 +331,7 @@ const Font& Font::brokenIdeographFont() const
 #ifndef NDEBUG
 String Font::description() const
 {
-    if (isCustomFont())
+    if (origin() == Origin::Remote)
         return "[custom font]";
 
     return platformData().description();
@@ -340,7 +340,7 @@ String Font::description() const
 
 const OpenTypeMathData* Font::mathData() const
 {
-    if (m_isLoading)
+    if (isInterstitial())
         return nullptr;
     if (!m_mathData) {
         m_mathData = OpenTypeMathData::create(m_platformData);
index b9628ea..def8c4f 100644 (file)
@@ -76,9 +76,21 @@ enum Pitch { UnknownPitch, FixedPitch, VariablePitch };
 class Font : public RefCounted<Font> {
 public:
     // Used to create platform fonts.
-    static Ref<Font> create(const FontPlatformData& platformData, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFallback = false)
+    enum class Origin {
+        Remote,
+        Local
+    };
+    enum class Interstitial {
+        Yes,
+        No
+    };
+    enum class OrientationFallback {
+        Fallback,
+        NoFallback
+    };
+    static Ref<Font> create(const FontPlatformData& platformData, Origin origin = Origin::Local, Interstitial interstitial = Interstitial::No, OrientationFallback orientationFallback = OrientationFallback::NoFallback)
     {
-        return adoptRef(*new Font(platformData, isCustomFont, isLoading, isTextOrientationFallback));
+        return adoptRef(*new Font(platformData, origin, interstitial, orientationFallback));
     }
 
     WEBCORE_EXPORT ~Font();
@@ -169,8 +181,8 @@ public:
     void determinePitch();
     Pitch pitch() const { return m_treatAsFixedPitch ? FixedPitch : VariablePitch; }
 
-    bool isCustomFont() const { return m_isCustomFont; }
-    bool isLoading() const { return m_isLoading; }
+    Origin origin() const { return m_origin ? Origin::Remote : Origin::Local; }
+    bool isInterstitial() const { return m_isInterstitial; }
 
 #ifndef NDEBUG
     String description() const;
@@ -208,7 +220,7 @@ public:
 #endif
 
 private:
-    Font(const FontPlatformData&, bool isCustomFont = false, bool isLoading = false, bool isTextOrientationFallback = false);
+    Font(const FontPlatformData&, Origin, Interstitial, OrientationFallback);
 
     void platformInit();
     void platformGlyphInit();
@@ -292,8 +304,8 @@ private:
 #endif
 
     unsigned m_treatAsFixedPitch : 1;
-    unsigned m_isCustomFont : 1; // Whether or not we are custom font loaded via @font-face
-    unsigned m_isLoading : 1; // Whether or not this custom font is still in the act of loading.
+    unsigned m_origin : 1; // Whether or not we are custom font loaded via @font-face
+    unsigned m_isInterstitial : 1; // Whether or not this custom font is the last resort placeholder for a loading font
 
     unsigned m_isTextOrientationFallback : 1;
     unsigned m_isBrokenIdeographFallback : 1;
@@ -335,7 +347,7 @@ ALWAYS_INLINE float Font::widthForGlyph(Glyph glyph) const
     // used in place of the actual font when isLoading() is true on both macOS and iOS.
     // The zero-width-space glyph in that font does not have a width of zero and, further, that glyph is used
     // for many other characters and must not be zero width when used for them.
-    if (isZeroWidthSpaceGlyph(glyph) && !isLoading())
+    if (isZeroWidthSpaceGlyph(glyph) && !isInterstitial())
         return 0;
 
     float width = m_glyphToWidthMap.metricsForGlyph(glyph);
index d1b7917..048c263 100644 (file)
@@ -62,7 +62,7 @@ private:
 
     bool isLoading() const final
     {
-        return m_font->isLoading();
+        return m_font->isInterstitial();
     }
 
     RefPtr<Font> m_font;
index 291720e..80514f0 100644 (file)
@@ -156,7 +156,7 @@ void Font::platformInit()
     // web standard. The AppKit adjustment of 20% is too big and is
     // incorrectly added to line spacing, so we use a 15% adjustment instead
     // and add it to the ascent.
-    if (!m_isCustomFont && needsAscentAdjustment(familyName.get()))
+    if (origin() == Origin::Local && needsAscentAdjustment(familyName.get()))
         ascent += std::round((ascent + descent) * 0.15f);
 #endif
 
index d528c7b..66b10f1 100644 (file)
@@ -125,7 +125,7 @@ RefPtr<Font> Font::platformCreateScaledFont(const FontDescription& fontDescripti
         scaledFontDescription,
         m_platformData.syntheticBold(),
         m_platformData.syntheticOblique()),
-        isCustomFont(), false);
+        origin(), Interstitial::No);
 }
 
 void Font::determinePitch()
index 99b7c55..6395ee7 100644 (file)
@@ -83,7 +83,7 @@ void Font::platformInit()
     float fCapHeight = scaleEmToUnits(iCapHeight, unitsPerEm) * pointSize;
     float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
 
-    if (!isCustomFont()) {
+    if (origin() == Origin::Local) {
         HWndDC dc(0);
         HGDIOBJ oldFont = SelectObject(dc, m_platformData.hfont());
         int faceLength = GetTextFace(dc, 0, 0);
index 0c918b4..ee36b5a 100644 (file)
@@ -134,7 +134,7 @@ void Font::platformInit()
     float fCapHeight = scaleEmToUnits(iCapHeight, unitsPerEm) * pointSize;
     float fLineGap = scaleEmToUnits(iLineGap, unitsPerEm) * pointSize;
 
-    if (!isCustomFont()) {
+    if (origin() == Origin::Local) {
         Vector<WCHAR> faceName = getFaceName(font);
         fAscent = ascentConsideringMacAscentHack(faceName.data(), fAscent, fDescent);
     }
index d1bd43b..562d2d4 100644 (file)
@@ -139,19 +139,19 @@ void Font::platformDestroy()
 RefPtr<Font> Font::platformCreateScaledFont(const FontDescription& fontDescription, float scaleFactor) const
 {
     float scaledSize = scaleFactor * m_platformData.size();
-    if (isCustomFont())
-        return Font::create(FontPlatformData::cloneWithSize(m_platformData, scaledSize), true, false);
+    if (origin() == Origin::Remote)
+        return Font::create(FontPlatformData::cloneWithSize(m_platformData, scaledSize), Font::Origin::Remote);
 
     LOGFONT winfont;
     GetObject(m_platformData.hfont(), sizeof(LOGFONT), &winfont);
     winfont.lfHeight = -lroundf(scaledSize * (m_platformData.useGDI() ? 1 : 32));
     auto hfont = adoptGDIObject(::CreateFontIndirect(&winfont));
-    return Font::create(FontPlatformData(WTFMove(hfont), scaledSize, m_platformData.syntheticBold(), m_platformData.syntheticOblique(), m_platformData.useGDI()), isCustomFont(), false);
+    return Font::create(FontPlatformData(WTFMove(hfont), scaledSize, m_platformData.syntheticBold(), m_platformData.syntheticOblique(), m_platformData.useGDI()), origin());
 }
 
 void Font::determinePitch()
 {
-    if (isCustomFont()) {
+    if (origin() == Origin::Remote) {
         m_treatAsFixedPitch = false;
         return;
     }
index 3d3dbf2..419064b 100644 (file)
@@ -156,7 +156,7 @@ static AvoidanceReasonFlags canUseForFontAndText(const RenderBlockFlow& flow, In
     // We assume that all lines have metrics based purely on the primary font.
     const auto& style = flow.style();
     auto& fontCascade = style.fontCascade();
-    if (fontCascade.primaryFont().isLoading())
+    if (fontCascade.primaryFont().isInterstitial())
         SET_REASON_AND_RETURN_IF_NEEDED(FlowIsMissingPrimaryFont, reasons, includeReasons);
     std::optional<float> lineHeightConstraint;
     if (style.lineBoxContain() & LineBoxContainGlyphs)