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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Shows glyph measurements and where scripts are placed, as numbers
use suki::font::{self};
use suki::layout::{Content, Layout};
use suki::node::Style;
use suki::{layout, parse};
fn main() {
let loaded = font::load(std::fs::read("font/latinmodern-math.otf").unwrap()).unwrap();
for character in ['\u{222b}', '\u{2211}', '\u{1d453}', 'x'] {
let glyph = font::glyph_of(&loaded, character).unwrap();
let (height, depth) = font::extent(&loaded, glyph);
let (left, right) = font::bearing(&loaded, glyph);
println!(
"{character} glyph {glyph} advance {:.3} height {:.3} depth {:.3} overhang {:.3} \
bearing left {left:.3} right {right:.3}",
font::advance(&loaded, glyph),
height,
depth,
font::italic_correction(&loaded, glyph)
);
if let Some(growth) = font::vertical_growth(&loaded, glyph) {
for variant in growth.variant.iter().take(3) {
let (left, right) = font::bearing(&loaded, variant.glyph);
println!(
" variant {} advance {:.3} vertical size {:.3} overhang {:.3} \
bearing left {left:.3} right {right:.3}",
variant.glyph,
font::advance(&loaded, variant.glyph),
variant.measure,
font::italic_correction(&loaded, variant.glyph)
);
}
}
}
for source in [r"\int_0^1", r"\sum_{k}^{n}", r"f_1^2"] {
let node = parse(source).unwrap();
let placed = layout::layout(&node, &loaded, 1.0, Style::Auto, true);
println!("\n{source}");
show(&placed, 0.0, 1);
}
}
fn show(placed: &Layout, x: f64, depth: usize) {
match &placed.content {
Content::Glyph {text, glyph, size, ..} => {
println!("{:width$}x {x:.3} width {:.3} '{text}' glyph {glyph} size {size:.2}",
"", placed.width, width = depth * 2);
}
Content::Group(children) => {
println!("{:width$}group x {x:.3} width {:.3}", "", placed.width, width = depth * 2);
for child in children {
show(&child.layout, x + child.x, depth + 1);
}
}
Content::Rule => println!("{:width$}rule x {x:.3} width {:.3}", "", placed.width, width = depth * 2),
}
}