pub struct PathBuilder { /* private fields */ }Expand description
Ergonomic builder for Path implementing the PDF path construction
operators (m, l, c, h) with the same state-machine semantics as
SplashPath::moveTo / lineTo / curveTo / close.
Implementations§
Source§impl PathBuilder
impl PathBuilder
Sourcepub fn move_to(&mut self, x: f64, y: f64) -> Result<(), PathError>
pub fn move_to(&mut self, x: f64, y: f64) -> Result<(), PathError>
Begin a new subpath at (x, y). Equivalent to the PDF m operator.
§Errors
Returns PathError::BogusPath if a one-point subpath is already
active (i.e. the previous operation was also a move_to with no
drawing operator in between). Callers must not silently ignore this
error: it indicates a malformed path construction sequence.
Sourcepub fn line_to(&mut self, x: f64, y: f64) -> Result<(), PathError>
pub fn line_to(&mut self, x: f64, y: f64) -> Result<(), PathError>
Add a line segment from the current point to (x, y).
Equivalent to the PDF l operator.
§Errors
Returns PathError::NoCurPt if there is no current point. Callers
must ensure a successful Self::move_to precedes this call.
§Panics
Panics if flags is empty despite a current point existing, which
would indicate a broken Path invariant (pts.len() == flags.len()).
Sourcepub fn curve_to(
&mut self,
x1: f64,
y1: f64,
x2: f64,
y2: f64,
x3: f64,
y3: f64,
) -> Result<(), PathError>
pub fn curve_to( &mut self, x1: f64, y1: f64, x2: f64, y2: f64, x3: f64, y3: f64, ) -> Result<(), PathError>
Add a cubic Bezier curve. Equivalent to the PDF c operator.
(x1, y1) and (x2, y2) are the two off-curve control points;
(x3, y3) is the on-curve endpoint. Three points are always appended:
the control points receive PathFlags::CURVE and the endpoint
receives PathFlags::LAST.
§Errors
Returns PathError::NoCurPt if there is no current point. Callers
must ensure a successful Self::move_to precedes this call.
§Panics
Panics if flags is empty despite a current point existing, which
would indicate a broken Path invariant (pts.len() == flags.len()).
Sourcepub fn close(&mut self, force: bool) -> Result<(), PathError>
pub fn close(&mut self, force: bool) -> Result<(), PathError>
Close the current subpath. Equivalent to the PDF h operator.
Behaviour:
- If
forceistrue, a closinglineTo(first)is always appended. - If
sp == last_idxthe subpath consists of exactly one point (themoveTowith no drawing operators). In this degenerate case the subpath is trivially “closed” (first == last by identity), so no extralineTois needed — the single point hasPathFlags::CLOSEDset on itself. This matches the C++SplashPath::closebehaviour. - Otherwise, a closing
lineTo(first)is appended only whenfirst != last(the path is not already closed geometrically).
After closing, cur_subpath is advanced to pts.len() (the
“no current point” sentinel), so Path::current_point returns None
until the next move_to.
§Errors
Returns PathError::NoCurPt if there is no current point. The ?
inside this method propagates any error from the internal line_to
call; since line_to only errors on NoCurPt and we have already
verified a current point exists at entry, that propagation path is only
reachable if an invariant is broken.
Sourcepub fn add_stroke_adjust_hint(
&mut self,
ctrl0: usize,
ctrl1: usize,
first_pt: usize,
last_pt: usize,
)
pub fn add_stroke_adjust_hint( &mut self, ctrl0: usize, ctrl1: usize, first_pt: usize, last_pt: usize, )
Add a stroke-adjust hint referencing existing point indices.
Indices refer to positions in Path::pts at build time.
Sourcepub fn cur_pt(&self) -> Option<PathPoint>
pub fn cur_pt(&self) -> Option<PathPoint>
Returns the current point (last appended endpoint), if any.
Returns None when there is no current point — i.e. on a freshly
created builder or immediately after a successful Self::close.
Delegates to Path::current_point.
Sourcepub const fn pts_len(&self) -> usize
pub const fn pts_len(&self) -> usize
Returns the number of points accumulated in the builder so far.
This is a read-only view used by callers that need to record point
indices for stroke-adjustment hints (e.g. raster::stroke::make_stroke_path).