use std::{fs::File, io::{BufWriter, Write}};
use crate::font::{GlyphHeader, GlyphPoint, SplineElement};
use super::Visitor;
pub struct SvgWriter<'a, W: Sized + Write> {
first_point: bool,
writer: &'a mut W,
points: Vec<(i32, i32)>,
control_points: Vec<(i32, i32)>,
virtual_points: Vec<(i32, i32)>
}
impl<'a, W: Sized + Write> SvgWriter<'a, W> {
pub fn new(out: &'a mut W) -> Self {
SvgWriter {
first_point: true,
writer: out,
points: vec![],
control_points: vec![],
virtual_points: vec![]
}
}
}
impl<'a, W: Sized + Write> SvgWriter<'a, W> {
fn handle_start_point(&mut self, point: &GlyphPoint) {
if self.first_point {
write!(self.writer, "M{} {} ", point.x, -point.y);
self.first_point = false;
}
}
fn handle_end_point(&mut self, point: &GlyphPoint) {
if point.is_endpoint {
self.first_point = true;
}
}
fn write_points(&mut self) {
for (x, y) in &self.points {
write!(self.writer, "");
}
for (x, y) in &self.control_points {
write!(self.writer, "");
}
for (x, y) in &self.virtual_points {
write!(self.writer, "");
}
}
}
impl<'a, W: Sized + Write> Visitor for SvgWriter<'a, W> {
fn write_prefix(&mut self, header: &GlyphHeader) {
write!(
self.writer,
"");
}
}