Reflect display font faces in SVG output
This commit is contained in:
1 parent
d40595c7e5
commit
96c88d2787
3 files changed
+49
-3
No files matched your search
@@ -1615,6 +1615,33 @@ mod tests {
|
||||
assert!(text.contains("/F2 4 0 R"));
|
||||
assert!(text.contains("BT /F2"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn svg_reflects_display_font_faces() {
|
||||
let mut list = crate::render::DisplayList::default();
|
||||
for (index, font) in [
|
||||
crate::render::FontFace::Roman,
|
||||
crate::render::FontFace::Bold,
|
||||
crate::render::FontFace::Italic,
|
||||
crate::render::FontFace::Mono,
|
||||
]
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
{
|
||||
list.push(crate::render::DisplayItem::Text {
|
||||
x: 10,
|
||||
y: 20 + index as i64 * 20,
|
||||
size: 10 * 65_536,
|
||||
text: format!("face{index}"),
|
||||
font,
|
||||
});
|
||||
}
|
||||
let svg = list.to_svg();
|
||||
assert!(svg.contains("font-family=\"serif\">face0"));
|
||||
assert!(svg.contains("font-weight=\"bold\">face1"));
|
||||
assert!(svg.contains("font-style=\"italic\">face2"));
|
||||
assert!(svg.contains("font-family=\"monospace\">face3"));
|
||||
}
|
||||
#[test]
|
||||
fn math_display_list_paints_symbols_and_fraction_rule() {
|
||||
let atom = crate::math::parse_math("x + \\frac{a}{b}");
|
||||
|
||||
@@ -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)
|
||||
));
|
||||
}
|
||||
|
||||
+1
-1
@@ -228,7 +228,7 @@ for a later overlaid slash.
|
||||
| M2 vertical/page builder | partial | vsize, topskip, insertions, marks, output hook, top/bottom floats, rules, vskip, penalties; interpreted `\output` and float pages absent |
|
||||
| M3 halign | partial | natural columns, spans, omit, hline rows, templates, noalign skip, rules; no PDF painter |
|
||||
| M4 math | partial | atoms, scripts, fractions, roots, delimiters, accents, operators, classes, braces, boxed, negated; no math painter/shrink wrapping |
|
||||
| M5 NFSS/TFM | partial | CMR10 widths and per-face Base-14 resources (Roman/Bold/Italic/BoldItalic/Mono); TFM loading and font embedding absent |
|
||||
| M5 NFSS/TFM | partial | CMR10 widths, per-face Base-14 PDF resources, and SVG font-family/weight/style for Roman/Bold/Italic/Mono; TFM loading and font embedding absent |
|
||||
| M6 specials/XObject | partial | raw specials, RGB image XObjects, URI link annotations; class/package execution absent |
|
||||
| M7 incremental integration | partial | edit replay + page hashes, not wired into v1 preview |
|
||||
|
||||
|
||||
Reference in new issue
Block a user