pub fn contour_to_path<T, C: PointCoord>(
points: &[T],
to_point: impl Fn(&T) -> (Point<C>, PointFlags),
start: PathContourStart,
sink: &mut impl PathSink,
) -> boolExpand description
Converts one contour into path commands, taking its points from a slice of
anything to_point can read them out of.
For outlines held in some shape other than parallel point and flag arrays — an autohinter’s points, say, which carry more per point than these do.
Returns false on the same terms as outline_to_path, and leaves what
it drew on the sink.
use read_fonts::{
model::glyph::outline::SvgSink,
tables::glyf::{outline::{contour_to_path, PathContourStart}, PointFlags},
types::Point,
};
// Whatever the caller happens to hold, so long as points can be read out.
struct MyPoint { x: f32, y: f32, on_curve: bool, _more: [u32; 8] }
let contour = [
MyPoint { x: 0.0, y: 0.0, on_curve: true, _more: [0; 8] },
MyPoint { x: 8.0, y: 0.0, on_curve: true, _more: [0; 8] },
MyPoint { x: 8.0, y: 8.0, on_curve: true, _more: [0; 8] },
];
let mut pen = SvgSink::with_precision(1);
assert!(contour_to_path(
&contour,
|p| {
let flags = if p.on_curve {
PointFlags::on_curve()
} else {
PointFlags::off_curve_quad()
};
(Point::new(p.x, p.y), flags)
},
PathContourStart::ScanBackward,
&mut pen,
));
assert_eq!(pen.as_ref(), "M0.0,0.0 L8.0,0.0 L8.0,8.0 Z");