The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Don't interpolate hidden points in stroke

These changes was commited to the Birdfont repository Wed, 15 Apr 2015 13:08:14 +0000.

Contributing

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

Updated Files

libbirdfont/KerningClasses.vala
libbirdfont/Path.vala
libbirdfont/StrokeTool.vala
libbirdfont/SvgParser.vala
libbirdfont/TabBar.vala
resources/icons.bf
--- a/libbirdfont/KerningClasses.vala +++ b/libbirdfont/KerningClasses.vala @@ -533,8 +533,6 @@ foreach (UniRange u in r.ranges) { for (unichar c = u.start; c <= u.stop; c++) { right = (!)c.to_string (); - - print (@"has? $(character.get_name ()) $right $( has_kerning (character.get_name (), right))\n"); if (font.has_glyph (right) && has_kerning (character.get_name (), right)) { kerning = get_kerning (character.get_name (), right); @@ -554,7 +552,6 @@ // TODO: The get_kerning () function is still slow. Optimize it. foreach (string right_glyph_name in single_kerning_letters_right) { Glyph? gl = font.get_glyph (right_glyph_name); - print (@"has? $(character.get_name ()) $right_glyph_name $( has_kerning (character.get_name (), right_glyph_name))\n"); if (gl != null && has_kerning (character.get_name (), right_glyph_name)) { kerning = get_kerning (character.get_name (), right_glyph_name); kl.add_unique ((!) gl , kerning);
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -1453,8 +1453,8 @@ } public static void get_point_for_step (EditPoint start, EditPoint stop, double step, out double x, out double y) { - PointType right = start.type; - PointType left = stop.type; + PointType right = PenTool.to_curve (start.type); + PointType left = PenTool.to_curve (stop.type); if (right == PointType.DOUBLE_CURVE || left == PointType.DOUBLE_CURVE) { x = double_bezier_path (step, start.x, start.get_right_handle ().x, stop.get_left_handle ().x, stop.x); @@ -1466,7 +1466,7 @@ x = bezier_path (step, start.x, start.get_right_handle ().x, stop.get_left_handle ().x, stop.x); y = bezier_path (step, start.y, start.get_right_handle ().y, stop.get_left_handle ().y, stop.y); } else { - warning (@"Mixed point types"); + warning (@"Mixed point types in segment $(start.x),$(start.y) to $(stop.x),$(stop.y) right: $(right), left: $(left) (start: $(start.type), stop: $(stop.type))"); x = bezier_path (step, start.x, start.get_right_handle ().x, stop.get_left_handle ().x, stop.x); y = bezier_path (step, start.y, start.get_right_handle ().y, stop.get_left_handle ().y, stop.y); }
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -985,66 +985,33 @@ out double ix, out double iy, bool skip_points_on_points = false) { double cross_x, cross_y; - Path lines1, lines2; - EditPoint a1, a2, b1, b2; ix = 0; iy = 0; + + Path.find_intersection_point (ep, next, p1, p2, out cross_x, out cross_y); - lines1 = new Path (); - lines2 = new Path (); - SvgParser.create_lines_for_segment (lines1, p1, p2); - SvgParser.create_lines_for_segment (lines2, ep, next); + if (Glyph.CANVAS_MIN < cross_x < Glyph.CANVAS_MAX + && Glyph.CANVAS_MIN < cross_y < Glyph.CANVAS_MAX) { + // iterate to find intersection. - lines1.xmax = fmax (p1.max_x (), p2.max_x ()); - lines1.xmin = fmax (p1.min_x (), p2.min_x ()); - lines1.ymax = fmax (p1.max_y (), p2.max_y ()); - lines1.ymin = fmax (p1.min_y (), p2.min_y ()); - - lines2.xmax = fmax (ep.max_x (), next.max_x ()); - lines2.xmin = fmax (ep.min_x (), next.min_x ()); - lines2.ymax = fmax (ep.max_y (), next.max_y ()); - lines2.ymin = fmax (ep.min_y (), next.min_y ()); - - if (!lines1.boundaries_intersecting (lines2)) { - return false; - } - - // FIXME: two intersection on the same segment - - for (int i = 0; i < lines1.points.size - 1; i++) { - a1 = lines1.points.get (i); - a2 = lines1.points.get (i + 1); - - for (int j = 0; j < lines2.points.size - 1; j++) { - b1 = lines2.points.get (j); - b2 = lines2.points.get (j + 1); + if (skip_points_on_points || + !((ep.x == cross_x && ep.y == cross_y) + || (next.x == cross_x && next.y == cross_y) + || (p1.x == cross_x && p1.y == cross_y) + || (p2.x == cross_x && p2.y == cross_y))) { + + if (is_line (ep.x, ep.y, cross_x, cross_y, next.x, next.y) + && is_line (p1.x, p1.y, cross_x, cross_y, p2.x, p2.y)) { - Path.find_intersection_point (a1, a2, b1, b2, out cross_x, out cross_y); - - if (Glyph.CANVAS_MIN < cross_x < Glyph.CANVAS_MAX - && Glyph.CANVAS_MIN < cross_y < Glyph.CANVAS_MAX) { - // iterate to find intersection. - - if (skip_points_on_points || - !((ep.x == cross_x && ep.y == cross_y) - || (next.x == cross_x && next.y == cross_y) - || (p1.x == cross_x && p1.y == cross_y) - || (p2.x == cross_x && p2.y == cross_y))) { - - if (is_line (ep.x, ep.y, cross_x, cross_y, next.x, next.y) - && is_line (p1.x, p1.y, cross_x, cross_y, p2.x, p2.y)) { - - ix = cross_x; - iy = cross_y; - - return true; - } - } + ix = cross_x; + iy = cross_y; + + return true; } - } + } } - + return false; } @@ -1948,6 +1915,17 @@ Path.get_point_for_step (start, end, step, out px, out py); + if (start.type == PointType.HIDDEN) { + start.tie_handles = false; + start.deleted = true; + } + + if (end.type == PointType.HIDDEN) { + start.tie_handles = false; + end.tie_handles = false; + end.deleted = true; + } + if (unlikely (added_points > 4)) { warning ("More than four points added in stroke."); added_points = 0; @@ -1960,12 +1938,14 @@ new_point.next = end; path.insert_new_point_on_path (new_point, step); added_points++; + size++; } else { added_points = 0; i++; } } + path.remove_deleted_points (); path.remove_points_on_points (); if (stroke_selected) {// FIXME: DELETE
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -468,7 +468,7 @@ } } - public static void create_lines_for_segment (Path path, EditPoint start, EditPoint end) { + public static void create_lines_for_segment (Path path, EditPoint start, EditPoint end, double tolerance) { double x1, x2, x3; double y1, y2, y3; double step_start, step, step_end; @@ -484,7 +484,7 @@ Path.get_point_for_step (start, end, step, out x2, out y2); Path.get_point_for_step (start, end, step_end, out x3, out y3); - if (!StrokeTool.is_flat (x1, y1, x2, y2, x3, y3, 1) + if (!StrokeTool.is_flat (x1, y1, x2, y2, x3, y3, tolerance) && step_end - step / 2.0 > step_start && step_end - step / 2.0 > 0.1 && step > 0.05 @@ -523,7 +523,7 @@ start = p.points.get (p.points.size - 1); foreach (EditPoint end in p.points) { - create_lines_for_segment (path, start, end); + create_lines_for_segment (path, start, end, 1); start = end; }
--- a/libbirdfont/TabBar.vala +++ b/libbirdfont/TabBar.vala @@ -683,7 +683,7 @@ menu_icon.set_font_size (40 / scale); menu_icon.widget_x = (int) (w - 25 / scale); - menu_icon.widget_y = (int) (2 / scale); + menu_icon.widget_y = (int) (h / 2.0 - 20 / scale); menu_icon.draw (cr); }
--- a/resources/icons.bf +++ b/resources/icons.bf @@ -280,10 +280,10 @@ </collection> <collection name="dropdown_menu"> <selected id="1"/> - <glyph id="1" left="-4" right="43.08994708994711"> - <path stroke="0" skew="0" data="S -4.0000000000,12.2098765432 L 69.2592592593,12.2098765432 L 69.2592592593,0.0000000000 L -4.0000000000,0.0000000000 L -4.0000000000,12.2098765432" /> - <path stroke="0" skew="0" data="S -4.0000000000,24.4197530865 L -4.0000000000,36.6296296296 L 69.2592592593,36.6296296296 L 69.2592592593,24.4197530865 L -4.0000000000,24.4197530865" /> - <path stroke="0" skew="0" data="S -4.0000000000,61.0493827161 L 69.2592592593,61.0493827161 L 69.2592592593,48.8395061728 L -4.0000000000,48.8395061728 L -4.0000000000,61.0493827161" /> + <glyph id="1" left="-4" right="69.259259259299995"> + <path stroke="0" skew="0" data="S -4.0000000000,8.0633248190 L 69.2592592593,8.0633248190 L 69.2592592593,-3.4022988506 L -4.0000000000,-3.4022988506 L -4.0000000000,8.0633248190" /> + <path stroke="0" skew="0" data="S -4.0000000000,21.0174542359 L -4.0000000000,32.4830779054 L 69.2592592593,32.4830779054 L 69.2592592593,21.0174542359 L -4.0000000000,21.0174542359" /> + <path stroke="0" skew="0" data="S -4.0000000000,57.3281183483 L 69.2592592593,57.3281183483 L 69.2592592593,45.1182418050 L -4.0000000000,45.1182418050 L -4.0000000000,57.3281183483" /> </glyph> </collection> <collection unicode="U+65"> @@ -467,10 +467,10 @@ </collection> <collection name="menu_icon"> <selected id="1"/> - <glyph id="1" left="-28" right="28"> - <path stroke="0" skew="0" data="S -20.0000000000,54.0582524272 L 24.0000000000,54.0582524272 L 24.0000000000,50.0582524272 L -20.0000000000,50.0582524272 L -20.0000000000,54.0582524272" /> - <path stroke="0" skew="0" data="S -20.0000000000,42.0582524272 L 24.0000000000,42.0582524272 L 24.0000000000,38.0582524272 L -20.0000000000,38.0582524272 L -20.0000000000,42.0582524272" /> - <path stroke="0" skew="0" data="S -20.0000000000,30.0582524272 L 24.0000000000,30.0582524272 L 24.0000000000,26.0582524272 L -20.0000000000,26.0582524272 L -20.0000000000,30.0582524272" /> + <glyph id="1" left="-20.425287356321846" right="23.574712643678154"> + <path stroke="0" skew="0" data="S -20.4252873563,40.8743443812 L 23.5747126437,40.8743443812 L 23.5747126437,36.8743443812 L -20.4252873563,36.8743443812 L -20.4252873563,40.8743443812" /> + <path stroke="0" skew="0" data="S -20.4252873563,29.1933098985 L 23.5747126437,29.1933098985 L 23.5747126437,25.1933098985 L -20.4252873563,25.1933098985 L -20.4252873563,29.1933098985" /> + <path stroke="0" skew="0" data="S -20.4252873563,17.4059535766 L 23.5747126437,17.4059535766 L 23.5747126437,13.4059535766 L -20.4252873563,13.4059535766 L -20.4252873563,17.4059535766" /> </glyph> </collection> <collection name="move">