Commit 3df8b060 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Allow a 'normal' value on font metrics override descriptors to do nothing

Previous implementation only parsed percentage values for these
descriptors, and treated 'normal' as a parse error.

This patch allows descriptors ascent-override, descent-override and
line-gap-override to parse their initial value 'normal' without
triggering a parse error.

Bug: 1098355
Change-Id: I5fc8ddaa0574becf6f8aa21e7c4df6b299f35533
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2415226
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Reviewed-by: default avatarAnders Hartvoll Ruud <andruud@chromium.org>
Cr-Commit-Position: refs/heads/master@{#808537}
parent 61e9caf2
......@@ -100,6 +100,16 @@ CSSFontFace* CreateCSSFontFace(FontFace* font_face,
return MakeGarbageCollected<CSSFontFace>(font_face, ranges);
}
const CSSValue* ConvertFontMetricOverrideValue(const CSSValue* parsed_value) {
if (parsed_value && parsed_value->IsIdentifierValue()) {
// We store the "normal" keyword value as nullptr
DCHECK_EQ(CSSValueID::kNormal,
To<CSSIdentifierValue>(parsed_value)->GetValueID());
return nullptr;
}
return parsed_value;
}
} // namespace
FontFace* FontFace::Create(ExecutionContext* context,
......@@ -362,13 +372,13 @@ bool FontFace::SetPropertyValue(const CSSValue* value,
css_font_face_->SetDisplay(CSSValueToFontDisplay(display_.Get()));
break;
case AtRuleDescriptorID::AscentOverride:
ascent_override_ = value;
ascent_override_ = ConvertFontMetricOverrideValue(value);
break;
case AtRuleDescriptorID::DescentOverride:
descent_override_ = value;
descent_override_ = ConvertFontMetricOverrideValue(value);
break;
case AtRuleDescriptorID::LineGapOverride:
line_gap_override_ = value;
line_gap_override_ = ConvertFontMetricOverrideValue(value);
break;
case AtRuleDescriptorID::AdvanceOverride:
advance_override_ = value;
......
......@@ -195,6 +195,10 @@ CSSValue* ConsumeFontMetricOverride(CSSParserTokenRange& range,
const CSSParserContext& context) {
if (!RuntimeEnabledFeatures::CSSFontMetricsOverrideEnabled())
return nullptr;
if (CSSIdentifierValue* normal =
css_parsing_utils::ConsumeIdent<CSSValueID::kNormal>(range)) {
return normal;
}
return css_parsing_utils::ConsumePercent(range, context,
kValueRangeNonNegative);
}
......
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/4792">
<title>Tests the 'normal' keyword on descriptors ascent-override, descent-override and line-gap-override</title>
<style>
@font-face {
font-family: Ahem;
src: local(Ahem), url(/fonts/Ahem.ttf);
}
</style>
<div style="font-family: Ahem">Test<br>Test</div>
<div style="font-family: Ahem">Test<br>Test</div>
<div style="font-family: Ahem">Test<br>Test</div>
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="author" href="mailto:xiaochengh@chromium.org">
<link rel="help" href="https://github.com/w3c/csswg-drafts/issues/4792">
<link rel="match" href="metrics-override-normal-keyword-ref.html">
<title>Tests the 'normal' keyword on descriptors ascent-override, descent-override and line-gap-override</title>
<style>
@font-face {
font-family: ascent-font;
src: local(Ahem), url(/fonts/Ahem.ttf);
ascent-override: 50%;
ascent-override: normal;
}
@font-face {
font-family: descent-font;
src: local(Ahem), url(/fonts/Ahem.ttf);
descent-override: 50%;
descent-override: normal;
}
@font-face {
font-family: line-gap-font;
src: local(Ahem), url(/fonts/Ahem.ttf);
line-gap-override: 50%;
line-gap-override: normal;
}
</style>
<div style="font-family: ascent-font">Test<br>Test</div>
<div style="font-family: descent-font">Test<br>Test</div>
<div style="font-family: line-gap-font">Test<br>Test</div>
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