The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Store active layer in font settings and cache tools

These changes was commited to the Birdfont repository Sun, 13 Dec 2015 22:45:37 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sun, 13 Dec 2015 22:45:37 +0000]

Updated Files

libbirdfont/DrawingTools.vala
libbirdfont/Expander.vala
libbirdfont/FontSettings.vala
libbirdfont/Glyph.vala
libbirdfont/Layer.vala
libbirdfont/LayerLabel.vala
libbirdfont/ToolCollection.vala
libbirdfont/Toolbox.vala
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -768,7 +768,7 @@ add_layer.select_action.connect ((self) => { layer_tools.visible = true; MainWindow.get_current_glyph ().add_new_layer (); - update_layers (); + update_layers (); // FIXME: speed optimization show_layers.selected = true; add_layer.selected = false; }); @@ -1619,6 +1619,7 @@ } MainWindow.get_toolbox ().update_expanders (); + layer_tools.clear_cache (); layer_tools.redraw (); Toolbox.redraw_tool_box (); }
--- a/libbirdfont/Expander.vala +++ b/libbirdfont/Expander.vala @@ -269,6 +269,14 @@ return r; } + public void cache () { + if (cached == null) { + Surface workbench = Screen.create_background_surface (1, 1); + Context context = new Context (workbench); + draw (context); + } + } + public void draw (Context cr) { Surface cache;
--- a/libbirdfont/FontSettings.vala +++ b/libbirdfont/FontSettings.vala @@ -65,7 +65,7 @@ foreach (var k in settings.keys) { sb.append ("\t<setting key=\""); - sb.append (k); + sb.append (XmlParser.encode (k)); sb.append ("\" "); sb.append ("value=\""); sb.append (XmlParser.encode (settings.get (k))); @@ -114,7 +114,7 @@ string v = ""; foreach (Attribute a in tag.get_attributes ()) { if (a.get_name () == "key") { - key = a.get_content (); + key = XmlParser.decode (a.get_content ()); } if (a.get_name () == "value") {
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -195,6 +195,10 @@ public void add_new_layer () { layers.add_layer (new Layer ()); current_layer = layers.subgroups.size - 1; + } + + public int get_layer_index (Layer layer) { + return layers.index_of (layer); } public GlyfData get_ttf_data () { @@ -471,6 +475,18 @@ } update_zoom_bar (); + + Font font = BirdFont.get_current_font (); + string index = font.settings.get_setting (@"Active Layer $(get_name ())"); + + if (index != "") { + int i = int.parse (index); + + if (0 <= i < layers.subgroups.size) { + current_layer = i; + } + } + DrawingTools.update_layers (); MainWindow.get_toolbox ().update_expanders (); }
--- a/libbirdfont/Layer.vala +++ b/libbirdfont/Layer.vala @@ -29,6 +29,10 @@ subgroups = new Gee.ArrayList<Layer> (); } + public int index_of (Layer sublayer) { + return subgroups.index_of (sublayer); + } + public PathList get_all_paths () { PathList p = new PathList ();
--- a/libbirdfont/LayerLabel.vala +++ b/libbirdfont/LayerLabel.vala @@ -158,11 +158,16 @@ } public void select_layer () { - MainWindow.get_current_glyph ().set_current_layer (layer); + Glyph glyph = MainWindow.get_current_glyph (); + glyph.set_current_layer (layer); DrawingTools.deselect_layers (); selected_layer = true; MainWindow.get_current_glyph ().clear_active_paths (); GlyphCanvas.redraw (); + + Font font = BirdFont.get_current_font (); + int index = glyph.get_layer_index (layer); + font.settings.set_setting (@"Active Layer $(glyph.get_name ())", @"$(index)"); } public void remove_layer () {
--- a/libbirdfont/ToolCollection.vala +++ b/libbirdfont/ToolCollection.vala @@ -1,5 +1,5 @@ /* - Copyright (C) 2013 Johan Mattsson + Copyright (C) 2013 2015 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 @@ -34,6 +34,12 @@ public Tool get_current_tool () { return current_tool; + } + + public void cache () { + foreach (Expander e in get_expanders ()) { + e.cache (); + } } public void redraw () {
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -101,6 +101,14 @@ public void update_all_expanders () { foreach (ToolCollection tc in tool_sets) { tc.redraw (); + } + } + + public static void cache_all_tools () { + Toolbox t = MainWindow.get_toolbox (); + + foreach (ToolCollection tc in t.tool_sets) { + tc.cache (); } }