Title: [187583] trunk
Revision
187583
Author
mcatanz...@igalia.com
Date
2015-07-30 07:51:09 -0700 (Thu, 30 Jul 2015)

Log Message

Web Inspector: [Freetype] Allow inspector to retrieve a list of system fonts
https://bugs.webkit.org/show_bug.cgi?id=147018

Reviewed by Carlos Garcia Campos.

Source/WebCore:

No new tests; unskipped inspector/css/get-system-fonts.html

* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::patternToFamilies): Added.
(WebCore::FontCache::systemFontFamilies): Implemented.
(WebCore::strongAliasesForFamily): Split some code off to patternToFamilies.

LayoutTests:

* inspector/css/get-system-fonts-expected.txt: Expect some free fonts to be missing....
* inspector/css/get-system-fonts.html: Check for some free fonts.
* platform/gtk/TestExpectations: Unskip the test.
* platform/gtk/inspector/css/get-system-fonts-expected.txt: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (187582 => 187583)


--- trunk/LayoutTests/ChangeLog	2015-07-30 11:10:38 UTC (rev 187582)
+++ trunk/LayoutTests/ChangeLog	2015-07-30 14:51:09 UTC (rev 187583)
@@ -1,3 +1,15 @@
+2015-07-30  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        Web Inspector: [Freetype] Allow inspector to retrieve a list of system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147018
+
+        Reviewed by Carlos Garcia Campos.
+
+        * inspector/css/get-system-fonts-expected.txt: Expect some free fonts to be missing....
+        * inspector/css/get-system-fonts.html: Check for some free fonts.
+        * platform/gtk/TestExpectations: Unskip the test.
+        * platform/gtk/inspector/css/get-system-fonts-expected.txt: Added.
+
 2015-07-30  Nan Wang  <n_w...@apple.com>
 
         AX: VoiceOver unable to access content in malformed trees

Modified: trunk/LayoutTests/inspector/css/get-system-fonts-expected.txt (187582 => 187583)


--- trunk/LayoutTests/inspector/css/get-system-fonts-expected.txt	2015-07-30 11:10:38 UTC (rev 187582)
+++ trunk/LayoutTests/inspector/css/get-system-fonts-expected.txt	2015-07-30 14:51:09 UTC (rev 187583)
@@ -1,4 +1,7 @@
-Has at least 5 fonts: true
-PASS: Includes Arial
-PASS: Includes Times
+This test ensures that the inspector can enumerate system font families, and checks for the existance of common fonts.
 
+Includes Arial
+Includes Times
+Missing DejaVu Sans
+Missing Liberation Serif
+

Modified: trunk/LayoutTests/inspector/css/get-system-fonts.html (187582 => 187583)


--- trunk/LayoutTests/inspector/css/get-system-fonts.html	2015-07-30 11:10:38 UTC (rev 187582)
+++ trunk/LayoutTests/inspector/css/get-system-fonts.html	2015-07-30 14:51:09 UTC (rev 187583)
@@ -3,19 +3,22 @@
 <head>
 <script type="text/_javascript_" src=""
 <script>
-// Testing that we can get the fonts on the system and that the fonts contain some universal fonts (arial, times, etc).
 function test() {
     function hasFontFamily(fontFamilies, fontFamily) {
-        return (fontFamilies.includes(fontFamily) ? "PASS: Includes " : "FAIL: Missing ") + fontFamily;
+        return (fontFamilies.includes(fontFamily) ? "Includes " : "Missing ") + fontFamily;
     }
 
     function fontFamilyNamesCallback(error, fontFamilyNames) {
         InspectorTest.assert(!error, "Error in getting font family names.");
 
         if (!error) {
-            InspectorTest.log("Has at least 5 fonts: " + (fontFamilyNames.length >= 5));
+            InspectorTest.assert(fontFamilyNames.length >= 5, "Has at least 5 fonts");
+            // We can't count on any font existing on every platform, so we list enough fonts here
+            // such that at least one will exist. Update your port's test expectations as needed.
             InspectorTest.log(hasFontFamily(fontFamilyNames, "Arial"));
             InspectorTest.log(hasFontFamily(fontFamilyNames, "Times"));
+            InspectorTest.log(hasFontFamily(fontFamilyNames, "DejaVu Sans"));
+            InspectorTest.log(hasFontFamily(fontFamilyNames, "Liberation Serif"));
         }
 
         InspectorTest.completeTest();
@@ -24,5 +27,8 @@
 }
 </script>
 </head>
-<body _onload_="runTest()"></body>
+<body _onload_="runTest()">
+  <p>This test ensures that the inspector can enumerate system font families, and checks for the
+     existance of common fonts.</p>
+</body>
 </html>

Modified: trunk/LayoutTests/platform/gtk/TestExpectations (187582 => 187583)


--- trunk/LayoutTests/platform/gtk/TestExpectations	2015-07-30 11:10:38 UTC (rev 187582)
+++ trunk/LayoutTests/platform/gtk/TestExpectations	2015-07-30 14:51:09 UTC (rev 187583)
@@ -1319,7 +1319,6 @@
 
 webkit.org/b/139362 inspector/css/pseudo-element-matches.html [ Timeout ]
 webkit.org/b/139362 inspector/css/selector-specificity.html [ Timeout Pass ]
-webkit.org/b/147018 inspector/css/get-system-fonts.html [ Skip ]
 webkit.org/b/147229 inspector/css/modify-rule-selector.html [ Skip ] # Timeout
 
 webkit.org/b/139363 media/media-controls-timeline-updates.html [ Timeout ]

Added: trunk/LayoutTests/platform/gtk/inspector/css/get-system-fonts-expected.txt (0 => 187583)


--- trunk/LayoutTests/platform/gtk/inspector/css/get-system-fonts-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/platform/gtk/inspector/css/get-system-fonts-expected.txt	2015-07-30 14:51:09 UTC (rev 187583)
@@ -0,0 +1,7 @@
+This test ensures that the inspector can enumerate system font families, and checks for the existance of common fonts.
+
+Missing Arial
+Missing Times
+Includes DejaVu Sans
+Includes Liberation Serif
+

Modified: trunk/Source/WebCore/ChangeLog (187582 => 187583)


--- trunk/Source/WebCore/ChangeLog	2015-07-30 11:10:38 UTC (rev 187582)
+++ trunk/Source/WebCore/ChangeLog	2015-07-30 14:51:09 UTC (rev 187583)
@@ -1,3 +1,17 @@
+2015-07-30  Michael Catanzaro  <mcatanz...@igalia.com>
+
+        Web Inspector: [Freetype] Allow inspector to retrieve a list of system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=147018
+
+        Reviewed by Carlos Garcia Campos.
+
+        No new tests; unskipped inspector/css/get-system-fonts.html
+
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::patternToFamilies): Added.
+        (WebCore::FontCache::systemFontFamilies): Implemented.
+        (WebCore::strongAliasesForFamily): Split some code off to patternToFamilies.
+
 2015-07-30  Nan Wang  <n_w...@apple.com>
 
         AX: VoiceOver unable to access content in malformed trees

Modified: trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp (187582 => 187583)


--- trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2015-07-30 11:10:38 UTC (rev 187582)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2015-07-30 14:51:09 UTC (rev 187583)
@@ -98,10 +98,34 @@
     return fontForPlatformData(alternateFontData);
 }
 
+static Vector<String> patternToFamilies(FcPattern& pattern)
+{
+    char* patternChars = reinterpret_cast<char*>(FcPatternFormat(&pattern, reinterpret_cast<const FcChar8*>("%{family}")));
+    String patternString = String::fromUTF8(patternChars);
+    free(patternChars);
+
+    Vector<String> results;
+    patternString.split(',', results);
+    return results;
+}
+
 Vector<String> FontCache::systemFontFamilies()
 {
-    // FIXME: <https://webkit.org/b/147018> Web Inspector: [Freetype] Allow inspector to retrieve a list of system fonts
+    RefPtr<FcPattern> scalablesOnlyPattern = adoptRef(FcPatternCreate());
+    FcPatternAddBool(scalablesOnlyPattern.get(), FC_SCALABLE, FcTrue);
+
+    FcUniquePtr<FcObjectSet> familiesOnly(FcObjectSetBuild(FC_FAMILY, nullptr));
+    FcUniquePtr<FcFontSet> fontSet(FcFontList(nullptr, scalablesOnlyPattern.get(), familiesOnly.get()));
+
     Vector<String> fontFamilies;
+    for (int i = 0; i < fontSet->nfont; i++) {
+        FcPattern* pattern = fontSet->fonts[i];
+        FcChar8* family = nullptr;
+        FcPatternGetString(pattern, FC_FAMILY, 0, &family);
+        if (family)
+            fontFamilies.appendVector(patternToFamilies(*pattern));
+    }
+
     return fontFamilies;
 }
 
@@ -277,16 +301,7 @@
         }
     }
 
-    // Take the resulting pattern and remove everything but the families.
-    minimal = adoptRef(FcPatternFilter(pattern.get(), familiesOnly.get()));
-    // Convert the pattern to a string, and cut out the non-family junk that gets added to the end.
-    char* patternChars = reinterpret_cast<char*>(FcPatternFormat(pattern.get(), reinterpret_cast<const FcChar8*>("%{family}")));
-    String patternString = String::fromUTF8(patternChars);
-    free(patternChars);
-
-    Vector<String> results;
-    patternString.split(',', results);
-    return results;
+    return patternToFamilies(*pattern);
 }
 
 static bool areStronglyAliased(const String& familyA, const String& familyB)
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to