Commit 825067c
User defined guides
Changed files (5)
modifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/Font.valamodifiedlibbirdfont/Glyph.valamodifiedlibbirdfont/Line.valamodifiedlibbirdfont/Menu.vala
Diff
@@ -351,6 +351,11 @@ class BirdFontFile : GLib.Object { os.put_string (@"\t<base_line>$(round (font.base_line))</base_line>\n"); os.put_string (@"\t<bottom_position>$(round (font.bottom_position))</bottom_position>\n"); os.put_string (@"\t<bottom_limit>$(round (font.bottom_limit))</bottom_limit>\n");+ + foreach (Line guide in BirdFont.get_current_font ().custom_guides) {+ os.put_string (@"\t<custom_guide label=\"$(guide.label)\">$(round (guide.pos))</custom_guide>\n");+ }+ os.put_string ("</horizontal>\n"); } @@ -1007,6 +1012,10 @@ class BirdFontFile : GLib.Object { } private void parse_horizontal_lines (Tag tag) {+ Line line;+ string label;+ double position;+ foreach (Tag t in tag) { if (t.get_name () == "top_limit" && t.get_content () != "") { font.top_limit = parse_double_from_node (t);@@ -1031,6 +1040,21 @@ class BirdFontFile : GLib.Object { if (t.get_name () == "bottom_limit" && t.get_content () != "") { font.bottom_limit = parse_double_from_node (t); }+ + if (t.get_name () == "custom_guide" && t.get_content () != "") {+ position = parse_double_from_node (t);+ + label = "";+ foreach (Attribute attr in t.get_attributes ()) {+ if (attr.get_name () == "label") {+ label = attr.get_content ();+ }+ }+ + line = new Line (label, position);+ + BirdFont.get_current_font ().custom_guides.add (line);+ } } } @@ -56,6 +56,9 @@ public class Font : GLib.Object { /** Bottom margin */ public double bottom_limit; + /** Custom guides. */+ public Gee.ArrayList<Line> custom_guides = new Gee.ArrayList<Line> ();+ public string? font_file = null; bool modified = false;@@ -1,5 +1,5 @@ /*- Copyright (C) 2012 2013 2014 Johan Mattsson+ Copyright (C) 2012 2013 2014 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 @@ -79,6 +79,7 @@ public class Glyph : FontDisplay { bool show_help_lines = true; bool xheight_lines_visible = false; bool margin_boundaries_visible = false;+ string new_guide_name = ""; Gee.ArrayList<Glyph> undo_list = new Gee.ArrayList<Glyph> (); Gee.ArrayList<Glyph> redo_list = new Gee.ArrayList<Glyph> ();@@ -495,6 +496,10 @@ public class Glyph : FontDisplay { add_line (bottom_margin_line); bottom_margin_line.set_visible (margin_boundaries_visible);+ + foreach (Line guide in BirdFont.get_current_font ().custom_guides) {+ add_line (guide);+ } } public double get_left_side_bearing () {@@ -2145,6 +2150,32 @@ public class Glyph : FontDisplay { return glyph_cache.get (font_size); }+ + public void add_custom_guide () {+ TextListener listener;+ + listener = new TextListener (t_("Guide"), "", t_("Add"));+ + listener.signal_text_input.connect ((text) => {+ new_guide_name = text;+ });+ + listener.signal_submit.connect (() => {+ Line guide;+ double position;+ + position = path_coordinate_y (allocation.height / 2.0);+ guide = new Line (new_guide_name, position);+ horizontal_help_lines.add (guide);+ + BirdFont.get_current_font ().custom_guides.add (guide);+ + MainWindow.native_window.hide_text_input ();+ GlyphCanvas.redraw ();+ });+ + MainWindow.native_window.set_text_listener (listener);+ } } }@@ -23,7 +23,7 @@ public class Line : GLib.Object { public bool dashed { get; set; } - string label;+ public string label; bool vertical; string metrics; @@ -1,5 +1,5 @@ /*- Copyright (C) 2014 Johan Mattsson+ Copyright (C) 2014 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 @@ -250,6 +250,13 @@ public class Menu : GLib.Object { }); edit_menu.items.add (remove_background_glyph); + MenuItem create_guide = add_menu_item (t_("Create Guide"), "create guide");+ create_guide.action.connect (() => {+ MainWindow.get_current_glyph ().add_custom_guide ();+ show_menu = false;+ });+ edit_menu.items.add (create_guide);+ MenuItem select_point_above = add_menu_item (t_("Select Point Above"), "select point above"); select_point_above.action.connect (() => { PenTool.select_point_up ();