Title: [267112] trunk/Source/WebCore
Revision
267112
Author
mmaxfi...@apple.com
Date
2020-09-15 16:34:48 -0700 (Tue, 15 Sep 2020)

Log Message

[Apple Win] Migrate the first part of SimpleFontData{CG}Win.cpp to FontCoreText.cpp
https://bugs.webkit.org/show_bug.cgi?id=216525

Reviewed by Dean Jackson.

This migrates:
- Font::isProbablyOnlyUsedToRenderIcons()
- Font::platformSupportsCodePoint()
- Font::determinePitch()
- Font::platformBoundsForGlyph()
- Font::platformPathForGlyph()
- Font::applyTransforms()

from the old Windows CG codepath to the Core Text codepath. This patch unifies these functions
between the Apple Windows port and the macOS / iOS ports.

Covered by existing tests.

* platform/graphics/Font.cpp:
(WebCore::Font::variantCapsSupportsCharacterForSynthesis const):
(WebCore::Font::platformSupportsCodePoint const): Deleted.
* platform/graphics/coretext/FontCoreText.cpp:
(WebCore::Font::platformWidthForGlyph const): Move this up into the #if !PLATFORM(WIN) section.
We don't want to migrate this one just yet because it causes a significant number of test failures,
which require more investigation.
(WebCore::Font::determinePitch):
(WebCore::Font::isProbablyOnlyUsedToRenderIcons const):
* platform/graphics/win/SimpleFontDataCGWin.cpp:
(WebCore::Font::platformBoundsForGlyph const): Deleted.
(WebCore::Font::platformPathForGlyph const): Deleted.
* platform/graphics/win/SimpleFontDataCairoWin.cpp:
(WebCore::Font::determinePitch): The WinCairo port is the only port still using the non-CG Windows
implementation of this function, so we can just move it directly into the CairoWin-specific file.
* platform/graphics/win/SimpleFontDataWin.cpp:
(WebCore::Font::determinePitch): Deleted.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (267111 => 267112)


--- trunk/Source/WebCore/ChangeLog	2020-09-15 23:33:23 UTC (rev 267111)
+++ trunk/Source/WebCore/ChangeLog	2020-09-15 23:34:48 UTC (rev 267112)
@@ -1,3 +1,41 @@
+2020-09-15  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [Apple Win] Migrate the first part of SimpleFontData{CG}Win.cpp to FontCoreText.cpp
+        https://bugs.webkit.org/show_bug.cgi?id=216525
+
+        Reviewed by Dean Jackson.
+
+        This migrates:
+        - Font::isProbablyOnlyUsedToRenderIcons()
+        - Font::platformSupportsCodePoint()
+        - Font::determinePitch()
+        - Font::platformBoundsForGlyph()
+        - Font::platformPathForGlyph()
+        - Font::applyTransforms()
+
+        from the old Windows CG codepath to the Core Text codepath. This patch unifies these functions
+        between the Apple Windows port and the macOS / iOS ports.
+
+        Covered by existing tests.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::variantCapsSupportsCharacterForSynthesis const):
+        (WebCore::Font::platformSupportsCodePoint const): Deleted.
+        * platform/graphics/coretext/FontCoreText.cpp:
+        (WebCore::Font::platformWidthForGlyph const): Move this up into the #if !PLATFORM(WIN) section.
+        We don't want to migrate this one just yet because it causes a significant number of test failures,
+        which require more investigation.
+        (WebCore::Font::determinePitch):
+        (WebCore::Font::isProbablyOnlyUsedToRenderIcons const):
+        * platform/graphics/win/SimpleFontDataCGWin.cpp:
+        (WebCore::Font::platformBoundsForGlyph const): Deleted.
+        (WebCore::Font::platformPathForGlyph const): Deleted.
+        * platform/graphics/win/SimpleFontDataCairoWin.cpp:
+        (WebCore::Font::determinePitch): The WinCairo port is the only port still using the non-CG Windows
+        implementation of this function, so we can just move it directly into the CairoWin-specific file.
+        * platform/graphics/win/SimpleFontDataWin.cpp:
+        (WebCore::Font::determinePitch): Deleted.
+
 2020-09-15  Chris Dumez  <cdu...@apple.com>
 
         ScriptProcessorNode should throw when trying to change its channel count or channel count mode

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (267111 => 267112)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2020-09-15 23:33:23 UTC (rev 267111)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2020-09-15 23:34:48 UTC (rev 267112)
@@ -474,7 +474,7 @@
     return *derivedFontData.brokenIdeographFont;
 }
 
-#if !USE(CORE_TEXT) || PLATFORM(WIN)
+#if !USE(CORE_TEXT)
 
 bool Font::isProbablyOnlyUsedToRenderIcons() const
 {
@@ -511,7 +511,7 @@
     return platformCreateScaledFont(fontDescription, scaleFactor);
 }
 
-#if !USE(CORE_TEXT) || PLATFORM(WIN)
+#if !USE(CORE_TEXT)
 void Font::applyTransforms(GlyphBuffer&, unsigned, unsigned, bool, bool, const AtomString&, StringView, TextDirection) const
 {
 }
@@ -647,11 +647,6 @@
         return true;
     }
 }
-
-bool Font::platformSupportsCodePoint(UChar32 character, Optional<UChar32> variation) const
-{
-    return variation ? false : glyphForCharacter(character);
-}
 #endif
 
 bool Font::supportsCodePoint(UChar32 character) const

Modified: trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp (267111 => 267112)


--- trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp	2020-09-15 23:33:23 UTC (rev 267111)
+++ trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp	2020-09-15 23:34:48 UTC (rev 267112)
@@ -51,13 +51,13 @@
 
 namespace WebCore {
 
-#if !PLATFORM(WIN)
-
 static inline bool caseInsensitiveCompare(CFStringRef a, CFStringRef b)
 {
     return a && CFStringCompare(a, b, kCFCompareCaseInsensitive) == kCFCompareEqualTo;
 }
 
+#if !PLATFORM(WIN)
+
 static bool fontHasVerticalGlyphs(CTFontRef font)
 {
     return fontHasEitherTable(font, kCTFontTableVhea, kCTFontTableVORG);
@@ -561,6 +561,28 @@
     return createDerivativeFont(scaledFont.get(), size, m_platformData.orientation(), fontTraits, m_platformData.syntheticBold(), m_platformData.syntheticOblique());
 }
 
+float Font::platformWidthForGlyph(Glyph glyph) const
+{
+    CGSize advance = CGSizeZero;
+
+    if (platformData().size()) {
+        bool horizontal = platformData().orientation() == FontOrientation::Horizontal;
+        CTFontOrientation orientation = horizontal || m_isBrokenIdeographFallback ? kCTFontOrientationHorizontal : kCTFontOrientationVertical;
+#if USE(CTFONTGETADVANCES_WORKAROUND)
+        CGFontRenderingStyle style = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
+        if (!CTFontIsAppleColorEmoji(m_platformData.ctFont()) && !m_platformData.hasVariations())
+            CTFontGetUnsummedAdvancesForGlyphsAndStyle(m_platformData.ctFont(), orientation, style, &glyph, &advance, 1);
+        else
+#endif
+        {
+            CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), orientation, &glyph, &advance, 1);
+        }
+    }
+    return advance.width + m_syntheticBoldOffset;
+}
+
+#endif
+
 void Font::applyTransforms(GlyphBuffer& glyphBuffer, unsigned beginningGlyphIndex, unsigned beginningStringIndex, bool enableKerning, bool requiresShaping, const AtomString& locale, StringView text, TextDirection textDirection) const
 {
     UNUSED_PARAM(requiresShaping);
@@ -646,7 +668,7 @@
 
 void Font::determinePitch()
 {
-    CTFontRef ctFont = m_platformData.font();
+    CTFontRef ctFont = m_platformData.ctFont();
     ASSERT(ctFont);
 
     // Special case Osaka-Mono.
@@ -664,7 +686,7 @@
     auto fullName = adoptCF(CTFontCopyFullName(ctFont));
     auto familyName = adoptCF(CTFontCopyFamilyName(ctFont));
 
-    int fixedPitch = extractNumber(adoptCF(static_cast<CFNumberRef>(CTFontCopyAttribute(m_platformData.font(), kCTFontFixedAdvanceAttribute))).get());
+    int fixedPitch = extractNumber(adoptCF(static_cast<CFNumberRef>(CTFontCopyAttribute(m_platformData.ctFont(), kCTFontFixedAdvanceAttribute))).get());
     m_treatAsFixedPitch = (CTFontGetSymbolicTraits(ctFont) & kCTFontMonoSpaceTrait) || fixedPitch || (caseInsensitiveCompare(fullName.get(), CFSTR("Osaka-Mono")) || caseInsensitiveCompare(fullName.get(), CFSTR("MS-PGothic")) || caseInsensitiveCompare(fullName.get(), CFSTR("MonotypeCorsiva")));
 #if PLATFORM(IOS_FAMILY)
     if (familyName && caseInsensitiveCompare(familyName.get(), CFSTR("Courier New"))) {
@@ -685,26 +707,6 @@
     return boundingBox;
 }
 
-float Font::platformWidthForGlyph(Glyph glyph) const
-{
-    CGSize advance = CGSizeZero;
-
-    if (platformData().size()) {
-        bool horizontal = platformData().orientation() == FontOrientation::Horizontal;
-        CTFontOrientation orientation = horizontal || m_isBrokenIdeographFallback ? kCTFontOrientationHorizontal : kCTFontOrientationVertical;
-#if USE(CTFONTGETADVANCES_WORKAROUND)
-        CGFontRenderingStyle style = kCGFontRenderingStyleAntialiasing | kCGFontRenderingStyleSubpixelPositioning | kCGFontRenderingStyleSubpixelQuantization | kCGFontAntialiasingStyleUnfiltered;
-        if (!CTFontIsAppleColorEmoji(m_platformData.ctFont()) && !m_platformData.hasVariations())
-            CTFontGetUnsummedAdvancesForGlyphsAndStyle(m_platformData.ctFont(), orientation, style, &glyph, &advance, 1);
-        else
-#endif
-        {
-            CTFontGetAdvancesForGlyphs(m_platformData.ctFont(), orientation, &glyph, &advance, 1);
-        }
-    }
-    return advance.width + m_syntheticBoldOffset;
-}
-
 Path Font::platformPathForGlyph(Glyph glyph) const
 {
     auto result = adoptCF(CTFontCreatePathForGlyph(platformData().ctFont(), glyph, nullptr));
@@ -733,7 +735,7 @@
 
 bool Font::isProbablyOnlyUsedToRenderIcons() const
 {
-    auto platformFont = platformData().font();
+    auto platformFont = platformData().ctFont();
     if (!platformFont)
         return false;
 
@@ -770,6 +772,4 @@
     });
 }
 
-#endif
-
 } // namespace WebCore

Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp (267111 => 267112)


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp	2020-09-15 23:33:23 UTC (rev 267111)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCGWin.cpp	2020-09-15 23:34:48 UTC (rev 267112)
@@ -112,25 +112,6 @@
     m_fontMetrics.setUnitsPerEm(unitsPerEm);
 }
 
-FloatRect Font::platformBoundsForGlyph(Glyph glyph) const
-{
-    if (!platformData().size())
-        return FloatRect();
-
-    if (m_platformData.useGDI())
-        return boundsForGDIGlyph(glyph);
-
-    CGRect box;
-    CGFontGetGlyphBBoxes(m_platformData.cgFont(), &glyph, 1, &box);
-    float pointSize = m_platformData.size();
-    CGFloat scale = pointSize / fontMetrics().unitsPerEm();
-    FloatRect boundingBox = CGRectApplyAffineTransform(box, CGAffineTransformMakeScale(scale, -scale));
-    if (m_syntheticBoldOffset)
-        boundingBox.setWidth(boundingBox.width() + m_syntheticBoldOffset);
-
-    return boundingBox;
-}
-
 float Font::platformWidthForGlyph(Glyph glyph) const
 {
     if (!platformData().size())
@@ -150,21 +131,6 @@
     return advance.width + m_syntheticBoldOffset;
 }
 
-Path Font::platformPathForGlyph(Glyph glyph) const
-{
-    auto ctFont = adoptCF(CTFontCreateWithGraphicsFont(platformData().cgFont(), platformData().size(), nullptr, nullptr));
-    auto result = adoptCF(CTFontCreatePathForGlyph(ctFont.get(), glyph, nullptr));
-    auto syntheticBoldOffset = this->syntheticBoldOffset();
-    if (syntheticBoldOffset) {
-        auto newPath = adoptCF(CGPathCreateMutable());
-        CGPathAddPath(newPath.get(), nullptr, result.get());
-        auto translation = CGAffineTransformMakeTranslation(syntheticBoldOffset, 0);
-        CGPathAddPath(newPath.get(), &translation, result.get());
-        return newPath;
-    }
-    return adoptCF(CGPathCreateMutableCopy(result.get()));
 }
 
-}
-
 #endif

Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp (267111 => 267112)


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp	2020-09-15 23:33:23 UTC (rev 267111)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataCairoWin.cpp	2020-09-15 23:34:48 UTC (rev 267112)
@@ -95,4 +95,30 @@
     RestoreDC(dc, -1);
 }
 
+void Font::determinePitch()
+{
+    if (origin() == Origin::Remote) {
+        m_treatAsFixedPitch = false;
+        return;
+    }
+
+    // TEXTMETRICS have this. Set m_treatAsFixedPitch based off that.
+    HWndDC dc(0);
+    SaveDC(dc);
+    SelectObject(dc, m_platformData.hfont());
+
+    // Yes, this looks backwards, but the fixed pitch bit is actually set if the font
+    // is *not* fixed pitch. Unbelievable but true!
+    TEXTMETRIC tm;
+    GetTextMetrics(dc, &tm);
+    m_treatAsFixedPitch = !(tm.tmPitchAndFamily & TMPF_FIXED_PITCH);
+
+    RestoreDC(dc, -1);
 }
+
+bool Font::platformSupportsCodePoint(UChar32 character, Optional<UChar32> variation) const
+{
+    return variation ? false : glyphForCharacter(character);
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp (267111 => 267112)


--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp	2020-09-15 23:33:23 UTC (rev 267111)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp	2020-09-15 23:34:48 UTC (rev 267112)
@@ -135,27 +135,6 @@
     return Font::create(FontPlatformData(WTFMove(hfont), scaledSize, m_platformData.syntheticBold(), m_platformData.syntheticOblique(), m_platformData.useGDI()), origin());
 }
 
-void Font::determinePitch()
-{
-    if (origin() == Origin::Remote) {
-        m_treatAsFixedPitch = false;
-        return;
-    }
-
-    // TEXTMETRICS have this.  Set m_treatAsFixedPitch based off that.
-    HWndDC dc(0);
-    SaveDC(dc);
-    SelectObject(dc, m_platformData.hfont());
-
-    // Yes, this looks backwards, but the fixed pitch bit is actually set if the font
-    // is *not* fixed pitch.  Unbelievable but true.
-    TEXTMETRIC tm;
-    GetTextMetrics(dc, &tm);
-    m_treatAsFixedPitch = ((tm.tmPitchAndFamily & TMPF_FIXED_PITCH) == 0);
-
-    RestoreDC(dc, -1);
-}
-
 FloatRect Font::boundsForGDIGlyph(Glyph glyph) const
 {
     HWndDC hdc(0);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to