Documentation
¶
Overview ¶
Package function evaluates the PDF functions (ISO 32000-2 §7.10) that an axial shading reads, exactly as pdfium does: cpdf_function.cpp for parsing and dispatch, cpdf_expintfunc.cpp for type 2 (exponential interpolation), cpdf_stitchfunc.cpp for type 3 (stitching). Every value pdfium holds is a C++ float, so this package computes in float32 throughout rather than Go's more precise float64 -- matching the wrong precision is what makes the output equal, and a shading samples its function 256 times per axis, where float64 would drift from what pdfium drew.
Only a one-input function of type 2 or 3 is read. A shading's function always takes the single interpolation parameter t as its input (§8.7.4.5.3), so a function declared with any other /Domain length is refused rather than guessed at. Type 0 (sampled, a lookup table read from a stream) and type 4 (PostScript calculator, a tiny interpreted language) are real parts of the specification but neither has shown up on a shading function in this corpus; adding either without a measured case to check it against would be unverifiable, so both are refused by name instead of approximated.
A type 3 stitching function nests through /Functions, and nothing stops a producer from writing a cycle (a function whose own /Functions eventually names itself again) or a DAG deep enough that unfolding it costs far more than the file justifies, since a shared reference parsed once per edge rather than once per node is exponential in the graph's size. Parse bounds both: a recursion depth limit, which also happens to be what stops a cycle, since a cycle recurses forever if nothing else does; and a total count of functions parsed by one top-level call, which bounds the DAG case directly.
The caller (render/native) turns any error this package returns into a page refusal, so every message names what was wrong and starts "function: ".
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Func ¶
type Func struct {
// contains filtered or unexported fields
}
Func is a parsed one-input function: type 2 (exponential interpolation) or type 3 (stitching). Every number it holds is a float32, matching the precision pdfium evaluates in.