The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Better boundary calculation in color fonts

These changes was commited to the Birdfont repository Thu, 16 Jun 2016 09:24:20 +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>
Thu, 16 Jun 2016 09:24:20 +0000 (11:24 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 16 Jun 2016 09:25:25 +0000 (11:25 +0200)
commit 82659c8964c7747da166cdcd0b2a07482f17d70a
tree 4e39daeba592f0a7325788daa8f550d93872f0a1
parent d178f2990513bd96cb48af90d0f61c2725820da7
Better boundary calculation in color fonts

libsvgbird/Ellipse.vala
libsvgbird/Layer.vala
--- a/libsvgbird/Ellipse.vala +++ b/libsvgbird/Ellipse.vala @@ -23,42 +23,6 @@ public double cy = 0; public double rx = 0; public double ry = 0; - - public override double left { - get { - return cx - rx - style.stroke_width / 2; - } - - set { - } - } - - public override double right { - get { - return cx + rx + style.stroke_width / 2; - } - - set { - } - } - - public override double top { - get { - return cy - ry - style.stroke_width / 2; - } - - set { - } - } - - public override double bottom { - get { - return cy + ry + style.stroke_width / 2; - } - - set { - } - } public Ellipse () { } @@ -104,8 +68,35 @@ public override string to_string () { 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/Layer.vala +++ b/libsvgbird/Layer.vala @@ -13,6 +13,7 @@ */ using Cairo; + using Math; namespace SvgBird { @@ -32,6 +33,10 @@ } public override void update_boundaries (Matrix view_matrix) { + if (objects.size == 0) { + return; + } + top = CANVAS_MAX; bottom = CANVAS_MIN; left = CANVAS_MAX; @@ -41,84 +46,13 @@ layer_matrix.multiply (layer_matrix, view_matrix); foreach (Object object in objects) { - if (object is Layer) { - Layer sublayer = (Layer) object; - sublayer.update_boundaries (layer_matrix); - } - - if (object.boundaries_height > 0.000001 - && object.boundaries_width > 0.000001) { + object.update_boundaries (layer_matrix); - Matrix object_matrix = object.transforms.get_matrix (); - object_matrix.multiply (object_matrix, layer_matrix); - - 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); - - 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); - } + left = fmin (left, object.left); + right = fmax (right, object.right); + top = fmin (top, object.top); + bottom = fmax (bottom, object.bottom); } - } - - 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) {