Commit d178f29
Apply matrix transform to boundaries
Changed files (4)
modifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/PathObject.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Object.vala
Diff
@@ -354,7 +354,7 @@ public class Glyph : FontDisplay { 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 @@ public class Glyph : FontDisplay { y2 = object.ymax; } }-+ return x1 != CANVAS_MAX; } @@ -734,7 +734,7 @@ public class Glyph : FontDisplay { x2 = max_x; y2 = min_y; - return max_x != CANVAS_MIN;+ return true; } void boundaries_for_object (SvgBird.Object object, @@ -1852,9 +1852,6 @@ public class Glyph : FontDisplay { Glyph g = copy (); undo_list.add (g); - print ("\n\n");- print_layers (g.layers);- if (clear_redo) { redo_list.clear (); }@@ -20,6 +20,42 @@ namespace BirdFont { 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 {@@ -31,40 +31,96 @@ public class Layer : Object { 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) { cr.save (); apply_transform (cr);@@ -115,17 +171,17 @@ public class Layer : Object { 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 @@ public class Layer : Object { } } - update_boundaries ();+ update_boundaries (Matrix.identity ()); } public static void copy_layer (Layer from, Layer to) {@@ -231,7 +231,7 @@ public abstract class Object : GLib.Object { cr.set_matrix (object_matrix); } - public virtual void update_boundaries () { + public virtual void update_boundaries (Matrix view_matrix) { } }