The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Use unicode sequences in ligature tab

These changes was commited to the Birdfont repository Fri, 03 Oct 2014 21:45:14 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 03 Oct 2014 21:45:14 +0000 (23:45 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 03 Oct 2014 21:45:38 +0000 (23:45 +0200)
commit 4f37a5c69c669ff6bf8b186eaa4f71361a742388
tree 97f87e76dda09b2211d349c2c7c2bbc268748602
parent 9754e01cc240e24576c9f4f14e640bd1f5ae10ce
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.

birdfont/GtkWindow.vala
libbirdfont/BirdFontFile.vala
libbirdfont/LigatureList.vala
libbirdfont/Ligatures.vala
libbirdfont/OpenFontFormat/GsubTable.vala
libbirdfont/OpenFontFormat/LigatureSet.vala
--- a/birdfont/GtkWindow.vala +++ b/birdfont/GtkWindow.vala @@ -764,10 +764,10 @@ 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 @@ 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 ();
--- a/libbirdfont/BirdFontFile.vala +++ b/libbirdfont/BirdFontFile.vala @@ -125,7 +125,6 @@ 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 @@ 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 @@ 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 @@ 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);
--- a/libbirdfont/LigatureList.vala +++ b/libbirdfont/LigatureList.vala @@ -48,14 +48,14 @@ 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 ()); } }
--- a/libbirdfont/Ligatures.vala +++ b/libbirdfont/Ligatures.vala @@ -30,7 +30,7 @@ // 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,32 +130,13 @@ 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; }); } } }
--- a/libbirdfont/OpenFontFormat/GsubTable.vala +++ b/libbirdfont/OpenFontFormat/GsubTable.vala @@ -81,15 +81,24 @@ 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;
--- a/libbirdfont/OpenFontFormat/LigatureSet.vala +++ b/libbirdfont/OpenFontFormat/LigatureSet.vala @@ -35,12 +35,23 @@ } 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 @@ 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 @@ 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;