The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Apply matrix transform to boundaries

These changes was commited to the Birdfont repository Wed, 15 Jun 2016 20:22:59 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Wed, 15 Jun 2016 20:22:59 +0000]

Updated Files

libbirdfont/Glyph.vala
libbirdfont/PathObject.vala
libsvgbird/Layer.vala
libsvgbird/Object.vala
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -354,7 +354,7 @@ y2 = CANVAS_MIN; foreach (SvgBird.Object object in objects) { - object.update_boundaries (); + object.update_boundaries (Matrix.identity ()); if (object is PathObject) { PathObject path = (PathObject) object; @@ -380,7 +380,7 @@ y2 = object.ymax; } } - + return x1 != CANVAS_MAX; } @@ -734,7 +734,7 @@ x2 = max_x; y2 = min_y; - return max_x != CANVAS_MIN; + return true; } void boundaries_for_object (SvgBird.Object object, @@ -1851,9 +1851,6 @@ public void store_undo_state (bool clear_redo = false) { Glyph g = copy (); undo_list.add (g); - - print ("\n\n"); - print_layers (g.layers); if (clear_redo) { redo_list.clear ();
--- a/libbirdfont/PathObject.vala +++ b/libbirdfont/PathObject.vala @@ -20,6 +20,42 @@ public class PathObject : SvgBird.Object { public Path path; + + public override double left { + get { + return path.xmin; + } + + set { + } + } + + public override double right { + get { + return path.xmax; + } + + set { + } + } + + public override double top { + get { + return -path.ymax; + } + + set { + } + } + + public override double bottom { + get { + return -path.ymin; + } + + set { + } + } public override double stroke { get {
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -31,38 +31,94 @@ transforms = new SvgTransforms (); } - public void update_boundaries () { + public override void update_boundaries (Matrix view_matrix) { top = CANVAS_MAX; bottom = CANVAS_MIN; left = CANVAS_MAX; right = CANVAS_MIN; + + Matrix layer_matrix = transforms.get_matrix (); + layer_matrix.multiply (layer_matrix, view_matrix); foreach (Object object in objects) { if (object is Layer) { Layer sublayer = (Layer) object; - sublayer.update_boundaries (); + sublayer.update_boundaries (layer_matrix); } if (object.boundaries_height > 0.000001 && object.boundaries_width > 0.000001) { - - if (object.top < top) { - top = object.top; - } - if (object.bottom > bottom) { - bottom = object.bottom; - } + Matrix object_matrix = object.transforms.get_matrix (); + object_matrix.multiply (object_matrix, layer_matrix); - if (object.left < left) { - left = object.left; - } + double x0, x1, x2, x3; + double y0, y1, y2, y3; + + x0 = object.left; + y0 = object.top; + x1 = object.right; + y1 = object.top; + x2 = object.right; + y2 = object.bottom; + x3 = object.left; + y3 = object.bottom; + + object_matrix.transform_point (ref x0, ref y0); + object_matrix.transform_point (ref x1, ref y1); + object_matrix.transform_point (ref x2, ref y2); + object_matrix.transform_point (ref x3, ref y3); - if (object.right > right) { - right = object.right; - } + left = min (left, x0, x1, x2, x3); + right = max (right, x0, x1, x2, x3); + top = min (top, y0, y1, y2, y3); + bottom = max (bottom, y0, y1, y2, y3); } } + } + + static double min (double x0, double x1, double x2, double x3, double x4) { + double r = x0; + + if (x1 < r) { + r = x1; + } + + if (x2 < r) { + r = x2; + } + + if (x3 < r) { + r = x3; + } + + if (x4 < r) { + r = x4; + } + + return r; + } + + static double max (double x0, double x1, double x2, double x3, double x4) { + double r = x0; + + if (x1 > r) { + r = x1; + } + + if (x2 > r) { + r = x2; + } + + if (x3 > r) { + r = x3; + } + + if (x4 > r) { + r = x4; + } + + return r; } public void draw (Context cr) { @@ -115,17 +171,17 @@ public void add_layer (Layer layer) { objects.add (layer); - update_boundaries (); + update_boundaries (Matrix.identity ()); } public void add_object (Object object) { objects.add (object); - update_boundaries (); + update_boundaries (Matrix.identity ()); } public void remove (Object o) { objects.remove (o); - update_boundaries (); + update_boundaries (Matrix.identity ()); } public void remove_layer (Layer layer) { @@ -138,7 +194,7 @@ } } - update_boundaries (); + update_boundaries (Matrix.identity ()); } public static void copy_layer (Layer from, Layer to) {
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -231,9 +231,9 @@ cr.set_matrix (object_matrix); } - public virtual void update_boundaries () { + public virtual void update_boundaries (Matrix view_matrix) { } } }