#[non_exhaustive]pub enum Function {
Sampled(Sampled),
Exponential(Exponential),
Stitching(Stitching),
PostScript(PostScript),
}Expand description
A loaded PDF function.
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Sampled(Sampled)
Type 0: samples on a regular grid, interpolated.
Exponential(Exponential)
Type 2: C0 + x^N * (C1 - C0).
Stitching(Stitching)
Type 3: sub-functions stitched over sub-intervals of the domain.
PostScript(PostScript)
Type 4: a small PostScript calculator program.
Implementations§
Source§impl Function
impl Function
Sourcepub fn input_count(&self) -> usize
pub fn input_count(&self) -> usize
How many inputs the function takes.
Sourcepub fn output_count(&self) -> usize
pub fn output_count(&self) -> usize
How many outputs the function produces.
Sourcepub fn range(&self) -> &[f32]
pub fn range(&self) -> &[f32]
The output intervals, empty when /Range was absent.
An empty range skips output clamping entirely, which is how a type 2 function with a negative exponent can return an infinity.
Sourcepub fn eval(&self, input: &[f32], out: &mut [f32]) -> Result<(), Error>
pub fn eval(&self, input: &[f32], out: &mut [f32]) -> Result<(), Error>
Evaluate the function.
§Errors
Error::FunctionArity when input.len() is not the declared input
count or out is shorter than the declared output count, and
Error::FunctionInterval when a /Domain or /Range interval has
its bounds the wrong way round — both of which PDFium reports by
returning “no result” and painting nothing.
let dict = Dict::from_pairs([
(Name::from("FunctionType"), Object::Int(2)),
(Name::from("Domain"), Object::Array(Array::of([Object::Int(0), Object::Int(1)]))),
(Name::from("N"), Object::Int(1)),
]);
let mut cache = FunctionCache::new();
let mut diags = Diagnostics::default();
let f = cache
.load(&Object::Dict(dict), &NoResolve, &Limits::default(), &mut diags)
.expect("a type 2 function");
let mut out = [0.0f32];
f.eval(&[0.25], &mut out).expect("evaluates");
assert!((out[0] - 0.25).abs() < 1e-6);