function

package
v1.1.1 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: MIT Imports: 4 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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.

func Parse

func Parse(s objects.Store, o objects.Object) (*Func, error)

Parse reads the function o (a dictionary, a stream, or a reference to either).

func (*Func) Call

func (f *Func) Call(x float32, out []float32)

Call evaluates f at x and writes Outputs() values to out, which must be at least that long.

func (*Func) Outputs

func (f *Func) Outputs() int

Outputs is how many values Call writes.

Jump to

Keyboard shortcuts

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