The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Bounding box for SVG rectangles

These changes was commited to the Birdfont repository Sat, 18 Jun 2016 19:08:49 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 18 Jun 2016 19:08:49 +0000]

Updated Files

libbirdfont/EmbeddedSvg.vala
libbirdfont/MenuTab.vala
libbirdfont/MoveTool.vala
libbirdfont/PathObject.vala
libbirdfont/ResizeTool.vala
libbirdfont/SvgParser.vala
libsvgbird/Circle.vala
libsvgbird/Ellipse.vala
libsvgbird/EmptyObject.vala
libsvgbird/Layer.vala
libsvgbird/Line.vala
libsvgbird/Object.vala
libsvgbird/Polygon.vala
libsvgbird/Polyline.vala
libsvgbird/Rectangle.vala
libsvgbird/SvgDrawing.vala
libsvgbird/SvgPath.vala
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -25,49 +25,18 @@ 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 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) {
--- a/libbirdfont/MenuTab.vala +++ b/libbirdfont/MenuTab.vala @@ -89,7 +89,7 @@ GlyphCanvas.redraw (); return false; }); - idle.attach (null); + idle.attach (MainContext.default ()); } public static bool validate_metadata () {
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -127,7 +127,7 @@ 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);
--- a/libbirdfont/PathObject.vala +++ b/libbirdfont/PathObject.vala @@ -70,7 +70,6 @@ public PathObject () { base (); path = new Path (); - update_region_boundaries (); } public PathObject.create_copy (PathObject p) { @@ -114,7 +113,7 @@ 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;
--- a/libbirdfont/ResizeTool.vala +++ b/libbirdfont/ResizeTool.vala @@ -555,7 +555,7 @@ 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 ()); } }
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -155,7 +155,7 @@ 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 ();
--- a/libsvgbird/Circle.vala +++ b/libsvgbird/Circle.vala @@ -35,9 +35,6 @@ } public override void move (double dx, double dy) { - } - - public override void update_region_boundaries () { } public override void rotate (double theta, double xc, double yc) {
--- a/libsvgbird/Ellipse.vala +++ b/libsvgbird/Ellipse.vala @@ -41,9 +41,6 @@ } public override void move (double dx, double dy) { - } - - public override void update_region_boundaries () { } public override void rotate (double theta, double xc, double yc) {
--- a/libsvgbird/EmptyObject.vala +++ b/libsvgbird/EmptyObject.vala @@ -31,9 +31,6 @@ public override void move (double dx, double dy) { } - public override void update_region_boundaries () { - } - public override void rotate (double theta, double xc, double yc) { }
--- a/libsvgbird/Layer.vala +++ b/libsvgbird/Layer.vala @@ -193,9 +193,6 @@ } public override void move (double dx, double dy) { - } - - public override void update_region_boundaries () { } public override void rotate (double theta, double xc, double yc) {
--- a/libsvgbird/Line.vala +++ b/libsvgbird/Line.vala @@ -47,9 +47,6 @@ public override void move (double dx, double dy) { } - public override void update_region_boundaries () { - } - public override void rotate (double theta, double xc, double yc) { }
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -114,15 +114,21 @@ 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;
--- a/libsvgbird/Polygon.vala +++ b/libsvgbird/Polygon.vala @@ -43,9 +43,6 @@ public override void move (double dx, double dy) { } - public override void update_region_boundaries () { - } - public override void rotate (double theta, double xc, double yc) { }
--- a/libsvgbird/Polyline.vala +++ b/libsvgbird/Polyline.vala @@ -39,9 +39,6 @@ } public override void move (double dx, double dy) { - } - - public override void update_region_boundaries () { } public override void rotate (double theta, double xc, double yc) {
--- a/libsvgbird/Rectangle.vala +++ b/libsvgbird/Rectangle.vala @@ -63,9 +63,6 @@ public override void move (double dx, double dy) { x += dx; y += dy; - } - - public override void update_region_boundaries () { } public override void rotate (double theta, double xc, double yc) { @@ -95,8 +92,76 @@ 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; } } }
--- a/libsvgbird/SvgDrawing.vala +++ b/libsvgbird/SvgDrawing.vala @@ -49,43 +49,13 @@ 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 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) {
--- a/libsvgbird/SvgPath.vala +++ b/libsvgbird/SvgPath.vala @@ -95,9 +95,6 @@ public override void move (double dx, double dy) { } - public override void update_region_boundaries () { - } - public override void rotate (double theta, double xc, double yc) { }