Skip to main content

Form

Struct Form 

Source
pub struct Form {
    pub fields: Vec<Field>,
    pub need_appearances: bool,
}
Expand description

Every terminal field of a document’s interactive form.

Loaded once from the catalog; the walk is the expensive part and nothing below repeats it.

Fields§

§fields: Vec<Field>

The terminal fields, in the order the /Fields tree reaches them.

§need_appearances: bool

Whether the form asks a reader to regenerate every widget’s appearance (/NeedAppearances).

Implementations§

Source§

impl Form

Source

pub fn load<R: Resolve>( catalog: &Dict, r: &R, limits: &Limits, diags: &mut Diagnostics, ) -> Option<Form>

Loads the document’s form, or nothing when the catalog declares none.

A catalog with an /AcroForm whose /Fields is absent or empty still yields a Form — an empty form is a different thing from no form, and only the second means “this document is not interactive”.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::form::Form;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object, PdfString};

let field = Dict::from_pairs([
    (Name::from("FT"), Object::Name(Name::from("Tx"))),
    (Name::from("T"), Object::Str(PdfString::literal(b"name"))),
    (Name::from("V"), Object::Str(PdfString::literal(b"Ada"))),
]);
let catalog = Dict::from_pairs([(
    Name::from("AcroForm"),
    Object::Dict(Dict::from_pairs([(
        Name::from("Fields"),
        Object::Array(Array::of([Object::Dict(field)])),
    )])),
)]);

let mut diags = Diagnostics::default();
let form = Form::load(&catalog, &NoResolve, &Limits::default(), &mut diags)
    .expect("the catalog declares an /AcroForm");

assert_eq!(form.len(), 1);
assert_eq!(form.fields[0].name, "name");
Source

pub fn len(&self) -> usize

How many terminal fields the form has.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::form::Form;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object, PdfString};

let field = Dict::from_pairs([
    (Name::from("FT"), Object::Name(Name::from("Tx"))),
    (Name::from("T"), Object::Str(PdfString::literal(b"name"))),
]);
let catalog = Dict::from_pairs([(
    Name::from("AcroForm"),
    Object::Dict(Dict::from_pairs([(
        Name::from("Fields"),
        Object::Array(Array::of([Object::Dict(field)])),
    )])),
)]);

let mut diags = Diagnostics::default();
let form = Form::load(&catalog, &NoResolve, &Limits::default(), &mut diags)
    .expect("the catalog declares an /AcroForm");

assert_eq!(form.len(), 1);
Source

pub fn is_empty(&self) -> bool

Whether the form has no fields at all.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::form::Form;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object, PdfString};

let field = Dict::from_pairs([
    (Name::from("FT"), Object::Name(Name::from("Tx"))),
    (Name::from("T"), Object::Str(PdfString::literal(b"name"))),
]);
let catalog = Dict::from_pairs([(
    Name::from("AcroForm"),
    Object::Dict(Dict::from_pairs([(
        Name::from("Fields"),
        Object::Array(Array::of([Object::Dict(field)])),
    )])),
)]);

let mut diags = Diagnostics::default();
let form = Form::load(&catalog, &NoResolve, &Limits::default(), &mut diags)
    .expect("the catalog declares an /AcroForm");

assert!(!form.is_empty());
Source

pub fn field(&self, name: &str) -> Option<&Field>

The field with this fully-qualified name.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::form::Form;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object, PdfString};

let field = Dict::from_pairs([
    (Name::from("FT"), Object::Name(Name::from("Tx"))),
    (Name::from("T"), Object::Str(PdfString::literal(b"name"))),
    (Name::from("V"), Object::Str(PdfString::literal(b"Ada"))),
]);
let catalog = Dict::from_pairs([(
    Name::from("AcroForm"),
    Object::Dict(Dict::from_pairs([(
        Name::from("Fields"),
        Object::Array(Array::of([Object::Dict(field)])),
    )])),
)]);

let mut diags = Diagnostics::default();
let form = Form::load(&catalog, &NoResolve, &Limits::default(), &mut diags)
    .expect("the catalog declares an /AcroForm");

assert!(form.field("name").is_some());
assert!(form.field("absent").is_none());
Source

pub fn calculation_order<R: Resolve>(&self, catalog: &Dict, r: &R) -> Vec<usize>

The order a recalculation visits fields in, read from /AcroForm /CO.

Indices into Form::fields, in the order the array lists them.

§An absent /CO is the answer, not a fallback

A document with no /CO array recalculates nothing, however many of its fields carry an /AA /C script: the sweep that drives calculation walks exactly this list and nothing else. So an empty answer here is “no calculation runs”, and a reader tempted to fall back to “every field, in /Fields order” would recalculate documents that must be left alone — visibly, on any file with a calculation script and no /CO.

Entries that resolve to nothing, to a non-dictionary, or to a dictionary that is not one of this form’s terminal fields are dropped. Duplicates are kept: the array is the order, and it is indexed positionally.

use pdfrum_common::{Diagnostics, Limits};
use pdfrum_doc::form::Form;
use pdfrum_object::{Array, Dict, Name, NoResolve, Object, PdfString};

let field = Dict::from_pairs([
    (Name::from("FT"), Object::Name(Name::from("Tx"))),
    (Name::from("T"), Object::Str(PdfString::literal(b"name"))),
    (Name::from("V"), Object::Str(PdfString::literal(b"Ada"))),
]);
let catalog = Dict::from_pairs([(
    Name::from("AcroForm"),
    Object::Dict(Dict::from_pairs([(
        Name::from("Fields"),
        Object::Array(Array::of([Object::Dict(field)])),
    )])),
)]);

let mut diags = Diagnostics::default();
let form = Form::load(&catalog, &NoResolve, &Limits::default(), &mut diags)
    .expect("the catalog declares an /AcroForm");

// No `/CO`: nothing recalculates. That is the answer, not a fallback.
assert!(form.calculation_order(&catalog, &NoResolve).is_empty());

Trait Implementations§

Source§

impl Clone for Form

Source§

fn clone(&self) -> Form

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 Form

Source§

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

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

impl Default for Form

Source§

fn default() -> Form

Returns the “default value” for a type. Read more
Source§

impl PartialEq for Form

Source§

fn eq(&self, other: &Form) -> 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 Form

Auto Trait Implementations§

§

impl Freeze for Form

§

impl RefUnwindSafe for Form

§

impl Send for Form

§

impl Sync for Form

§

impl Unpin for Form

§

impl UnsafeUnpin for Form

§

impl UnwindSafe for Form

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> 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.