Documentation
¶
Overview ¶
Package pdf is the Prism PDF renderer. It walks the Scene IR directly and emits PDF drawing primitives via github.com/signintech/gopdf (D088). Vector preserved throughout: no SVG → PNG bridge, no rasterisation; every mark dispatches to a per-geom handler that emits PDF path / curve / image operators.
Default fonts (Inter regular + bold, JetBrains Mono regular — D089) are bundled under render/pdf/fonts/ as TTF subsets embedded at compile time via go:embed. The --font-dir CLI flag lets users override with their own .ttf set; missing canonical names fall back to the bundle.
Multi-page output via RenderOpts.Paginate: a SceneGrid with N cells produces an N-page PDF when Paginate is true; otherwise the whole grid renders to a single page sized to the outer frame.
Theme handoff per D090: PDF reads SceneDoc.Theme RGB triplets directly (NOT the Theme.CSS string the JS port consumes). Alpha per D091: per-mark alpha applied via ExtGState; gradient fills flatten to the first stop with PRISM_WARN_PDF_GRADIENT_FLATTENED appended to SceneDoc.Warnings.
Index ¶
Constants ¶
const ( FontSansRegular = "prism-sans-regular" FontSansBold = "prism-sans-bold" FontMonoRegular = "prism-mono-regular" )
Canonical font names registered into every PDF. Renderers reference these by name through gopdf.SetFont; the bundled .ttf files (or any override loaded via WithFontDir) supply the actual glyph bytes.
Variables ¶
This section is empty.
Functions ¶
func ApplyGradientFlatten ¶
func ApplyGradientFlatten(pdf *gopdf.GoPdf, g scene.Gradient, markType scene.MarkType) (code, gradientID string)
ApplyGradientFlatten paints a flattened-to-first-stop solid fill and returns the canonical warning code so the caller can attach it to SceneDoc.Warnings. PDF backend (signintech/gopdf v0.36) lacks a public axial / radial gradient API, so every gradient flattens.
Warning code is chosen based on the gradient shape so consumers can distinguish the "expected" linear/radial flatten path from the "unsupported geometry" angular / text paths.
Exported so per-mark renderers can opt in incrementally as their fill resolvers gain gradient awareness; the marks dispatcher does not call it directly yet.
Types ¶
type Option ¶
type Option func(*Renderer)
Option mutates a Renderer at construction time.
func WithFontDir ¶
WithFontDir overrides the bundled fonts. Files named prism-sans-regular.ttf / prism-sans-bold.ttf / prism-mono-regular.ttf inside the dir take precedence; a case-insensitive scan handles common upstream names (Inter-*.ttf, JetBrainsMono-*.ttf).
type Renderer ¶
type Renderer struct {
// contains filtered or unexported fields
}
Renderer is the PDF implementation of render.Renderer. Stateless between calls; safe to share across goroutines (gopdf state is created fresh inside Render).
func New ¶
New returns a PDF renderer configured by the supplied options. Zero options = bundled fonts, default page size from the SceneDoc's outer frame.
func (*Renderer) Render ¶
Render implements render.Renderer. Walks the SceneDoc top-down:
- SceneGrid → AddPage per cell (Paginate=true) or one outer page with all cells (Paginate=false)
- Scene → applyTheme background fill (when non-transparent)
- SceneLayer → ordered by slice index (D052)
- Mark → renderMark dispatches to one of nine per-geom handlers
Warnings raised at render time (gradient flatten, unsupported path commands recovered as partial output) append to doc.Warnings — the caller surfaces them.