From 63213f3a65facb09b70de754d2850781db799d53 Mon Sep 17 00:00:00 2001 From: luckyadam Date: Thu, 15 Aug 2024 15:13:19 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=AD=97=E4=BD=93=E8=A7=A3=E6=9E=90?= =?UTF-8?q?=E8=B7=AF=E5=BE=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- __test__/fixure/pesudo.scss | 26 ++++++++++++++++++++++++++ src/style_parser.rs | 12 ++++++++++-- 2 files changed, 36 insertions(+), 2 deletions(-) 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()); + } } }); },