Commit 4f37a5c
Use unicode sequences in ligature tab Allow the font designer to enter values on the form U+XX where XX is the unicode value in hex.
Changed files (6)
modifiedbirdfont/GtkWindow.valamodifiedlibbirdfont/BirdFontFile.valamodifiedlibbirdfont/LigatureList.valamodifiedlibbirdfont/Ligatures.valamodifiedlibbirdfont/OpenFontFormat/GsubTable.valamodifiedlibbirdfont/OpenFontFormat/LigatureSet.vala
Diff
@@ -764,10 +764,10 @@ public class GtkWindow : Gtk.Window, NativeWindow { menubar.append (tab_launcher); menubar.append (tool_launcher); menubar.append (kerning_launcher);+ menubar.append (ligature_launcher); if (BirdFont.has_argument ("--test")) { menubar.append (git_launcher);- menubar.append (ligature_launcher); } return menubar; @@ -855,7 +855,7 @@ public class GtkWindow : Gtk.Window, NativeWindow { text_box.show (); text_entry.set_text (listener.default_text); text_entry.activate.connect (() => {- listener.signal_submit (listener.default_text);+ text_listener.signal_submit (text_entry.text); text_input_is_active = false; }); text_entry.grab_focus ();@@ -125,7 +125,6 @@ class BirdFontFile : GLib.Object { write_settings (os); os.put_string ("\n");- // FIXME: add this to a font specific settings file if (font.background_images.size > 0) { os.put_string (@"<images>\n");@@ -181,6 +180,7 @@ class BirdFontFile : GLib.Object { TooltipArea.show_text (t_("Saving")); }); + os.put_string ("\n"); write_spacing_classes (os); write_kerning (os); write_closing_root_tag (os);@@ -687,7 +687,7 @@ class BirdFontFile : GLib.Object { public static string serialize_attribute (string s) { string n = s.replace ("\"", "quote");- n = n.replace ("&", "ampersand");+ n = n.replace ("&", "ampersand"); return n; } @@ -1362,9 +1362,9 @@ class BirdFontFile : GLib.Object { 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");+ string lig = serialize_attribute (liga);+ string sequence = serialize_attribute (subst);+ os.put_string (@"<ligature sequence=\"$(sequence)\" replacement=\"$(lig)\"/>\n"); }); } catch (GLib.Error e) { warning (e.message);@@ -48,14 +48,14 @@ public class LigatureList : Table { ligatures.remove_at (row.get_index ()); MainWindow.native_window.hide_text_input (); } else if (column == 0) {- return_if_fail (0 <= row.get_index () < ligatures.count ());- ligatures.set_substitution (row.get_index ());- } else if (column == 2) { if (!(0 <= row.get_index () < ligatures.count ())) { warning (@"Index: $(row.get_index ()) ligatures.count (): $(ligatures.count ())"); return; }- ligatures.set_ligature (row.get_index ());+ ligatures.set_ligature (row.get_index ()); + } else if (column == 2) {+ return_if_fail (0 <= row.get_index () < ligatures.count ());+ ligatures.set_substitution (row.get_index ()); } } @@ -30,7 +30,7 @@ public class Ligatures : GLib.Object { // FIXME: keep ligatures sorted, long strings first public void get_ligatures (LigatureIterator iter) { foreach (Ligature l in ligatures) {- iter (l.ligature, l.substitution);+ iter (l.substitution, l.ligature); } } @@ -130,29 +130,10 @@ public class Ligatures : GLib.Object { first = (Ligature) a; next = (Ligature) b; - chars_first = first.substitution.char_count ();- chars_next = next.substitution.char_count ();+ chars_first = first.substitution.split (" ").length;+ chars_next = next.substitution.split (" ").length; return chars_next - chars_first;- - if (first.get_first_char () == next.get_first_char ()) {- chars_first = first.substitution.char_count ();- chars_next = next.substitution.char_count ();- - - r = chars_first > chars_next; // DELETE- print (@"$chars_first $chars_next $(first.substitution) $(next.substitution) $(r) \n");- - if (chars_first != chars_next) {- return 0;- }- - r = chars_first > chars_next;- } else { - r = first.get_first_char () > next.get_first_char ();- }- - return (r) ? 1 : -1; }); } }@@ -81,15 +81,24 @@ public class GsubTable : OtfTable { liga_sets = new Gee.ArrayList<LigatureSet> (); lig_set = new LigatureSet (glyf_table); last_set = new LigatureSet (glyf_table);- ligatures.get_ligatures ((s, l) => {+ ligatures.get_ligatures ((s, lig) => { string[] parts = s.split (" ");- + string l = lig;++ if (l.has_prefix ("U+") || l.has_prefix ("u+")) {+ l = (!) Font.to_unichar (l).to_string ();+ }+ if (!font.has_glyph (l)) { warning (@"Ligature $l does not correspond to a glyph in this font."); return; } - foreach (string p in parts) {+ foreach (string p in parts) { + if (p.has_prefix ("U+") || p.has_prefix ("u+")) {+ p = (!) Font.to_unichar (p).to_string ();+ }+ if (!font.has_glyph (p)) { warning (@"Ligature substitution of $p is not possible, the character does have a glyph."); return;@@ -35,12 +35,23 @@ public class LigatureSet : GLib.Object { } public string get_coverage_char () {+ string s;+ string[] sp;+ if (ligatures.size == 0) { warning ("No ligatures in set."); return ""; } - return (!) ligatures.get (0).substitution.get (0).to_string ();+ s = ligatures.get (0).substitution;+ + if (s.has_prefix ("U+") || s.has_prefix ("u+")) {+ sp = s.split (" ");+ return_val_if_fail (sp.length > 0, "");+ s = (!) Font.to_unichar (sp[0]).to_string ();+ }+ + return (!) s.get (0).to_string (); } public FontData get_set_data () throws GLib.Error {@@ -71,8 +82,16 @@ public class LigatureSet : GLib.Object { void add_ligature (FontData fd, Ligature ligature) throws GLib.Error { string[] parts = ligature.substitution.split (" "); bool first = true;- int gid = glyf_table.get_gid (ligature.ligature);- + int gid;+ string l;++ l = ligature.ligature;+ if (l.has_prefix ("U+") || l.has_prefix ("u+")) {+ l = (!) Font.to_unichar (l).to_string ();+ }+ + gid = glyf_table.get_gid (l);+ if (gid == -1) { warning (@"No glyph ID for ligature $(ligature.ligature)."); gid = 0;@@ -84,8 +103,19 @@ public class LigatureSet : GLib.Object { fd.add_ushort ((uint16) parts.length); foreach (string p in parts) {+ if (p.has_prefix ("U+") || p.has_prefix ("u+")) {+ p = (!) Font.to_unichar (p).to_string ();+ }++ gid = (uint16) glyf_table.get_gid (p);++ if (gid == -1) {+ warning (@"No glyph ID for ligature $(ligature.ligature).");+ gid = 0;+ }+ if (!first) {- fd.add_ushort ((uint16) glyf_table.get_gid (p));+ fd.add_ushort ((uint16) gid); } first = false;