Clone in a terminal:
Commit 82659c8
Johan Mattsson - 2016-06-16T09:25:25+00:00
82659c8964c7747da166cdcd0b2a07482f17d70ajohan.mattsson.m@gmail.com

Better boundary calculation in color fonts

Changed files (2)

Diff

diff --git a/libsvgbird/Ellipse.vala b/libsvgbird/Ellipse.valaindex a7a336a..24eef9d 100644--- a/libsvgbird/Ellipse.vala+++ b/libsvgbird/Ellipse.vala@@ -23,42 +23,6 @@ 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 () { 	}@@ -105,6 +69,33 @@ public class Ellipse : Object { 	public override string to_string () { 		return "Ellipse"; 	}++	public override void update_boundaries (Matrix view_matrix) {+		Matrix object_matrix = transforms.get_matrix ();+		object_matrix.multiply (object_matrix, view_matrix);++		double radius_x = rx + style.stroke_width / 2;+		double radius_y = ry + style.stroke_width / 2;+		+		double px, py;+		+		top = CANVAS_MAX;+		bottom = CANVAS_MIN;+		left = CANVAS_MAX;+		right = CANVAS_MIN;+		+		for (double a = 0; a < 2 * PI; a += (2 * PI) / 20) {+			px = cx + radius_x * cos (a);+			py = cy + radius_y * sin (a);+			+			object_matrix.transform_point (ref px, ref py);+			+			top = fmin (top, py);+			bottom = fmax (bottom, py);+			left = fmin (left, px);+			right = fmax (right, px);+		}+	} }  }diff --git a/libsvgbird/Layer.vala b/libsvgbird/Layer.valaindex 983284d..70d8146 100644--- a/libsvgbird/Layer.vala+++ b/libsvgbird/Layer.vala@@ -13,6 +13,7 @@ */  using Cairo;+using Math;  namespace SvgBird { @@ -32,6 +33,10 @@ public class Layer : Object { 	} 	 	public override void update_boundaries (Matrix view_matrix) {+		if (objects.size == 0) {+			return;+		}+		 		top = CANVAS_MAX; 		bottom = CANVAS_MIN; 		left = CANVAS_MAX;@@ -41,84 +46,13 @@ public class Layer : Object { 		layer_matrix.multiply (layer_matrix, view_matrix);  		foreach (Object object in objects) {-			if (object is Layer) {-				Layer sublayer = (Layer) object;-				sublayer.update_boundaries (layer_matrix);-			}-			-			if (object.boundaries_height > 0.000001 -				&& object.boundaries_width > 0.000001) {--				Matrix object_matrix = object.transforms.get_matrix ();-				object_matrix.multiply (object_matrix, layer_matrix);-				-				double x0, x1, x2, x3;-				double y0, y1, y2, y3;-				-				x0 = object.left;-				y0 = object.top;-				x1 = object.right;-				y1 = object.top;-				x2 = object.right;-				y2 = object.bottom;-				x3 = object.left;-				y3 = object.bottom;--				object_matrix.transform_point (ref x0, ref y0);-				object_matrix.transform_point (ref x1, ref y1);-				object_matrix.transform_point (ref x2, ref y2);-				object_matrix.transform_point (ref x3, ref y3);+			object.update_boundaries (layer_matrix); -				left = min (left, x0, x1, x2, x3);-				right = max (right, x0, x1, x2, x3);-				top = min (top, y0, y1, y2, y3);-				bottom = max (bottom, y0, y1, y2, y3);-			}-		}-	}-	-	static double min (double x0, double x1, double x2, double x3, double x4) {-		double r = x0;--		if (x1 < r) {-			r = x1;-		}--		if (x2 < r) {-			r = x2;+			left = fmin (left, object.left);+			right = fmax (right, object.right);+			top = fmin (top, object.top);+			bottom = fmax (bottom, object.bottom); 		}--		if (x3 < r) {-			r = x3;-		}--		if (x4 < r) {-			r = x4;-		}-		-		return r;-	}--	static double max (double x0, double x1, double x2, double x3, double x4) {-		double r = x0;--		if (x1 > r) {-			r = x1;-		}--		if (x2 > r) {-			r = x2;-		}--		if (x3 > r) {-			r = x3;-		}--		if (x4 > r) {-			r = x4;-		}-		-		return r; 	} 	 	public void draw (Context cr) {

Contact

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