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
//! 波括弧がどの字形を選んでいるかを見る
use suki::font;
use suki::layout::Content;
use suki::node::Style;
use suki::{layout, parse};
fn main() {
let loaded = font::load(std::fs::read("font/latinmodern-math.otf").unwrap()).unwrap();
let mut body = String::from("a");
for step in 0..6 {
if step > 0 {
body.push_str("+a");
}
let source = format!(r"\overbrace{{{body}}}");
let node = parse(&source).unwrap();
let placed = layout::layout(&node, &loaded, 1.0, Style::Auto, true);
let Content::Group(row) = &placed.content else {continue};
let Content::Group(parts) = &row[0].layout.content else {continue};
let inside = &parts[0].layout;
let mark = &parts[1].layout;
let shape = match &mark.content {
Content::Glyph {glyph, ..} => format!("字形 {glyph}"),
Content::Group(pieces) => format!("部品 {} 個", pieces.len()),
Content::Rule => "線".to_string(),
};
println!(
"中身の幅 {:.3} 印 {shape} 幅 {:.3} 高さ {:.3} 深さ {:.3}",
inside.width, mark.width, mark.height, mark.depth
);
}
}