-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathresolve_packages.rs
48 lines (39 loc) · 1.42 KB
/
resolve_packages.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
#[cfg(feature = "packages")]
use std::fs;
#[cfg(feature = "packages")]
use typst::foundations::Bytes;
#[cfg(feature = "packages")]
use typst::text::Font;
#[cfg(feature = "packages")]
use typst_as_lib::TypstTemplate;
#[cfg(feature = "packages")]
static OUTPUT: &str = "./examples/output.pdf";
#[cfg(feature = "packages")]
static TEMPLATE_FILE: &str = include_str!("./templates/resolve_files.typ");
#[cfg(feature = "packages")]
static ROOT: &str = "./examples/templates";
#[cfg(feature = "packages")]
static FONT: &[u8] = include_bytes!("./fonts/texgyrecursor-regular.otf");
#[cfg(feature = "packages")]
fn main() {
let font = Font::new(Bytes::from(FONT), 0).expect("Could not parse font!");
// Read in fonts and the main source file.
// We can use this template more than once, if needed (Possibly
// with different input each time).
let template = TypstTemplate::new(vec![font], TEMPLATE_FILE)
.with_file_system_resolver(ROOT)
.with_package_file_resolver(None);
// Run it
let doc = template
.compile()
.output
.expect("typst::compile() returned an error!");
let options = Default::default();
// Create pdf
let pdf = typst_pdf::pdf(&doc, &options).expect("Could not generate pdf.");
fs::write(OUTPUT, pdf).expect("Could not write pdf.");
}
#[cfg(not(feature = "packages"))]
fn main() {
eprintln!("You need to run this with flag `--features=packages`!")
}