Commit eb62a54
Fix bounding box for SVG files with strokes
Changed files (4)
modifiedlibbirdfont/EmbeddedSvg.valamodifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/SvgStyle.vala
Diff
@@ -94,8 +94,6 @@ public class EmbeddedSvg : SvgBird.Object { svg.append ("</svg>\n"); - print (svg.str);- return svg.str; } @@ -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);@@ -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;@@ -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 () {