Clone in a terminal:
Commit de8200f
Johan Mattsson - 2012-08-19T13:59:02+00:00
de8200ffcbe3058ffbc27be69bbc80222a244651johan.mattsson.m@gmail.com

merge selected paths

Changed files (4)

Diff

diff --git a/src/Glyph.vala b/src/Glyph.valaindex 6b4eab7..27b710b 100644--- a/src/Glyph.vala+++ b/src/Glyph.vala@@ -496,10 +496,10 @@ class Glyph : FontDisplay { 	public override void key_press (EventKey e) {	 		if (e.keyval == Key.DEL) { 			if (active_paths.length () != 0) {+				 				foreach (Path p in active_paths) {-					close_path (); 					path_list.remove (p);-					redraw_area (0, 0, allocation.width, allocation.height);	+					redraw_area (0, 0, allocation.width, allocation.height); 				} 				 				clear_active_paths ();@@ -1616,10 +1616,15 @@ class Glyph : FontDisplay { 		 		clear_active_paths (); 		foreach (Path p in g.active_paths) {-			add_path (p);+			add_active_path (p); 		} 		 		undo_list.remove_link (undo_list.last ());+		+		open_path ();+		close_path ();+		+		redraw_area (0, 0, allocation.width, allocation.height); 	} 	 	public ImageSurface get_thumbnail () {@@ -1678,21 +1683,64 @@ class Glyph : FontDisplay { 		((!)p).insert_new_point_on_path (ep); 	} 	+	/** Merge selected paths. */ 	public void merge_all () {+		delete_invisible_paths ();+		+		if (active_paths.length () < 2) {+			return;+		}+		+		foreach (Path p0 in active_paths) {+			// while (merge_path (p0));+			merge_path (p0);+		}+		+		open_path ();+		close_path ();+		+		redraw_area (0, 0, allocation.width, allocation.height);+	}+	+	public bool merge_path (Path p0) { 		Path? m;+		Path mp; 		int i = 0; 		-		delete_invisible_paths ();-		-		if (path_list.length () >= 2) {-			m = ((!) path_list.first ()).data.merge (((!) path_list.last ()).data);-			delete_path (path_list.first ().data);-			delete_path (path_list.last ().data);+		foreach (Path p1 in active_paths) {+			if (p0 == p1) {+				p0 = p1;+				continue;+			}+			+			m = p0.merge (p1);++			if (m == null) {+				p0 = p1;+				continue;+			}+			+			mp = (!) m; -			((!) m).close ();+			delete_path (p0);+			delete_path (p1); 			-			add_path (((!) m).copy ());+			mp.close ();			+			add_path (mp.copy ());+			+			add_active_path (mp);++			active_paths.remove_all (p0);+			active_paths.remove_all (p1);++			p0 = mp;+			+			mp.create_list ();+			+			return true; 		}+		+		return false; 	} } diff --git a/src/MoveTool.vala b/src/MoveTool.valaindex aadd448..b020a4a 100644--- a/src/MoveTool.vala+++ b/src/MoveTool.vala@@ -59,8 +59,6 @@ class MoveTool : Tool { 				p.set_selected (false); 			} 			-			return_if_fail (glyph.active_paths.length () != 0);-			 			foreach (Path path in glyph.active_paths) { 				if (path.is_clockwise ()) { 					path.set_color (0.2, 0.2, 0.4, 0.8);diff --git a/src/Path.vala b/src/Path.valaindex 2873885..e7ceab9 100644--- a/src/Path.vala+++ b/src/Path.vala@@ -350,20 +350,6 @@ class Path { 		return false; 	} 	-	private static unowned List<EditPoint>? first_outside (Path source, Path union) {-		unowned List<EditPoint> p = source.points.first ();-		bool begins_outside = false;-		for (int i = 0; i < p.length (); i++) {-			if (!union.is_over (p.data.x, p.data.y) && !union.has_edit_point (p.data)) {-				return p; // a good place to start-			}-			-			p = p.next;-		}-		-		return null;-	}-	 	private bool force_union_directions (Path union) { 		bool r; 		@@ -409,66 +395,6 @@ class Path { 		 		return true; 	}-	-	private static Path create_merged_path (Path source, Path union) {-		Path merged = new Path ();-		-		uint ml = union.points.length () + source.points.length ();-		-		unowned List<EditPoint> p;-		unowned List<EditPoint> eli;-		-		unowned List<EditPoint>? fou;-		Path? swap;-		-		// begin outside.-		fou = first_outside (source, union);-		if (fou == null) {-			swap = union;-			union = source;-			source = (!) swap;-		}-		-		fou = first_outside (source, union);-		return_if_fail (fou != null);-		-		p = (!) fou;-		eli = p;-		-		// create a new path from this path + union-		bool u = false;-		uint i = 0;-				-		while (true) {-			if (i == ml) break;-			if (++i == ml) { // FIXME: do something better-				break;-			}-						-			if (!merged.has_edit_point_at (p.data.x, p.data.y)) {-				merged.add (p.data.x, p.data.y);-			}-		-			eli = (!u) ? union.points : source.points;-			-			int tni = 0;			-			foreach (var t in eli) {-				-				if (p.data.x == t.x && p.data.y == t.y) {-					p = eli.nth (tni);-					u = !u;					-					break;-				}-				-				tni++;-			}-			-			if (p == p.last ()) p = p.first ();-			else p = p.next;-		}-		-		return merged;	-	} 		 	private bool has_edit_point_at (double x, double y) { 		foreach (var p in points) {@@ -805,21 +731,21 @@ class Path { 	}	 	 	public bool is_over (double x, double y) {+		Glyph g = MainWindow.get_current_glyph ();+		+		x = x * Glyph.ivz () + g.view_offset_x - Glyph.xc ();+		y = y * Glyph.ivz () + g.view_offset_y - Glyph.yc ();++		y *= -1;+		 		if (!is_over_boundry (x, y)) { 			return false; 		}  		return true; 	}-+	 	public bool is_over_boundry (double x, double y) {-		Glyph g = MainWindow.get_current_glyph ();-		-		x = x * Glyph.ivz () + g.view_offset_x - Glyph.xc ();-		y = y * Glyph.ivz () + g.view_offset_y - Glyph.yc ();--		y *= -1;-				 		return (ymin <= y <= ymax) && (xmin <= x <= xmax); 	} @@ -1574,7 +1500,14 @@ class Path { 		 		} 		-		points = (owned) list;+		while (points.length () > 0) {+			points.remove_link (points.first ());+		}+		+		foreach (EditPoint p in list) {+			points.append (p);+		}+		 	} 	 	public Path? merge (Path p) {@@ -1589,6 +1522,11 @@ class Path { 		uint len_i; 		int i, j; 		uint len_j;+		bool over;+		+		if (p == this) {+			return null;+		} 		 		// add editpoints points on intersections  		foreach (Intersection inter in il.points) {@@ -1612,6 +1550,28 @@ class Path {  		} 		+		if (il.points.length () == 0) {+			return null;+		}+		+		// begin outside intersection+		ex = points.first ().data;+		for (i = 0; i < points.length (); i++) {+			ex = ex.get_next ().data;+			+			if (!p.is_over_boundry (ex.x, ex.y)) {+				set_new_start (ex);+				break;				+			}+		}++		if (i == points.length ()) {+			warning ("No point outside path.");+			return null;+		}++		// p.set_new_start (il.points.first ().data.editpoint_b);+	 		// create a new path  		ex = points.last ().data; 		ix = points.last ().data;@@ -1626,7 +1586,7 @@ class Path {  			// add new point for path a 			np.add_point (ex);-			ix.recalculate_linear_handles ();+			ex.recalculate_linear_handles (); 			 			// swap paths 			if (il.has_edit_point (ex)) {@@ -1637,6 +1597,8 @@ class Path { 				ex.right_handle.angle  = s.editpoint_b.right_handle.angle; 				ex.right_handle.length = s.editpoint_b.right_handle.length; +				ex.left_handle.type = PointType.CURVE;+ 				// read until we find ex 				for (j = 0; j < p.points.length (); j++) { 					ix = p.points.nth (j).data;@@ -1653,7 +1615,6 @@ class Path { 					ix = p.points.nth ((j + offset_j) % len_j).data; 					 					// add-					ix.right_handle .move_to_coordinate (0, 0); 					np.add_point (ix); 					ix.recalculate_linear_handles (); 					@@ -1661,14 +1622,15 @@ class Path { 						s = (!) il.get_intersection (ix); 						break; 					}-					 				}  				ix.type = PointType.CURVE; 				ix.right_handle.type = PointType.CURVE; 				ix.right_handle.angle  = s.editpoint_a.right_handle.angle; 				ix.right_handle.length = s.editpoint_a.right_handle.length;-					+				+				ix.left_handle.type = PointType.CURVE;+				 				if (j == points.length ()) { 					np.close (); 					return np;diff --git a/src/Toolbox.vala b/src/Toolbox.valaindex 94ae216..a0189c2 100644--- a/src/Toolbox.vala+++ b/src/Toolbox.vala@@ -91,7 +91,7 @@ class Toolbox : DrawingArea { 		// Fixa: draw_tools.add_tool (shrink_tool);	 		 		// Draw tool modifiers-		Tool new_point = new Tool ("new_point", "Add new points to path", 'a');+		Tool new_point = new Tool ("new_point", "Add new points", 'a'); 		new_point.select_action.connect((self) => { 				select_draw_tool (); 			});

Contact

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