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.
Bounding box for SVG rectangles
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 SvgTransform copy () { 35 SvgTransform transform = new SvgTransform (); 36 transform.type = type; 37 transform.arguments = arguments.copy (); 38 return transform; 39 } 40 41 public string to_string () { 42 StringBuilder sb = new StringBuilder (); 43 44 sb.append (@"$type"); 45 sb.append (" "); 46 47 for (int i = 0; i < arguments.size; i++) { 48 sb.append (@"$(arguments.get_double (i)) "); 49 } 50 51 return sb.str; 52 } 53 54 public Matrix get_matrix () { 55 Matrix matrix; 56 57 matrix = Matrix.identity (); 58 59 if (type == TransformType.SCALE) { 60 if (arguments.size == 1) { 61 double s = arguments.get_double (0); 62 matrix.scale (s, s); 63 return matrix; 64 } else if (arguments.size == 2) { 65 double s0 = arguments.get_double (0); 66 double s1 = arguments.get_double (1); 67 matrix.scale (s0, s1); 68 } 69 } else if (type == TransformType.TRANSLATE) { 70 if (arguments.size == 1) { 71 double s = arguments.get_double (0); 72 matrix.translate (s, 0); 73 } else if (arguments.size == 2) { 74 double s0 = arguments.get_double (0); 75 double s1 = arguments.get_double (1); 76 matrix.translate (s0, s1); 77 } 78 } else if (type == TransformType.MATRIX) { 79 if (arguments.size == 6) { 80 double s0 = arguments.get_double (0); 81 double s1 = arguments.get_double (1); 82 double s2 = arguments.get_double (2); 83 double s3 = arguments.get_double (3); 84 double s4 = arguments.get_double (4); 85 double s5 = arguments.get_double (5); 86 87 matrix = Matrix (s0, s1, s2, s3, s4, s5); 88 } 89 } 90 91 return matrix; 92 } 93 } 94 95 } 96