[Cocoa] The system Japanese font cannot be italicized
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Jun 2017 23:52:22 +0000 (23:52 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 20 Jun 2017 23:52:22 +0000 (23:52 +0000)
https://bugs.webkit.org/show_bug.cgi?id=173300
<rdar://problem/31805407>

Reviewed by Ryosuke Niwa.

Source/WebCore:

Items in the system font cascade list may lie about whether or not they support italics.
In order to get the truth, we need to use the physical font underlying the font in question,
because this one won't lie. Then, we can interrogate this physical font about its traits
in order to synthesize italics correctly.

Test: fast/text/system-font-japanese-synthetic-italic.html

* platform/graphics/cocoa/FontCacheCoreText.cpp:
(WebCore::lookupFallbackFont):
* platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
(WebCore::FontFamilySpecificationCoreText::fontRanges):

LayoutTests:

* fast/text/system-font-japanese-synthetic-italic-expected-mismatch.html: Added.
* fast/text/system-font-japanese-synthetic-italic.html: Added.
* platform/mac/TestExpectations: This codepath doesn't work in El Capitan.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/system-font-japanese-synthetic-italic-expected-mismatch.html [new file with mode: 0644]
LayoutTests/fast/text/system-font-japanese-synthetic-italic.html [new file with mode: 0644]
LayoutTests/platform/mac/TestExpectations
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/cocoa/FontCacheCoreText.cpp
Source/WebCore/platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp

index 8f77cb8..857c208 100644 (file)
@@ -1,3 +1,15 @@
+2017-06-20  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] The system Japanese font cannot be italicized
+        https://bugs.webkit.org/show_bug.cgi?id=173300
+        <rdar://problem/31805407>
+
+        Reviewed by Ryosuke Niwa.
+
+        * fast/text/system-font-japanese-synthetic-italic-expected-mismatch.html: Added.
+        * fast/text/system-font-japanese-synthetic-italic.html: Added.
+        * platform/mac/TestExpectations: This codepath doesn't work in El Capitan.
+
 2017-06-20  Ryan Haddad  <ryanhaddad@apple.com>
 
         Unreviewed, rolling out r218524.
diff --git a/LayoutTests/fast/text/system-font-japanese-synthetic-italic-expected-mismatch.html b/LayoutTests/fast/text/system-font-japanese-synthetic-italic-expected-mismatch.html
new file mode 100644 (file)
index 0000000..6a970f2
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+This test makes sure that the Japanese system font can be italicized. The test passes if the character below is oblique (either because the font supports it or because WebKit synthesizes the oblique).
+<div style="font: 100px 'system-ui';">の</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/system-font-japanese-synthetic-italic.html b/LayoutTests/fast/text/system-font-japanese-synthetic-italic.html
new file mode 100644 (file)
index 0000000..0b48830
--- /dev/null
@@ -0,0 +1,10 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+</head>
+<body>
+This test makes sure that the Japanese system font can be italicized. The test passes if the character below is oblique (either because the font supports it or because WebKit synthesizes the oblique).
+<div style="font: 100px 'system-ui'; font-style: italic;">の</div>
+</body>
+</html>
index 10421e0..72493a8 100644 (file)
@@ -1605,3 +1605,4 @@ webkit.org/b/173328 [ ElCapitan Sierra ] fast/text/system-font-fallback.html [ I
 
 webkit.org/b/173487 imported/w3c/web-platform-tests/IndexedDB/large-nested-cloning.html [ Pass Failure ]
 
+webkit.org/b/313156 [ ElCapitan ] fast/text/system-font-japanese-synthetic-italic.html [ ImageOnlyFailure ]
index b2acde7..008b672 100644 (file)
@@ -1,3 +1,23 @@
+2017-06-20  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [Cocoa] The system Japanese font cannot be italicized
+        https://bugs.webkit.org/show_bug.cgi?id=173300
+        <rdar://problem/31805407>
+
+        Reviewed by Ryosuke Niwa.
+
+        Items in the system font cascade list may lie about whether or not they support italics.
+        In order to get the truth, we need to use the physical font underlying the font in question,
+        because this one won't lie. Then, we can interrogate this physical font about its traits
+        in order to synthesize italics correctly.
+
+        Test: fast/text/system-font-japanese-synthetic-italic.html
+
+        * platform/graphics/cocoa/FontCacheCoreText.cpp:
+        (WebCore::lookupFallbackFont):
+        * platform/graphics/cocoa/FontFamilySpecificationCoreText.cpp:
+        (WebCore::FontFamilySpecificationCoreText::fontRanges):
+
 2017-06-20  Chris Dumez  <cdumez@apple.com>
 
         Use WTF::Function instead of std::function in more places in WebCore/
index 8b03058..d5a35f1 100644 (file)
@@ -1292,7 +1292,12 @@ static RetainPtr<CTFontRef> lookupFallbackFont(CTFontRef font, FontSelectionValu
 #endif
 
     CFIndex coveredLength = 0;
-    auto result = adoptCF(CTFontCreateForCharactersWithLanguage(font, characters, length, localeString.get(), &coveredLength));
+    RetainPtr<CTFontRef> result;
+#if !USE_PLATFORM_SYSTEM_FALLBACK_LIST && ((PLATFORM(MAC) && __MAC_OS_X_VERSION_MIN_REQUIRED >= 101200) || (PLATFORM(IOS) && __IPHONE_OS_VERSION_MIN_REQUIRED >= 100000))
+    result = adoptCF(CTFontCreatePhysicalFontForCharactersWithLanguage(font, characters, length, localeString.get(), &coveredLength));
+#else
+    result = adoptCF(CTFontCreateForCharactersWithLanguage(font, characters, length, localeString.get(), &coveredLength));
+#endif
 
 #if PLATFORM(IOS)
     // Callers of this function won't include multiple code points. "Length" is to know how many code units
index 4321470..15f9c37 100644 (file)
 
 #include "FontCache.h"
 #include "FontSelector.h"
+#include "SoftLinking.h"
 #include <CoreText/CoreText.h>
 
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+SOFT_LINK_FRAMEWORK(CoreText);
+SOFT_LINK_MAY_FAIL(CoreText, CTFontCopyPhysicalFont, CTFontRef, (CTFontRef font), (font));
+#endif
+
 namespace WebCore {
 
 FontFamilySpecificationCoreText::FontFamilySpecificationCoreText(CTFontDescriptorRef fontDescriptor)
@@ -47,10 +53,18 @@ FontRanges FontFamilySpecificationCoreText::fontRanges(const FontDescription& fo
 
     auto font = adoptCF(CTFontCreateWithFontDescriptor(m_fontDescriptor.get(), size, nullptr));
 
+    auto fontForSynthesisComputation = font;
+#if USE_PLATFORM_SYSTEM_FALLBACK_LIST
+    if (canLoadCTFontCopyPhysicalFont()) {
+        if (auto physicalFont = adoptCF(CTFontCopyPhysicalFont(font.get())))
+            fontForSynthesisComputation = physicalFont;
+    }
+#endif
+
     font = preparePlatformFont(font.get(), fontDescription, nullptr, nullptr, { }, fontDescription.computedSize());
 
     bool syntheticBold, syntheticOblique;
-    std::tie(syntheticBold, syntheticOblique) = computeNecessarySynthesis(font.get(), fontDescription).boldObliquePair();
+    std::tie(syntheticBold, syntheticOblique) = computeNecessarySynthesis(fontForSynthesisComputation.get(), fontDescription).boldObliquePair();
 
     FontPlatformData fontPlatformData(font.get(), size, syntheticBold, syntheticOblique, fontDescription.orientation(), fontDescription.widthVariant(), fontDescription.textRenderingMode());