-apple-system-font-monospaced-numbers doesn't work on iOS
authordino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Apr 2015 23:26:11 +0000 (23:26 +0000)
committerdino@apple.com <dino@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 30 Apr 2015 23:26:11 +0000 (23:26 +0000)
https://bugs.webkit.org/show_bug.cgi?id=144478
<rdar://problem/20544940>

Reviewed by Brent Fulgham.

Source/WebCore:

Make sure to start from the system font descriptor when
asking for a monospaced numeric alternate.

Test: platform/ios-simulator/fast/text/system-monospaced-numbers.html

* platform/graphics/ios/FontCacheIOS.mm:
(WebCore::createCTFontWithFamilyNameAndWeight):

LayoutTests:

A test that draws two lines of different numbers and checks
they are the same width.

* platform/ios-simulator/fast/text/system-monospaced-numbers-expected.txt: Added.
* platform/ios-simulator/fast/text/system-monospaced-numbers.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/platform/ios-simulator/fast/text/system-monospaced-numbers-expected.txt [new file with mode: 0644]
LayoutTests/platform/ios-simulator/fast/text/system-monospaced-numbers.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/platform/graphics/ios/FontCacheIOS.mm

index 98917b0..96f0bee 100644 (file)
@@ -1,3 +1,17 @@
+2015-04-30  Dean Jackson  <dino@apple.com>
+
+        -apple-system-font-monospaced-numbers doesn't work on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=144478
+        <rdar://problem/20544940>
+
+        Reviewed by Brent Fulgham.
+
+        A test that draws two lines of different numbers and checks
+        they are the same width.
+
+        * platform/ios-simulator/fast/text/system-monospaced-numbers-expected.txt: Added.
+        * platform/ios-simulator/fast/text/system-monospaced-numbers.html: Added.
+
 2015-04-30  Joseph Pecoraro  <pecoraro@apple.com>
 
         Unreviewed, ios-simulator gardening
diff --git a/LayoutTests/platform/ios-simulator/fast/text/system-monospaced-numbers-expected.txt b/LayoutTests/platform/ios-simulator/fast/text/system-monospaced-numbers-expected.txt
new file mode 100644 (file)
index 0000000..ebee32b
--- /dev/null
@@ -0,0 +1,7 @@
+These next two lines should be the same width
+
+00:11:22.33
+
+11:11:11.11
+
+PASS: widths were the same
diff --git a/LayoutTests/platform/ios-simulator/fast/text/system-monospaced-numbers.html b/LayoutTests/platform/ios-simulator/fast/text/system-monospaced-numbers.html
new file mode 100644 (file)
index 0000000..6721161
--- /dev/null
@@ -0,0 +1,31 @@
+<style>
+span {
+    font-family: -apple-system-font-monospaced-numbers;
+    font-size: 24px
+}
+</style>
+<script>
+if (window.testRunner)
+    window.testRunner.dumpAsText();
+
+window.addEventListener("load", run, false);
+
+function run() {
+    var a = document.getElementById("a");
+    var b = document.getElementById("b");
+    var result = document.getElementById("result");
+
+    var aRect = a.getBoundingClientRect();
+    var bRect = b.getBoundingClientRect();
+
+    if (aRect.width == bRect.width)
+        result.textContent = "PASS: widths were the same";
+    else
+        result.textContent = "FAIL: widths were not the same";
+}
+</script>
+<p>These next two lines should be the same width</p>
+<p><span id="a">00:11:22.33</span></p>
+<p><span id="b">11:11:11.11</span></p>
+
+<p id="result"></p>
index 2fe06cd..ed4c73c 100644 (file)
@@ -1,3 +1,19 @@
+2015-04-30  Dean Jackson  <dino@apple.com>
+
+        -apple-system-font-monospaced-numbers doesn't work on iOS
+        https://bugs.webkit.org/show_bug.cgi?id=144478
+        <rdar://problem/20544940>
+
+        Reviewed by Brent Fulgham.
+
+        Make sure to start from the system font descriptor when
+        asking for a monospaced numeric alternate.
+
+        Test: platform/ios-simulator/fast/text/system-monospaced-numbers.html
+
+        * platform/graphics/ios/FontCacheIOS.mm:
+        (WebCore::createCTFontWithFamilyNameAndWeight):
+
 2015-04-30  Oliver Hunt  <oliver@apple.com>
 
         DOM bindings should not be using a reference type to point to a temporary object
index de82924..6b81bff 100644 (file)
@@ -625,11 +625,9 @@ static CTFontRef createCTFontWithFamilyNameAndWeight(const String& familyName, C
 
     static NeverDestroyed<AtomicString> systemUIMonospacedNumbersFontWithApplePrefix("-apple-system-font-monospaced-numbers", AtomicString::ConstructFromLiteral);
     if (equalIgnoringCase(familyName, systemUIMonospacedNumbersFontWithApplePrefix)) {
-        NSDictionary *attributes = @{ (NSString *)kCTFontFeatureTypeIdentifierKey : @(kNumberSpacingType),
-            (NSString *)kCTFontFeatureSelectorIdentifierKey : @(kMonospacedNumbersSelector) };
-
-        RetainPtr<CTFontDescriptorRef> fontDescriptor = adoptCF(CTFontDescriptorCreateWithAttributesAndOptions((CFDictionaryRef)attributes, kCTFontDescriptorOptionSystemUIFont | kCTFontDescriptorOptionPreferAppleSystemFont));
-        return CTFontCreateWithFontDescriptor(fontDescriptor.get(), size, nullptr);
+        RetainPtr<CTFontDescriptorRef> systemFontDescriptor = adoptCF(CTFontDescriptorCreateForUIType(kCTFontUIFontSystem, size, nullptr));
+        RetainPtr<CTFontDescriptorRef> monospaceFontDescriptor = adoptCF(CTFontDescriptorCreateCopyWithFeature(systemFontDescriptor.get(), (CFNumberRef)@(kNumberSpacingType), (CFNumberRef)@(kMonospacedNumbersSelector)));
+        return CTFontCreateWithFontDescriptor(monospaceFontDescriptor.get(), size, nullptr);
     }