Skip to content

Commit 69ee0dd

Browse files
committed
Fix font
1 parent 4ec4020 commit 69ee0dd

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

src/lib.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2053,6 +2053,19 @@ mod tests {
20532053
"#
20542054
});
20552055

2056+
test(r#"
2057+
.foo {
2058+
font: 12px "Helvetica", "Times New Roman", sans-serif;
2059+
line-height: var(--lh);
2060+
}
2061+
"#, indoc! {r#"
2062+
.foo {
2063+
font: 12px Helvetica, Times New Roman, sans-serif;
2064+
line-height: var(--lh);
2065+
}
2066+
"#
2067+
});
2068+
20562069
minify_test(r#"
20572070
.foo {
20582071
font-family: "Helvetica", "Times New Roman", sans-serif;

src/properties/font.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::values::{
66
percentage::Percentage
77
};
88
use crate::traits::{Parse, ToCss, PropertyHandler};
9-
use super::Property;
9+
use super::{Property, PropertyId};
1010
use crate::declaration::DeclarationList;
1111
use crate::printer::Printer;
1212

@@ -597,7 +597,7 @@ pub(crate) struct FontHandler {
597597
}
598598

599599
impl PropertyHandler for FontHandler {
600-
fn handle_property(&mut self, property: &Property, _: &mut DeclarationList) -> bool {
600+
fn handle_property(&mut self, property: &Property, dest: &mut DeclarationList) -> bool {
601601
use Property::*;
602602

603603
macro_rules! property {
@@ -626,6 +626,10 @@ impl PropertyHandler for FontHandler {
626626
self.has_any = true;
627627
// TODO: reset other properties
628628
}
629+
Unparsed(val) if is_font_property(&val.property_id) => {
630+
self.finalize(dest);
631+
dest.push(property.clone());
632+
}
629633
_ => return false
630634
}
631635

@@ -695,3 +699,18 @@ impl PropertyHandler for FontHandler {
695699
}
696700
}
697701
}
702+
703+
#[inline]
704+
fn is_font_property(property_id: &PropertyId) -> bool {
705+
match property_id {
706+
PropertyId::FontFamily |
707+
PropertyId::FontSize |
708+
PropertyId::FontStyle |
709+
PropertyId::FontWeight |
710+
PropertyId::FontStretch |
711+
PropertyId::FontVariantCaps |
712+
PropertyId::LineHeight |
713+
PropertyId::Font => true,
714+
_ => false
715+
}
716+
}

0 commit comments

Comments
 (0)