Registry / RepositoryTypeScriptRustPython
Rollpie
ReadmeFiles
Versions
Info
Download
0.2.0579.9 KB2026-09-150.1.1576.6 KB2026-09-12
Version
0.1.1
Copyright
Rollpie, Irohabook
Publisher
math
Published
2026-09-12
Size
576.6 KB
Downloads
4
Checksum
8e0181e42f4abdc9f91c1ff48b058761bf1940be8d2d4747e5e74bd3014f4322
Dependencies
None

inspect.rs

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
//! 字形の寸法と、添字がどこに置かれるかを数字で見る

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} 送り {:.3} 高さ {:.3} 深さ {:.3} 張り出し {:.3} 余白 左 {left:.3} 右 {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!(
                    "    変種 {} 送り {:.3} 縦 {:.3} 張り出し {:.3} 余白 左 {left:.3} 右 {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} 幅 {:.3} 「{text}」字形 {glyph} 大きさ {size:.2}",
                "", placed.width, width = depth * 2);
        }
        Content::Group(children) => {
            println!("{:width$}まとまり x {x:.3} 幅 {:.3}", "", placed.width, width = depth * 2);
            for child in children {
                show(&child.layout, x + child.x, depth + 1);
            }
        }
        Content::Rule => println!("{:width$}線 x {x:.3} 幅 {:.3}", "", placed.width, width = depth * 2),
    }
}