Changeset 266982 in webkit


Ignore:
Timestamp:
Sep 12, 2020 4:01:36 PM (4 years ago)
Author:
mmaxfield@apple.com
Message:

[Apple Win] Add a CTFont member to FontPlatformData
https://bugs.webkit.org/show_bug.cgi?id=216432

Reviewed by Darin Adler.

.:

Include *CoreText.cpp files on the Apple Win port.

  • Source/cmake/OptionsAppleWin.cmake:

Source/WebCore:

This is the second step on the path to replacing the Apple Win port's use of CGFont with CTFont.
This patch adds m_ctFont to FontPlatformData, and makes FontPlatformData's constructors create
this object from their existing arguments. It also enables the USE(CORE_TEXT) flag on the Apple
Win port, but manually disables each of the USE(CORE_TEXT) sites on Windows, so there isn't any
behavior change just yet. The new member, m_ctFont, is therefore still unused in this patch. The
next steps will be replacing our current Apple Win font functions with their USE(CORE_TEXT)
counterparts, one-by-one. (Replacing them one-by-one is better than doing them all at once in a
giant mondo-patch.)

No new tests because there is no behavior change yet.

  • PlatformAppleWin.cmake:
  • platform/graphics/Font.cpp:
  • platform/graphics/FontCascade.cpp:
  • platform/graphics/FontPlatformData.cpp:
  • platform/graphics/FontPlatformData.h: The #defines are temporarily getting worse before they'll

be getting better. When this project is done, there will be fewer #defines, and this file will be
cleaner than it was when I started.
(WebCore::FontPlatformData::cgFont const):
(WebCore::FontPlatformData::ctFont const):

  • platform/graphics/coretext/FontCascadeCoreText.cpp:
  • platform/graphics/coretext/FontCoreText.cpp:
  • platform/graphics/coretext/FontPlatformDataCoreText.cpp:
  • platform/graphics/coretext/GlyphPageCoreText.cpp:
  • platform/graphics/win/FontPlatformDataCGWin.cpp:

(WebCore::FontPlatformData::platformDataInit):
(WebCore::FontPlatformData::FontPlatformData):
(WebCore::FontPlatformData::hash const):
(WebCore::FontPlatformData::platformIsEqual const):

Location:
trunk
Files:
13 edited

Legend:

Unmodified
Added
Removed
  • trunk/ChangeLog

    r266833 r266982  
     12020-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Apple Win] Add a CTFont member to FontPlatformData
     4        https://bugs.webkit.org/show_bug.cgi?id=216432
     5
     6        Reviewed by Darin Adler.
     7
     8        Include ***CoreText.cpp files on the Apple Win port.
     9
     10        * Source/cmake/OptionsAppleWin.cmake:
     11
    1122020-09-10  Adrian Perez de Castro  <aperez@igalia.com>
    213
  • trunk/Source/WebCore/ChangeLog

    r266981 r266982  
     12020-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
     2
     3        [Apple Win] Add a CTFont member to FontPlatformData
     4        https://bugs.webkit.org/show_bug.cgi?id=216432
     5
     6        Reviewed by Darin Adler.
     7
     8        This is the second step on the path to replacing the Apple Win port's use of CGFont with CTFont.
     9        This patch adds m_ctFont to FontPlatformData, and makes FontPlatformData's constructors create
     10        this object from their existing arguments. It also enables the USE(CORE_TEXT) flag on the Apple
     11        Win port, but manually disables each of the USE(CORE_TEXT) sites on Windows, so there isn't any
     12        behavior change just yet. The new member, m_ctFont, is therefore still unused in this patch. The
     13        next steps will be replacing our current Apple Win font functions with their USE(CORE_TEXT)
     14        counterparts, one-by-one. (Replacing them one-by-one is better than doing them all at once in a
     15        giant mondo-patch.)
     16
     17        No new tests because there is no behavior change yet.
     18
     19        * PlatformAppleWin.cmake:
     20        * platform/graphics/Font.cpp:
     21        * platform/graphics/FontCascade.cpp:
     22        * platform/graphics/FontPlatformData.cpp:
     23        * platform/graphics/FontPlatformData.h: The #defines are temporarily getting worse before they'll
     24        be getting better. When this project is done, there will be fewer #defines, and this file will be
     25        cleaner than it was when I started.
     26        (WebCore::FontPlatformData::cgFont const):
     27        (WebCore::FontPlatformData::ctFont const):
     28        * platform/graphics/coretext/FontCascadeCoreText.cpp:
     29        * platform/graphics/coretext/FontCoreText.cpp:
     30        * platform/graphics/coretext/FontPlatformDataCoreText.cpp:
     31        * platform/graphics/coretext/GlyphPageCoreText.cpp:
     32        * platform/graphics/win/FontPlatformDataCGWin.cpp:
     33        (WebCore::FontPlatformData::platformDataInit):
     34        (WebCore::FontPlatformData::FontPlatformData):
     35        (WebCore::FontPlatformData::hash const):
     36        (WebCore::FontPlatformData::platformIsEqual const):
     37
    1382020-09-12  Myles C. Maxfield  <mmaxfield@apple.com>
    239
  • trunk/Source/WebCore/PlatformAppleWin.cmake

    r264786 r266982  
    151151        platform/graphics/cg/UTIRegistry.cpp
    152152
     153        platform/graphics/coretext/FontCascadeCoreText.cpp
     154        platform/graphics/coretext/FontCoreText.cpp
     155        platform/graphics/coretext/FontPlatformDataCoreText.cpp
     156        platform/graphics/coretext/GlyphPageCoreText.cpp
     157
    153158        platform/graphics/opentype/OpenTypeCG.cpp
    154159
  • trunk/Source/WebCore/platform/graphics/Font.cpp

    r266936 r266982  
    475475}
    476476
    477 #if !USE(CORE_TEXT)
     477#if !USE(CORE_TEXT) || PLATFORM(WIN)
    478478
    479479bool Font::isProbablyOnlyUsedToRenderIcons() const
     
    512512}
    513513
    514 #if !USE(CORE_TEXT)
     514#if !USE(CORE_TEXT) || PLATFORM(WIN)
    515515void Font::applyTransforms(GlyphBuffer&, unsigned, unsigned, bool, bool, const AtomString&, StringView, TextDirection) const
    516516{
  • trunk/Source/WebCore/platform/graphics/FontCascade.cpp

    r266936 r266982  
    596596}
    597597
    598 #if !USE(CORE_TEXT)
     598#if !USE(CORE_TEXT) || PLATFORM(WIN)
    599599bool FontCascade::isSubpixelAntialiasingAvailable()
    600600{
  • trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp

    r266936 r266982  
    3232#endif
    3333
     34#if PLATFORM(WIN) && USE(CORE_TEXT)
     35#include <pal/spi/win/CoreTextSPIWin.h>
     36#endif
     37
    3438namespace WebCore {
    3539
     
    5256{
    5357}
    54 
    55 #if USE(CG) && PLATFORM(WIN)
    56 FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
    57     : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode)
    58 {
    59     m_cgFont = cgFont;
    60     ASSERT(m_cgFont);
    61 }
    62 #endif
    6358
    6459#if !USE(FREETYPE)
     
    8580#endif
    8681
    87 #if !USE(CORE_TEXT)
     82#if !USE(CORE_TEXT) || PLATFORM(WIN)
    8883
    8984String FontPlatformData::familyName() const
  • trunk/Source/WebCore/platform/graphics/FontPlatformData.h

    r266936 r266982  
    8787#endif
    8888
     89#if PLATFORM(WIN)
     90    FontPlatformData(GDIObject<HFONT>, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
     91#if USE(CG)
     92    FontPlatformData(GDIObject<HFONT>, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
     93    FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant, TextRenderingMode);
     94#endif
     95#if USE(DIRECT2D)
     96    FontPlatformData(GDIObject<HFONT>&&, COMPtr<IDWriteFont>&&, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
     97#endif
     98#if USE(CAIRO)
     99    FontPlatformData(GDIObject<HFONT>, cairo_font_face_t*, float size, bool bold, bool italic);
     100#endif
     101#endif
     102
     103#if USE(FREETYPE)
     104    FontPlatformData(cairo_font_face_t*, RefPtr<FcPattern>&&, float size, bool fixedWidth, bool syntheticBold, bool syntheticOblique, FontOrientation);
     105#endif
     106
    89107    static FontPlatformData cloneWithOrientation(const FontPlatformData&, FontOrientation);
    90108    static FontPlatformData cloneWithSyntheticOblique(const FontPlatformData&, bool);
    91109    static FontPlatformData cloneWithSize(const FontPlatformData&, float);
    92110
    93 #if USE(CG) && PLATFORM(WIN)
    94     FontPlatformData(CGFontRef, float size, bool syntheticBold, bool syntheticOblique, FontOrientation, FontWidthVariant, TextRenderingMode);
    95 #endif
    96 
    97 #if PLATFORM(WIN)
    98     FontPlatformData(GDIObject<HFONT>, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
    99 #endif
    100 
    101 #if PLATFORM(WIN) && USE(CG)
    102     FontPlatformData(GDIObject<HFONT>, CGFontRef, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
    103 #endif
    104 
    105 #if PLATFORM(WIN) && USE(DIRECT2D)
    106     FontPlatformData(GDIObject<HFONT>&&, COMPtr<IDWriteFont>&&, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
    107 #endif
    108 
    109 #if PLATFORM(WIN) && USE(CAIRO)
    110     FontPlatformData(GDIObject<HFONT>, cairo_font_face_t*, float size, bool bold, bool italic);
    111 #endif
    112 
    113 #if USE(FREETYPE)
    114     FontPlatformData(cairo_font_face_t*, RefPtr<FcPattern>&&, float size, bool fixedWidth, bool syntheticBold, bool syntheticOblique, FontOrientation);
    115 #endif
    116 
    117111#if PLATFORM(WIN)
    118112    HFONT hfont() const { return m_font ? m_font->get() : 0; }
    119113    bool useGDI() const { return m_useGDI; }
    120 #endif
    121 
    122 #if USE(CORE_TEXT)
     114#if USE(CG)
     115    CGFontRef cgFont() const { return m_cgFont.get(); }
     116#endif
     117#if USE(CORE_TEXT)
     118    CTFontRef ctFont() const { return m_ctFont.get(); }
     119#endif
     120#elif USE(CORE_TEXT)
    123121    CTFontRef font() const { return m_font.get(); }
    124122    WEBCORE_EXPORT CTFontRef registeredFont() const; // Returns nullptr iff the font is not registered, such as web fonts (otherwise returns font()).
     
    136134
    137135    bool hasVariations() const { return m_hasVariations; }
    138 
    139 #if USE(CG) && PLATFORM(WIN)
    140     CGFontRef cgFont() const { return m_cgFont.get(); }
    141 #endif
    142136
    143137#if USE(DIRECT2D)
     
    200194    }
    201195
    202 #if PLATFORM(COCOA) || PLATFORM(WIN) || USE(FREETYPE)
    203196    RefPtr<SharedBuffer> openTypeTable(uint32_t table) const;
    204 #endif
    205 
    206 #if !LOG_DISABLED
     197
    207198    String description() const;
    208 #endif
    209199
    210200private:
     
    223213#endif
    224214
    225 #if USE(CORE_TEXT)
     215#if PLATFORM(WIN)
     216    RefPtr<SharedGDIObject<HFONT>> m_font; // FIXME: Delete this in favor of m_ctFont or m_dwFont or m_scaledFont.
     217#if USE(CG)
     218    RetainPtr<CGFontRef> m_cgFont; // FIXME: Delete this in favor of m_ctFont.
     219#endif
     220#if USE(CORE_TEXT)
     221    RetainPtr<CTFontRef> m_ctFont;
     222#endif
     223#elif USE(CORE_TEXT)
    226224    // FIXME: Get rid of one of these. These two fonts are subtly different, and it is not obvious which one to use where.
    227225    RetainPtr<CTFontRef> m_font;
    228226    mutable RetainPtr<CTFontRef> m_ctFont;
    229 #elif PLATFORM(WIN)
    230     RefPtr<SharedGDIObject<HFONT>> m_font;
    231 #endif
    232 
    233 #if USE(CG) && PLATFORM(WIN)
    234     RetainPtr<CGFontRef> m_cgFont;
    235227#endif
    236228
     
    248240#endif
    249241
    250     // The values below are common to all ports
    251     // FIXME: If they're common to all ports, they should move to Font
    252242    float m_size { 0 };
    253243
  • trunk/Source/WebCore/platform/graphics/coretext/FontCascadeCoreText.cpp

    r266977 r266982  
    4242namespace WebCore {
    4343
     44#if !PLATFORM(WIN)
     45
    4446// Confusingly, even when CGFontRenderingGetFontSmoothingDisabled() returns true, CGContextSetShouldSmoothFonts() still impacts text
    4547// rendering, which is why this function uses the "subpixel antialiasing" rather than "smoothing" terminology.
     
    310312}
    311313
    312 }
     314#endif
     315
     316}
  • trunk/Source/WebCore/platform/graphics/coretext/FontCoreText.cpp

    r266977 r266982  
    5252namespace WebCore {
    5353
     54#if !PLATFORM(WIN)
     55
    5456static inline bool caseInsensitiveCompare(CFStringRef a, CFStringRef b)
    5557{
     
    769771}
    770772
     773#endif
     774
    771775} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/coretext/FontPlatformDataCoreText.cpp

    r266977 r266982  
    3535
    3636namespace WebCore {
     37
     38#if !PLATFORM(WIN)
    3739
    3840FontPlatformData::FontPlatformData(CTFontRef font, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
     
    181183}
    182184
     185#endif
     186
    183187} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/coretext/GlyphPageCoreText.cpp

    r266977 r266982  
    4242namespace WebCore {
    4343
     44#if !PLATFORM(WIN)
     45
    4446static bool shouldFillWithVerticalGlyphs(const UChar* buffer, unsigned bufferLength, const Font& font)
    4547{
     
    7981}
    8082
     83#endif
     84
    8185} // namespace WebCore
  • trunk/Source/WebCore/platform/graphics/win/FontPlatformDataCGWin.cpp

    r238298 r266982  
    2929#include "SharedGDIObject.h"
    3030#include <pal/spi/cg/CoreGraphicsSPI.h>
     31#include <pal/spi/win/CoreTextSPIWin.h>
    3132#include <wtf/HashMap.h>
    3233#include <wtf/RetainPtr.h>
     
    115116    GetObject(font, sizeof(logfont), &logfont);
    116117    m_cgFont = adoptCF(CGFontCreateWithPlatformFont(&logfont));
     118    m_ctFont = adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), size, nullptr, nullptr));
    117119    if (!m_useGDI)
    118120        m_isSystemFont = !wcscmp(faceName, L"Lucida Grande");
     
    125127    , m_font(SharedGDIObject<HFONT>::create(WTFMove(hfont)))
    126128    , m_cgFont(font)
     129    , m_ctFont(adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), size, nullptr, nullptr)))
    127130    , m_useGDI(useGDI)
    128131{
    129132}
    130133
     134FontPlatformData::FontPlatformData(CGFontRef cgFont, float size, bool syntheticBold, bool syntheticOblique, FontOrientation orientation, FontWidthVariant widthVariant, TextRenderingMode textRenderingMode)
     135    : FontPlatformData(size, syntheticBold, syntheticOblique, orientation, widthVariant, textRenderingMode)
     136{
     137    m_cgFont = cgFont;
     138    ASSERT(m_cgFont);
     139    m_ctFont = adoptCF(CTFontCreateWithGraphicsFont(m_cgFont.get(), size, nullptr, nullptr));
     140}
     141
    131142unsigned FontPlatformData::hash() const
    132143{
    133     return m_font ? m_font->hash() : 0;
     144    unsigned fontHash = m_font ? m_font->hash() : 0;
     145    CFHashCode cgFontHash = WTF::safeCFHash(m_cgFont.get());
     146    CFHashCode ctFontHash = WTF::safeCFHash(m_ctFont.get());
     147    uintptr_t hashCodes[] = { fontHash, cgFontHash, ctFontHash, m_useGDI };
     148    return StringHasher::hashMemory<sizeof(hashCodes)>(hashCodes);
    134149}
    135150
     
    137152{
    138153    return m_font == other.m_font
    139         && m_cgFont == other.m_cgFont
     154        && WTF::safeCFEqual(m_cgFont.get(), other.m_cgFont.get())
     155        && WTF::safeCFEqual(m_ctFont.get(), other.m_ctFont.get())
    140156        && m_useGDI == other.m_useGDI;
    141157}
  • trunk/Source/cmake/OptionsAppleWin.cmake

    r259606 r266982  
    4949    SET_AND_EXPOSE_TO_BUILD(USE_CA ON)
    5050    SET_AND_EXPOSE_TO_BUILD(USE_CG ON)
     51    SET_AND_EXPOSE_TO_BUILD(USE_CORE_TEXT ON)
    5152
    5253    set(CMAKE_REQUIRED_INCLUDES ${WEBKIT_LIBRARIES_INCLUDE_DIR})
Note: See TracChangeset for help on using the changeset viewer.