[GTK] Support the "system" CSS font family
authoraperez@igalia.com <aperez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Oct 2017 19:21:19 +0000 (19:21 +0000)
committeraperez@igalia.com <aperez@igalia.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 3 Oct 2017 19:21:19 +0000 (19:21 +0000)
https://bugs.webkit.org/show_bug.cgi?id=177755

Reviewed by Carlos Garcia Campos.

Obtain the system UI font from the GtkSettings::gtk-font-name property

Source/WebCore:

Test: platform/gtk/fonts/systemFont.html

* platform/graphics/freetype/FontCacheFreeType.cpp:
(WebCore::getFamilyNameStringFromFamily): Use defaultGtkSystemFont()
to handle -webkit-system-font and -webkit-system-ui.
(WebCore::isCommonlyUsedGenericFamily): Handle -webkit-system-font and
-webkit-system-ui as generic family names.
* platform/graphics/gtk/GtkUtilities.cpp:
(WebCore::defaultGtkSystemFont): Added.
* platform/graphics/gtk/GtkUtilities.h: Add prototype for defaultGtkSystemFont().

LayoutTests:

* platform/gtk/fonts/systemFont-expected.html: Added.
* platform/gtk/fonts/systemFont.html: Added.

git-svn-id: http://svn.webkit.org/repository/webkit/trunk@222800 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/platform/gtk/fonts/systemFont-expected.html [new file with mode: 0644]
LayoutTests/platform/gtk/fonts/systemFont.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp
Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp
Source/WebCore/platform/gtk/GtkUtilities.cpp
Source/WebCore/platform/gtk/GtkUtilities.h

index 43cbae5..6f667e1 100644 (file)
@@ -1,3 +1,15 @@
+2017-10-03  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK] Support the "system" CSS font family
+        https://bugs.webkit.org/show_bug.cgi?id=177755
+
+        Reviewed by Carlos Garcia Campos.
+
+        Obtain the system UI font from the GtkSettings::gtk-font-name property
+
+        * platform/gtk/fonts/systemFont-expected.html: Added.
+        * platform/gtk/fonts/systemFont.html: Added.
+
 2017-10-03  Daniel Bates  <dabates@apple.com>
 
         [XHR] Only exempt Dashboard widgets from XHR header restrictions
diff --git a/LayoutTests/platform/gtk/fonts/systemFont-expected.html b/LayoutTests/platform/gtk/fonts/systemFont-expected.html
new file mode 100644 (file)
index 0000000..833da45
--- /dev/null
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html>
+       <head>
+        <meta charset="utf-8" />
+               <title>SystemFont-Expected</title>
+               <style type="text/css">
+               p { font-family: 'Liberation Sans' }
+               </style>
+       </head>
+       <body>
+               <p>System font</p>
+               <p><i>Italic system font</i></p>
+               <p><b>Bold system font</b></p>
+               <p><i><b>Bold italic system font</b></i></p>
+
+               <p>System font</p>
+               <p><i>Italic system font</i></p>
+               <p><b>Bold system font</b></p>
+               <p><i><b>Bold italic system font</b></i></p>
+
+               <p style="font-size: 24px">System font</p>
+               <p style="font-size: 12pt"><i>Italic system font</i></p>
+               <p style="font-size: small"><b>Bold system font</b></p>
+               <p style="font-size: 2em"><i><b>Bold italic system font</b></i></p>
+       </body>
+</html>
diff --git a/LayoutTests/platform/gtk/fonts/systemFont.html b/LayoutTests/platform/gtk/fonts/systemFont.html
new file mode 100644 (file)
index 0000000..80328e4
--- /dev/null
@@ -0,0 +1,27 @@
+<!DOCTYPE html>
+<html>
+       <head>
+        <meta charset="utf-8" />
+               <title>SystemFont</title>
+               <style type="text/css">
+               p.system-font { font-family: -webkit-system-font }
+               p.system-ui { font-family: -webkit-system-ui }
+               </style>
+       </head>
+       <body>
+               <p class="system-font">System font</p>
+               <p class="system-font"><i>Italic system font</i></p>
+               <p class="system-font"><b>Bold system font</b></p>
+               <p class="system-font"><i><b>Bold italic system font</b></i></p>
+
+               <p class="system-ui">System font</p>
+               <p class="system-ui"><i>Italic system font</i></p>
+               <p class="system-ui"><b>Bold system font</b></p>
+               <p class="system-ui"><i><b>Bold italic system font</b></i></p>
+
+               <p class="system-font" style="font-size: 24px">System font</p>
+               <p class="system-font" style="font-size: 12pt"><i>Italic system font</i></p>
+               <p class="system-font" style="font-size: small"><b>Bold system font</b></p>
+               <p class="system-font" style="font-size: 2em"><i><b>Bold italic system font</b></i></p>
+       </body>
+</html>
index f1c7995..1d4d1a4 100644 (file)
@@ -1,3 +1,23 @@
+2017-10-03  Adrian Perez de Castro  <aperez@igalia.com>
+
+        [GTK] Support the "system" CSS font family
+        https://bugs.webkit.org/show_bug.cgi?id=177755
+
+        Reviewed by Carlos Garcia Campos.
+
+        Obtain the system UI font from the GtkSettings::gtk-font-name property
+
+        Test: platform/gtk/fonts/systemFont.html
+
+        * platform/graphics/freetype/FontCacheFreeType.cpp:
+        (WebCore::getFamilyNameStringFromFamily): Use defaultGtkSystemFont()
+        to handle -webkit-system-font and -webkit-system-ui.
+        (WebCore::isCommonlyUsedGenericFamily): Handle -webkit-system-font and
+        -webkit-system-ui as generic family names.
+        * platform/graphics/gtk/GtkUtilities.cpp:
+        (WebCore::defaultGtkSystemFont): Added.
+        * platform/graphics/gtk/GtkUtilities.h: Add prototype for defaultGtkSystemFont().
+
 2017-10-03  Daniel Bates  <dabates@apple.com>
 
         [XHR] Only exempt Dashboard widgets from XHR header restrictions
index 158acd8..ae16d24 100644 (file)
 #include <wtf/Assertions.h>
 #include <wtf/text/CString.h>
 
+#if PLATFORM(GTK)
+#include "GtkUtilities.h"
+#endif
+
 namespace WebCore {
 
 void FontCache::platformInit()
@@ -157,6 +161,12 @@ static String getFamilyNameStringFromFamily(const AtomicString& family)
         return "cursive";
     if (family == fantasyFamily)
         return "fantasy";
+
+#if PLATFORM(GTK)
+    if (family == systemUiFamily || family == "-webkit-system-font")
+        return defaultGtkSystemFont();
+#endif
+
     return "";
 }
 
@@ -316,6 +326,10 @@ static inline bool isCommonlyUsedGenericFamily(const String& familyNameString)
         || equalLettersIgnoringASCIICase(familyNameString, "serif")
         || equalLettersIgnoringASCIICase(familyNameString, "monospace")
         || equalLettersIgnoringASCIICase(familyNameString, "fantasy")
+#if PLATFORM(GTK)
+        || equalLettersIgnoringASCIICase(familyNameString, "-webkit-system-font")
+        || equalLettersIgnoringASCIICase(familyNameString, "-webkit-system-ui")
+#endif
         || equalLettersIgnoringASCIICase(familyNameString, "cursive");
 }
 
index 683d8f5..ef5089e 100644 (file)
@@ -33,6 +33,7 @@
 #include <gtk/gtk.h>
 #include <mutex>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/glib/GUniquePtr.h>
 
 namespace WebCore {
 
index 4c48bd1..def8cd4 100644 (file)
@@ -64,6 +64,17 @@ WallTime wallTimeForEvent(const GdkEvent* event)
     return MonotonicTime::fromRawSeconds(gdk_event_get_time(event) / 1000.).approximateWallTime();
 }
 
+String defaultGtkSystemFont()
+{
+    GUniqueOutPtr<char> fontString;
+    g_object_get(gtk_settings_get_default(), "gtk-font-name", &fontString.outPtr(), nullptr);
+    // We need to remove the size from the value of the property,
+    // which is separated from the font family using a space.
+    if (auto* spaceChar = strrchr(fontString.get(), ' '))
+        *spaceChar = '\0';
+    return String::fromUTF8(fontString.get());
+}
+
 #if ENABLE(DEVELOPER_MODE)
 static CString topLevelPath()
 {
index 511e601..b1c8d9a 100644 (file)
@@ -22,6 +22,7 @@
 #include <wtf/MonotonicTime.h>
 #include <wtf/WallTime.h>
 #include <wtf/text/CString.h>
+#include <wtf/text/WTFString.h>
 
 namespace WebCore {
 
@@ -36,6 +37,8 @@ WallTime wallTimeForEvent(const GdkEventType* event) { return MonotonicTime::fro
 template<>
 WallTime wallTimeForEvent(const GdkEvent*);
 
+String defaultGtkSystemFont();
+
 #if ENABLE(DEVELOPER_MODE)
 CString webkitBuildDirectory();
 #endif