Skip to main content

Policy

Struct Policy 

Source
#[non_exhaustive]
pub struct Policy { pub unembeddable_font: Concession, pub unrepresentable_content: Concession, pub forbidden_feature: Concession, }
Expand description

What the conversion is permitted to do to a document it cannot convert faithfully.

Every field defaults to Concession::Refuse, so Policy::default() is the strict policy: convert what can be converted losslessly and refuse anything else. Widening it is an explicit act per axis.

The axes are separate because a caller’s answers genuinely differ between them — an archive may accept a substituted font (the text stays text, and stays searchable) while refusing a rasterized page (the text stops being text at all).

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§unembeddable_font: Concession

A font that is used for rendering, is not embedded, and whose program we do not have.

Refusing stops the conversion and names the font, because an unembedded font is a hard PDF/A failure that no amount of other repair will fix.

Accepting is meant to substitute a standard font of the same broad shape. That repair is not implemented yet, so today accepting means “convert as far as you can”: every other repair applies, the font stays unembedded, and no Compromise is reported because nothing was compromised. It is the honest reading of Accept until the substitution lands.

§unrepresentable_content: Concession

Content the level forbids outright and that cannot be rewritten — transparency under A-1b being the case.

Refusing stops the conversion and names the page. Only A-1b can reach this: A-2b permits transparency, so nothing there is unrepresentable.

Accepting is meant to rasterize the offending page — faithful to the appearance, and destroying the text, the vectors and the selectability. That repair is not implemented yet, so accepting reads as “convert as far as you can” exactly as Policy::unembeddable_font does, and Conversion::rasterized_pages is always empty for now.

§forbidden_feature: Concession

An annotation or action of a kind PDF/A forbids.

Accepting removes it — the JavaScript, the /Launch action, the /Movie annotation. Refusing stops the conversion. This is separated from the two above because it is the one most callers do want: a launch action in an archived file is a liability, not content, and stripping it is the point of archiving rather than a loss.

It also covers one repair that adds rather than removes: PDF/A requires every annotation be visible and printable, so an annotation hidden by its /F flags has them cleared and becomes visible. That changes what the page draws, which is why it needs permission and reports Compromise::AnnotationFlagsChanged.

Implementations§

Source§

impl Policy

Source

pub const fn strict() -> Self

Refuse every compromise: convert only what converts losslessly.

The same as Policy::default(), named so a caller can say what they mean at the call site.

Source

pub const fn lossy() -> Self

Accept every compromise the pipeline knows how to make.

The archivist’s policy: produce a conforming file and tell me what it cost. Every compromise still lands in Conversion::compromises — the difference from Policy::strict is what stops the conversion, never what goes unreported.

Source

pub const fn unembeddable_font(self, concession: Concession) -> Self

This policy with Policy::unembeddable_font set.

The struct is #[non_exhaustive] so that a concession added later is not a breaking change for callers — which also means a caller cannot write a struct literal. These three are how a policy is built from one of the two named starting points:

use pdfrum_doc::pdfa::{Concession, Policy};

// Strip what PDF/A forbids, but never substitute a font behind my back.
let policy = Policy::strict().forbidden_feature(Concession::Accept);
assert!(policy.forbidden_feature.accepts());
assert!(!policy.unembeddable_font.accepts());
Source

pub const fn unrepresentable_content(self, concession: Concession) -> Self

This policy with Policy::unrepresentable_content set.

Source

pub const fn forbidden_feature(self, concession: Concession) -> Self

This policy with Policy::forbidden_feature set.

Trait Implementations§

Source§

impl Clone for Policy

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 Copy for Policy

Source§

impl Debug for Policy

Source§

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

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

impl Default for Policy

Source§

fn default() -> Self

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

impl Eq for Policy

Source§

impl PartialEq for Policy

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 Policy

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