use crate::path::PathBuilder;
pub(crate) struct OutlineSink<'a> {
builder: &'a mut PathBuilder,
scale: f32,
origin_x: f32,
baseline_y: f32,
}
impl<'a> OutlineSink<'a> {
pub(crate) fn new(
builder: &'a mut PathBuilder,
scale: f32,
origin_x: f32,
baseline_y: f32,
) -> Self {
OutlineSink { builder, scale, origin_x, baseline_y }
}
#[inline]
fn map(&self, x: f32, y: f32) -> (f32, f32) {
(self.origin_x + x * self.scale, self.baseline_y - y * self.scale)
}
}
impl ttf_parser::OutlineBuilder for OutlineSink<'_> {
fn move_to(&mut self, x: f32, y: f32) {
let (px, py) = self.map(x, y);
self.builder.move_to(px, py);
}
fn line_to(&mut self, x: f32, y: f32) {
let (px, py) = self.map(x, y);
self.builder.line_to(px, py);
}
fn quad_to(&mut self, x1: f32, y1: f32, x: f32, y: f32) {
let (cx, cy) = self.map(x1, y1);
let (px, py) = self.map(x, y);
self.builder.quad_to(cx, cy, px, py);
}
fn curve_to(&mut self, x1: f32, y1: f32, x2: f32, y2: f32, x: f32, y: f32) {
let (c1x, c1y) = self.map(x1, y1);
let (c2x, c2y) = self.map(x2, y2);
let (px, py) = self.map(x, y);
self.builder.cubic_to(c1x, c1y, c2x, c2y, px, py);
}
fn close(&mut self) {
self.builder.close();
}
}