Add PDFStandard type and constants

Also rename the PDFStandard field in CLIOptions to PDFStandards, and change its type from string to []PDFStandard.

This is a breaking change.
This commit is contained in:
David Vogel 2025-02-26 17:27:24 +01:00
parent c2d62b2373
commit 0668d15070

View File

@ -1,4 +1,4 @@
// Copyright (c) 2024 David Vogel
// Copyright (c) 2024-2025 David Vogel
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
@ -22,6 +22,14 @@ const (
OutputFormatHTML OutputFormat = "html" // this format is only available since 0.13.0
)
type PDFStandard string
const (
PDFStandard1_7 PDFStandard = "1.7" // PDF 1.7
PDFStandardA_2B PDFStandard = "a-2b" // PDF/A-2b
PDFStandardA_3B PDFStandard = "a-3b" // PDF/A-3b (Available since Typst 0.13.0 and later)
)
type CLIOptions struct {
Root string // Configures the project root (for absolute paths).
Input map[string]string // String key-value pairs visible through `sys.inputs`.
@ -42,13 +50,10 @@ type CLIOptions struct {
Format OutputFormat // The format of the output file, inferred from the extension by default.
PPI int // The PPI (pixels per inch) to use for PNG export. Defaults to 144.
// One (or multiple comma-separated) PDF standards that Typst will enforce conformance with.
// One (or multiple) PDF standards that Typst will enforce conformance with.
//
// Possible values:
//
// - 1.7: PDF 1.7
// - a-2b: PDF/A-2b
PDFStandard string
// See typst.PDFStandard for possible values.
PDFStandards []PDFStandard
Custom []string // Custom command line options go here.
}
@ -112,8 +117,15 @@ func (c *CLIOptions) Args() (result []string) {
result = append(result, "--ppi", strconv.FormatInt(int64(c.PPI), 10))
}
if c.PDFStandard != "" {
result = append(result, "--pdf-standard", c.PDFStandard)
if len(c.PDFStandards) > 0 {
var standards string
for i, standard := range c.PDFStandards {
if i > 0 {
standards += ","
}
standards += string(standard)
}
result = append(result, "--pdf-standard", standards)
}
result = append(result, c.Custom...)