Skip to main content

Stroke

Struct Stroke 

Source
pub struct Stroke {
    pub color: Color,
    pub width: f64,
    pub cap: LineCap,
    pub join: LineJoin,
    pub miter_limit: MiterLimit,
    pub dash: Option<Dash>,
}
Expand description

A stroke’s colour, width and pen shape, in canvas units.

The fields stay public and every one but color and width has a default, so Stroke { cap: LineCap::Round, ..Stroke::new(color, 1.0) } works and the four settings ISO 32000-1 §8.4.3.3-§8.4.3.6 name are reachable without builder ceremony. Stroke::new keeps meaning what it always meant: PDF’s own defaults — butt cap, miter join, miter limit 10, no dash.

Fields§

§color: Color

The colour. Its alpha is honoured, as an /ExtGState /CA.

§width: f64

The line width in canvas units — page points.

§cap: LineCap

How the open ends of a subpath are drawn. J.

§join: LineJoin

How two segments meet at a corner. j.

§miter_limit: MiterLimit

Where a LineJoin::Miter corner becomes a bevel instead, as the ratio of miter length to line width. M.

§dash: Option<Dash>

The on/off pattern, or None for a solid line. d.

Implementations§

Source§

impl Stroke

Source

pub fn new(color: Color, width: f64) -> Self

A solid stroke of color at width points, with PDF’s default pen: butt cap, miter join, miter limit 10.

let hairline = pdfrum::Stroke::new(pdfrum::Color::BLACK, 0.5);
assert_eq!(hairline.width, 0.5);
assert_eq!(hairline.cap, pdfrum::LineCap::Butt);
assert!(hairline.dash.is_none());
Source

pub fn with_cap(self, cap: LineCap) -> Self

The same stroke with cap at its open ends.

use pdfrum::{Color, LineCap, Stroke};

let round = Stroke::new(Color::BLACK, 4.0).with_cap(LineCap::Round);
assert_eq!(round.cap, LineCap::Round);
Source

pub fn with_join(self, join: LineJoin) -> Self

The same stroke with join at its corners.

use pdfrum::{Color, LineJoin, Stroke};

let soft = Stroke::new(Color::BLACK, 4.0).with_join(LineJoin::Round);
assert_eq!(soft.join, LineJoin::Round);
Source

pub fn with_miter_limit(self, limit: MiterLimit) -> Self

The same stroke with limit on its miter joins.

use pdfrum::{Color, MiterLimit, Stroke};

let blunt = Stroke::new(Color::BLACK, 4.0).with_miter_limit(MiterLimit::new(2.0));
assert_eq!(blunt.miter_limit.get(), 2.0);
Source

pub fn with_dash(self, dash: Dash) -> Self

The same stroke dashed by dash.

use pdfrum::{Color, Dash, Stroke};

let dashed = Stroke::new(Color::BLACK, 1.0)
    .with_dash(Dash::new(&[4.0, 2.0], 0.0).expect("a valid dash"));
assert!(dashed.dash.is_some());

Trait Implementations§

Source§

impl Clone for Stroke

Source§

fn clone(&self) -> Stroke

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 Stroke

Source§

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

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

impl PartialEq for Stroke

Source§

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

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