Skip to main content

Function

Enum Function 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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

Source

pub fn input_count(&self) -> usize

How many inputs the function takes.

Source

pub fn output_count(&self) -> usize

How many outputs the function produces.

Source

pub fn domain(&self) -> &[f32]

The input intervals, [lo0, hi0, lo1, hi1, …].

Source

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.

Source

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);
Source

pub fn eval_into(&self, input: &[f32], out: &mut [f32]) -> usize

Evaluate, returning the number of outputs written and 0 on any failure.

This is the shape every colorspace and shading call site wants: the C++ returns an optional count, and zero means “paint nothing”.

Trait Implementations§

Source§

impl Clone for Function

Source§

fn clone(&self) -> Function

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Function

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl PartialEq for Function

Source§

fn eq(&self, other: &Function) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Function

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, S> SimdFrom<T, S> for T
where S: Simd,

Source§

fn simd_from(_simd: S, value: T) -> T

Source§

impl<F, T, S> SimdInto<T, S> for F
where T: SimdFrom<F, S>, S: Simd,

Source§

fn simd_into(self, simd: S) -> T

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.