Commit 52446ca
Convert SVG to BirdFont path in overview
Changed files (4)
modifiedlibbirdfont/MoveTool.valamodifiedlibbirdfont/OverViewItem.valamodifiedlibbirdfont/OverviewTools.valamodifiedlibbirdfont/SvgParser.vala
Diff
@@ -500,27 +500,51 @@ public class MoveTool : Tool { public void convert_svg_to_monochrome () { Font font = BirdFont.get_current_font ();+ ObjectGroup embedded_paths; Glyph glyph = MainWindow.get_current_glyph ();- Gee.ArrayList<EmbeddedSvg> embedded_paths;- embedded_paths = new Gee.ArrayList<EmbeddedSvg> ();+ + embedded_paths = new ObjectGroup (); foreach (SvgBird.Object object in glyph.active_paths) { if (object is EmbeddedSvg) {- embedded_paths.add ((EmbeddedSvg) object);+ embedded_paths.add (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);+ }+ + convert_objects_to_monochrome_glyph (glyph, embedded_paths);+ GlyphCanvas.redraw ();+ }++ public void convert_glyph_to_monochrome (Glyph glyph) {+ Font font = BirdFont.get_current_font ();+ ObjectGroup embedded_paths;+ + embedded_paths = new ObjectGroup ();++ foreach (SvgBird.Object object in glyph.get_visible_objects ()) {+ if (object is EmbeddedSvg) {+ embedded_paths.add (object); } }+ + convert_objects_to_monochrome_glyph (glyph, embedded_paths);+ } - GlyphCanvas.redraw ();+ public void convert_objects_to_monochrome_glyph (Glyph glyph, ObjectGroup embedded_paths) {+ Font font = BirdFont.get_current_font ();++ foreach (SvgBird.Object object in embedded_paths) {+ if (object is EmbeddedSvg) {+ EmbeddedSvg svg = (EmbeddedSvg) object;+ glyph.clear_active_paths ();+ PathList path_list = SvgParser.import_svg_data_in_glyph (svg.svg_data, glyph);+ glyph.delete_object (svg);+ + foreach (Path path in path_list.paths) {+ path.move (svg.x - glyph.left_limit, svg.y - font.top_position);+ }+ }+ } } } @@ -423,6 +423,11 @@ public class OverViewItem : GLib.Object { public void clear_cache () { cache = null;+ + if (glyphs != null) {+ GlyphCollection gc = (!) glyphs;+ gc.get_current ().overview_thumbnail = null;+ } } public void draw_label_background (Context cr) {@@ -18,7 +18,8 @@ namespace BirdFont { public enum Transform { SLANT,- SIZE+ SIZE,+ SVG_TO_TTF } public class OverviewTools : ToolCollection {@@ -188,6 +189,19 @@ public class OverviewTools : ToolCollection { Tool search_glyph = new Tool ("search", t_("Search")); search_glyph.select_action.connect (search_for_glyph); glyph_expander.add_tool (search_glyph);++ Tool convert_to_ttf = new Tool ("svg_to_birdfont_overview", t_("Convert SVG file to monochrome glyph"));+ convert_to_ttf.set_icon ("svg_to_birdfont");+ + convert_to_ttf.select_action.connect ((self) => {+ process_transform (Transform.SVG_TO_TTF);+ self.set_selected (false);+ BirdFont.get_current_font ().touch ();+ });+ + convert_to_ttf.selected = false;+ convert_to_ttf.set_persistent (false);+ glyph_expander.add_tool (convert_to_ttf); SpinButton master_size; current_master_size = 0;@@ -321,10 +335,15 @@ public class OverviewTools : ToolCollection { DrawingTools.resize_tool.resize_glyph (g, scale, scale, false); } }+ + if (transform == Transform.SVG_TO_TTF) {+ DrawingTools.move_tool.convert_glyph_to_monochrome (gc.get_current ());+ } } } foreach (OverViewItem item in o.visible_items) {+ item.clear_cache (); item.draw_glyph_from_font (); } @@ -136,8 +136,12 @@ public class SvgParser { } public static PathList import_svg_data (string xml_data, SvgFormat format = SvgFormat.NONE) {+ Glyph glyph = MainWindow.get_current_glyph ();+ return import_svg_data_in_glyph (xml_data, glyph, format);+ }+ + public static PathList import_svg_data_in_glyph (string xml_data, Glyph glyph, SvgFormat format = SvgFormat.NONE) { PathList path_list = new PathList ();- Glyph glyph; string[] lines = xml_data.split ("\n"); bool has_format = false; SvgParser parser = new SvgParser ();@@ -166,7 +170,6 @@ public class SvgParser { XmlTree xml_tree = new XmlTree (xml_data); path_list = parser.parse_svg_file (xml_tree.get_root ()); - glyph = MainWindow.get_current_glyph (); foreach (Path p in path_list.paths) { PathObject path = new PathObject.for_path (p); glyph.add_object (path);