The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix bounding box

These changes was commited to the Birdfont repository Wed, 22 Jun 2016 09:38:44 +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>
Wed, 22 Jun 2016 09:38:44 +0000 (11:38 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 22 Jun 2016 09:38:44 +0000 (11:38 +0200)
commit 00300e4406fe164ec8c62c90304beb9c165a7803
tree 52509f3797e8c1f3a8b05b0fd493b6061a098c85
parent 45c9c3049b7344f2dd7637b452317591363f0641
Fix bounding box

libbirdfont/EmbeddedSvg.vala
libsvgbird/Layer.vala
libsvgbird/Object.vala
libsvgbird/SvgDrawing.vala
libsvgbird/SvgTransforms.vala
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -23,16 +23,16 @@ 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;
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -44,22 +44,25 @@ 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,24 +82,19 @@ 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 (); - } - - 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 (); }
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -253,10 +253,8 @@ 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;
--- a/libsvgbird/SvgDrawing.vala +++ b/libsvgbird/SvgDrawing.vala @@ -52,20 +52,21 @@ 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 @@ 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;
--- a/libsvgbird/SvgTransforms.vala +++ b/libsvgbird/SvgTransforms.vala @@ -18,6 +18,9 @@ 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 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 ()); } @@ -55,6 +54,10 @@ 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 ());