[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

mrobinson at webkit.org mrobinson at webkit.org
Wed Dec 22 15:03:26 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit ae9f8941a19c46832c19e40de260ca07a5adb6a9
Author: mrobinson at webkit.org <mrobinson at webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Wed Oct 27 19:31:47 2010 +0000

    2010-10-27  Martin Robinson  <mrobinson at igalia.com>
    
            Reviewed by Gustavo Noronha Silva.
    
            [Cairo] Font fallback determination is very ineffecient
            https://bugs.webkit.org/show_bug.cgi?id=42052
    
            Added a test which verifies the correct result rendering with a custom
            font that is missing many glyphs.
    
            * platform/gtk/fonts/custom-font-missing-glyphs-expected.checksum: Added.
            * platform/gtk/fonts/custom-font-missing-glyphs-expected.png: Added.
            * platform/gtk/fonts/custom-font-missing-glyphs-expected.txt: Added.
            * platform/gtk/fonts/custom-font-missing-glyphs.html: Added.
            * platform/gtk/fonts/resources/mostly-empty-font.ttf: Added. A font that I
            created in fotnforge which is composed of empty glyphs, except for 'A' which
            has a lonely polyhedron for a glyph.
    2010-10-27  Martin Robinson  <mrobinson at igalia.com>
    
            Reviewed by Gustavo Noronha Silva.
    
            [Cairo] Font fallback determination is very ineffecient
            https://bugs.webkit.org/show_bug.cgi?id=42052
    
            When choosing a fallback font in FontCache::getFontDataForCharacters, use FontConfig's
            mechanism for searching the fallback list directly, instead of scanning the list manually.
            If the font is a custom font or any other font with no FontConfig pattern associated with
            it, as FontConfig for a font that can supply the missing glyphs.
    
            Test: platform/gtk/fonts/custom-font-missing-glyphs.html
    
            * platform/graphics/cairo/FontCacheFreeType.cpp:
            (WebCore::createFontConfigPatternForCharacters): Added this helper which turns
            a collection of unicode characters into a FontConfig pattern.
            (WebCore::findBestFontGivenFallbacks): Using a FontConfig pattern created with th
            above helper and a FcFontSet of fallback fonts, this helper will find a font in
            the set which fulfills the requirments.
            (WebCore::FontCache::getFontDataForCharacters): Given an existing font with missing
            glyphs, either find an appropriate fallback font from the list of FontConfig fallbacks
            or ask FontConfig directly for an appropriate font.
            * platform/graphics/cairo/FontPlatformDataFreeType.h: Made a member mutable, as it is
            initialized lazily.
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@70688 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/LayoutTests/ChangeLog b/LayoutTests/ChangeLog
index f78903d..d061fa8 100644
--- a/LayoutTests/ChangeLog
+++ b/LayoutTests/ChangeLog
@@ -1,3 +1,21 @@
+2010-10-27  Martin Robinson  <mrobinson at igalia.com>
+
+        Reviewed by Gustavo Noronha Silva.
+
+        [Cairo] Font fallback determination is very ineffecient
+        https://bugs.webkit.org/show_bug.cgi?id=42052
+
+        Added a test which verifies the correct result rendering with a custom
+        font that is missing many glyphs.
+
+        * platform/gtk/fonts/custom-font-missing-glyphs-expected.checksum: Added.
+        * platform/gtk/fonts/custom-font-missing-glyphs-expected.png: Added.
+        * platform/gtk/fonts/custom-font-missing-glyphs-expected.txt: Added.
+        * platform/gtk/fonts/custom-font-missing-glyphs.html: Added.
+        * platform/gtk/fonts/resources/mostly-empty-font.ttf: Added. A font that I
+        created in fotnforge which is composed of empty glyphs, except for 'A' which
+        has a lonely polyhedron for a glyph.
+
 2010-10-27  Renata Hodovan  <reni at inf.u-szeged.hu>
 
         Reviewed by Dirk Schulze.
diff --git a/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.checksum b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.checksum
new file mode 100644
index 0000000..69916ca
--- /dev/null
+++ b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.checksum
@@ -0,0 +1 @@
+5005df094573c31f185e0f51a389df06
\ No newline at end of file
diff --git a/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.png b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.png
new file mode 100644
index 0000000..813a2ba
Binary files /dev/null and b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.png differ
diff --git a/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.txt b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.txt
new file mode 100644
index 0000000..3221039
--- /dev/null
+++ b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs-expected.txt
@@ -0,0 +1,8 @@
+layer at (0,0) size 800x600
+  RenderView at (0,0) size 800x600
+layer at (0,0) size 800x600
+  RenderBlock {HTML} at (0,0) size 800x600
+    RenderBody {BODY} at (8,8) size 784x584
+      RenderBlock {DIV} at (0,0) size 784x12
+        RenderText {#text} at (0,0) size 357x11
+          text run at (0,0) width 357: "A B C D E F G H I J K L M N O P Q R S T U V W X Y Z"
diff --git a/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs.html b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs.html
new file mode 100644
index 0000000..d7432f1
--- /dev/null
+++ b/LayoutTests/platform/gtk/fonts/custom-font-missing-glyphs.html
@@ -0,0 +1,12 @@
+<html> 
+<head> 
+<style> 
+    @font-face { 
+        src: url(resources/mostly-empty-font.ttf) format(truetype);
+        font-family: MostlyEmptyFont;
+    }
+</style> 
+<body> 
+<div style="font-family: MostlyEmptyFont;">A B C D E F G H I J K L M N O P Q R S T U V W X Y Z</div> 
+</body> 
+</html> 
diff --git a/LayoutTests/platform/gtk/fonts/resources/mostly-empty-font.ttf b/LayoutTests/platform/gtk/fonts/resources/mostly-empty-font.ttf
new file mode 100644
index 0000000..403e12c
Binary files /dev/null and b/LayoutTests/platform/gtk/fonts/resources/mostly-empty-font.ttf differ
diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index b6d4018..683fbae 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,29 @@
+2010-10-27  Martin Robinson  <mrobinson at igalia.com>
+
+        Reviewed by Gustavo Noronha Silva.
+
+        [Cairo] Font fallback determination is very ineffecient
+        https://bugs.webkit.org/show_bug.cgi?id=42052
+
+        When choosing a fallback font in FontCache::getFontDataForCharacters, use FontConfig's
+        mechanism for searching the fallback list directly, instead of scanning the list manually.
+        If the font is a custom font or any other font with no FontConfig pattern associated with
+        it, as FontConfig for a font that can supply the missing glyphs.
+
+        Test: platform/gtk/fonts/custom-font-missing-glyphs.html
+
+        * platform/graphics/cairo/FontCacheFreeType.cpp:
+        (WebCore::createFontConfigPatternForCharacters): Added this helper which turns
+        a collection of unicode characters into a FontConfig pattern.
+        (WebCore::findBestFontGivenFallbacks): Using a FontConfig pattern created with th
+        above helper and a FcFontSet of fallback fonts, this helper will find a font in
+        the set which fulfills the requirments.
+        (WebCore::FontCache::getFontDataForCharacters): Given an existing font with missing
+        glyphs, either find an appropriate fallback font from the list of FontConfig fallbacks
+        or ask FontConfig directly for an appropriate font.
+        * platform/graphics/cairo/FontPlatformDataFreeType.h: Made a member mutable, as it is
+        initialized lazily.
+
 2010-10-27  Alexander Pavlov  <apavlov at chromium.org>
 
         Reviewed by Pavel Feldman.
diff --git a/WebCore/platform/graphics/cairo/FontCacheFreeType.cpp b/WebCore/platform/graphics/cairo/FontCacheFreeType.cpp
index 5dca010..cd9ee46 100644
--- a/WebCore/platform/graphics/cairo/FontCacheFreeType.cpp
+++ b/WebCore/platform/graphics/cairo/FontCacheFreeType.cpp
@@ -41,33 +41,63 @@ void FontCache::platformInit()
         ASSERT_NOT_REACHED();
 }
 
-const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
+FcPattern* createFontConfigPatternForCharacters(const UChar* characters, int length)
 {
-    FcResult fresult;
-    FontPlatformData* prim = const_cast<FontPlatformData*>(&font.primaryFont()->platformData());
+    FcPattern* pattern = FcPatternCreate();
+
+    FcCharSet* fontConfigCharSet = FcCharSetCreate();
+    for (int i = 0; i < length; ++i) {
+        if (U16_IS_SURROGATE(characters[i]) && U16_IS_SURROGATE_LEAD(characters[i])
+                && i != length - 1 && U16_IS_TRAIL(characters[i + 1])) {
+            FcCharSetAddChar(fontConfigCharSet, U16_GET_SUPPLEMENTARY(characters[i], characters[i+1]));
+            i++;
+        } else
+            FcCharSetAddChar(fontConfigCharSet, characters[i]);
+    }
+    FcPatternAddCharSet(pattern, FC_CHARSET, fontConfigCharSet);
+    FcCharSetDestroy(fontConfigCharSet);
 
-    // FIXME: This should not happen, apparently. We are null-checking
-    // for now just to avoid crashing.
-    if (!prim || !prim->m_pattern)
+    FcPatternAddBool(pattern, FC_SCALABLE, FcTrue);
+    FcConfigSubstitute(0, pattern, FcMatchPattern);
+    FcDefaultSubstitute(pattern);
+    return pattern;
+}
+
+FcPattern* findBestFontGivenFallbacks(const FontPlatformData& fontData, FcPattern* pattern)
+{
+    if (!fontData.m_pattern)
         return 0;
 
-    if (!prim->m_fallbacks)
-        prim->m_fallbacks = FcFontSort(0, prim->m_pattern.get(), FcTrue, 0, &fresult);
+    if (!fontData.m_fallbacks) {
+        FcResult fontConfigResult;
+        fontData.m_fallbacks = FcFontSort(0, fontData.m_pattern.get(), FcTrue, 0, &fontConfigResult);
+    }
 
-    FcFontSet* fs = prim->m_fallbacks;
+    if (!fontData.m_fallbacks)
+        return 0;
 
-    for (int i = 0; i < fs->nfont; i++) {
-        PlatformRefPtr<FcPattern> fin = adoptPlatformRef(FcFontRenderPrepare(0, prim->m_pattern.get(), fs->fonts[i]));
-        cairo_font_face_t* fontFace = cairo_ft_font_face_create_for_pattern(fin.get());
-        FontPlatformData alternateFont(fontFace, font.fontDescription().computedPixelSize(), false, false);
-        cairo_font_face_destroy(fontFace);
-        alternateFont.m_pattern = fin;
-        SimpleFontData* sfd = getCachedFontData(&alternateFont);
-        if (sfd->containsCharacters(characters, length))
-            return sfd;
+    FcFontSet* sets[] = { fontData.m_fallbacks };
+    FcResult fontConfigResult;
+    return FcFontSetMatch(0, sets, 1, pattern, &fontConfigResult);
+}
+
+const SimpleFontData* FontCache::getFontDataForCharacters(const Font& font, const UChar* characters, int length)
+{
+    PlatformRefPtr<FcPattern> pattern = adoptPlatformRef(createFontConfigPatternForCharacters(characters, length));
+    const FontPlatformData& fontData = font.primaryFont()->platformData();
+
+    PlatformRefPtr<FcPattern> fallbackPattern = adoptPlatformRef(findBestFontGivenFallbacks(fontData, pattern.get()));
+    if (fallbackPattern) {
+        FontPlatformData alternateFontData(fallbackPattern.get(), font.fontDescription());
+        return getCachedFontData(&alternateFontData);
     }
 
-    return 0;
+    FcResult fontConfigResult;
+    PlatformRefPtr<FcPattern> resultPattern = adoptPlatformRef(FcFontMatch(0, pattern.get(), &fontConfigResult));
+    if (!resultPattern)
+        return 0;
+    FontPlatformData alternateFontData(resultPattern.get(), font.fontDescription());
+    return getCachedFontData(&alternateFontData);
 }
 
 SimpleFontData* FontCache::getSimilarFontPlatformData(const Font& font)
diff --git a/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h b/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h
index 7d3ff99..d47d556 100644
--- a/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h
+++ b/WebCore/platform/graphics/cairo/FontPlatformDataFreeType.h
@@ -86,7 +86,7 @@ public:
 #endif
 
     PlatformRefPtr<FcPattern> m_pattern;
-    FcFontSet* m_fallbacks;
+    mutable FcFontSet* m_fallbacks; // Initialized lazily.
     float m_size;
     bool m_syntheticBold;
     bool m_syntheticOblique;

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list