The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Set SVG padding in CSS and fix rounded rectangles

These changes was commited to the Birdfont repository Fri, 01 Jul 2016 22:46:58 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 01 Jul 2016 22:46:58 +0000 (00:46 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 01 Jul 2016 22:46:58 +0000 (00:46 +0200)
commit 84cb9e1a7daffd7e99363766504dcc78574a61fa
tree c9e100466ae738bdb21ed63bef8344c95d7c0507
parent 20c551d07a062d92a2c40496a34a7a6d6c080537
Set SVG padding in CSS and fix rounded rectangles

libsvgbird/Doubles.vala
libsvgbird/Rectangle.vala
libsvgbird/SvgStyle.vala
--- a/libsvgbird/Doubles.vala +++ b/libsvgbird/Doubles.vala @@ -94,7 +94,7 @@ 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";
--- a/libsvgbird/Rectangle.vala +++ b/libsvgbird/Rectangle.vala @@ -44,12 +44,15 @@ } 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) {
--- a/libsvgbird/SvgStyle.vala +++ b/libsvgbird/SvgStyle.vala @@ -26,10 +26,45 @@ 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 @@ 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 @@ 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) {