Implement XeTeX OpenType embolden across PDF and SVG
This commit is contained in:
1 parent
45ea5d4297
commit
5a4271364a
7 files changed
+236
-78
No files matched your search
@@ -560,30 +560,46 @@ impl DisplayList {
|
||||
std::collections::btree_map::Entry::Vacant(entry) => entry.insert(font.face()?),
|
||||
std::collections::btree_map::Entry::Occupied(entry) => entry.into_mut(),
|
||||
};
|
||||
let path = opentype_paths.entry((font.id, *glyph))
|
||||
.or_insert_with(|| crate::opentype::outline(face, *glyph));
|
||||
let x = *x as f64 / 65536.;
|
||||
let y = *y as f64 / 65536.;
|
||||
let scale = *size as f64 / (65536. * f64::from(face.units_per_em()));
|
||||
let [extend, slant] = font.paint_transform();
|
||||
let embolden = font.paint_embolden();
|
||||
let horizontal = scale * extend;
|
||||
// Place the transformed outline in page units before
|
||||
// stroking. The font matrix must not distort the stroke.
|
||||
let transform = (embolden > 0.).then_some([horizontal, scale * slant, -scale]);
|
||||
let path_size = if transform.is_some() { *size } else { 0 };
|
||||
let path = opentype_paths.entry((font.id, *glyph, path_size))
|
||||
.or_insert_with(|| crate::opentype::outline(face, *glyph, transform));
|
||||
if !path.is_empty() {
|
||||
use std::fmt::Write as _;
|
||||
let [extend, slant] = font.paint_transform();
|
||||
let horizontal = scale * extend;
|
||||
write!(
|
||||
out,
|
||||
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5}) ",
|
||||
"<g data-font=\"{}\" data-glyph=\"{glyph}\" aria-label=\"{}\"><path d=\"{path}\" transform=\"translate({x:.5} {y:.5})",
|
||||
escape(&font.name), escape(text),
|
||||
).unwrap();
|
||||
if slant == 0. {
|
||||
write!(out, "scale({horizontal:.9} -{scale:.9})").unwrap();
|
||||
} else {
|
||||
let shear = scale * slant;
|
||||
write!(out, "matrix({horizontal:.9} 0 {shear:.9} -{scale:.9} 0 0)").unwrap();
|
||||
if transform.is_none() {
|
||||
if slant == 0. {
|
||||
write!(out, " scale({horizontal:.9} -{scale:.9})").unwrap();
|
||||
} else {
|
||||
let shear = scale * slant;
|
||||
write!(out, " matrix({horizontal:.9} 0 {shear:.9} -{scale:.9} 0 0)").unwrap();
|
||||
}
|
||||
}
|
||||
writeln!(
|
||||
out, "\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}/></g>",
|
||||
write!(
|
||||
out, "\" fill=\"#{:02x}{:02x}{:02x}\"{fill_opacity}",
|
||||
fill[0], fill[1], fill[2],
|
||||
).unwrap();
|
||||
if embolden > 0. {
|
||||
let stroke_width = embolden / self.units.bp(65536);
|
||||
write!(
|
||||
out,
|
||||
" stroke=\"#{:02x}{:02x}{:02x}\" stroke-width=\"{stroke_width:.9}\" stroke-miterlimit=\"10\"{stroke_opacity}",
|
||||
stroke[0], stroke[1], stroke[2],
|
||||
).unwrap();
|
||||
}
|
||||
out.push_str("/></g>\n");
|
||||
}
|
||||
}
|
||||
DisplayItem::MathGlyph {
|
||||
|
||||
Reference in new issue
Block a user