The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix path start point

These changes was commited to the Birdfont repository Sat, 09 Jul 2016 22:58:04 +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>
Sat, 09 Jul 2016 22:58:04 +0000 (00:58 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 09 Jul 2016 22:58:04 +0000 (00:58 +0200)
commit 6650e23a21caebdacaa48c4bdf411e112115ffee
tree d00a47f180966912e0d3f56c2a07ff2dd5e1ea3e
parent 1d1bd5db06278f185460dffaf25204b5e41b75c6
Fix path start point

libbirdfont/SvgParser.vala
libsvgbird/Doubles.vala
libsvgbird/Points.vala
libsvgbird/SvgFile.vala
libsvgbird/SvgPath.vala
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -1165,6 +1165,7 @@ switch (points[i].type) { case POINT_ARC: + // FIXME: /* draw_arc (cr, , points[i + 2].value, points[i + 3].value, points[i + 4].value,
--- a/libsvgbird/Doubles.vala +++ b/libsvgbird/Doubles.vala @@ -63,27 +63,35 @@ 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;
--- a/libsvgbird/Points.vala +++ b/libsvgbird/Points.vala @@ -32,6 +32,10 @@ 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) {
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -800,15 +800,18 @@ 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 @@ 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 @@ 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 @@ 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);
--- a/libsvgbird/SvgPath.vala +++ b/libsvgbird/SvgPath.vala @@ -36,11 +36,35 @@ public override void draw_outline (Context cr) { foreach (Points p in points) { + move_to_start (cr, p); draw_points (cr, p); if (p.closed) { cr.close_path (); } + } + } + + 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; } } @@ -48,7 +72,6 @@ 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) {