Provide a runnable local Beta and fix multi-page SVG previews

This commit is contained in:
gloamxun committed 2026-11-29 13:19:00 +08:00
1 parent fb557c09c6
commit 9841e88900
7 files changed
+324 -9

No files matched your search

+12 -3
View File
@@ -625,7 +625,7 @@ impl DisplayList {
write!(
out,
"<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"",
escape(font), escape(glyph), escape(&label), path,
escape_attribute(font), escape_attribute(glyph), escape_attribute(&label), path,
).unwrap();
if let Some([vx2, vy]) = vertical_origin {
let vx = f64::from(vx2) / 2.0;
@@ -680,7 +680,7 @@ impl DisplayList {
write!(
out,
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5})",
escape(&font.name), escape(text),
escape_attribute(&font.name), escape_attribute(text),
).unwrap();
if transform.is_none() {
if let Some([a, b, c, d, e, f]) = vertical {
@@ -733,7 +733,7 @@ impl DisplayList {
let scale = *size as f64 / 65_536_000.0;
out.push_str(&format!(
"<g data-font=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><use href=\"#math-{}-{slot}\" transform=\"translate({x:.5} {y:.5}) scale({scale:.8} -{scale:.8})\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/><text x=\"{x:.5}\" y=\"{y:.5}\" opacity=\"0\" aria-hidden=\"true\">{}</text></g>\n",
face.name(), escape(&character.to_string()), face.0,
escape_attribute(face.name()), escape_attribute(&character.to_string()), face.0,
fill[0], fill[1], fill[2], escape(&character.to_string())
));
}
@@ -1083,6 +1083,15 @@ fn base64(data: &[u8]) -> String {
out
}
fn escape_attribute(text: &str) -> String {
let escaped = escape(text);
if text.contains('"') {
escaped.replace('"', "&quot;")
} else {
escaped
}
}
fn escape(text: &str) -> String {
text.replace('&', "&amp;")
.replace('<', "&lt;")
+21 -1
View File
@@ -6,11 +6,31 @@ use texrra_tex_core::math::{MathAtom, parse_math};
use texrra_tex_core::math_font::MathFontId;
use texrra_tex_core::paragraph::{HorizontalItem, InlineSegment, ParagraphFont, ParagraphStyle};
use texrra_tex_core::pdf::{PageOrigin, display_lists_to_pdf_with_cm_type1};
use texrra_tex_core::render::DisplayItem;
use texrra_tex_core::render::{DisplayItem, DisplayList};
use texrra_tex_core::{Document, Engine, Unit, VerticalItem};
const PT: i64 = 65_536;
#[test]
fn svg_glyph_labels_escape_attribute_quotes() {
let display = DisplayList {
width: 12 * PT,
height: 12 * PT,
items: vec![DisplayItem::MathGlyph {
x: 0,
y: 6 * PT,
size: 10 * PT,
character: '"',
face: MathFontId(0),
slot: b'"',
}],
..DisplayList::default()
};
let svg = display.try_to_svg().unwrap();
assert!(svg.contains(r#"aria-label="&quot;"><use"#));
assert!(svg.contains(r#"aria-hidden="true">"</text>"#));
}
#[test]
fn structural_display_edits_replay_the_preceding_paragraph_dependency() {
let style = ParagraphStyle {