Skip to content

Commit

Permalink
Handle new PointType::QClose
Browse files Browse the repository at this point in the history
  • Loading branch information
ctrlcctrlv committed Sep 15, 2020
1 parent 2d4bda4 commit 319cf55
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/io.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ pub fn load_glif<F: AsRef<Path> + Clone>(filename: F) {
glifparser::read_ufo_glif(&fs::read_to_string(&filename).expect("Failed to read file"));

if env::var("DEBUG_DUMP_GLYPH").is_ok() {
debug!("{:?}", glif);
debug!("{:#?}", glif);
}

STATE.with(|v| {
Expand Down
18 changes: 17 additions & 1 deletion src/renderer/glyph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,23 @@ pub fn draw(canvas: &mut Canvas) -> Path {
)
}
OutlineType::Quadratic => {
path.quad_to(h1, (calc_x(firstpoint.x), calc_y(firstpoint.y)))
match lastpoint.ptype {
PointType::QClose => {
// This is safe as a lone QClose is illegal and should
// cause a crash anyway if it's happening.
let prevpoint = &contour[contour.len() - 2];
let ph = prevpoint.handle_or_colocated(
WhichHandle::A,
calc_x,
calc_y,
);
path.quad_to(ph, h1)
}
_ => path.quad_to(
h1,
(calc_x(firstpoint.x), calc_y(firstpoint.y)),
),
}
}
OutlineType::Spiro => panic!("Spiro as yet unimplemented."),
};
Expand Down
10 changes: 7 additions & 3 deletions src/renderer/points/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use crate::glifparser;
use crate::state::{HandleStyle, PointLabels};
use crate::STATE;

use glifparser::Point as GlifPoint;
use glifparser::{Point as GlifPoint, PointType};

use std::iter::Peekable;

Expand Down Expand Up @@ -302,7 +302,7 @@ pub fn draw_handlebars<T>(
}
_ => {}
}
if point.ptype == glifparser::PointType::QCurve {
if point.ptype == PointType::QCurve || point.ptype == PointType::QClose {
if let Some(pp) = prevpoint {
match pp.a {
Handle::At(x, y) => {
Expand All @@ -321,6 +321,10 @@ pub fn draw_complete_point<T>(
selected: bool,
canvas: &mut Canvas,
) {
if point.ptype == PointType::QClose {
return;
}

draw_point(
(calc_x(point.x), calc_y(point.y)),
(point.x, point.y),
Expand Down Expand Up @@ -376,7 +380,7 @@ pub fn draw_all(canvas: &mut Canvas) {
pub fn draw_selected(canvas: &mut Canvas) {
STATE.with(|v| {
for point in &v.borrow().selected {
if point.ptype != glifparser::PointType::QCurve {
if point.ptype != PointType::QCurve {
if v.borrow().handle_style == HandleStyle::Handlebars {
draw_handlebars(None, point, true, canvas);
}
Expand Down

0 comments on commit 319cf55

Please sign in to comment.