Title: [222800] trunk
Revision
222800
Author
ape...@igalia.com
Date
2017-10-03 12:21:19 -0700 (Tue, 03 Oct 2017)

Log Message

[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

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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (222799 => 222800)


--- trunk/LayoutTests/ChangeLog	2017-10-03 19:17:23 UTC (rev 222799)
+++ trunk/LayoutTests/ChangeLog	2017-10-03 19:21:19 UTC (rev 222800)
@@ -1,3 +1,15 @@
+2017-10-03  Adrian Perez de Castro  <ape...@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  <daba...@apple.com>
 
         [XHR] Only exempt Dashboard widgets from XHR header restrictions

Added: trunk/LayoutTests/platform/gtk/fonts/systemFont-expected.html (0 => 222800)


--- trunk/LayoutTests/platform/gtk/fonts/systemFont-expected.html	                        (rev 0)
+++ trunk/LayoutTests/platform/gtk/fonts/systemFont-expected.html	2017-10-03 19:21:19 UTC (rev 222800)
@@ -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>

Added: trunk/LayoutTests/platform/gtk/fonts/systemFont.html (0 => 222800)


--- trunk/LayoutTests/platform/gtk/fonts/systemFont.html	                        (rev 0)
+++ trunk/LayoutTests/platform/gtk/fonts/systemFont.html	2017-10-03 19:21:19 UTC (rev 222800)
@@ -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>

Modified: trunk/Source/WebCore/ChangeLog (222799 => 222800)


--- trunk/Source/WebCore/ChangeLog	2017-10-03 19:17:23 UTC (rev 222799)
+++ trunk/Source/WebCore/ChangeLog	2017-10-03 19:21:19 UTC (rev 222800)
@@ -1,3 +1,23 @@
+2017-10-03  Adrian Perez de Castro  <ape...@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  <daba...@apple.com>
 
         [XHR] Only exempt Dashboard widgets from XHR header restrictions

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


--- trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2017-10-03 19:17:23 UTC (rev 222799)
+++ trunk/Source/WebCore/platform/graphics/freetype/FontCacheFreeType.cpp	2017-10-03 19:21:19 UTC (rev 222800)
@@ -33,6 +33,10 @@
 #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 @@
         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 @@
         || 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");
 }
 

Modified: trunk/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp (222799 => 222800)


--- trunk/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp	2017-10-03 19:17:23 UTC (rev 222799)
+++ trunk/Source/WebCore/platform/graphics/gtk/GdkCairoUtilities.cpp	2017-10-03 19:21:19 UTC (rev 222800)
@@ -33,6 +33,7 @@
 #include <gtk/gtk.h>
 #include <mutex>
 #include <wtf/NeverDestroyed.h>
+#include <wtf/glib/GUniquePtr.h>
 
 namespace WebCore {
 

Modified: trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp (222799 => 222800)


--- trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp	2017-10-03 19:17:23 UTC (rev 222799)
+++ trunk/Source/WebCore/platform/gtk/GtkUtilities.cpp	2017-10-03 19:21:19 UTC (rev 222800)
@@ -64,6 +64,17 @@
     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()
 {

Modified: trunk/Source/WebCore/platform/gtk/GtkUtilities.h (222799 => 222800)


--- trunk/Source/WebCore/platform/gtk/GtkUtilities.h	2017-10-03 19:17:23 UTC (rev 222799)
+++ trunk/Source/WebCore/platform/gtk/GtkUtilities.h	2017-10-03 19:21:19 UTC (rev 222800)
@@ -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 @@
 template<>
 WallTime wallTimeForEvent(const GdkEvent*);
 
+String defaultGtkSystemFont();
+
 #if ENABLE(DEVELOPER_MODE)
 CString webkitBuildDirectory();
 #endif
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to