Title: [229264] releases/WebKitGTK/webkit-2.20/Source/WebCore
Revision
229264
Author
[email protected]
Date
2018-03-05 05:16:04 -0800 (Mon, 05 Mar 2018)

Log Message

Merge r229128 - [FreeType] Color emojis in WebKitGTK+ for great justice
https://bugs.webkit.org/show_bug.cgi?id=183155

Reviewed by Michael Catanzaro.

Emojis are actually rendered if there's an emoji font installed in the system, but the size is so tiny that we
don't see them. This is because for some reason the matrix we are getting from fontconfig contains a scale,
which we don't expect. We only get the fontconfig matrix to apply rotations in case of oblique fonts, and then we
always apply the scale for the computed pixel font size. Ignoring the fontconfig matrix scale fixes the issue.

* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::fontWeightToFontconfigWeight): Moved here since it's now used by configurePatternForFontDescription().
(WebCore::configurePatternForFontDescription): Helper function to apply the same options for fallback pattern.
(WebCore::createFontConfigPatternForCharacters): Use configurePatternForFontDescription().
(WebCore::findBestFontGivenFallbacks): Adopt the returned reference.
(WebCore::FontCache::systemFallbackForCharacters): Clean it up.
(WebCore::FontCache::createFontPlatformData): Use configurePatternForFontDescription().
* platform/graphics/freetype/FontPlatformDataFreeType.cpp:
(WebCore::FontPlatformData::buildScaledFont): Ignore the scale returned by fontconfig matrix.

Modified Paths

Diff

Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog (229263 => 229264)


--- releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog	2018-03-05 13:15:55 UTC (rev 229263)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/ChangeLog	2018-03-05 13:16:04 UTC (rev 229264)
@@ -1,3 +1,25 @@
+2018-03-01  Carlos Garcia Campos  <[email protected]>
+
+        [FreeType] Color emojis in WebKitGTK+ for great justice
+        https://bugs.webkit.org/show_bug.cgi?id=183155
+
+        Reviewed by Michael Catanzaro.
+
+        Emojis are actually rendered if there's an emoji font installed in the system, but the size is so tiny that we
+        don't see them. This is because for some reason the matrix we are getting from fontconfig contains a scale,
+        which we don't expect. We only get the fontconfig matrix to apply rotations in case of oblique fonts, and then we
+        always apply the scale for the computed pixel font size. Ignoring the fontconfig matrix scale fixes the issue.
+
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::fontWeightToFontconfigWeight): Moved here since it's now used by configurePatternForFontDescription().
+        (WebCore::configurePatternForFontDescription): Helper function to apply the same options for fallback pattern.
+        (WebCore::createFontConfigPatternForCharacters): Use configurePatternForFontDescription().
+        (WebCore::findBestFontGivenFallbacks): Adopt the returned reference.
+        (WebCore::FontCache::systemFallbackForCharacters): Clean it up.
+        (WebCore::FontCache::createFontPlatformData): Use configurePatternForFontDescription().
+        * platform/graphics/freetype/FontPlatformDataFreeType.cpp:
+        (WebCore::FontPlatformData::buildScaledFont): Ignore the scale returned by fontconfig matrix.
+
 2018-02-28  Chris Dumez  <[email protected]>
 
         html/browsers/browsing-the-web/navigating-across-documents/006.html fails with async policy delegates

Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp (229263 => 229264)


--- releases/WebKitGTK/webkit-2.20/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2018-03-05 13:15:55 UTC (rev 229263)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2018-03-05 13:16:04 UTC (rev 229264)
@@ -46,8 +46,40 @@
         ASSERT_NOT_REACHED();
 }
 
-static RefPtr<FcPattern> createFontConfigPatternForCharacters(const UChar* characters, int bufferLength)
+static int fontWeightToFontconfigWeight(FontSelectionValue weight)
 {
+    if (weight < FontSelectionValue(150))
+        return FC_WEIGHT_THIN;
+    if (weight < FontSelectionValue(250))
+        return FC_WEIGHT_ULTRALIGHT;
+    if (weight < FontSelectionValue(350))
+        return FC_WEIGHT_LIGHT;
+    if (weight < FontSelectionValue(450))
+        return FC_WEIGHT_REGULAR;
+    if (weight < FontSelectionValue(550))
+        return FC_WEIGHT_MEDIUM;
+    if (weight < FontSelectionValue(650))
+        return FC_WEIGHT_SEMIBOLD;
+    if (weight < FontSelectionValue(750))
+        return FC_WEIGHT_BOLD;
+    if (weight < FontSelectionValue(850))
+        return FC_WEIGHT_EXTRABOLD;
+    return FC_WEIGHT_ULTRABLACK;
+}
+
+static bool configurePatternForFontDescription(FcPattern* pattern, const FontDescription& fontDescription)
+{
+    if (!FcPatternAddInteger(pattern, FC_SLANT, fontDescription.italic() ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
+        return false;
+    if (!FcPatternAddInteger(pattern, FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
+        return false;
+    if (!FcPatternAddDouble(pattern, FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
+        return false;
+    return true;
+}
+
+static RefPtr<FcPattern> createFontConfigPatternForCharacters(const FontDescription& fontDescription, const UChar* characters, int bufferLength)
+{
     RefPtr<FcPattern> pattern = adoptRef(FcPatternCreate());
     FcUniquePtr<FcCharSet> fontConfigCharSet(FcCharSetCreate());
 
@@ -61,6 +93,10 @@
     FcPatternAddCharSet(pattern.get(), FC_CHARSET, fontConfigCharSet.get());
 
     FcPatternAddBool(pattern.get(), FC_SCALABLE, FcTrue);
+
+    if (!configurePatternForFontDescription(pattern.get(), fontDescription))
+        return nullptr;
+
     FcConfigSubstitute(nullptr, pattern.get(), FcMatchPattern);
     cairo_ft_font_options_substitute(getDefaultCairoFontOptions(), pattern.get());
     FcDefaultSubstitute(pattern.get());
@@ -74,26 +110,28 @@
         return nullptr;
 
     FcResult fontConfigResult;
-    return FcFontSetMatch(nullptr, &fallbacks, 1, pattern, &fontConfigResult);
+    return adoptRef(FcFontSetMatch(nullptr, &fallbacks, 1, pattern, &fontConfigResult));
 }
 
 RefPtr<Font> FontCache::systemFallbackForCharacters(const FontDescription& description, const Font* originalFontData, bool, const UChar* characters, unsigned length)
 {
-    RefPtr<FcPattern> pattern = createFontConfigPatternForCharacters(characters, length);
-    const FontPlatformData& fontData = originalFontData->platformData();
+    RefPtr<FcPattern> pattern = createFontConfigPatternForCharacters(description, characters, length);
+    if (!pattern)
+        return nullptr;
 
-    RefPtr<FcPattern> fallbackPattern = findBestFontGivenFallbacks(fontData, pattern.get());
-    if (fallbackPattern) {
+
+    if (RefPtr<FcPattern> fallbackPattern = findBestFontGivenFallbacks(originalFontData->platformData(), pattern.get())) {
         FontPlatformData alternateFontData(fallbackPattern.get(), description);
         return fontForPlatformData(alternateFontData);
     }
 
     FcResult fontConfigResult;
-    RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(nullptr, pattern.get(), &fontConfigResult));
-    if (!resultPattern)
-        return nullptr;
-    FontPlatformData alternateFontData(resultPattern.get(), description);
-    return fontForPlatformData(alternateFontData);
+    if (RefPtr<FcPattern> resultPattern = adoptRef(FcFontMatch(nullptr, pattern.get(), &fontConfigResult))) {
+        FontPlatformData alternateFontData(resultPattern.get(), description);
+        return fontForPlatformData(alternateFontData);
+    }
+
+    return nullptr;
 }
 
 static Vector<String> patternToFamilies(FcPattern& pattern)
@@ -170,27 +208,6 @@
     return "";
 }
 
-static int fontWeightToFontconfigWeight(FontSelectionValue weight)
-{
-    if (weight < FontSelectionValue(150))
-        return FC_WEIGHT_THIN;
-    if (weight < FontSelectionValue(250))
-        return FC_WEIGHT_ULTRALIGHT;
-    if (weight < FontSelectionValue(350))
-        return FC_WEIGHT_LIGHT;
-    if (weight < FontSelectionValue(450))
-        return FC_WEIGHT_REGULAR;
-    if (weight < FontSelectionValue(550))
-        return FC_WEIGHT_MEDIUM;
-    if (weight < FontSelectionValue(650))
-        return FC_WEIGHT_SEMIBOLD;
-    if (weight < FontSelectionValue(750))
-        return FC_WEIGHT_BOLD;
-    if (weight < FontSelectionValue(850))
-        return FC_WEIGHT_EXTRABOLD;
-    return FC_WEIGHT_ULTRABLACK;
-}
-
 // This is based on Chromium BSD code from Skia (src/ports/SkFontMgr_fontconfig.cpp). It is a
 // hack for lack of API in Fontconfig: https://bugs.freedesktop.org/show_bug.cgi?id=19375
 // FIXME: This is horrible. It should be deleted once Fontconfig can do this itself.
@@ -345,13 +362,8 @@
     if (!FcPatternAddString(pattern.get(), FC_FAMILY, reinterpret_cast<const FcChar8*>(familyNameString.utf8().data())))
         return nullptr;
 
-    bool italic = fontDescription.italic();
-    if (!FcPatternAddInteger(pattern.get(), FC_SLANT, italic ? FC_SLANT_ITALIC : FC_SLANT_ROMAN))
+    if (!configurePatternForFontDescription(pattern.get(), fontDescription))
         return nullptr;
-    if (!FcPatternAddInteger(pattern.get(), FC_WEIGHT, fontWeightToFontconfigWeight(fontDescription.weight())))
-        return nullptr;
-    if (!FcPatternAddDouble(pattern.get(), FC_PIXEL_SIZE, fontDescription.computedPixelSize()))
-        return nullptr;
 
     // The strategy is originally from Skia (src/ports/SkFontHost_fontconfig.cpp):
     //

Modified: releases/WebKitGTK/webkit-2.20/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp (229263 => 229264)


--- releases/WebKitGTK/webkit-2.20/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp	2018-03-05 13:15:55 UTC (rev 229263)
+++ releases/WebKitGTK/webkit-2.20/Source/WebCore/platform/graphics/freetype/FontPlatformDataFreeType.cpp	2018-03-05 13:16:04 UTC (rev 229264)
@@ -306,11 +306,11 @@
     // These matrices may be stacked in the pattern, so it's our job to get them all and multiply them.
     for (int i = 0; FcPatternGetMatrix(optionsPattern, FC_MATRIX, i, &tempFontConfigMatrix) == FcResultMatch; i++)
         FcMatrixMultiply(&fontConfigMatrix, &fontConfigMatrix, tempFontConfigMatrix);
-    cairo_matrix_init(&fontMatrix, fontConfigMatrix.xx, -fontConfigMatrix.yx,
-        -fontConfigMatrix.xy, fontConfigMatrix.yy, 0, 0);
 
+    cairo_matrix_init(&fontMatrix, 1, -fontConfigMatrix.yx, -fontConfigMatrix.xy, 1, 0, 0);
+
     // The matrix from FontConfig does not include the scale. Scaling a font with width zero size leads
-    // to a failed cairo_scaled_font_t instantiations. Instead we scale we scale the font to a very tiny
+    // to a failed cairo_scaled_font_t instantiations. Instead we scale the font to a very tiny
     // size and just abort rendering later on.
     float realSize = m_size ? m_size : 1;
     cairo_matrix_scale(&fontMatrix, realSize, realSize);
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to