The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Remove old stroke code

These changes was commited to the Birdfont repository Sun, 29 Mar 2015 09:40:17 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 29 Mar 2015 09:40:17 +0000]

Updated Files

libbirdfont/StrokeTool.vala
--- a/libbirdfont/StrokeTool.vala +++ b/libbirdfont/StrokeTool.vala @@ -210,13 +210,13 @@ end = ep.get_next ().copy (); move_segment (start, end, thickness); - - start.get_left_handle ().convert_to_line (); // sharp corner - + stroked.add_point (start); stroked.add_point (end); - end.get_right_handle ().convert_to_line (); // sharp corner + // sharp corner + start.get_left_handle ().convert_to_line (); + end.get_right_handle ().convert_to_line (); } stroked.recalculate_linear_handles (); @@ -252,359 +252,8 @@ stroke_stop.independent_x += qx; stroke_stop.independent_y += qy; - } - - static Path change_stroke_width (Path original, double thickness) { - Path stroked = new Path (); - EditPoint ep; - uint k; - uint npoints; - Path new_path; - - EditPoint np, sp, nprev, sprev; - - int i = 0; - - double la, qx, qy; - - EditPoint split_point = new EditPoint (); - EditPoint start, stop, new_start; - EditPoint stroke_start, stroke_stop; - EditPoint segment_start, segment_stop; - EditPointHandle r, l; - double left_x, left_y; - bool new_point = false; - double m, n; - bool bad_segment = false; - bool failed = false; - int size; - - new_path = original.copy (); - new_path.remove_points_on_points (); - - // Add corner nodes - foreach (EditPoint e in original.points) { - new_path.add_point (e.copy ()); - new_path.add_point (e.copy ()); - } - - new_path.update_region_boundaries (); - - k = 0; - npoints = new_path.points.size; - - if (npoints < 2) { - warning ("npoints < 2"); - return new_path; - } - - left_x = 0; - left_y = 0; - start = new_path.get_first_point (); - int it = 0; - - foreach (EditPoint e in new_path.points) { - e.flags |= EditPoint.CORNER; - } - - // double points are not good for this purpose, convert them to the quadratic form - new_path.add_hidden_double_points (); - - // add tangent points to the path - segment_start = new_path.get_first_point (); - size = new_path.points.size; - - for (int j = 0; j < size; j++) { - segment_stop = segment_start.get_next (); - Path.all_of (segment_start, segment_stop, (x, y, t) => { - if (t == 0 && t != 1) { - return true; - } - - split_point = new EditPoint (x, y); - - split_point.prev = segment_start; - split_point.next = segment_stop; - - segment_start.next = split_point; - segment_stop.prev = split_point; - - new_path.insert_new_point_on_path (split_point, t); - - return false; - }, 2); - - segment_start = segment_stop; - } - new_path.remove_points_on_points (); - - // calculate offset - bad_segment = false; - EditPoint previous_start = new EditPoint (); - for (int points_to_process = new_path.points.size - 1; points_to_process >= 0; points_to_process--) { - - if (++it > 1000) { // FIXME: delete - warning ("Skipping the rest of the path."); - break; - } - - if (is_null (start) || start.next == null) { - warning ("No next point"); - break; - } - - stop = start.get_next (); - - if (stop.type == PointType.NONE) { - break; - } - - // move point - stroke_start = start.copy (); - stroke_stop = stop.copy (); - - stroke_start.set_tie_handle (false); - stroke_stop.set_tie_handle (false); - - start.set_tie_handle (false); - stop.set_tie_handle (false); - - // FIXME: first point? - stroke_start.get_left_handle ().move_to_coordinate_delta (left_x, left_y); - - r = stroke_start.get_right_handle (); - l = stroke_stop.get_left_handle (); - - m = cos (r.angle + PI / 2) * thickness; - n = sin (r.angle + PI / 2) * thickness; - - stroke_start.independent_x += m; - stroke_start.independent_y += n; - - stroke_start.get_right_handle ().move_to_coordinate_delta (m, n); - - la = l.angle; - qx = cos (la - PI / 2) * thickness; - qy = sin (la - PI / 2) * thickness; - - left_x = qx; - left_y = qy; - stroke_stop.get_left_handle ().move_to_coordinate_delta (left_x, left_y); - - stroke_stop.independent_x += qx; - stroke_stop.independent_y += qy; - - // avoid jagged edges - double dar = stroke_start.get_right_handle ().angle - start.get_right_handle ().angle; - double dal = stroke_stop.get_left_handle ().angle - stop.get_left_handle ().angle; - - if (fabs (dal) > 1) { - stroke_stop.get_left_handle ().angle = stop.get_left_handle () .angle; - } - - if (fabs (dar) > 1) { - print ("FIX:"); - stroke_start.get_right_handle ().angle = start.get_right_handle () .angle; - } - - // Create a segment of the stroked path - Gee.ArrayList<EditPoint> on_stroke = new Gee.ArrayList<EditPoint> (); - int n_samples = 0; - Path.all_of (stroke_start, stroke_stop, (x, y, t) => { - if (t == 0 || t == 1) { - return true; - } - - if (n_samples >= 2) { - return false; - } - - on_stroke.add (new EditPoint (x, y)); - n_samples++; - return true; - }, 3); - - if (on_stroke.size != 2) { - warning (@"on_stroke.size: $(on_stroke.size)"); - return stroked; - } - - // compare the outline of the stroke to the original path and - // add new points if offset differs from stroke width - i = 0; - new_point = false; - if (!bad_segment) { - Path.all_of (start, stop, (x, y, t) => { - double d; - EditPoint point_on_stroke; - double stroke_width = fabs (thickness); - - if (t == 0 || t == 1) { - return true; - } - - if (i >= on_stroke.size) { - warning (@"Out of bounds. ($i >= $(on_stroke.size)) t: $t"); - return false; - } - - point_on_stroke = on_stroke.get (i++); - d = fabs (Path.distance (point_on_stroke.x, x, point_on_stroke.y, y) - stroke_width); - split_point = new EditPoint (x, y); - - if (d > 1) { - bad_segment = true; // add more points - return false; - } - - if (d > 0.2) { - split_point.prev = start; - split_point.next = stop; - - start.next = split_point; - stop.prev = split_point; - - if (start.x == split_point.x && start.y == split_point.y) { - warning (@"Point already added. Error: $d"); - bad_segment = true; - failed = true; - return false; - } else { - new_path.insert_new_point_on_path (split_point, t); - new_point = true; - } - } - return !new_point; - }, 3); - } - - if (failed) { - return stroked; - } - - if (!new_point) { - ep = stroke_start.copy (); - stroked.add_point (ep); - previous_start = stroke_start; - new_start = stop.get_next (); - } else { - la = split_point.get_left_handle ().angle; - qx = cos (la - PI / 2) * thickness; - qy = sin (la - PI / 2) * thickness; - left_x = qx; - left_y = qy; - - points_to_process += 2; // process the current point and the new point - new_start = start; - } - - start = new_start; - } - - new_path.remove_deleted_points (); - if (!(stroked.points.size == new_path.points.size && new_path.points.size > 1)) { - warning (@"stroked.points.size == new_path.points.size: $(stroked.points.size) != $(new_path.points.size)"); - return stroked; - } - - // delete end point - if (new_path.points.size > 2 && stroked.points.size > 2) { - stroked.delete_last_point (); - new_path.delete_last_point (); - - l = new_path.get_last_point ().get_left_handle (); - - stroked.get_last_point ().get_left_handle ().angle = l.angle; - stroked.get_last_point ().get_left_handle ().length = l.length; - stroked.get_last_point ().get_left_handle ().type = l.type; - } - - // remove self intersection - - EditPoint snext, nnext; - double back_ratio = 0; - double next_ratio = 0; - - snext = new EditPoint (); - nnext = new EditPoint (); - - stroked.remove_deleted_points (); - new_path.remove_deleted_points (); - - return_val_if_fail (stroked.points.size == new_path.points.size, stroked); - - // adjust angle and length of control point handles - double last_ratio = 0; // FIXME: FIRST POINT - - double last_prev_ratio = 0; - - double ratio = 0; - - nprev = new_path.points.get (new_path.points.size - 1); - sprev = stroked.points.get (stroked.points.size - 1); - for (int index = 0; index < stroked.points.size; index++) { - np = new_path.points.get (index); - sp = stroked.points.get (index); - - if (index < stroked.points.size - 1) { - nnext = new_path.points.get (index + 1); - snext = stroked.points.get (index + 1); - } - - if (np.type == PointType.NONE || nnext.type == PointType.NONE) { - break; - } - - // angle - double dar = sp.get_right_handle ().angle - np.get_right_handle ().angle; - double dal = sp.get_left_handle ().angle - np.get_left_handle ().angle; - - if (fabs (dal) > 1) { // FIXME 0.1? PI? - sp.get_left_handle ().angle = np.get_left_handle () .angle; - } - - if (fabs (dar) > 1) { - print (@"FIX: $(sp) $(np)"); - sp.get_right_handle ().angle = np.get_right_handle () .angle; - } - - sp.get_left_handle ().angle = np.get_left_handle () .angle; - sp.get_right_handle ().angle = np.get_right_handle () .angle; - - // length - next_ratio = Path.distance (snext.x, sp.x, snext.y, sp.y); - next_ratio /= Path.distance (nnext.x, np.x, nnext.y, np.y); - - back_ratio = Path.distance (sprev.x, sp.x, sprev.y, sp.y); - back_ratio /= Path.distance (nprev.x, np.x, nprev.y, np.y); - - if (!(0.0002 < next_ratio < fabs (thickness) - && 0.0002 < back_ratio < fabs (thickness))) { - ratio = last_ratio; - sp.get_right_handle ().length = Path.distance (snext.x, sp.x, snext.y, sp.y); // HANDLE TYPE - - ratio = last_ratio; - sp.get_left_handle ().length = Path.distance (snext.x, sp.x, snext.y, sp.y); - } else { - ratio = next_ratio; - sp.get_right_handle ().length *= ratio; - - ratio = back_ratio; - sp.get_left_handle ().length *= ratio; - - last_ratio = next_ratio; - last_prev_ratio = back_ratio; - } - - nprev = np; - sprev = sp; - } - - stroked.set_stroke (0); - - return stroked; } } }