Commit d1133cb
Resize SVG objects
Changed files (4)
modifiedREADME.mdmodifiedlibsvgbird/Object.valamodifiedlibsvgbird/SvgStyle.valamodifiedlibsvgbird/SvgTransforms.vala
Diff
@@ -60,7 +60,7 @@ Configure the project with ./configure --nonnull ## 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"@@ -105,6 +105,23 @@ public abstract class Object : GLib.Object { 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);+ } public void to_object_distance (ref double x, ref double y) { Matrix m = view_matrix;@@ -274,6 +291,7 @@ public abstract class Object : GLib.Object { 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);@@ -26,6 +26,8 @@ public class SvgStyle : GLib.Object { public Gradient? fill_gradient = null; public LineCap line_cap = LineCap.BUTT; + public bool visible = true;+ public double padding_top { get { return SvgFile.parse_number (get_css_property ("padding-top"));@@ -322,6 +324,14 @@ public class SvgStyle : GLib.Object { 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;+ }+ } } void parse_key_value_pairs (string svg_style) {@@ -23,8 +23,6 @@ public class SvgTransforms : GLib.Object { 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 class SvgTransforms : GLib.Object { } 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 @@ public class SvgTransforms : GLib.Object { rotation = 0; size_matrix = Matrix.identity ();- scale_x = 1;- scale_y = 1; translate_x = 0; translate_y = 0;@@ -104,18 +92,22 @@ public class SvgTransforms : GLib.Object { 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 @@ public class SvgTransforms : GLib.Object { } 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; }