The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

SvgTransform.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

Revisions

View the latest version of libsvgbird/SvgTransform.vala.
Move the SVG parser and the SVG rendering code to libsvgbird
1 /* 2 Copyright (C) 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 B; 16 using Cairo; 17 18 namespace SvgBird { 19 20 public enum TransformType { 21 NONE, 22 TRANSLATE, 23 MATRIX, 24 SCALE 25 } 26 27 public class SvgTransform : GLib.Object { 28 public TransformType type = TransformType.NONE; 29 public Doubles arguments = new Doubles.for_capacity (10); 30 31 public SvgTransform () { 32 } 33 34 public Matrix get_matrix () { 35 Matrix matrix; 36 37 matrix = Matrix.identity (); 38 39 if (type == TransformType.SCALE) { 40 if (arguments.size == 1) { 41 double s = arguments.get_double (0); 42 matrix.scale (s, s); 43 return matrix; 44 } else if (arguments.size == 2) { 45 double s0 = arguments.get_double (0); 46 double s1 = arguments.get_double (1); 47 matrix.scale (s0, s1); 48 } 49 } else if (type == TransformType.TRANSLATE) { 50 if (arguments.size == 1) { 51 double s = arguments.get_double (0); 52 matrix.translate (s, 0); 53 } else if (arguments.size == 2) { 54 double s0 = arguments.get_double (0); 55 double s1 = arguments.get_double (1); 56 matrix.translate (s0, s1); 57 } 58 } else if (type == TransformType.MATRIX) { 59 if (arguments.size == 6) { 60 double s0 = arguments.get_double (0); 61 double s1 = arguments.get_double (1); 62 double s2 = arguments.get_double (2); 63 double s3 = arguments.get_double (3); 64 double s4 = arguments.get_double (4); 65 double s5 = arguments.get_double (5); 66 67 matrix = Matrix (s0, s1, s2, s3, s4, s5); 68 } 69 } 70 71 return matrix; 72 } 73 } 74 75 } 76