Implement native automatic font expansion for paragraphs

This commit is contained in:
gloamxun committed 2026-11-20 23:29:37 +08:00
1 parent 1dd745afcb
commit ebbc9e2c17
24 files changed
+632 -34

No files matched your search

+9 -1
View File
@@ -135,6 +135,7 @@ pub enum DisplayItem {
struct NativeSvgGlyph<'a> {
position: [i64; 2],
size: i64,
expansion: i32,
slot: u8,
font: &'a str,
glyph: &'a str,
@@ -173,6 +174,7 @@ impl DisplayItem {
Ok(NativeSvgGlyph {
position: [*x, *y],
size: *size,
expansion: font.expansion,
slot: *slot,
font: paint.program.name(),
glyph: &paint.encoding[usize::from(*slot)],
@@ -411,6 +413,7 @@ impl DisplayList {
let NativeSvgGlyph {
position: [x, y],
size,
expansion,
slot,
font,
glyph,
@@ -423,12 +426,17 @@ impl DisplayList {
let x = x as f64 / 65_536.0;
let y = y as f64 / 65_536.0;
let scale = size as f64 / 65_536_000.0;
let horizontal_scale = if expansion == 0 {
scale
} else {
scale * f64::from(1000 + expansion) / 1000.0
};
let label = if type1 {
crate::type1::glyph_unicode_text(glyph).unwrap_or_default()
} else {
String::new()
};
out.push_str(&format!("<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"translate({x:.5} {y:.5}) scale({scale:.8} -{scale:.8})\" fill=\"#{:02x}{:02x}{:02x}\"/></g>\n", escape(font), escape(glyph), escape(&label), path, fill[0],fill[1],fill[2]));
out.push_str(&format!("<g data-font=\"{}\" data-glyph=\"{}\" data-slot=\"{slot}\" aria-label=\"{}\"><path d=\"{}\" transform=\"translate({x:.5} {y:.5}) scale({horizontal_scale:.8} -{scale:.8})\" fill=\"#{:02x}{:02x}{:02x}\"/></g>\n", escape(font), escape(glyph), escape(&label), path, fill[0],fill[1],fill[2]));
}
DisplayItem::MathGlyph {
x,