Commit 00300e4
Fix bounding box
Changed files (5)
modifiedlibbirdfont/EmbeddedSvg.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/SvgDrawing.valamodifiedlibsvgbird/SvgTransforms.vala
Diff
@@ -23,16 +23,16 @@ public class EmbeddedSvg : SvgBird.Object { public string svg_data = ""; public SvgDrawing drawing = new SvgDrawing (); - public double x { get; set; }- public double y { get; set; }- + public double x;+ public double y;+ public EmbeddedSvg (SvgDrawing drawing) { this.drawing = drawing; } public override bool update_boundaries (Matrix view_matrix) { drawing.update_boundaries (view_matrix);- + left = x + drawing.left; right = x + drawing.right; top = -y + drawing.top;@@ -45,21 +45,24 @@ public class Layer : Object { Matrix layer_matrix = transforms.get_matrix (); layer_matrix.multiply (layer_matrix, view_matrix); + base.update_boundaries (view_matrix);+ foreach (Object object in objects) {- bool has_size = object.update_boundaries (layer_matrix);- - if (has_size) {- left = fmin (left, object.left);- right = fmax (right, object.right);- top = fmin (top, object.top);- bottom = fmax (bottom, object.bottom);- }+ object.update_boundaries (layer_matrix); } return boundaries_width != 0; } public void draw (Context cr) {+ draw_layer (cr, true);+ }++ public override void draw_outline (Context cr) {+ draw_layer (cr, false);+ }+ + private void draw_layer (Context cr, bool paint) { cr.save (); apply_transform (cr); @@ -79,10 +82,18 @@ public class Layer : Object { if (object is Layer) { Layer sublayer = (Layer) object;- sublayer.draw (cr); + + if (paint) {+ sublayer.draw (cr);+ } else {+ sublayer.draw_outline (cr);+ } } else { object.draw_outline (cr);- object.paint (cr);+ + if (paint) {+ object.paint (cr);+ } } cr.restore (); }@@ -90,19 +101,6 @@ public class Layer : Object { cr.restore (); } - public override void draw_outline (Context cr) {- apply_transform (cr);- - foreach (Object object in objects) {- cr.save ();- object.apply_transform (cr);- object.draw_outline (cr);- cr.restore ();- }- - cr.restore ();- }- public int index_of (Layer sublayer) { return objects.index_of (sublayer); }@@ -253,10 +253,8 @@ public abstract class Object : GLib.Object { ImageSurface surface = new Cairo.ImageSurface (Cairo.Format.ARGB32, 1, 1); Context context = new Cairo.Context (surface); - Matrix object_matrix = transforms.get_matrix ();- object_matrix.multiply (object_matrix, view_matrix);- context.set_matrix (object_matrix);- + context.set_matrix (view_matrix);+ apply_transform (context); draw_outline (context); double x0, y0, x1, y1;@@ -52,20 +52,21 @@ public class SvgDrawing : Object { public override bool update_boundaries (Matrix view_matrix) { root_layer.update_boundaries (view_matrix); - left = x + root_layer.left;- right = x + root_layer.right;- top = y + root_layer.top;- bottom = y + root_layer.bottom;- + left = root_layer.left;+ right = root_layer.right;+ top = root_layer.top;+ bottom = root_layer.bottom;+ return true; }- + public override bool is_over (double x, double y) { return (this.x <= x <= this.x + width) && (this.y <= y <= this.y + height); } public void draw (Context cr) {+ apply_transform (cr); root_layer.draw (cr); } @@ -78,8 +79,6 @@ public class SvgDrawing : Object { SvgBird.Object.copy_attributes (this, drawing); drawing.root_layer = (Layer) root_layer.copy (); drawing.defs = defs.copy ();- drawing.x = x;- drawing.y = y; drawing.width = width; drawing.height = height; return drawing;@@ -19,6 +19,9 @@ namespace SvgBird { public class SvgTransforms : GLib.Object { public Gee.ArrayList<SvgTransform> transforms; + public double x = 0;+ public double y = 0;+ public SvgTransforms () { transforms = new Gee.ArrayList<SvgTransform> (); }@@ -40,13 +43,9 @@ public class SvgTransforms : GLib.Object { public Matrix get_matrix () { Matrix matrix = Matrix.identity (); - if (transforms.size == 0) {- return Matrix.identity ();- }- - matrix = transforms.get (0).get_matrix ();+ matrix.translate (x, y); - for (int i = 1; i < transforms.size; i++) {+ for (int i = 0; i < transforms.size; i++) { matrix.multiply (matrix, transforms.get (i).get_matrix ()); } @@ -56,6 +55,10 @@ public class SvgTransforms : GLib.Object { public string to_string () { StringBuilder sb = new StringBuilder (); + if (x != 0 || y != 0) {+ sb.append (@"$(TransformType.TRANSLATE): $x,$y ");+ }+ foreach (SvgTransform t in transforms) { sb.append (t.to_string ()); sb.append (" ");