The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

SVG M instruction

These changes was commited to the Birdfont repository Fri, 08 Jul 2016 16:39:44 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Fri, 08 Jul 2016 16:39:44 +0000]

Updated Files

libbirdfont/SvgParser.vala
libsvgbird/Doubles.vala
libsvgbird/Points.vala
libsvgbird/SvgFile.vala
libsvgbird/SvgPath.vala
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -1148,7 +1148,7 @@ 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 @@ return path_list; } - path.add_point (next); - for (int i = 0; i < p.size; i += 8) { switch (points[i].type) { @@ -1188,11 +1186,6 @@ 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 ();
--- a/libsvgbird/Doubles.vala +++ b/libsvgbird/Doubles.vala @@ -33,6 +33,48 @@ ~Doubles () { delete data; 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) { @@ -46,6 +88,7 @@ data[i] = data[i + n]; } } + void increase_capacity () { int new_capacity = 2 * capacity;
--- a/libsvgbird/Points.vala +++ b/libsvgbird/Points.vala @@ -18,13 +18,19 @@ 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 { return point_data.size; } + } + + 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) { @@ -38,8 +44,6 @@ public Points copy () { Points p = new Points (); p.point_data = point_data.copy (); - p.x = x; - p.y = y; p.closed = closed; return p; }
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -801,19 +801,14 @@ 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 @@ 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;
--- a/libsvgbird/SvgPath.vala +++ b/libsvgbird/SvgPath.vala @@ -36,7 +36,6 @@ 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) {