Commit d179b3a
Use Cairo to calculate bounding boxes
Changed files (5)
modifiedlibsvgbird/Ellipse.valamodifiedlibsvgbird/Object.valamodifiedlibsvgbird/Polygon.valamodifiedlibsvgbird/Polyline.valamodifiedlibsvgbird/Rectangle.vala
Diff
@@ -67,32 +67,6 @@ public class Ellipse : Object { return "Ellipse"; } - public override void update_boundaries (Matrix view_matrix) {- Matrix object_matrix = transforms.get_matrix ();- object_matrix.multiply (object_matrix, view_matrix);-- double radius_x = rx + style.stroke_width / 2;- double radius_y = ry + style.stroke_width / 2;- - double px, py;- - top = CANVAS_MAX;- bottom = CANVAS_MIN;- left = CANVAS_MAX;- right = CANVAS_MIN;- - for (double a = 0; a < 2 * PI; a += (2 * PI) / 20) {- px = cx + radius_x * cos (a);- py = cy + radius_y * sin (a);- - object_matrix.transform_point (ref px, ref py);- - top = fmin (top, py);- bottom = fmax (bottom, py);- left = fmin (left, px);- right = fmax (right, px);- }- } } }@@ -237,7 +237,28 @@ public abstract class Object : GLib.Object { cr.set_matrix (object_matrix); } - public virtual void update_boundaries (Matrix view_matrix) { + public virtual void update_boundaries (Matrix view_matrix) {+ 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);+ + draw_outline (context);+ + double x0, y0, x1, y1;+ + if (style.stroke_width == 0) {+ context.path_extents (out x0, out y0, out x1, out y1);+ } else {+ context.stroke_extents (out x0, out y0, out x1, out y1);+ }+ + left = x0;+ top = y0;+ right = x1;+ bottom = y1; } } @@ -29,6 +29,8 @@ public class Polygon : Object { } public override void draw_outline (Context cr) {+ return_if_fail (points.size % 2 == 0);+ if (points.size > 2) { cr.move_to (points.data[0].value, points.data[1].value); @@ -63,6 +65,7 @@ public class Polygon : Object { public override string to_string () { return "Polygon"; }+ } }@@ -29,6 +29,8 @@ public class Polyline : Object { } public override void draw_outline (Context cr) {+ return_if_fail (points.size % 2 == 0);+ if (points.size > 2) { cr.move_to (points.data[0].value, points.data[1].value); @@ -94,73 +94,6 @@ public class Rectangle : Object { 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;- } } }