Re-add CLI supports for many standards at the same time

This commit is contained in:
Laurenz Stampfl 2024-12-17 17:21:06 +01:00
parent 1ac74d472d
commit c14cddd55a
3 changed files with 168 additions and 29 deletions

152
Cargo.lock generated
View File

@ -806,6 +806,20 @@ dependencies = [
"roxmltree",
]
[[package]]
name = "fontdb"
version = "0.21.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "37be9fc20d966be438cd57a45767f73349477fb0f85ce86e000557f787298afb"
dependencies = [
"fontconfig-parser",
"log",
"memmap2",
"slotmap",
"tinyvec",
"ttf-parser",
]
[[package]]
name = "fontdb"
version = "0.22.0"
@ -1319,23 +1333,23 @@ dependencies = [
"comemo",
"flate2",
"float-cmp 0.10.0",
"fontdb",
"fontdb 0.22.0",
"gif",
"image-webp",
"imagesize",
"miniz_oxide",
"once_cell",
"pdf-writer",
"pdf-writer 0.12.0 (git+https://github.com/LaurenzV/pdf-writer?rev=f95a19c)",
"rayon",
"resvg",
"resvg 0.44.0",
"rustybuzz",
"siphasher 1.0.1",
"skrifa",
"subsetter",
"subsetter 0.2.0 (git+https://github.com/typst/subsetter?rev=172416a)",
"tiny-skia",
"tiny-skia-path",
"usvg",
"xmp-writer",
"usvg 0.44.0",
"xmp-writer 0.3.0 (git+https://github.com/LaurenzV/xmp-writer?rev=1c2b8ae9)",
"yoke",
"zune-jpeg",
"zune-png",
@ -1767,6 +1781,18 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8835116a5c179084a830efb3adc117ab007512b535bc1a21c991d3b32a6b44dd"
[[package]]
name = "pdf-writer"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "be17f48d7fbbd22c6efedb58af5d409aa578e407f40b29a0bcb4e66ed84c5c98"
dependencies = [
"bitflags 2.6.0",
"itoa",
"memchr",
"ryu",
]
[[package]]
name = "pdf-writer"
version = "0.12.0"
@ -2086,6 +2112,23 @@ version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b15c43186be67a4fd63bee50d0303afffcef381492ebe2c5d87f324e1b8815c"
[[package]]
name = "resvg"
version = "0.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c7314563c59c7ce31c18e23ad3dd092c37b928a0fa4e1c0a1a6504351ab411d1"
dependencies = [
"gif",
"image-webp",
"log",
"pico-args",
"rgb",
"svgtypes",
"tiny-skia",
"usvg 0.43.0",
"zune-jpeg",
]
[[package]]
name = "resvg"
version = "0.44.0"
@ -2099,7 +2142,7 @@ dependencies = [
"rgb",
"svgtypes",
"tiny-skia",
"usvg",
"usvg 0.44.0",
"zune-jpeg",
]
@ -2468,11 +2511,37 @@ dependencies = [
"syn",
]
[[package]]
name = "subsetter"
version = "0.2.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "74f98178f34057d4d4de93d68104007c6dea4dfac930204a69ab4622daefa648"
[[package]]
name = "subsetter"
version = "0.2.0"
source = "git+https://github.com/typst/subsetter?rev=172416a#172416a806246e6e9010d400d5690ca7a026e53d"
[[package]]
name = "svg2pdf"
version = "0.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5014c9dadcf318fb7ef8c16438e95abcc9de1ae24d60d5bccc64c55100c50364"
dependencies = [
"fontdb 0.21.0",
"image",
"log",
"miniz_oxide",
"once_cell",
"pdf-writer 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"resvg 0.43.0",
"siphasher 1.0.1",
"subsetter 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"tiny-skia",
"ttf-parser",
"usvg 0.43.0",
]
[[package]]
name = "svgtypes"
version = "0.15.2"
@ -2919,7 +2988,7 @@ dependencies = [
"ecow",
"env_proxy",
"flate2",
"fontdb",
"fontdb 0.22.0",
"native-tls",
"once_cell",
"openssl",
@ -2976,7 +3045,7 @@ dependencies = [
"csv",
"ecow",
"flate2",
"fontdb",
"fontdb 0.22.0",
"hayagriva",
"icu_properties",
"icu_provider",
@ -3015,7 +3084,7 @@ dependencies = [
"unicode-math-class",
"unicode-segmentation",
"unscanny",
"usvg",
"usvg 0.44.0",
"wasmi",
"xmlwriter",
]
@ -3047,6 +3116,32 @@ dependencies = [
"typst-utils",
]
[[package]]
name = "typst-pdf-old"
version = "0.12.0"
dependencies = [
"arrayvec",
"base64",
"bytemuck",
"comemo",
"ecow",
"image",
"indexmap 2.6.0",
"miniz_oxide",
"pdf-writer 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
"serde",
"subsetter 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)",
"svg2pdf",
"ttf-parser",
"typst-assets",
"typst-library",
"typst-macros",
"typst-syntax",
"typst-timing",
"typst-utils",
"xmp-writer 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "typst-realize"
version = "0.12.0"
@ -3071,7 +3166,7 @@ dependencies = [
"comemo",
"image",
"pixglyph",
"resvg",
"resvg 0.44.0",
"tiny-skia",
"ttf-parser",
"typst-library",
@ -3293,6 +3388,33 @@ dependencies = [
"serde",
]
[[package]]
name = "usvg"
version = "0.43.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6803057b5cbb426e9fb8ce2216f3a9b4ca1dd2c705ba3cbebc13006e437735fd"
dependencies = [
"base64",
"data-url",
"flate2",
"fontdb 0.21.0",
"imagesize",
"kurbo",
"log",
"pico-args",
"roxmltree",
"rustybuzz",
"simplecss",
"siphasher 1.0.1",
"strict-num",
"svgtypes",
"tiny-skia-path",
"unicode-bidi",
"unicode-script",
"unicode-vo",
"xmlwriter",
]
[[package]]
name = "usvg"
version = "0.44.0"
@ -3302,7 +3424,7 @@ dependencies = [
"base64",
"data-url",
"flate2",
"fontdb",
"fontdb 0.22.0",
"imagesize",
"kurbo",
"log",
@ -3687,6 +3809,12 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9"
[[package]]
name = "xmp-writer"
version = "0.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8254499146a4fd0c86e3e99cf4a9f468f595808fb49ff8f3e495f2b117bf4ebc"
[[package]]
name = "xmp-writer"
version = "0.3.0"

View File

@ -245,10 +245,11 @@ pub struct CompileArgs {
#[arg(long = "pdf-version")]
pub pdf_version: Option<PdfVersion>,
/// A PDF standard that Typst will enforce
/// conformance with.
#[arg(long = "pdf-standard")]
pub pdf_standard: Option<PdfStandard>,
/// A number of PDF standards that Typst will enforce
/// conformance with (currently, only one standard at a time
/// is supported).
#[arg(long = "pdf-standard", value_delimiter = ',')]
pub pdf_standard: Vec<PdfStandard>,
/// The PPI (pixels per inch) to use for PNG export.
#[arg(long = "ppi", default_value_t = 144.0)]

View File

@ -64,8 +64,8 @@ pub struct CompileConfig {
pub open: Option<Option<String>>,
/// The version that should be used to export the PDF.
pub pdf_version: Option<PdfVersion>,
/// A standard the PDF should conform to.
pub pdf_standard: Option<PdfStandard>,
/// A list of standards the PDF should conform to.
pub pdf_standard: Vec<PdfStandard>,
/// A path to write a Makefile rule describing the current compilation.
pub make_deps: Option<PathBuf>,
/// The PPI (pixels per inch) to use for PNG export.
@ -155,7 +155,7 @@ impl CompileConfig {
export_cache: ExportCache::new(),
#[cfg(feature = "http-server")]
server,
pdf_standard: args.pdf_standard,
pdf_standard: args.pdf_standard.clone(),
})
}
}
@ -276,6 +276,25 @@ fn export_pdf(document: &PagedDocument, config: &CompileConfig) -> SourceResult<
}
};
let validator = match config.pdf_standard.first() {
None => Validator::None,
Some(s) => {
if config.pdf_standard.len() > 1 {
bail!(Span::detached(), "cannot export using more than one PDF standard";
hint: "typst currently only supports export using \
one standard at the same time");
} else {
match s {
PdfStandard::A_1b => Validator::A1_B,
PdfStandard::A_2b => Validator::A2_B,
PdfStandard::A_2u => Validator::A2_U,
PdfStandard::A_3b => Validator::A3_B,
PdfStandard::A_3u => Validator::A3_U,
}
}
}
};
let options = PdfOptions {
ident: Smart::Auto,
timestamp,
@ -286,16 +305,7 @@ fn export_pdf(document: &PagedDocument, config: &CompileConfig) -> SourceResult<
PdfVersion::V_1_6 => typst_pdf::PdfVersion::Pdf16,
PdfVersion::V_1_7 => typst_pdf::PdfVersion::Pdf17,
}),
validator: config
.pdf_standard
.map(|s| match s {
PdfStandard::A_1b => Validator::A1_B,
PdfStandard::A_2b => Validator::A2_B,
PdfStandard::A_2u => Validator::A2_U,
PdfStandard::A_3b => Validator::A3_B,
PdfStandard::A_3u => Validator::A3_U,
})
.unwrap_or(Validator::None),
validator,
};
let buffer = typst_pdf::pdf(document, &options)?;
config