Clone in a terminal:
Commit ed4a3e8
Johan Mattsson - 2015-09-29T11:51:38+00:00
ed4a3e8de25e9131356ddebbaad0e842d71b5397johan.mattsson.m@gmail.com

Select replacement glyph in OTF feature tab All alternate glyphs and the glyph that will replaced is referenced by name (not unicode).

Changed files (6)

Diff

diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex 454f71c..5241295 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -192,12 +192,12 @@ class BirdFontFile : GLib.Object {  	public void write_alternates (DataOutputStream os) throws GLib.Error { 		foreach (Alternate alternate in font.alternates.alternates) {-			string character = @"$(Font.to_hex (alternate.character))";+			string glyph_name = alternate.glyph_name; 			string tag = alternate.tag; 			 			foreach (string alt in alternate.alternates) { 				os.put_string (@"<alternate ");-				os.put_string (@"character=\"$character\" ");+				os.put_string (@"glyph=\"$glyph_name\" "); 				os.put_string (@"alternate=\"$alt\" "); 				os.put_string (@"tag=\"$(tag)\" />\n"); 			}@@ -832,13 +832,13 @@ class BirdFontFile : GLib.Object { 	} 	 	public void parse_alternate (Tag tag) {-		unichar character = '\0';+		string glyph_name = ""; 		string alt = ""; 		string alt_tag = ""; 		 		foreach (Attribute attribute in tag.get_attributes ()) {-			if (attribute.get_name () == "character") {-				character = Font.to_unichar (attribute.get_content ());+			if (attribute.get_name () == "glyph") {+				glyph_name = unserialize (attribute.get_content ()); 			} 			 			if (attribute.get_name () == "alternate") {@@ -850,7 +850,7 @@ class BirdFontFile : GLib.Object { 			} 		} 		-		font.add_alternate (character, alt, alt_tag);+		font.add_alternate (glyph_name, alt, alt_tag); 	} 	 	public void parse_format (Tag tag) {diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex 6b2d414..03aed28 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -186,11 +186,11 @@ public class Font : GLib.Object { 		font_deleted (); 	} -	public Alternate? get_alternate (unichar character, string tag) {+	public Alternate? get_alternate (string glyph_name, string tag) { 		Gee.ArrayList<Alternate> alt = alternates.get_alt (tag); 		 		foreach (Alternate a in alt) {-			if (a.character == character) {+			if (a.glyph_name == glyph_name) { 				return a; 			} 		}@@ -202,10 +202,10 @@ public class Font : GLib.Object { 		GlyphCollection alternate, string tag) {  		Alternate  a;-		Alternate? alt = get_alternate (glyph.get_unicode_character (), tag);+		Alternate? alt = get_alternate (glyph.get_name (), tag); 		 		if (alt == null) {-			a = new Alternate (glyph.get_unicode_character (), tag);+			a = new Alternate (glyph.get_name (), tag); 			alternates.add (a); 		} else { 			a = (!) alt;@@ -216,14 +216,14 @@ public class Font : GLib.Object { 		glyph_cache.insert (alternate.get_name (), alternate); 	} -	public void add_alternate (unichar character, string alternate, +	public void add_alternate (string glyph_name, string alternate,  		string tag) { 			 		Alternate  a;-		Alternate? alt = get_alternate (character, tag);+		Alternate? alt = get_alternate (glyph_name, tag); 		 		if (alt == null) {-			a = new Alternate (character, tag);+			a = new Alternate (glyph_name, tag); 			alternates.add (a); 		} else { 			a = (!) alt;diff --git a/libbirdfont/OpenFontFormat/Alternate.vala b/libbirdfont/OpenFontFormat/Alternate.valaindex d42d09c..9dbdd0c 100644--- a/libbirdfont/OpenFontFormat/Alternate.vala+++ b/libbirdfont/OpenFontFormat/Alternate.vala@@ -16,18 +16,18 @@ namespace BirdFont {  public class Alternate : GLib.Object { 	-	public unichar character;+	public string glyph_name; 	public Gee.ArrayList<string> alternates; 	public string tag; 	-	public Alternate (unichar character, string tag) {-		this.character = character;+	public Alternate (string glyph_name, string tag) {+		this.glyph_name = glyph_name; 		this.alternates = new Gee.ArrayList<string> (); 		this.tag = tag; 	} -	public void add (string glyph_name) {-		alternates.add (glyph_name);+	public void add (string alternate_name) {+		alternates.add (alternate_name); 	} 	 	public void remove (GlyphCollection g) {@@ -45,7 +45,7 @@ public class Alternate : GLib.Object { 	} 	 	public Alternate copy () {-		Alternate n = new Alternate (character, tag);+		Alternate n = new Alternate (glyph_name, tag);  		foreach (string s in alternates) { 			n.add (s);diff --git a/libbirdfont/OpenFontFormat/AlternateFeature.vala b/libbirdfont/OpenFontFormat/AlternateFeature.valaindex 062a25b..bd2428b 100644--- a/libbirdfont/OpenFontFormat/AlternateFeature.vala+++ b/libbirdfont/OpenFontFormat/AlternateFeature.vala@@ -29,7 +29,7 @@ public class AlternateFeature : GLib.Object { 		alternates.sort ((a, b) => { 			Alternate alt1 = (Alternate) a; 			Alternate alt2 = (Alternate) b;-			return strcmp ((!) alt1.character.to_string (), (!) alt2.character.to_string ());+			return strcmp (alt1.glyph_name, alt2.glyph_name); 		}); 	} 	@@ -89,7 +89,7 @@ public class AlternateFeature : GLib.Object { 		fd.add_ushort (1); // format 		fd.add_ushort ((uint16) alternates.size); // coverage array length 		foreach (Alternate alternate in alternates) {-			string glyph_name = (!) alternate.character.to_string ();+			string glyph_name = alternate.glyph_name; 			fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name)); 		} 		diff --git a/libbirdfont/OtfFeatureTable.vala b/libbirdfont/OtfFeatureTable.valaindex a66c82f..7ee8b87 100644--- a/libbirdfont/OtfFeatureTable.vala+++ b/libbirdfont/OtfFeatureTable.vala@@ -22,8 +22,11 @@ public class OtfFeatureTable : Table { 	 	static const int NONE = 0; 	static const int OTF_FEATURE = 1;+	static const int SOURCE_GLYPH = 2; // the glyph to replace+	static const int REPLACEMENT_GLYPH = 3; 	 	GlyphCollection glyph_collection;+	GlyphCollection? replacement_glyph = null; 	string alternate_name = ""; 	TextListener listener; 	@@ -36,7 +39,27 @@ public class OtfFeatureTable : Table { 	}  	public override void selected_row (Row row, int column, bool delete_button) {-		if (row.get_index () == OTF_FEATURE) {+		int row_index = row.get_index ();+		+		if (row_index == SOURCE_GLYPH) {+			GlyphSelection gs = new GlyphSelection ();+			+			gs.selected_glyph.connect ((gc) => {+				glyph_collection = gc;		+				MainWindow.get_tab_bar ().select_tab_name (get_name ());+			});+			+			GlyphCanvas.set_display (gs);+		} else if (row_index == REPLACEMENT_GLYPH) {+			GlyphSelection gs = new GlyphSelection ();+			+			gs.selected_glyph.connect ((gc) => {+				replacement_glyph = gc;		+				MainWindow.get_tab_bar ().select_tab_name (get_name ());+			});+			+			GlyphCanvas.set_display (gs);+		} else if (row_index == OTF_FEATURE) { 			String s = (String) row.get_row_data (); 			add_new_alternate (s.data); 		}@@ -50,9 +73,19 @@ public class OtfFeatureTable : Table { 		row = new Row.headline (t_("OTF Features")); 		rows.add (row); 		-		row = new Row.columns_1 (t_("Glyph") + ": " + glyph_collection.get_name (), NONE, false);+		row = new Row.columns_1 (t_("Glyph") + ": " + glyph_collection.get_name (), SOURCE_GLYPH, false); 		rows.add (row);-					+		+		string replacement = t_("New glyph");+		+		if (replacement_glyph != null) {+			GlyphCollection gc = (!) replacement_glyph;+			replacement = gc.get_name ();+		}+		+		row = new Row.columns_1 (t_("Replacement") + ": " + replacement, REPLACEMENT_GLYPH, false);+		rows.add (row);+ 		// FIXME: reuse parts of this for fractions etc. 	 		row = new Row.headline (t_("Tag"));@@ -122,7 +155,15 @@ public class OtfFeatureTable : Table { 			} 		}); 		-		TabContent.show_text_input (listener);+		if (replacement_glyph != null) {+			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);+		} else {+			TabContent.show_text_input (listener);+		}+		 	} } diff --git a/libbirdfont/OverView.vala b/libbirdfont/OverView.valaindex d13f133..3108315 100644--- a/libbirdfont/OverView.vala+++ b/libbirdfont/OverView.vala@@ -450,7 +450,7 @@ public class OverView : FontDisplay { 	 	int get_items_per_row () { 		int i = 1;-		double tab_with = allocation.width;+		double tab_with = allocation.width - 30; // 30 px for the scroll bar 		OverViewItem.margin = OverViewItem.width * 0.1; 		double l = OverViewItem.margin + OverViewItem.full_width (); 		

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112