Title: [253313] trunk/Source/WebCore
Revision
253313
Author
[email protected]
Date
2019-12-09 17:50:00 -0800 (Mon, 09 Dec 2019)

Log Message

[WinCairo] Add support of Unicode surrogate pair for simple texts
https://bugs.webkit.org/show_bug.cgi?id=205003

Reviewed by Don Olmstead.

FontCache::systemFallbackForCharacters of Windows port was working
only for BMP because it's using GetFontUnicodeRanges API which
supports only BMP. Use GetCharacterPlacement API to get glyphs for
non-BMP.

GlyphPage::fill of WinCairo port was working only for BMP because
it's using GetGlyphIndices API which supports only BMP. Use
GetCharacterPlacement API to get glyphs for non-BMP.

This change can be tested by pixel tests, but WinCairo port
doesn't include -expected.png files yet. Tested manually.

* platform/graphics/win/FontCacheWin.cpp:
(WebCore::currentFontContainsCharacterNonBMP): Added.
(WebCore::currentFontContainsCharacter): Changed to take a string
instead of a 16bit character.
(WebCore::FontCache::systemFallbackForCharacters):
* platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp:
(WebCore::GlyphPage::fill): Use GetCharacterPlacement for non-BMP.

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (253312 => 253313)


--- trunk/Source/WebCore/ChangeLog	2019-12-10 01:48:58 UTC (rev 253312)
+++ trunk/Source/WebCore/ChangeLog	2019-12-10 01:50:00 UTC (rev 253313)
@@ -1,3 +1,30 @@
+2019-12-09  Fujii Hironori  <[email protected]>
+
+        [WinCairo] Add support of Unicode surrogate pair for simple texts
+        https://bugs.webkit.org/show_bug.cgi?id=205003
+
+        Reviewed by Don Olmstead.
+
+        FontCache::systemFallbackForCharacters of Windows port was working
+        only for BMP because it's using GetFontUnicodeRanges API which
+        supports only BMP. Use GetCharacterPlacement API to get glyphs for
+        non-BMP.
+
+        GlyphPage::fill of WinCairo port was working only for BMP because
+        it's using GetGlyphIndices API which supports only BMP. Use
+        GetCharacterPlacement API to get glyphs for non-BMP.
+
+        This change can be tested by pixel tests, but WinCairo port
+        doesn't include -expected.png files yet. Tested manually.
+
+        * platform/graphics/win/FontCacheWin.cpp:
+        (WebCore::currentFontContainsCharacterNonBMP): Added.
+        (WebCore::currentFontContainsCharacter): Changed to take a string
+        instead of a 16bit character.
+        (WebCore::FontCache::systemFallbackForCharacters):
+        * platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp:
+        (WebCore::GlyphPage::fill): Use GetCharacterPlacement for non-BMP.
+
 2019-12-09  Megan Gardner  <[email protected]>
 
         Fill HighlightRangeGroup and HighlightMap with values from _javascript_

Modified: trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp (253312 => 253313)


--- trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2019-12-10 01:48:58 UTC (rev 253312)
+++ trunk/Source/WebCore/platform/graphics/win/FontCacheWin.cpp	2019-12-10 01:50:00 UTC (rev 253313)
@@ -183,8 +183,36 @@
     return codePageMasks;
 }
 
-static bool currentFontContainsCharacter(HDC hdc, UChar character)
+static bool currentFontContainsCharacterNonBMP(HDC hdc, const UChar* str)
 {
+    ASSERT(U_IS_LEAD(str[0]) && U_IS_TRAIL(str[1]));
+
+    SCRIPT_CACHE sc = { };
+    SCRIPT_FONTPROPERTIES fp = { };
+    fp.cBytes = sizeof fp;
+    ScriptGetFontProperties(hdc, &sc, &fp);
+    ScriptFreeCache(&sc);
+
+    wchar_t glyphs[2] = { };
+    GCP_RESULTS gcpResults = { };
+    gcpResults.lStructSize = sizeof gcpResults;
+    gcpResults.nGlyphs = 2;
+    gcpResults.lpGlyphs = glyphs;
+    GetCharacterPlacement(hdc, wcharFrom(str), 2, 0, &gcpResults, GCP_GLYPHSHAPE);
+
+    if (gcpResults.nGlyphs != 1)
+        return false;
+    auto glyph = glyphs[0];
+    return !(glyph == fp.wgBlank || glyph == fp.wgInvalid || glyph == fp.wgDefault);
+}
+
+static bool currentFontContainsCharacter(HDC hdc, const UChar* str, size_t length)
+{
+    ASSERT(length <= 2);
+    if (length == 2)
+        return currentFontContainsCharacterNonBMP(hdc, str);
+    UChar character = str[0];
+
     static Vector<char, 512> glyphsetBuffer;
     glyphsetBuffer.resize(GetFontUnicodeRanges(hdc, 0));
     GLYPHSET* glyphset = reinterpret_cast<GLYPHSET*>(glyphsetBuffer.data());
@@ -213,14 +241,15 @@
 
 RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& description, const Font* originalFontData, IsForPlatformFont, PreferColoredFont, const UChar* characters, unsigned length)
 {
-    UChar character = characters[0];
     RefPtr<Font> fontData;
     HWndDC hdc(0);
     HFONT primaryFont = originalFontData->platformData().hfont();
     HGDIOBJ oldFont = SelectObject(hdc, primaryFont);
     HFONT hfont = 0;
+    IMLangFontLinkType* langFontLink = getFontLinkInterface();
 
-    if (IMLangFontLinkType* langFontLink = getFontLinkInterface()) {
+    if (length == 1 && langFontLink) {
+        UChar character = characters[0];
         // Try MLang font linking first.
         DWORD codePages = 0;
         if (SUCCEEDED(langFontLink->GetCharCodePages(character, &codePages))) {
@@ -236,7 +265,7 @@
                         // We asked about a code page that is not one of the code pages
                         // returned by MLang, so the font might not contain the character.
                         SelectObject(hdc, hfont);
-                        if (!currentFontContainsCharacter(hdc, character)) {
+                        if (!currentFontContainsCharacter(hdc, characters, length)) {
                             DeleteObject(hfont);
                             hfont = 0;
                         }
@@ -287,7 +316,7 @@
         GetTextFace(hdc, LF_FACESIZE, name);
         familyName = String(name);
 
-        if (containsCharacter || currentFontContainsCharacter(hdc, character))
+        if (containsCharacter || currentFontContainsCharacter(hdc, characters, length))
             break;
 
         if (!linkedFonts)

Modified: trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp (253312 => 253313)


--- trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp	2019-12-10 01:48:58 UTC (rev 253312)
+++ trunk/Source/WebCore/platform/graphics/win/GlyphPageTreeNodeCairoWin.cpp	2019-12-10 01:50:00 UTC (rev 253313)
@@ -37,10 +37,7 @@
 
 bool GlyphPage::fill(UChar* buffer, unsigned bufferLength)
 {
-    // bufferLength will be greater than the requested number of glyphs if the buffer contains surrogate pairs.
-    // We won't support this for now.
-    if (bufferLength > GlyphPage::size)
-        return false;
+    ASSERT(bufferLength == GlyphPage::size || bufferLength == 2 * GlyphPage::size);
 
     const Font& font = this->font();
     bool haveGlyphs = false;
@@ -49,17 +46,45 @@
     SaveDC(dc);
     SelectObject(dc, font.platformData().hfont());
 
-    WORD localGlyphBuffer[GlyphPage::size * 2];
-    DWORD result = GetGlyphIndices(dc, wcharFrom(buffer), bufferLength, localGlyphBuffer, GGI_MARK_NONEXISTING_GLYPHS);
-    bool success = result != GDI_ERROR && static_cast<unsigned>(result) == bufferLength;
-    if (success) {
+    if (bufferLength == GlyphPage::size) {
+        WORD localGlyphBuffer[GlyphPage::size * 2];
+        DWORD result = GetGlyphIndices(dc, wcharFrom(buffer), bufferLength, localGlyphBuffer, GGI_MARK_NONEXISTING_GLYPHS);
+        bool success = result != GDI_ERROR && static_cast<unsigned>(result) == bufferLength;
+
+        if (success) {
+            for (unsigned i = 0; i < GlyphPage::size; i++) {
+                Glyph glyph = localGlyphBuffer[i];
+                if (glyph == 0xffff)
+                    setGlyphForIndex(i, 0);
+                else {
+                    setGlyphForIndex(i, glyph);
+                    haveGlyphs = true;
+                }
+            }
+        }
+    } else {
+        SCRIPT_CACHE sc = { };
+        SCRIPT_FONTPROPERTIES fp = { };
+        fp.cBytes = sizeof fp;
+        ScriptGetFontProperties(dc, &sc, &fp);
+        ScriptFreeCache(&sc);
+
         for (unsigned i = 0; i < GlyphPage::size; i++) {
-            Glyph glyph = localGlyphBuffer[i];
-            if (glyph == 0xffff)
-                setGlyphForIndex(i, 0);
-            else {
-                setGlyphForIndex(i, glyph);
-                haveGlyphs = true;
+            wchar_t glyphs[2] = { };
+            GCP_RESULTS gcpResults = { };
+            gcpResults.lStructSize = sizeof gcpResults;
+            gcpResults.nGlyphs = 2;
+            gcpResults.lpGlyphs = glyphs;
+            GetCharacterPlacement(dc, wcharFrom(buffer) + i * 2, 2, 0, &gcpResults, GCP_GLYPHSHAPE);
+            bool success = 1 == gcpResults.nGlyphs;
+            if (success) {
+                auto glyph = glyphs[0];
+                if (glyph == fp.wgBlank || glyph == fp.wgInvalid || glyph == fp.wgDefault)
+                    setGlyphForIndex(i, 0);
+                else {
+                    setGlyphForIndex(i, glyph);
+                    haveGlyphs = true;
+                }
             }
         }
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to