Skip to main content

Dash

Struct Dash 

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

A dash pattern — ISO 32000-1 §8.4.3.6’s dash array and phase, written as d.

§Why construction is fallible

d is one of the few graphics-state operators a reader may reject outright: a negative length, or an array summing to zero, is not a degenerate dash but an invalid one, and a viewer that refuses it refuses the whole content stream — every later operator with it. So an invalid array is caught here, at construction, rather than normalized into a pattern the caller did not ask for and cannot see. Dash::new returns None and nothing reaches the stream.

A solid line is spelled Stroke::dash = None, so an empty array is refused too: it has a valid PDF spelling, but it means the thing the Option already says.

Implementations§

Source§

impl Dash

Source

pub fn new(lengths: &[f64], phase: f64) -> Option<Self>

A dash of alternating on/off lengths, starting phase units into the pattern.

None if lengths is empty, holds anything negative or not finite, or sums to zero, or if phase is negative or not finite — each of which is an invalid d operand rather than an unusual one.

use pdfrum::Dash;

assert!(Dash::new(&[4.0, 2.0], 0.0).is_some());
assert!(Dash::new(&[4.0, -2.0], 0.0).is_none());
assert!(Dash::new(&[0.0, 0.0], 0.0).is_none());
assert!(Dash::new(&[], 0.0).is_none());
Source

pub fn lengths(&self) -> &[f64]

The alternating on/off lengths.

let dash = pdfrum::Dash::new(&[3.0, 1.0], 0.5).expect("a valid dash");
assert_eq!(dash.lengths(), &[3.0, 1.0]);
assert_eq!(dash.phase(), 0.5);
Source

pub fn phase(&self) -> f64

How far into the pattern the line starts.

Trait Implementations§

Source§

impl Clone for Dash

Source§

fn clone(&self) -> Dash

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 Dash

Source§

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

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

impl PartialEq for Dash

Source§

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

Auto Trait Implementations§

§

impl Freeze for Dash

§

impl RefUnwindSafe for Dash

§

impl Send for Dash

§

impl Sync for Dash

§

impl Unpin for Dash

§

impl UnsafeUnpin for Dash

§

impl UnwindSafe for Dash

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