Commit 2066fc8
Fix SVG matrix transforms
Changed files (4)
modifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/Svg/Object.valamodifiedlibbirdfont/Svg/Rectangle.valamodifiedlibbirdfont/Svg/SvgPath.vala
Diff
@@ -1802,8 +1802,6 @@ public class Glyph : FontDisplay { color = p.color == null ? Color.black () : (!) p.color; p.draw_path (cr, color); }- } else {- o.draw (cr); } } @@ -1811,6 +1809,13 @@ public class Glyph : FontDisplay { 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) { Path p = ((PathObject) o).get_path ();@@ -85,11 +85,11 @@ public abstract class Object : GLib.Object { 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,21 +131,26 @@ public abstract class Object : GLib.Object { 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); } }@@ -35,7 +35,6 @@ public class Rectangle : Object { public override void draw (Context cr, Color? c = null) { cr.save ();- apply_transform (cr); if (rx == 0 && ry == 0) {@@ -44,8 +43,7 @@ public class Rectangle : Object { draw_rounded_corners (cr); } - fill_and_stroke (cr);-+ paint (cr); cr.restore (); } @@ -32,7 +32,6 @@ public class SvgPath : Object { 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 @@ public class SvgPath : Object { } } - fill_and_stroke (cr);+ apply_transform (cr); + paint (cr); cr.restore (); }