Commit 00ae500
tie quadratic handles
Changed files (6)
modifiedlibbirdfont/EditPoint.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/GridTool.valamodifiedlibbirdfont/Line.valamodifiedlibbirdfont/OpenFontFormat/HeadTable.valamodifiedlibbirdfont/Path.vala
Diff
@@ -189,12 +189,18 @@ public class EditPoint { tie_handles = t; } - public void process_tied_handle () {+ public void process_tied_handle () + requires (next != null && prev != null) { double a, b, c, length, angle; EditPointHandle eh;+ EditPointHandle prev_rh, next_lh; eh = right_handle; + if (left_handle.type == PointType.QUADRATIC) {+ left_handle.length = 0;+ }+ a = left_handle.x () - right_handle.x (); b = left_handle.y () - right_handle.y (); c = a * a + b * b;@@ -211,9 +217,30 @@ public class EditPoint { angle = -acos (a / length) + PI; } - if (left_handle.type == PointType.LINE_DOUBLE_CURVE || left_handle.type == PointType.QUADRATIC) {+ if (left_handle.type == PointType.QUADRATIC) {+ left_handle.type = PointType.DOUBLE_CURVE;+ right_handle.type = PointType.DOUBLE_CURVE;+ + prev_rh = get_prev ().data.get_right_handle ();+ next_lh = get_next ().data.get_left_handle ();+ + prev_rh.type = PointType.DOUBLE_CURVE; + next_lh.type = PointType.DOUBLE_CURVE;+ + left_handle.move_to_coordinate (prev_rh.x (), prev_rh.y ());+ left_handle.length *= 0.5;+ right_handle.length *= 0.5;+ prev_rh.length *= 0.5;+ next_lh.length *= 0.5;+ } else if (left_handle.type == PointType.LINE_DOUBLE_CURVE) { left_handle.type = PointType.DOUBLE_CURVE;- right_handle.type = PointType.DOUBLE_CURVE; + right_handle.type = PointType.DOUBLE_CURVE;+ + prev_rh = get_prev ().data.get_right_handle ();+ next_lh = get_next ().data.get_left_handle ();+ + prev_rh.type = PointType.DOUBLE_CURVE; + next_lh.type = PointType.DOUBLE_CURVE; } else if (left_handle.type == PointType.LINE_CUBIC) { left_handle.type = PointType.CUBIC; right_handle.type = PointType.CUBIC;@@ -732,9 +732,6 @@ public class Font : GLib.Object { liga = g.get_ligature_string (); ligature.insert (liga, gc); }- - // take xheight from appropriate lower case letter- // xheight_position = estimate_xheight (); } public bool parse_otf_file (string path) throws GLib.Error {@@ -114,7 +114,7 @@ class GridTool : Tool { n = 0; for (i = baseline.get_pos () - step; i >= top_margin.get_pos () - 7 * step; i -= step) {- t = new Line ("grid", i, Line.HOROIZONTAL);+ t = new Line ("grid", i, Line.HORIZONTAL); t.set_moveable (false); t.set_color (0.2, 0.6, 0.2, 0.2); vertical.append (t); @@ -126,7 +126,7 @@ class GridTool : Tool { } for (i = baseline.get_pos (); i <= bottom_margin.get_pos () + 7 * step; i += step) {- u = new Line ("grid", i, Line.HOROIZONTAL);+ u = new Line ("grid", i, Line.HORIZONTAL); u.set_moveable (false); u.set_color (0.2, 0.6, 0.2, 0.2); vertical.append (u); @@ -162,7 +162,7 @@ class GridTool : Tool { if (!coordinate) { xpos = new Line ("", 0, Line.VERTICAL);- ypos = new Line ("", 0, Line.HOROIZONTAL);+ ypos = new Line ("", 0, Line.HORIZONTAL); xpos.set_move (true); ypos.set_move (true);@@ -171,7 +171,7 @@ class GridTool : Tool { ypos.move_line_to (x, y, g.allocation); } else { xpos = new Line ("", x, Line.VERTICAL);- ypos = new Line ("", y, Line.HOROIZONTAL);+ ypos = new Line ("", y, Line.HORIZONTAL); } m = double.MAX;@@ -22,7 +22,7 @@ namespace BirdFont { /** Help line */ public class Line : GLib.Object { public static const bool VERTICAL = true;- public static const bool HOROIZONTAL = false;+ public static const bool HORIZONTAL = false; string label; bool vertical;@@ -85,12 +85,6 @@ public class Line : GLib.Object { this.a = a; } - // Valabug, it should be: public “void set_list_item (unowned List<Line> ll) {”- // Keeping list_item public for now- public void set_list_item (void* ll) {- // list_item = ll;- }- public bool is_moving () { return move; }@@ -60,7 +60,7 @@ class HeadTable : Table { } public double get_units_per_em () {- return units_per_em * 10; // Fixa: we can refactor this number+ return units_per_em * 10; } public override void parse (FontData dis) throws GLib.Error {@@ -1120,20 +1120,17 @@ public class Path { curve_y = -0.25 * start.y + 0.75 * stop.get_left_handle ().y () + 0.75 * start.get_right_handle ().y () - 0.25 * stop.y; } - public void insert_new_point_on_path (EditPoint? epp) {+ public void insert_new_point_on_path (EditPoint ep) { EditPoint start, stop; double x0, x1, y0, y1; double position, min;- - EditPoint ep; PointType left, right;-- if (epp == null) {+ + if (ep.next == null || ep.prev == null) {+ warning ("missing point"); return; } - ep = (!) epp;- start = ep.get_prev ().data; stop = ep.get_next ().data; @@ -1184,13 +1181,13 @@ public class Path { ep.get_left_handle ().set_point_type (PointType.DOUBLE_CURVE); ep.get_right_handle ().set_point_type (PointType.DOUBLE_CURVE);- } else if (right == PointType.QUADRATIC) { + } else if (right == PointType.QUADRATIC) { x0 = quadratic_bezier_vector (1 - position, stop.x, start.get_right_handle ().x (), start.x); y0 = quadratic_bezier_vector (1 - position, stop.y, start.get_right_handle ().y (), start.y); ep.get_right_handle ().move_to_coordinate (x0, y0); ep.get_left_handle ().set_point_type (PointType.QUADRATIC); - ep.get_right_handle ().set_point_type (PointType.QUADRATIC); + ep.get_right_handle ().set_point_type (PointType.QUADRATIC); } else { bezier_vector (position, start.x, start.get_right_handle ().x (), stop.get_left_handle ().x (), stop.x, out x0, out x1); bezier_vector (position, start.y, start.get_right_handle ().y (), stop.get_left_handle ().y (), stop.y, out y0, out y1);