Implements parser/serializer for font-synthesis

This commit is contained in:
Rohit Burra 2016-10-28 15:02:15 +05:30
parent 3c16dde1f2
commit 690cf65a85
2 changed files with 80 additions and 1 deletions

View file

@ -765,7 +765,7 @@ fn static_assert() {
</%self:impl_trait>
<%self:impl_trait style_struct_name="Font"
skip_longhands="font-family font-size font-weight"
skip_longhands="font-family font-size font-weight font-synthesis"
skip_additionals="*">
pub fn set_font_family(&mut self, v: longhands::font_family::computed_value::T) {
@ -828,6 +828,22 @@ fn static_assert() {
// This is used for PartialEq, which we don't implement for gecko style structs.
pub fn compute_font_hash(&mut self) {}
pub fn set_font_synthesis(&mut self, v: longhands::font_synthesis::computed_value::T) {
use gecko_bindings::structs::{NS_FONT_SYNTHESIS_WEIGHT, NS_FONT_SYNTHESIS_STYLE};
self.gecko.mFont.synthesis = 0;
if v.weight {
self.gecko.mFont.synthesis |= NS_FONT_SYNTHESIS_WEIGHT as u8;
}
if v.style {
self.gecko.mFont.synthesis |= NS_FONT_SYNTHESIS_STYLE as u8;
}
}
pub fn copy_font_synthesis_from(&mut self, other: &Self) {
self.gecko.mFont.synthesis = other.gecko.mFont.synthesis;
}
</%self:impl_trait>
<% skip_box_longhands= """display overflow-y vertical-align

View file

@ -344,6 +344,69 @@ ${helpers.single_keyword("font-variant",
}
</%helpers:longhand>
<%helpers:longhand products="gecko" name="font-synthesis" animatable="False">
use cssparser::ToCss;
use std::fmt;
use values::LocalToCss;
use values::computed::ComputedValueAsSpecified;
use values::NoViewportPercentage;
impl ComputedValueAsSpecified for SpecifiedValue {}
impl NoViewportPercentage for SpecifiedValue {}
pub mod computed_value {
pub use super::SpecifiedValue as T;
}
#[derive(Debug, Clone, PartialEq)]
#[cfg_attr(feature = "servo", derive(HeapSizeOf))]
pub struct SpecifiedValue {
pub weight: bool,
pub style: bool,
}
impl ToCss for computed_value::T {
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
if self.weight && self.style {
dest.write_str("weight style")
} else if self.style {
dest.write_str("style")
} else if self.weight {
dest.write_str("weight")
} else {
dest.write_str("none")
}
}
}
#[inline]
pub fn get_initial_value() -> computed_value::T {
SpecifiedValue { weight: true, style: true }
}
pub fn parse(_context: &ParserContext, input: &mut Parser) -> Result<SpecifiedValue, ()> {
let mut result = SpecifiedValue { weight: false, style: false };
match_ignore_ascii_case! {try!(input.expect_ident()),
"none" => Ok(result),
"weight" => {
result.weight = true;
if input.try(|input| input.expect_ident_matching("style")).is_ok() {
result.style = true;
}
Ok(result)
},
"style" => {
result.style = true;
if input.try(|input| input.expect_ident_matching("weight")).is_ok() {
result.weight = true;
}
Ok(result)
},
_ => Err(())
}
}
</%helpers:longhand>
// FIXME: This prop should be animatable
${helpers.single_keyword("font-stretch",
"normal ultra-condensed extra-condensed condensed \