mirror of
https://github.com/servo/servo.git
synced 2025-06-21 15:49:04 +01:00
Auto merge of #20191 - jfkthame:font-shorthand-resets-variation-settings, r=emilio
style: Make 'font' shorthand reset 'font-variation-settings' property As required by the spec: https://drafts.csswg.org/css-fonts-4/#font-prop See https://bugzilla.mozilla.org/show_bug.cgi?id=1435983 Basically, make font-variation-settings work in the same way as font-feature-settings already does. - [X] `./mach build -d` does not report any errors - [X] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). - [ ] There are tests for these changes OR - [X] These changes do not require tests because font-variation-settings isn't supported in servo; it is implemented here for gecko/stylo, and will be tested by mozilla-central mochitests. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/20191) <!-- Reviewable:end -->
This commit is contained in:
commit
1783e41f34
8 changed files with 87 additions and 14 deletions
|
@ -26,7 +26,7 @@ use style_traits::{Comma, CssWriter, OneOrMoreSeparated, ParseError};
|
||||||
use style_traits::{StyleParseErrorKind, ToCss};
|
use style_traits::{StyleParseErrorKind, ToCss};
|
||||||
use values::computed::font::FamilyName;
|
use values::computed::font::FamilyName;
|
||||||
#[cfg(feature = "gecko")]
|
#[cfg(feature = "gecko")]
|
||||||
use values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
|
use values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
|
||||||
use values::specified::url::SpecifiedUrl;
|
use values::specified::url::SpecifiedUrl;
|
||||||
|
|
||||||
/// A source for a font-face rule.
|
/// A source for a font-face rule.
|
||||||
|
@ -397,7 +397,7 @@ font_face_descriptors! {
|
||||||
"font-feature-settings" feature_settings / mFontFeatureSettings: SpecifiedFontFeatureSettings,
|
"font-feature-settings" feature_settings / mFontFeatureSettings: SpecifiedFontFeatureSettings,
|
||||||
|
|
||||||
/// The variation settings of this font face.
|
/// The variation settings of this font face.
|
||||||
"font-variation-settings" variation_settings / mFontVariationSettings: FontVariationSettings,
|
"font-variation-settings" variation_settings / mFontVariationSettings: SpecifiedFontVariationSettings,
|
||||||
|
|
||||||
/// The language override of this font face.
|
/// The language override of this font face.
|
||||||
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue,
|
"font-language-override" language_override / mFontLanguageOverride: font_language_override::SpecifiedValue,
|
||||||
|
|
|
@ -22,7 +22,7 @@ use std::str;
|
||||||
use str::CssStringWriter;
|
use str::CssStringWriter;
|
||||||
use values::computed::font::FamilyName;
|
use values::computed::font::FamilyName;
|
||||||
use values::generics::font::FontTag;
|
use values::generics::font::FontTag;
|
||||||
use values::specified::font::{FontVariationSettings, SpecifiedFontFeatureSettings};
|
use values::specified::font::{SpecifiedFontVariationSettings, SpecifiedFontFeatureSettings};
|
||||||
|
|
||||||
/// A @font-face rule
|
/// A @font-face rule
|
||||||
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
pub type FontFaceRule = RefPtr<nsCSSFontFaceRule>;
|
||||||
|
@ -74,7 +74,7 @@ impl ToNsCssValue for SpecifiedFontFeatureSettings {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ToNsCssValue for FontVariationSettings {
|
impl ToNsCssValue for SpecifiedFontVariationSettings {
|
||||||
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
fn convert(self, nscssvalue: &mut nsCSSValue) {
|
||||||
if self.0.is_empty() {
|
if self.0.is_empty() {
|
||||||
nscssvalue.set_normal();
|
nscssvalue.set_normal();
|
||||||
|
|
|
@ -19,7 +19,8 @@ SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
|
||||||
font_size_adjust font_variant_alternates
|
font_size_adjust font_variant_alternates
|
||||||
font_variant_ligatures font_variant_east_asian
|
font_variant_ligatures font_variant_east_asian
|
||||||
font_variant_numeric font_language_override
|
font_variant_numeric font_language_override
|
||||||
font_feature_settings font_optical_sizing""".split()
|
font_feature_settings font_variation_settings
|
||||||
|
font_optical_sizing""".split()
|
||||||
|
|
||||||
|
|
||||||
def maybe_moz_logical_alias(product, side, prop):
|
def maybe_moz_logical_alias(product, side, prop):
|
||||||
|
|
|
@ -167,6 +167,7 @@ ${helpers.predefined_type("font-variation-settings",
|
||||||
products="gecko",
|
products="gecko",
|
||||||
gecko_pref="layout.css.font-variations.enabled",
|
gecko_pref="layout.css.font-variations.enabled",
|
||||||
initial_value="computed::FontVariationSettings::normal()",
|
initial_value="computed::FontVariationSettings::normal()",
|
||||||
|
initial_specified_value="specified::FontVariationSettings::normal()",
|
||||||
animation_value_type="ComputedValue",
|
animation_value_type="ComputedValue",
|
||||||
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
|
||||||
spec="${variation_spec}")}
|
spec="${variation_spec}")}
|
||||||
|
@ -371,6 +372,7 @@ ${helpers.predefined_type("-x-text-zoom",
|
||||||
font_language_override: longhands::font_language_override::computed_value
|
font_language_override: longhands::font_language_override::computed_value
|
||||||
::T(system.languageOverride),
|
::T(system.languageOverride),
|
||||||
font_feature_settings: longhands::font_feature_settings::get_initial_value(),
|
font_feature_settings: longhands::font_feature_settings::get_initial_value(),
|
||||||
|
font_variation_settings: longhands::font_variation_settings::get_initial_value(),
|
||||||
font_variant_alternates: longhands::font_variant_alternates::get_initial_value(),
|
font_variant_alternates: longhands::font_variant_alternates::get_initial_value(),
|
||||||
system_font: *self,
|
system_font: *self,
|
||||||
default_font_type: system.fontlist.mDefaultFontType,
|
default_font_type: system.fontlist.mDefaultFontType,
|
||||||
|
|
|
@ -17,7 +17,8 @@
|
||||||
${'font-variant-numeric' if product == 'gecko' else ''}
|
${'font-variant-numeric' if product == 'gecko' else ''}
|
||||||
${'font-variant-position' if product == 'gecko' else ''}
|
${'font-variant-position' if product == 'gecko' else ''}
|
||||||
${'font-language-override' if product == 'gecko' else ''}
|
${'font-language-override' if product == 'gecko' else ''}
|
||||||
${'font-feature-settings' if product == 'gecko' else ''}"
|
${'font-feature-settings' if product == 'gecko' else ''}
|
||||||
|
${'font-variation-settings' if product == 'gecko' else ''}"
|
||||||
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
|
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font">
|
||||||
use parser::Parse;
|
use parser::Parse;
|
||||||
use properties::longhands::{font_family, font_style, font_weight, font_stretch};
|
use properties::longhands::{font_family, font_style, font_weight, font_stretch};
|
||||||
|
@ -32,7 +33,7 @@
|
||||||
variant_alternates variant_east_asian \
|
variant_alternates variant_east_asian \
|
||||||
variant_ligatures variant_numeric \
|
variant_ligatures variant_numeric \
|
||||||
variant_position feature_settings \
|
variant_position feature_settings \
|
||||||
optical_sizing".split()
|
variation_settings optical_sizing".split()
|
||||||
%>
|
%>
|
||||||
% if product == "gecko":
|
% if product == "gecko":
|
||||||
% for prop in gecko_sub_properties:
|
% for prop in gecko_sub_properties:
|
||||||
|
@ -162,9 +163,14 @@
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if let Some(v) = self.font_variation_settings {
|
||||||
|
if v != &font_variation_settings::get_initial_specified_value() {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
% for name in gecko_sub_properties:
|
% for name in gecko_sub_properties:
|
||||||
% if name != "optical_sizing":
|
% if name != "optical_sizing" and name != "variation_settings":
|
||||||
if self.font_${name} != &font_${name}::get_initial_specified_value() {
|
if self.font_${name} != &font_${name}::get_initial_specified_value() {
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
@ -203,7 +209,7 @@
|
||||||
let mut all = true;
|
let mut all = true;
|
||||||
|
|
||||||
% for prop in SYSTEM_FONT_LONGHANDS:
|
% for prop in SYSTEM_FONT_LONGHANDS:
|
||||||
% if prop == "font_optical_sizing":
|
% if prop == "font_optical_sizing" or prop == "font_variation_settings":
|
||||||
if let Some(value) = self.${prop} {
|
if let Some(value) = self.${prop} {
|
||||||
% else:
|
% else:
|
||||||
{
|
{
|
||||||
|
|
|
@ -1653,7 +1653,7 @@ impl Parse for FontVariantNumeric {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This property provides low-level control over OpenType or TrueType font variations.
|
/// This property provides low-level control over OpenType or TrueType font features.
|
||||||
pub type SpecifiedFontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;
|
pub type SpecifiedFontFeatureSettings = FontSettings<FeatureTagValue<Integer>>;
|
||||||
|
|
||||||
/// Define initial settings that apply when the font defined by an @font-face
|
/// Define initial settings that apply when the font defined by an @font-face
|
||||||
|
@ -1910,7 +1910,71 @@ impl Parse for FontLanguageOverride {
|
||||||
|
|
||||||
/// This property provides low-level control over OpenType or TrueType font
|
/// This property provides low-level control over OpenType or TrueType font
|
||||||
/// variations.
|
/// variations.
|
||||||
pub type FontVariationSettings = FontSettings<VariationValue<Number>>;
|
pub type SpecifiedFontVariationSettings = FontSettings<VariationValue<Number>>;
|
||||||
|
|
||||||
|
/// Define initial settings that apply when the font defined by an @font-face
|
||||||
|
/// rule is rendered.
|
||||||
|
#[derive(Clone, Debug, MallocSizeOf, PartialEq, ToCss)]
|
||||||
|
pub enum FontVariationSettings {
|
||||||
|
/// Value of `FontSettings`
|
||||||
|
Value(SpecifiedFontVariationSettings),
|
||||||
|
/// System font
|
||||||
|
System(SystemFont)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FontVariationSettings {
|
||||||
|
#[inline]
|
||||||
|
/// Get default value of `font-variation-settings` as normal
|
||||||
|
pub fn normal() -> FontVariationSettings {
|
||||||
|
FontVariationSettings::Value(FontSettings::normal())
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get `font-variation-settings` with system font
|
||||||
|
pub fn system_font(f: SystemFont) -> Self {
|
||||||
|
FontVariationSettings::System(f)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Get system font
|
||||||
|
pub fn get_system(&self) -> Option<SystemFont> {
|
||||||
|
if let FontVariationSettings::System(s) = *self {
|
||||||
|
Some(s)
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ToComputedValue for FontVariationSettings {
|
||||||
|
type ComputedValue = computed::FontVariationSettings;
|
||||||
|
|
||||||
|
fn to_computed_value(&self, context: &Context) -> computed::FontVariationSettings {
|
||||||
|
match *self {
|
||||||
|
FontVariationSettings::Value(ref v) => v.to_computed_value(context),
|
||||||
|
FontVariationSettings::System(_) => {
|
||||||
|
#[cfg(feature = "gecko")] {
|
||||||
|
context.cached_system_font.as_ref().unwrap().font_variation_settings.clone()
|
||||||
|
}
|
||||||
|
#[cfg(feature = "servo")] {
|
||||||
|
unreachable!()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn from_computed_value(other: &computed::FontVariationSettings) -> Self {
|
||||||
|
FontVariationSettings::Value(ToComputedValue::from_computed_value(other))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Parse for FontVariationSettings {
|
||||||
|
/// normal | <variation-tag-value>#
|
||||||
|
fn parse<'i, 't>(
|
||||||
|
context: &ParserContext,
|
||||||
|
input: &mut Parser<'i, 't>
|
||||||
|
) -> Result<FontVariationSettings, ParseError<'i>> {
|
||||||
|
SpecifiedFontVariationSettings::parse(context, input).map(FontVariationSettings::Value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn parse_one_feature_value<'i, 't>(
|
fn parse_one_feature_value<'i, 't>(
|
||||||
context: &ParserContext,
|
context: &ParserContext,
|
||||||
|
|
|
@ -4857,7 +4857,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
|
||||||
use style::font_face::{FontDisplay, FontWeight, Source};
|
use style::font_face::{FontDisplay, FontWeight, Source};
|
||||||
use style::properties::longhands::font_language_override;
|
use style::properties::longhands::font_language_override;
|
||||||
use style::values::computed::font::FamilyName;
|
use style::values::computed::font::FamilyName;
|
||||||
use style::values::specified::font::{SpecifiedFontFeatureSettings, FontVariationSettings};
|
use style::values::specified::font::{SpecifiedFontFeatureSettings, SpecifiedFontVariationSettings};
|
||||||
|
|
||||||
let string = unsafe { (*value).to_string() };
|
let string = unsafe { (*value).to_string() };
|
||||||
let mut input = ParserInput::new(&string);
|
let mut input = ParserInput::new(&string);
|
||||||
|
@ -4907,7 +4907,7 @@ pub extern "C" fn Servo_ParseFontDescriptor(
|
||||||
eCSSFontDesc_Src / Vec<Source>,
|
eCSSFontDesc_Src / Vec<Source>,
|
||||||
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
|
eCSSFontDesc_UnicodeRange / Vec<UnicodeRange>,
|
||||||
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
|
eCSSFontDesc_FontFeatureSettings / SpecifiedFontFeatureSettings,
|
||||||
eCSSFontDesc_FontVariationSettings / FontVariationSettings,
|
eCSSFontDesc_FontVariationSettings / SpecifiedFontVariationSettings,
|
||||||
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
|
eCSSFontDesc_FontLanguageOverride / font_language_override::SpecifiedValue,
|
||||||
eCSSFontDesc_Display / FontDisplay,
|
eCSSFontDesc_Display / FontDisplay,
|
||||||
]
|
]
|
||||||
|
|
|
@ -40,7 +40,7 @@ size_of_test!(test_size_of_rule_node, RuleNode, 80);
|
||||||
|
|
||||||
// This is huge, but we allocate it on the stack and then never move it,
|
// This is huge, but we allocate it on the stack and then never move it,
|
||||||
// we only pass `&mut SourcePropertyDeclaration` references around.
|
// we only pass `&mut SourcePropertyDeclaration` references around.
|
||||||
size_of_test!(test_size_of_parsed_declaration, style::properties::SourcePropertyDeclaration, 576);
|
size_of_test!(test_size_of_parsed_declaration, style::properties::SourcePropertyDeclaration, 608);
|
||||||
|
|
||||||
size_of_test!(test_size_of_computed_image, computed::image::Image, 40);
|
size_of_test!(test_size_of_computed_image, computed::image::Image, 40);
|
||||||
size_of_test!(test_size_of_specified_image, specified::image::Image, 40);
|
size_of_test!(test_size_of_specified_image, specified::image::Image, 40);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue