1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
//! 指定した字形をそのまま並べて見る
use suki::font;
use suki::outline::{bounds, path_data};
use suki::text::number;
fn main() {
let loaded = font::load(std::fs::read("font/latinmodern-math.otf").unwrap()).unwrap();
let units = font::units_per_em(&loaded);
let wanted: Vec<u16> = std::env::args()
.skip(1)
.filter_map(|value| value.parse().ok())
.collect();
println!("<!DOCTYPE html><html lang=\"ja\"><head><meta charset=\"utf-8\"><title>字形</title>");
println!("<style>body{{margin:0;padding:24px;font-family:system-ui,sans-serif;font-size:12px}}");
println!(".row{{margin-bottom:20px}}.name{{color:#767676;margin-bottom:4px}}</style></head><body>");
for glyph in wanted {
let drawn = font::outline_of(&loaded, glyph);
let (left, bottom, right, top) = bounds(&drawn);
let width = (right - left) / units;
let height = (top - bottom) / units;
println!("<div class=\"row\"><div class=\"name\">字形 {glyph}</div>");
println!(
"<svg width=\"{}px\" height=\"{}px\" viewBox=\"{} {} {} {}\" fill=\"#1f1f1f\"><path d=\"{}\"/></svg></div>",
number(width * 200.0),
number(height * 200.0),
number(left / units),
number(-top / units),
number(width),
number(height),
path_data(&drawn, 1.0 / units, 0.0, 0.0)
);
}
println!("</body></html>");
}