Clone in a terminal:
Commit 23ab3b1
Johan Mattsson - 2015-10-14T08:15:51+00:00
23ab3b1ca06c50653a111ebf29ee25b1d2bc2757johan.mattsson.m@gmail.com

Parse ellipse instruction in SVG files

Changed files (3)

Diff

diff --git a/birdfont/Main.vala b/birdfont/Main.valaindex 14c6cfd..104ea8d 100644--- a/birdfont/Main.vala+++ b/birdfont/Main.vala@@ -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 ();diff --git a/libbirdfont/CircleTool.vala b/libbirdfont/CircleTool.valaindex a0c529e..37290f5 100644--- a/libbirdfont/CircleTool.vala+++ b/libbirdfont/CircleTool.vala@@ -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 ();diff --git a/libbirdfont/SvgParser.vala b/libbirdfont/SvgParser.valaindex 5d4202b..8d8d24d 100644--- a/libbirdfont/SvgParser.vala+++ b/libbirdfont/SvgParser.vala@@ -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;

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112