Changeset 248748 in webkit
- Timestamp:
- Aug 15, 2019 2:49:01 PM (5 years ago)
- Location:
- trunk/Source/WebCore
- Files:
-
- 2 added
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Source/WebCore/ChangeLog
r248747 r248748 1 2019-08-15 Brent Fulgham <bfulgham@apple.com> 2 3 [FTW] Support web fonts 4 https://bugs.webkit.org/show_bug.cgi?id=200771 5 <rdar://problem/54350291> 6 7 Reviewed by Dean Jackson. 8 9 The current code path for handling web fonts uses 'AddFontMemResourceEx'. Unfortunately, this only updates the font caches used by GDI, and is not exposed to DirectWrite. 10 11 This patch does the following: 12 1. Moves some code into a new DirectWriteUtilities file, similar to how Direct2D is handled, so we 13 can share code in more places. 14 2. After adding the font to GDI, it adds the font information to the DirectWrite font cache. 15 3. Add logic to check the overall system DirectWrite fonts, as well as the custom font cache used 16 for downloaded fonts. 17 18 * PlatformFTW.cmake: Add DirectWriteUtilities.cpp 19 * css/CSSFontFaceSource.cpp: 20 * loader/cache/CachedFont.cpp: 21 * loader/cache/CachedSVGFont.cpp: 22 * platform/graphics/Font.cpp: 23 * platform/graphics/Font.h: 24 * platform/graphics/FontCache.cpp: 25 * platform/graphics/FontPlatformData.cpp: 26 * platform/graphics/FontPlatformData.h: 27 * platform/graphics/opentype/OpenTypeUtilities.cpp: 28 (WebCore::renameAndActivateFont): 29 * platform/graphics/win/DirectWriteUtilities.cpp: Added. 30 * platform/graphics/win/DirectWriteUtilities.h: Added. 31 * platform/graphics/win/FontCacheWin.cpp: 32 (WebCore::createGDIFont): 33 * platform/graphics/win/FontCascadeDirect2D.cpp: 34 * platform/graphics/win/FontCustomPlatformData.cpp: 35 (WebCore::FontCustomPlatformData::fontPlatformData): 36 * platform/graphics/win/FontPlatformDataDirect2D.cpp: 37 (WebCore::FontPlatformData::platformDataInit): 38 (WebCore::FontPlatformData::FontPlatformData): 39 (WebCore::FontPlatformData::createFallbackFont): 40 * platform/graphics/win/FontPlatformDataWin.cpp: 41 * platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp: 42 (WebCore::GlyphPage::fill): 43 * platform/graphics/win/GraphicsContextDirect2D.cpp: 44 * platform/graphics/win/SimpleFontDataDirect2D.cpp: 45 (WebCore::Font::systemDWriteFactory): Deleted. 46 (WebCore::Font::systemDWriteGdiInterop): Deleted. 47 * platform/graphics/win/SimpleFontDataWin.cpp: 48 1 49 2019-08-15 Jer Noble <jer.noble@apple.com> 2 50 -
trunk/Source/WebCore/PlatformFTW.cmake
r248020 r248748 65 65 platform/graphics/win/Direct2DOperations.cpp 66 66 platform/graphics/win/Direct2DUtilities.cpp 67 platform/graphics/win/DirectWriteUtilities.cpp 67 68 platform/graphics/win/FloatPointDirect2D.cpp 68 69 platform/graphics/win/FloatRectDirect2D.cpp … … 151 152 ) 152 153 154 if (USE_CF) 155 list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES 156 "${WEBCORE_DIR}/loader/archive/cf" 157 "${WEBCORE_DIR}/platform/cf" 158 "${WEBCORE_DIR}/platform/cf/win" 159 ) 160 161 list(APPEND WebCore_SOURCES 162 editing/SmartReplaceCF.cpp 163 164 loader/archive/cf/LegacyWebArchive.cpp 165 166 platform/cf/KeyedDecoderCF.cpp 167 platform/cf/KeyedEncoderCF.cpp 168 platform/cf/SharedBufferCF.cpp 169 170 platform/cf/win/CertificateCFWin.cpp 171 172 platform/text/cf/HyphenationCF.cpp 173 ) 174 175 list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS 176 loader/archive/cf/LegacyWebArchive.h 177 178 platform/cf/win/CertificateCFWin.h 179 ) 180 181 list(APPEND WebCore_LIBRARIES ${COREFOUNDATION_LIBRARY}) 182 list(APPEND WebCoreTestSupport_LIBRARIES ${COREFOUNDATION_LIBRARY}) 183 else () 184 list(APPEND WebCore_SOURCES 185 platform/text/Hyphenation.cpp 186 ) 187 endif () 188 153 189 list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS 154 190 accessibility/win/AccessibilityObjectWrapperWin.h … … 161 197 platform/graphics/win/Direct2DOperations.h 162 198 platform/graphics/win/Direct2DUtilities.h 199 platform/graphics/win/DirectWriteUtilities.h 163 200 platform/graphics/win/FullScreenController.h 164 201 platform/graphics/win/FullScreenControllerClient.h … … 214 251 ) 215 252 253 make_directory(${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WebKit.resources/en.lproj) 254 file(COPY 255 "${WEBCORE_DIR}/en.lproj/Localizable.strings" 256 "${WEBCORE_DIR}/en.lproj/mediaControlsLocalizedStrings.js" 257 DESTINATION 258 ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WebKit.resources/en.lproj 259 ) 216 260 file(COPY 217 261 "${WEBCORE_DIR}/Modules/mediacontrols/mediaControlsApple.css" -
trunk/Source/WebCore/css/CSSFontFaceSource.cpp
r247377 r248748 49 49 #endif 50 50 51 #if USE(DIRECT2D)52 #include <dwrite.h>53 #endif54 55 51 namespace WebCore { 56 52 -
trunk/Source/WebCore/loader/cache/CachedFont.cpp
r246490 r248748 39 39 #include "WOFFFileFormat.h" 40 40 #include <wtf/Vector.h> 41 42 #if USE(DIRECT2D)43 #include <dwrite.h>44 #endif45 41 46 42 namespace WebCore { -
trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp
r248728 r248748 40 40 #include "TypedElementDescendantIterator.h" 41 41 #include "SVGToOTFFontConversion.h" 42 43 #if USE(DIRECT2D)44 #include <dwrite.h>45 #endif46 42 47 43 namespace WebCore { -
trunk/Source/WebCore/platform/graphics/Font.cpp
r246490 r248748 44 44 #if ENABLE(OPENTYPE_VERTICAL) 45 45 #include "OpenTypeVerticalData.h" 46 #endif47 48 #if USE(DIRECT2D)49 #include <dwrite.h>50 46 #endif 51 47 -
trunk/Source/WebCore/platform/graphics/Font.h
r247566 r248748 52 52 53 53 #if USE(DIRECT2D) 54 interface IDWriteFactory ;54 interface IDWriteFactory5; 55 55 interface IDWriteGdiInterop; 56 56 #endif … … 220 220 #endif 221 221 222 #if USE(DIRECT2D)223 WEBCORE_EXPORT static IDWriteFactory* systemDWriteFactory();224 WEBCORE_EXPORT static IDWriteGdiInterop* systemDWriteGdiInterop();225 #endif226 227 222 private: 228 223 Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback); -
trunk/Source/WebCore/platform/graphics/FontCache.cpp
r247498 r248748 47 47 #endif 48 48 49 #if USE(DIRECT2D)50 #include <dwrite.h>51 #endif52 53 49 #if PLATFORM(IOS_FAMILY) 54 50 #include <wtf/Lock.h> -
trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp
r227552 r248748 30 30 #include "SharedBuffer.h" 31 31 #include <CoreGraphics/CGFont.h> 32 #endif33 34 #if USE(DIRECT2D)35 #include <dwrite.h>36 32 #endif 37 33 -
trunk/Source/WebCore/platform/graphics/FontPlatformData.h
r248152 r248748 66 66 67 67 #if USE(DIRECT2D) 68 #include <dwrite .h>68 #include <dwrite_3.h> 69 69 #endif 70 70 … … 104 104 105 105 #if PLATFORM(WIN) && USE(DIRECT2D) 106 FontPlatformData(GDIObject<HFONT> , IDWriteFont*, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);106 FontPlatformData(GDIObject<HFONT>&&, IDWriteFont*, float size, bool syntheticBold, bool syntheticOblique, bool useGDI); 107 107 #endif 108 108 … … 146 146 147 147 static HRESULT createFallbackFont(const LOGFONT&, IDWriteFont**); 148 static HRESULT createFallbackFont(HFONT, IDWriteFont**); 148 149 #endif 149 150 -
trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp
r173949 r248748 29 29 30 30 #include "SharedBuffer.h" 31 32 #if USE(DIRECT2D) 33 #include "DirectWriteUtilities.h" 34 #include <dwrite_3.h> 35 #endif 31 36 32 37 namespace WebCore { … … 424 429 } 425 430 431 #if USE(DIRECT2D) 432 HRESULT hr = DirectWrite::addFontFromDataToProcessCollection(rewrittenFontData); 433 ASSERT(SUCCEEDED(hr)); 434 #endif 435 426 436 return fontHandle; 427 437 } -
trunk/Source/WebCore/platform/graphics/win/BackingStoreBackendDirect2DImpl.h
r248444 r248748 35 35 namespace WebCore { 36 36 37 class IntSize; 38 37 39 class BackingStoreBackendDirect2DImpl final : public BackingStoreBackendDirect2D { 38 40 public: -
trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp
r247720 r248748 48 48 49 49 #if USE(DIRECT2D) 50 #include <dwrite .h>50 #include <dwrite_3.h> 51 51 #endif 52 52 … … 507 507 matchData.m_chosen.lfStrikeOut = false; 508 508 matchData.m_chosen.lfCharSet = DEFAULT_CHARSET; 509 #if USE(CG) || USE(CAIRO) 509 #if USE(CG) || USE(CAIRO) || USE(DIRECT2D) 510 510 matchData.m_chosen.lfOutPrecision = OUT_TT_ONLY_PRECIS; 511 511 #else -
trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp
r248020 r248748 41 41 #include "WebCoreTextRenderer.h" 42 42 #include <d2d1.h> 43 #include <dwrite .h>43 #include <dwrite_3.h> 44 44 #include <wtf/MathExtras.h> 45 45 -
trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp
r239156 r248748 35 35 36 36 #if USE(DIRECT2D) 37 #include " Font.h"38 #include <dwrite .h>37 #include "DirectWriteUtilities.h" 38 #include <dwrite_3.h> 39 39 #endif 40 40 … … 66 66 logFont.lfStrikeOut = false; 67 67 logFont.lfCharSet = DEFAULT_CHARSET; 68 #if USE(CG) || USE(CAIRO) 68 #if USE(CG) || USE(CAIRO) || USE(DIRECT2D) 69 69 logFont.lfOutPrecision = OUT_TT_ONLY_PRECIS; 70 70 #else … … 77 77 78 78 auto hfont = adoptGDIObject(::CreateFontIndirect(&logFont)); 79 80 79 #if USE(CG) 81 80 RetainPtr<CGFontRef> cgFont = adoptCF(CGFontCreateWithPlatformFont(&logFont)); 82 81 return FontPlatformData(WTFMove(hfont), cgFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate); 83 82 #else 84 COMPtr<IDWriteFont> dwFont; 85 HRESULT hr = Font::systemDWriteGdiInterop()->CreateFontFromLOGFONT(&logFont, &dwFont); 86 if (!SUCCEEDED(hr)) { 87 LOGFONT customFont; 88 hr = ::GetObject(hfont.get(), sizeof(LOGFONT), &customFont); 89 if (SUCCEEDED(hr)) 90 hr = FontPlatformData::createFallbackFont(customFont, &dwFont); 91 } 92 RELEASE_ASSERT(SUCCEEDED(hr)); 83 COMPtr<IDWriteFont> dwFont = DirectWrite::createWithPlatformFont(logFont); 93 84 return FontPlatformData(WTFMove(hfont), dwFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate); 94 85 #endif -
trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp
r237980 r248748 29 29 #if USE(DIRECT2D) 30 30 31 #include "DirectWriteUtilities.h" 31 32 #include "GraphicsContext.h" 33 #include "HWndDC.h" 32 34 #include "SharedGDIObject.h" 33 35 #include <d2d1.h> 34 #include <dwrite .h>36 #include <dwrite_3.h> 35 37 #include <wtf/Vector.h> 36 38 … … 40 42 { 41 43 LOGFONT logfont; 42 GetObject(font, sizeof(logfont), &logfont); 43 44 HRESULT hr = Font::systemDWriteGdiInterop()->CreateFontFromLOGFONT(&logfont, &m_dwFont); 45 if (!SUCCEEDED(hr)) { 46 hr = FontPlatformData::createFallbackFont(logfont, &m_dwFont); 47 if (!SUCCEEDED(hr)) 48 return; 49 } 44 HRESULT hr = ::GetObject(font, sizeof(LOGFONT), &logfont); 45 if (SUCCEEDED(hr)) 46 m_dwFont = DirectWrite::createWithPlatformFont(logfont); 47 RELEASE_ASSERT(m_dwFont); 50 48 51 49 hr = m_dwFont->CreateFontFace(&m_dwFontFace); 52 if (!SUCCEEDED(hr)) 53 return; 50 RELEASE_ASSERT(SUCCEEDED(hr)); 54 51 55 52 if (!m_useGDI) … … 57 54 } 58 55 59 FontPlatformData::FontPlatformData(GDIObject<HFONT> hfont, IDWriteFont* font, float size, bool bold, bool oblique, bool useGDI)56 FontPlatformData::FontPlatformData(GDIObject<HFONT>&& hfont, IDWriteFont* font, float size, bool bold, bool oblique, bool useGDI) 60 57 : m_syntheticBold(bold) 61 58 , m_syntheticOblique(oblique) … … 125 122 return E_POINTER; 126 123 124 *dwFont = DirectWrite::createWithPlatformFont(logFont).get(); 125 126 return S_OK; 127 } 128 129 HRESULT FontPlatformData::createFallbackFont(HFONT hfont, IDWriteFont** dwFont) 130 { 131 if (!dwFont) 132 return E_POINTER; 133 127 134 COMPtr<IDWriteFontCollection> fontCollection; 128 HRESULT hr = Font::systemDWriteFactory()->GetSystemFontCollection(&fontCollection);135 HRESULT hr = DirectWrite::factory()->GetSystemFontCollection(&fontCollection); 129 136 if (FAILED(hr)) 130 137 return hr; 131 138 132 wchar_t localeName[LOCALE_NAME_MAX_LENGTH];133 int localeLength = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);139 HWndDC hdc(0); 140 HGDIOBJ oldFont = ::SelectObject(hdc, hfont); 134 141 135 COMPtr<IDWriteFontFamily> fontFamily; 136 137 unsigned fontFamilyCount = fontCollection->GetFontFamilyCount(); 138 for (unsigned fontIndex = 0; fontIndex < fontFamilyCount; ++fontIndex) { 139 hr = fontCollection->GetFontFamily(fontIndex, &fontFamily); 140 if (FAILED(hr)) 141 return hr; 142 143 COMPtr<IDWriteLocalizedStrings> familyNames; 144 hr = fontFamily->GetFamilyNames(&familyNames); 145 if (FAILED(hr)) 146 return hr; 147 148 BOOL exists = false; 149 unsigned localeIndex = 0; 150 if (localeLength) 151 hr = familyNames->FindLocaleName(localeName, &localeIndex, &exists); 152 153 if (SUCCEEDED(hr) && !exists) 154 hr = familyNames->FindLocaleName(L"en-us", &localeIndex, &exists); 155 156 if (FAILED(hr)) 157 return hr; 158 159 unsigned familyNameLength = 0; 160 hr = familyNames->GetStringLength(localeIndex, &familyNameLength); 161 if (!SUCCEEDED(hr)) 162 return hr; 163 164 Vector<wchar_t> familyName(familyNameLength + 1); 165 hr = familyNames->GetString(localeIndex, familyName.data(), familyName.size()); 166 if (!SUCCEEDED(hr)) 167 return hr; 168 169 if (!wcscmp(logFont.lfFaceName, familyName.data())) 170 break; 171 172 fontFamily = nullptr; 142 COMPtr<IDWriteFontFace> fontFace; 143 hr = DirectWrite::gdiInterop()->CreateFontFaceFromHdc(hdc, &fontFace); 144 if (FAILED(hr)) { 145 ::SelectObject(hdc, oldFont); 146 return hr; 173 147 } 174 148 175 if (!fontFamily) { 176 hr = fontCollection->GetFontFamily(0, &fontFamily); 177 if (FAILED(hr)) 178 return hr; 149 LOGFONT gdiBasedFont = { }; 150 hr = DirectWrite::gdiInterop()->ConvertFontFaceToLOGFONT(fontFace.get(), &gdiBasedFont); 151 if (FAILED(hr)) { 152 ::SelectObject(hdc, oldFont); 153 return hr; 179 154 } 180 155 181 DWRITE_FONT_WEIGHT weight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight); 182 DWRITE_FONT_STRETCH stretch = static_cast<DWRITE_FONT_STRETCH>(logFont.lfQuality); 183 DWRITE_FONT_STYLE style = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL; 156 hr = fontCollection->GetFontFromFontFace(fontFace.get(), dwFont); 184 157 185 hr = fontFamily->GetFirstMatchingFont(weight, stretch, style, dwFont); 158 if (!SUCCEEDED(hr)) 159 hr = DirectWrite::webProcessFontCollection()->GetFontFromFontFace(fontFace.get(), dwFont); 186 160 187 return hr; 161 ::SelectObject(hdc, oldFont); 162 if (SUCCEEDED(hr)) 163 return hr; 164 165 return createFallbackFont(gdiBasedFont, dwFont); 188 166 } 189 167 -
trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp
r248285 r248748 35 35 36 36 #if USE(DIRECT2D) 37 #include <dwrite .h>37 #include <dwrite_3.h> 38 38 #endif 39 39 -
trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp
r247014 r248748 29 29 #if USE(DIRECT2D) 30 30 31 #include "DirectWriteUtilities.h" 31 32 #include "Font.h" 32 33 #include "TextAnalyzerHelper.h" 33 #include <dwrite .h>34 #include <dwrite_3.h> 34 35 35 36 namespace WebCore { … … 44 45 45 46 COMPtr<IDWriteTextAnalyzer> analyzer; 46 HRESULT hr = Font::systemDWriteFactory()->CreateTextAnalyzer(&analyzer);47 HRESULT hr = DirectWrite::factory()->CreateTextAnalyzer(&analyzer); 47 48 RELEASE_ASSERT(SUCCEEDED(hr)); 48 49 -
trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp
r248444 r248748 39 39 #include <d2d1.h> 40 40 #include <d2d1effects.h> 41 #include <dwrite .h>41 #include <dwrite_3.h> 42 42 #include <wtf/URL.h> 43 43 -
trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp
r247014 r248748 29 29 #if USE(DIRECT2D) 30 30 31 #include "DirectWriteUtilities.h" 31 32 #include "FloatRect.h" 32 33 #include "FontCache.h" … … 37 38 #include "NotImplemented.h" 38 39 #include <comutil.h> 39 #include <dwrite .h>40 #include <dwrite_3.h> 40 41 #include <mlang.h> 41 42 #include <unicode/uchar.h> … … 47 48 48 49 namespace WebCore { 49 50 IDWriteFactory* Font::systemDWriteFactory()51 {52 static IDWriteFactory* directWriteFactory = nullptr;53 if (!directWriteFactory) {54 HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(directWriteFactory), reinterpret_cast<IUnknown**>(&directWriteFactory));55 RELEASE_ASSERT(SUCCEEDED(hr));56 }57 58 return directWriteFactory;59 }60 61 IDWriteGdiInterop* Font::systemDWriteGdiInterop()62 {63 static IDWriteGdiInterop* directWriteGdiInterop = nullptr;64 if (!directWriteGdiInterop) {65 HRESULT hr = systemDWriteFactory()->GetGdiInterop(&directWriteGdiInterop);66 RELEASE_ASSERT(SUCCEEDED(hr));67 }68 69 return directWriteGdiInterop;70 }71 50 72 51 static Vector<WCHAR> getFaceName(IDWriteFont* font) -
trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp
r246831 r248748 38 38 #include <wtf/win/GDIObject.h> 39 39 40 #if USE(DIRECT2D)41 #include <dwrite.h>42 #endif43 44 40 namespace WebCore { 45 41
Note: See TracChangeset
for help on using the changeset viewer.