The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Convert SVG to BirdFont path in overview

These changes was commited to the Birdfont repository Fri, 24 Jun 2016 19:44:23 +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>
Fri, 24 Jun 2016 19:44:23 +0000 (21:44 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 24 Jun 2016 19:44:23 +0000 (21:44 +0200)
commit 52446ca04b7f55b4758fc31738997c5d741ebd5f
tree bc8029f43d7ec3cb7432c4cb4a15533b90a38324
parent 411918b8949d023307f677708a16a01eb7c3a0df
Convert SVG to BirdFont path in overview

libbirdfont/MoveTool.vala
libbirdfont/OverViewItem.vala
libbirdfont/OverviewTools.vala
libbirdfont/SvgParser.vala
--- a/libbirdfont/MoveTool.vala +++ b/libbirdfont/MoveTool.vala @@ -500,29 +500,53 @@ 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); + } + } + } } } }
--- a/libbirdfont/OverViewItem.vala +++ b/libbirdfont/OverViewItem.vala @@ -423,6 +423,11 @@ 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) {
--- a/libbirdfont/OverviewTools.vala +++ b/libbirdfont/OverviewTools.vala @@ -18,7 +18,8 @@ public enum Transform { SLANT, - SIZE + SIZE, + SVG_TO_TTF } public class OverviewTools : ToolCollection { @@ -188,6 +189,19 @@ 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; @@ -320,11 +334,16 @@ double scale = resize.get_value () / 100; 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 (); }
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -136,8 +136,12 @@ } 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 @@ 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);