use super::*;
pub struct PointsBuilder<'a, T: Write> {
inner: &'a mut T,
}
impl<'a, T: Write> PointsBuilder<'a, T> {
pub(super) fn new(inner: &'a mut T) -> Result<Self, fmt::Error> {
write!(inner, " points=\"")?;
Ok(PointsBuilder { inner })
}
pub fn add_point(
&mut self,
x: impl fmt::Display,
y: impl fmt::Display,
) -> Result<&mut Self, fmt::Error> {
write!(self.inner, "{},{} ", x, y)?;
Ok(self)
}
pub(super) fn finish(&'a mut self) -> Result<&'a mut T, fmt::Error> {
write!(self.inner, "\"")?;
Ok(self.inner)
}
}
pub enum PathCommand<F: fmt::Display> {
M(F, F),
M_(F, F),
L(F, F),
L_(F, F),
H(F),
H_(F),
V(F),
V_(F),
C(F, F, F, F, F, F),
C_(F, F, F, F, F, F),
S(F, F, F, F),
S_(F, F, F, F),
Q(F, F, F, F),
Q_(F, F, F, F),
T(F, F),
T_(F, F),
A(F, F, F, F, F, F, F),
A_(F, F, F, F, F, F, F),
}
impl<F: fmt::Display> PathCommand<F> {
pub fn write<T: fmt::Write>(&self, writer: &mut T) -> fmt::Result {
use PathCommand::*;
match self {
M(x, y) => {
write!(writer, " M {} {}", x, y)
}
M_(x, y) => {
write!(writer, " m {} {}", x, y)
}
L(x, y) => {
write!(writer, " L {} {}", x, y)
}
L_(x, y) => {
write!(writer, " l {} {}", x, y)
}
H(a) => {
write!(writer, " H {}", a)
}
H_(a) => {
write!(writer, " h {}", a)
}
V(a) => {
write!(writer, " V {}", a)
}
V_(a) => {
write!(writer, " v {}", a)
}
C(x1, y1, x2, y2, x, y) => {
write!(writer, " C {} {}, {} {}, {} {}", x1, y1, x2, y2, x, y)
}
C_(dx1, dy1, dx2, dy2, dx, dy) => {
write!(writer, " c {} {}, {} {}, {} {}", dx1, dy1, dx2, dy2, dx, dy)
}
S(x2, y2, x, y) => {
write!(writer, " S {},{} {} {}", x2, y2, x, y)
}
S_(x2, y2, x, y) => {
write!(writer, " s {},{} {} {}", x2, y2, x, y)
}
Q(x1, y1, x, y) => {
write!(writer, " Q {} {}, {} {}", x1, y1, x, y)
}
Q_(dx1, dy1, dx, dy) => {
write!(writer, " q {} {}, {} {}", dx1, dy1, dx, dy)
}
T(x, y) => {
write!(writer, " T {} {}", x, y)
}
T_(x, y) => {
write!(writer, " t {} {}", x, y)
}
A(rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y) => {
write!(
writer,
" A {} {} {} {} {} {} {}",
rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, x, y
)
}
A_(rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, dx, dy) => {
write!(
writer,
" a {} {} {} {} {} {} {}",
rx, ry, x_axis_rotation, large_arc_flag, sweep_flag, dx, dy
)
}
}
}
}
pub struct PathBuilder<'a, T> {
inner: &'a mut T,
}
impl<'a, T: Write> PathBuilder<'a, T> {
pub(super) fn new(inner: &'a mut T) -> Result<Self, fmt::Error> {
write!(inner, " d=\"")?;
Ok(PathBuilder { inner })
}
pub fn draw_z(&mut self) -> Result<&mut Self, fmt::Error> {
write!(self.inner, "Z")?;
Ok(self)
}
pub fn draw<F: fmt::Display>(&mut self, val: PathCommand<F>) -> Result<&mut Self, fmt::Error> {
val.write(self.inner)?;
Ok(self)
}
pub(super) fn finish(&'a mut self) -> Result<&'a mut T, fmt::Error> {
write!(self.inner, "\"")?;
Ok(self.inner)
}
}