Clone in a terminal:
Commit 09a32df
Johan Mattsson - 2015-03-23T15:24:24+00:00
09a32dfd62349ed96d8e552181081e9eb819a168johan.mattsson.m@gmail.com

Multiple subtables of contextual ligatures

Changed files (5)

Diff

diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex aaec547..eff3e78 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -97,7 +97,7 @@ public class Font : GLib.Object { 	 	public Gee.ArrayList<Glyph> deleted_glyphs; -	Ligatures ligatures_substitution;+	public Ligatures ligature_substitution; 	 	public static string? default_license = null;  	@@ -135,7 +135,7 @@ public class Font : GLib.Object { 		bfp_file = new BirdFontPart (this); 		 		deleted_glyphs = new Gee.ArrayList<Glyph> ();-		ligatures_substitution = new Ligatures (this);+		ligature_substitution = new Ligatures (this); 		 		background_images = new Gee.ArrayList<BackgroundImage> (); 		@@ -148,7 +148,7 @@ public class Font : GLib.Object { 	}  	public Ligatures get_ligatures () {-		return ligatures_substitution;+		return ligature_substitution; 	}  	public void set_weight (string w) {diff --git a/libbirdfont/OpenFontFormat/ContextualLigature.vala b/libbirdfont/OpenFontFormat/ContextualLigature.valaindex 7bd2a7b..7baaf21 100644--- a/libbirdfont/OpenFontFormat/ContextualLigature.vala+++ b/libbirdfont/OpenFontFormat/ContextualLigature.vala@@ -39,6 +39,81 @@ public class ContextualLigature : GLib.Object { 		 		return ligature_list; 	}+	+	public FontData get_data (GlyfTable glyf_table) {+		FontData fd = new FontData ();+		+		Gee.ArrayList<string> backtrack = GsubTable.get_names (backtrack);+		Gee.ArrayList<string> input = GsubTable.get_names (input);+		Gee.ArrayList<string> lookahead = GsubTable.get_names (lookahead);+		+		// FIXME: add ligatures+		+		uint16 lookahead_offset, input_offset, backtrack_offset;+		+		fd.add_ushort (3); // format identifier+		+		backtrack_offset = 14 + (uint16) (lookahead.size * 2) + (uint16) (input.size * 2) + (uint16) (backtrack.size * 2);+		fd.add_ushort ((uint16) backtrack.size); // backtrack glyph count+		for (uint16 i = 0; i < backtrack.size; i++) {+			fd.add_ushort (backtrack_offset + 6 * i); // array of offsets to coverage table+		}+		+		input_offset = 14 + (uint16) (lookahead.size * 2) + (uint16) (input.size * 2)  + (uint16) (backtrack.size * (2 + 6));+		fd.add_ushort ((uint16) input.size); // input glyph count (middle)+		for (uint16 i = 0; i < input.size; i++) {+			fd.add_ushort (input_offset + 6 * i); // array of offsets to coverage table+		}+		+		lookahead_offset = 14 + (uint16) (lookahead.size * 2) + (uint16) (input.size * (2 + 6)) + (uint16) (backtrack.size * (2 + 6));+		fd.add_ushort ((uint16) lookahead.size); // lookahead glyph count+		for (uint16 i = 0; i < lookahead.size; i++) {+			fd.add_ushort (lookahead_offset + 6 * i); // array of offsets to coverage table+		}+		+		fd.add_ushort (1); // substitute count+		// substitution lookup records+		fd.add_ushort (0); // glyph sequence index for the character that will be substituted +		fd.add_ushort (1); // go to the ligature substitution via lookup table++		// backtrack coverage table1+		if (fd.length_with_padding () != backtrack_offset) {+			warning (@"Wrong backtrack offset: $backtrack_offset != $(fd.length_with_padding ())");+		}+		+		// gid array +		foreach (string glyph_name in backtrack) {+			fd.add_ushort (1); // format+			fd.add_ushort ((uint16) backtrack.size); // coverage array length+			fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name));+		}+				+		// input coverage table1+		if (fd.length_with_padding () != input_offset) {+			warning (@"Wrong input offset: $input_offset != $(fd.length_with_padding ())");+		}+		+		// gid array +		foreach (string glyph_name in input) {+			fd.add_ushort (1); // format+			fd.add_ushort ((uint16) input.size); // coverage array length+			fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name));+		}++		// lookahead coverage table1+		if (fd.length_with_padding () != lookahead_offset) {+			warning (@"Wrong lookahead offset: $lookahead_offset != $(fd.length_with_padding ())");+		}	++		// gid array +		foreach (string glyph_name in lookahead) {+			fd.add_ushort (1); // format+			fd.add_ushort ((uint16) lookahead.size); // coverage array length+			fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name));+		}+		+		return fd;+	} }  }diff --git a/libbirdfont/OpenFontFormat/ContextualLigatureSet.vala b/libbirdfont/OpenFontFormat/ContextualLigatureSet.valaindex aae011f..b7d0470 100644--- a/libbirdfont/OpenFontFormat/ContextualLigatureSet.vala+++ b/libbirdfont/OpenFontFormat/ContextualLigatureSet.vala@@ -31,12 +31,11 @@ public class ContextualLigatureSet : GLib.Object { 	} 	 	void add_contextual_ligatures () {-		ContextualLigature ligature ;-		LigatureSet s;+		Font font = BirdFont.get_current_font ();+		Ligatures ligatures = font.ligature_substitution; 		-		if (BirdFont.has_argument ("--test")) {-			ligature = new ContextualLigature ("ralt", "a", "r", "t t");-			ligature_context.add (ligature);+		foreach (ContextualLigature c in ligatures.contextual_ligatures) {+			ligature_context.add (c); 		} 	} }diff --git a/libbirdfont/OpenFontFormat/GsubTable.vala b/libbirdfont/OpenFontFormat/GsubTable.valaindex 0a83ec8..852364a 100644--- a/libbirdfont/OpenFontFormat/GsubTable.vala+++ b/libbirdfont/OpenFontFormat/GsubTable.vala@@ -100,7 +100,13 @@ public class GsubTable : OtfTable { 			fd.add_ushort (4); // offset to lookup 1  		} 		-		uint16 lookups_end = lookups * 8;+		uint16 lookups_end;+		+		lookups_end = lookups * 8;+		if (contextual.has_ligatures ()) {+			lookups_end += 2 * ((uint16) contextual.ligature_context.size - 1);+		}+		 		length = 0; 		fd.add_ushort (4); // lookup type  		fd.add_ushort (0); // lookup flags@@ -119,13 +125,19 @@ public class GsubTable : OtfTable {  			fd.add_ushort (6); // lookup type  			fd.add_ushort (0); // lookup flags-			fd.add_ushort (1); // number of subtables-			fd.add_ushort (lookups_end + length); // array of offsets to subtable-			length += (uint16) chained_context.length_with_padding ();-			lookups_end -= 8;+			fd.add_ushort ((uint16) contextual.ligature_context.size); // number of subtables FIXME: 1?+			+			foreach (ContextualLigature c in contextual.ligature_context) {+				fd.add_ushort (lookups_end + length); // array of offsets to subtable+				length += (uint16) c.get_data (glyf_table).length_with_padding ();+			}+			+			lookups_end -= 7 + 2 * contextual.ligature_context.size; 		} 		-		warn_if_fail (lookups_end == 0);+		if (lookups_end == 0) {+			warning ("Wring offset to end of lookups.");+		} 		 		fd.append (clig_subtable); 		@@ -183,79 +195,13 @@ public class GsubTable : OtfTable {  	// chaining contextual substitution format3 	FontData get_chaining_contextual_substition_subtable (ContextualLigatureSet contexts) throws GLib.Error {-		FontData fd = new FontData ();+		FontData fd_all = new FontData (); 		 		foreach (ContextualLigature context in contexts.ligature_context) {-			-			Gee.ArrayList<string> backtrack = get_names (context.backtrack);-			Gee.ArrayList<string> input = get_names (context.input);-			Gee.ArrayList<string> lookahead = get_names (context.lookahead);-			-			uint16 lookahead_offset, input_offset, backtrack_offset;-			-			fd.add_ushort (3); // format identifier-			-			backtrack_offset = 14 + (uint16) (lookahead.size * 2) + (uint16) (input.size * 2) + (uint16) (backtrack.size * 2);-			fd.add_ushort ((uint16) backtrack.size); // backtrack glyph count-			for (uint16 i = 0; i < input.size; i++) {-				fd.add_ushort (backtrack_offset + 6 * i); // array of offsets to coverage table-			}-			-			input_offset = 14 + (uint16) (lookahead.size * 2) + (uint16) (input.size * 2)  + (uint16) (backtrack.size * (2 + 6));-			fd.add_ushort ((uint16) input.size); // input glyph count (middle)-			for (uint16 i = 0; i < input.size; i++) {-				fd.add_ushort (input_offset + 6 * i); // array of offsets to coverage table-			}-			-			lookahead_offset = 14 + (uint16) (lookahead.size * 2) + (uint16) (input.size * (2 + 6)) + (uint16) (backtrack.size * (2 + 6));-			fd.add_ushort ((uint16) lookahead.size); // lookahead glyph count-			for (uint16 i = 0; i < lookahead.size; i++) {-				fd.add_ushort (lookahead_offset + 6 * i); // array of offsets to coverage table-			}-			-			fd.add_ushort (1); // substitute count-			// substitution lookup records-			fd.add_ushort (0); // glyph sequence index-			fd.add_ushort (1); // go to the ligature substitution via lookup table--			// backtrack coverage table1-			if (fd.length_with_padding () != backtrack_offset) {-				warning (@"Wrong backtrack offset: $backtrack_offset != $(fd.length_with_padding ())");-			}-			-			// gid array -			foreach (string glyph_name in backtrack) {-				fd.add_ushort (1); // format-				fd.add_ushort ((uint16) backtrack.size); // coverage array length-				fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name));-			}-					-			// input coverage table1-			if (fd.length_with_padding () != input_offset) {-				warning (@"Wrong input offset: $input_offset != $(fd.length_with_padding ())");-			}-			-			// gid array -			foreach (string glyph_name in input) {-				fd.add_ushort (1); // format-				fd.add_ushort ((uint16) input.size); // coverage array length-				fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name));-			}--			// lookahead coverage table1-			if (fd.length_with_padding () != lookahead_offset) {-				warning (@"Wrong lookahead offset: $lookahead_offset != $(fd.length_with_padding ())");-			}--			// gid array -			foreach (string glyph_name in lookahead) {-				fd.add_ushort (1); // format-				fd.add_ushort ((uint16) lookahead.size); // coverage array length-				fd.add_ushort ((uint16) glyf_table.get_gid (glyph_name));-			}+			fd_all.append (context.get_data (glyf_table)); // FIXME: remove.. 		} 		-		return fd;+		return fd_all; 	} 	 	void parse_ligatures (FontData fd, int table_start) {diff --git a/libbirdfont/OpenFontFormat/LigatureSetList.vala b/libbirdfont/OpenFontFormat/LigatureSetList.valaindex ae4d757..285a4ce 100644--- a/libbirdfont/OpenFontFormat/LigatureSetList.vala+++ b/libbirdfont/OpenFontFormat/LigatureSetList.vala@@ -49,10 +49,13 @@ public class LigatureSetList : GLib.Object {  	void add_contextual_ligatures (GlyfTable glyf_table, ContextualLigatureSet ligatures) { 		foreach (ContextualLigature c in ligatures.ligature_context) {-			add_ligatures (glyf_table, "r", c.ligatures); // FIXME: parts = ""+			foreach (string l in c.ligatures.strip ().split (" ")) {+				add_ligatures (glyf_table, "r", l); // FIXME: parts = ""+			} 		} 	}-	++	// multiple ligatures in non-contextual substitution 	// FIXME: what if parts equals "" ? Which set does ligatures becomes a part of? 	public void add_ligatures (GlyfTable glyf_table, string characters, string ligatures)  		requires (!is_null (lig_set) && !is_null (last_set)) {

Contact

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