The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Resize paths

These changes was commited to the Birdfont repository Sun, 26 Jun 2016 16:24:43 +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>
Sun, 26 Jun 2016 16:24:43 +0000 (18:24 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 26 Jun 2016 16:24:43 +0000 (18:24 +0200)
commit 05222cac34dc561136118ccd5fba2dfa96f72215
tree e85b37b442f6b4c67253d5c02bbd32bf538858c3
parent bd7708bae6e853ea8b8a3f311499bdeeca8c2d5c
Resize paths

libbirdfont/MoveTool.vala
libbirdfont/ResizeTool.vala
libbirdfont/SvgParser.vala
libsvgbird/SvgTransforms.vala
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -283,13 +283,10 @@ 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; }
--- a/libbirdfont/ResizeTool.vala +++ b/libbirdfont/ResizeTool.vala @@ -128,16 +128,6 @@ 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 @@ 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 @@ || resize_path_proportional || resize_width) { - glyph = MainWindow.get_current_glyph (); - + glyph = MainWindow.get_current_glyph (); GlyphCanvas.redraw (); } @@ -371,11 +358,7 @@ 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 @@ } } - 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 @@ glyph.remove_lines (); glyph.add_help_lines (); } + + update_selection_box (); } public static void update_selection_box () { @@ -450,21 +435,6 @@ resize_selected_paths (ratio, 1); last_resize_x = px; last_resize_y = py; - } - } - - 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; - } } }
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -80,15 +80,22 @@ } public static void import_color_svg (Glyph glyph, string path) { - EmbeddedSvg drawing = SvgParser.parse_embedded_svg_data (path); + string 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; + 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) { @@ -1602,6 +1609,8 @@ XmlTree tree = new XmlTree (xml_data); SvgDrawing drawing = new SvgDrawing (); SvgFile svg_file = new SvgFile (); + + print (xml_data); XmlElement root = tree.get_root (); drawing = svg_file.parse_svg_file (root);
--- a/libsvgbird/SvgTransforms.vala +++ b/libsvgbird/SvgTransforms.vala @@ -18,6 +18,7 @@ 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 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 @@ 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 @@ } transformation_matrix.multiply (transformation_matrix, rotation_matrix); + transformation_matrix.multiply (transformation_matrix, size_matrix); return transformation_matrix; }