Commit b80faef6 authored by Xiaocheng Hu's avatar Xiaocheng Hu Committed by Commit Bot

Introduce letter-spacing-override descriptor for @font-face (1/2)

Design doc: https://bit.ly/39qATQ4

This patch adds a new @font-face descriptor to override spacing between
characters when the font is used.

For simplicity, this patch only implements the parsing of the
descriptor, but doesn't affect any rendering. A follow up patch
(crrev.com/c/2318510) will apply it in text shaping.

Note: Though we don't have a stable spec at the moment, we land
it behind a flag to make testing and discussion easier.

Bug: 1098355
Change-Id: I7921aad0d03e0b7da0c2fca77c99324ab7449e2b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2335823Reviewed-by: default avatarDominik Röttsches <drott@chromium.org>
Reviewed-by: default avatarChris Harrelson <chrishtr@chromium.org>
Reviewed-by: default avatarRune Lillesveen <futhark@chromium.org>
Commit-Queue: Xiaocheng Hu <xiaochengh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#794696}
parent eb091c7e
...@@ -717,6 +717,7 @@ enum CSSSampleId { ...@@ -717,6 +717,7 @@ enum CSSSampleId {
kScrollbarGutter = 671, kScrollbarGutter = 671,
kAscentOverride = 672, kAscentOverride = 672,
kDescentOverride = 673, kDescentOverride = 673,
kLetterSpacingOverride = 674,
// 1. Add new features above this line (don't change the assigned numbers of // 1. Add new features above this line (don't change the assigned numbers of
// the existing items). // the existing items).
// 2. Run the src/tools/metrics/histograms/update_use_counter_css.py script // 2. Run the src/tools/metrics/histograms/update_use_counter_css.py script
......
...@@ -5133,6 +5133,12 @@ ...@@ -5133,6 +5133,12 @@
is_property: false, is_property: false,
runtime_flag: "CSSFontMetricsOverride", runtime_flag: "CSSFontMetricsOverride",
}, },
{
name: "letter-spacing-override",
is_descriptor: true,
is_property: false,
runtime_flag: "CSSFontMetricsOverride",
},
// Shorthands // Shorthands
{ {
......
...@@ -195,6 +195,8 @@ FontFace* FontFace::Create(Document* document, ...@@ -195,6 +195,8 @@ FontFace* FontFace::Create(Document* document,
AtRuleDescriptorID::AscentOverride) && AtRuleDescriptorID::AscentOverride) &&
font_face->SetPropertyFromStyle(properties, font_face->SetPropertyFromStyle(properties,
AtRuleDescriptorID::DescentOverride) && AtRuleDescriptorID::DescentOverride) &&
font_face->SetPropertyFromStyle(
properties, AtRuleDescriptorID::LetterSpacingOverride) &&
font_face->GetFontSelectionCapabilities().IsValid() && font_face->GetFontSelectionCapabilities().IsValid() &&
!font_face->family().IsEmpty()) { !font_face->family().IsEmpty()) {
font_face->InitCSSFontFace(document->GetExecutionContext(), *src); font_face->InitCSSFontFace(document->GetExecutionContext(), *src);
...@@ -363,6 +365,9 @@ bool FontFace::SetPropertyValue(const CSSValue* value, ...@@ -363,6 +365,9 @@ bool FontFace::SetPropertyValue(const CSSValue* value,
case AtRuleDescriptorID::DescentOverride: case AtRuleDescriptorID::DescentOverride:
descent_override_ = value; descent_override_ = value;
break; break;
case AtRuleDescriptorID::LetterSpacingOverride:
letter_spacing_override_ = value;
break;
default: default:
NOTREACHED(); NOTREACHED();
return false; return false;
...@@ -806,6 +811,7 @@ void FontFace::Trace(Visitor* visitor) const { ...@@ -806,6 +811,7 @@ void FontFace::Trace(Visitor* visitor) const {
visitor->Trace(display_); visitor->Trace(display_);
visitor->Trace(ascent_override_); visitor->Trace(ascent_override_);
visitor->Trace(descent_override_); visitor->Trace(descent_override_);
visitor->Trace(letter_spacing_override_);
visitor->Trace(error_); visitor->Trace(error_);
visitor->Trace(loaded_property_); visitor->Trace(loaded_property_);
visitor->Trace(css_font_face_); visitor->Trace(css_font_face_);
...@@ -843,6 +849,10 @@ FontMetricsOverride FontFace::GetFontMetricsOverride() const { ...@@ -843,6 +849,10 @@ FontMetricsOverride FontFace::GetFontMetricsOverride() const {
result.descent_override = result.descent_override =
To<CSSPrimitiveValue>(*descent_override_).GetFloatValue() / 100; To<CSSPrimitiveValue>(*descent_override_).GetFloatValue() / 100;
} }
if (letter_spacing_override_) {
result.letter_spacing_override =
To<CSSPrimitiveValue>(*letter_spacing_override_).GetFloatValue();
}
return result; return result;
} }
......
...@@ -135,7 +135,7 @@ class CORE_EXPORT FontFace : public ScriptWrappable, ...@@ -135,7 +135,7 @@ class CORE_EXPORT FontFace : public ScriptWrappable,
bool HasPendingActivity() const final; bool HasPendingActivity() const final;
bool HasFontMetricsOverride() const { bool HasFontMetricsOverride() const {
return ascent_override_ || descent_override_; return ascent_override_ || descent_override_ || letter_spacing_override_;
} }
FontMetricsOverride GetFontMetricsOverride() const; FontMetricsOverride GetFontMetricsOverride() const;
...@@ -179,6 +179,7 @@ class CORE_EXPORT FontFace : public ScriptWrappable, ...@@ -179,6 +179,7 @@ class CORE_EXPORT FontFace : public ScriptWrappable,
Member<const CSSValue> display_; Member<const CSSValue> display_;
Member<const CSSValue> ascent_override_; Member<const CSSValue> ascent_override_;
Member<const CSSValue> descent_override_; Member<const CSSValue> descent_override_;
Member<const CSSValue> letter_spacing_override_;
LoadStatusType status_; LoadStatusType status_;
Member<DOMException> error_; Member<DOMException> error_;
......
...@@ -208,6 +208,13 @@ CSSValue* ConsumeFontMetricOverride(CSSParserTokenRange& range, ...@@ -208,6 +208,13 @@ CSSValue* ConsumeFontMetricOverride(CSSParserTokenRange& range,
kValueRangeNonNegative); kValueRangeNonNegative);
} }
CSSValue* ConsumeLetterSpacingOverride(CSSParserTokenRange& range,
const CSSParserContext& context) {
if (!RuntimeEnabledFeatures::CSSFontMetricsOverrideEnabled())
return nullptr;
return css_parsing_utils::ConsumeNumber(range, context, kValueRangeAll);
}
} // namespace } // namespace
CSSValue* AtRuleDescriptorParser::ParseFontFaceDescriptor( CSSValue* AtRuleDescriptorParser::ParseFontFaceDescriptor(
...@@ -261,6 +268,9 @@ CSSValue* AtRuleDescriptorParser::ParseFontFaceDescriptor( ...@@ -261,6 +268,9 @@ CSSValue* AtRuleDescriptorParser::ParseFontFaceDescriptor(
case AtRuleDescriptorID::DescentOverride: case AtRuleDescriptorID::DescentOverride:
parsed_value = ConsumeFontMetricOverride(range, context); parsed_value = ConsumeFontMetricOverride(range, context);
break; break;
case AtRuleDescriptorID::LetterSpacingOverride:
parsed_value = ConsumeLetterSpacingOverride(range, context);
break;
default: default:
break; break;
} }
......
...@@ -54,6 +54,9 @@ ...@@ -54,6 +54,9 @@
{ {
name: "initial-value" name: "initial-value"
}, },
{
name: "letter-spacing-override"
},
{ {
name: "max-height", name: "max-height",
}, },
......
...@@ -12,6 +12,7 @@ namespace blink { ...@@ -12,6 +12,7 @@ namespace blink {
struct FontMetricsOverride { struct FontMetricsOverride {
base::Optional<float> ascent_override; base::Optional<float> ascent_override;
base::Optional<float> descent_override; base::Optional<float> descent_override;
base::Optional<float> letter_spacing_override;
}; };
} // namespace blink } // namespace blink
......
...@@ -213,6 +213,7 @@ justifySelf ...@@ -213,6 +213,7 @@ justifySelf
left left
length length
letterSpacing letterSpacing
letterSpacingOverride
lightingColor lightingColor
lineBreak lineBreak
lineHeight lineHeight
......
...@@ -45259,6 +45259,7 @@ Called by update_use_counter_css.py.--> ...@@ -45259,6 +45259,7 @@ Called by update_use_counter_css.py.-->
<int value="671" label="scrollbar-gutter"/> <int value="671" label="scrollbar-gutter"/>
<int value="672" label="ascent-override"/> <int value="672" label="ascent-override"/>
<int value="673" label="descent-override"/> <int value="673" label="descent-override"/>
<int value="674" label="letter-spacing-override"/>
</enum> </enum>
<enum name="MappedEditingCommands"> <enum name="MappedEditingCommands">
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