stylo: System font support for font-weight

This commit is contained in:
Manish Goregaokar 2017-03-21 20:38:12 -07:00 committed by Manish Goregaokar
parent b0dcb72722
commit 5184f29e10
4 changed files with 40 additions and 7 deletions

View file

@ -15,7 +15,7 @@ ALL_SIZES = [(size, False) for size in PHYSICAL_SIZES] + [(size, True) for size
SYSTEM_FONT_LONGHANDS = """font_family font_size font_style
font_variant_caps font_stretch font_kerning
font_variant_position""".split()
font_variant_position font_weight""".split()
def maybe_moz_logical_alias(product, side, prop):
if product == "gecko" and side[1]:

View file

@ -1530,10 +1530,7 @@ fn static_assert() {
${impl_simple_copy('font_weight', 'mFont.weight')}
pub fn clone_font_weight(&self) -> longhands::font_weight::computed_value::T {
debug_assert!(self.gecko.mFont.weight >= 100);
debug_assert!(self.gecko.mFont.weight <= 900);
debug_assert!(self.gecko.mFont.weight % 10 == 0);
unsafe { transmute(self.gecko.mFont.weight) }
unsafe { longhands::font_weight::computed_value::T::from_gecko_weight(self.gecko.mFont.weight) }
}
pub fn set_font_synthesis(&mut self, v: longhands::font_synthesis::computed_value::T) {

View file

@ -310,6 +310,7 @@ ${helpers.single_keyword_system("font-variant-caps",
use std::fmt;
use style_traits::ToCss;
use values::HasViewportPercentage;
use properties::longhands::system_font::SystemFont;
no_viewport_percentage!(SpecifiedValue);
@ -323,6 +324,7 @@ ${helpers.single_keyword_system("font-variant-caps",
% for weight in range(100, 901, 100):
Weight${weight},
% endfor
System(SystemFont),
}
impl ToCss for SpecifiedValue {
@ -335,9 +337,11 @@ ${helpers.single_keyword_system("font-variant-caps",
% for weight in range(100, 901, 100):
SpecifiedValue::Weight${weight} => dest.write_str("${weight}"),
% endfor
SpecifiedValue::System(_) => Ok(())
}
}
}
/// normal | bold | bolder | lighter | 100 | 200 | 300 | 400 | 500 | 600 | 700 | 800 | 900
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
input.try(|input| {
@ -369,6 +373,19 @@ ${helpers.single_keyword_system("font-variant-caps",
}
}
impl SpecifiedValue {
pub fn system_font(f: SystemFont) -> Self {
SpecifiedValue::System(f)
}
pub fn get_system(&self) -> Option<SystemFont> {
if let SpecifiedValue::System(s) = *self {
Some(s)
} else {
None
}
}
}
/// Used in @font-face, where relative keywords are not allowed.
impl Parse for computed_value::T {
fn parse(context: &ParserContext, input: &mut Parser) -> Result<Self, ()> {
@ -379,7 +396,8 @@ ${helpers.single_keyword_system("font-variant-caps",
SpecifiedValue::Normal => Ok(computed_value::T::Weight400),
SpecifiedValue::Bold => Ok(computed_value::T::Weight700),
SpecifiedValue::Bolder |
SpecifiedValue::Lighter => Err(())
SpecifiedValue::Lighter => Err(()),
SpecifiedValue::System(..) => unreachable!(),
}
}
}
@ -403,6 +421,15 @@ ${helpers.single_keyword_system("font-variant-caps",
_ => false
}
}
/// Obtain a Servo computed value from a Gecko computed font-weight
pub unsafe fn from_gecko_weight(weight: u16) -> Self {
use std::mem::transmute;
debug_assert!(weight >= 100);
debug_assert!(weight <= 900);
debug_assert!(weight % 10 == 0);
transmute(weight)
}
}
}
impl ToCss for computed_value::T {
@ -457,6 +484,11 @@ ${helpers.single_keyword_system("font-variant-caps",
computed_value::T::Weight800 => computed_value::T::Weight700,
computed_value::T::Weight900 => computed_value::T::Weight700,
},
SpecifiedValue::System(_) => {
<%self:nongecko_unreachable>
context.style.cached_system_font.as_ref().unwrap().font_weight.clone()
</%self:nongecko_unreachable>
}
}
}
@ -2014,9 +2046,13 @@ ${helpers.single_keyword("-moz-math-variant",
quoted: true
})
}).collect::<Vec<_>>();
let weight = unsafe {
longhands::font_weight::computed_value::T::from_gecko_weight(system.weight)
};
let ret = ComputedSystemFont {
font_family: longhands::font_family::computed_value::T(family),
font_size: Au(system.size),
font_weight: weight,
% for kwprop in kw_font_props:
${kwprop}: longhands::${kwprop}::computed_value::T::from_gecko_keyword(
system.${to_camel_case_lower(kwprop.replace('font_', ''))} as u32

View file

@ -46,7 +46,7 @@
% for name in SYSTEM_FONT_LONGHANDS:
${name}: ${name}::SpecifiedValue::system_font(sys),
% endfor
% for name in gecko_sub_properties + "weight variant_caps stretch".split():
% for name in gecko_sub_properties + "variant_caps stretch".split():
% if "font_" + name not in SYSTEM_FONT_LONGHANDS:
font_${name}: font_${name}::get_initial_specified_value(),
% endif