[iOS] Support bold and thin italicized system fonts
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 00:02:15 +0000 (00:02 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 2 Jul 2015 00:02:15 +0000 (00:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=146463
<rdar://problem/20948885>

Reviewed by Darin Adler.

Source/WebCore:

Add the italicized attribute to font descriptors.

Test: fast/text/weighted-italicized-system-font.html

* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::createCTFontWithFamilyNameAndWeight):
* platform/graphics/mac/FontCacheMac.mm:
(WebCore::fontWithFamilySpecialCase):
(WebCore::fontWithFamily):
* platform/spi/cocoa/CoreTextSPI.h:

LayoutTests:

* fast/text/weighted-italicized-system-font-expected.html: Added.
* fast/text/weighted-italicized-system-font.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/fast/text/weighted-italicized-system-font-expected.html [new file with mode: 0644]
LayoutTests/fast/text/weighted-italicized-system-font.html [new file with mode: 0644]
LayoutTests/platform/mac-mavericks/fast/text/weighted-italicized-system-font-expected.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ios/FontCacheIOS.mm
Source/WebCore/platform/graphics/mac/FontCacheMac.mm
Source/WebCore/platform/spi/cocoa/CoreTextSPI.h

index 3d7a842..dd45700 100644 (file)
@@ -1,3 +1,14 @@
+2015-07-01  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [iOS] Support bold and thin italicized system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=146463
+        <rdar://problem/20948885>
+
+        Reviewed by Darin Adler.
+
+        * fast/text/weighted-italicized-system-font-expected.html: Added.
+        * fast/text/weighted-italicized-system-font.html: Added.
+
 2015-07-01  Matthew Mirman  <mmirman@apple.com>
 
         Unreviewed, rolling out r185889
diff --git a/LayoutTests/fast/text/weighted-italicized-system-font-expected.html b/LayoutTests/fast/text/weighted-italicized-system-font-expected.html
new file mode 100644 (file)
index 0000000..bca1664
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that bold &amp; thin italicized system fonts render without synthetic bold.
+<div style="font: 100px -apple-system; font-style: italic;">
+<span style="font-weight: 100;">a</span>
+<span style="font-weight: 700;">a</span>
+</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/weighted-italicized-system-font.html b/LayoutTests/fast/text/weighted-italicized-system-font.html
new file mode 100644 (file)
index 0000000..07f6c84
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that bold &amp; thin italicized system fonts render without synthetic bold.
+<div style="font: 100px -apple-system; font-synthesis: none; font-style: italic;">
+<span style="font-weight: 100;">a</span>
+<span style="font-weight: 700;">a</span>
+</div>
+</body>
+</html>
diff --git a/LayoutTests/platform/mac-mavericks/fast/text/weighted-italicized-system-font-expected.html b/LayoutTests/platform/mac-mavericks/fast/text/weighted-italicized-system-font-expected.html
new file mode 100644 (file)
index 0000000..c8105ef
--- /dev/null
@@ -0,0 +1,12 @@
+<!DOCTYPE html>
+<html>
+<head>
+</head>
+<body>
+This test makes sure that bold &amp; thin italicized system fonts render without synthetic bold.
+<div style="font: 100px -apple-system;">
+<span style="font-weight: 100;">a</span>
+<span style="font-weight: 700;">a</span>
+</div>
+</body>
+</html>
index 52f29ed..16b1e98 100644 (file)
@@ -1,3 +1,22 @@
+2015-07-01  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        [iOS] Support bold and thin italicized system fonts
+        https://bugs.webkit.org/show_bug.cgi?id=146463
+        <rdar://problem/20948885>
+
+        Reviewed by Darin Adler.
+
+        Add the italicized attribute to font descriptors.
+
+        Test: fast/text/weighted-italicized-system-font.html
+
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::createCTFontWithFamilyNameAndWeight):
+        * platform/graphics/mac/FontCacheMac.mm:
+        (WebCore::fontWithFamilySpecialCase):
+        (WebCore::fontWithFamily):
+        * platform/spi/cocoa/CoreTextSPI.h:
+
 2015-07-01  Alex Christensen  <achristensen@webkit.org>
 
         Fix ANGLE Windows build after r186169.
index fd49b7d..c9131c2 100644 (file)
@@ -615,11 +615,8 @@ static CTFontRef createCTFontWithFamilyNameAndWeight(const String& familyName, C
         if (weight > 300) {
             // The comment below has been copied from CoreText/UIFoundation. However, in WebKit we synthesize the oblique,
             // so we should investigate the result <rdar://problem/14449340>:
-            // We don't do bold-italic for system fonts. If you ask for it, we'll assume that you're just kidding and that you really want bold. This is a feature.
             if (traits & kCTFontTraitBold)
                 fontType = kCTFontUIFontEmphasizedSystem;
-            else if (traits & kCTFontTraitItalic)
-                fontType = static_cast<CTFontUIFontType>(kCTFontUIFontSystemItalic);
         } else if (weight > 250)
             fontType = static_cast<CTFontUIFontType>(kCTFontUIFontSystemLight);
         else if (weight > 150)
@@ -627,6 +624,8 @@ static CTFontRef createCTFontWithFamilyNameAndWeight(const String& familyName, C
         else
             fontType = static_cast<CTFontUIFontType>(kCTFontUIFontSystemUltraLight);
         RetainPtr<CTFontDescriptorRef> fontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(fontType, size, nullptr));
+        if (traits & kCTFontTraitItalic)
+            fontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithSymbolicTraits(fontDescriptor.get(), kCTFontItalicTrait, kCTFontItalicTrait));
         return CTFontCreateWithFontDescriptor(fontDescriptor.get(), size, nullptr);
     }
 
index 7fae93b..6d9c4f8 100644 (file)
@@ -228,16 +228,19 @@ static CGFloat toNSFontWeight(FontWeight fontWeight)
 }
 #endif
 
-static Optional<NSFont*> fontWithFamilySpecialCase(const AtomicString& family, FontWeight weight, float size)
+static Optional<NSFont*> fontWithFamilySpecialCase(const AtomicString& family, FontWeight weight, NSFontTraitMask desiredTraits, float size)
 {
     if (equalIgnoringASCIICase(family, "-webkit-system-font")
         || equalIgnoringASCIICase(family, "-apple-system")
         || equalIgnoringASCIICase(family, "-apple-system-font")) {
 #if __MAC_OS_X_VERSION_MIN_REQUIRED >= 101000
-        return [NSFont systemFontOfSize:size weight:toNSFontWeight(weight)];
+        NSFont *result = [NSFont systemFontOfSize:size weight:toNSFontWeight(weight)];
 #else
-        return (weight >= FontWeight600) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
+        NSFont *result = (weight >= FontWeight600) ? [NSFont boldSystemFontOfSize:size] : [NSFont systemFontOfSize:size];
 #endif
+        if (desiredTraits & NSFontItalicTrait)
+            result = [[NSFontManager sharedFontManager] convertFont:result toHaveTrait:desiredTraits];
+        return result;
     }
 
     if (equalIgnoringASCIICase(family, "-apple-system-monospaced-numbers")) {
@@ -263,7 +266,7 @@ static Optional<NSFont*> fontWithFamilySpecialCase(const AtomicString& family, F
 // we then do a search based on the family names of the installed fonts.
 static NSFont *fontWithFamily(const AtomicString& family, NSFontTraitMask desiredTraits, FontWeight weight, float size)
 {
-    if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, size))
+    if (const auto& specialCase = fontWithFamilySpecialCase(family, weight, desiredTraits, size))
         return specialCase.value();
 
     NSFontManager *fontManager = [NSFontManager sharedFontManager];
index a3ac258..9b04c2d 100644 (file)
@@ -75,6 +75,7 @@ void CTFontSetRenderingParameters(CTFontRef, CGContextRef);
 
 CTFontDescriptorRef CTFontDescriptorCreateForUIType(CTFontUIFontType, CGFloat size, CFStringRef language);
 CTFontDescriptorRef CTFontDescriptorCreateWithTextStyle(CFStringRef style, CFStringRef size, CFStringRef language);
+CTFontDescriptorRef CTFontDescriptorCreateCopyWithSymbolicTraits(CTFontDescriptorRef original, CTFontSymbolicTraits symTraitValue, CTFontSymbolicTraits symTraitMask);
 
 #if PLATFORM(COCOA)
 #if !USE(APPLE_INTERNAL_SDK)