The Birdfont Source Code


All Repositories / birdfont.git / blobdiff – RSS feed

Linear gradients and matrix tranform on gradients

Changes made to libbirdfont/Svg/Object.vala

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
--- libbirdfont/Svg/Object.vala +++ libbirdfont/Svg/Object.vala @@ -22,7 +22,7 @@ public bool visible = true; public SvgStyle style = new SvgStyle (); - public Gee.ArrayList<SvgTransform> transforms = new Gee.ArrayList<SvgTransform> (); + public SvgTransforms transforms = new SvgTransforms (); public virtual Color? color { get; set; } // FIXME: keep this in svg style public virtual Color? stroke_color { get; set; } @@ -94,9 +94,7 @@ if (style.fill_gradient != null) { apply_gradient (cr, (!) style.fill_gradient); - } - - if (style.fill != null) { + } else if (style.fill != null) { fill = (!) style.fill; cr.set_source_rgba (fill.r, fill.g, fill.b, fill.a); } @@ -111,9 +109,7 @@ if (style.stroke_gradient != null) { apply_gradient (cr, (!) style.stroke_gradient); - } - - if (style.stroke != null) { + } else if (style.stroke != null) { stroke = (!) style.stroke; cr.set_source_rgba (stroke.r, stroke.g, stroke.b, stroke.a); } @@ -140,47 +136,19 @@ 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) { - foreach (SvgTransform transform in transforms) { - if (transform.type == TransformType.SCALE) { - if (transform.arguments.size == 1) { - double s = transform.arguments.get_double (0); - cr.scale (s, s); - } else if (transform.arguments.size == 2) { - double s0 = transform.arguments.get_double (0); - double s1 = transform.arguments.get_double (1); - cr.scale (s0, s1); - } - } else if (transform.type == TransformType.TRANSLATE) { - if (transform.arguments.size == 1) { - double s = transform.arguments.get_double (0); - cr.translate (s, 0); - } else if (transform.arguments.size == 2) { - double s0 = transform.arguments.get_double (0); - double s1 = transform.arguments.get_double (1); - cr.translate (s0, s1); - } - } else if (transform.type == TransformType.MATRIX) { - if (transform.arguments.size == 1) { - double s0 = transform.arguments.get_double (0); - double s1 = transform.arguments.get_double (1); - double s2 = transform.arguments.get_double (2); - double s3 = transform.arguments.get_double (3); - double s4 = transform.arguments.get_double (4); - double s5 = transform.arguments.get_double (5); + Matrix matrix = transforms.get_matrix (); + cr.set_matrix (matrix); + } - Matrix matrix = Matrix (s0, s1, s2, s3, s4, s5); - cr.set_matrix (matrix); - } - } - } - } } }