documents: export and measuring choose fonts as gpui draws: a missing family falls to sans-serif, then any face
CI / platforms (windows-latest) (push) Failing after 11s
CI / site (push) Successful in 26s
CI / crate (push) Failing after 11m39s
CI / platforms (ubuntu-24.04) (push) Canceled after 0s

This commit is contained in:
ZacharyZhang-NY committed 2026-10-12 12:23:55 -04:00
1 parent 50a59d2620
commit a0011772ae
2 files changed
+21 -2

No files matched your search

+18 -1
View File
@@ -107,10 +107,27 @@ pub fn diagram_svg(source: &str) -> Result<String, SharedString> {
flatten(&svg(&chart)?)
}
/// usvg reading with the system's fonts.
/// usvg reading with the system's fonts, chosen as gpui draws.
pub(crate) fn options() -> usvg::Options<'static> {
let named = usvg::FontResolver::default_font_selector();
let select_font = Box::new(
move |font: &usvg::Font, db: &mut Arc<usvg::fontdb::Database>| {
// A missing family falls to sans-serif, then any face.
let sans = usvg::fontdb::Query {
families: &[usvg::fontdb::Family::SansSerif],
..Default::default()
};
named(font, db)
.or_else(|| db.query(&sans))
.or_else(|| db.faces().next().map(|face| face.id))
},
);
usvg::Options {
fontdb: fonts(),
font_resolver: usvg::FontResolver {
select_font,
select_fallback: usvg::FontResolver::default_fallback_selector(),
},
..usvg::Options::default()
}
}
+3 -1
View File
@@ -36,7 +36,9 @@ fn every_glyph_lies_inside_the_picture() {
r"\left(\frac{a}{b}\right)",
] {
let (svg, shape) = svg(&formula(source, false)).expect("typesets");
let tree = usvg::Tree::from_data(svg.as_bytes(), &usvg::Options::default()).expect("svg");
// Measured with the fonts it draws with.
let options = crate::documents::svg_options();
let tree = usvg::Tree::from_data(svg.as_bytes(), &options).expect("svg");
let ink = tree.root().abs_stroke_bounding_box();
let (w, h) = (shape.width.as_f32(), shape.height.as_f32());
let near = |a: f32, b: f32| (a - b).abs() < 0.01;