The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Use Cairo to calculate bounding boxes

These changes was commited to the Birdfont repository Sat, 18 Jun 2016 20:57:34 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 18 Jun 2016 20:57:34 +0000 (22:57 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 18 Jun 2016 20:57:34 +0000 (22:57 +0200)
commit d179b3a9dbf27733892f74e010ebb2165bb3af37
tree dd9d2753e25f82e131f56eeb565f3db7b059e1d2
parent e12cf38e5c8f9b6f9279fa16614c721b09ef8937
Use Cairo to calculate bounding boxes

libsvgbird/Ellipse.vala
libsvgbird/Object.vala
libsvgbird/Polygon.vala
libsvgbird/Polyline.vala
libsvgbird/Rectangle.vala
--- a/libsvgbird/Ellipse.vala +++ b/libsvgbird/Ellipse.vala @@ -67,33 +67,7 @@ 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); - } - } } }
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -237,9 +237,30 @@ 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; } } }
--- a/libsvgbird/Polygon.vala +++ b/libsvgbird/Polygon.vala @@ -29,6 +29,8 @@ } 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,7 +65,8 @@ public override string to_string () { return "Polygon"; } + } }
--- a/libsvgbird/Polyline.vala +++ b/libsvgbird/Polyline.vala @@ -29,6 +29,8 @@ } 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);
--- a/libsvgbird/Rectangle.vala +++ b/libsvgbird/Rectangle.vala @@ -94,74 +94,7 @@ 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; - } } }