From 3de6f5a887e9da074c3d23d781f3e67cd7241c53 Mon Sep 17 00:00:00 2001 From: Jonathan Kew Date: Mon, 30 Jan 2023 13:27:29 +0000 Subject: [PATCH] style: Avoid redundantly serializing the initial value of font-weight (400) as part of the font shorthand in computed style Differential Revision: https://phabricator.services.mozilla.com/D168250 --- components/style/properties/shorthands/font.mako.rs | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/components/style/properties/shorthands/font.mako.rs b/components/style/properties/shorthands/font.mako.rs index e1c1c270a5e..a202f88012a 100644 --- a/components/style/properties/shorthands/font.mako.rs +++ b/components/style/properties/shorthands/font.mako.rs @@ -39,7 +39,7 @@ use crate::properties::longhands::font_size; use crate::properties::longhands::font_variant_caps; use crate::values::specified::text::LineHeight; - use crate::values::specified::FontSize; + use crate::values::specified::{FontSize, FontWeight}; use crate::values::specified::font::{FontStretch, FontStretchKeyword}; #[cfg(feature = "gecko")] use crate::values::specified::font::SystemFont; @@ -224,13 +224,22 @@ return Ok(()); } - % for name in "style variant_caps weight".split(): + % for name in "style variant_caps".split(): if self.font_${name} != &font_${name}::get_initial_specified_value() { self.font_${name}.to_css(dest)?; dest.write_char(' ')?; } % endfor + // The initial specified font-weight value of 'normal' computes as a number (400), + // not to the keyword, so we need to check for that as well in order to properly + // serialize the computed style. + if self.font_weight != &FontWeight::normal() && + self.font_weight != &FontWeight::from_gecko_keyword(400) { + self.font_weight.to_css(dest)?; + dest.write_char(' ')?; + } + if font_stretch != FontStretchKeyword::Normal { font_stretch.to_css(dest)?; dest.write_char(' ')?;