Title: [167724] trunk/Source/WebCore
Revision
167724
Author
mmaxfi...@apple.com
Date
2014-04-23 14:33:14 -0700 (Wed, 23 Apr 2014)

Log Message

[OS X] Make checking if a font is the system font more robust
https://bugs.webkit.org/show_bug.cgi?id=132030

Reviewed by Dean Jackson.

Instead of inspecting a font's name to determine if it is a system font,
on OS X we can ask the system directly.

This patch also moves a platform-specific check into platform-specific
code, so that other platforms don't check for OS X-specific behavior.

Covered by existing tests.

* platform/graphics/Font.cpp:
(WebCore::Font::hasValidAverageCharWidth):
* platform/graphics/Font.h:
* platform/graphics/mac/FontMac.mm:
(WebCore::Font::primaryFontDataIsSystemFont):

Modified Paths

Diff

Modified: trunk/Source/WebCore/ChangeLog (167723 => 167724)


--- trunk/Source/WebCore/ChangeLog	2014-04-23 21:27:54 UTC (rev 167723)
+++ trunk/Source/WebCore/ChangeLog	2014-04-23 21:33:14 UTC (rev 167724)
@@ -1,3 +1,24 @@
+2014-04-23  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        [OS X] Make checking if a font is the system font more robust
+        https://bugs.webkit.org/show_bug.cgi?id=132030
+
+        Reviewed by Dean Jackson.
+
+        Instead of inspecting a font's name to determine if it is a system font,
+        on OS X we can ask the system directly.
+
+        This patch also moves a platform-specific check into platform-specific
+        code, so that other platforms don't check for OS X-specific behavior.
+
+        Covered by existing tests.
+
+        * platform/graphics/Font.cpp:
+        (WebCore::Font::hasValidAverageCharWidth):
+        * platform/graphics/Font.h:
+        * platform/graphics/mac/FontMac.mm:
+        (WebCore::Font::primaryFontDataIsSystemFont):
+
 2014-04-23  David Hyatt  <hy...@apple.com>
 
         [New Multicolumn] Assertion failure in huge-column-count.html

Modified: trunk/Source/WebCore/platform/graphics/Font.cpp (167723 => 167724)


--- trunk/Source/WebCore/platform/graphics/Font.cpp	2014-04-23 21:27:54 UTC (rev 167723)
+++ trunk/Source/WebCore/platform/graphics/Font.cpp	2014-04-23 21:33:14 UTC (rev 167724)
@@ -481,11 +481,11 @@
     if (family.isEmpty())
         return false;
 
-    // Internal fonts on OS X also have an invalid entry in the table for avgCharWidth.
-    // They are hidden by having a name that begins with a period, so simply search
-    // for that here rather than try to keep the list up to date.
-    if (family.startsWith('.'))
+#if PLATFORM(MAC) || PLATFORM(IOS)
+    // Internal fonts on OS X and iOS also have an invalid entry in the table for avgCharWidth.
+    if (primaryFontDataIsSystemFont())
         return false;
+#endif
 
     static HashSet<AtomicString>* fontFamiliesWithInvalidCharWidthMap = 0;
 

Modified: trunk/Source/WebCore/platform/graphics/Font.h (167723 => 167724)


--- trunk/Source/WebCore/platform/graphics/Font.h	2014-04-23 21:27:54 UTC (rev 167723)
+++ trunk/Source/WebCore/platform/graphics/Font.h	2014-04-23 21:33:14 UTC (rev 167724)
@@ -189,6 +189,8 @@
     static CodePath characterRangeCodePath(const LChar*, unsigned) { return Simple; }
     static CodePath characterRangeCodePath(const UChar*, unsigned len);
 
+    bool primaryFontDataIsSystemFont() const;
+
 private:
     enum ForTextEmphasisOrNot { NotForTextEmphasis, ForTextEmphasis };
 

Modified: trunk/Source/WebCore/platform/graphics/mac/FontMac.mm (167723 => 167724)


--- trunk/Source/WebCore/platform/graphics/mac/FontMac.mm	2014-04-23 21:27:54 UTC (rev 167723)
+++ trunk/Source/WebCore/platform/graphics/mac/FontMac.mm	2014-04-23 21:33:14 UTC (rev 167724)
@@ -34,6 +34,11 @@
 #endif
 #import <wtf/MathExtras.h>
 
+#if __has_include(<CoreText/CTFontDescriptorPriv.h>)
+#import <CoreText/CTFontDescriptorPriv.h>
+#endif
+extern "C" bool CTFontDescriptorIsSystemUIFont(CTFontDescriptorRef);
+
 #if ENABLE(LETTERPRESS)
 #import "SoftLinking.h"
 #if __has_include(<CoreGraphics/CoreGraphicsPrivate.h>)
@@ -535,4 +540,16 @@
 }
 #endif
 
+bool Font::primaryFontDataIsSystemFont() const
+{
+#if PLATFORM(IOS) || __MAC_OS_X_VERSION_MIN_REQUIRED > 1090
+    RetainPtr<CTFontDescriptorRef> descriptor = CTFontCopyFontDescriptor(primaryFont()->platformData().ctFont());
+    return CTFontDescriptorIsSystemUIFont(descriptor.get());
+#else
+    // System fonts are hidden by having a name that begins with a period, so simply search
+    // for that here rather than try to keep the list up to date.
+    return firstFamily().startsWith('.');
+#endif
 }
+
+}
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to