The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix SVG matrix transforms

These changes was commited to the Birdfont repository Sat, 09 Jan 2016 18:37:24 +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 Jan 2016 18:37:24 +0000 (19:37 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sat, 09 Jan 2016 18:37:24 +0000 (19:37 +0100)
commit 2066fc882714960ddb43f9d94ffeb38f162021cb
tree 9be084830bed9858fd0585b592184afde5fedcc7
parent 76c9ad8905cf9d3013d67ecb82b884adf105aa7f
Fix SVG matrix transforms

libbirdfont/Glyph.vala
libbirdfont/Svg/Object.vala
libbirdfont/Svg/Rectangle.vala
libbirdfont/Svg/SvgPath.vala
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -1802,14 +1802,19 @@ color = p.color == null ? Color.black () : (!) p.color; p.draw_path (cr, color); } - } else { - o.draw (cr); } } cr.close_path (); cr.fill (); cr.restore (); + + // FIXME: layer transforms + foreach (Object o in get_visible_objects ()) { + if (!(o is PathObject)) { + o.draw (cr); + } + } foreach (Object o in active_paths) { if (o is PathObject) {
--- a/libbirdfont/Svg/Object.vala +++ b/libbirdfont/Svg/Object.vala @@ -85,11 +85,11 @@ return "Object"; } - public void fill_and_stroke (Context cr) { + public void paint (Context cr) { Color fill, stroke; bool need_fill = style.fill_gradient != null || style.fill != null; bool need_stroke = style.stroke_gradient != null || style.stroke != null; - + cr.set_line_width (style.stroke_width); if (style.fill_gradient != null) { @@ -131,24 +131,29 @@ g.y1, g.x2, g.y2); + + Matrix gradient_matrix = g.get_matrix (); + gradient_matrix.invert (); + pattern.set_matrix (gradient_matrix); foreach (Stop s in g.stops) { Color c = s.color; pattern.add_color_stop_rgba (s.offset, c.r, c.g, c.b, c.a); } - - pattern.set_matrix (g.get_matrix ()); - + cr.set_source (pattern); } } public void apply_transform (Context cr) { - Matrix matrix = transforms.get_matrix (); - cr.set_matrix (matrix); + Matrix view_matrix = cr.get_matrix (); + Matrix object_matrix = transforms.get_matrix (); + + object_matrix.multiply (object_matrix, view_matrix); + cr.set_matrix (object_matrix); } } }
--- a/libbirdfont/Svg/Rectangle.vala +++ b/libbirdfont/Svg/Rectangle.vala @@ -35,7 +35,6 @@ public override void draw (Context cr, Color? c = null) { cr.save (); - apply_transform (cr); if (rx == 0 && ry == 0) { @@ -44,8 +43,7 @@ draw_rounded_corners (cr); } - fill_and_stroke (cr); - + paint (cr); cr.restore (); }
--- a/libbirdfont/Svg/SvgPath.vala +++ b/libbirdfont/Svg/SvgPath.vala @@ -32,7 +32,6 @@ public override void draw (Context cr, Color? c = null) { cr.save (); - apply_transform (cr); cr.new_path (); foreach (Points p in points) { @@ -44,7 +43,8 @@ } } - fill_and_stroke (cr); + apply_transform (cr); + paint (cr); cr.restore (); }