Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6646,6 +6646,55 @@ mod tests {
..Browsers::default()
},
);

minify_test(
".foo { font: 10px serif; font-variant-numeric: oldstyle-nums; }",
".foo{font:10px serif;font-variant-numeric:oldstyle-nums}",
);
minify_test(
".foo { font-variant-numeric: oldstyle-nums; font: 10px serif; }",
".foo{font:10px serif}",
);
minify_test(
".foo { font: 10px serif; font-variant-numeric: oldstyle-nums; font-variant-alternates: stylistic(my-style); }",
".foo{font:10px serif;font-variant-numeric:oldstyle-nums;font-variant-alternates:stylistic(my-style)}",
);
minify_test(
".foo { font: 10px serif; font-variant: small-caps; }",
".foo{font:10px serif;font-variant:small-caps}",
);
minify_test(
".foo { font-kerning: none; font: 10px serif; }",
".foo{font:10px serif}",
);
minify_test(
".foo { font: 10px serif; font-kerning: none; }",
".foo{font:10px serif;font-kerning:none}",
);
minify_test(
".foo { font-optical-sizing: none; font: 10px serif; }",
".foo{font:10px serif}",
);
minify_test(
".foo { font: 10px serif; font-optical-sizing: none; }",
".foo{font:10px serif;font-optical-sizing:none}",
);
minify_test(
".foo { font-synthesis-style: oblique-only; font: 10px serif; }",
".foo{font:10px serif}",
);
minify_test(
".foo { font: 10px serif; font-synthesis-style: oblique-only; }",
".foo{font:10px serif;font-synthesis-style:oblique-only}",
);
minify_test(
".foo { font-kerning: none; }",
".foo{font-kerning:none}",
);
minify_test(
".foo { font-kerning: none; font: 10px serif; font-optical-sizing: none; }",
".foo{font:10px serif;font-optical-sizing:none}",
);
}

#[test]
Expand Down
20 changes: 20 additions & 0 deletions src/properties/font.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
use std::collections::HashSet;

use super::{Property, PropertyId};
use crate::properties::custom::CustomPropertyName;
use crate::compat::Feature;
use crate::context::PropertyHandlerContext;
use crate::declaration::{DeclarationBlock, DeclarationList};
Expand Down Expand Up @@ -824,6 +825,7 @@ pub(crate) struct FontHandler<'i> {
line_height: Option<LineHeight>,
variant_caps: Option<FontVariantCaps>,
flushed_properties: FontProperty,
longhand_properties: Vec<Property<'i>>,
has_any: bool,
}

Expand Down Expand Up @@ -875,6 +877,7 @@ impl<'i> PropertyHandler<'i> for FontHandler<'i> {
self.stretch = Some(val.stretch.clone());
self.line_height = Some(val.line_height.clone());
self.variant_caps = Some(val.variant_caps.clone());
self.longhand_properties.clear();
self.has_any = true;
// TODO: reset other properties
}
Expand All @@ -885,6 +888,11 @@ impl<'i> PropertyHandler<'i> for FontHandler<'i> {
.insert(FontProperty::try_from(&val.property_id).unwrap());
dest.push(property.clone());
}
Custom(val) if is_longhand_font_property(&val.name) => {
// Store font-variant, font-kerning, font-optical-sizing, font-size-adjust, etc. to ensure they're
// omitted if they precede a `font` shorthand property, and won't be reordered if they follow one
self.longhand_properties.push(property.clone());
}
_ => return false,
}

Expand All @@ -900,6 +908,7 @@ impl<'i> PropertyHandler<'i> for FontHandler<'i> {
impl<'i> FontHandler<'i> {
fn flush(&mut self, decls: &mut DeclarationList<'i>, context: &mut PropertyHandlerContext<'i, '_>) {
if !self.has_any {
decls.extend(self.longhand_properties.drain(..));
return;
}

Expand Down Expand Up @@ -991,6 +1000,8 @@ impl<'i> FontHandler<'i> {
push!(LineHeight, val);
}
}

decls.extend(self.longhand_properties.drain(..));
}
}

Expand Down Expand Up @@ -1032,6 +1043,15 @@ fn compatible_font_family(mut family: Option<Vec<FontFamily>>, is_supported: boo
return family;
}

#[inline]
fn is_longhand_font_property(name: &CustomPropertyName) -> bool {
if let CustomPropertyName::Unknown(name) = name {
name.as_ref().starts_with("font-")
} else {
false
}
}

#[inline]
fn is_font_property(property_id: &PropertyId) -> bool {
match property_id {
Expand Down