Diff
Modified: trunk/Source/WebCore/ChangeLog (248747 => 248748)
--- trunk/Source/WebCore/ChangeLog 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/ChangeLog 2019-08-15 21:49:01 UTC (rev 248748)
@@ -1,3 +1,51 @@
+2019-08-15 Brent Fulgham <[email protected]>
+
+ [FTW] Support web fonts
+ https://bugs.webkit.org/show_bug.cgi?id=200771
+ <rdar://problem/54350291>
+
+ Reviewed by Dean Jackson.
+
+ 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.
+
+ This patch does the following:
+ 1. Moves some code into a new DirectWriteUtilities file, similar to how Direct2D is handled, so we
+ can share code in more places.
+ 2. After adding the font to GDI, it adds the font information to the DirectWrite font cache.
+ 3. Add logic to check the overall system DirectWrite fonts, as well as the custom font cache used
+ for downloaded fonts.
+
+ * PlatformFTW.cmake: Add DirectWriteUtilities.cpp
+ * css/CSSFontFaceSource.cpp:
+ * loader/cache/CachedFont.cpp:
+ * loader/cache/CachedSVGFont.cpp:
+ * platform/graphics/Font.cpp:
+ * platform/graphics/Font.h:
+ * platform/graphics/FontCache.cpp:
+ * platform/graphics/FontPlatformData.cpp:
+ * platform/graphics/FontPlatformData.h:
+ * platform/graphics/opentype/OpenTypeUtilities.cpp:
+ (WebCore::renameAndActivateFont):
+ * platform/graphics/win/DirectWriteUtilities.cpp: Added.
+ * platform/graphics/win/DirectWriteUtilities.h: Added.
+ * platform/graphics/win/FontCacheWin.cpp:
+ (WebCore::createGDIFont):
+ * platform/graphics/win/FontCascadeDirect2D.cpp:
+ * platform/graphics/win/FontCustomPlatformData.cpp:
+ (WebCore::FontCustomPlatformData::fontPlatformData):
+ * platform/graphics/win/FontPlatformDataDirect2D.cpp:
+ (WebCore::FontPlatformData::platformDataInit):
+ (WebCore::FontPlatformData::FontPlatformData):
+ (WebCore::FontPlatformData::createFallbackFont):
+ * platform/graphics/win/FontPlatformDataWin.cpp:
+ * platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp:
+ (WebCore::GlyphPage::fill):
+ * platform/graphics/win/GraphicsContextDirect2D.cpp:
+ * platform/graphics/win/SimpleFontDataDirect2D.cpp:
+ (WebCore::Font::systemDWriteFactory): Deleted.
+ (WebCore::Font::systemDWriteGdiInterop): Deleted.
+ * platform/graphics/win/SimpleFontDataWin.cpp:
+
2019-08-15 Jer Noble <[email protected]>
[Cocoa] Adopt -preventDisplaySleepForVideoPlayback
Modified: trunk/Source/WebCore/PlatformFTW.cmake (248747 => 248748)
--- trunk/Source/WebCore/PlatformFTW.cmake 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/PlatformFTW.cmake 2019-08-15 21:49:01 UTC (rev 248748)
@@ -64,6 +64,7 @@
platform/graphics/win/DIBPixelData.cpp
platform/graphics/win/Direct2DOperations.cpp
platform/graphics/win/Direct2DUtilities.cpp
+ platform/graphics/win/DirectWriteUtilities.cpp
platform/graphics/win/FloatPointDirect2D.cpp
platform/graphics/win/FloatRectDirect2D.cpp
platform/graphics/win/FloatSizeDirect2D.cpp
@@ -150,6 +151,41 @@
rendering/RenderThemeWin.cpp
)
+if (USE_CF)
+ list(APPEND WebCore_PRIVATE_INCLUDE_DIRECTORIES
+ "${WEBCORE_DIR}/loader/archive/cf"
+ "${WEBCORE_DIR}/platform/cf"
+ "${WEBCORE_DIR}/platform/cf/win"
+ )
+
+ list(APPEND WebCore_SOURCES
+ editing/SmartReplaceCF.cpp
+
+ loader/archive/cf/LegacyWebArchive.cpp
+
+ platform/cf/KeyedDecoderCF.cpp
+ platform/cf/KeyedEncoderCF.cpp
+ platform/cf/SharedBufferCF.cpp
+
+ platform/cf/win/CertificateCFWin.cpp
+
+ platform/text/cf/HyphenationCF.cpp
+ )
+
+ list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
+ loader/archive/cf/LegacyWebArchive.h
+
+ platform/cf/win/CertificateCFWin.h
+ )
+
+ list(APPEND WebCore_LIBRARIES ${COREFOUNDATION_LIBRARY})
+ list(APPEND WebCoreTestSupport_LIBRARIES ${COREFOUNDATION_LIBRARY})
+else ()
+ list(APPEND WebCore_SOURCES
+ platform/text/Hyphenation.cpp
+ )
+endif ()
+
list(APPEND WebCore_PRIVATE_FRAMEWORK_HEADERS
accessibility/win/AccessibilityObjectWrapperWin.h
@@ -160,6 +196,7 @@
platform/graphics/win/DIBPixelData.h
platform/graphics/win/Direct2DOperations.h
platform/graphics/win/Direct2DUtilities.h
+ platform/graphics/win/DirectWriteUtilities.h
platform/graphics/win/FullScreenController.h
platform/graphics/win/FullScreenControllerClient.h
platform/graphics/win/GraphicsContextImplDirect2D.h
@@ -213,7 +250,14 @@
shlwapi
)
+make_directory(${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WebKit.resources/en.lproj)
file(COPY
+ "${WEBCORE_DIR}/en.lproj/Localizable.strings"
+ "${WEBCORE_DIR}/en.lproj/mediaControlsLocalizedStrings.js"
+ DESTINATION
+ ${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/WebKit.resources/en.lproj
+)
+file(COPY
"${WEBCORE_DIR}/Modules/mediacontrols/mediaControlsApple.css"
"${WEBCORE_DIR}/Modules/mediacontrols/mediaControlsApple.js"
DESTINATION
Modified: trunk/Source/WebCore/css/CSSFontFaceSource.cpp (248747 => 248748)
--- trunk/Source/WebCore/css/CSSFontFaceSource.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/css/CSSFontFaceSource.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -48,10 +48,6 @@
#include "SVGURIReference.h"
#endif
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
namespace WebCore {
inline void CSSFontFaceSource::setStatus(Status newStatus)
Modified: trunk/Source/WebCore/loader/cache/CachedFont.cpp (248747 => 248748)
--- trunk/Source/WebCore/loader/cache/CachedFont.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/loader/cache/CachedFont.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -39,10 +39,6 @@
#include "WOFFFileFormat.h"
#include <wtf/Vector.h>
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
namespace WebCore {
CachedFont::CachedFont(CachedResourceRequest&& request, const PAL::SessionID& sessionID, const CookieJar* cookieJar, Type type)
Modified: trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp (248747 => 248748)
--- trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/loader/cache/CachedSVGFont.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -40,10 +40,6 @@
#include "TypedElementDescendantIterator.h"
#include "SVGToOTFFontConversion.h"
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
namespace WebCore {
CachedSVGFont::CachedSVGFont(CachedResourceRequest&& request, const PAL::SessionID& sessionID, const CookieJar* cookieJar)
Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/Font.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -45,10 +45,6 @@
#include "OpenTypeVerticalData.h"
#endif
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
namespace WebCore {
unsigned GlyphPage::s_count = 0;
Modified: trunk/Source/WebCore/platform/graphics/Font.h (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/Font.h 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/Font.h 2019-08-15 21:49:01 UTC (rev 248748)
@@ -51,7 +51,7 @@
#endif
#if USE(DIRECT2D)
-interface IDWriteFactory;
+interface IDWriteFactory5;
interface IDWriteGdiInterop;
#endif
@@ -219,11 +219,6 @@
static float ascentConsideringMacAscentHack(const WCHAR*, float ascent, float descent);
#endif
-#if USE(DIRECT2D)
- WEBCORE_EXPORT static IDWriteFactory* systemDWriteFactory();
- WEBCORE_EXPORT static IDWriteGdiInterop* systemDWriteGdiInterop();
-#endif
-
private:
Font(const FontPlatformData&, Origin, Interstitial, Visibility, OrientationFallback);
Modified: trunk/Source/WebCore/platform/graphics/FontCache.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/FontCache.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/FontCache.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -46,10 +46,6 @@
#include "OpenTypeVerticalData.h"
#endif
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
#if PLATFORM(IOS_FAMILY)
#include <wtf/Lock.h>
#include <wtf/RecursiveLockAdapter.h>
Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -31,10 +31,6 @@
#include <CoreGraphics/CGFont.h>
#endif
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
namespace WebCore {
FontPlatformData::FontPlatformData(WTF::HashTableDeletedValueType)
Modified: trunk/Source/WebCore/platform/graphics/FontPlatformData.h (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/FontPlatformData.h 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/FontPlatformData.h 2019-08-15 21:49:01 UTC (rev 248748)
@@ -65,7 +65,7 @@
#endif
#if USE(DIRECT2D)
-#include <dwrite.h>
+#include <dwrite_3.h>
#endif
namespace WebCore {
@@ -103,7 +103,7 @@
#endif
#if PLATFORM(WIN) && USE(DIRECT2D)
- FontPlatformData(GDIObject<HFONT>, IDWriteFont*, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
+ FontPlatformData(GDIObject<HFONT>&&, IDWriteFont*, float size, bool syntheticBold, bool syntheticOblique, bool useGDI);
#endif
#if PLATFORM(WIN) && USE(CAIRO)
@@ -145,6 +145,7 @@
IDWriteFontFace* dwFontFace() const { return m_dwFontFace.get(); }
static HRESULT createFallbackFont(const LOGFONT&, IDWriteFont**);
+ static HRESULT createFallbackFont(HFONT, IDWriteFont**);
#endif
bool isFixedPitch() const;
Modified: trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/opentype/OpenTypeUtilities.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -29,6 +29,11 @@
#include "SharedBuffer.h"
+#if USE(DIRECT2D)
+#include "DirectWriteUtilities.h"
+#include <dwrite_3.h>
+#endif
+
namespace WebCore {
struct BigEndianUShort {
@@ -423,6 +428,11 @@
return 0;
}
+#if USE(DIRECT2D)
+ HRESULT hr = DirectWrite::addFontFromDataToProcessCollection(rewrittenFontData);
+ ASSERT(SUCCEEDED(hr));
+#endif
+
return fontHandle;
}
Modified: trunk/Source/WebCore/platform/graphics/win/BackingStoreBackendDirect2DImpl.h (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/BackingStoreBackendDirect2DImpl.h 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/BackingStoreBackendDirect2DImpl.h 2019-08-15 21:49:01 UTC (rev 248748)
@@ -34,6 +34,8 @@
namespace WebCore {
+class IntSize;
+
class BackingStoreBackendDirect2DImpl final : public BackingStoreBackendDirect2D {
public:
WEBCORE_EXPORT BackingStoreBackendDirect2DImpl(const IntSize&, float deviceScaleFactor);
Added: trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.cpp (0 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.cpp (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -0,0 +1,225 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "DirectWriteUtilities.h"
+
+#if USE(DIRECT2D)
+
+#include "COMPtr.h"
+#include "SharedBuffer.h"
+#include <dwrite_3.h>
+
+
+namespace WebCore {
+
+namespace DirectWrite {
+
+IDWriteFactory5* factory()
+{
+ static IDWriteFactory5* directWriteFactory = nullptr;
+ if (!directWriteFactory) {
+ HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(directWriteFactory), reinterpret_cast<IUnknown**>(&directWriteFactory));
+ directWriteFactory->AddRef();
+ RELEASE_ASSERT(SUCCEEDED(hr));
+ }
+
+ return directWriteFactory;
+}
+
+IDWriteGdiInterop* gdiInterop()
+{
+ static IDWriteGdiInterop* directWriteGdiInterop = nullptr;
+ if (!directWriteGdiInterop) {
+ HRESULT hr = factory()->GetGdiInterop(&directWriteGdiInterop);
+ directWriteGdiInterop->AddRef();
+ RELEASE_ASSERT(SUCCEEDED(hr));
+ }
+
+ return directWriteGdiInterop;
+}
+
+static IDWriteInMemoryFontFileLoader* memoryFontLoader()
+{
+ static IDWriteInMemoryFontFileLoader* memoryFontLoader = nullptr;
+ if (!memoryFontLoader) {
+ HRESULT hr = factory()->CreateInMemoryFontFileLoader(&memoryFontLoader);
+ RELEASE_ASSERT(SUCCEEDED(hr));
+ memoryFontLoader->AddRef();
+
+ hr = factory()->RegisterFontFileLoader(memoryFontLoader);
+ RELEASE_ASSERT(SUCCEEDED(hr));
+ }
+
+ return memoryFontLoader;
+}
+
+static IDWriteFontSetBuilder1* fontSetBuilder()
+{
+ static IDWriteFontSetBuilder1* fontSetBuilder = nullptr;
+ if (!fontSetBuilder) {
+ HRESULT hr = factory()->CreateFontSetBuilder(&fontSetBuilder);
+ RELEASE_ASSERT(SUCCEEDED(hr));
+ fontSetBuilder->AddRef();
+ }
+
+ return fontSetBuilder;
+}
+
+static COMPtr<IDWriteFontSet> fontSet;
+static COMPtr<IDWriteFontCollection1> fontCollection;
+static UINT32 fontCount = 0;
+
+IDWriteFontCollection1* webProcessFontCollection()
+{
+ HRESULT hr = S_OK;
+
+ if (!fontSet) {
+ hr = fontSetBuilder()->CreateFontSet(&fontSet);
+ if (!SUCCEEDED(hr))
+ return nullptr;
+
+ fontCollection = nullptr;
+ hr = factory()->CreateFontCollectionFromFontSet(fontSet.get(), &fontCollection);
+ if (!SUCCEEDED(hr))
+ return nullptr;
+
+ ASSERT(fontCollection->GetFontFamilyCount() == fontCount);
+ }
+
+ return fontCollection.get();
+}
+
+HRESULT addFontFromDataToProcessCollection(const Vector<char>& fontData)
+{
+ COMPtr<IDWriteFontFile> fontFile;
+ HRESULT hr = memoryFontLoader()->CreateInMemoryFontFileReference(factory(), fontData.data(), fontData.size(), nullptr, &fontFile);
+ if (!SUCCEEDED(hr))
+ return hr;
+
+ hr = fontSetBuilder()->AddFontFile(fontFile.get());
+ if (!SUCCEEDED(hr))
+ return hr;
+
+ fontSet = nullptr;
+ ++fontCount;
+
+ return hr;
+}
+
+Vector<wchar_t> familyNameForLocale(IDWriteFontFamily* fontFamily, const Vector<wchar_t>& localeName)
+{
+ COMPtr<IDWriteLocalizedStrings> familyNames;
+ HRESULT hr = fontFamily->GetFamilyNames(&familyNames);
+ if (FAILED(hr))
+ return { };
+
+ BOOL exists = false;
+ unsigned localeIndex = 0;
+ if (!localeName.isEmpty())
+ hr = familyNames->FindLocaleName(localeName.data(), &localeIndex, &exists);
+
+ if (SUCCEEDED(hr) && !exists)
+ hr = familyNames->FindLocaleName(L"en-us", &localeIndex, &exists);
+
+ if (FAILED(hr))
+ return { };
+
+ unsigned familyNameLength = 0;
+ hr = familyNames->GetStringLength(localeIndex, &familyNameLength);
+ if (!SUCCEEDED(hr))
+ return { };
+
+ Vector<wchar_t> familyName(familyNameLength + 1);
+ hr = familyNames->GetString(localeIndex, familyName.data(), familyName.size());
+ if (!SUCCEEDED(hr))
+ return { };
+
+ return familyName;
+}
+
+COMPtr<IDWriteFontFamily> fontFamilyForCollection(IDWriteFontCollection* fontCollection, const Vector<wchar_t>& localeName, const LOGFONT& logFont)
+{
+ COMPtr<IDWriteFontFamily> fontFamily;
+
+ unsigned fontFamilyCount = fontCollection->GetFontFamilyCount();
+ for (unsigned fontIndex = 0; fontIndex < fontFamilyCount; ++fontIndex) {
+ HRESULT hr = fontCollection->GetFontFamily(fontIndex, &fontFamily);
+ if (FAILED(hr))
+ return nullptr;
+
+ auto familyName = familyNameForLocale(fontFamily.get(), localeName);
+
+ if (!wcscmp(logFont.lfFaceName, familyName.data()))
+ return fontFamily;
+
+ fontFamily = nullptr;
+ }
+
+ return nullptr;
+}
+
+COMPtr<IDWriteFont> createWithPlatformFont(const LOGFONT& logFont)
+{
+ COMPtr<IDWriteFontCollection> systemFontCollection;
+ HRESULT hr = factory()->GetSystemFontCollection(&systemFontCollection);
+ if (FAILED(hr))
+ return nullptr;
+
+ Vector<wchar_t> localeName(LOCALE_NAME_MAX_LENGTH);
+ int localeLength = GetUserDefaultLocaleName(localeName.data(), LOCALE_NAME_MAX_LENGTH);
+
+ COMPtr<IDWriteFontFamily> fontFamily = fontFamilyForCollection(systemFontCollection.get(), localeName, logFont);
+ if (!fontFamily)
+ fontFamily = fontFamilyForCollection(webProcessFontCollection(), localeName, logFont);
+
+ if (!fontFamily) {
+ // Just return the first system font.
+ hr = systemFontCollection->GetFontFamily(0, &fontFamily);
+ if (FAILED(hr))
+ return nullptr;
+
+#ifndef NDEBUG
+ auto familyName = familyNameForLocale(fontFamily.get(), localeName);
+ UNUSED_VARIABLE(familyName);
+#endif
+ }
+
+ DWRITE_FONT_WEIGHT weight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight);
+ DWRITE_FONT_STRETCH stretch = static_cast<DWRITE_FONT_STRETCH>(logFont.lfQuality);
+ DWRITE_FONT_STYLE style = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
+
+ COMPtr<IDWriteFont> dwFont;
+ hr = fontFamily->GetFirstMatchingFont(weight, stretch, style, &dwFont);
+ ASSERT(SUCCEEDED(hr));
+
+ return dwFont;
+}
+
+} // namespace DirectWrite
+
+} // namespace WebCore
+
+#endif // USE(DIRECT2D)
Added: trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.h (0 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.h (rev 0)
+++ trunk/Source/WebCore/platform/graphics/win/DirectWriteUtilities.h 2019-08-15 21:49:01 UTC (rev 248748)
@@ -0,0 +1,59 @@
+/*
+ * Copyright (C) 2019 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#if USE(DIRECT2D)
+
+#include "COMPtr.h"
+
+interface IDWriteFactory5;
+interface IDWriteFont;
+interface IDWriteFontCollection;
+interface IDWriteFontCollection1;
+interface IDWriteFontFamily;
+interface IDWriteGdiInterop;
+
+namespace WebCore {
+
+class SharedBuffer;
+
+namespace DirectWrite {
+
+IDWriteFactory5* factory();
+IDWriteGdiInterop* gdiInterop();
+
+IDWriteFontCollection1* webProcessFontCollection();
+
+HRESULT addFontFromDataToProcessCollection(const Vector<char>& fontData);
+COMPtr<IDWriteFontFamily> fontFamilyForCollection(IDWriteFontCollection*, const Vector<wchar_t>& localeName, const LOGFONT&);
+COMPtr<IDWriteFont> createWithPlatformFont(const LOGFONT&);
+Vector<wchar_t> familyNameForLocale(IDWriteFontFamily*, const Vector<wchar_t>& localeName);
+
+} // namespace DirectWrite
+
+} // namespace WebCore
+
+#endif // USE(DIRECT2D)
Modified: trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -47,7 +47,7 @@
#endif
#if USE(DIRECT2D)
-#include <dwrite.h>
+#include <dwrite_3.h>
#endif
using std::min;
@@ -506,7 +506,7 @@
matchData.m_chosen.lfUnderline = false;
matchData.m_chosen.lfStrikeOut = false;
matchData.m_chosen.lfCharSet = DEFAULT_CHARSET;
-#if USE(CG) || USE(CAIRO)
+#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
matchData.m_chosen.lfOutPrecision = OUT_TT_ONLY_PRECIS;
#else
matchData.m_chosen.lfOutPrecision = OUT_TT_PRECIS;
Modified: trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/FontCascadeDirect2D.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -40,7 +40,7 @@
#include "UniscribeController.h"
#include "WebCoreTextRenderer.h"
#include <d2d1.h>
-#include <dwrite.h>
+#include <dwrite_3.h>
#include <wtf/MathExtras.h>
namespace WebCore {
Modified: trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/FontCustomPlatformData.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -34,8 +34,8 @@
#endif
#if USE(DIRECT2D)
-#include "Font.h"
-#include <dwrite.h>
+#include "DirectWriteUtilities.h"
+#include <dwrite_3.h>
#endif
namespace WebCore {
@@ -65,7 +65,7 @@
logFont.lfUnderline = false;
logFont.lfStrikeOut = false;
logFont.lfCharSet = DEFAULT_CHARSET;
-#if USE(CG) || USE(CAIRO)
+#if USE(CG) || USE(CAIRO) || USE(DIRECT2D)
logFont.lfOutPrecision = OUT_TT_ONLY_PRECIS;
#else
logFont.lfOutPrecision = OUT_TT_PRECIS;
@@ -76,20 +76,11 @@
logFont.lfWeight = bold ? 700 : 400;
auto hfont = adoptGDIObject(::CreateFontIndirect(&logFont));
-
#if USE(CG)
RetainPtr<CGFontRef> cgFont = adoptCF(CGFontCreateWithPlatformFont(&logFont));
return FontPlatformData(WTFMove(hfont), cgFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
#else
- COMPtr<IDWriteFont> dwFont;
- HRESULT hr = Font::systemDWriteGdiInterop()->CreateFontFromLOGFONT(&logFont, &dwFont);
- if (!SUCCEEDED(hr)) {
- LOGFONT customFont;
- hr = ::GetObject(hfont.get(), sizeof(LOGFONT), &customFont);
- if (SUCCEEDED(hr))
- hr = FontPlatformData::createFallbackFont(customFont, &dwFont);
- }
- RELEASE_ASSERT(SUCCEEDED(hr));
+ COMPtr<IDWriteFont> dwFont = DirectWrite::createWithPlatformFont(logFont);
return FontPlatformData(WTFMove(hfont), dwFont.get(), size, bold, italic, renderingMode == FontRenderingMode::Alternate);
#endif
}
Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataDirect2D.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -28,10 +28,12 @@
#if USE(DIRECT2D)
+#include "DirectWriteUtilities.h"
#include "GraphicsContext.h"
+#include "HWndDC.h"
#include "SharedGDIObject.h"
#include <d2d1.h>
-#include <dwrite.h>
+#include <dwrite_3.h>
#include <wtf/Vector.h>
namespace WebCore {
@@ -39,24 +41,19 @@
void FontPlatformData::platformDataInit(HFONT font, float size, HDC hdc, WCHAR* faceName)
{
LOGFONT logfont;
- GetObject(font, sizeof(logfont), &logfont);
+ HRESULT hr = ::GetObject(font, sizeof(LOGFONT), &logfont);
+ if (SUCCEEDED(hr))
+ m_dwFont = DirectWrite::createWithPlatformFont(logfont);
+ RELEASE_ASSERT(m_dwFont);
- HRESULT hr = Font::systemDWriteGdiInterop()->CreateFontFromLOGFONT(&logfont, &m_dwFont);
- if (!SUCCEEDED(hr)) {
- hr = FontPlatformData::createFallbackFont(logfont, &m_dwFont);
- if (!SUCCEEDED(hr))
- return;
- }
-
hr = m_dwFont->CreateFontFace(&m_dwFontFace);
- if (!SUCCEEDED(hr))
- return;
+ RELEASE_ASSERT(SUCCEEDED(hr));
if (!m_useGDI)
m_isSystemFont = !wcscmp(faceName, L"Lucida Grande");
}
-FontPlatformData::FontPlatformData(GDIObject<HFONT> hfont, IDWriteFont* font, float size, bool bold, bool oblique, bool useGDI)
+FontPlatformData::FontPlatformData(GDIObject<HFONT>&& hfont, IDWriteFont* font, float size, bool bold, bool oblique, bool useGDI)
: m_syntheticBold(bold)
, m_syntheticOblique(oblique)
, m_size(size)
@@ -124,67 +121,48 @@
if (!dwFont)
return E_POINTER;
+ *dwFont = DirectWrite::createWithPlatformFont(logFont).get();
+
+ return S_OK;
+}
+
+HRESULT FontPlatformData::createFallbackFont(HFONT hfont, IDWriteFont** dwFont)
+{
+ if (!dwFont)
+ return E_POINTER;
+
COMPtr<IDWriteFontCollection> fontCollection;
- HRESULT hr = Font::systemDWriteFactory()->GetSystemFontCollection(&fontCollection);
+ HRESULT hr = DirectWrite::factory()->GetSystemFontCollection(&fontCollection);
if (FAILED(hr))
return hr;
- wchar_t localeName[LOCALE_NAME_MAX_LENGTH];
- int localeLength = GetUserDefaultLocaleName(localeName, LOCALE_NAME_MAX_LENGTH);
+ HWndDC hdc(0);
+ HGDIOBJ oldFont = ::SelectObject(hdc, hfont);
- COMPtr<IDWriteFontFamily> fontFamily;
-
- unsigned fontFamilyCount = fontCollection->GetFontFamilyCount();
- for (unsigned fontIndex = 0; fontIndex < fontFamilyCount; ++fontIndex) {
- hr = fontCollection->GetFontFamily(fontIndex, &fontFamily);
- if (FAILED(hr))
- return hr;
-
- COMPtr<IDWriteLocalizedStrings> familyNames;
- hr = fontFamily->GetFamilyNames(&familyNames);
- if (FAILED(hr))
- return hr;
-
- BOOL exists = false;
- unsigned localeIndex = 0;
- if (localeLength)
- hr = familyNames->FindLocaleName(localeName, &localeIndex, &exists);
-
- if (SUCCEEDED(hr) && !exists)
- hr = familyNames->FindLocaleName(L"en-us", &localeIndex, &exists);
-
- if (FAILED(hr))
- return hr;
-
- unsigned familyNameLength = 0;
- hr = familyNames->GetStringLength(localeIndex, &familyNameLength);
- if (!SUCCEEDED(hr))
- return hr;
-
- Vector<wchar_t> familyName(familyNameLength + 1);
- hr = familyNames->GetString(localeIndex, familyName.data(), familyName.size());
- if (!SUCCEEDED(hr))
- return hr;
-
- if (!wcscmp(logFont.lfFaceName, familyName.data()))
- break;
-
- fontFamily = nullptr;
+ COMPtr<IDWriteFontFace> fontFace;
+ hr = DirectWrite::gdiInterop()->CreateFontFaceFromHdc(hdc, &fontFace);
+ if (FAILED(hr)) {
+ ::SelectObject(hdc, oldFont);
+ return hr;
}
- if (!fontFamily) {
- hr = fontCollection->GetFontFamily(0, &fontFamily);
- if (FAILED(hr))
- return hr;
+ LOGFONT gdiBasedFont = { };
+ hr = DirectWrite::gdiInterop()->ConvertFontFaceToLOGFONT(fontFace.get(), &gdiBasedFont);
+ if (FAILED(hr)) {
+ ::SelectObject(hdc, oldFont);
+ return hr;
}
- DWRITE_FONT_WEIGHT weight = static_cast<DWRITE_FONT_WEIGHT>(logFont.lfWeight);
- DWRITE_FONT_STRETCH stretch = static_cast<DWRITE_FONT_STRETCH>(logFont.lfQuality);
- DWRITE_FONT_STYLE style = logFont.lfItalic ? DWRITE_FONT_STYLE_ITALIC : DWRITE_FONT_STYLE_NORMAL;
+ hr = fontCollection->GetFontFromFontFace(fontFace.get(), dwFont);
- hr = fontFamily->GetFirstMatchingFont(weight, stretch, style, dwFont);
+ if (!SUCCEEDED(hr))
+ hr = DirectWrite::webProcessFontCollection()->GetFontFromFontFace(fontFace.get(), dwFont);
- return hr;
+ ::SelectObject(hdc, oldFont);
+ if (SUCCEEDED(hr))
+ return hr;
+
+ return createFallbackFont(gdiBasedFont, dwFont);
}
}
Modified: trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/FontPlatformDataWin.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -34,7 +34,7 @@
#include <wtf/text/WTFString.h>
#if USE(DIRECT2D)
-#include <dwrite.h>
+#include <dwrite_3.h>
#endif
using std::min;
Modified: trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeDirect2D.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -28,9 +28,10 @@
#if USE(DIRECT2D)
+#include "DirectWriteUtilities.h"
#include "Font.h"
#include "TextAnalyzerHelper.h"
-#include <dwrite.h>
+#include <dwrite_3.h>
namespace WebCore {
@@ -43,7 +44,7 @@
bool haveGlyphs = false;
COMPtr<IDWriteTextAnalyzer> analyzer;
- HRESULT hr = Font::systemDWriteFactory()->CreateTextAnalyzer(&analyzer);
+ HRESULT hr = DirectWrite::factory()->CreateTextAnalyzer(&analyzer);
RELEASE_ASSERT(SUCCEEDED(hr));
auto& fontPlatformData = font.platformData();
Modified: trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/GraphicsContextDirect2D.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -38,7 +38,7 @@
#include "PlatformContextDirect2D.h"
#include <d2d1.h>
#include <d2d1effects.h>
-#include <dwrite.h>
+#include <dwrite_3.h>
#include <wtf/URL.h>
#pragma warning (disable : 4756)
Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataDirect2D.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -28,6 +28,7 @@
#if USE(DIRECT2D)
+#include "DirectWriteUtilities.h"
#include "FloatRect.h"
#include "FontCache.h"
#include "FontDescription.h"
@@ -36,7 +37,7 @@
#include "HWndDC.h"
#include "NotImplemented.h"
#include <comutil.h>
-#include <dwrite.h>
+#include <dwrite_3.h>
#include <mlang.h>
#include <unicode/uchar.h>
#include <unicode/unorm.h>
@@ -47,28 +48,6 @@
namespace WebCore {
-IDWriteFactory* Font::systemDWriteFactory()
-{
- static IDWriteFactory* directWriteFactory = nullptr;
- if (!directWriteFactory) {
- HRESULT hr = DWriteCreateFactory(DWRITE_FACTORY_TYPE_SHARED, __uuidof(directWriteFactory), reinterpret_cast<IUnknown**>(&directWriteFactory));
- RELEASE_ASSERT(SUCCEEDED(hr));
- }
-
- return directWriteFactory;
-}
-
-IDWriteGdiInterop* Font::systemDWriteGdiInterop()
-{
- static IDWriteGdiInterop* directWriteGdiInterop = nullptr;
- if (!directWriteGdiInterop) {
- HRESULT hr = systemDWriteFactory()->GetGdiInterop(&directWriteGdiInterop);
- RELEASE_ASSERT(SUCCEEDED(hr));
- }
-
- return directWriteGdiInterop;
-}
-
static Vector<WCHAR> getFaceName(IDWriteFont* font)
{
if (!font)
Modified: trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp (248747 => 248748)
--- trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp 2019-08-15 21:39:32 UTC (rev 248747)
+++ trunk/Source/WebCore/platform/graphics/win/SimpleFontDataWin.cpp 2019-08-15 21:49:01 UTC (rev 248748)
@@ -37,10 +37,6 @@
#include <wtf/MathExtras.h>
#include <wtf/win/GDIObject.h>
-#if USE(DIRECT2D)
-#include <dwrite.h>
-#endif
-
namespace WebCore {
static bool g_shouldApplyMacAscentHack;