Commit 9743884
Convert embedded SVG files to BirdFont paths
Changed files (4)
modifiedlibbirdfont/ClipTool.valamodifiedlibbirdfont/DrawingTools.valamodifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/SvgParser.vala
Diff
@@ -146,8 +146,6 @@ public class ClipTool : Tool { if (bf_clipboard_data) { import_birdfont_clipboard (data, paste_guide_lines, false); } else if (data != "") {- //SvgParser.import_svg_data (data, SvgFormat.INKSCAPE);- print (@"$data\n\n"); SvgParser.import_svg_color_data (data); } @@ -1,5 +1,5 @@ /*- Copyright (C) 2012 2013 2014 2015 Johan Mattsson+ Copyright (C) 2012 2013 2014 2015 2016 Johan Mattsson This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as @@ -102,7 +102,7 @@ public class DrawingTools : ToolCollection { Tool move_layer; Tool flip_vertical; Tool flip_horizontal;- Tool full_height_tool;+ Tool monochrome_tool; public ZoomBar zoom_bar; @@ -569,13 +569,12 @@ public class DrawingTools : ToolCollection { reverse_path_tool = new OrientationTool ("reverse_path", t_("Create counter from outline")); draw_tool_modifiers.add_tool (reverse_path_tool); - full_height_tool = new Tool ("full_height", t_("Scale object to font top/baseline"));- full_height_tool.select_action.connect ((self) => {- resize_tool.full_height ();- GlyphCanvas.redraw ();+ monochrome_tool = new Tool ("svg_to_birdfont", t_("Convert SVG file to monochrome glyph"));+ monochrome_tool.select_action.connect ((self) => {+ move_tool.convert_svg_to_monochrome (); }); - draw_tool_modifiers.add_tool (full_height_tool);+ draw_tool_modifiers.add_tool (monochrome_tool); // close path close_path_tool = new Tool ("close_path", t_("Close path"));@@ -1322,7 +1321,7 @@ public class DrawingTools : ToolCollection { height.set_tool_visibility (false); reverse_path_tool.set_tool_visibility (false);- full_height_tool.set_tool_visibility (false);+ monochrome_tool.set_tool_visibility (false); move_layer.set_tool_visibility (false); flip_vertical.set_tool_visibility (false); flip_horizontal.set_tool_visibility (false);@@ -1394,7 +1393,7 @@ public class DrawingTools : ToolCollection { flip_vertical.set_tool_visibility (true); flip_horizontal.set_tool_visibility (true); - full_height_tool.set_tool_visibility (true);+ monochrome_tool.set_tool_visibility (true); } public override void reset_selection (Tool current_tool) {@@ -497,6 +497,31 @@ public class MoveTool : Tool { cr.stroke (); cr.restore (); }++ public void convert_svg_to_monochrome () {+ Font font = BirdFont.get_current_font ();+ Glyph glyph = MainWindow.get_current_glyph ();+ Gee.ArrayList<EmbeddedSvg> embedded_paths;+ embedded_paths = new Gee.ArrayList<EmbeddedSvg> ();++ foreach (SvgBird.Object object in glyph.active_paths) {+ if (object is EmbeddedSvg) {+ embedded_paths.add ((EmbeddedSvg) object);+ }+ } + + foreach (EmbeddedSvg svg in embedded_paths) {+ glyph.clear_active_paths ();+ PathList path_list = SvgParser.import_svg_data (svg.svg_data);+ glyph.delete_object (svg);+ + foreach (Path path in path_list.paths) {+ path.move (svg.x - glyph.left_limit, svg.y - font.top_position);+ }+ }++ GlyphCanvas.redraw ();+ } } }@@ -135,7 +135,7 @@ public class SvgParser { MainWindow.file_chooser (t_("Import"), fc, FileChooser.LOAD | FileChooser.DIRECTORY); } - public static void import_svg_data (string xml_data, SvgFormat format = SvgFormat.NONE) {+ public static PathList import_svg_data (string xml_data, SvgFormat format = SvgFormat.NONE) { PathList path_list = new PathList (); Glyph glyph; string[] lines = xml_data.split ("\n");@@ -174,7 +174,9 @@ public class SvgParser { path.update_boundaries_for_object (); } - glyph.close_path (); + glyph.close_path ();+ + return path_list; } public static string replace (string content, string start, string stop, string replacement) {