The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Fix ligature substitutions with space

These changes was commited to the Birdfont repository Sat, 12 Dec 2015 08:27:40 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Sat, 12 Dec 2015 08:27:40 +0000]

Updated Files

libbirdfont/OpenFontFormat/Ligature.vala
libbirdfont/OpenFontFormat/LigatureCollection.vala
libbirdfont/OpenFontFormat/LigatureSet.vala
--- a/libbirdfont/OpenFontFormat/Ligature.vala +++ b/libbirdfont/OpenFontFormat/Ligature.vala @@ -24,7 +24,38 @@ } public unichar get_first_char () { - return substitution.get (0); + unichar first; + int index = 0; + + get_coverage (substitution).get_next_char (ref index, out first); + + return first; + } + + public static string get_coverage (string ligatures) { + string[] sp; + unichar first; + int index = 0; + string characters = ligatures; + + if (characters.has_prefix ("U+") || characters.has_prefix ("u+")) { + sp = characters.split (" "); + return_val_if_fail (sp.length > 0, ""); + characters = (!) Font.to_unichar (sp[0]).to_string (); + } + sp = characters.split (" "); + + if (sp.length == 0) { + return ""; + } + + if (sp[0] == "space") { + sp[0] = " "; + } + + sp[0].get_next_char (ref index, out first); + + return (!) first.to_string (); } public void set_ligature () {
--- a/libbirdfont/OpenFontFormat/LigatureCollection.vala +++ b/libbirdfont/OpenFontFormat/LigatureCollection.vala @@ -64,7 +64,11 @@ if (l.has_prefix ("U+") || l.has_prefix ("u+")) { l = (!) Font.to_unichar (l).to_string (); } - + + if (l == "space") { + l = " "; + } + if (!font.has_glyph (l)) { warning (@"Ligature $l does not correspond to a glyph in this font."); return; @@ -73,6 +77,10 @@ foreach (string p in parts) { if (p.has_prefix ("U+") || p.has_prefix ("u+")) { p = (!) Font.to_unichar (p).to_string (); + } + + if (p == "space") { + p = " "; } if (!font.has_glyph (p)) { @@ -105,7 +113,21 @@ ligature_sets.sort ((a, b) => { LigatureSet la = (LigatureSet) a; LigatureSet lb = (LigatureSet) b; - return (int) (la.get_coverage_char ().get_char () - lb.get_coverage_char ().get_char ()); + string ca, cb; + + if (la.get_coverage_char () == "space") { + ca = " "; + } else { + ca = la.get_coverage_char (); + } + + if (lb.get_coverage_char () == "space") { + cb = " "; + } else { + cb = lb.get_coverage_char (); + } + + return strcmp (ca, cb); }); }
--- a/libbirdfont/OpenFontFormat/LigatureSet.vala +++ b/libbirdfont/OpenFontFormat/LigatureSet.vala @@ -30,28 +30,17 @@ if (ligatures.size == 0) { return false; } - + return ligatures.get (0).substitution.has_prefix (s); } public string get_coverage_char () { - string s; - string[] sp; - if (ligatures.size == 0) { warning ("No ligatures in set."); return ""; } - 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 (); + return Ligature.get_coverage (ligatures.get (0).substitution); } public FontData get_set_data () throws GLib.Error { @@ -89,6 +78,10 @@ l = ligature.ligature.strip (); if (l.has_prefix ("U+") || l.has_prefix ("u+")) { l = (!) Font.to_unichar (l).to_string (); + } + + if (l == "space") { + l = " "; } gid = glyf_table.get_gid (l); @@ -108,6 +101,10 @@ p = (!) Font.to_unichar (p).to_string (); } + if (p == "space") { + p = " "; + } + gid = (uint16) glyf_table.get_gid (p); if (gid == -1) {