The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Rotation

These changes was commited to the Birdfont repository Fri, 22 Jul 2016 16:02:49 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Fri, 22 Jul 2016 16:02:49 +0000]

Updated Files

libsvgbird/SvgFile.vala
libsvgbird/SvgTransform.vala
libsvgbird/SvgTransforms.vala
--- a/libsvgbird/SvgFile.vala +++ b/libsvgbird/SvgFile.vala @@ -680,6 +680,9 @@ transform_functions.add (matrix (functions[i])); } + if (functions[i].has_prefix ("rotate")) { + transform_functions.add (rotate (functions[i])); + } // TODO: rotate etc. } @@ -737,6 +740,19 @@ } return n; + } + + private static SvgTransform rotate (string function) { + string parameters = get_transform_parameters (function); + string[] p = parameters.split (" "); + SvgTransform transform = new SvgTransform (); + transform.type = TransformType.ROTATE; + + if (p.length > 0) { + transform.arguments.add (parse_double (p[0])); + } + + return transform; } private static SvgTransform scale (string function) {
--- a/libsvgbird/SvgTransform.vala +++ b/libsvgbird/SvgTransform.vala @@ -21,7 +21,8 @@ NONE, TRANSLATE, MATRIX, - SCALE + SCALE, + ROTATE } public class SvgTransform : GLib.Object { @@ -67,7 +68,14 @@ matrix = Matrix.identity (); - if (type == TransformType.SCALE) { + if (type == TransformType.ROTATE) { + if (arguments.size == 1) { + double r = arguments.get_double (0); + r *= Math.PI / 180; + matrix.rotate (r); + return matrix; + } + } else if (type == TransformType.SCALE) { if (arguments.size == 1) { double s = arguments.get_double (0); matrix.scale (s, s);
--- a/libsvgbird/SvgTransforms.vala +++ b/libsvgbird/SvgTransforms.vala @@ -30,6 +30,14 @@ transforms = new Gee.ArrayList<SvgTransform> (); rotation_matrix = Matrix.identity (); size_matrix = Matrix.identity (); + } + + public double get_rotation () { + Matrix m = get_matrix (); + double w = 1; + double h = 1; + m.transform_distance (ref w, ref h); + return Math.atan2 (h, w); } public void collapse_transforms () {