The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Use entire path instead of control points in glyph boundaries

These changes was commited to the Birdfont repository Tue, 14 Apr 2015 10:26:22 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Tue, 14 Apr 2015 10:26:22 +0000]

Updated Files

libbirdfont/Glyph.vala
libbirdfont/Line.vala
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -211,7 +211,6 @@ p.update_region_boundaries (); if (p.points.size > 1) { - if (p.xmin < x1) { x1 = p.xmin; } @@ -492,7 +491,7 @@ public double get_left_side_bearing () { double x1, y1, x2, y2; - if (boundaries (out x1, out y1, out x2, out y2)) { + if (get_boundaries (out x1, out y1, out x2, out y2)) { return x1 - left_limit; } else { return right_limit - left_limit; @@ -502,11 +501,60 @@ public double get_right_side_bearing () { double x1, y1, x2, y2; - if (boundaries (out x1, out y1, out x2, out y2)) { + if (get_boundaries (out x1, out y1, out x2, out y2)) { return right_limit - x2; } else { return right_limit - left_limit; } + } + + public bool get_boundaries (out double x1, out double y1, + out double x2, out double y2) { + + double max_x, min_x, max_y, min_y; + + if (path_list.size == 0) { + x1 = 0; + y1 = 0; + x2 = 0; + y2 = 0; + return false; + } + + max_x = CANVAS_MIN; + min_x = CANVAS_MAX; + max_y = CANVAS_MIN; + min_y = CANVAS_MAX; + + // FIXME: optimize + foreach (Path p in path_list) { + p.all_of_path ((x, y, t) => { + if (x > max_x) { + max_x = x; + } + + if (y > max_y) { + max_y = y; + } + + if (x < min_x) { + min_x = x; + } + + if (y < min_y) { + min_y = y; + } + + return true; + }); + } + + x1 = min_x; + y1 = max_y; + x2 = max_x; + y2 = min_y; + + return max_x != CANVAS_MIN; } bool has_top_line () {
--- a/libbirdfont/Line.vala +++ b/libbirdfont/Line.vala @@ -161,13 +161,13 @@ parsed_value = double.parse (submitted_value); if (lsb) { - if (glyph.boundaries (out x1, out y1, out x2, out y2)) { + if (glyph.get_boundaries (out x1, out y1, out x2, out y2)) { parsed_value = x1 - parsed_value; } else { parsed_value = glyph.right_limit - parsed_value; } } else if (rsb) { - if (glyph.boundaries (out x1, out y1, out x2, out y2)) { + if (glyph.get_boundaries (out x1, out y1, out x2, out y2)) { parsed_value += x2; } else { parsed_value = glyph.left_limit - parsed_value;