Commit 42291994 authored by Dominik Röttsches's avatar Dominik Röttsches Committed by Commit Bot

Parse ranges for stretch in @font-face

Allow ranges for font-stretch in @font-face, compare
https://drafts.csswg.org/css-fonts-4/#font-prop-desc

Bug: 749091
Change-Id: I79cafc1f7c496617bfb4eca21e28b4b451bdfae5
Reviewed-on: https://chromium-review.googlesource.com/582862
Commit-Queue: Dominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarmeade_UTC10 <meade@chromium.org>
Reviewed-by: default avatarBugs Nash <bugsnash@chromium.org>
Cr-Commit-Position: refs/heads/master@{#491697}
parent 9e3561e0
...@@ -25,8 +25,8 @@ var styleValidTests = { ...@@ -25,8 +25,8 @@ var styleValidTests = {
}; };
var styleInvalidTests = { var styleInvalidTests = {
'weight': ['100 400'], 'weight': ['100 400', 'calc(0 - 100)', 'calc(200 + 801)'],
'stretch': ['100% 110%', '0%', '100% 150%'] 'stretch': ['100% 110%', '0%', '100% 150%', 'calc(1 + 10%)']
}; };
function testParseStyle() { function testParseStyle() {
...@@ -64,6 +64,9 @@ var faceTests = { ...@@ -64,6 +64,9 @@ var faceTests = {
['100%', '100%'], ['100%', '100%'],
['110%', '110%'], ['110%', '110%'],
['111.5%', '111.5%'], ['111.5%', '111.5%'],
[ "50% 200%", "50% 200%" ],
[ "0.1% 1%", "0.1% 1%" ],
[ "900% 901%", "900% 901%" ],
['ultra-condensed', 'ultra-condensed'], ['ultra-condensed', 'ultra-condensed'],
['ultra-expanded', 'ultra-expanded'], ['ultra-expanded', 'ultra-expanded'],
], ],
...@@ -82,8 +85,8 @@ var faceInvalidTests = { ...@@ -82,8 +85,8 @@ var faceInvalidTests = {
'a b c', 'a b c',
], ],
'stretch': [ 'stretch': [
'0%', '60% 70% 80%', 'a%', 'a b c', '0.1', '-60% 80%', 'ultra-expannnned', '-0.5%', '-1%', '0%', 'calc(0% - 10%)', '60% 70% 80%', 'a%', 'a b c', '0.1',
'50% 0' '-60% 80%', 'ultra-expannnned', '50% 0'
], ],
}; };
......
...@@ -813,7 +813,8 @@ bool CSSPropertyParser::ParseFontFaceDescriptor(CSSPropertyID prop_id) { ...@@ -813,7 +813,8 @@ bool CSSPropertyParser::ParseFontFaceDescriptor(CSSPropertyID prop_id) {
parsed_value = ConsumeFontDisplay(range_); parsed_value = ConsumeFontDisplay(range_);
break; break;
case CSSPropertyFontStretch: case CSSPropertyFontStretch:
parsed_value = CSSPropertyFontUtils::ConsumeFontStretch(range_); parsed_value = CSSPropertyFontUtils::ConsumeFontStretch(
range_, kCSSFontFaceRuleMode);
break; break;
case CSSPropertyFontStyle: case CSSPropertyFontStyle:
parsed_value = CSSPropertyFontUtils::ConsumeFontStyle(range_); parsed_value = CSSPropertyFontUtils::ConsumeFontStyle(range_);
......
...@@ -4,15 +4,16 @@ ...@@ -4,15 +4,16 @@
#include "core/css/properties/CSSPropertyAPIFontStretch.h" #include "core/css/properties/CSSPropertyAPIFontStretch.h"
#include "core/css/parser/CSSParserContext.h"
#include "core/css/properties/CSSPropertyFontUtils.h" #include "core/css/properties/CSSPropertyFontUtils.h"
namespace blink { namespace blink {
const CSSValue* CSSPropertyAPIFontStretch::parseSingleValue( const CSSValue* CSSPropertyAPIFontStretch::parseSingleValue(
CSSParserTokenRange& range, CSSParserTokenRange& range,
const CSSParserContext&, const CSSParserContext& context,
const CSSParserLocalContext&) { const CSSParserLocalContext&) {
return CSSPropertyFontUtils::ConsumeFontStretch(range); return CSSPropertyFontUtils::ConsumeFontStretch(range, context.Mode());
} }
} // namespace blink } // namespace blink
...@@ -126,15 +126,28 @@ static CSSValue* CombineToRangeListOrNull(const CSSPrimitiveValue* range_start, ...@@ -126,15 +126,28 @@ static CSSValue* CombineToRangeListOrNull(const CSSPrimitiveValue* range_start,
return value_list; return value_list;
} }
CSSValue* CSSPropertyFontUtils::ConsumeFontStretch(CSSParserTokenRange& range) { CSSValue* CSSPropertyFontUtils::ConsumeFontStretch(
CSSParserTokenRange& range,
const CSSParserMode& parser_mode) {
CSSIdentifierValue* parsed_keyword = ConsumeFontStretchKeywordOnly(range); CSSIdentifierValue* parsed_keyword = ConsumeFontStretchKeywordOnly(range);
if (parsed_keyword) if (parsed_keyword)
return parsed_keyword; return parsed_keyword;
CSSPrimitiveValue* percent =
CSSPrimitiveValue* start_percent =
CSSPropertyParserHelpers::ConsumePercent(range, kValueRangeNonNegative);
if (!start_percent || start_percent->GetFloatValue() <= 0)
return nullptr;
// In a non-font-face context, more than one percentage is not allowed.
if (parser_mode != kCSSFontFaceRuleMode || range.AtEnd())
return start_percent;
CSSPrimitiveValue* end_percent =
CSSPropertyParserHelpers::ConsumePercent(range, kValueRangeNonNegative); CSSPropertyParserHelpers::ConsumePercent(range, kValueRangeNonNegative);
if (!percent || percent->GetFloatValue() <= 0) if (!end_percent || end_percent->GetFloatValue() <= 0)
return nullptr; return nullptr;
return percent;
return CombineToRangeListOrNull(start_percent, end_percent);
} }
CSSValue* CSSPropertyFontUtils::ConsumeFontWeight( CSSValue* CSSPropertyFontUtils::ConsumeFontWeight(
......
...@@ -35,7 +35,8 @@ class CSSPropertyFontUtils { ...@@ -35,7 +35,8 @@ class CSSPropertyFontUtils {
static CSSIdentifierValue* ConsumeFontStretchKeywordOnly( static CSSIdentifierValue* ConsumeFontStretchKeywordOnly(
CSSParserTokenRange&); CSSParserTokenRange&);
static CSSValue* ConsumeFontStretch(CSSParserTokenRange&); static CSSValue* ConsumeFontStretch(CSSParserTokenRange&,
const CSSParserMode&);
static CSSValue* ConsumeFontStyle(CSSParserTokenRange&); static CSSValue* ConsumeFontStyle(CSSParserTokenRange&);
static CSSValue* ConsumeFontWeight(CSSParserTokenRange&, static CSSValue* ConsumeFontWeight(CSSParserTokenRange&,
const CSSParserMode&); const CSSParserMode&);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment