Skip to main content

FieldSpec

Struct FieldSpec 

Source
pub struct FieldSpec { /* private fields */ }
Expand description

A form field to create.

The name is the field’s identity: ISO 32000-1 §12.7.3.2 makes the fully qualified name what an action, an export or a script addresses a field by, and Form::field is the only lookup the reader offers. So a name that is already taken is refused rather than silently merged into the existing field — see Error::DuplicateFieldName.

use kurbo::Rect;
use pdfrum_edit::{FieldKindSpec, FieldSpec};

let spec = FieldSpec::new("email", Rect::new(72.0, 700.0, 300.0, 720.0), FieldKindSpec::Text)
    .max_len(64)
    .tooltip("Your email address")
    .required(true);
assert_eq!(spec.name(), "email");

Implementations§

Source§

impl FieldSpec

Source

pub fn new(name: impl Into<String>, rect: Rect, kind: FieldKindSpec) -> Self

A field of kind named name, drawn in rect in default user space.

For a FieldKindSpec::Radio group rect is the rectangle the field reports; each button carries its own, so pass the group’s bounding box or any rectangle — the buttons are what a reader draws.

Source

pub fn name(&self) -> &str

The name this field will be addressed by.

Source

pub fn value(self, value: impl Into<String>) -> Self

/V: the field’s initial value.

For a text field this is the text. For a check box or a radio group it is a state name — the on-state of the box, or the export value of the button to select — and anything else leaves the control clear, exactly as Off would.

Source

pub fn default_value(self, value: impl Into<String>) -> Self

/DV: the value a reset action restores.

Defaults to Self::value when that is set, since a field whose initial value resets to empty is rarely what an author means.

Source

pub fn tooltip(self, text: impl Into<String>) -> Self

/TU: the tooltip a reader shows, and the accessible name a screen reader announces.

Source

pub fn da(self, da: impl Into<String>) -> Self

/DA: the appearance string the value is laid out with.

Defaults to DEFAULT_FIELD_DA. A /DA naming a face that is not in the form’s /DR falls back to a substituted one at draw time rather than failing, so a caller who embeds a face should name it here and register it with add_form_font.

Source

pub fn max_len(self, max: i64) -> Self

/MaxLen: the longest value the field accepts, in characters.

Text fields only; ignored on a button. Setting it is also what turns the comb flag (bit 25) into evenly spaced cells, which is why the two are usually written together.

Source

pub fn read_only(self, yes: bool) -> Self

/Ff bit 1: the field may not be changed.

Source

pub fn required(self, yes: bool) -> Self

/Ff bit 2: the field must have a value when the form is submitted.

Source

pub fn multiline(self, yes: bool) -> Self

/Ff bit 13: the text field accepts more than one line.

Text fields only.

Source

pub fn password(self, yes: bool) -> Self

/Ff bit 14: the text field masks what is typed.

Text fields only.

Source

pub fn comb(self, yes: bool) -> Self

/Ff bit 25: the text field is divided into Self::max_len evenly spaced cells.

The comb flag has no meaning without a /MaxLen, and the reader’s layout ignores it when there is none.

Source

pub fn flags(self, bits: i64) -> Self

Any further /Ff bits, as FieldFlags::bits reports them.

The named setters above cover the bits a caller reaches for; this is the escape hatch for the rest, and for round-tripping a flag word read off an existing field.

Source

pub fn appearance(self, appearance: WidgetAppearance) -> Self

/MK: the background, border and caption the widget is drawn with.

A field with no /MK has no background and no visible border — the chrome generator paints only what /MK names — so a field meant to look like a box wants at least a WidgetAppearance::border.

Trait Implementations§

Source§

impl Clone for FieldSpec

Source§

fn clone(&self) -> Self

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 FieldSpec

Source§

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

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

impl PartialEq for FieldSpec

Source§

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

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> Same for T

Source§

type Output = T

Should always be Self
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<U, T> ToOwnedObj<U> for T
where U: FromObjRef<T>,

Source§

fn to_owned_obj(&self, data: FontData<'_>) -> U

Convert this type into T, using the provided data to resolve any offsets.
Source§

impl<U, T> ToOwnedTable<U> for T
where U: FromTableRef<T>,

Source§

fn to_owned_table(&self) -> U

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.