The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Move embedded SVG files

These changes was commited to the Birdfont repository Sun, 10 Jan 2016 00:51:02 +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, 10 Jan 2016 00:51:02 +0000 (01:51 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 10 Jan 2016 00:51:02 +0000 (01:51 +0100)
commit 07e24257a09062ba8749f424f421df9ad8791dd4
tree 90ef5c7af14bc4365e0a666cb66d2b737070eec6
parent b7a4f7f10f4bdd85e9928fb465d31be2fa4e9254
Move embedded SVG files

libbirdfont/BirdFontFile.vala
libbirdfont/EmbeddedSvg.vala
libbirdfont/Glyph.vala
libbirdfont/MoveTool.vala
libbirdfont/Path.vala
libbirdfont/PathObject.vala
libbirdfont/Svg/SvgDrawing.vala
libbirdfont/TestCases.vala
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -1470,7 +1470,6 @@ string type = ""; double x = 0; double y = 0; - EmbeddedSvg svg; foreach (Attribute attribute in tag.get_attributes ()) { if (attribute.get_name () == "x") { @@ -1488,7 +1487,9 @@ if (type == "svg") { SvgFile svg_file = new SvgFile (); - svg = svg_file.parse_data (tag.get_content ()); + EmbeddedSvg svg = svg_file.parse_data (tag.get_content ()); + svg.x = x; + svg.y = y; layer.add_object (svg); } }
--- a/libbirdfont/EmbeddedSvg.vala +++ b/libbirdfont/EmbeddedSvg.vala @@ -22,32 +22,12 @@ public string svg_data = ""; public SvgDrawing drawing = new SvgDrawing (); - public double x { - get { - return drawing.x; - } + public double x { get; set; } + public double y { get; set; } - set { - drawing.x = value; - } - } - - public double y { - get { - return drawing.y; - } - - set { - drawing.y = value; - } - } - - // FIXME: boundaries for embedded SVG - public override double xmin { get { - Glyph g = MainWindow.get_current_glyph (); - return g.left_limit; + return x; } set { @@ -56,8 +36,7 @@ public override double xmax { get { - Glyph g = MainWindow.get_current_glyph (); - return g.right_limit; + return x + drawing.width; } set { @@ -67,8 +46,7 @@ public override double ymin { get { - Font font = BirdFont.get_current_font (); - return font.bottom_position; + return y - drawing.height; } set { @@ -77,8 +55,7 @@ public override double ymax { get { - Font font = BirdFont.get_current_font (); - return font.top_position; + return y; } set { @@ -93,12 +70,20 @@ drawing.update_region_boundaries (); } + // FIXME: handle this in SVG library instead public override bool is_over (double x, double y) { - return drawing.is_over (x, y); + print (@" $(this.x) <= $(x) <= $(this.x) + $(drawing.width)"); + print (@" $(this.y) <= $(y) <= $(this.y) + $(drawing.height)"); + + return (this.x <= x <= this.x + drawing.width) + && (this.y - drawing.height <= y <= this.y); } public override void draw (Context cr) { + cr.save (); + cr.translate (Glyph.xc () + x, Glyph.yc () - y); drawing.draw (cr); + cr.restore (); } public override Object copy () { @@ -108,7 +93,8 @@ } public override void move (double dx, double dy) { - drawing.move (dx, dy); + x += dx; + y += dy; } public override void rotate (double theta, double xc, double yc) {
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -133,7 +133,6 @@ public Layer layers = new Layer (); public int current_layer = 0; public Gee.ArrayList<Object> active_paths = new Gee.ArrayList<Object> (); - public Gee.ArrayList<Layer> selected_groups = new Gee.ArrayList<Layer> (); // used if this glyph originates from a fallback font public double top_limit = 0; @@ -263,7 +262,6 @@ } public void clear_active_paths () { - selected_groups.clear (); active_paths.clear (); } @@ -276,6 +274,7 @@ } } + // FIXME: delete group public void add_active_object (Layer? group, Object? o) { Object object; Layer g; @@ -296,13 +295,6 @@ } PenTool.active_path = path.get_path (); - } - } - - if (group != null) { - g = (!) group; - if (!selected_groups.contains (g)) { - selected_groups.add (g); } } } @@ -1207,61 +1199,14 @@ return -y; } - public Layer? get_path_at (double x, double y) { - Layer? group = null; - bool found = false; - - foreach (Layer layer in get_current_layer ().subgroups) { - foreach (Object o in layer.objects) { - if (o.is_over (x, y)) { - found = true; - group = layer; - } + public Object? get_object_at (double x, double y) { + foreach (Object o in get_current_layer ().objects) { + if (o.is_over (x, y)) { + return o; } } - - if (!found) { - foreach (Path pt in get_paths_in_current_layer ()) { - if (pt.is_over (x, y)) { - Layer layer = new Layer (); - layer.is_counter = true; - layer.single_path = true; - layer.add_path (pt); - group = layer; - } - } - } - - return group; - } - - public bool select_path (double x, double y) { - Path? p = null; - bool found = false; - - foreach (Path pt in get_paths_in_current_layer ()) { - if (pt.is_over (x, y)) { - p = pt; - found = true; - } - } - - if (!KeyBindings.has_shift ()) { - clear_active_paths (); - } - - add_active_path (null, p); - - return found; - } - - public bool is_over_selected_path (double x, double y) { - foreach (Object p in active_paths) { - if (p.is_over (x, y)) { - return true; - } - } - return false; + + return null; } public void queue_redraw_path (Path path) { @@ -1278,48 +1223,6 @@ double xtb = -view_offset_x - xmax; redraw_area ((int)xtb - 10, (int)yta - 10, (int)(xtb - xta) + 10, (int) (yta - ytb) + 10); - } - - public Path get_closeset_path (double x, double y) { - double d; - EditPoint ep = new EditPoint (); - - Path min_point = new Path (); - double min_distance = double.MAX; - - double xt = path_coordinate_x (x); - double yt = path_coordinate_y (y); - var paths = get_visible_paths (); - - foreach (Path p in paths) { - if (p.is_over (xt, yt)) { - return p; - } - } - - foreach (Path p in paths) { - if (p.points.size == 0) continue; - - p.get_closest_point_on_path (ep, xt, yt); - d = Math.pow (ep.x - xt, 2) + Math.pow (ep.y - yt, 2); - - if (d < min_distance) { - min_distance = d; - min_point = p; - } - - } - - // a path without any editpoints - if (paths.size > 0) { - return paths.get (0); - } - - if (unlikely (min_distance == double.MAX)) { - warning (@"No path found in path_list."); - } - - return min_point; } public void move_selected_edit_point_coordinates (EditPoint selected_point, double xt, double yt) { @@ -1754,6 +1657,13 @@ p.draw_edit_points (cr); } cr.restore (); + } + + // FIXME: layer transforms + foreach (Object o in get_visible_objects ()) { + if (!(o is PathObject)) { + o.draw (cr); + } } if (!is_open ()) { @@ -1778,13 +1688,6 @@ cr.close_path (); cr.fill (); cr.restore (); - - // FIXME: layer transforms - foreach (Object o in get_visible_objects ()) { - if (!(o is PathObject)) { - o.draw (cr); - } - } foreach (Object o in active_paths) { if (o is PathObject) { @@ -1855,8 +1758,8 @@ } if (unlikely (Preferences.draw_boundaries)) { - foreach (Path p in get_visible_paths ()) { - p.draw_boundaries (cmp); + foreach (Object o in get_visible_objects ()) { + draw_boundaries (o, cmp); } } @@ -2552,7 +2455,22 @@ return paths; } + public void draw_boundaries (Object object, Context cr) { + double x = Glyph.reverse_path_coordinate_x (object.xmin); + double y = Glyph.reverse_path_coordinate_y (object.ymin); + double x2 = Glyph.reverse_path_coordinate_x (object.xmax); + double y2 = Glyph.reverse_path_coordinate_y (object.ymax); + + cr.save (); + + Theme.color (cr, "Default Background"); + cr.set_line_width (2); + cr.rectangle (x, y, x2 - x, y2 - y); + cr.stroke (); + + cr.restore (); + } } }
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -127,16 +127,6 @@ delta_x = -dx; delta_y = -dy; - - foreach (Layer group in glyph.selected_groups) { - if (group.gradient != null) { - Gradient g = (!) group.gradient; - g.x1 += delta_x; - g.x2 += delta_x; - g.y1 += delta_y; - g.y2 += delta_y; - } - } foreach (Object object in glyph.active_paths) { object.move (delta_x, delta_y); @@ -198,36 +188,30 @@ Glyph glyph = MainWindow.get_current_glyph (); Object object; bool selected = false; - Layer? group; - Layer g; + Object? o; - glyph.store_undo_state (); - group_selection = false; - - group = glyph.get_path_at (x, y); - - if (group != null) { - g = (!) group; - return_if_fail (g.objects.objects.size > 0); - object = g.objects.objects.get (0); + glyph.store_undo_state (); + double px = Glyph.path_coordinate_x (x); + double py = Glyph.path_coordinate_y (y); + o = glyph.get_object_at (px, py); + + if (o != null) { + object = (!) o; selected = glyph.active_paths_contains (object); - + if (!selected && !KeyBindings.has_shift ()) { glyph.clear_active_paths (); } - foreach (Object lp in g.objects) { - if (selected && KeyBindings.has_shift ()) { - glyph.selected_groups.remove ((!) group); - glyph.active_paths.remove (lp); - } else { - glyph.add_active_object ((!) group, lp); - } - } + if (selected && KeyBindings.has_shift ()) { + glyph.active_paths.remove (object); + } else { + glyph.add_active_object (null, object); + } } else if (!KeyBindings.has_shift ()) { glyph.clear_active_paths (); } - + update_selection_boundaries (); move_path = true;
--- a/libbirdfont/Path.vala +++ b/libbirdfont/Path.vala @@ -172,22 +172,6 @@ public bool empty () { return points.size == 0; - } - - public void draw_boundaries (Context cr) { - double x = Glyph.reverse_path_coordinate_x (xmin); - double y = Glyph.reverse_path_coordinate_y (ymin); - double x2 = Glyph.reverse_path_coordinate_x (xmax); - double y2 = Glyph.reverse_path_coordinate_y (ymax); - - cr.save (); - - Theme.color (cr, "Default Background"); - cr.set_line_width (2); - cr.rectangle (x, y, x2 - x, y2 - y); - cr.stroke (); - - cr.restore (); } public void draw_outline (Context cr) { @@ -821,17 +805,6 @@ new_path.highlight_last_segment = highlight_last_segment; return new_path; - } - - public bool is_over (double x, double y) { - Glyph g = MainWindow.get_current_glyph (); - - x = x * Glyph.ivz () + g.view_offset_x - Glyph.xc (); - y = y * Glyph.ivz () + g.view_offset_y - Glyph.yc (); - - y *= -1; - - return is_over_coordinate (x, y); } public bool is_over_coordinate (double x, double y) {
--- a/libbirdfont/PathObject.vala +++ b/libbirdfont/PathObject.vala @@ -153,7 +153,7 @@ } public override bool is_over (double x, double y) { - return path.is_over (x, y); + return path.is_over_coordinate (x, y); } public override void draw (Context cr) {
--- a/libbirdfont/Svg/SvgDrawing.vala +++ b/libbirdfont/Svg/SvgDrawing.vala @@ -27,7 +27,7 @@ public double y = 0; public double width = 0; public double height = 0; - + public override void update_region_boundaries () { } @@ -37,9 +37,14 @@ } public override void draw (Context cr) { + cr.save (); + cr.translate (x, y); + foreach (Object o in root_layer.get_visible_objects ().objects) { o.draw (cr); } + + cr.restore (); } public override Object copy () {
--- a/libbirdfont/TestCases.vala +++ b/libbirdfont/TestCases.vala @@ -33,7 +33,6 @@ add (test_drawing, "Pen tool"); add (test_delete_points, "Delete edit points"); add (test_convert_to_quadratic_bezier_path, "Convert to quadratic path"); - add (test_over_path, "Over path"); add (test_export, "Export"); add (test_background_coordinates, "Background coordinates"); add (test_spin_button, "Spin button"); @@ -580,58 +579,6 @@ MainWindow.get_tab_bar ().select_tab_name ("Preview"); Tool.yield (); } - - } - - public static void test_over_path () { - Glyph g; - Path p = new Path (); - Tool pen_tool; - - pen_tool = MainWindow.get_toolbox ().get_tool ("pen_tool"); - test_select_action (pen_tool); - test_open_next_glyph (); - - g = MainWindow.get_current_glyph (); - - test_click_action (pen_tool, 3, 10, 10); - test_click_action (pen_tool, 3, 10, 10); - test_click_action (pen_tool, 3, 100, 10); - test_click_action (pen_tool, 3, 100, 100); - test_click_action (pen_tool, 3, 10, 100); - test_click_action (pen_tool, 2, 0, 0); - - g.close_path (); - - warn_if_fail (g.active_paths.size == 0); - - g.select_path (50, 50); - - warn_if_fail (g.active_paths.size == 1); - - p.add (-10, 10); - p.add (10, 10); - p.add (10, -10); - p.add (-10, -10); - p.update_region_boundaries(); - g.add_path (p); - g.close_path (); - - if (!p.is_over_coordinate (0, 0)) { - warning ("Coordinate 0, 0 is not in path."); - } - - if (!p.is_over_coordinate (-10, 10)) { - warning ("Corner corrdinate -10, 10 is not in path."); - } - - warn_if_fail (!p.is_over_coordinate (-20, -20)); - - for (double x = -10; x <= 10; x += 0.1) { - for (double y = 10; y <= 10; y += 0.1) { - warn_if_fail (p.is_over_coordinate (x, y)); - } - } }