The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix bounding box for SVG files with strokes

These changes was commited to the Birdfont repository Sun, 26 Jun 2016 17:14:01 +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>
Sun, 26 Jun 2016 17:14:01 +0000 (19:14 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 26 Jun 2016 17:14:01 +0000 (19:14 +0200)
commit eb62a544ad92a4fee096cfec3a205b9664a1aaac
tree 6ab85fbb8e7fbf6087ebeba68d2150b7448cfc77
parent 05222cac34dc561136118ccd5fba2dfa96f72215
Fix bounding box for SVG files with strokes

libbirdfont/EmbeddedSvg.vala
libbirdfont/SvgParser.vala
libsvgbird/Object.vala
libsvgbird/SvgStyle.vala
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -93,8 +93,6 @@ svg.append ("</g>\n"); svg.append ("</svg>\n"); - - print (svg.str); return svg.str; }
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -92,7 +92,7 @@ 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); } @@ -1609,8 +1609,6 @@ XmlTree tree = new XmlTree (xml_data); SvgDrawing drawing = new SvgDrawing (); SvgFile svg_file = new SvgFile (); - - print (xml_data); XmlElement root = tree.get_root (); drawing = svg_file.parse_svg_file (root);
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -203,22 +203,29 @@ /** @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); } 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;
--- a/libsvgbird/SvgStyle.vala +++ b/libsvgbird/SvgStyle.vala @@ -146,13 +146,21 @@ } 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 () {