Clone in a terminal:
Commit c30e9a0
Johan Mattsson - 2013-07-03T14:41:46+00:00
c30e9a05ad404ee991b3de2f961cc7841d1c1413johan.mattsson.m@gmail.com

Parse corners from Illustrators SVG export Corners are actually cubic points with the last handle at the same position as the endpoint.

Changed files (4)

Diff

diff --git a/libbirdfont/EditPointHandle.vala b/libbirdfont/EditPointHandle.valaindex 8948201..386ebf3 100644--- a/libbirdfont/EditPointHandle.vala+++ b/libbirdfont/EditPointHandle.vala@@ -120,6 +120,8 @@ public class EditPointHandle  { 		c = a * a + b * b; 		 		if (c == 0) {+			angle = 0; // FIXME: this should be a different point type without line handles+			length = 0; 			return; 		} 		diff --git a/libbirdfont/ImportSvg.vala b/libbirdfont/ImportSvg.valaindex 312a001..b4192b4 100644--- a/libbirdfont/ImportSvg.vala+++ b/libbirdfont/ImportSvg.vala@@ -195,7 +195,7 @@ public class ImportSvg { 	} 	 	/** -	 * Add svg paths to glyph.+	 * Add svg paths to a glyph. 	 *  	 * @param d svg data 	 * @param glyph add paths to this glyph@@ -589,7 +589,7 @@ public class ImportSvg { 					cy = 2 * py - py2; // if (svg_glyph) ? 					p[pi++] = cx; 					p[pi++] = cy;-					+										 					cx = px + parse_double (c[++i]); 					 					if (svg_glyph) {@@ -603,7 +603,7 @@ public class ImportSvg { 					 					p[pi++] = px2; 					p[pi++] = py2;-					+ 					cx = px + parse_double (c[++i]); 					 					if (svg_glyph) {@@ -614,7 +614,7 @@ public class ImportSvg { 					 					p[pi++] = cx; 					p[pi++] = cy;-					+							 					px = cx; 					py = cy; 				}@@ -738,7 +738,10 @@ public class ImportSvg { 				ep2.get_left_handle ().move_to_coordinate (x0, y0); 				ep2.type = PointType.QUADRATIC;		 			}-					+++			// all the (ep2.get_left_handle ().length == 0) is needed to parse corners in illustrator correctly +			// it should be a different point type.			 			if (command[i] == "C") { 				x0 = p[ic++]; 				y0 = p[ic++];@@ -754,46 +757,56 @@ public class ImportSvg {  				// start with line handles 				ep1 = path.points.last ().data;-				ep1.get_right_handle ().type = PointType.LINE_CUBIC;-				ep1.type = PointType.LINE_CUBIC; 				-				lx = ep1.x + ((x2 - ep1.x) / 3);-				ly = ep1.y + ((y2 - ep1.y) / 3);-								-				ep1.get_right_handle ().move_to_coordinate (lx, ly);-				ep1.recalculate_linear_handles ();+				if (ep1.get_right_handle ().length != 0) {+					ep1.get_right_handle ().type = PointType.LINE_CUBIC;+					ep1.type = PointType.LINE_CUBIC;+					+					lx = ep1.x + ((x2 - ep1.x) / 3);+					ly = ep1.y + ((y2 - ep1.y) / 3);+													+					ep1.get_right_handle ().move_to_coordinate (lx, ly);+					ep1.recalculate_linear_handles ();+				}			 				 				// set curve handles 				ep1 = path.points.last ().data;-				ep1.recalculate_linear_handles ();-				ep1.get_right_handle ().type = PointType.CUBIC;-				ep1.get_right_handle ().move_to_coordinate (x0, y0);-				ep1.type = PointType.CUBIC;-				+				if (ep1.get_right_handle ().length != 0 || path.points.length () == 1) {+					ep1.recalculate_linear_handles ();+					ep1.get_right_handle ().type = PointType.CUBIC;+					ep1.get_right_handle ().move_to_coordinate (x0, y0);+					ep1.type = PointType.CUBIC;+				} else {+					ep1.get_right_handle ().type = PointType.CUBIC;+					ep1.get_right_handle ().length = 0;+				}  				path.add (x2, y2);-								+					 				ep2 = path.points.last ().data; 				ep2.recalculate_linear_handles ();+				ep2.type = PointType.CUBIC; 				ep2.get_left_handle ().type = PointType.CUBIC;+				 				ep2.get_left_handle ().move_to_coordinate (x1, y1);-				ep2.type = PointType.CUBIC; 				-				ep1.recalculate_linear_handles ();+				if (ep2.get_left_handle ().length == 0) {+					ep2.get_right_handle ().length = 0;+				} 			} 			 			if (command[i] == "z") { 				// last point is first 				ep1 = path.points.last ().data; 				ep2 = path.points.first ().data;-				+ 				if (ep1.x == ep2.x && ep1.y == ep2.y) {-					path.points.remove_link (path.points.last ()); 					ep2.left_handle.angle = ep1.left_handle.angle; 					ep2.left_handle.length = ep1.left_handle.length; 					ep2.left_handle.type = ep1.left_handle.type;+					path.points.remove_link (path.points.last ()); 				}-				+ 				glyph.add_path (path); 				glyph.close_path (); 								diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex 2c4136d..651a023 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -51,7 +51,7 @@ public class MenuTab : FontDisplay { 	} 	 	public override string get_name () {-		return "Menu";+		return "Files"; 	} 	 	public override bool is_html_canvas () {@@ -157,18 +157,10 @@ c.append ("""  #if traslations  		// xgettext needs these lines in order to extract strings properly-		_("Create a new font")-		_("Add name and description to this font.");-		_("Preferences");-		_("Export SVG, TTF & EOT fonts");-		_("Name");-		_("Glyph sequence");+		_("Files"); 		_("Recent files") 		_("Recover");-		_("Export SVG font and view the result");-		_("Export SVG font and view the result");-		_("Delete all");-		_("Update name & description")+		_("Delete all");	 #endif  		return c.str;diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex eed98d4..e4f4ef7 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -725,16 +725,18 @@ public class Path { 				stderr.printf (@"$(e.y)\n"); 			} -			ycoordinates.append (ycoordinates.last ().data.copy ());+			if (ycoordinates.length () != 0) {+				ycoordinates.append (ycoordinates.last ().data.copy ());+			} 			 			return true; 		} 		 		for (unowned List<EditPoint> e = ycoordinates.first (); true; e = e.next) {-			return_val_if_fail (!is_null (e), true);+			return_val_if_fail (!is_null (e) || !is_null (e.data), true); 			 			if (y <= e.data.y + tolerance) {-				return_val_if_fail (!is_null (e.next), true);+				return_val_if_fail (!is_null (e.next) || !is_null (e.data), true); 				 				e = e.next; 

Contact

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