{"modulePath":"github.com/model-harness/pdftools","version":"v1.3.0","isLatest":true,"isStandardLibrary":false,"goos":"all","goarch":"all","docs":"# package function\n\nPackage 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.\n\nOnly 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.\n\nA 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.\n\nThe caller (render/native) turns any error this package returns into a page refusal, so every message names what was wrong and starts \"function: \".\n\n## Types\n\n```go\ntype Func struct {\n\t// contains filtered or unexported fields\n}\n```\nFunc 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.\n\n```go\nfunc Parse(s objects.Store, o objects.Object) (*Func, error)\n```\nParse reads the function o (a dictionary, a stream, or a reference to either).\n\n```go\nfunc (f *Func) Call(x float32, out []float32)\n```\nCall evaluates f at x and writes Outputs() values to out, which must be at least that long.\n\n```go\nfunc (f *Func) Outputs() int\n```\nOutputs is how many values Call writes.\n\n","path":"github.com/model-harness/pdftools/function","name":"function","synopsis":"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).","isRedistributable":true}
