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
impl Dash
Sourcepub fn new(lengths: &[f64], phase: f64) -> Option<Self>
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());