Clone in a terminal:
Commit 84cb9e1
Johan Mattsson - 2016-07-01T22:46:58+00:00
84cb9e1a7daffd7e99363766504dcc78574a61fajohan.mattsson.m@gmail.com

Set SVG padding in CSS and fix rounded rectangles

Changed files (3)

Diff

diff --git a/libsvgbird/Doubles.vala b/libsvgbird/Doubles.valaindex 431e1cf..13f96dd 100644--- a/libsvgbird/Doubles.vala+++ b/libsvgbird/Doubles.vala@@ -94,7 +94,7 @@ public class Doubles : GLib.Object { 		string v = p.to_string (); 		char[] c = new char [501]; 		-		v = p.format (c, "%3.15f");+		v = p.format (c, "%3.5f"); 		 		if (v.index_of ("e") != -1) {	 			return "0.0";diff --git a/libsvgbird/Rectangle.vala b/libsvgbird/Rectangle.valaindex d9cb79e..0fcee4e 100644--- a/libsvgbird/Rectangle.vala+++ b/libsvgbird/Rectangle.vala@@ -44,12 +44,15 @@ public class Rectangle : Object { 	} 	 	public void draw_rounded_corners (Context cr) {+		cr.save (); 		cr.new_path ();+		cr.translate (-rx, -ry); 		elliptical_arc (cr, x + width - rx, y + ry, -PI / 2, 0); 		elliptical_arc (cr, x + width - rx, y + height - ry, 0, PI / 2); 		elliptical_arc (cr, x + rx, y + height - ry, PI / 2, PI); 		elliptical_arc (cr, x + rx, y + ry, PI, PI + PI / 2); 		cr.close_path ();+		cr.restore (); 	} 	 	public void elliptical_arc (Context cr, double x, double y, double angle_start, double angle_stop) {diff --git a/libsvgbird/SvgStyle.vala b/libsvgbird/SvgStyle.valaindex d1f7b76..85b8754 100644--- a/libsvgbird/SvgStyle.vala+++ b/libsvgbird/SvgStyle.vala@@ -26,10 +26,45 @@ public class SvgStyle : GLib.Object { 	public Gradient? fill_gradient = null; 	public LineCap line_cap = LineCap.BUTT; -	public double padding_top = 0;-	public double padding_right = 0;-	public double padding_bottom = 0;-	public double padding_left = 0;+	public double padding_top {+		get {+			return SvgFile.parse_number (get_css_property ("padding-top"));+		}+		+		set {+			set_style ("padding-top", Doubles.round (value) + "px");+		}+	}+	+	public double padding_right {+		get {+			return SvgFile.parse_number (get_css_property ("padding-right"));+		}+		+		set {+			set_style ("padding-right", Doubles.round (value) + "px");+		}+	}+	+	public double padding_bottom {+		get {+			return SvgFile.parse_number (get_css_property ("padding-bottom"));+		}+		+		set {+			set_style ("padding-bottom", Doubles.round (value) + "px");+		}+	}+	+	public double padding_left {+		get {+			return SvgFile.parse_number (get_css_property ("padding-left"));+		}+		+		set {+			set_style ("padding-left", Doubles.round (value) + "px");+		}+	}  	public double stroke_width = 0; @@ -243,7 +278,7 @@ public class SvgStyle : GLib.Object { 		return s; 	} 	-	static void set_style_properties (Defs? d, SvgStyle s) {+	public static void set_style_properties (Defs? d, SvgStyle s) { 		double fill_opacity = 1; 		double stroke_opacity = 1; @@ -277,11 +312,6 @@ public class SvgStyle : GLib.Object { 			Color color = (!) s.stroke; 			color.a = stroke_opacity; 		}-		-		s.padding_bottom = SvgFile.parse_number (s.get_css_property ("padding-bottom"));-		s.padding_top = SvgFile.parse_number (s.get_css_property ("padding-top"));-		s.padding_left = SvgFile.parse_number (s.get_css_property ("padding-left"));-		s.padding_right = SvgFile.parse_number (s.get_css_property ("padding-right")); 	} 	 	void parse_key_value_pairs (string svg_style) {

Contact

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