Title: [206679] trunk
Revision
206679
Author
mmaxfi...@apple.com
Date
2016-09-30 14:59:15 -0700 (Fri, 30 Sep 2016)

Log Message

Parse font-variation-settings
https://bugs.webkit.org/show_bug.cgi?id=162781

Reviewed by Simon Fraser.

Source/WebCore:

CSS Fonts level 4 [1] details the font-variation-settings property which allows variations
to be applied to fonts which accept it. The property accepts a list of key/value
pairs where the keys are four-character Ascii codes and the values are floating
point values. The implementation uses font-feature-settings as a model, but with one
big difference: font-variation-settings can be animated. The set of variation points
are animated individually.

This font variations work is being done behind a run-time switch, which is settable from
the Safari Develop menu.

Now that FontDescription is growing, I'd like to do an investigation into the possibility of
moving some of the rare pieces of it into their own class to reduce memory. However, upon
advice, this investigation will be fairly involved and should be done in its own bug.

Test: fast/text/variations/getComputedStyle.html

* CMakeLists.txt:
* WebCore.xcodeproj/project.pbxproj:
* css/CSSAllInOne.cpp:
* css/CSSComputedStyleDeclaration.cpp:
(WebCore::ComputedStyleExtractor::propertyValue):
* css/CSSFontVariationValue.cpp: Copied from Source/WebCore/platform/graphics/FontTaggedSettings.cpp.
(WebCore::CSSFontVariationValue::CSSFontVariationValue):
(WebCore::CSSFontVariationValue::customCSSText):
(WebCore::CSSFontVariationValue::equals):
* css/CSSFontVariationValue.h: Copied from Source/WebCore/platform/graphics/FontTaggedSettings.cpp.
* css/CSSPropertyNames.in:
* css/CSSValue.cpp:
(WebCore::CSSValue::equals):
(WebCore::CSSValue::cssText):
(WebCore::CSSValue::destroy):
* css/CSSValue.h:
(WebCore::CSSValue::isFontVariationValue):
(WebCore::CSSValue::isFontFeatureValue): Deleted.
* css/StyleBuilderConverter.h:
(WebCore::StyleBuilderConverter::convertFontVariationSettings):
* css/StyleBuilderCustom.h:
(WebCore::StyleBuilderCustom::applyInitialFontVariationSettings):
(WebCore::StyleBuilderCustom::applyInheritFontVariationSettings):
(WebCore::StyleBuilderCustom::applyInheritFontFeatureSettings): Deleted.
* css/parser/CSSParser.cpp:
(WebCore::CSSParserContext::CSSParserContext):
(WebCore::operator==):
(WebCore::CSSParser::parseValue):
(WebCore::CSSParser::parseFontFeatureSettings):
(WebCore::CSSParser::parseFontVariationTag):
(WebCore::CSSParser::parseFontVariationSettings):
* css/parser/CSSParser.h:
* css/parser/CSSParserMode.h:
* platform/graphics/FontCache.h:
(WebCore::FontDescriptionKey::FontDescriptionKey):
(WebCore::FontDescriptionKey::operator==):
(WebCore::FontDescriptionKey::computeHash):
* platform/graphics/FontDescription.cpp:
* platform/graphics/FontDescription.h:
(WebCore::FontDescription::variationSettings):
(WebCore::FontDescription::setVariationSettings):
(WebCore::FontDescription::operator==):
(WebCore::FontDescription::featureSettings): Deleted.
(WebCore::FontDescription::setFeatureSettings): Deleted.
* platform/graphics/FontTaggedSettings.cpp:
(WebCore::FontVariationSettings::hash):
(WebCore::operator<<):
* platform/graphics/FontTaggedSettings.h:

LayoutTests:

* fast/text/variations/getComputedStyle-expected.txt: Added.
* fast/text/variations/getComputedStyle.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (206678 => 206679)


--- trunk/LayoutTests/ChangeLog	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/LayoutTests/ChangeLog	2016-09-30 21:59:15 UTC (rev 206679)
@@ -1,3 +1,13 @@
+2016-09-30  Myles C. Maxfield  <mmaxfi...@apple.com>
+
+        Parse font-variation-settings
+        https://bugs.webkit.org/show_bug.cgi?id=162781
+
+        Reviewed by Simon Fraser.
+
+        * fast/text/variations/getComputedStyle-expected.txt: Added.
+        * fast/text/variations/getComputedStyle.html: Added.
+
 2016-09-30  Ryan Haddad  <ryanhad...@apple.com>
 
         Mark inspector/debugger/breakpoints tests as slow on release, skipped on debug.

Added: trunk/LayoutTests/fast/text/variations/getComputedStyle-expected.txt (0 => 206679)


--- trunk/LayoutTests/fast/text/variations/getComputedStyle-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/text/variations/getComputedStyle-expected.txt	2016-09-30 21:59:15 UTC (rev 206679)
@@ -0,0 +1,12 @@
+PASS window.getComputedStyle(document.getElementById('test0')).getPropertyValue('font-variation-settings') is "'wght' 2"
+PASS window.getComputedStyle(document.getElementById('test1')).getPropertyValue('font-variation-settings') is "'wght' 3"
+PASS window.getComputedStyle(document.getElementById('test2')).getPropertyValue('font-variation-settings') is "'wght' 2, 'wdth' 1.2"
+PASS window.getComputedStyle(document.getElementById('test2')).getPropertyValue('font-variation-settings') is window.getComputedStyle(document.getElementById('test3')).getPropertyValue('font-variation-settings')
+PASS window.getComputedStyle(document.getElementById('test4')).getPropertyValue('font-variation-settings') is "normal"
+PASS window.getComputedStyle(document.getElementById('test5')).getPropertyValue('font-variation-settings') is "normal"
+PASS window.getComputedStyle(document.getElementById('test6')).getPropertyValue('font-variation-settings') is "normal"
+PASS window.getComputedStyle(document.getElementById('test7')).getPropertyValue('font-variation-settings') is "'wght' 27"
+PASS successfullyParsed is true
+
+TEST COMPLETE
+
Property changes on: trunk/LayoutTests/fast/text/variations/getComputedStyle-expected.txt
___________________________________________________________________

Added: svn:eol-style

+native \ No newline at end of property

Added: svn:keywords

+Author Date Id Rev URL \ No newline at end of property

Added: trunk/LayoutTests/fast/text/variations/getComputedStyle.html (0 => 206679)


--- trunk/LayoutTests/fast/text/variations/getComputedStyle.html	                        (rev 0)
+++ trunk/LayoutTests/fast/text/variations/getComputedStyle.html	2016-09-30 21:59:15 UTC (rev 206679)
@@ -0,0 +1,32 @@
+<!DOCTYPE html>
+<html>
+<head>
+<meta charset="utf-8">
+<script>
+if (window.internals)
+   window.internals.settings.setVariationFontsEnabled(true);
+</script>
+<script src=""
+</head>
+<body>
+<div id="test0" style="font-family: 'Skia'; font-variation-settings: 'wght' 2;"></div>
+<div id="test1" style="font-family: 'Skia'; font-variation-settings: 'wght' 2, 'wght' 3;"></div>
+<div id="test2" style="font-family: 'Skia'; font-variation-settings: 'wght' 2, 'wdth' 1.2;"></div>
+<div id="test3" style="font-family: 'Skia'; font-variation-settings: 'wdth' 1.2, 'wght' 2;"></div>
+<div id="test4" style="font-family: 'Skia'; font-variation-settings: normal;"></div>
+<div id="test5" style="font-family: 'Skia'; font-variation-settings: 'abcde' 3;"></div>
+<div id="test6" style="font-family: 'Skia'; font-variation-settings: 'abc한국어e' 3;"></div>
+<div id="test7" style="font-family: 'Skia'; font-variation-settings: 'wght' 27;"></div>
+<script>
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test0')).getPropertyValue('font-variation-settings')", "'wght' 2");
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test1')).getPropertyValue('font-variation-settings')", "'wght' 3");
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test2')).getPropertyValue('font-variation-settings')", "'wght' 2, 'wdth' 1.2");
+shouldBe("window.getComputedStyle(document.getElementById('test2')).getPropertyValue('font-variation-settings')", "window.getComputedStyle(document.getElementById('test3')).getPropertyValue('font-variation-settings')");
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test4')).getPropertyValue('font-variation-settings')", "normal");
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test5')).getPropertyValue('font-variation-settings')", "normal");
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test6')).getPropertyValue('font-variation-settings')", "normal");
+shouldBeEqualToString("window.getComputedStyle(document.getElementById('test7')).getPropertyValue('font-variation-settings')", "'wght' 27");
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/CMakeLists.txt (206678 => 206679)


--- trunk/Source/WebCore/CMakeLists.txt	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/CMakeLists.txt	2016-09-30 21:59:15 UTC (rev 206679)
@@ -1266,6 +1266,7 @@
     css/CSSFontFeatureValue.cpp
     css/CSSFontSelector.cpp
     css/CSSFontValue.cpp
+    css/CSSFontVariationValue.cpp
     css/CSSFunctionValue.cpp
     css/CSSGradientValue.cpp
     css/CSSGridAutoRepeatValue.cpp

Modified: trunk/Source/WebCore/ChangeLog (206678 => 206679)


--- trunk/Source/WebCore/ChangeLog	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/ChangeLog	2016-09-30 21:59:15 UTC (rev 206679)
@@ -1,5 +1,77 @@
 2016-09-30  Myles C. Maxfield  <mmaxfi...@apple.com>
 
+        Parse font-variation-settings
+        https://bugs.webkit.org/show_bug.cgi?id=162781
+
+        Reviewed by Simon Fraser.
+
+        CSS Fonts level 4 [1] details the font-variation-settings property which allows variations
+        to be applied to fonts which accept it. The property accepts a list of key/value
+        pairs where the keys are four-character Ascii codes and the values are floating
+        point values. The implementation uses font-feature-settings as a model, but with one
+        big difference: font-variation-settings can be animated. The set of variation points
+        are animated individually.
+
+        This font variations work is being done behind a run-time switch, which is settable from
+        the Safari Develop menu.
+
+        Now that FontDescription is growing, I'd like to do an investigation into the possibility of
+        moving some of the rare pieces of it into their own class to reduce memory. However, upon
+        advice, this investigation will be fairly involved and should be done in its own bug.
+
+        Test: fast/text/variations/getComputedStyle.html
+
+        * CMakeLists.txt:
+        * WebCore.xcodeproj/project.pbxproj:
+        * css/CSSAllInOne.cpp:
+        * css/CSSComputedStyleDeclaration.cpp:
+        (WebCore::ComputedStyleExtractor::propertyValue):
+        * css/CSSFontVariationValue.cpp: Copied from Source/WebCore/platform/graphics/FontTaggedSettings.cpp.
+        (WebCore::CSSFontVariationValue::CSSFontVariationValue):
+        (WebCore::CSSFontVariationValue::customCSSText):
+        (WebCore::CSSFontVariationValue::equals):
+        * css/CSSFontVariationValue.h: Copied from Source/WebCore/platform/graphics/FontTaggedSettings.cpp.
+        * css/CSSPropertyNames.in:
+        * css/CSSValue.cpp:
+        (WebCore::CSSValue::equals):
+        (WebCore::CSSValue::cssText):
+        (WebCore::CSSValue::destroy):
+        * css/CSSValue.h:
+        (WebCore::CSSValue::isFontVariationValue):
+        (WebCore::CSSValue::isFontFeatureValue): Deleted.
+        * css/StyleBuilderConverter.h:
+        (WebCore::StyleBuilderConverter::convertFontVariationSettings):
+        * css/StyleBuilderCustom.h:
+        (WebCore::StyleBuilderCustom::applyInitialFontVariationSettings):
+        (WebCore::StyleBuilderCustom::applyInheritFontVariationSettings):
+        (WebCore::StyleBuilderCustom::applyInheritFontFeatureSettings): Deleted.
+        * css/parser/CSSParser.cpp:
+        (WebCore::CSSParserContext::CSSParserContext):
+        (WebCore::operator==):
+        (WebCore::CSSParser::parseValue):
+        (WebCore::CSSParser::parseFontFeatureSettings):
+        (WebCore::CSSParser::parseFontVariationTag):
+        (WebCore::CSSParser::parseFontVariationSettings):
+        * css/parser/CSSParser.h:
+        * css/parser/CSSParserMode.h:
+        * platform/graphics/FontCache.h:
+        (WebCore::FontDescriptionKey::FontDescriptionKey):
+        (WebCore::FontDescriptionKey::operator==):
+        (WebCore::FontDescriptionKey::computeHash):
+        * platform/graphics/FontDescription.cpp:
+        * platform/graphics/FontDescription.h:
+        (WebCore::FontDescription::variationSettings):
+        (WebCore::FontDescription::setVariationSettings):
+        (WebCore::FontDescription::operator==):
+        (WebCore::FontDescription::featureSettings): Deleted.
+        (WebCore::FontDescription::setFeatureSettings): Deleted.
+        * platform/graphics/FontTaggedSettings.cpp:
+        (WebCore::FontVariationSettings::hash):
+        (WebCore::operator<<):
+        * platform/graphics/FontTaggedSettings.h:
+
+2016-09-30  Myles C. Maxfield  <mmaxfi...@apple.com>
+
         Followup patch to r206664
         https://bugs.webkit.org/show_bug.cgi?id=162774
 

Modified: trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj (206678 => 206679)


--- trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/WebCore.xcodeproj/project.pbxproj	2016-09-30 21:59:15 UTC (rev 206679)
@@ -5469,6 +5469,8 @@
 		C105DA620F3AA68F001DD44F /* TextEncodingDetectorICU.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */; };
 		C105DA640F3AA6B8001DD44F /* TextEncodingDetector.h in Headers */ = {isa = PBXBuildFile; fileRef = C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */; };
 		C2015C0A1BE6FEB200822389 /* FontVariantBuilder.h in Headers */ = {isa = PBXBuildFile; fileRef = C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */; };
+		C21DF2E91D9E4E9900F5B24C /* CSSFontVariationValue.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */; };
+		C21DF2EA1D9E4E9900F5B24C /* CSSFontVariationValue.h in Headers */ = {isa = PBXBuildFile; fileRef = C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */; };
 		C26017A31C72DC9900F74A16 /* CSSFontFaceSet.cpp in Sources */ = {isa = PBXBuildFile; fileRef = C26017A11C72DC9900F74A16 /* CSSFontFaceSet.cpp */; };
 		C26017A41C72DC9900F74A16 /* CSSFontFaceSet.h in Headers */ = {isa = PBXBuildFile; fileRef = C26017A21C72DC9900F74A16 /* CSSFontFaceSet.h */; };
 		C280833F1C6DC26F001451B6 /* JSFontFace.h in Headers */ = {isa = PBXBuildFile; fileRef = C280833E1C6DC22C001451B6 /* JSFontFace.h */; };
@@ -12970,6 +12972,8 @@
 		C105DA610F3AA68F001DD44F /* TextEncodingDetectorICU.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = TextEncodingDetectorICU.cpp; sourceTree = "<group>"; };
 		C105DA630F3AA6B8001DD44F /* TextEncodingDetector.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = TextEncodingDetector.h; sourceTree = "<group>"; };
 		C2015C091BE6FE2C00822389 /* FontVariantBuilder.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = FontVariantBuilder.h; sourceTree = "<group>"; };
+		C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontVariationValue.cpp; sourceTree = "<group>"; };
+		C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontVariationValue.h; sourceTree = "<group>"; };
 		C24685131A148E1800811792 /* CoreGraphicsSPI.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CoreGraphicsSPI.h; sourceTree = "<group>"; };
 		C26017A11C72DC9900F74A16 /* CSSFontFaceSet.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = CSSFontFaceSet.cpp; sourceTree = "<group>"; };
 		C26017A21C72DC9900F74A16 /* CSSFontFaceSet.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CSSFontFaceSet.h; sourceTree = "<group>"; };
@@ -22600,6 +22604,8 @@
 				3FFFF9A6159D9A550020BBD5 /* WebKitCSSViewportRule.cpp */,
 				3FFFF9A7159D9A550020BBD5 /* WebKitCSSViewportRule.h */,
 				3F2B33E3165ABD3500E3987C /* WebKitCSSViewportRule.idl */,
+				C21DF2E71D9E4E9900F5B24C /* CSSFontVariationValue.cpp */,
+				C21DF2E81D9E4E9900F5B24C /* CSSFontVariationValue.h */,
 			);
 			path = css;
 			sourceTree = "<group>";
@@ -24709,6 +24715,7 @@
 				A8D223FE16B52E4E00157288 /* HTMLResourcePreloader.h in Headers */,
 				A871DC250A15205700B12A68 /* HTMLScriptElement.h in Headers */,
 				977B3875122883E900B81FF8 /* HTMLScriptRunner.h in Headers */,
+				C21DF2EA1D9E4E9900F5B24C /* CSSFontVariationValue.h in Headers */,
 				977B3876122883E900B81FF8 /* HTMLScriptRunnerHost.h in Headers */,
 				A81369D8097374F600D74463 /* HTMLSelectElement.h in Headers */,
 				9B69D3B51B98FFE900E3512B /* HTMLSlotElement.h in Headers */,
@@ -28470,6 +28477,7 @@
 				DB23C2CB0A508D29002489EB /* IndentOutdentCommand.cpp in Sources */,
 				517138EF1BED1D1A000D5F01 /* IndexKey.cpp in Sources */,
 				51EEAA731BEFFAB100218008 /* IndexValueEntry.cpp in Sources */,
+				C21DF2E91D9E4E9900F5B24C /* CSSFontVariationValue.cpp in Sources */,
 				517138F71BF128BB000D5F01 /* IndexValueStore.cpp in Sources */,
 				A8CFF5E60A155A05000A4234 /* InlineBox.cpp in Sources */,
 				B57CB52D182A3EED0079A647 /* InlineElementBox.cpp in Sources */,

Modified: trunk/Source/WebCore/css/CSSAllInOne.cpp (206678 => 206679)


--- trunk/Source/WebCore/css/CSSAllInOne.cpp	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/CSSAllInOne.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -48,6 +48,7 @@
 #include "CSSFontFeatureValue.cpp"
 #include "CSSFontSelector.cpp"
 #include "CSSFontValue.cpp"
+#include "CSSFontVariationValue.cpp"
 #include "CSSFunctionValue.cpp"
 #include "CSSGradientValue.cpp"
 #include "CSSGridLineNamesValue.cpp"

Modified: trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp (206678 => 206679)


--- trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/CSSComputedStyleDeclaration.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -36,6 +36,7 @@
 #include "CSSCustomPropertyValue.h"
 #include "CSSFontFeatureValue.h"
 #include "CSSFontValue.h"
+#include "CSSFontVariationValue.h"
 #include "CSSFunctionValue.h"
 #include "CSSLineBoxContainValue.h"
 #include "CSSParser.h"
@@ -62,6 +63,7 @@
 #include "RenderBox.h"
 #include "RenderStyle.h"
 #include "SVGElement.h"
+#include "Settings.h"
 #include "ShapeValue.h"
 #include "StyleInheritedData.h"
 #include "StyleProperties.h"
@@ -2879,6 +2881,18 @@
                 list->append(CSSFontFeatureValue::create(FontTag(feature.tag()), feature.value()));
             return list;
         }
+        case CSSPropertyFontVariationSettings: {
+            if (styledNode->document().settings() && styledNode->document().settings()->variationFontsEnabled()) {
+                const FontVariationSettings& variationSettings = style->fontDescription().variationSettings();
+                if (variationSettings.isEmpty())
+                    return cssValuePool.createIdentifierValue(CSSValueNormal);
+                RefPtr<CSSValueList> list = CSSValueList::createCommaSeparated();
+                for (auto& feature : variationSettings)
+                    list->append(CSSFontVariationValue::create(feature.tag(), feature.value()));
+                return list;
+            }
+            break;
+        }
 #if ENABLE(CSS_GRID_LAYOUT)
         case CSSPropertyGridAutoFlow: {
             RefPtr<CSSValueList> list = CSSValueList::createSpaceSeparated();

Copied: trunk/Source/WebCore/css/CSSFontVariationValue.cpp (from rev 206678, trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp) (0 => 206679)


--- trunk/Source/WebCore/css/CSSFontVariationValue.cpp	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSFontVariationValue.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -0,0 +1,56 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "CSSFontVariationValue.h"
+
+#include <wtf/text/StringBuilder.h>
+
+namespace WebCore {
+
+CSSFontVariationValue::CSSFontVariationValue(FontTag tag, float value)
+    : CSSValue(FontVariationClass)
+    , m_tag(tag)
+    , m_value(value)
+{
+}
+
+String CSSFontVariationValue::customCSSText() const
+{
+    StringBuilder builder;
+    builder.append('\'');
+    for (char c : m_tag)
+        builder.append(c);
+    builder.appendLiteral("' ");
+    builder.appendNumber(m_value);
+    return builder.toString();
+}
+
+bool CSSFontVariationValue::equals(const CSSFontVariationValue& other) const
+{
+    return m_tag == other.m_tag && m_value == other.m_value;
+}
+
+}

Copied: trunk/Source/WebCore/css/CSSFontVariationValue.h (from rev 206678, trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp) (0 => 206679)


--- trunk/Source/WebCore/css/CSSFontVariationValue.h	                        (rev 0)
+++ trunk/Source/WebCore/css/CSSFontVariationValue.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2016 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#pragma once
+
+#include "CSSValue.h"
+#include "FontTaggedSettings.h"
+
+namespace WebCore {
+
+class CSSFontVariationValue final : public CSSValue {
+public:
+    static Ref<CSSFontVariationValue> create(FontTag tag, float value)
+    {
+        return adoptRef(*new CSSFontVariationValue(tag, value));
+    }
+
+    const FontTag& tag() const { return m_tag; }
+    float value() const { return m_value; }
+    String customCSSText() const;
+
+    bool equals(const CSSFontVariationValue&) const;
+
+private:
+    CSSFontVariationValue(FontTag, float);
+
+    FontTag m_tag;
+    const float m_value;
+};
+
+} // namespace WebCore
+
+SPECIALIZE_TYPE_TRAITS_CSS_VALUE(CSSFontVariationValue, isFontVariationValue())

Modified: trunk/Source/WebCore/css/CSSPropertyNames.in (206678 => 206679)


--- trunk/Source/WebCore/css/CSSPropertyNames.in	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/CSSPropertyNames.in	2016-09-30 21:59:15 UTC (rev 206679)
@@ -105,6 +105,7 @@
 font-weight [Inherited, Custom=All]
 text-rendering [Inherited, FontProperty, NameForMethods=TextRenderingMode]
 font-feature-settings [Inherited, FontProperty, Custom=Initial|Inherit, Converter=FontFeatureSettings, NameForMethods=FeatureSettings]
+font-variation-settings [Inherited, FontProperty, Custom=Initial|Inherit, Converter=FontVariationSettings, NameForMethods=VariationSettings]
 -webkit-font-kerning [Inherited, FontProperty, NameForMethods=Kerning]
 font-kerning = -webkit-font-kerning
 -webkit-font-smoothing [Inherited, FontProperty]

Modified: trunk/Source/WebCore/css/CSSValue.cpp (206678 => 206679)


--- trunk/Source/WebCore/css/CSSValue.cpp	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/CSSValue.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -43,6 +43,7 @@
 #include "CSSFontFaceSrcValue.h"
 #include "CSSFontFeatureValue.h"
 #include "CSSFontValue.h"
+#include "CSSFontVariationValue.h"
 #include "CSSFunctionValue.h"
 #include "CSSGradientValue.h"
 #include "CSSImageSetValue.h"
@@ -176,6 +177,8 @@
             return compareCSSValues<CSSFontFaceSrcValue>(*this, other);
         case FontFeatureClass:
             return compareCSSValues<CSSFontFeatureValue>(*this, other);
+        case FontVariationClass:
+            return compareCSSValues<CSSFontVariationValue>(*this, other);
         case FunctionClass:
             return compareCSSValues<CSSFunctionValue>(*this, other);
         case LinearGradientClass:
@@ -282,6 +285,8 @@
         return downcast<CSSFontFaceSrcValue>(*this).customCSSText();
     case FontFeatureClass:
         return downcast<CSSFontFeatureValue>(*this).customCSSText();
+    case FontVariationClass:
+        return downcast<CSSFontVariationValue>(*this).customCSSText();
     case FunctionClass:
         return downcast<CSSFunctionValue>(*this).customCSSText();
     case LinearGradientClass:
@@ -396,6 +401,9 @@
     case FontFeatureClass:
         delete downcast<CSSFontFeatureValue>(this);
         return;
+    case FontVariationClass:
+        delete downcast<CSSFontVariationValue>(this);
+        return;
     case FunctionClass:
         delete downcast<CSSFunctionValue>(this);
         return;

Modified: trunk/Source/WebCore/css/CSSValue.h (206678 => 206679)


--- trunk/Source/WebCore/css/CSSValue.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/CSSValue.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -83,6 +83,7 @@
     bool isVariableValue() const { return m_classType == VariableClass; }
     bool isFunctionValue() const { return m_classType == FunctionClass; }
     bool isFontFeatureValue() const { return m_classType == FontFeatureClass; }
+    bool isFontVariationValue() const { return m_classType == FontVariationClass; }
     bool isFontFaceSrcValue() const { return m_classType == FontFaceSrcClass; }
     bool isFontValue() const { return m_classType == FontClass; }
     bool isImageGeneratorValue() const { return m_classType >= CanvasClass && m_classType <= RadialGradientClass; }
@@ -169,6 +170,7 @@
         AspectRatioClass,
         BorderImageSliceClass,
         FontFeatureClass,
+        FontVariationClass,
         FontClass,
         FontFaceSrcClass,
         FunctionClass,

Modified: trunk/Source/WebCore/css/StyleBuilderConverter.h (206678 => 206679)


--- trunk/Source/WebCore/css/StyleBuilderConverter.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/StyleBuilderConverter.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -31,6 +31,7 @@
 #include "CSSCalculationValue.h"
 #include "CSSContentDistributionValue.h"
 #include "CSSFontFeatureValue.h"
+#include "CSSFontVariationValue.h"
 #include "CSSFunctionValue.h"
 #include "CSSGridAutoRepeatValue.h"
 #include "CSSGridLineNamesValue.h"
@@ -120,6 +121,7 @@
     static bool convertOverflowScrolling(StyleResolver&, CSSValue&);
 #endif
     static FontFeatureSettings convertFontFeatureSettings(StyleResolver&, CSSValue&);
+    static FontVariationSettings convertFontVariationSettings(StyleResolver&, CSSValue&);
     static SVGLength convertSVGLength(StyleResolver&, CSSValue&);
     static Vector<SVGLength> convertSVGLengthVector(StyleResolver&, CSSValue&);
     static Vector<SVGLength> convertStrokeDashArray(StyleResolver&, CSSValue&);
@@ -1144,6 +1146,21 @@
     return settings;
 }
 
+inline FontVariationSettings StyleBuilderConverter::convertFontVariationSettings(StyleResolver&, CSSValue& value)
+{
+    if (is<CSSPrimitiveValue>(value)) {
+        ASSERT(downcast<CSSPrimitiveValue>(value).getValueID() == CSSValueNormal);
+        return { };
+    }
+
+    FontVariationSettings settings;
+    for (auto& item : downcast<CSSValueList>(value)) {
+        auto& feature = downcast<CSSFontVariationValue>(item.get());
+        settings.insert({ feature.tag(), feature.value() });
+    }
+    return settings;
+}
+
 #if PLATFORM(IOS)
 inline bool StyleBuilderConverter::convertTouchCallout(StyleResolver&, CSSValue& value)
 {

Modified: trunk/Source/WebCore/css/StyleBuilderCustom.h (206678 => 206679)


--- trunk/Source/WebCore/css/StyleBuilderCustom.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/StyleBuilderCustom.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -112,6 +112,8 @@
     static void applyInheritWebkitMaskImage(StyleResolver&) { }
     static void applyInitialFontFeatureSettings(StyleResolver&) { }
     static void applyInheritFontFeatureSettings(StyleResolver&) { }
+    static void applyInitialFontVariationSettings(StyleResolver&) { }
+    static void applyInheritFontVariationSettings(StyleResolver&) { }
 
     // Custom handling of inherit + value setting only.
     static void applyInheritDisplay(StyleResolver&);

Modified: trunk/Source/WebCore/css/parser/CSSParser.cpp (206678 => 206679)


--- trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/parser/CSSParser.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -43,6 +43,7 @@
 #include "CSSFontFaceSrcValue.h"
 #include "CSSFontFeatureValue.h"
 #include "CSSFontValue.h"
+#include "CSSFontVariationValue.h"
 #include "CSSFunctionValue.h"
 #include "CSSGradientValue.h"
 #include "CSSImageSetValue.h"
@@ -271,6 +272,7 @@
 #endif
         springTimingFunctionEnabled = settings->springTimingFunctionEnabled();
         useNewParser = settings->newCSSParserEnabled();
+        variationFontsEnabled = settings->variationFontsEnabled();
     }
 
 #if PLATFORM(IOS)
@@ -293,7 +295,8 @@
         && a.needsSiteSpecificQuirks == b.needsSiteSpecificQuirks
         && a.enforcesCSSMIMETypeInNoQuirksMode == b.enforcesCSSMIMETypeInNoQuirksMode
         && a.useLegacyBackgroundSizeShorthandBehavior == b.useLegacyBackgroundSizeShorthandBehavior
-        && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled;
+        && a.springTimingFunctionEnabled == b.springTimingFunctionEnabled
+        && a.variationFontsEnabled == b.variationFontsEnabled;
 }
 
 CSSParser::CSSParser(const CSSParserContext& context)
@@ -2971,6 +2974,14 @@
         else
             return parseFontFeatureSettings(important);
         break;
+    case CSSPropertyFontVariationSettings:
+        if (m_context.variationFontsEnabled) {
+            if (id == CSSValueNormal)
+                validPrimitive = true;
+            else
+                return parseFontVariationSettings(important);
+        }
+        break;
     case CSSPropertyFontVariantLigatures:
         if (id == CSSValueNormal || id == CSSValueNone)
             validPrimitive = true;
@@ -10625,6 +10636,60 @@
     return false;
 }
 
+bool CSSParser::parseFontVariationTag(CSSValueList& settings)
+{
+    CSSParserValue* value = m_valueList->current();
+    // Feature tag name comes first
+    if (value->unit != CSSPrimitiveValue::CSS_STRING)
+        return false;
+    FontTag tag;
+    if (value->string.length() != tag.size())
+        return false;
+    for (unsigned i = 0; i < tag.size(); ++i) {
+        // Limits the range of characters to 0x20-0x7E, following the tag name rules defiend in the OpenType specification.
+        UChar character = value->string[i];
+        if (character < 0x20 || character > 0x7E)
+            return false;
+        tag[i] = toASCIILower(character);
+    }
+
+    value = m_valueList->next();
+    if (!value || value->unit != CSSPrimitiveValue::CSS_NUMBER)
+        return false;
+
+    float tagValue = value->fValue;
+    m_valueList->next();
+
+    settings.append(CSSFontVariationValue::create(tag, tagValue));
+    return true;
+}
+
+bool CSSParser::parseFontVariationSettings(bool important)
+{
+    if (m_valueList->size() == 1 && m_valueList->current()->id == CSSValueNormal) {
+        auto normalValue = CSSValuePool::singleton().createIdentifierValue(CSSValueNormal);
+        m_valueList->next();
+        addProperty(CSSPropertyFontVariationSettings, WTFMove(normalValue), important);
+        return true;
+    }
+
+    auto settings = CSSValueList::createCommaSeparated();
+    for (CSSParserValue* value = m_valueList->current(); value; value = m_valueList->next()) {
+        if (!parseFontVariationTag(settings))
+            return false;
+
+        // If the list isn't parsed fully, the current value should be comma.
+        value = m_valueList->current();
+        if (value && !isComma(value))
+            return false;
+    }
+    if (settings->length()) {
+        addProperty(CSSPropertyFontVariationSettings, WTFMove(settings), important);
+        return true;
+    }
+    return false;
+}
+
 bool CSSParser::parseFontVariantLigatures(bool important, bool unknownIsFailure, bool implicit)
 {
     auto values = CSSValueList::createSpaceSeparated();

Modified: trunk/Source/WebCore/css/parser/CSSParser.h (206678 => 206679)


--- trunk/Source/WebCore/css/parser/CSSParser.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/parser/CSSParser.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -364,6 +364,9 @@
     bool parseFontFeatureTag(CSSValueList&);
     bool parseFontFeatureSettings(bool important);
 
+    bool parseFontVariationTag(CSSValueList&);
+    bool parseFontVariationSettings(bool important);
+
     bool parseFlowThread(CSSPropertyID, bool important);
     bool parseRegionThread(CSSPropertyID, bool important);
 

Modified: trunk/Source/WebCore/css/parser/CSSParserMode.h (206678 => 206679)


--- trunk/Source/WebCore/css/parser/CSSParserMode.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/css/parser/CSSParserMode.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -104,6 +104,7 @@
     bool useLegacyBackgroundSizeShorthandBehavior { false };
     bool springTimingFunctionEnabled { false };
     bool useNewParser { false };
+    bool variationFontsEnabled { false };
 };
 
 bool operator==(const CSSParserContext&, const CSSParserContext&);

Modified: trunk/Source/WebCore/platform/graphics/FontCache.h (206678 => 206679)


--- trunk/Source/WebCore/platform/graphics/FontCache.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/platform/graphics/FontCache.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -76,6 +76,7 @@
         , m_weight(description.weight())
         , m_flags(makeFlagsKey(description))
         , m_featureSettings(description.featureSettings())
+        , m_variationSettings(description.variationSettings())
     { }
 
     explicit FontDescriptionKey(WTF::HashTableDeletedValueType)
@@ -85,7 +86,7 @@
     bool operator==(const FontDescriptionKey& other) const
     {
         return m_size == other.m_size && m_weight == other.m_weight && m_flags == other.m_flags
-            && m_featureSettings == other.m_featureSettings;
+            && m_featureSettings == other.m_featureSettings && m_variationSettings == other.m_variationSettings;
     }
 
     bool operator!=(const FontDescriptionKey& other) const
@@ -103,6 +104,7 @@
         for (unsigned flagItem : m_flags)
             hasher.add(flagItem);
         hasher.add(m_featureSettings.hash());
+        hasher.add(m_variationSettings.hash());
         return hasher.hash();
     }
 
@@ -143,6 +145,7 @@
     unsigned m_weight { 0 };
     std::array<unsigned, 2> m_flags {{ 0, 0 }};
     FontFeatureSettings m_featureSettings;
+    FontVariationSettings m_variationSettings;
 };
 
 struct FontDescriptionKeyHash {

Modified: trunk/Source/WebCore/platform/graphics/FontDescription.cpp (206678 => 206679)


--- trunk/Source/WebCore/platform/graphics/FontDescription.cpp	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -35,7 +35,7 @@
 namespace WebCore {
 
 struct SameSizeAsFontCascadeDescription {
-    Vector<void*> vector;
+    Vector<void*> vector[2];
     AtomicString string;
     float size;
     unsigned bitfields1;

Modified: trunk/Source/WebCore/platform/graphics/FontDescription.h (206678 => 206679)


--- trunk/Source/WebCore/platform/graphics/FontDescription.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/platform/graphics/FontDescription.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -59,6 +59,7 @@
     NonCJKGlyphOrientation nonCJKGlyphOrientation() const { return static_cast<NonCJKGlyphOrientation>(m_nonCJKGlyphOrientation); }
     FontWidthVariant widthVariant() const { return static_cast<FontWidthVariant>(m_widthVariant); }
     const FontFeatureSettings& featureSettings() const { return m_featureSettings; }
+    const FontVariationSettings& variationSettings() const { return m_variationSettings; }
     FontSynthesis fontSynthesis() const { return static_cast<FontSynthesis>(m_fontSynthesis); }
     FontVariantLigatures variantCommonLigatures() const { return static_cast<FontVariantLigatures>(m_variantCommonLigatures); }
     FontVariantLigatures variantDiscretionaryLigatures() const { return static_cast<FontVariantLigatures>(m_variantDiscretionaryLigatures); }
@@ -105,6 +106,7 @@
     void setWidthVariant(FontWidthVariant widthVariant) { m_widthVariant = widthVariant; } // Make sure new callers of this sync with FontPlatformData::isForTextCombine()!
     void setLocale(const AtomicString&);
     void setFeatureSettings(FontFeatureSettings&& settings) { m_featureSettings = WTFMove(settings); }
+    void setVariationSettings(FontVariationSettings&& settings) { m_variationSettings = WTFMove(settings); }
     void setFontSynthesis(FontSynthesis fontSynthesis) { m_fontSynthesis = fontSynthesis; }
     void setVariantCommonLigatures(FontVariantLigatures variant) { m_variantCommonLigatures = static_cast<unsigned>(variant); }
     void setVariantDiscretionaryLigatures(FontVariantLigatures variant) { m_variantDiscretionaryLigatures = static_cast<unsigned>(variant); }
@@ -125,7 +127,9 @@
     FontTraitsMask traitsMask() const;
 
 private:
+    // FIXME: Investigate moving these into their own object on the heap (to save memory).
     FontFeatureSettings m_featureSettings;
+    FontVariationSettings m_variationSettings;
     AtomicString m_locale;
 
     float m_computedSize { 0 }; // Computed size adjusted for the minimum font size and the zoom factor.
@@ -167,6 +171,7 @@
         && m_widthVariant == other.m_widthVariant
         && m_locale == other.m_locale
         && m_featureSettings == other.m_featureSettings
+        && m_variationSettings == other.m_variationSettings
         && m_fontSynthesis == other.m_fontSynthesis
         && m_variantCommonLigatures == other.m_variantCommonLigatures
         && m_variantDiscretionaryLigatures == other.m_variantDiscretionaryLigatures

Modified: trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp (206678 => 206679)


--- trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/platform/graphics/FontTaggedSettings.cpp	2016-09-30 21:59:15 UTC (rev 206679)
@@ -44,4 +44,36 @@
     return hasher.hash();
 }
 
+template <>
+unsigned FontVariationSettings::hash() const
+{
+    static_assert(sizeof(float) == sizeof(int), "IntegerHasher needs to accept floats too");
+    union {
+        float f;
+        int i;
+    } floatToInt;
+
+    IntegerHasher hasher;
+    for (auto& variation : m_list) {
+        hasher.add(FourCharacterTagHash::hash(variation.tag()));
+        floatToInt.f = variation.value();
+        hasher.add(floatToInt.i);
+    }
+    return hasher.hash();
 }
+
+TextStream& operator<<(TextStream& ts, const FontVariationSettings& item)
+{
+    for (unsigned i = 0; i < item.size(); ++i) {
+        auto& variation = item.at(i);
+        StringBuilder s;
+        s.append(variation.tag()[0]);
+        s.append(variation.tag()[1]);
+        s.append(variation.tag()[2]);
+        s.append(variation.tag()[3]);
+        ts.dumpProperty(s.toString(), item.at(i).value());
+    }
+    return ts;
+}
+
+}

Modified: trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h (206678 => 206679)


--- trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h	2016-09-30 21:53:38 UTC (rev 206678)
+++ trunk/Source/WebCore/platform/graphics/FontTaggedSettings.h	2016-09-30 21:59:15 UTC (rev 206679)
@@ -136,5 +136,8 @@
 
 typedef FontTaggedSetting<int> FontFeature;
 typedef FontTaggedSettings<int> FontFeatureSettings;
+typedef FontTaggedSettings<float> FontVariationSettings;
 
+TextStream& operator<<(TextStream&, const FontVariationSettings&);
+
 }
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to