The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Merge ../birdfont-2.x

These changes was commited to the Birdfont repository Mon, 13 Jun 2016 11:03: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
[Mon, 13 Jun 2016 11:03:23 +0000]

Updated Files

libbirdfont/AbstractMenu.vala
libbirdfont/BirdFontFile.vala
libbirdfont/DrawingTools.vala
libbirdfont/Glyph.vala
libbirdfont/GlyphSelection.vala
libbirdfont/OtfFeatureTable.vala
libbirdfont/OverviewTools.vala
libbirdfont/SpacingClass.vala
libbirdfont/SpacingClassTab.vala
libbirdfont/SpacingClassTools.vala
libbirdfont/SpacingData.vala
libbirdfont/Toolbox.vala
--- a/libbirdfont/AbstractMenu.vala +++ b/libbirdfont/AbstractMenu.vala @@ -231,6 +231,7 @@ public void add_tool_key_bindings () { ToolItem tool_item; + foreach (ToolCollection tool_set in MainWindow.get_toolbox ().tool_sets) { foreach (Expander e in tool_set.get_expanders ()) { foreach (Tool t in e.tool) {
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -26,7 +26,7 @@ Font font; public static const int FORMAT_MAJOR = 2; - public static const int FORMAT_MINOR = 1; + public static const int FORMAT_MINOR = 2; public static const int MIN_FORMAT_MAJOR = 0; public static const int MIN_FORMAT_MINOR = 0; @@ -277,11 +277,25 @@ foreach (SpacingClass sc in s.classes) { os.put_string ("<spacing "); os.put_string ("first=\""); - os.put_string (Font.to_hex (sc.first.get_char ())); + + if (sc.first.char_count () == 1) { + os.put_string (Font.to_hex (sc.first.get_char ())); + } else { + os.put_string ("name:"); + os.put_string (XmlParser.encode (sc.first)); + } + os.put_string ("\" "); os.put_string ("next=\""); - os.put_string (Font.to_hex (sc.next.get_char ())); + + if (sc.next.char_count () == 1) { + os.put_string (Font.to_hex (sc.next.get_char ())); + } else { + os.put_string ("name:"); + os.put_string (XmlParser.encode (sc.next)); + } + os.put_string ("\" "); os.put_string ("/>\n"); @@ -1128,6 +1142,7 @@ private void parse_spacing_class (Tag tag) { string first, next; + string name; SpacingData spacing = font.get_spacing (); first = ""; @@ -1135,11 +1150,21 @@ foreach (Attribute attr in tag.get_attributes ()) { if (attr.get_name () == "first") { - first = (!) Font.to_unichar (attr.get_content ()).to_string (); + if (attr.get_content ().has_prefix ("U+")) { + first = (!) Font.to_unichar (attr.get_content ()).to_string (); + } else if (attr.get_content ().has_prefix ("name:")) { + name = attr.get_content ().substring ("name:".length); + first = XmlParser.decode (name); + } } if (attr.get_name () == "next") { - next = (!) Font.to_unichar (attr.get_content ()).to_string (); + if (attr.get_content ().has_prefix ("U+")) { + next = (!) Font.to_unichar (attr.get_content ()).to_string (); + } else if (attr.get_content ().has_prefix ("name:")) { + name = attr.get_content ().substring ("name:".length); + next = XmlParser.decode (name); + } } } @@ -1157,6 +1182,7 @@ foreach (Attribute attr in tag.get_attributes ()) { if (attr.get_name () == "left") { + range_left.parse_ranges (unserialize (attr.get_content ())); }
--- a/libbirdfont/DrawingTools.vala +++ b/libbirdfont/DrawingTools.vala @@ -192,9 +192,10 @@ }); draw_tools.add_tool (move_background); - move_canvas = new Tool ("move_canvas", - t_("Move canvas"), - t_("Press space and click to move the canvas.")); + move_canvas = new Tool ("move_canvas", t_("Move canvas") + + "\n" + t_("Ctrl + Shift + Click") + + "\n" + t_("Space + Click") + "\n"); + move_canvas.select_action.connect ((self) => { update_drawing_and_background_tools (self); });
--- a/libbirdfont/Glyph.vala +++ b/libbirdfont/Glyph.vala @@ -1056,7 +1056,9 @@ return; } - if (move_canvas || DrawingTools.move_canvas.is_selected ()) { + if (move_canvas + || DrawingTools.move_canvas.is_selected () + || (KeyBindings.has_ctrl () && KeyBindings.has_shift ())) { view_is_moving = true; move_offset_x = view_offset_x; move_offset_y = view_offset_y; @@ -1813,7 +1815,7 @@ private void move_view_offset (double x, double y) { view_offset_x = move_offset_x + (pointer_begin_x - x) * (1/view_zoom); view_offset_y = move_offset_y + (pointer_begin_y - y) * (1/view_zoom); - redraw_area (0, 0, allocation.width, allocation.height); + GlyphCanvas.redraw (); } public void store_undo_state (bool clear_redo = false) { @@ -2306,7 +2308,7 @@ SpacingData sd; sd = font.get_spacing (); - s = sd.get_all_connections ((!) unichar_code.to_string ()); + s = sd.get_all_connections (get_name ()); foreach (string l in s) { if (l != (!) unichar_code.to_string ()) {
--- a/libbirdfont/GlyphSelection.vala +++ b/libbirdfont/GlyphSelection.vala @@ -27,7 +27,7 @@ FontDisplay.dirty_scrollbar = true; open_glyph_signal.connect ((gc) => { - selected_glyph (gc); + selected_glyph (gc); Toolbox.redraw_tool_box (); });
--- a/libbirdfont/OtfFeatureTable.vala +++ b/libbirdfont/OtfFeatureTable.vala @@ -26,7 +26,7 @@ static const int REPLACEMENT_GLYPH = 3; static const int ALTERNATE_ENTRY = 4; - GlyphCollection glyph_collection; + GlyphCollection? glyph_collection = null; GlyphCollection? replacement_glyph = null; string alternate_name = ""; TextListener listener; @@ -34,7 +34,7 @@ Gee.ArrayList<AlternateItem> undo_items; // FIXME: implement redo - public OtfFeatureTable (GlyphCollection gc) { + public OtfFeatureTable (GlyphCollection? gc) { glyph_collection = gc; undo_items = new Gee.ArrayList<AlternateItem> (); } @@ -102,7 +102,15 @@ row = new Row.headline (t_("Glyph Substitutions")); rows.add (row); - row = new Row.columns_1 (t_("Glyph") + ": " + glyph_collection.get_name (), SOURCE_GLYPH, false); + string glyph = ""; + + if (glyph_collection == null) { + glyph = t_("New glyph"); + } else { + glyph = ((!) glyph_collection).get_name (); + } + + row = new Row.columns_1 (t_("Glyph") + ": " + glyph, SOURCE_GLYPH, false); rows.add (row); string replacement = t_("New glyph"); @@ -176,7 +184,14 @@ } public void add_new_alternate (string tag) { - GlyphCollection gc = glyph_collection; + GlyphCollection gc; + + if (glyph_collection == null) { + MainWindow.show_message (t_("Select a glyph to create an alternate for.")); + return; + } + + gc = (!) glyph_collection; listener = new TextListener (t_("Glyph name"), "", t_("Add")); @@ -190,19 +205,15 @@ OverView overview = MainWindow.get_overview (); font = BirdFont.get_current_font (); - - if (alternate_name == "" || gc.is_unassigned ()) { - MainWindow.tabs.close_display (this); - return; - } - + if (font.glyph_name.has_key (alternate_name)) { MainWindow.show_message (t_("All glyphs must have unique names.")); } else { alt = new GlyphCollection.with_glyph ('\0', alternate_name); alt.set_unassigned (true); font.add_new_alternate (gc, alt, tag); - MainWindow.tabs.close_display (this); + update_rows (); + GlyphCanvas.redraw (); MainWindow.get_overview ().update_item_list (); overview.open_glyph_signal (alt); } @@ -212,7 +223,8 @@ GlyphCollection replacement = (!) replacement_glyph; Font f = BirdFont.get_current_font (); f.add_alternate (gc.get_name (), replacement.get_name (), tag); - MainWindow.tabs.close_display (this); + update_rows (); + GlyphCanvas.redraw (); } else { TabContent.show_text_input (listener); }
--- a/libbirdfont/OverviewTools.vala +++ b/libbirdfont/OverviewTools.vala @@ -279,15 +279,16 @@ public void add_new_alternate (Tool tool) { OverView o = MainWindow.get_overview (); OverViewItem oi = o.selected_item; - GlyphCollection gc; + GlyphCollection? gc; tool.set_selected (false); - if (oi.glyphs == null || ((!) oi.glyphs).is_unassigned ()) { - return; + gc = (!) oi.glyphs; + + if (oi.glyphs != null && ((!) oi.glyphs).is_unassigned ()) { + gc = null; } - gc = (!) oi.glyphs; MainWindow.tabs.add_tab (new OtfFeatureTable (gc)); }
--- a/libbirdfont/SpacingClass.vala +++ b/libbirdfont/SpacingClass.vala @@ -39,6 +39,11 @@ public void set_next () { update_first = false; update (next); + } + + public void update_class (string value, bool first) { + update_first = first; + update (value); } void update (string val) { @@ -48,7 +53,7 @@ string v = text; if (v.has_prefix ("U+") || v.has_prefix ("u+")) { - v = (!) Font.to_unichar (val).to_string (); + v = ((!) Font.to_unichar (val).to_string ()).dup (); } if (update_first) {
--- a/libbirdfont/SpacingClassTab.vala +++ b/libbirdfont/SpacingClassTab.vala @@ -20,12 +20,26 @@ public static int NEW_CLASS = -1; Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); + public static SpacingClass current_class; + public static bool current_class_first_element; public SpacingClassTab () { + current_class = new SpacingClass ("", ""); } public override Gee.ArrayList<Row> get_rows () { return rows; + } + + public static void set_class (string glyph) { + print(@"G: $(glyph)\n"); + if (current_class_first_element) { + current_class.first = glyph; + } else { + current_class.next = glyph; + } + + MainWindow.get_spacing_class_tab ().update_rows (); } public override void selected_row (Row row, int column, bool delete_button) { @@ -51,11 +65,15 @@ warning (@"Index: $(row.get_index ()) classes.size: $(spacing.classes.size)"); return; } - spacing.classes.get (row.get_index ()).set_first (); + current_class = spacing.classes.get (row.get_index ()); + current_class.set_first (); + current_class_first_element = true; font.touch (); } else if (column == 2) { return_if_fail (0 <= row.get_index () < spacing.classes.size); - spacing.classes.get (row.get_index ()).set_next (); + current_class = spacing.classes.get (row.get_index ()); + current_class.set_next (); + current_class_first_element = false; font.touch (); } }
--- /dev/null +++ b/libbirdfont/SpacingClassTools.vala @@ -1,1 +1,67 @@ + /* + Copyright (C) 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 + published by the Free Software Foundation; either version 3 of the + License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + */ + + using Cairo; + using Math; + + namespace BirdFont { + + public class SpacingClassTools : ToolCollection { + public static Gee.ArrayList<Expander> expanders; + + public SpacingClassTools () { + expanders = new Gee.ArrayList<Expander> (); + + Expander font_name = new Expander (); + font_name.add_tool (new FontName ()); + + Expander spacing_class_tools = new Expander (); + Tool insert = new Tool ("insert_glyph_from_overview_in_spacing_class", t_("Insert glyph from overview")); + + insert.set_icon ("insert_glyph_from_overview"); + + insert.select_action.connect ((self) => { + GlyphSelection glyph_selection = new GlyphSelection (); + + glyph_selection.selected_glyph.connect ((glyph_collection) => { + SpacingClassTab.set_class (glyph_collection.get_name ()); + MainWindow.get_tab_bar ().select_tab_name ("SpacingClasses"); + }); + + GlyphCanvas.set_display (glyph_selection); + self.set_selected (false); + + TabContent.hide_text_input (); + }); + spacing_class_tools.add_tool (insert); + + expanders.add (font_name); + + expanders.add (spacing_class_tools); + } + + public override Gee.ArrayList<Expander> get_expanders () { + return expanders; + } + + public override Gee.ArrayList<string> get_displays () { + Gee.ArrayList<string> d = new Gee.ArrayList<string> (); + d.add ("SpacingClasses"); + return d; + } + + } + + }
--- a/libbirdfont/SpacingData.vala +++ b/libbirdfont/SpacingData.vala @@ -69,7 +69,7 @@ add_connections (s.next); } } - + if (s.next == glyph) { if (!has_connection (s.first)) { add_connections (s.first);
--- a/libbirdfont/Toolbox.vala +++ b/libbirdfont/Toolbox.vala @@ -27,6 +27,7 @@ public static OverviewTools overview_tools; public static BackgroundTools background_tools; public static SpacingTools spacing_tools; + public static SpacingClassTools spacing_class_tools; public static FileTools file_tools; public static ThemeTools theme_tools; @@ -64,6 +65,7 @@ overview_tools = new OverviewTools (); background_tools = new BackgroundTools (); spacing_tools = new SpacingTools (); + spacing_class_tools = new SpacingClassTools (); file_tools = new FileTools (); theme_tools = new ThemeTools (); @@ -74,6 +76,7 @@ tool_sets.add (kerning_tools); tool_sets.add (preview_tools); tool_sets.add (overview_tools); + tool_sets.add (spacing_class_tools); tool_sets.add (background_tools); // the menu has all the file_tools commands, it will not be added here tool_sets.add (hidden_tools); // tools without a button @@ -123,6 +126,8 @@ current_set = (ToolCollection) overview_tools; } else if (tab_name == "Backgrounds") { current_set = (ToolCollection) background_tools; + } else if (tab_name == "SpacingClasses") { + current_set = (ToolCollection) spacing_class_tools; } else if (tab_name == "Themes") { current_set = (ToolCollection) theme_tools; } else if (t != null && ((!) t).get_display () is GlyphTab) {