Clone in a terminal:
Commit 2f77284
Johan Mattsson - 2016-06-15T13:15:26+00:00
2f772845a024ac45eb528a4e3bc241e87c1ab8e0johan.mattsson.m@gmail.com

SVG boundaries for ellipses

Changed files (7)

Diff

diff --git a/libbirdfont/EmbeddedSvg.vala b/libbirdfont/EmbeddedSvg.valaindex f7f2f61..38c5add 100644--- a/libbirdfont/EmbeddedSvg.vala+++ b/libbirdfont/EmbeddedSvg.vala@@ -26,42 +26,42 @@ public class EmbeddedSvg : SvgBird.Object { 	public double x { get; set; } 	public double y { get; set; } -	public override double left {+	public override double left {  		get {-			return x;+			return x + drawing.left; 		} 		 		set { 		} 	}--	public override double right {+	+	public override double right {  		get {-			return x + drawing.width;+			return x + drawing.right; 		}-+		 		set { 		} 	}-	+ 	public override double top { 		get {-			return y - drawing.height;+			return drawing.top - y; 		}-+		 		set { 		} 	}  	public override double bottom { 		get {-			return y;+			return drawing.bottom - y; 		}-+		 		set { 		} 	}-			+		 	public EmbeddedSvg (SvgDrawing drawing) { 		this.drawing = drawing; 	}@@ -71,8 +71,8 @@ public class EmbeddedSvg : SvgBird.Object { 	}  	public override bool is_over (double x, double y) {-		return (this.x <= x <= this.x + drawing.width) -			&& (this.y - drawing.height <= y <= this.y);+		return (xmin <= x <= xmax) +			&& (ymin <= y <= ymax); 	} 	 	public void draw_embedded_svg (Context cr) {diff --git a/libbirdfont/Glyph.vala b/libbirdfont/Glyph.valaindex fc9ac2c..7f7ee9c 100644--- a/libbirdfont/Glyph.vala+++ b/libbirdfont/Glyph.vala@@ -2459,7 +2459,10 @@ public class Glyph : FontDisplay { 		return g2; 	} 	-	// FIXME: convert everything to the new SvgBird.Object code+	public Gee.ArrayList<SvgBird.Object> get_active_objects () {+		return active_paths;+	}+	 	public Gee.ArrayList<Path> get_active_paths () { 		Gee.ArrayList<Path> paths = new Gee.ArrayList<Path> (); 		@@ -2567,7 +2570,7 @@ public class Glyph : FontDisplay { 		px2 = CANVAS_MIN; 		py2 = CANVAS_MIN; 		-		foreach (Path p in get_active_paths ()) {+		foreach (SvgBird.Object p in get_active_objects ()) { 			if (px > p.xmin) { 				px = p.xmin; 			} diff --git a/libbirdfont/MoveTool.vala b/libbirdfont/MoveTool.valaindex 24866d0..f6c6bfd 100644--- a/libbirdfont/MoveTool.vala+++ b/libbirdfont/MoveTool.vala@@ -343,7 +343,7 @@ public class MoveTool : Tool { 		PenTool.reset_stroke (); 		update_selection_boundaries (); 		objects_moved ();-		glyph.redraw_area (0, 0, glyph.allocation.width, glyph.allocation.height);+		GlyphCanvas.redraw (); 	}  	static void tie_path_to_ttf_grid (SvgBird.Object p) {diff --git a/libsvgbird/Ellipse.vala b/libsvgbird/Ellipse.valaindex 0c2fd28..a7a336a 100644--- a/libsvgbird/Ellipse.vala+++ b/libsvgbird/Ellipse.vala@@ -23,7 +23,43 @@ public class Ellipse : Object { 	public double cy = 0; 	public double rx = 0; 	public double ry = 0;++	public override double left {+		get {+			return cx - rx - style.stroke_width / 2;+		}+		+		set {+		}+	}++	public override double right  {+		get {+			return cx + rx + style.stroke_width / 2;+		}+		+		set {+		}+	}+	+	public override double top  {+		get {+			return cy - ry - style.stroke_width / 2;+		}+		+		set {+		}+	} 	+	public override double bottom  {+		get {+			return cy + ry + style.stroke_width / 2;+		}+		+		set {+		}+	}+		 	public Ellipse () { 	} 	@@ -59,9 +95,6 @@ public class Ellipse : Object { 	public override Object copy () { 		Ellipse e = new Ellipse (); 		Object.copy_attributes (this, e);-		-		print (@"cy $(cy)\n");-		 		e.cx = cx; 		e.cy = cy; 		e.rx = rx;diff --git a/libsvgbird/Layer.vala b/libsvgbird/Layer.valaindex 115cb8b..a4620e2 100644--- a/libsvgbird/Layer.vala+++ b/libsvgbird/Layer.vala@@ -31,6 +31,40 @@ public class Layer : Object { 		transforms = new SvgTransforms (); 	} 	+	public void update_boundaries () {+		top = CANVAS_MAX;+		bottom = CANVAS_MIN;+		left = CANVAS_MAX;+		right = CANVAS_MIN;++		foreach (Object object in objects) {+			if (object is Layer) {+				Layer sublayer = (Layer) object;+				sublayer.update_boundaries ();+			}+			+			if (object.boundaries_height > 0.000001 +				&& object.boundaries_width > 0.000001) {+				+				if (object.top < top) {+					top = object.top;+				}++				if (object.bottom > bottom) {+					bottom = object.bottom;+				}+				+				if (object.left < left) {+					left = object.left;+				}++				if (object.right > right) {+					right = object.right;+				}+			}+		}+	}+	 	public void draw (Context cr) { 		cr.save (); 		apply_transform (cr);@@ -81,14 +115,17 @@ public class Layer : Object { 		 	public void add_layer (Layer layer) { 		objects.add (layer);+		update_boundaries (); 	} 	 	public void add_object (Object object) { 		objects.add (object);+		update_boundaries (); 	}  	public void remove (Object o) { 		objects.remove (o);+		update_boundaries (); 	} 	 	public void remove_layer (Layer layer) {@@ -100,6 +137,8 @@ public class Layer : Object { 				sublayer.remove_layer (layer); 			} 		}+		+		update_boundaries (); 	} 	 	public static void copy_layer (Layer from, Layer to) {diff --git a/libsvgbird/Object.vala b/libsvgbird/Object.valaindex 1819dea..d964400 100644--- a/libsvgbird/Object.vala+++ b/libsvgbird/Object.vala@@ -72,29 +72,33 @@ public abstract class Object : GLib.Object {  	public double ymin { 		get {-			return top - boundaries_height;+			return -top - boundaries_height; 		} 		 		set {-			top = value + boundaries_height;+			top = boundaries_height - value; 		} 	}  	public double ymax { 		get {-			return top;+			return -top; 		} 		 		set {-			top = value;+			top = -value; 		} 	} +	// FIXME: DELETE 	public virtual double rotation { get; set; } 	public virtual double stroke { get; set; } 	public virtual LineCap line_cap { get; set; default = LineCap.BUTT; } 	public virtual bool fill { get; set; }-		+	+	public const double CANVAS_MAX = 100000;+	public const double CANVAS_MIN = -100000;+	 	public Object () {	 	} @@ -226,7 +230,9 @@ public abstract class Object : GLib.Object { 		object_matrix.multiply (object_matrix, view_matrix); 		cr.set_matrix (object_matrix); 	}-					+	+	public virtual void update_boundaries () {	+	} }  }diff --git a/libsvgbird/SvgDrawing.vala b/libsvgbird/SvgDrawing.valaindex ba157b2..5b870b1 100644--- a/libsvgbird/SvgDrawing.vala+++ b/libsvgbird/SvgDrawing.vala@@ -51,7 +51,7 @@ public class SvgDrawing : Object {  	public override double left { 		get {-			return x;+			return root_layer.left; 		}  		set {@@ -60,7 +60,7 @@ public class SvgDrawing : Object {  	public override double right { 		get {-			return x + width;+			return root_layer.right; 		} 		 		set {@@ -69,7 +69,7 @@ public class SvgDrawing : Object {  	public override double top { 		get {-			return y;+			return root_layer.top; 		} 		 		set {@@ -78,7 +78,7 @@ public class SvgDrawing : Object {  	public override double bottom { 		get {-			return y + height;+			return root_layer.bottom; 		} 		 		set {

Contact

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