Skip to main content

PathEncoder

Struct PathEncoder 

Source
pub struct PathEncoder<'a> { /* private fields */ }
Expand description

Encoder for path segments.

Implementations§

Source§

impl<'a> PathEncoder<'a>

Source

pub fn new( tags: &'a mut Vec<PathTag>, data: &'a mut Vec<u32>, n_segments: &'a mut u32, n_paths: &'a mut u32, is_fill: bool, ) -> Self

Creates a new path encoder for the specified path tags and data.

If is_fill is true, ensures that all subpaths are closed. Otherwise, the path is treated as a stroke and an additional “stroke cap marker” segment is inserted at the end of every subpath.

§Stroke Encoding

Every subpath within a stroked path is terminated with a “stroke cap marker” segment. This segment tells the GPU stroker whether to draw a cap or a join based on the topology of the path:

  1. This marker segment is encoded as a quad-to (2 additional points) for an open path and a line-to (1 additional point) for a closed path. An open path gets drawn with a start and end cap. A closed path gets drawn with a single join in place of the caps where the subpath’s start and end control points meet.

  2. The marker segment tells the GPU flattening stage how to render caps and joins while processing each path segment in parallel. All subpaths end with the marker segment which is the only segment that has the SUBPATH_END_BIT set to 1.

    The algorithm is as follows:

    • If a GPU thread is processing a regular segment (i.e. SUBPATH_END_BIT is 0), it outputs the offset curves for the segment. If the segment is immediately followed by the marker segment, then the same thread draws an end cap if the subpath is open (i.e. the marker is a quad-to) or a join if the subpath is closed (i.e. the marker is a line-to) using the tangent encoded in the marker segment. If the segment is immediately followed by another regular segment, then the thread draws a join using the start tangent of the neighboring segment.

    • If a GPU thread is processing the marker segment (i.e. SUBPATH_END_BIT is 1), then it draws a start cap using the information encoded in the segment IF the subpath is open (i.e. the marker is a quad-to). If the subpath is closed (i.e. the marker is a line-to), the thread draws nothing.

Source

pub fn move_to(&mut self, x: f32, y: f32)

Encodes a move, starting a new subpath.

Source

pub fn line_to(&mut self, x: f32, y: f32)

Encodes a line.

Source

pub fn quad_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32)

Encodes a quadratic bezier.

Source

pub fn cubic_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x3: f32, y3: f32)

Encodes a cubic bezier.

Source

pub fn close(&mut self)

Closes the current subpath.

Source

pub fn shape(&mut self, shape: &impl Shape)

Encodes a shape.

Source

pub fn path_elements(&mut self, path: impl Iterator<Item = PathEl>)

Encodes a path iterator

Source

pub fn finish(self, insert_path_marker: bool) -> u32

Completes path encoding and returns the actual number of encoded segments.

If insert_path_marker is true, encodes the PathTag::PATH tag to signify the end of a complete path object. Setting this to false allows encoding multiple paths with differing transforms for a single draw object.

Trait Implementations§

Source§

impl OutlinePen for PathEncoder<'_>

Source§

fn move_to(&mut self, x: f32, y: f32)

Emit a command to begin a new subpath at (x, y).
Source§

fn line_to(&mut self, x: f32, y: f32)

Emit a line segment from the current point to (x, y).
Source§

fn quad_to(&mut self, cx0: f32, cy0: f32, x: f32, y: f32)

Emit a quadratic bezier segment from the current point with a control point at (cx0, cy0) and ending at (x, y).
Source§

fn curve_to(&mut self, cx0: f32, cy0: f32, cx1: f32, cy1: f32, x: f32, y: f32)

Emit a cubic bezier segment from the current point with control points at (cx0, cy0) and (cx1, cy1) and ending at (x, y).
Source§

fn close(&mut self)

Emit a command to close the current subpath.

Auto Trait Implementations§

§

impl<'a> !UnwindSafe for PathEncoder<'a>

§

impl<'a> Forget for PathEncoder<'a>

§

impl<'a> Freeze for PathEncoder<'a>
where &'a mut Vec<PathTag>: Freeze, &'a mut Vec<u32>: Freeze, &'a mut u32: Freeze,

§

impl<'a> Move for PathEncoder<'a>

§

impl<'a> RefUnwindSafe for PathEncoder<'a>

§

impl<'a> Send for PathEncoder<'a>
where RawVecInner: Send,

§

impl<'a> Sync for PathEncoder<'a>
where RawVecInner: Sync,

§

impl<'a> Unpin for PathEncoder<'a>
where &'a mut Vec<PathTag>: Unpin, &'a mut Vec<u32>: Unpin, &'a mut u32: Unpin,

§

impl<'a> UnsafeUnpin for PathEncoder<'a>
where &'a mut Vec<PathTag>: UnsafeUnpin, &'a mut Vec<u32>: UnsafeUnpin, &'a mut u32: UnsafeUnpin,

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<P> CommandSink for P
where P: OutlinePen,

Source§

fn move_to(&mut self, x: Fixed, y: Fixed)

Source§

fn line_to(&mut self, x: Fixed, y: Fixed)

Source§

fn curve_to( &mut self, cx0: Fixed, cy0: Fixed, cx1: Fixed, cy1: Fixed, x: Fixed, y: Fixed, )

Source§

fn close(&mut self)

Source§

fn hstem(&mut self, y: Fixed, dy: Fixed)

Horizontal stem hint at y with height dy.
Source§

fn vstem(&mut self, x: Fixed, dx: Fixed)

Vertical stem hint at x with width dx.
Source§

fn hint_mask(&mut self, mask: &[u8])

Bitmask defining the hints that should be made active for the commands that follow.
Source§

fn counter_mask(&mut self, mask: &[u8])

Bitmask defining the counter hints that should be made active for the commands that follow.
Source§

fn clear_hints(&mut self)

Clear accumulated stem hints and all data derived from them.
Source§

fn finish(&mut self)

Called when charstring evaluation is complete.
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, 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.