Support calc() in font-variation-settings and font-feature-settings
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 May 2017 06:03:24 +0000 (06:03 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 23 May 2017 06:03:24 +0000 (06:03 +0000)
https://bugs.webkit.org/show_bug.cgi?id=171032

Reviewed by David Hyatt.

Source/WebCore:

Tests: css3/font-feature-settings-calc.html
       fast/text/variations/calc.html

We can use the convenience functions in CSSPropertyParserHelpers.cpp.

* css/parser/CSSPropertyParser.cpp:
(WebCore::consumeFontFeatureTag):
(WebCore::consumeFontVariationTag):

LayoutTests:

* css3/font-feature-settings-calc-expected.html: Added.
* css3/font-feature-settings-calc.html: Added.
* fast/text/variations/calc-expected.html: Added.
* fast/text/variations/calc.html: Added.

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

LayoutTests/ChangeLog
LayoutTests/css3/font-feature-settings-calc-expected.html [new file with mode: 0644]
LayoutTests/css3/font-feature-settings-calc.html [new file with mode: 0644]
LayoutTests/fast/text/variations/calc-expected.html [new file with mode: 0644]
LayoutTests/fast/text/variations/calc.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/css/parser/CSSPropertyParser.cpp

index e17228e..3250d6b 100644 (file)
@@ -1,3 +1,15 @@
+2017-05-22  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Support calc() in font-variation-settings and font-feature-settings
+        https://bugs.webkit.org/show_bug.cgi?id=171032
+
+        Reviewed by David Hyatt.
+
+        * css3/font-feature-settings-calc-expected.html: Added.
+        * css3/font-feature-settings-calc.html: Added.
+        * fast/text/variations/calc-expected.html: Added.
+        * fast/text/variations/calc.html: Added.
+
 2017-05-22  Ryan Haddad  <ryanhaddad@apple.com>
 
         Mark to imported/w3c/web-platform-tests/webrtc tests as failing on ios-wk2.
diff --git a/LayoutTests/css3/font-feature-settings-calc-expected.html b/LayoutTests/css3/font-feature-settings-calc-expected.html
new file mode 100644 (file)
index 0000000..f365a48
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "FontFeaturesTestOTF";
+    src: url("resources/FontWithFeatures.otf") format("opentype");
+}
+</style>
+</head>
+<body>
+This test makes sure that calc() can be used in font-feature-settings.
+<div style="font: 48px 'FontFeaturesTestOTF';">
+<span style="font-feature-settings: 'zero' 1;">W</span>
+</div>
+</body>
+<html>
diff --git a/LayoutTests/css3/font-feature-settings-calc.html b/LayoutTests/css3/font-feature-settings-calc.html
new file mode 100644 (file)
index 0000000..fa7f576
--- /dev/null
@@ -0,0 +1,17 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "FontFeaturesTestOTF";
+    src: url("resources/FontWithFeatures.otf") format("opentype");
+}
+</style>
+</head>
+<body>
+This test makes sure that calc() can be used in font-feature-settings.
+<div style="font: 48px 'FontFeaturesTestOTF';">
+<span style="font-feature-settings: 'zero' calc(3 - 2);">W</span>
+</div>
+</body>
+<html>
diff --git a/LayoutTests/fast/text/variations/calc-expected.html b/LayoutTests/fast/text/variations/calc-expected.html
new file mode 100644 (file)
index 0000000..0f9f62b
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "Boxis";
+    src: url("resources/Boxis-VF.ttf");
+}
+</style>
+</head>
+<body>
+This test makes sure that calc() works in font-variation-settings.
+<div style="font: 48px 'Boxis'; font-variation-settings: 'desc' 0, 'hght' 750, 'trac' 0, 'wdth' 400;">Hi</div>
+</body>
+</html>
diff --git a/LayoutTests/fast/text/variations/calc.html b/LayoutTests/fast/text/variations/calc.html
new file mode 100644 (file)
index 0000000..7b514ac
--- /dev/null
@@ -0,0 +1,15 @@
+<!DOCTYPE html>
+<html>
+<head>
+<style>
+@font-face {
+    font-family: "Boxis";
+    src: url("resources/Boxis-VF.ttf");
+}
+</style>
+</head>
+<body>
+This test makes sure that calc() works in font-variation-settings.
+<div style="font: 48px 'Boxis'; font-variation-settings: 'desc' 0, 'hght' 750, 'trac' 0, 'wdth' calc(200 + 200);">Hi</div>
+</body>
+</html>
index bef8655..f03a3d8 100644 (file)
@@ -1,3 +1,19 @@
+2017-05-22  Myles C. Maxfield  <mmaxfield@apple.com>
+
+        Support calc() in font-variation-settings and font-feature-settings
+        https://bugs.webkit.org/show_bug.cgi?id=171032
+
+        Reviewed by David Hyatt.
+
+        Tests: css3/font-feature-settings-calc.html
+               fast/text/variations/calc.html
+
+        We can use the convenience functions in CSSPropertyParserHelpers.cpp.
+
+        * css/parser/CSSPropertyParser.cpp:
+        (WebCore::consumeFontFeatureTag):
+        (WebCore::consumeFontVariationTag):
+
 2017-05-22  Michael Catanzaro  <mcatanzaro@igalia.com>
 
         Unreviewed, attempt to fix test runner by removing Unicode character from stderr output
index b9af41e..02cc1fe 100644 (file)
@@ -479,13 +479,14 @@ static RefPtr<CSSFontFeatureValue> consumeFontFeatureTag(CSSParserTokenRange& ra
     }
 
     int tagValue = 1;
-    // Feature tag values could follow: <integer> | on | off
-    if (range.peek().type() == NumberToken && range.peek().numericValueType() == IntegerValueType && range.peek().numericValue() >= 0) {
-        tagValue = clampTo<int>(range.consumeIncludingWhitespace().numericValue());
-        if (tagValue < 0)
+    if (!range.atEnd() && range.peek().type() != CommaToken) {
+        // Feature tag values could follow: <integer> | on | off
+        if (auto primitiveValue = consumeInteger(range, 0))
+            tagValue = primitiveValue->intValue();
+        else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff)
+            tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn;
+        else
             return nullptr;
-    } else if (range.peek().id() == CSSValueOn || range.peek().id() == CSSValueOff) {
-        tagValue = range.consumeIncludingWhitespace().id() == CSSValueOn;
     }
     return CSSFontFeatureValue::create(WTFMove(tag), tagValue);
 }
@@ -523,10 +524,13 @@ static RefPtr<CSSValue> consumeFontVariationTag(CSSParserTokenRange& range)
         tag[i] = character;
     }
     
-    if (range.atEnd() || range.peek().type() != NumberToken)
+    if (range.atEnd())
         return nullptr;
 
-    float tagValue = range.consumeIncludingWhitespace().numericValue();
+    double tagValue = 0;
+    auto success = consumeNumberRaw(range, tagValue);
+    if (!success)
+        return nullptr;
     
     return CSSFontVariationValue::create(tag, tagValue);
 }