summaryrefslogtreecommitdiff
path: root/crates/typst-cli/src/compile.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/typst-cli/src/compile.rs')
-rw-r--r--crates/typst-cli/src/compile.rs25
1 files changed, 13 insertions, 12 deletions
diff --git a/crates/typst-cli/src/compile.rs b/crates/typst-cli/src/compile.rs
index 331a2b1f..0fa66d62 100644
--- a/crates/typst-cli/src/compile.rs
+++ b/crates/typst-cli/src/compile.rs
@@ -95,19 +95,14 @@ pub fn compile_once(
Ok(())
}
-enum ExportImageFormat {
- Png,
- Svg,
-}
-
/// Export into the target format.
fn export(document: &Document, command: &CompileCommand) -> StrResult<()> {
match command.output().extension() {
Some(ext) if ext.eq_ignore_ascii_case("png") => {
- export_image(document, command, ExportImageFormat::Png)
+ export_image(document, command, ImageExportFormat::Png)
}
Some(ext) if ext.eq_ignore_ascii_case("svg") => {
- export_image(document, command, ExportImageFormat::Svg)
+ export_image(document, command, ImageExportFormat::Svg)
}
_ => export_pdf(document, command),
}
@@ -121,18 +116,24 @@ fn export_pdf(document: &Document, command: &CompileCommand) -> StrResult<()> {
Ok(())
}
+/// An image format to export in.
+enum ImageExportFormat {
+ Png,
+ Svg,
+}
+
/// Export to one or multiple PNGs.
fn export_image(
document: &Document,
command: &CompileCommand,
- fmt: ExportImageFormat,
+ fmt: ImageExportFormat,
) -> StrResult<()> {
// Determine whether we have a `{n}` numbering.
let output = command.output();
let string = output.to_str().unwrap_or_default();
let numbered = string.contains("{n}");
if !numbered && document.pages.len() > 1 {
- bail!("cannot export multiple PNGs without `{{n}}` in output path");
+ bail!("cannot export multiple images without `{{n}}` in output path");
}
// Find a number width that accommodates all pages. For instance, the
@@ -149,13 +150,13 @@ fn export_image(
output.as_path()
};
match fmt {
- ExportImageFormat::Png => {
+ ImageExportFormat::Png => {
let pixmap =
typst::export::render(frame, command.ppi / 72.0, Color::WHITE);
pixmap.save_png(path).map_err(|_| "failed to write PNG file")?;
}
- ExportImageFormat::Svg => {
- let svg = typst::export::svg_frame(frame);
+ ImageExportFormat::Svg => {
+ let svg = typst::export::svg(frame);
fs::write(path, svg).map_err(|_| "failed to write SVG file")?;
}
}