Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
style: Add font-optical-sizing property.
Bug: 1435692
Reviewed-by: emilio
  • Loading branch information
jfkthame authored and emilio committed Mar 3, 2018
1 parent 5bfd74e commit 93b7d01
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 23 deletions.
2 changes: 1 addition & 1 deletion components/style/properties/data.py
Expand Up @@ -19,7 +19,7 @@
font_size_adjust font_variant_alternates
font_variant_ligatures font_variant_east_asian
font_variant_numeric font_language_override
font_feature_settings""".split()
font_feature_settings font_optical_sizing""".split()


def maybe_moz_logical_alias(product, side, prop):
Expand Down
35 changes: 24 additions & 11 deletions components/style/properties/longhand/font.mako.rs
Expand Up @@ -15,15 +15,16 @@ ${helpers.predefined_type("font-family",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-family",
servo_restyle_damage="rebuild_and_reflow")}

${helpers.single_keyword_system("font-style",
"normal italic oblique",
gecko_constant_prefix="NS_FONT_STYLE",
gecko_ffi_name="mFont.style",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-style",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete",
servo_restyle_damage="rebuild_and_reflow")}

${helpers.single_keyword_system(
"font-style",
"normal italic oblique",
gecko_constant_prefix="NS_FONT_STYLE",
gecko_ffi_name="mFont.style",
spec="https://drafts.csswg.org/css-fonts/#propdef-font-style",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
animation_value_type="discrete",
servo_restyle_damage="rebuild_and_reflow"
)}

<% font_variant_caps_custom_consts= { "small-caps": "SMALLCAPS",
"all-small-caps": "ALLSMALL",
Expand Down Expand Up @@ -180,6 +181,16 @@ ${helpers.predefined_type("font-language-override",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://drafts.csswg.org/css-fonts-3/#propdef-font-language-override")}

${helpers.single_keyword_system("font-optical-sizing",
"auto none",
products="gecko",
gecko_pref="layout.css.font-variations.enabled",
gecko_ffi_name="mFont.opticalSizing",
gecko_constant_prefix="NS_FONT_OPTICAL_SIZING",
animation_value_type="discrete",
flags="APPLIES_TO_FIRST_LETTER APPLIES_TO_FIRST_LINE APPLIES_TO_PLACEHOLDER",
spec="https://www.w3.org/TR/css-fonts-4/#font-optical-sizing-def")}

${helpers.predefined_type("-x-lang",
"XLang",
products="gecko",
Expand Down Expand Up @@ -278,9 +289,11 @@ ${helpers.predefined_type("-x-text-zoom",
-moz-list -moz-field""".split()
kw_font_props = """font_style font_variant_caps font_stretch
font_kerning font_variant_position font_variant_ligatures
font_variant_east_asian font_variant_numeric""".split()
font_variant_east_asian font_variant_numeric
font_optical_sizing""".split()
kw_cast = """font_style font_variant_caps font_stretch
font_kerning font_variant_position""".split()
font_kerning font_variant_position
font_optical_sizing""".split()
%>
#[derive(Clone, Copy, Debug, Eq, Hash, MallocSizeOf, PartialEq, ToCss)]
pub enum SystemFont {
Expand Down
42 changes: 31 additions & 11 deletions components/style/properties/shorthand/font.mako.rs
Expand Up @@ -10,6 +10,7 @@
font-size line-height font-family
${'font-size-adjust' if product == 'gecko' else ''}
${'font-kerning' if product == 'gecko' else ''}
${'font-optical-sizing' if product == 'gecko' else ''}
${'font-variant-alternates' if product == 'gecko' else ''}
${'font-variant-east-asian' if product == 'gecko' else ''}
${'font-variant-ligatures' if product == 'gecko' else ''}
Expand All @@ -30,7 +31,8 @@
gecko_sub_properties = "kerning language_override size_adjust \
variant_alternates variant_east_asian \
variant_ligatures variant_numeric \
variant_position feature_settings".split()
variant_position feature_settings \
optical_sizing".split()
%>
% if product == "gecko":
% for prop in gecko_sub_properties:
Expand Down Expand Up @@ -155,11 +157,19 @@
% endif

% if product == "gecko":
% for name in gecko_sub_properties:
if self.font_${name} != &font_${name}::get_initial_specified_value() {
return Ok(());
}
% endfor
if let Some(v) = self.font_optical_sizing {
if v != &font_optical_sizing::get_initial_specified_value() {
return Ok(());
}
}

% for name in gecko_sub_properties:
% if name != "optical_sizing":
if self.font_${name} != &font_${name}::get_initial_specified_value() {
return Ok(());
}
% endif
% endfor
% endif

// In case of serialization for canvas font, we need to drop
Expand Down Expand Up @@ -193,12 +203,22 @@
let mut all = true;
% for prop in SYSTEM_FONT_LONGHANDS:
if let Some(s) = self.${prop}.get_system() {
debug_assert!(sys.is_none() || s == sys.unwrap());
sys = Some(s);
} else {
all = false;
% if prop == "font_optical_sizing":
if let Some(value) = self.${prop} {
% else:
{
let value = self.${prop};
% endif
match value.get_system() {
Some(s) => {
debug_assert!(sys.is_none() || s == sys.unwrap());
sys = Some(s);
}
None => {
all = false;
}
}
}
% endfor
if self.line_height != &LineHeight::normal() {
all = false
Expand Down

0 comments on commit 93b7d01

Please sign in to comment.