Commit 05222ca
Resize paths
Changed files (4)
modifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/ResizeTool.valamodifiedlibbirdfont/SvgParser.valamodifiedlibsvgbird/SvgTransforms.vala
Diff
@@ -283,13 +283,10 @@ public class MoveTool : Tool { py2 = -10000; top = 10000; left = 10000;++ glyph.layers.update_boundaries_for_object (); foreach (SvgBird.Object o in glyph.active_paths) {- if (o is PathObject) {- Path p = ((PathObject) o).get_path ();- p.update_region_boundaries ();- }- if (top > o.top) { top = o.top; }@@ -128,16 +128,6 @@ public class ResizeTool : Tool { if (object is PathObject) { PathObject path = (PathObject) object; Path p = path.get_path ();- - /*- Matrix matrix = Matrix.identity ();- matrix.scale (1, -1);- matrix.multiply (matrix, object.transforms.get_matrix ());- matrix.invert ();- p.transform (matrix);- object.transforms.clear ();- */- p.create_full_stroke (); } else { object.transforms.collapse_transforms ();@@ -150,12 +140,10 @@ public class ResizeTool : Tool { if (resize_path_proportional && can_resize (x, y)) { resize_proportional (x, y);- update_selection_box (); } if (resize_width && can_resize (x, y)) { resize_horizontal (x, y);- update_selection_box (); } if (rotate_path) {@@ -167,8 +155,7 @@ public class ResizeTool : Tool { || resize_path_proportional || resize_width) { - glyph = MainWindow.get_current_glyph ();- + glyph = MainWindow.get_current_glyph (); GlyphCanvas.redraw (); } @@ -371,11 +358,7 @@ public class ResizeTool : Tool { public void resize_glyph (Glyph glyph, double ratio_x, double ratio_y, bool selected = true) {- - double resize_pos_x = 0;- double resize_pos_y = 0;- double selection_minx, selection_miny, dx, dy;- + if (!selected) { glyph.clear_active_paths (); @@ -384,24 +367,24 @@ public class ResizeTool : Tool { } } - get_selection_min (out resize_pos_x, out resize_pos_y);- - // resize paths- foreach (SvgBird.Object selected_path in glyph.active_paths) {- selected_path.transforms.resize (ratio_x, ratio_y);- }- - // move paths relative to the updated xmin and xmax- get_selection_min (out selection_minx, out selection_miny);- dx = resize_pos_x - selection_minx;- dy = resize_pos_y - selection_miny;- - foreach (SvgBird.Object selected_path in glyph.active_paths) {- selected_path.move (dx, dy); + foreach (SvgBird.Object p in glyph.active_paths) {+ if (p is EmbeddedSvg) {+ EmbeddedSvg svg = (EmbeddedSvg) p;+ x = selection_box_left - svg.x;+ y = selection_box_top + svg.y + selection_box_height;+ p.transforms.resize (ratio_x, ratio_y, x, y);+ } else if (p is PathObject) {+ Path path = ((PathObject) p).get_path ();+ x = selection_box_center_x - selection_box_width / 2;+ y = selection_box_center_y - selection_box_height / 2;+ SvgTransforms transform = new SvgTransforms ();+ transform.resize (ratio_x, ratio_y, x, y);+ Matrix matrix = transform.get_matrix ();+ path.transform (matrix);+ } } if (glyph.active_paths.size > 0) {- update_selection_box (); objects_resized (selection_box_width, selection_box_height); } @@ -414,6 +397,8 @@ public class ResizeTool : Tool { glyph.remove_lines (); glyph.add_help_lines (); }++ update_selection_box (); } public static void update_selection_box () {@@ -453,21 +438,6 @@ public class ResizeTool : Tool { } } - void get_selection_min (out double x, out double y) {- Glyph glyph = MainWindow.get_current_glyph ();- x = double.MAX;- y = double.MAX;- foreach (SvgBird.Object p in glyph.active_paths) {- if (p.xmin < x) {- x = p.xmin;- }- - if (p.ymin < y) {- y = p.ymin;- }- }- }- bool can_resize (double x, double y) { Glyph glyph = MainWindow.get_current_glyph (); double h, w;@@ -80,15 +80,22 @@ public class SvgParser { } public static void import_color_svg (Glyph glyph, string path) {- EmbeddedSvg drawing = SvgParser.parse_embedded_svg_data (path);- - glyph.add_object (drawing);- drawing.update_boundaries_for_object ();- - Font font = BirdFont.get_current_font ();+ string xml_data; - drawing.x = glyph.left_limit;- drawing.y = font.top_position - font.base_line;+ try {+ FileUtils.get_contents (path, out xml_data);+ EmbeddedSvg drawing = SvgParser.parse_embedded_svg_data (xml_data);+ + glyph.add_object (drawing);+ drawing.update_boundaries_for_object ();+ + Font font = BirdFont.get_current_font ();+ + drawing.x = glyph.left_limit;+ drawing.y = font.top_position - font.base_line;+ } catch (GLib.Error e) {+ warning (e.message);+ } } public static void import_folder (SvgType type) {@@ -1603,6 +1610,8 @@ public class SvgParser { SvgDrawing drawing = new SvgDrawing (); SvgFile svg_file = new SvgFile (); + print (xml_data);+ XmlElement root = tree.get_root (); drawing = svg_file.parse_svg_file (root); EmbeddedSvg svg = new EmbeddedSvg (drawing);@@ -18,6 +18,7 @@ namespace SvgBird { public class SvgTransforms : GLib.Object { public Matrix rotation_matrix;+ public Matrix size_matrix; public Gee.ArrayList<SvgTransform> transforms; public double x = 0;@@ -29,25 +30,38 @@ public class SvgTransforms : GLib.Object { public SvgTransforms () { transforms = new Gee.ArrayList<SvgTransform> (); rotation_matrix = Matrix.identity ();+ size_matrix = Matrix.identity (); } public void collapse_transforms () {- SvgTransform transform = new SvgTransform.for_matrix (rotation_matrix);- add (transform);+ SvgTransform rotation_transform = new SvgTransform.for_matrix (rotation_matrix);+ add (rotation_transform); 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 transform_transform = new SvgTransform.for_matrix (collapsed);+ SvgTransform collapsed_transform = new SvgTransform.for_matrix (collapsed); clear ();- add (transform_transform);+ add (collapsed_transform); } public void clear () { transforms.clear ();+ rotation_matrix = Matrix.identity (); rotation = 0;+ + size_matrix = Matrix.identity ();+ scale_x = 1;+ scale_y = 1; } public void rotate (double theta, double x, double y) {@@ -67,9 +81,18 @@ public class SvgTransforms : GLib.Object { rotation_matrix.translate (-x, -y); } - public void resize (double x, double y) {- scale_x += x;- scale_y += y;+ public void resize (double ratio_x, double ratio_y, double x, double y) {+ scale_x *= ratio_x;+ scale_y *= ratio_y;++ if (scale_x <= 0 || scale_y <= 0) {+ return;+ }++ size_matrix = Matrix.identity ();+ size_matrix.translate (x, y);+ size_matrix.scale (scale_x, scale_y);+ size_matrix.translate (-x, -y); } public SvgTransforms copy () {@@ -95,6 +118,7 @@ public class SvgTransforms : GLib.Object { } transformation_matrix.multiply (transformation_matrix, rotation_matrix);+ transformation_matrix.multiply (transformation_matrix, size_matrix); return transformation_matrix; }