Commit 23ab3b1
Parse ellipse instruction in SVG files
Changed files (3)
modifiedbirdfont/Main.valamodifiedlibbirdfont/CircleTool.valamodifiedlibbirdfont/SvgParser.vala
Diff
@@ -20,7 +20,6 @@ using BirdFont; public static int main (string[] arg) { GtkWindow native_window; MainWindow window;- string file; BirdFont.BirdFont birdfont; birdfont = new BirdFont.BirdFont ();@@ -141,6 +141,33 @@ public class CircleTool : Tool { return path; } + public static Path create_ellipse (double x, double y,+ double rx, double ry, PointType pt) { + + double px, py;+ Path path = new Path ();+ double steps = (pt == PointType.QUADRATIC) ? PI / 8 : PI / 4; + + for (double angle = 0; angle < 2 * PI; angle += steps) {+ px = rx * cos (angle) + x;+ py = ry * sin (angle) + y;+ path.add (px, py);+ }+ + path.init_point_type (pt);+ path.close ();+ path.recalculate_linear_handles ();++ for (int i = 0; i < 3; i++) {+ foreach (EditPoint ep in path.points) {+ ep.set_tie_handle (true);+ ep.process_tied_handle ();+ }+ }++ return path;+ }+ void press (int button, double x, double y) { Glyph glyph = MainWindow.get_current_glyph (); Path path = new Path ();@@ -194,6 +194,10 @@ public class SvgParser { if (t.get_name () == "circle") { parse_circle (t, pl); }+ + if (t.get_name () == "ellipse") {+ parse_ellipse (t, pl);+ } } return pl.get_all_paths ();@@ -241,6 +245,10 @@ public class SvgParser { if (t.get_name () == "circle") { parse_circle (t, pl); }++ if (t.get_name () == "ellipse") {+ parse_ellipse (t, pl);+ } } foreach (Attribute attr in tag.get_attributes ()) { @@ -491,7 +499,77 @@ public class SvgParser { style.apply (npl); pl.paths.append (npl); }++ private void parse_ellipse (Tag tag, Layer pl) {+ Path p;+ double x, y, rx, ry;+ Glyph g;+ PathList npl;+ BezierPoints[] bezier_points;+ SvgStyle style = new SvgStyle ();+ bool hidden = false;+ + npl = new PathList ();+ + x = 0;+ y = 0;+ rx = 0;+ ry = 0;+ + foreach (Attribute attr in tag.get_attributes ()) { + if (attr.get_name () == "cx") {+ x = parse_double (attr.get_content ());+ }+ + if (attr.get_name () == "cy") {+ y = -parse_double (attr.get_content ());+ }++ if (attr.get_name () == "rx") {+ rx = parse_double (attr.get_content ());+ }++ if (attr.get_name () == "ry") {+ ry = parse_double (attr.get_content ());+ }+ + if (attr.get_name () == "style") {+ style = SvgStyle.parse (attr.get_content ());+ } + if (attr.get_name () == "display" && attr.get_content () == "none") {+ hidden = true;+ }+ }+ + if (hidden) {+ return;+ }+ + bezier_points = new BezierPoints[1];+ bezier_points[0] = new BezierPoints ();+ bezier_points[0].type == 'L';+ bezier_points[0].x0 = x;+ bezier_points[0].y0 = y;++ g = MainWindow.get_current_glyph ();+ move_and_resize (bezier_points, 1, false, 1, g);+ + p = CircleTool.create_ellipse (bezier_points[0].x0,+ bezier_points[0].y0, rx, ry, PointType.CUBIC);++ npl.add (p);+ + foreach (Attribute attr in tag.get_attributes ()) {+ if (attr.get_name () == "transform") {+ transform_paths (attr.get_content (), npl);+ }+ }+ + style.apply (npl);+ pl.paths.append (npl);+ }+ private void parse_rect (Tag tag, Layer pl) { Path p; double x, y, x2, y2;