mirror of
https://github.com/servo/servo.git
synced 2025-08-07 06:25:32 +01:00
Drop initial values of properties other than font-size and font-family in serialization of canvas font attribute.
According to the canvas spec [1], we must drop initial values other than font-size and font-family when we serialize canvas font attribute. As for font-size and font-family, the default values, '10px sans-serif' [2] are not dropped at all. [1] https://html.spec.whatwg.org/multipage/scripting.html#dom-context-2d-font [2] https://html.spec.whatwg.org/multipage/scripting.html#canvastextdrawingstyles
This commit is contained in:
parent
7330dab51f
commit
e7b777384c
2 changed files with 91 additions and 38 deletions
|
@ -122,8 +122,67 @@
|
|||
SomeSystem,
|
||||
None
|
||||
}
|
||||
% endif
|
||||
enum SerializeFor {
|
||||
Normal,
|
||||
% if product == "gecko":
|
||||
Canvas,
|
||||
% endif
|
||||
}
|
||||
|
||||
impl<'a> LonghandsToSerialize<'a> {
|
||||
impl<'a> LonghandsToSerialize<'a> {
|
||||
fn to_css_for<W>(&self,
|
||||
serialize_for: SerializeFor,
|
||||
dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
% if product == "gecko":
|
||||
match self.check_system() {
|
||||
CheckSystemResult::AllSystem(sys) => return sys.to_css(dest),
|
||||
CheckSystemResult::SomeSystem => return Ok(()),
|
||||
CheckSystemResult::None => ()
|
||||
}
|
||||
% endif
|
||||
|
||||
% if product == "gecko" or data.testing:
|
||||
% for name in gecko_sub_properties:
|
||||
if self.font_${name} != &font_${name}::get_initial_specified_value() {
|
||||
return Ok(());
|
||||
}
|
||||
% endfor
|
||||
% endif
|
||||
|
||||
// In case of serialization for canvas font, we need to drop
|
||||
// initial values of properties other than size and family.
|
||||
% for name in "style variant_caps weight stretch".split():
|
||||
let needs_this_property = match serialize_for {
|
||||
SerializeFor::Normal => true,
|
||||
% if product == "gecko":
|
||||
SerializeFor::Canvas =>
|
||||
self.font_${name} != &font_${name}::get_initial_specified_value(),
|
||||
% endif
|
||||
};
|
||||
if needs_this_property {
|
||||
self.font_${name}.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
}
|
||||
% endfor
|
||||
|
||||
self.font_size.to_css(dest)?;
|
||||
|
||||
match *self.line_height {
|
||||
line_height::SpecifiedValue::Normal => {},
|
||||
_ => {
|
||||
dest.write_str("/")?;
|
||||
self.line_height.to_css(dest)?;
|
||||
}
|
||||
}
|
||||
|
||||
dest.write_str(" ")?;
|
||||
self.font_family.to_css(dest)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
% if product == "gecko":
|
||||
/// Check if some or all members are system fonts
|
||||
fn check_system(&self) -> CheckSystemResult {
|
||||
let mut sys = None;
|
||||
|
@ -148,47 +207,18 @@
|
|||
CheckSystemResult::None
|
||||
}
|
||||
}
|
||||
}
|
||||
% endif
|
||||
|
||||
/// Serialize the shorthand value for canvas font attribute.
|
||||
pub fn to_css_for_canvas<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
self.to_css_for(SerializeFor::Canvas, dest)
|
||||
}
|
||||
% endif
|
||||
}
|
||||
|
||||
// This may be a bit off, unsure, possibly needs changes
|
||||
impl<'a> ToCss for LonghandsToSerialize<'a> {
|
||||
fn to_css<W>(&self, dest: &mut W) -> fmt::Result where W: fmt::Write {
|
||||
% if product == "gecko":
|
||||
match self.check_system() {
|
||||
CheckSystemResult::AllSystem(sys) => return sys.to_css(dest),
|
||||
CheckSystemResult::SomeSystem => return Ok(()),
|
||||
CheckSystemResult::None => ()
|
||||
}
|
||||
% endif
|
||||
|
||||
% if product == "gecko" or data.testing:
|
||||
% for name in gecko_sub_properties:
|
||||
if self.font_${name} != &font_${name}::get_initial_specified_value() {
|
||||
return Ok(());
|
||||
}
|
||||
% endfor
|
||||
% endif
|
||||
|
||||
% for name in "style variant_caps weight stretch".split():
|
||||
self.font_${name}.to_css(dest)?;
|
||||
dest.write_str(" ")?;
|
||||
% endfor
|
||||
|
||||
self.font_size.to_css(dest)?;
|
||||
|
||||
match *self.line_height {
|
||||
line_height::SpecifiedValue::Normal => {},
|
||||
_ => {
|
||||
dest.write_str("/")?;
|
||||
self.line_height.to_css(dest)?;
|
||||
}
|
||||
}
|
||||
|
||||
dest.write_str(" ")?;
|
||||
self.font_family.to_css(dest)?;
|
||||
|
||||
Ok(())
|
||||
self.to_css_for(SerializeFor::Normal, dest)
|
||||
}
|
||||
}
|
||||
</%helpers:shorthand>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue