assembly

package
v0.2.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 9, 2026 License: MPL-2.0 Imports: 9 Imported by: 0

Documentation

Overview

Package assembly defines PDFConcat's domain values and the neutral job tree: the ordered PDFs, blank pages, and directory groups that both the plan decoder and the command-line shortcut compile to.

Index

Constants

View Source
const (
	// AnchorTopLeft and the eight anchors after it are the nine anchor points of a page, in grid order.
	AnchorTopLeft Anchor = 1
	// AnchorTop is the top edge, centered.
	AnchorTop Anchor = 2
	// AnchorTopRight is the top right corner.
	AnchorTopRight Anchor = 3
	// AnchorLeft is the left edge, centered.
	AnchorLeft Anchor = 4
	// AnchorCenter is the middle of the page.
	AnchorCenter Anchor = 5
	// AnchorRight is the right edge, centered.
	AnchorRight Anchor = 6
	// AnchorBottomLeft is the bottom left corner.
	AnchorBottomLeft Anchor = 7
	// AnchorBottom is the bottom edge, centered.
	AnchorBottom Anchor = 8
	// AnchorBottomRight is the bottom right corner.
	AnchorBottomRight Anchor = 9

	// PlaceLeft puts the left edge of the block at the anchor.
	PlaceLeft HorizontalPlacement = 1
	// PlaceCenter centers the block on the anchor.
	PlaceCenter HorizontalPlacement = 2
	// PlaceRight puts the right edge of the block at the anchor.
	PlaceRight HorizontalPlacement = 3

	// PlaceTop hangs the block below the anchor.
	PlaceTop VerticalPlacement = 1
	// PlaceMiddle centers the block on the anchor.
	PlaceMiddle VerticalPlacement = 2
	// PlaceBottom stands the block above the anchor.
	PlaceBottom VerticalPlacement = 3
)
View Source
const (
	// StageJob is the structural validity of the job tree and its limits.
	StageJob Stage = "job"
	// StagePath is path and font-file resolution.
	StagePath Stage = "path"
	// StageStyle is the values of the non-geometric appearance fields.
	StageStyle Stage = "style"
	// StageGeometry is page sizes and page totals.
	StageGeometry Stage = "geometry"

	// CodeInvalidJob means the job tree breaks a structural rule or limit.
	CodeInvalidJob Code = "job_invalid"
	// CodeBaseNotAbsolute means a base directory is not absolute.
	CodeBaseNotAbsolute Code = "base_not_absolute"
	// CodePathDriveRelative means a Windows path names a drive without a root (C:x).
	CodePathDriveRelative Code = "path_drive_relative"
	// CodePathRootedWithoutDrive means a Windows path has a root but no drive (\x or /x).
	CodePathRootedWithoutDrive Code = "path_rooted_without_drive"
	// CodeStyleInvalid means an appearance value is outside its domain.
	CodeStyleInvalid Code = "style_invalid"
	// CodeSizeUnresolved means a blank inherits a page size and no source page is available.
	CodeSizeUnresolved Code = "size_unresolved"
	// CodeSizeOutOfRange means the inherited page size is outside what a generated page can have.
	CodeSizeOutOfRange Code = "size_out_of_range"
	// CodeSourceEmpty means a source reports no pages.
	CodeSourceEmpty Code = "source_empty"
	// CodePageTotalExceeded means a page total passes the backend's integer boundary or the generated-page limit.
	CodePageTotalExceeded Code = "page_total_exceeded"
	// CodeFontUnavailable means no content identity was supplied for a font the job uses.
	CodeFontUnavailable Code = "font_unavailable"

	// MaxRelated bounds Error.Related.
	MaxRelated = 8
)
View Source
const (
	// MaxNodes bounds the structural nodes of a job: items (PDF paths, blanks, groups) and the blank, text,
	// and font objects that style them.
	MaxNodes = 250_000
	// MaxGroupDepth bounds the nesting of directory groups.
	MaxGroupDepth = 64
	// MaxContributions bounds the PDF and blank items after groups are flattened.
	MaxContributions = 100_000
	// MaxBlankCount bounds the pages of one blank item, so that a typo such as an extra digit cannot
	// ask for billions of pages.
	MaxBlankCount = 1_000_000
	// MaxGeneratedPages bounds the sum of all blank counts.
	MaxGeneratedPages = 1_000_000

	// ItemPDF is a source PDF.
	ItemPDF ItemKind = 1
	// ItemBlank is Count consecutive generated pages sharing one style.
	ItemBlank ItemKind = 2
	// ItemGroup is a directory prefix for nested items; it has no other effect on the sequence.
	ItemGroup ItemKind = 3
)
View Source
const (
	// SizeExplicit means the blank's size was written.
	SizeExplicit SizeSource = 1
	// SizeFromPrecedingLast means the blank took the last page of the nearest preceding source.
	SizeFromPrecedingLast SizeSource = 2
	// SizeFromFollowingFirst means a leading blank took the first page of the first source.
	SizeFromFollowingFirst SizeSource = 3
	// SizeFitTarget means implicit/inherit canvas resolution used the effective fit target directly.
	SizeFitTarget SizeSource = 4

	// RunSource is the pages of one source occurrence.
	RunSource RunKind = 1
	// RunGenerated is one distinct generated page repeated.
	RunGenerated RunKind = 2

	// MaxOutputPages bounds domain page-number arithmetic to signed 32 bits.
	// The selected backend applies its own, potentially smaller resource-policy limit.
	MaxOutputPages = math.MaxInt32
)
View Source
const (
	// PathStylePOSIX is the syntax of Linux and macOS: only "/" separates, and only a leading "/" anchors.
	PathStylePOSIX PathStyle = 1
	// PathStyleWindows is the syntax of Windows: "/" and "\" separate; a drive letter and colon, or two
	// leading separators (UNC, verbatim, and device paths), anchor.
	PathStyleWindows PathStyle = 2

	// PathRelative is anchored to a base directory.
	PathRelative PathClass = 1
	// PathAbsolute is anchored to the filesystem root: a POSIX "/x", a Windows "C:\x" or "C:/x", or a UNC
	// "\\server\share\x".
	PathAbsolute PathClass = 2
	// PathDriveRelative is a Windows "C:x": relative to the current directory of drive C, which depends on
	// process state outside the job.
	PathDriveRelative PathClass = 3
	// PathRootedWithoutDrive is a Windows "\x" or "/x": rooted on the current drive, which depends on
	// process state outside the job.
	PathRootedWithoutDrive PathClass = 4
)
View Source
const (

	// MaxLeading is the largest line height, as a multiple of the font size.
	MaxLeading float64 = 10
	// MinLeading is the smallest line height, as a multiple of the font size.
	MinLeading float64 = 1
	// MinFontSize is the smallest font size.
	MinFontSize Length = 1
	// MaxTextRunes is the longest text of one generated page, in Unicode scalar values.
	MaxTextRunes = 10000
)

Built-in appearance defaults for generated blanks, and the limits of the values.

View Source
const (
	// AlignLeft starts every line at the left edge of the block.
	AlignLeft TextAlign = 1
	// AlignCenter centers every line in the block.
	AlignCenter TextAlign = 2
	// AlignRight ends every line at the right edge of the block.
	AlignRight TextAlign = 3
	// AlignJustify stretches every line but the last of a paragraph to the block's width.
	AlignJustify TextAlign = 4

	// OverflowError rejects text that is too wide, too tall, or outside the page. It is the default.
	OverflowError Overflow = 1
	// OverflowAllow places the text as specified even when it extends beyond the page.
	OverflowAllow Overflow = 2
)
View Source
const DefaultFontName = "default"

DefaultFontName is the plan spelling of the built-in font.

Variables

View Source
var (
	// ErrInvalidLength reports text that is not a length.
	ErrInvalidLength = errors.New("invalid length")
	// ErrInvalidColor reports text that is not a color or background.
	ErrInvalidColor = errors.New("invalid color")
	// ErrInvalidPageSize reports text that is not a page size.
	ErrInvalidPageSize = errors.New("invalid page size")
	// ErrUnknownName reports a name that is not one of the allowed names of an enumeration.
	ErrUnknownName = errors.New("unknown name")
	// ErrOutOfRange reports a value outside its documented domain: not finite, too small, or too large.
	ErrOutOfRange = errors.New("value out of range")
	// ErrInvalidText reports text that is not valid UTF-8 or is too long.
	ErrInvalidText = errors.New("invalid text")
	// ErrInvalidPath reports a path that no filesystem can hold.
	ErrInvalidPath = errors.New("invalid path")
	// ErrInvalidJob reports a structural fault in a job: an empty sequence, a malformed item, or a crossed limit.
	ErrInvalidJob = errors.New("invalid job")
	// ErrUnresolvedSize reports a generated page that inherits its size when no source page is available.
	ErrUnresolvedSize = errors.New(`page size "inherit" has no source page to inherit from; give the blank an explicit size`)
)

Sentinel errors for the domain values. Every error returned by a parser or validator wraps one of them, so callers can classify a failure with errors.Is while the message stays specific.

View Source
var ErrBaseNotAbsolute = errors.New("base directory is not absolute")

ErrBaseNotAbsolute reports a base directory that is not an absolute path.

View Source
var ErrSourceGeometry = errors.New("source geometry does not match the flattened sources")

ErrSourceGeometry reports inspection results that do not match the flattened sources.

Functions

func AddCounts

func AddCounts(a, b, limit int64) (int64, error)

AddCounts returns a+b, or an error when either is negative or the sum exceeds limit. It is the checked addition for page totals, so a sum can neither wrap nor pass its declared bound.

func AlignNames

func AlignNames() []string

AlignNames lists the alignment names.

func AnchorNames

func AnchorNames() []string

AnchorNames lists the anchor names in grid order.

func CheckBlankCount

func CheckBlankCount(count int64) error

CheckBlankCount checks that count is between 1 and MaxBlankCount.

func CheckPathText

func CheckPathText(path string) error

CheckPathText rejects paths that JSON cannot represent losslessly or that no filesystem can hold.

func JoinDir

func JoinDir(dir, name string) string

JoinDir resolves name against the base directory dir lexically: an absolute name stands alone, an empty name is dir itself, and otherwise the two are joined with "/". No filesystem is consulted.

func OverflowNames

func OverflowNames() []string

OverflowNames lists the overflow policy names.

func PageSizeNames

func PageSizeNames() []string

PageSizeNames lists the paper names ParsePageSize accepts, in the order the documentation uses.

func ResolvePath

func ResolvePath(base, what, name string) (string, error)

ResolvePath resolves name against the absolute base directory base, lexically and under the rules of the host: an absolute name stands alone, and the result is cleaned. The text is a literal path, not a pattern or a URL, and no filesystem is consulted, so ".." is collapsed lexically. A name that depends on process state (a Windows "C:x" or "\x") is rejected, and what names the field in the message.

func ValidateTextValue

func ValidateTextValue(text string) error

ValidateTextValue checks that text is valid UTF-8 of at most MaxTextRunes characters.

Types

type Anchor

type Anchor uint8

Anchor selects the point on the page that a text block is attached to.

func ParseAnchor

func ParseAnchor(name string) (Anchor, error)

ParseAnchor resolves an anchor name (exact lower case).

func (Anchor) Horizontal

func (a Anchor) Horizontal() HorizontalPlacement

Horizontal returns the horizontal component of the anchor, which is its column in the grid.

func (Anchor) String

func (a Anchor) String() string

String returns the anchor's configuration name.

func (Anchor) Vertical

func (a Anchor) Vertical() VerticalPlacement

Vertical returns the vertical component of the anchor, which is its row in the grid.

type ArgumentSource

type ArgumentSource struct{}

ArgumentSource is the Source of jobs compiled from command-line operands. Ref N is the operand at zero-based position N, excluding the executable name.

func (ArgumentSource) Name

func (ArgumentSource) Name() string

Name returns "argv".

func (ArgumentSource) Pointer

func (ArgumentSource) Pointer(ref Ref, _ string) string

Pointer returns "argv:N" for operand N; member is ignored.

func (ArgumentSource) Position

func (ArgumentSource) Position(int64) (int, int)

Position returns 0, 0: operands have no line or column.

type BlankItem

type BlankItem struct {
	// Style layers over the job defaults.
	Style BlankStyle
	// CountOrigin locates the "count" value, or the item when the count is implicit.
	CountOrigin Origin
	// Count is the number of consecutive pages, 1 to MaxBlankCount (see CheckBlankCount).
	Count int64
}

BlankItem is the payload of an ItemBlank.

type BlankSpec

type BlankSpec struct {
	Text       TextSpec
	Dim        PageDim
	Background Fill
}

BlankSpec is a fully resolved, directly renderable blank page. It is comparable and carries no provenance, so identical blanks can be rendered once and reused.

func (BlankSpec) Validate

func (b BlankSpec) Validate() error

Validate checks every value of the spec, so that a directly constructed spec is as safe as a parsed one.

type BlankStyle

type BlankStyle struct {
	Text       TextStyle
	Size       Field[PageSize]
	Background Field[Fill]
}

BlankStyle is the partial, layerable description of a generated blank page. Layers combine with Over: per-item over plan defaults over the built-ins that Resolve applies.

func (*BlankStyle) IsZero

func (s *BlankStyle) IsZero() bool

IsZero reports whether no field is set.

func (*BlankStyle) Over

func (s *BlankStyle) Over(base *BlankStyle) BlankStyle

Over returns a style in which fields set on s win and the remaining fields come from base.

func (*BlankStyle) Resolve

func (s *BlankStyle) Resolve(inherited PageDim) (BlankSpec, error)

Resolve applies built-in defaults and the inherited page size, validating every value. inherited is the size of the neighboring source page; the zero PageDim means there is none.

type Code

type Code string

Code is a stable snake_case diagnostic identifier. Messages are not stable; codes are.

type Color

type Color struct {
	R, G, B uint8
}

Color is an sRGB color.

func ParseColor

func ParseColor(text string) (Color, error)

ParseColor parses #RGB or #RRGGBB (hexadecimal digits of either case).

func (Color) String

func (c Color) String() string

String formats the color as #RRGGBB.

type Contribution

type Contribution struct {
	// TextOverrides references the original item declarations, independent of appearance deduplication.
	TextOverrides *TextStyle
	// Path is the absolute, lexically cleaned path of a PDF; empty for a blank.
	Path string
	// Origin is the item that wrote the contribution; explain it with Locate.
	Origin Origin
	// Count is the number of pages of a blank; for a PDF it is 1, one occurrence of the source.
	Count int64
	// Index is the position of the contribution in Flattened.Contributions.
	Index int
	// File indexes Flattened.Files for a PDF and is -1 for a blank.
	File int
	// Style indexes Flattened.Styles for a blank and is -1 for a PDF.
	Style int
	Kind  ItemKind
}

Contribution is one PDF or blank entry of the flattened sequence. Counts stay compact: a blank of a million pages is one Contribution.

type Error

type Error struct {
	// Consumers lists every affected flattened contribution in instruction order.
	Consumers []Origin
	// Err is the underlying cause, matched by [errors.Is] and [errors.As].
	Err error
	// Message states what is wrong and how to repair it.
	Message string
	Code    Code
	Stage   Stage
	// Related locates further contributions with the same problem, in input order, at most MaxRelated.
	Related []Location
	// Location is where the problem was written; for a shared problem, its first contribution.
	Location Location
	// Affected is the number of contributions the problem applies to.
	Affected int64
}

Error is one located, coded problem found while resolving a job. Its shape matches the plan decoder's error: stage, code, location, and an actionable message.

func NewSharedError

func NewSharedError(src Source, origins []Origin, member string, template Error) *Error

NewSharedError builds an error about a problem shared by several contributions. It is located at the first of origins, with the following origins (at most MaxRelated) as related locations; member is appended to each node's pointer. template supplies Stage, Code, Err, Message, and Affected.

func (*Error) Error

func (d *Error) Error() string

Error formats the diagnostic as "location: message [code]".

func (*Error) Unwrap

func (d *Error) Unwrap() error

Unwrap returns the underlying cause.

type Errors

type Errors []*Error

Errors is every problem one resolution step found, in input order. It is the error those steps return, so a caller reports all problems rather than the first.

func Diagnostics

func Diagnostics(err error) Errors

Diagnostics returns the diagnostics carried by err: those of an Errors, or err alone as an uncoded error when it is any other error, and nil for a nil error.

func (Errors) Error

func (l Errors) Error() string

Error formats the first diagnostic and counts the rest.

func (Errors) Unwrap

func (l Errors) Unwrap() []error

Unwrap returns the diagnostics, so errors.Is and errors.As see every cause.

type Field

type Field[T comparable] struct {
	Value  T
	Origin Origin
	// contains filtered or unexported fields
}

Field is a value of a layered style together with where it was written. The zero Field is unset.

func Set

func Set[T comparable](value T, origin Origin) Field[T]

Set returns a set Field.

func (Field[T]) ApplyTo

func (f Field[T]) ApplyTo(target *T)

ApplyTo stores the held value in *target, and leaves *target alone when the field is unset.

func (Field[T]) IsSet

func (f Field[T]) IsSet() bool

IsSet reports whether the field holds a value.

func (Field[T]) Over

func (f Field[T]) Over(base Field[T]) Field[T]

Over returns f when it is set, otherwise base. The winner keeps its own Origin, so a resolved style can say which layer supplied each value.

type Fill

type Fill struct {
	Color   Color
	Painted bool
}

Fill is the background of a generated page: a color, or no painting. The zero value paints nothing.

func FillColor

func FillColor(color Color) Fill

FillColor returns a Fill that paints color.

func ParseFill

func ParseFill(text string) (Fill, error)

ParseFill parses a color, or "none" for a page that is not painted.

func (Fill) String

func (f Fill) String() string

String formats the fill the way ParseFill accepts it.

type FitTarget added in v0.2.0

type FitTarget string

FitTarget is an explicitly requested portrait paper target. The empty value means no fitting.

const (
	// FitA4 selects ISO A4 portrait.
	FitA4 FitTarget = "A4"
	// FitLegal selects US Legal portrait.
	FitLegal FitTarget = "Legal"
)

func ParseFitTarget added in v0.2.0

func ParseFitTarget(text string) (FitTarget, error)

ParseFitTarget accepts only the two supported spellings; dimensions come from namedPageSizes.

func (FitTarget) Dim added in v0.2.0

func (t FitTarget) Dim() (PageDim, error)

Dim resolves the authoritative named-paper dimensions.

type Flattened

type Flattened struct {
	// Source explains every Origin.
	Source Source
	// TextDefaults references the job defaults; callers must keep job declarations immutable.
	TextDefaults  *TextStyle
	Contributions []Contribution
	Files         []SourceFile
	Fonts         []FontFileUse
	Styles        []LayeredStyle
	// FitTo retains the effective global target declaration.
	FitTo Field[FitTarget]
	// GeneratedPages is the sum of the blank counts.
	GeneratedPages int64
}

Flattened is the job as an ordered list of contributions with its distinct sources, fonts, and appearances, each in order of first use. Resolve turns it into a Layout once the sources' page geometry is known.

func Flatten

func Flatten(job *Job) (*Flattened, error)

Flatten expands the job's groups into the ordered contributions in one pass, resolving every path against its group's directory. It does not expand counts, copy subtrees, or deduplicate anything in the sequence. It retains references to the job's text declarations for exact provenance; callers must not mutate those declarations while using the flattened job. Validation ensures every limit; the problems found while resolving paths and appearance values are returned together as a Errors.

func (*Flattened) Resolve

func (f *Flattened) Resolve(sources []SourceGeometry, fonts FontDigests) (*Layout, error)

Resolve takes the inspected sources (parallel to f.Files) and the loaded fonts' identities, and resolves every generated page's size, the distinct generated appearances, the output ranges and the compact runs. Leading blanks inherit the first page of the first source; every other blank inherits the last page of the nearest preceding source; an explicit size changes nothing for later blanks. All problems found are returned together as a Errors, in input order.

type Font

type Font struct {
	// File is the declared path of a font file; empty selects the built-in font.
	File string
	// Base is the directory File resolves against: the base of the scope that declared the font. It is
	// fixed where the font is declared, before any layering, so a font keeps its own base wherever it is used.
	Base string
}

Font selects the font of generated text: the built-in default, or a TrueType file. A font choice is one atomic value; it never layers member by member.

func FontFile

func FontFile(file, base string) (Font, error)

FontFile returns a file-backed font declared in a scope whose base directory is base.

func (Font) IsDefault

func (f Font) IsDefault() bool

IsDefault reports whether the font is the built-in one.

func (Font) String

func (f Font) String() string

String describes the font: its plan name, or its file path.

type FontDigest

type FontDigest [sha256.Size]byte

FontDigest is the SHA-256 identity of font file content.

type FontDigests

type FontDigests func(path string) (FontDigest, bool)

FontDigests returns the content identity of the font file at an absolute path, or of the built-in font for the empty path. It reports false when the font was not loaded.

type FontFileUse

type FontFileUse struct {
	// Path is the absolute, lexically cleaned path.
	Path string
	// Declarations are each distinct declaration of this captured file, in input order.
	Declarations []Origin
}

FontFileUse is one distinct font file a blank's text asks for.

type HorizontalPlacement

type HorizontalPlacement uint8

HorizontalPlacement is where a text block sits relative to its anchor's x coordinate.

type Item

type Item struct {
	// Items are the members of an ItemGroup; never empty.
	Items []Item
	// Path is the declared path of an ItemPDF, relative to its group's base unless absolute.
	Path string
	// Blank is set for an ItemBlank.
	Blank *BlankItem
	// Dir is the declared directory of an ItemGroup, relative to the enclosing base unless absolute.
	Dir    Field[string]
	Origin Origin
	Kind   ItemKind
}

Item is one entry of the ordered sequence.

func NewBlankItem

func NewBlankItem(origin Origin, style *BlankStyle, count int64) (Item, error)

NewBlankItem returns an ItemBlank of count pages.

func NewGroupItem

func NewGroupItem(origin Origin, dir string, items []Item) Item

NewGroupItem returns an ItemGroup holding items.

func NewPDFItem

func NewPDFItem(origin Origin, path string) Item

NewPDFItem returns an ItemPDF.

type ItemKind

type ItemKind uint8

ItemKind identifies a job item.

func (ItemKind) String

func (k ItemKind) String() string

String returns the kind's name.

type Job

type Job struct {
	// Source explains every Origin in the tree.
	Source Source
	// Items is the ordered sequence; never empty.
	Items []Item
	// Base is the initial base directory: the plan's directory, the --base-dir value, or the working
	// directory. Plan output and the default font resolve against it.
	Base string
	// Output is the declared output path; unset when the job names none. It resolves against Base.
	Output Field[string]
	// FitTo is the optional global portrait target.
	FitTo Field[FitTarget]
	// Dir is the declared directory for the top-level items, relative to Base.
	Dir Field[string]
	// Defaults is the style every blank layers over. Its font resolves against Base.
	Defaults BlankStyle
	// Origin is the root.
	Origin Origin
}

Job is the complete, unresolved description of an assembly. It is a bounded tree built once; flattening it into contributions is a separate step that keeps every Origin.

func NewOperandJob

func NewOperandJob(workingDir string, operands []Operand) (*Job, error)

NewOperandJob compiles ordered direct operands into the same Job a plan produces. Paths resolve against workingDir, which must be absolute; each Origin is the operand's argv position. The result is validated.

func (*Job) ItemsBase

func (j *Job) ItemsBase() string

ItemsBase is the directory the top-level items resolve against.

func (*Job) Validate

func (j *Job) Validate() error

Validate checks every structural bound and invariant of a job: non-empty sequences, valid kinds and counts, group depth, node and contribution limits, and the generated page total. It is the check for jobs built without the plan decoder, and the oracle for decoded ones.

type LayeredStyle

type LayeredStyle struct {
	Style BlankStyle
	// FirstUse is the first blank that has this appearance.
	FirstUse Origin
}

LayeredStyle is one distinct appearance after item over job defaults, before page sizes are known. Values deduplicate independently of declaration origins; each consumer retains its original declaration layer. A file font's effective path is absolute with no base.

type Layout

type Layout struct {
	Source Source
	Flat   *Flattened
	// Placements parallels Flat.Contributions.
	Placements []Placement
	Specs      []ResolvedSpec
	Runs       []Run
	Totals     Totals
}

Layout is the resolved output order: every contribution's pages, the distinct generated appearances, and the compact runs the engine assembles. Every sum was checked.

type Length

type Length float64

Length is a distance in PDF user-space units (points, 1/72 inch).

const (
	// MinPageSide is the smallest page side of a generated page.
	MinPageSide Length = 1

	// MaxPageSide is the largest page side of a generated page (the PDF implementation limit of 200 inches).
	MaxPageSide = MaxLength
)
const (
	// MaxLength bounds the magnitude of every length: the PDF implementation limit for page dimensions
	// (200 inches).
	MaxLength Length = 14400
)

func NewLength

func NewLength(points float64) (Length, error)

NewLength checks that points is finite and within ±MaxLength.

func ParseLength

func ParseLength(text string) (Length, error)

ParseLength parses a decimal number with an optional unit suffix (pt, mm, cm, in) and no surrounding space. A bare number is in points. The result is finite and within ±MaxLength.

func (Length) Validate

func (l Length) Validate() error

Validate reports whether the length is finite and within ±MaxLength.

type Location

type Location struct {
	Source  string
	Pointer string
	Offset  int64
	Line    int
	Column  int
}

Location is an Origin explained: where a value was written.

func Locate

func Locate(src Source, origin Origin, member string) Location

Locate explains origin in src. member is the pointer suffix of a field below the node ("" for the node itself), such as "/count" or "/blank/text/font".

func (Location) String

func (l Location) String() string

String formats the location as "name:line:column (byte N) at /pointer".

type Operand

type Operand struct {
	// Path is the PDF path, taken literally; unused for a blank.
	Path string
	// Position is the zero-based position of the argument in argv, excluding the executable name.
	Position int
	// Blank marks the --blank directive: one generated page that inherits its size.
	Blank bool
}

Operand is one ordered direct operand of the command line: a PDF path, or the --blank directive.

type Origin

type Origin struct {
	// Offset is the absolute byte offset of the value in the original document, including any
	// leading byte order mark. It is zero for command-line sources.
	Offset int64
	// Ref is the item (or the root) that contains the value.
	Ref Ref
}

Origin locates one value in the job's Source. It is small because every styled field carries one.

type Overflow

type Overflow uint8

Overflow is the policy for text that does not fit its box or page.

func ParseOverflow

func ParseOverflow(name string) (Overflow, error)

ParseOverflow resolves an overflow policy name (exact lower case).

func (Overflow) String

func (o Overflow) String() string

String returns the policy's configuration name.

type PageDim

type PageDim struct {
	Width, Height Length
}

PageDim is the displayed width and height of one page, in points.

func NewPageDim

func NewPageDim(width, height Length) (PageDim, error)

NewPageDim checks that both sides are finite and between MinPageSide and MaxPageSide.

func (PageDim) String

func (d PageDim) String() string

String formats the dimensions in points, such as "595.28x841.89pt".

func (PageDim) Validate

func (d PageDim) Validate() error

Validate checks that both sides are finite and between MinPageSide and MaxPageSide.

type PageGeometry

type PageGeometry struct {
	Width, Height float64
}

PageGeometry is the visible size of one source page in physical points.

type PageRange

type PageRange struct {
	Start, End, Count int64
}

PageRange is a run of output pages, 1-based and inclusive.

type PageSize

type PageSize struct {
	Dim     PageDim
	Inherit bool
}

PageSize describes the page size of a generated blank: either the size inherited from a neighboring source page or an explicit size.

func ParsePageSize

func ParsePageSize(text string) (PageSize, error)

ParsePageSize parses "inherit", a paper name (A3, A4, A5, B4, B5, Letter, Legal, Tabloid; portrait, exact case), or WIDTHxHEIGHT with an optional unit shared by both sides, such as 210x297mm or 8.5x11in.

func (PageSize) String

func (s PageSize) String() string

String formats the size: "inherit", or the dimensions in points.

func (PageSize) Validate

func (s PageSize) Validate() error

Validate checks an explicit size; an inherited size has nothing to check until it is resolved.

type PathClass

type PathClass uint8

PathClass says how a path is anchored.

func ClassifyPath

func ClassifyPath(style PathStyle, path string) PathClass

ClassifyPath says how path is anchored under the syntax rules of style. It reads the text only; it never consults a filesystem, so it makes no claim that a path means the same thing on another host.

type PathStyle

type PathStyle uint8

PathStyle is a family of path syntax rules. Classification is pure string work, so the rules of every style are testable on every host; only HostPathStyle ever decides a real resolution.

func HostPathStyle

func HostPathStyle() PathStyle

HostPathStyle returns the style of the running operating system.

type Placement

type Placement struct {
	// Range is the output pages the contribution covers.
	Range PageRange
	// Spec indexes Layout.Specs for a blank and is -1 for a PDF.
	Spec int
	// SizeFrom is the contribution whose page supplied an inherited size; -1 unless SizeSource is
	// not SizeExplicit.
	SizeFrom int
	// Size says how a blank got its size.
	Size SizeSource
}

Placement is the resolved position of one contribution in the output.

type Ref

type Ref uint32

Ref identifies a node of a job's source. A JSON plan numbers its nodes in reading order from the root (Ref 0); a command line numbers its operands from zero, excluding the executable name. The Source that created a job turns a Ref into a pointer.

type ResolvedSpec

type ResolvedSpec struct {
	// Origins locates the first contributions that use the spec, in input order, at most MaxRelated+1.
	Origins  []Origin
	Spec     BlankSpec
	Declared TextStyle
	// Uses is the number of contributions that use the spec.
	Uses       int64
	FontDigest FontDigest
}

ResolvedSpec is one distinct generated page appearance.

type Run

type Run struct {
	// Index is the Layout.Specs index of a generated run, or the Flattened.Files index of a source run.
	Index int
	// FirstPage is the first source page of a source run (always 1, whole files); 0 for a generated run.
	FirstPage int64
	// Count is the number of source pages, or the repeat count of a generated page.
	Count int64
	Kind  RunKind
}

Run is a compact piece of the output order for the engine.

type RunKind

type RunKind uint8

RunKind says what a Run covers.

type SizeSource

type SizeSource uint8

SizeSource says where a generated page got its size.

type Source

type Source interface {
	// Name is the file name, "<stdin>", "<inline>", or "argv".
	Name() string
	// Pointer returns the JSON pointer of the node (such as "/items/42/items/3"), with member appended
	// for a field of that node (such as "/count"), or "argv:N" for a command-line operand.
	Pointer(ref Ref, member string) string
	// Position returns the 1-based line and byte column of an offset, or 0, 0 when the source has none.
	Position(offset int64) (int, int)
}

Source describes the document a job was read from, so an Origin can be explained. Implementations are the plan decoder's document and ArgumentSource.

type SourceFile

type SourceFile struct {
	Path string
	// FirstUse is the first contribution that names the file.
	FirstUse Origin
	// Uses is the number of occurrences; repeated sources are never merged in the sequence.
	Uses int
}

SourceFile is one distinct source PDF, identified by its normalized path.

type SourceGeometry

type SourceGeometry struct {
	First, Last PageGeometry
	Pages       int64
}

SourceGeometry is what inspecting one source tells the layout: its page count and the visible geometry of its first and last pages.

type SpecKey

type SpecKey struct {
	Spec       BlankSpec
	FontDigest FontDigest
}

SpecKey identifies a distinct generated page: the resolved appearance plus the font's content.

type Stage

type Stage string

Stage names the phase that produced a diagnostic.

type TextAlign

type TextAlign uint8

TextAlign is the justification of lines within a text block.

func ParseTextAlign

func ParseTextAlign(name string) (TextAlign, error)

ParseTextAlign resolves an alignment name (exact lower case).

func (TextAlign) String

func (a TextAlign) String() string

String returns the alignment's configuration name.

type TextSpec

type TextSpec struct {
	Value    string
	Font     Font
	Size     Length
	X, Y     Length
	Width    Length
	Leading  float64
	Color    Color
	Anchor   Anchor
	Align    TextAlign
	Overflow Overflow
}

TextSpec is the fully resolved text of a blank. An empty Value means no text.

func (TextSpec) Validate

func (t TextSpec) Validate() error

Validate checks the text values.

type TextStyle

type TextStyle struct {
	Font     Field[Font]
	Value    Field[string]
	Size     Field[Length]
	Color    Field[Color]
	Anchor   Field[Anchor]
	X        Field[Length]
	Y        Field[Length]
	Width    Field[Length]
	Align    Field[TextAlign]
	Leading  Field[float64]
	Overflow Field[Overflow]
}

TextStyle is the partial, layerable description of the text printed on a blank. An empty Value means no text.

type Totals

type Totals struct {
	Source, Generated, Total int64
}

Totals are the page counts of an output.

type VerticalPlacement

type VerticalPlacement uint8

VerticalPlacement is where a text block sits relative to its anchor's y coordinate.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL