use ab_glyph::{point, Font, FontRef, Glyph, OutlineBuilder};
enum OutlineCurve {
Move(f32, f32),
Line(f32, f32),
Cubic(f32, f32, f32, f32, f32, f32),
Quad(f32, f32, f32, f32),
Close,
}
#[derive(Default)]
struct SvgOutlineBuilder(Vec<OutlineCurve>);
impl OutlineBuilder for SvgOutlineBuilder {
fn move_to(&mut self, x: f32, y: f32) {
self.0.push(OutlineCurve::Move(x, y))
}
fn line_to(&mut self, x: f32, y: f32) {
self.0.push(OutlineCurve::Line(x, y))
}
fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) {
self.0.push(OutlineCurve::Cubic(x1, y1, x2, y2, x, y))
}
fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) {
self.0.push(OutlineCurve::Quad(x1, y1, x, y))
}
fn close(&mut self) {
self.0.push(OutlineCurve::Close)
}
}
let q_glyph: Glyph = font
.glyph_id('q')
.with_scale_and_position(24.0, point(100.0, 0.0));
let mut outline_builder = SvgOutlineBuilder::default();
let outline = font.outline_with_builder(q_glyph, &mut outline_builder);
This is not currently possible with the current API. This should probably also include reexporting the OutlineBuilder
from owned_ttf_parser
.
I apologize for filing yet another issue, but I feel like this could make the crate more useful in a wider range of use cases. If you feel like this is a welcome change, I would be happy to submit a PR for it.