Commit 1c06696
Bounding box for SVG rectangles
Changed files (17)
modifiedlibbirdfont/EmbeddedSvg.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/PathObject.valamodifiedlibbirdfont/ResizeTool.valamodifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/Circle.valamodifiedlibsvgbird/Ellipse.valamodifiedlibsvgbird/EmptyObject.valamodifiedlibsvgbird/Layer.valamodifiedlibsvgbird/Line.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/Polygon.valamodifiedlibsvgbird/Polyline.valamodifiedlibsvgbird/Rectangle.valamodifiedlibsvgbird/SvgDrawing.valamodifiedlibsvgbird/SvgPath.vala
Diff
@@ -25,49 +25,18 @@ public class EmbeddedSvg : SvgBird.Object { public double x { get; set; } public double y { get; set; }-- public override double left { - get {- return x + drawing.left;- }- - set {- }- }- - public override double right { - get {- return x + drawing.right;- }- - set {- }- }-- public override double top {- get {- return drawing.top - y;- }- - set {- }- }-- public override double bottom {- get {- return drawing.bottom - y;- }- - set {- }- } public EmbeddedSvg (SvgDrawing drawing) { this.drawing = drawing; } - public override void update_region_boundaries () {- drawing.update_region_boundaries ();+ public override void update_boundaries (Matrix view_matrix) {+ drawing.update_boundaries (view_matrix);+ + left = x + drawing.left;+ right = x + drawing.right;+ top = -y + drawing.top;+ bottom = -y + drawing.bottom; } public override bool is_over (double x, double y) {@@ -88,6 +57,7 @@ public class EmbeddedSvg : SvgBird.Object { public override void move (double dx, double dy) { x += dx; y += dy;+ move_bounding_box (dx, -dy); } public override void rotate (double theta, double xc, double yc) {@@ -89,7 +89,7 @@ public class MenuTab : FontDisplay { GlyphCanvas.redraw (); return false; });- idle.attach (null);+ idle.attach (MainContext.default ()); } public static bool validate_metadata () {@@ -127,7 +127,7 @@ public class MoveTool : Tool { moved = true; delta_x = -dx;- delta_y = -dy;+ delta_y = dy; foreach (SvgBird.Object object in glyph.active_paths) { object.move (delta_x, delta_y);@@ -70,7 +70,6 @@ public class PathObject : SvgBird.Object { public PathObject () { base (); path = new Path ();- update_region_boundaries (); } public PathObject.create_copy (PathObject p) {@@ -114,7 +113,7 @@ public class PathObject : SvgBird.Object { return path; } - public override void update_region_boundaries () {+ public override void update_boundaries (Matrix matrix) { xmin = Glyph.CANVAS_MAX; xmax = Glyph.CANVAS_MIN; ymin = Glyph.CANVAS_MAX;@@ -555,7 +555,7 @@ public class ResizeTool : Tool { Path p = ((PathObject) path).get_path (); SvgParser.apply_matrix (p, 1, 0, s, 1, 0, 0); p.skew = skew;- path.update_region_boundaries ();+ path.update_boundaries (Matrix.identity ()); } } @@ -155,7 +155,7 @@ public class SvgParser { PathObject path = new PathObject.for_path (p); glyph.add_object (path); glyph.add_active_object (null, path); // FIXME: groups- path.update_region_boundaries ();+ path.update_boundaries (Cairo.Matrix.identity ()); } glyph.close_path (); @@ -36,9 +36,6 @@ public class Circle : Object { public override void move (double dx, double dy) { }- - public override void update_region_boundaries () {- } public override void rotate (double theta, double xc, double yc) { }@@ -42,9 +42,6 @@ public class Ellipse : Object { public override void move (double dx, double dy) { }- - public override void update_region_boundaries () {- } public override void rotate (double theta, double xc, double yc) { }@@ -31,9 +31,6 @@ public class EmptyObject : Object { public override void move (double dx, double dy) { } - public override void update_region_boundaries () {- }- public override void rotate (double theta, double xc, double yc) { } @@ -194,9 +194,6 @@ public class Layer : Object { public override void move (double dx, double dy) { }- - public override void update_region_boundaries () {- } public override void rotate (double theta, double xc, double yc) { }@@ -47,9 +47,6 @@ public class Line : Object { public override void move (double dx, double dy) { } - public override void update_region_boundaries () {- }- public override void rotate (double theta, double xc, double yc) { } @@ -114,15 +114,21 @@ public abstract class Object : GLib.Object { return open; } - public abstract void update_region_boundaries (); public abstract bool is_over (double x, double y); public abstract void draw_outline (Context cr); public abstract Object copy ();- public abstract void move (double dx, double dy); public abstract void rotate (double theta, double xc, double yc); public abstract bool is_empty (); public abstract void resize (double ratio_x, double ratio_y);+ public abstract void move (double dx, double dy);+ + public virtual void move_bounding_box (double dx, double dy) {+ top += dy;+ bottom += dy;+ left += dx;+ right += dx;+ } public static void copy_attributes (Object from, Object to) { to.open = from.open;@@ -43,9 +43,6 @@ public class Polygon : Object { public override void move (double dx, double dy) { } - public override void update_region_boundaries () {- }- public override void rotate (double theta, double xc, double yc) { } @@ -40,9 +40,6 @@ public class Polyline : Object { public override void move (double dx, double dy) { }- - public override void update_region_boundaries () {- } public override void rotate (double theta, double xc, double yc) { }@@ -64,9 +64,6 @@ public class Rectangle : Object { x += dx; y += dy; }- - public override void update_region_boundaries () {- } public override void rotate (double theta, double xc, double yc) { }@@ -96,6 +93,74 @@ public class Rectangle : Object { public override string to_string () { return "Rectangle"; }++ public override void update_boundaries (Matrix view_matrix) {+ Matrix object_matrix = transforms.get_matrix ();+ object_matrix.multiply (object_matrix, view_matrix);++ double x0, x1, x2, x3;+ double y0, y1, y2, y3;++ double half_stroke_width = style.stroke_width / 2;+ + x0 = x - half_stroke_width;+ y0 = y - half_stroke_width;++ x1 = x + width + half_stroke_width;+ y1 = y - half_stroke_width;++ x2 = x + width + half_stroke_width;+ y2 = y + height + half_stroke_width;++ x3 = x - half_stroke_width;+ y3 = y + height + half_stroke_width;+ + 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);+ + top = min (y0, y1, y2, y3);+ bottom = max (y0, y1, y2, y3);+ left = min (x0, x1, x2, x3);+ right = max (x0, x1, x2, x3);+ }+ + double min (double x0, double x1, double x2, double x3) {+ double m = x0;+ + if (x1 < m) {+ m = x1;+ }+ + if (x2 < m) {+ m = x2;+ }+ + if (x3 < m) {+ m = x3;+ }+ + return m;+ }+ + double max (double x0, double x1, double x2, double x3) {+ double m = x0;+ + if (x1 > m) {+ m = x1;+ }+ + if (x2 > m) {+ m = x2;+ }+ + if (x3 > m) {+ m = x3;+ }++ return m;+ } } }@@ -49,43 +49,13 @@ public class SvgDrawing : Object { public double svg_width = 0; public double svg_height = 0; - public override double left {- get {- return root_layer.left;- }-- set {- }- }-- public override double right {- get {- return root_layer.right;- }+ public override void update_boundaries (Matrix view_matrix) {+ root_layer.update_boundaries (view_matrix); - set {- }- }-- public override double top {- get {- return root_layer.top;- }- - set {- }- }-- public override double bottom {- get {- return root_layer.bottom;- }- - set {- }- }-- public override void update_region_boundaries () {+ left = x + root_layer.left;+ right = x + root_layer.right;+ top = y + root_layer.top;+ bottom = y + root_layer.bottom; } public override bool is_over (double x, double y) {@@ -116,6 +86,7 @@ public class SvgDrawing : Object { public override void move (double dx, double dy) { x += dx; y += dy;+ move_bounding_box (dx, dy); } public override void rotate (double theta, double xc, double yc) {@@ -95,9 +95,6 @@ public class SvgPath : Object { public override void move (double dx, double dy) { } - public override void update_region_boundaries () {- }- public override void rotate (double theta, double xc, double yc) { }