Auto merge of #20187 - emilio:font-optical-sizing, r=emilio

style: Add font-optical-sizing property.

Patch by Jonathan Kew <jkew@mozilla.com>.

Bug: 1435692
Reviewed-by: emilio

<!-- 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/20187)
<!-- Reviewable:end -->
This commit is contained in:
bors-servo 2018-03-03 15:10:30 -05:00 committed by GitHub
commit df079286c2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 2188 additions and 1246 deletions

File diff suppressed because it is too large Load diff

View file

@ -19,7 +19,7 @@ SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
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):

View file

@ -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",
@ -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",
@ -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 {

View file

@ -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 ''}
@ -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:
@ -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
@ -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