Clone in a terminal:
Commit 9754e01
Johan Mattsson - 2014-10-03T20:37:35+00:00
9754e01cc240e24576c9f4f14e640bd1f5ae10cejohan.mattsson.m@gmail.com

Add ligatures to the bf file format.

Changed files (2)

Diff

diff --git a/libbirdfont/BirdFontFile.vala b/libbirdfont/BirdFontFile.valaindex 5f63ab9..82637f3 100644--- a/libbirdfont/BirdFontFile.vala+++ b/libbirdfont/BirdFontFile.vala@@ -137,13 +137,8 @@ class BirdFontFile : GLib.Object { 				os.put_string (@"</images>\n"); 				os.put_string ("\n"); 			}-		-			// FIXME: no need to iterate over all glyphs twise+			 			font.glyph_cache.for_each ((gc) => {-				if (is_null (gc)) {-					warning ("No glyph collection");-				}-				 				try { 					write_glyph_collection (gc, os); 				} catch (GLib.Error e) {@@ -153,6 +148,9 @@ class BirdFontFile : GLib.Object { 				TooltipArea.show_text (t_("Saving")); 			}); 			+			os.put_string ("\n");+			write_ligatures (os);+			 			font.glyph_cache.for_each ((gc) => { 				BackgroundImage bg; 				@@ -663,7 +661,11 @@ class BirdFontFile : GLib.Object { 			if (t.get_name () == "spacing") { 				parse_spacing_class (t); 			}-									++			if (t.get_name () == "ligature") {+				parse_ligature (t);+			}+												 			TooltipArea.show_text (t_("Loading XML data.")); 		} @@ -683,6 +685,12 @@ class BirdFontFile : GLib.Object { 		} 	} +	public static string serialize_attribute (string s) {+		string n = s.replace ("\"", "quote");+		n = n.replace ("&", "ampersand");+		return n;+	}+ 	public static string unserialize (string s) { 		StringBuilder b; 		string r;@@ -1348,6 +1356,39 @@ class BirdFontFile : GLib.Object { 		 		img.set_position (img.img_x, img.img_y);	 	}+	+	public void write_ligatures (DataOutputStream os) {+		Ligatures ligatures = font.get_ligatures ();+		+		try {+			ligatures.get_ligatures ((subst, liga) => {+				string l = serialize_attribute (liga);+				string s = serialize_attribute (subst);+				os.put_string ("<ligature sequence=\"$(s)\" replacement=\"$(l)\"/>\n");+			});+		} catch (GLib.Error e) {+			warning (e.message);+		}+	}+	+	public void parse_ligature (Tag t) {+		string sequence = "";+		string ligature = "";+		Ligatures ligatures;+		+		foreach (Attribute a in t.get_attributes ()) {+			if (a.get_name () == "sequence") {+				sequence = a.get_content ();+			}++			if (a.get_name () == "replacement") {+				ligature = a.get_content ();+			}+		}+		+		ligatures = font.get_ligatures ();+		ligatures.add_ligature (sequence, ligature);+	} }  }diff --git a/libbirdfont/BirdFontPart.vala b/libbirdfont/BirdFontPart.valaindex 2fceb0a..0947e4e 100644--- a/libbirdfont/BirdFontPart.vala+++ b/libbirdfont/BirdFontPart.vala@@ -199,6 +199,12 @@ public class BirdFontPart : GLib.Object{ 			bf.write_closing_root_tag (os); 			os.close (); +			os = create_file ("ligatures.bfp");+			bf.write_root_tag (os);+			bf.write_ligatures (os);+			bf.write_closing_root_tag (os);+			os.close ();+			 			font.glyph_cache.for_each ((gc) => { 				try { 					string selected_file_name;

Contact

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