Commit b2e08e8
SVG M instruction
Changed files (5)
modifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/Doubles.valamodifiedlibsvgbird/Points.valamodifiedlibsvgbird/SvgFile.valamodifiedlibsvgbird/SvgPath.vala
Diff
@@ -1148,7 +1148,7 @@ public class SvgParser { Path path = new Path (); PointValue* points = p.point_data.data;- EditPoint next = new EditPoint (p.x, -p.y, PointType.CUBIC);+ EditPoint next = new EditPoint (); EditPointHandle handle; if (p.size == 0) {@@ -1161,8 +1161,6 @@ public class SvgParser { return path_list; } - path.add_point (next);- for (int i = 0; i < p.size; i += 8) { switch (points[i].type) {@@ -1188,11 +1186,6 @@ public class SvgParser { handle.y = -points[i + 4].value; handle.type = PointType.CUBIC; - handle = next.get_right_handle ();- handle.x = p.x;- handle.y = -p.y;- handle.type = PointType.CUBIC;- break; case POINT_LINE: handle = next.get_right_handle ();@@ -35,6 +35,48 @@ public class Doubles : GLib.Object { data = null; } + public void set_double (int index, double p) {+ if (unlikely (index < 0)) {+ warning ("index < 0");+ return;+ }++ if (unlikely (index >= size)) {+ warning ("index >= size");+ return;+ }+ + data[index].value = p;+ }+ + public void insert (int position, double p) {+ if (capacity < size + 1) {+ increase_capacity ();+ }+ + if (unlikely (position < 0 || position > size)) {+ warning (@"Bad poisition $position.");+ return;+ }+ + PointValue* point_data = new PointValue[capacity];+ + if (position > 0) {+ Posix.memcpy (point_data, data, sizeof (PointValue) * position);+ }+ + 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));+ }+ + size += 1;+ delete data;+ data = point_data;+ }+ public void remove_first (int n) { if (size < n) { return;@@ -47,6 +89,7 @@ public class Doubles : GLib.Object { } } + void increase_capacity () { int new_capacity = 2 * capacity; PointValue* new_data = new PointValue[new_capacity];@@ -18,8 +18,6 @@ namespace SvgBird { public class Points : GLib.Object { public Doubles point_data = new Doubles.for_capacity (100);- public double x = 0;- public double y = 0; public bool closed = false; public int size { get {@@ -27,6 +25,14 @@ public class Points : GLib.Object { } } + public void set_double (int index, double p) {+ point_data.set_double (index, p);+ }+ + public void insert (int index, double p) {+ point_data.insert (index, p);+ }+ public void add (double p) { point_data.add (p); }@@ -38,8 +44,6 @@ public class Points : GLib.Object { public Points copy () { Points p = new Points (); p.point_data = point_data.copy ();- p.x = x;- p.y = y; p.closed = closed; return p; }@@ -801,19 +801,14 @@ public class SvgFile : GLib.Object { for (int i = 0; i < points_size; i++) { // FIXME: add more types if (bezier_points[i].type == 'M') {- if (i == 0) {- points.x = bezier_points[i].x0;- points.y = bezier_points[i].y0;- } else {- points.add_type (POINT_LINE);- points.add (bezier_points[i].x0);- points.add (bezier_points[i].y0);- points.add (0);- points.add (0);- points.add (0);- points.add (0);- points.add (0);- }+ points.add_type (POINT_LINE);+ points.add (bezier_points[i].x0);+ points.add (bezier_points[i].y0);+ points.add (0);+ points.add (0);+ points.add (0);+ points.add (0);+ points.add (0); } else if (bezier_points[i].type == 'C') { points.add_type (POINT_CUBIC); points.add (bezier_points[i].x0);@@ -877,11 +872,23 @@ 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.x = p.point_data.get_double (p.point_data.size - 3);- illustrator_points.y = p.point_data.get_double (p.point_data.size - 2);+ illustrator_points.insert (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);+ illustrator_points.insert (4, 0);+ illustrator_points.insert (5, 0);+ illustrator_points.insert (6, 0);+ illustrator_points.insert (7, 0); } else {- illustrator_points.x = p.point_data.get_double (p.point_data.size - 7);- illustrator_points.y = p.point_data.get_double (p.point_data.size - 6);+ illustrator_points.insert (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);+ illustrator_points.insert (4, 0);+ illustrator_points.insert (5, 0);+ illustrator_points.insert (6, 0);+ illustrator_points.insert (7, 0); } int start = 0;@@ -36,7 +36,6 @@ public class SvgPath : Object { public override void draw_outline (Context cr) { foreach (Points p in points) {- cr.move_to (p.x, p.y); draw_points (cr, p); if (p.closed) {