The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

LinearGradient.vala in /libsvgbird

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
Circle boundaries heads/master
1 /* 2 Copyright (C) 2015 2016 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Cairo; 16 using Math; 17 18 namespace SvgBird { 19 20 public class LinearGradient : Gradient { 21 public double x1; 22 public double y1; 23 public double x2; 24 public double y2; 25 26 public LinearGradient () { 27 base (); 28 x1 = 0; 29 y1 = 0; 30 x2 = 0; 31 y2 = 0; 32 } 33 34 public override Gradient copy () { 35 LinearGradient g = new LinearGradient (); 36 37 g.x1 = x1; 38 g.y1 = y1; 39 g.x2 = x2; 40 g.y2 = y2; 41 42 foreach (Stop s in stops) { 43 g.stops.add (s.copy ()); 44 } 45 46 copy_gradient (this, g); 47 48 return g; 49 } 50 51 public override string to_string () { 52 StringBuilder description = new StringBuilder (); 53 description.append (@"Gradient $(id): "); 54 description.append (@"x1=$x1, y1=$y1, x2=$x2, y2=$y2"); 55 56 foreach (Stop stop in stops) { 57 description.append (" "); 58 description.append (stop.to_string ()); 59 } 60 61 return description.str; 62 } 63 64 public override void move (double dx, double dy) { 65 double x = dx; 66 double y = dy; 67 68 Matrix parent = parent_matrix; 69 parent.invert (); 70 parent.transform_distance (ref x, ref y); 71 72 Matrix m = Matrix.identity (); 73 m.translate (-x, -y); 74 75 transforms.transforms.insert (0, new SvgTransform.for_matrix (m)); 76 transforms.collapse_transforms (); 77 } 78 } 79 80 } 81