The Birdfont Source Code
User defined guides
These changes was commited to the Birdfont repository Sat, 07 Mar 2015 18:24:20 +0000.
Contributing
Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
User defined guides
--- a/libbirdfont/BirdFontFile.vala
+++ b/libbirdfont/BirdFontFile.vala
@@ -351,6 +351,11 @@
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 @@
}
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);
@@ -1030,6 +1039,21 @@
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);
}
}
}
--- a/libbirdfont/Font.vala
+++ b/libbirdfont/Font.vala
@@ -55,6 +55,9 @@
/** Bottom margin */
public double bottom_limit;
+
+ /** Custom guides. */
+ public Gee.ArrayList<Line> custom_guides = new Gee.ArrayList<Line> ();
public string? font_file = null;
--- a/libbirdfont/Glyph.vala
+++ b/libbirdfont/Glyph.vala
@@ -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 @@
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 @@
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 () {
@@ -2144,8 +2149,34 @@
}
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);
}
}
}
--- a/libbirdfont/Line.vala
+++ b/libbirdfont/Line.vala
@@ -23,7 +23,7 @@
public bool dashed { get; set; }
- string label;
+ public string label;
bool vertical;
string metrics;
--- a/libbirdfont/Menu.vala
+++ b/libbirdfont/Menu.vala
@@ -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
@@ -249,6 +249,13 @@
show_menu = false;
});
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 (() => {