summaryrefslogtreecommitdiff
path: root/src/main.rs
diff options
context:
space:
mode:
authorLaurenz <laurmaedje@gmail.com>2021-11-14 13:13:27 +0100
committerLaurenz <laurmaedje@gmail.com>2021-11-14 13:13:27 +0100
commit14048937b877d242de8b585905cdab3ac6acd9ee (patch)
tree2228bf996d47937c3c075c5d4e212aa72bb9d57a /src/main.rs
parentc6f8ad35f45248f1fd36ee00195966f1629c6ca7 (diff)
Search for fonts in the project directory
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs25
1 files changed, 19 insertions, 6 deletions
diff --git a/src/main.rs b/src/main.rs
index 55f83cd7..b2ae1ea3 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -10,7 +10,10 @@ use same_file::is_same_file;
use termcolor::{ColorChoice, StandardStream, WriteColor};
use typst::diag::Error;
+use typst::export;
+use typst::loading::FsLoader;
use typst::source::SourceStore;
+use typst::Context;
fn main() {
if let Err(error) = try_main() {
@@ -27,14 +30,24 @@ fn try_main() -> anyhow::Result<()> {
});
// Create a loader for fonts and files.
- let loader = typst::loading::FsLoader::new()
- .with_path("fonts")
- .with_system()
- .wrap();
+ let mut loader = FsLoader::new();
+
+ // Search for fonts in the project directory.
+ if let Some(dir) = args.input.parent() {
+ if dir.as_os_str().is_empty() {
+ // Just a filename, so directory is current directory.
+ loader.search_path(".");
+ } else {
+ loader.search_path(dir);
+ }
+ }
+
+ // Search system fonts only now to give local fonts priority.
+ loader.search_system();
// Create the context which holds loaded source files, fonts, images and
// cached artifacts.
- let mut ctx = typst::Context::new(loader);
+ let mut ctx = Context::new(loader.wrap());
// Ensure that the source file is not overwritten.
if is_same_file(&args.input, &args.output).unwrap_or(false) {
@@ -48,7 +61,7 @@ fn try_main() -> anyhow::Result<()> {
match ctx.typeset(id) {
// Export the PDF.
Ok(document) => {
- let buffer = typst::export::pdf(&ctx, &document);
+ let buffer = export::pdf(&ctx, &document);
fs::write(&args.output, buffer).context("failed to write PDF file")?;
}