Reflect display font faces in SVG output

This commit is contained in:
gloamxun committed 2026-10-20 18:30:12 +08:00
1 parent d40595c7e5
commit 96c88d2787
3 files changed
+49 -3

No files matched your search

+21 -2
View File
@@ -123,13 +123,32 @@ impl DisplayList {
for item in &self.items {
match item {
DisplayItem::Text {
x, y, size, text, ..
x,
y,
size,
text,
font,
} => {
let x = *x as f64 / 65_536.0;
let y = *y as f64 / 65_536.0;
let size = *size as f64 / 65_536.0;
let family = if matches!(font, FontFace::Mono) {
"monospace"
} else {
"serif"
};
let weight = if matches!(font, FontFace::Bold | FontFace::BoldItalic) {
" font-weight=\"bold\""
} else {
""
};
let style = if matches!(font, FontFace::Italic | FontFace::BoldItalic) {
" font-style=\"italic\""
} else {
""
};
out.push_str(&format!(
"<text x=\"{x:.3}\" y=\"{y:.3}\" font-size=\"{size:.3}\" font-family=\"serif\">{}</text>\n",
"<text x=\"{x:.3}\" y=\"{y:.3}\" font-size=\"{size:.3}\" font-family=\"{family}\"{weight}{style}>{}</text>\n",
escape(text)
));
}