fix crash in json encoding
This commit is contained in:
parent
7c03386380
commit
b893835866
4 changed files with 66 additions and 5 deletions
|
@ -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 });
|
||||
|
|
|
@ -24,6 +24,8 @@ pub trait Visitor: Sized {
|
|||
self.write_spline(&spline_element)
|
||||
});
|
||||
|
||||
debug!("done writing splines");
|
||||
|
||||
self.write_suffix();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue