mirror of
https://github.com/a-b-street/abstreet.git
synced 2024-12-01 10:44:56 +03:00
custom font families
This commit is contained in:
parent
3eea1f2a45
commit
ec08a9177e
@ -24,6 +24,4 @@ serde_derive = "1.0.98"
|
||||
simsearch = "0.1.4"
|
||||
stretch = "0.3.2"
|
||||
textwrap = "0.11"
|
||||
# TODO We need the ability to remove the harfbuzz dependency, which doesn't
|
||||
# build well on Windows.
|
||||
usvg = { git = "https://github.com/RazrFalcon/resvg" }
|
||||
usvg = { git = "https://github.com/dabreegster/resvg" }
|
||||
|
@ -402,9 +402,16 @@ fn render_text(txt: TextSpan) -> GeomBatch {
|
||||
// If these are large enough, does this work?
|
||||
let max_w = 9999.0;
|
||||
let max_h = 9999.0;
|
||||
let family = if txt.font == DEJA_VU {
|
||||
"font-family=\"DejaVu Sans\""
|
||||
} else if txt.font == ROBOTO {
|
||||
"font-family=\"Roboto\""
|
||||
} else {
|
||||
"font-family=\"Roboto\" font-weight=\"bold\""
|
||||
};
|
||||
|
||||
let svg = format!(
|
||||
r##"<svg width="{}" height="{}" viewBox="0 0 {} {}" fill="none" xmlns="http://www.w3.org/2000/svg"><text x="0" y="0" fill="{}" font-size="{}" font-family="{}">{}</text></svg>"##,
|
||||
r##"<svg width="{}" height="{}" viewBox="0 0 {} {}" fill="none" xmlns="http://www.w3.org/2000/svg"><text x="0" y="0" fill="{}" font-size="{}" {}>{}</text></svg>"##,
|
||||
max_w,
|
||||
max_h,
|
||||
max_w,
|
||||
@ -413,11 +420,15 @@ fn render_text(txt: TextSpan) -> GeomBatch {
|
||||
// TODO Plumb through default font size?
|
||||
txt.size.unwrap_or(30),
|
||||
// TODO Make these work
|
||||
"DejaVu Sans",
|
||||
family,
|
||||
txt.text
|
||||
);
|
||||
|
||||
let svg_tree = usvg::Tree::from_str(&svg, &usvg::Options::default()).unwrap();
|
||||
let mut opts = usvg::Options::default();
|
||||
// TODO Bundle better
|
||||
opts.font_directories
|
||||
.push("/home/dabreegster/abstreet/ezgui/src/assets".to_string());
|
||||
let svg_tree = usvg::Tree::from_str(&svg, &opts).unwrap();
|
||||
let mut batch = GeomBatch::new();
|
||||
match crate::svg::add_svg_inner(&mut batch, svg_tree) {
|
||||
Ok(_) => batch,
|
||||
|
Loading…
Reference in New Issue
Block a user