The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Remove old SVG parser code

These changes was commited to the Birdfont repository Wed, 06 Jul 2016 21:33:32 +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>
Wed, 06 Jul 2016 21:33:32 +0000 (23:33 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 06 Jul 2016 21:39:14 +0000 (23:39 +0200)
commit 968e3adce72437b8a1271877abfbec2fe346d4d8
tree c539152bdf5a4037197b6b1cfaa1cb29447dceda
parent ebdb5a59faa23f13ab176de0e120aae5f250aae0
Remove old SVG parser code

libbirdfont/SvgParser.vala
libsvgbird/SvgFile.vala
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -1138,15 +1138,6 @@ } move_and_resize (bezier_points, points, svg_glyph, units, glyph); - - /* - if (format == SvgFormat.ILLUSTRATOR) { - path_list = create_paths_illustrator (bezier_points, points); - } else { - - } - */ - path_list = create_svg_paths (d, format); // TODO: Find out if it is possible to tie handles. @@ -1238,6 +1229,8 @@ } path.recalculate_linear_handles (); + + path.remove_points_on_points (); path_list.add (path); } @@ -1343,308 +1336,6 @@ warning ("Last point not found."); } - PathList create_paths_inkscape (BezierPoints[] b, int num_b) { - double last_x; - double last_y; - PointType last_type; - Path path; - PathList path_list = new PathList (); - EditPoint ep = new EditPoint (); - Gee.ArrayList<EditPoint> smooth_points = new Gee.ArrayList<EditPoint> (); - - path = new Path (); - - if (num_b == 0) { - warning ("No SVG data"); - return path_list; - } - - if (b[0].type != 'M') { - warning ("Path must begin with M or m."); - return path_list; - } - - find_last_handle (0, b, num_b, out last_x, out last_y, out last_type); - - for (int i = 0; i < num_b; i++) { - if (b[i].type == '\0') { - warning ("Parser error."); - return path_list; - } - - if (b[i].type == 'z') { - path.close (); - path.create_list (); - path.recalculate_linear_handles (); - path_list.add (path); - path = new Path (); - - if (i + 1 >= num_b) { - break; - } else { - find_last_handle (i + 1, b, num_b, out last_x, out last_y, out last_type); - } - } - - if (i >= num_b) { - break; - } - - if (b[i].type == 'M') { - ep = path.add (b[i].x0, b[i].y0); - ep.set_point_type (PointType.CUBIC); - - ep.get_left_handle ().set_point_type (PointType.LINE_CUBIC); - - if (i == 0 || (b[i - 1].type == 'z')) { - ep.get_left_handle ().set_point_type (last_type); - ep.get_left_handle ().move_to_coordinate (last_x, last_y); - } else { - if (b[i - 1].type == 'C' || b[i - 1].type == 'S') { - ep.get_left_handle ().set_point_type (PointType.CUBIC); - ep.get_left_handle ().move_to_coordinate (b[i + 1].x1, b[i + 1].y1); - } - - if (b[i + 1].type == 'C' || b[i - 1].type == 'S') { - ep.get_right_handle ().set_point_type (PointType.CUBIC); - ep.get_right_handle ().move_to_coordinate (b[i + 1].x0, b[i + 1].y0); - } else if (b[i + 1].type == 'L' || b[i + 1].type == 'M') { - ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC); - } - } - } - - if (b[i].type == 'L') { - return_val_if_fail (i != 0, path_list); - - ep = path.add (b[i].x0, b[i].y0); - ep.set_point_type (PointType.CUBIC); - ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC); - ep.get_left_handle ().set_point_type (PointType.LINE_CUBIC); - - if (b[i + 1].type == 'L' || b[i + 1].type == 'M' || b[i + 1].type == 'z') { - ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC); - } - - if (b[i -1].type == 'L' || b[i - 1].type == 'M') { - ep.get_left_handle ().set_point_type (PointType.LINE_CUBIC); - } - } - - if (b[i].type == 'Q') { - return_val_if_fail (i != 0, path_list); - - ep.set_point_type (PointType.QUADRATIC); - - ep.get_right_handle ().set_point_type (PointType.QUADRATIC); - ep.get_right_handle ().move_to_coordinate (b[i].x0, b[i].y0); - - if (b[i + 1].type != 'z') { - ep = path.add (b[i].x1, b[i].y1); - - ep.get_left_handle ().set_point_type (PointType.QUADRATIC); - ep.get_left_handle ().move_to_coordinate (b[i].x0, b[i].y0); - } - } - - if (b[i].type == 'C' || b[i].type == 'S') { - return_val_if_fail (i != 0, path_list); - - ep.set_point_type (PointType.CUBIC); - - ep.get_right_handle ().set_point_type (PointType.CUBIC); - ep.get_right_handle ().move_to_coordinate (b[i].x0, b[i].y0); - - if (b[i].type == 'S') { - smooth_points.add (ep); - } - - if (b[i + 1].type != 'z') { - ep = path.add (b[i].x2, b[i].y2); - - ep.get_left_handle ().set_point_type (PointType.CUBIC); - ep.get_left_handle ().move_to_coordinate (b[i].x1, b[i].y1); - } - } - } - - foreach (EditPoint e in smooth_points) { - e.set_point_type (PointType.LINE_DOUBLE_CURVE); - e.get_right_handle ().set_point_type (PointType.LINE_DOUBLE_CURVE); - e.get_left_handle ().set_point_type (PointType.LINE_DOUBLE_CURVE); - } - - foreach (EditPoint e in smooth_points) { - path.recalculate_linear_handles_for_point (e); - } - - for (int i = 0; i < 3; i++) { - foreach (EditPoint e in smooth_points) { - e.set_tie_handle (true); - e.process_tied_handle (); - } - } - - if (path.points.size > 0) { - path_list.add (path); - } - - foreach (Path p in path_list.paths) { - p.remove_points_on_points (); - } - - return path_list; - } - - PathList create_paths_illustrator (BezierPoints[] b, int num_b) { - Path path; - PathList path_list = new PathList (); - EditPoint ep; - bool first_point = true; - double first_left_x, first_left_y; - Gee.ArrayList<EditPoint> smooth_points = new Gee.ArrayList<EditPoint> (); - - if (num_b > b.length) { - warning ("num_b > b.length: $num_b > $(b.length)"); - return path_list; - } - - path = new Path (); - - if (num_b <= 1) { - warning ("No SVG data"); - return path_list; - } - - first_left_x = 0; - first_left_y = 0; - - ep = new EditPoint (); - - for (int i = 0; i < num_b; i++) { - if (b[i].type == '\0') { - warning ("Parser error."); - return path_list; - } else if (b[i].type == 'z') { - path.close (); - path.create_list (); - - int first_index = 1; - - for (int j = i - 1; j >= 1; j--) { - if (b[j].type == 'z') { - first_index = j + 1; // from z to M - } - } - - if (b[first_index].type == 'C' || b[first_index].type == 'S') { - return_val_if_fail (path.points.size != 0, path_list); - ep = path.points.get (path.points.size - 1); - - if (b[i - 1].type != 'L' ) { - ep.get_right_handle ().set_point_type (PointType.CUBIC); - ep.get_right_handle ().move_to_coordinate (b[first_index].x0, b[first_index].y0); - } - } else if (b[first_index].type == 'L') { - return_val_if_fail (path.points.size != 0, path_list); - ep = path.points.get (path.points.size - 1); - ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC); - path.recalculate_linear_handles_for_point (ep); - } else { - warning ("Unexpected type: %s", (!) b[first_index].type.to_string ()); - } - - path.recalculate_linear_handles (); - path_list.add (path); - - path = new Path (); - first_point = true; - } else if (b[i].type == 'L' || b[i].type == 'M') { - - if (first_point) { - first_left_x = b[i].x0; - first_left_y = b[i].y0; - } - - ep = path.add (b[i].x0, b[i].y0); - ep.set_point_type (PointType.CUBIC); // TODO: quadratic - ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC); - - ep.get_left_handle ().set_point_type (PointType.CUBIC); - ep.get_left_handle ().move_to_coordinate (b[i].x0 - 0.00001, b[i].y0 - 0.00001); - - if (b[i + 1].type == 'C' || b[i + 1].type == 'S') { - return_val_if_fail (i + 1 < num_b, path_list); - ep.get_right_handle ().set_point_type (PointType.CUBIC); - ep.get_right_handle ().move_to_coordinate (b[i + 1].x0, b[i + 1].y0); - } - - first_point = false; - } else if (b[i].type == 'Q') { - warning ("Illustrator does not support quadratic control points."); - warning (@"$(b[i])\n"); - } else if (b[i].type == 'C' || b[i].type == 'S') { - - if (first_point) { - first_left_x = b[i].x0; - first_left_y = b[i].y0; - } - - ep = path.add (b[i].x2, b[i].y2); - ep.set_point_type (PointType.CUBIC); - - ep.get_right_handle ().set_point_type (PointType.CUBIC); - ep.get_left_handle ().set_point_type (PointType.CUBIC); - - ep.get_left_handle ().move_to_coordinate (b[i].x1, b[i].y1); - - if (b[i].type == 'S') { - smooth_points.add (ep); - } - - if (b[i + 1].type != 'z' && i != num_b - 1) { - ep.get_right_handle ().move_to_coordinate (b[i + 1].x0, b[i + 1].y0); - } else { - ep.get_right_handle ().move_to_coordinate (first_left_x, first_left_y); - } - - first_point = false; - } else { - warning ("Unknown control point type."); - warning (@"$(b[i])\n"); - } - } - - foreach (EditPoint e in smooth_points) { - e.set_point_type (PointType.LINE_CUBIC); - e.get_right_handle ().set_point_type (PointType.LINE_CUBIC); - e.get_left_handle ().set_point_type (PointType.LINE_CUBIC); - } - - foreach (EditPoint e in smooth_points) { - path.recalculate_linear_handles_for_point (e); - } - - for (int i = 0; i < 3; i++) { - foreach (EditPoint e in smooth_points) { - e.set_tie_handle (true); - e.get_right_handle ().set_point_type (PointType.CUBIC); - e.get_left_handle ().set_point_type (PointType.CUBIC); - e.process_tied_handle (); - } - } - - if (path.points.size > 0) { - path_list.add (path); - } - - foreach (Path p in path_list.paths) { - p.remove_points_on_points (); - } - - return path_list; - } - public static double parse_double (string? s) { if (unlikely (is_null (s))) { warning ("Got null instead of expected string.");
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -877,7 +877,7 @@ foreach (Points p in path_data) { return_val_if_fail (p.point_data.size % 8 == 0, path_data); - if (p.point_data.size > 16) { + if (p.point_data.size > 8) { Points illustrator_points = new Points (); illustrator_points.x = p.point_data.get_double (p.point_data.size - 3); @@ -894,34 +894,7 @@ } } - return illustrator_path_data; - - /* - foreach (Points p in path_data) { - //p.point_data.remove_first (8); - p.point_data.size -= 8; - p.point_data.get_double (0) - p.point_data.get_double (1) - } - */ - - - - /*EditPoint first = path.delete_first_point (); - EditPoint last = path.get_last_point (); - handle = last.get_right_handle (); - - last.get_right_handle ().independent_x = first.get_left_handle ().x; - last.get_right_handle ().independent_y = first.get_left_handle ().y; - - if (points[0].type == POINT_CUBIC && !handle.is_line ()) { - handle.set_point_type (PointType.CUBIC); - handle.move_to_coordinate (points[0].value, points[1].value); - } else { - handle.set_point_type (PointType.LINE_CUBIC); - path.recalculate_linear_handles_for_point (last); - } - */ + path_data = illustrator_path_data; } return path_data;