diff --git a/__test__/fixure/pesudo.scss b/__test__/fixure/pesudo.scss index 395cbf3..d66a023 100644 --- a/__test__/fixure/pesudo.scss +++ b/__test__/fixure/pesudo.scss @@ -23,3 +23,29 @@ height:1000px; } } + +@font-face { + font-family: JDZH-Light; + src: url('https://wq.360buyimg.com/data/ppms/others/JDZH_Light.ttf') format('truetype'); + } + + @font-face { + font-family: JDZH-Regular; + src: url('https://wq.360buyimg.com/data/ppms/others/JDZH_Regular.ttf') format('truetype'); + } + + @font-face { + font-family: JDZH-Bold; + src: url('https://wq.360buyimg.com/data/ppms/others/JDZH_Bold.ttf') format('truetype'); + } + + @font-face { + font-family: JDZhengHT-EN-Bold; + src: url('https://wq.360buyimg.com/data/ppms/others/JDZhengHei_01_Bold.ttf') format('truetype'); + } + + @font-face { + font-family: JDZhengHT-EN-Regular; + src: url('https://wq.360buyimg.com/data/ppms/others/JDZH_Regular.ttf') format('truetype'); + } + \ No newline at end of file diff --git a/src/style_parser.rs b/src/style_parser.rs index 1ea3ad9..2253989 100644 --- a/src/style_parser.rs +++ b/src/style_parser.rs @@ -248,7 +248,7 @@ impl<'i> Visitor<'i> for StyleVisitor<'i> { if let Some(next) = source.iter().next() { match next { Source::Url(value) => { - font_face.src = value.url.to_css_string(PrinterOptions::default()).unwrap(); + font_face.src = value.url.url.as_ref().to_string(); }, _ => {} } @@ -284,7 +284,15 @@ impl<'i> Visitor<'i> for StyleVisitor<'i> { _ => {} }; if !font_face.font_family.is_empty() && !font_face.src.is_empty() { - self.all_fonts.borrow_mut().push(font_face.clone()); + let mut all_fonts = self.all_fonts.borrow_mut(); + let has_font_index = all_fonts + .iter() + .position(|font| font.font_family == font_face.font_family); + if let Some(index) = has_font_index { + all_fonts[index] = font_face.clone(); + } else { + all_fonts.push(font_face.clone()); + } } }); },