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
//! Shows typesetting partway through. Prints the number of pages and what went on the pages
//!
//! Usage: cargo run --example probe -- document.tex [typeface for Japanese text]
use hongo::layout::Block;
use hongo::style::Style;
use std::path::Path;
fn main() {
let argument: Vec<String> = std::env::args().skip(1).collect();
let path = argument.first().expect("give a document to read");
let source = std::fs::read_to_string(path).expect("cannot read the document");
let base = Path::new(path).parent().unwrap_or(Path::new(".")).to_path_buf();
let japanese = argument.get(1).map(std::path::PathBuf::from);
let library = hongo::font::open(
Path::new("font/latinmodern-math.otf"),
None,
None,
None,
None,
None,
japanese.as_deref(),
)
.expect("cannot read the typefaces");
let characters: Vec<char> = source.chars().collect();
let mut document = hongo::parse::parse(&characters).expect("cannot read the source");
let mut numbering = hongo::number::assign(&mut document);
let style = Style::default();
for round in 1..=3 {
let (block, _, _) =
hongo::layout::build(&document, &library, &style, &numbering, &base).expect("cannot lay out the document");
let count = block
.iter()
.filter(|one| matches!(one, Block::Content {..}))
.count();
let (page, _) = hongo::page::paginate(&block, &library, &style, &mut numbering);
println!("pass {round}: {} pages, {count} lines of content", page.len());
}
}