Clone in a terminal:
Commit 07e2425
Johan Mattsson - 2016-01-10T00:51:02+00:00
07e24257a09062ba8749f424f421df9ad8791dd4johan.mattsson.m@gmail.com

Move embedded SVG files

Changed files (8)

Diff

diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex ad24c2a..ddf27b0 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -1470,7 +1470,6 @@ class BirdFontFile : GLib.Object { 		string type = ""; 		double x = 0; 		double y = 0;-		EmbeddedSvg svg; 		 		foreach (Attribute attribute in tag.get_attributes ()) { 			if (attribute.get_name () == "x") {@@ -1488,7 +1487,9 @@ class BirdFontFile : GLib.Object { 		 		if (type == "svg") { 			SvgFile svg_file = new SvgFile ();-			svg = svg_file.parse_data (tag.get_content ());+			EmbeddedSvg svg = svg_file.parse_data (tag.get_content ());+			svg.x = x;+			svg.y = y; 			layer.add_object (svg); 		} 	}diff --git a/libbirdfont/EmbeddedSvg.vala b/libbirdfont/EmbeddedSvg.valaindex 8683f42..2ae8a5c 100644--- a/libbirdfont/EmbeddedSvg.vala+++ b/libbirdfont/EmbeddedSvg.vala@@ -22,32 +22,12 @@ public class EmbeddedSvg : Object { 	public string svg_data = ""; 	public SvgDrawing drawing = new SvgDrawing (); 	-	public double x {-		get {-			return drawing.x;-		}--		set {-			drawing.x = value;-		}-	}+	public double x { get; set; }+	public double y { get; set; } -	public double y {-		get {-			return drawing.y;-		}-		-		set {-			drawing.y = value;-		}-	}-	-	// FIXME: boundaries for embedded SVG-	 	public override double xmin { 		get {-			Glyph g = MainWindow.get_current_glyph ();-			return g.left_limit;+			return x; 		} 		 		set {@@ -56,8 +36,7 @@ public class EmbeddedSvg : Object {  	public override double xmax { 		get {-			Glyph g = MainWindow.get_current_glyph ();-			return g.right_limit;+			return x + drawing.width; 		}  		set {@@ -67,8 +46,7 @@ public class EmbeddedSvg : Object {  	public override double ymin { 		get {-			Font font = BirdFont.get_current_font ();-			return font.bottom_position;+			return y - drawing.height; 		}  		set {@@ -77,8 +55,7 @@ public class EmbeddedSvg : Object {  	public override double ymax { 		get {-			Font font = BirdFont.get_current_font ();-			return font.top_position;+			return y; 		}  		set {@@ -93,12 +70,20 @@ public class EmbeddedSvg : Object { 		drawing.update_region_boundaries (); 	} +	// FIXME: handle this in SVG library instead 	public override bool is_over (double x, double y) {-		return drawing.is_over (x, y);+		print (@" $(this.x) <= $(x) <= $(this.x) + $(drawing.width)");+		print (@" $(this.y) <= $(y) <= $(this.y) + $(drawing.height)");+			+		return (this.x <= x <= this.x + drawing.width) +			&& (this.y - drawing.height <= y <= this.y); 	} 	 	public override void draw (Context cr) {+		cr.save ();+		cr.translate (Glyph.xc () + x, Glyph.yc () - y); 		drawing.draw (cr);+		cr.restore (); 	} 	 	public override Object copy () {@@ -108,7 +93,8 @@ public class EmbeddedSvg : Object { 	} 	 	public override void move (double dx, double dy) {-		drawing.move (dx, dy);+		x += dx;+		y += dy; 	} 	 	public override void rotate (double theta, double xc, double yc) {diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex 9e99a0a..98f4bde 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -133,7 +133,6 @@ public class Glyph : FontDisplay { 	public Layer layers = new Layer (); 	public int current_layer = 0; 	public Gee.ArrayList<Object> active_paths = new Gee.ArrayList<Object> ();-	public Gee.ArrayList<Layer> selected_groups = new Gee.ArrayList<Layer> ();  	// used if this glyph originates from a fallback font 	public double top_limit = 0;@@ -263,7 +262,6 @@ public class Glyph : FontDisplay { 	}  	public void clear_active_paths () {-		selected_groups.clear (); 		active_paths.clear (); 	} @@ -276,6 +274,7 @@ public class Glyph : FontDisplay { 		} 	} 	+	// FIXME: delete group 	public void add_active_object (Layer? group, Object? o) { 		Object object; 		Layer g;@@ -298,13 +297,6 @@ public class Glyph : FontDisplay { 				PenTool.active_path = path.get_path (); 			} 		}--		if (group != null) {-			g = (!) group;-			if (!selected_groups.contains (g)) {-				selected_groups.add (g);-			}-		} 	}  	public bool active_paths_contains (Object object) {@@ -1207,61 +1199,14 @@ public class Glyph : FontDisplay { 		return -y; 	} -	public Layer? get_path_at (double x, double y) {-		Layer? group = null;-		bool found = false;--		foreach (Layer layer in get_current_layer ().subgroups) {-			foreach (Object o in layer.objects) {-				if (o.is_over (x, y)) {-					found = true;-					group = layer;-				}-			}-		}--		if (!found) {-			foreach (Path pt in get_paths_in_current_layer ()) {-				if (pt.is_over (x, y)) {-					Layer layer = new Layer ();-					layer.is_counter = true;-					layer.single_path = true;-					layer.add_path (pt);-					group = layer;-				}-			}-		}--		return group;-	}--	public bool select_path (double x, double y) {-		Path? p = null;-		bool found = false;--		foreach (Path pt in get_paths_in_current_layer ()) {-			if (pt.is_over (x, y)) {-				p = pt;-				found = true;-			}-		}--		if (!KeyBindings.has_shift ()) {-			clear_active_paths ();-		}--		add_active_path (null, p);--		return found;-	}--	public bool is_over_selected_path (double x, double y) {-		foreach (Object p in active_paths) {-			if (p.is_over (x, y)) {-				return true;+	public Object? get_object_at (double x, double y) {+		foreach (Object o in get_current_layer ().objects) {+			if (o.is_over (x, y)) {+				return o; 			} 		}-		return false;+		+		return null; 	}  	public void queue_redraw_path (Path path) {@@ -1280,48 +1225,6 @@ public class Glyph : FontDisplay { 		redraw_area ((int)xtb - 10, (int)yta - 10, (int)(xtb - xta) + 10, (int) (yta - ytb) + 10); 	} -	public Path get_closeset_path (double x, double y) {-		double d;-		EditPoint ep = new EditPoint ();--		Path min_point = new Path ();-		double min_distance = double.MAX;--		double xt = path_coordinate_x (x);-		double yt = path_coordinate_y (y);-		var paths = get_visible_paths ();--		foreach (Path p in paths) {-			if (p.is_over (xt, yt)) {-				return p;-			}-		}--		foreach (Path p in paths) {-			if (p.points.size == 0) continue;--			p.get_closest_point_on_path (ep, xt, yt);-			d = Math.pow (ep.x - xt, 2) + Math.pow (ep.y - yt, 2);--			if (d < min_distance) {-				min_distance = d;-				min_point = p;-			}--		}--		// a path without any editpoints-		if (paths.size > 0) {-			return paths.get (0);-		}--		if (unlikely (min_distance == double.MAX)) {-			warning (@"No path found in path_list.");-		}--		return min_point;-	}- 	public void move_selected_edit_point_coordinates (EditPoint selected_point, double xt, double yt) { 		double x, y; @@ -1756,6 +1659,13 @@ public class Glyph : FontDisplay { 			cr.restore (); 		} +		// FIXME: layer transforms+		foreach (Object o in get_visible_objects ()) {+			if (!(o is PathObject)) {+				o.draw (cr);+			}+		}+ 		if (!is_open ()) { 			// This was good for testing but it is way too slow: 			// Svg.draw_svg_path (cr, get_svg_data (), Glyph.xc () + left, Glyph.yc () - baseline);@@ -1779,13 +1689,6 @@ public class Glyph : FontDisplay { 			cr.fill (); 			cr.restore (); -			// FIXME: layer transforms-			foreach (Object o in get_visible_objects ()) {-				if (!(o is PathObject)) {-					o.draw (cr);-				}-			}- 			foreach (Object o in active_paths) { 				if (o is PathObject) { 					Path p = ((PathObject) o).get_path ();@@ -1855,8 +1758,8 @@ public class Glyph : FontDisplay { 		}  		if (unlikely (Preferences.draw_boundaries)) {-			foreach (Path p in get_visible_paths ()) {-				p.draw_boundaries (cmp);+			foreach (Object o in get_visible_objects ()) {+				draw_boundaries (o, cmp); 			} 		} @@ -2552,6 +2455,21 @@ public class Glyph : FontDisplay { 		return paths; 	} 	+	public void draw_boundaries  (Object object, Context cr) {+		double x = Glyph.reverse_path_coordinate_x (object.xmin); +		double y = Glyph.reverse_path_coordinate_y (object.ymin);+		double x2 = Glyph.reverse_path_coordinate_x (object.xmax);+		double y2 = Glyph.reverse_path_coordinate_y (object.ymax);+		+		cr.save ();+		+		Theme.color (cr, "Default Background");+		cr.set_line_width (2);+		cr.rectangle (x, y, x2 - x, y2 - y);+		cr.stroke ();+		+		cr.restore ();+	} }  }diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex ce5d5dc..1f3b2fd 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -127,16 +127,6 @@ public class MoveTool : Tool {  			delta_x = -dx; 			delta_y = -dy;-	-			foreach (Layer group in glyph.selected_groups) {-				if (group.gradient != null) {-					Gradient g = (!) group.gradient;-					g.x1 += delta_x;-					g.x2 += delta_x;-					g.y1 += delta_y;-					g.y2 += delta_y;-				}-			} 			 			foreach (Object object in glyph.active_paths) { 				object.move (delta_x, delta_y);@@ -198,36 +188,30 @@ public class MoveTool : Tool { 		Glyph glyph = MainWindow.get_current_glyph (); 		Object object; 		bool selected = false;-		Layer? group;-		Layer g;+		Object? o; 		-		glyph.store_undo_state ();-		group_selection = false;-	-		group = glyph.get_path_at (x, y);-		-		if (group != null) {-			g = (!) group;-			return_if_fail (g.objects.objects.size > 0);-			object = g.objects.objects.get (0);+		glyph.store_undo_state ();	+		double px = Glyph.path_coordinate_x (x);+		double py = Glyph.path_coordinate_y (y);+		o = glyph.get_object_at (px, py);++		if (o != null) {+			object = (!) o; 			selected = glyph.active_paths_contains (object);-			+ 			 			if (!selected && !KeyBindings.has_shift ()) { 				glyph.clear_active_paths (); 			}  			-			foreach (Object lp in g.objects) {-				if (selected && KeyBindings.has_shift ()) {-					glyph.selected_groups.remove ((!) group);-					glyph.active_paths.remove (lp);-				} else {-					glyph.add_active_object ((!) group, lp);-				}-			}+			if (selected && KeyBindings.has_shift ()) {+				glyph.active_paths.remove (object);+			} else {+				glyph.add_active_object (null, object);+			}			 		} else if (!KeyBindings.has_shift ()) { 			glyph.clear_active_paths (); 		}-		+ 		update_selection_boundaries ();  		move_path = true;diff --git a/libbirdfont/Path.vala b/libbirdfont/Path.valaindex 18cdcd3..488f395 100644--- a/libbirdfont/Path.vala+++ b/libbirdfont/Path.vala@@ -174,22 +174,6 @@ public class Path : GLib.Object { 		return points.size == 0; 	} -	public void draw_boundaries  (Context cr) {-		double x = Glyph.reverse_path_coordinate_x (xmin); -		double y = Glyph.reverse_path_coordinate_y (ymin);-		double x2 = Glyph.reverse_path_coordinate_x (xmax);-		double y2 = Glyph.reverse_path_coordinate_y (ymax);-		-		cr.save ();-		-		Theme.color (cr, "Default Background");-		cr.set_line_width (2);-		cr.rectangle (x, y, x2 - x, y2 - y);-		cr.stroke ();-		-		cr.restore ();-	}- 	public void draw_outline (Context cr) { 		unowned EditPoint? n = null; 		unowned EditPoint en;@@ -821,17 +805,6 @@ public class Path : GLib.Object { 		new_path.highlight_last_segment = highlight_last_segment; 		 		return new_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;-		-		return is_over_coordinate (x, y); 	} 	 	public bool is_over_coordinate (double x, double y) {diff --git a/libbirdfont/PathObject.vala b/libbirdfont/PathObject.valaindex 12850f0..b31e334 100644--- a/libbirdfont/PathObject.vala+++ b/libbirdfont/PathObject.vala@@ -153,7 +153,7 @@ public class PathObject : Object { 	}  	public override bool is_over (double x, double y) {-		return path.is_over (x, y);+		return path.is_over_coordinate (x, y); 	}  	public override void draw (Context cr) {diff --git a/libbirdfont/Svg/SvgDrawing.vala b/libbirdfont/Svg/SvgDrawing.valaindex ffc4c6c..84cb925 100644--- a/libbirdfont/Svg/SvgDrawing.vala+++ b/libbirdfont/Svg/SvgDrawing.vala@@ -27,7 +27,7 @@ public class SvgDrawing : Object { 	public double y = 0; 	public double width = 0; 	public double height = 0;-	+		 	public override void update_region_boundaries () { 	} 	@@ -37,9 +37,14 @@ public class SvgDrawing : Object { 	} 	 	public override void draw (Context cr) {+		cr.save ();+		cr.translate (x, y);+ 		foreach (Object o in root_layer.get_visible_objects ().objects) { 			o.draw (cr); 		}++		cr.restore (); 	} 	 	public override Object copy () {diff --git a/libbirdfont/TestCases.vala b/libbirdfont/TestCases.valaindex b6ae008..913219c 100644--- a/libbirdfont/TestCases.vala+++ b/libbirdfont/TestCases.vala@@ -33,7 +33,6 @@ class TestCases { 		add (test_drawing, "Pen tool"); 		add (test_delete_points, "Delete edit points"); 		add (test_convert_to_quadratic_bezier_path, "Convert to quadratic path");-		add (test_over_path, "Over path"); 		add (test_export, "Export"); 		add (test_background_coordinates, "Background coordinates"); 		add (test_spin_button, "Spin button");@@ -583,58 +582,6 @@ class TestCases { 		 	} -	public static void test_over_path () {-		Glyph g;-		Path p = new Path ();-		Tool pen_tool;-		-		pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool");-		test_select_action (pen_tool);-		test_open_next_glyph ();-		-		g = MainWindow.get_current_glyph ();--		test_click_action (pen_tool, 3, 10, 10);-		test_click_action (pen_tool, 3, 10, 10);-		test_click_action (pen_tool, 3, 100, 10);-		test_click_action (pen_tool, 3, 100, 100);-		test_click_action (pen_tool, 3, 10, 100);-		test_click_action (pen_tool, 2, 0, 0);--		g.close_path ();--		warn_if_fail (g.active_paths.size == 0);--		g.select_path (50, 50);--		warn_if_fail (g.active_paths.size == 1);-		-		p.add (-10, 10);-		p.add (10, 10);-		p.add (10, -10);-		p.add (-10, -10);-		p.update_region_boundaries();-		g.add_path (p);-		g.close_path ();--		if (!p.is_over_coordinate (0, 0)) {-			warning ("Coordinate 0, 0 is not in path.");-		}-		-		if (!p.is_over_coordinate (-10, 10)) {-			warning ("Corner corrdinate -10, 10 is not in path.");-		}-		-		warn_if_fail (!p.is_over_coordinate (-20, -20));-		-		for (double x = -10; x <= 10; x += 0.1) {-			for (double y = 10; y <= 10; y += 0.1) {-				warn_if_fail (p.is_over_coordinate (x, y));-			} -		} -		-	}- 	public static void test_convert_to_quadratic_bezier_path () { 		Glyph g; 		Path p, p1;

Contact

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