Skip to content

Commit

Permalink
feat: 字体解析路径
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyadam committed Aug 15, 2024
1 parent 1ef20d0 commit 63213f3
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 2 deletions.
26 changes: 26 additions & 0 deletions __test__/fixure/pesudo.scss
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}

12 changes: 10 additions & 2 deletions src/style_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
},
_ => {}
}
Expand Down Expand Up @@ -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());
}
}
});
},
Expand Down

0 comments on commit 63213f3

Please # to comment.