Skip to content

Commit

Permalink
Add Error::ConvertContour
Browse files Browse the repository at this point in the history
This lets us avoid returning `ErrorKind` directly
  • Loading branch information
cmyr committed May 12, 2021
1 parent bc44f07 commit 68045cd
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ pub enum Error {
ExpectedPlistDictionary(String),
ExpectedPlistString,
ExpectedPositiveValue,
#[cfg(feature = "kurbo")]
ConvertContour(ErrorKind),
}

/// An error representing a failure to validate UFO groups.
Expand Down Expand Up @@ -182,6 +184,8 @@ impl std::fmt::Display for Error {
Error::ExpectedPositiveValue => {
write!(f, "PositiveIntegerOrFloat expects a positive value.")
}
#[cfg(feature = "kurbo")]
Error::ConvertContour(cause) => write!(f, "Failed to convert contour: '{}'", cause),
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions src/glyph/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ impl Contour {

/// Converts the `Contour` to a [`kurbo::BezPath`].
#[cfg(feature = "kurbo")]
pub fn to_kurbo(&self) -> Result<kurbo::BezPath, ErrorKind> {
pub fn to_kurbo(&self) -> Result<kurbo::BezPath, Error> {
let mut path = kurbo::BezPath::new();
let mut offs = std::collections::VecDeque::new();
let mut points = if self.is_closed() {
Expand All @@ -286,10 +286,10 @@ impl Contour {
PointType::OffCurve => offs.push_back(kurbo_point),
PointType::Curve => {
match offs.make_contiguous() {
[] => return Err(ErrorKind::BadPoint),
[] => return Err(Error::ConvertContour(ErrorKind::BadPoint)),
[p1] => path.quad_to(*p1, kurbo_point),
[p1, p2] => path.curve_to(*p1, *p2, kurbo_point),
_ => return Err(ErrorKind::TooManyOffCurves),
_ => return Err(Error::ConvertContour(ErrorKind::TooManyOffCurves)),
};
offs.clear();
}
Expand Down

0 comments on commit 68045cd

Please sign in to comment.