fix crash in json encoding

This commit is contained in:
lauchmelder 2025-03-06 23:55:12 +01:00
parent 7c03386380
commit b893835866
4 changed files with 66 additions and 5 deletions

View file

@ -287,6 +287,7 @@ impl<'a> SplineIter<'a> {
if point.on_curve {
self.last_point = Some(IndexedGlyphPoint { point, index });
self.first_point = Some(IndexedGlyphPoint { point, index });
self.final_control = None;
return Ok(());
} else {
self.final_control = Some(IndexedGlyphPoint { point, index });

View file

@ -24,6 +24,8 @@ pub trait Visitor: Sized {
self.write_spline(&spline_element)
});
debug!("done writing splines");
self.write_suffix();
}
}

View file

@ -1,5 +1,6 @@
use std::io::Write;
use log::debug;
use serde::Serialize;
use crate::font::{GlyphHeader, GlyphPoint, SplineElement, SplineElementData};
@ -85,11 +86,13 @@ impl<W: Sized + Write> Visitor for JsonWriter<W> {
}
fn write_spline(&mut self, spline: &SplineElement) {
debug!("index correction: {}", self.index_correction);
let indexed_spline = match spline.data {
SplineElementData::Line(start, end) => ContourElement::Line(start.index - self.index_correction, end.index - self.index_correction),
SplineElementData::Bezier(start, control, end) => ContourElement::Bezier(start.index - self.index_correction, control.index - self.index_correction, end.index - self.index_correction)
};
debug!("pushing spline to contours array at position {}/{}", self.current_contour, self.body.contours.len());
self.body.contours[self.current_contour].elements.push(indexed_spline);
if spline.is_last {
self.index_correction = self.body.contours[self.current_contour].points.len();