Clone in a terminal:
Commit eb62a54
Johan Mattsson - 2016-06-26T17:14:01+00:00
eb62a544ad92a4fee096cfec3a205b9664a1aaacjohan.mattsson.m@gmail.com

Fix bounding box for SVG files with strokes

Changed files (4)

Diff

diff --git a/libbirdfont/EmbeddedSvg.vala b/libbirdfont/EmbeddedSvg.valaindex af84c7d..c7aa09a 100644--- a/libbirdfont/EmbeddedSvg.vala+++ b/libbirdfont/EmbeddedSvg.vala@@ -94,8 +94,6 @@ public class EmbeddedSvg : SvgBird.Object { 		 		svg.append ("</svg>\n"); 		-		print (svg.str);-		 		return svg.str; 	} diff --git a/libbirdfont/SvgParser.vala b/libbirdfont/SvgParser.valaindex 47e7b05..bfe70e8 100644--- a/libbirdfont/SvgParser.vala+++ b/libbirdfont/SvgParser.vala@@ -92,7 +92,7 @@ public class SvgParser { 			Font font = BirdFont.get_current_font (); 			 			drawing.x = glyph.left_limit;-			drawing.y = font.top_position - font.base_line;+			drawing.y = font.top_limit - font.base_line; 		} catch (GLib.Error e) { 			warning (e.message); 		}@@ -1610,8 +1610,6 @@ public class SvgParser { 		SvgDrawing drawing = new SvgDrawing ();	 		SvgFile svg_file = new SvgFile ();  -		print (xml_data);- 		XmlElement root = tree.get_root (); 		drawing = svg_file.parse_svg_file (root); 		EmbeddedSvg svg = new EmbeddedSvg (drawing);diff --git a/libsvgbird/Object.vala b/libsvgbird/Object.valaindex b6525ce..1e6e814 100644--- a/libsvgbird/Object.vala+++ b/libsvgbird/Object.vala@@ -203,16 +203,19 @@ public abstract class Object : GLib.Object { 	/** @return true if the object has an area. */ 	public virtual bool update_boundaries (Context context) { 		double x0, y0, x1, y1;+		bool has_stroke = style.has_stroke (); -		context.set_line_width (style.stroke_width);+		if (has_stroke) {+			context.set_line_width (style.stroke_width);+		} else {+			context.set_line_width (0);+		}+		 		draw_outline (context);  		context.save (); 		-		Matrix m = Matrix.identity ();-		context.set_matrix (m);-		-		if (style.stroke_width > 0) {	+		if (has_stroke) {	 			context.stroke_extents (out x0, out y0, out x1, out y1); 		} else { 			context.path_extents (out x0, out y0, out x1, out y1);@@ -220,6 +223,10 @@ public abstract class Object : GLib.Object { 		 		context.restore (); 		+		Matrix m = context.get_matrix ();+		m.transform_point (ref x0, ref y0);+		m.transform_point (ref x1, ref y1);+		 		left = x0; 		top = y0; 		right = x1;diff --git a/libsvgbird/SvgStyle.vala b/libsvgbird/SvgStyle.valaindex d35f244..c6ebc87 100644--- a/libsvgbird/SvgStyle.vala+++ b/libsvgbird/SvgStyle.vala@@ -146,13 +146,21 @@ public class SvgStyle : GLib.Object { 	} 	 	public bool has_stroke () {-		bool s = true;+		bool has_stroke = true; 		 		if (style.has_key ("stroke")) {-			s = style.get ("stroke") != "none";+			has_stroke = style.get ("stroke") != "none"; 		}-				-		return stroke_width > 0 && s;+		+		if (stroke != null) {+			Color c = (!) stroke;+			+			if (c.a == 0) {+				return false;+			}+		}+		+		return stroke_width > 0 && has_stroke; 	} 		 	public double get_stroke_width () {

Contact

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