Commit 6650e23
Fix path start point
Changed files (5)
modifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/Doubles.valamodifiedlibsvgbird/Points.valamodifiedlibsvgbird/SvgFile.valamodifiedlibsvgbird/SvgPath.vala
Diff
@@ -1165,6 +1165,7 @@ public class SvgParser { switch (points[i].type) { case POINT_ARC:+ // FIXME: /* draw_arc (cr, , points[i + 2].value, points[i + 3].value, points[i + 4].value,@@ -63,27 +63,35 @@ public class Doubles : GLib.Object { data[index].type = t; } - public void insert (int position, double p) {+ public void insert (int index, double p) {+ insert_element (index);+ data[index].value = p;+ }+ + public void insert_type (int index, uchar p) {+ insert_element (index); + data[index].type = p;+ }+ + public void insert_element (int index) { if (capacity < size + 1) { increase_capacity (); } - if (unlikely (position < 0 || position > size)) {- warning (@"Bad poisition $position.");+ if (unlikely (index < 0 || index > size)) {+ warning (@"Bad index $index."); return; } PointValue* point_data = new PointValue[capacity]; - if (position > 0) {- Posix.memcpy (point_data, data, sizeof (PointValue) * position);+ if (index > 0) {+ Posix.memcpy (point_data, data, sizeof (PointValue) * index); } - point_data[position].value = p;- - if (position < size) {- int dest_position = position + 1; - Posix.memcpy (point_data + dest_position, data + position, sizeof (PointValue) * (size - position));+ if (index < size) {+ int dest_position = index + 1; + Posix.memcpy (point_data + dest_position, data + index, sizeof (PointValue) * (size - index)); } size += 1;@@ -33,6 +33,10 @@ public class Points : GLib.Object { public void set_double (int index, double p) { point_data.set_double (index, p); }++ public void insert_type (int index, uchar t) {+ point_data.insert_type (index, t);+ } public void insert (int index, double p) { point_data.insert (index, p);@@ -800,15 +800,18 @@ public class SvgFile : GLib.Object { double first_x = 0; double first_y = 0;++ if (points_size > 0) {+ first_x = bezier_points[0].x0;+ first_y = bezier_points[0].y0;+ }+ for (int i = 0; i < points_size; i++) { // FIXME: add more types if (bezier_points[i].type == 'M') {- first_x = bezier_points[i].x0;- first_y = bezier_points[i].y0;- points.add_type (POINT_LINE);- points.add (first_x);- points.add (first_y);+ points.add (bezier_points[i].x0);+ points.add (bezier_points[i].y0); points.add (0); points.add (0); points.add (0);@@ -867,6 +870,11 @@ public class SvgFile : GLib.Object { path_data.add (points); points = new Points ();+ + if (i + 1 < points_size) {+ first_x = bezier_points[i + 1].x0;+ first_y = bezier_points[i + 1].y0;+ } } else { string type = (!) bezier_points[i].type.to_string (); warning (@"SVG conversion not implemented for $type");@@ -887,7 +895,7 @@ public class SvgFile : GLib.Object { Points illustrator_points = new Points (); if (p.point_data.get_point_type (p.point_data.size - 8) == POINT_CUBIC) {- illustrator_points.insert (0, POINT_LINE);+ illustrator_points.insert_type (0, POINT_LINE); illustrator_points.insert (1, p.point_data.get_double (p.point_data.size - 3)); illustrator_points.insert (2, p.point_data.get_double (p.point_data.size - 2)); illustrator_points.insert (3, 0);@@ -896,7 +904,7 @@ public class SvgFile : GLib.Object { illustrator_points.insert (6, 0); illustrator_points.insert (7, 0); } else {- illustrator_points.insert (0, POINT_LINE);+ illustrator_points.insert_type (0, POINT_LINE); illustrator_points.insert (1, p.point_data.get_double (p.point_data.size - 7)); illustrator_points.insert (2, p.point_data.get_double (p.point_data.size - 6)); illustrator_points.insert (3, 0);@@ -36,6 +36,7 @@ public class SvgPath : Object { public override void draw_outline (Context cr) { foreach (Points p in points) {+ move_to_start (cr, p); draw_points (cr, p); if (p.closed) {@@ -44,11 +45,33 @@ public class SvgPath : Object { } } + public void move_to_start (Context cr, Points path) {+ int size = path.point_data.size;+ + // points are padded up to 8 units+ return_if_fail (size % 8 == 0);+ return_if_fail (size >= 8);+ + switch (path.get_point_type (0)) {+ case POINT_ARC: + cr.move_to (path.get_double (6), path.get_double (7));+ break;+ case POINT_CUBIC:+ cr.move_to (path.get_double (5), path.get_double (6));+ break;+ case POINT_LINE:+ cr.move_to (path.get_double (1), path.get_double (2));+ break;+ default:+ warning (@"Unknown type $(path.get_point_type (0))");+ break;+ }+ }+ public void draw_points (Context cr, Points path) { PointValue* points = path.point_data.data; int size = path.point_data.size; - // points are padded up to 8 units return_if_fail (size % 8 == 0); for (int i = 0; i < size; i += 8) {