The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Resize SVG objects

These changes was commited to the Birdfont repository Thu, 21 Jul 2016 22:20:14 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 21 Jul 2016 22:20:14 +0000 (00:20 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Thu, 21 Jul 2016 22:20:14 +0000 (00:20 +0200)
commit d1133cbf040141e0532645333a93870e767a8bc5
tree 079bcfe7852e9b2c935a2f65358e9c6cfb22560b
parent d573ed0fda5b9741faa95bb0c343f3ea2b6614a6
Resize SVG objects

README.md
libsvgbird/Object.vala
libsvgbird/SvgStyle.vala
libsvgbird/SvgTransforms.vala
--- a/README.md +++ b/README.md @@ -60,10 +60,10 @@ ## Packages Windows and Mac binaries can be downloaded from - http://birdfont.org Many Linux distributions have packages of + https://birdfont.org Many Linux distributions have packages of Birdfont in their repositories. There is a BSD package in OpenBSD. [birdfont]: https://birdfont.org/images/birdfont_logo2.png "Birdfont logo" [xmlbird]: https://birdfont.org/xmlbird.php "XML Bird – XML Parser for programs written in VALA"
--- a/libsvgbird/Object.vala +++ b/libsvgbird/Object.vala @@ -103,6 +103,23 @@ public void to_object_view (ref double x, ref double y) { Matrix m = view_matrix; m.invert (); + m.transform_point (ref x, ref y); + } + + public void to_parent_distance (ref double x, ref double y) { + Matrix m = parent_matrix; + m.invert (); + m.transform_distance (ref x, ref y); + } + + public void to_parent_view (ref double x, ref double y) { + Matrix m = parent_matrix; + m.invert (); + m.transform_point (ref x, ref y); + } + + public void from_object_view (ref double x, ref double y) { + Matrix m = view_matrix; m.transform_point (ref x, ref y); } @@ -274,6 +291,7 @@ bool has_stroke = style.has_stroke (); apply_transform (context); + view_matrix = context.get_matrix (); if (style.fill_gradient != null) { apply_gradient (context, (!) style.fill_gradient);
--- a/libsvgbird/SvgStyle.vala +++ b/libsvgbird/SvgStyle.vala @@ -25,6 +25,8 @@ public Gradient? stroke_gradient = null; public Gradient? fill_gradient = null; public LineCap line_cap = LineCap.BUTT; + + public bool visible = true; public double padding_top { get { @@ -321,6 +323,14 @@ if (s.stroke != null) { Color color = (!) s.stroke; color.a = stroke_opacity; + } + + string? v = s.get_css_property ("visibility"); + if (v != null) { + string visible = (!) v; + if (visible == "hidden" || visible == "collapse") { + s.visible = false; + } } }
--- a/libsvgbird/SvgTransforms.vala +++ b/libsvgbird/SvgTransforms.vala @@ -23,8 +23,6 @@ public double rotation = 0; public double total_rotation = 0; - public double scale_x = 1; - public double scale_y = 1; public double translate_x = 0; public double translate_y = 0; @@ -35,27 +33,19 @@ } public void collapse_transforms () { - Matrix translate_matrix = Matrix.identity (); - translate_matrix.translate (translate_x, translate_y); - SvgTransform translate_transform = new SvgTransform.for_matrix (translate_matrix); - add (translate_transform); - - SvgTransform rotation_transform = new SvgTransform.for_matrix (rotation_matrix); - add (rotation_transform); + Matrix collapsed = get_matrix (); + translate_x = 0; + translate_y = 0; + rotation_matrix = Matrix.identity (); rotation = 0; - - SvgTransform size_transform = new SvgTransform.for_matrix (size_matrix); - add (size_transform); size_matrix = Matrix.identity (); - scale_x = 1; - scale_y = 1; - Matrix collapsed = get_matrix (); - SvgTransform collapsed_transform = new SvgTransform.for_matrix (collapsed); clear (); + + SvgTransform collapsed_transform = new SvgTransform.for_matrix (collapsed); add (collapsed_transform); } @@ -66,8 +56,6 @@ rotation = 0; size_matrix = Matrix.identity (); - scale_x = 1; - scale_y = 1; translate_x = 0; translate_y = 0; @@ -104,18 +92,22 @@ rotation_matrix.translate (-x, -y); } - public void resize (double ratio_x, double ratio_y, double x, double y) { - scale_x *= ratio_x; - scale_y *= ratio_y; - + public void resize (double scale_x, double scale_y, double x, double y) { if (scale_x <= 0 || scale_y <= 0) { return; } - + + double x2 = x; + double y2 = y; + size_matrix = Matrix.identity (); - size_matrix.translate (x, y); size_matrix.scale (scale_x, scale_y); - size_matrix.translate (-x, -y); + size_matrix.transform_point (ref x2, ref y2); + + double dx = x - x2; + double dy = y - y2; + + size_matrix.translate (dx / scale_x, dy / scale_y); } public SvgTransforms copy () { @@ -141,8 +133,9 @@ } transformation_matrix.translate (translate_x, translate_y); - transformation_matrix.multiply (transformation_matrix, size_matrix); + transformation_matrix.multiply (transformation_matrix, rotation_matrix); + transformation_matrix.multiply (transformation_matrix, size_matrix); return transformation_matrix; }