The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix kerning for ligatures

These changes was commited to the Birdfont repository Fri, 10 Oct 2014 08:50:28 +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, 10 Oct 2014 08:50:28 +0000 (10:50 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Fri, 10 Oct 2014 08:50:28 +0000 (10:50 +0200)
commit 808f5a2fac7697deb7a29b47c13933cc404309b8
tree c020c74f7f2aadbf53c47db552e045959fc3495e
parent 163bc4184167962a5658bcfc52be7c5bc8d77b0f
Fix kerning for ligatures

libbirdfont/KerningClasses.vala
libbirdfont/OpenFontFormat/GlyfTable.vala
libbirdfont/OpenFontFormat/KernList.vala
--- a/libbirdfont/KerningClasses.vala +++ b/libbirdfont/KerningClasses.vala @@ -174,6 +174,10 @@ gn.parse_ranges (n); } catch (MarkupError e) { warning (e.message); + } + + if (!(gf.is_class () || gn.is_class ())) { + return false; } return get_kerning_item_index (gf, gn) != -1; @@ -405,35 +409,35 @@ Gee.ArrayList<KerningPair> pairs = new Gee.ArrayList<KerningPair> (); double kerning; string right; + string name; + Glyph? g; // Create a list of first glyph in all pairs foreach (GlyphRange r in classes_first) { foreach (UniRange u in r.ranges) { for (unichar c = u.start; c <= u.stop; c++) { - string name = (!)c.to_string (); - Glyph? g = font.get_glyph (name); + name = (!)c.to_string (); + g = font.get_glyph (name); if (g != null && !left_glyphs.contains ((!) g)) { left_glyphs.add ((!) g); } } } - - // TODO: GlyphRange.unassigned + + foreach (string n in r.unassigned) { + g = font.get_glyph (n); + if (g != null && !left_glyphs.contains ((!) g)) { + left_glyphs.add ((!) g); + } + } } - foreach (string name in single_kerning_letters_left) { - Glyph? g = font.get_glyph (name); + foreach (string n in single_kerning_letters_left) { + g = font.get_glyph (n); if (g != null && !left_glyphs.contains ((!) g)) { left_glyphs.add ((!) g); } } - - left_glyphs.sort ((a, b) => { - Glyph first, next; - first = (Glyph) a; - next = (Glyph) b; - return strcmp (first.get_name (), next.get_name ()); - }); // add the right hand glyph and the kerning value foreach (Glyph character in left_glyphs) { @@ -445,19 +449,25 @@ for (unichar c = u.start; c <= u.stop; c++) { right = (!)c.to_string (); - if (font.has_glyph (right)) { + if (font.has_glyph (right) && has_kerning (character.get_name (), right)) { kerning = get_kerning (character.get_name (), right); kl.add_unique ((!) font.get_glyph (right), kerning); } } } - // TODO: GlyphRange.unassigned + + foreach (string n in r.unassigned) { + if (font.has_glyph (n) && has_kerning (character.get_name (), n)) { + kerning = get_kerning (character.get_name (), n); + kl.add_unique ((!) font.get_glyph (n), kerning); + } + } } - // TODO: The get_kerning () function is still rather slow. Optimize it. + // TODO: The get_kerning () function is still slow. Optimize it. foreach (string right_glyph_name in single_kerning_letters_right) { Glyph? gl = font.get_glyph (right_glyph_name); - if (gl != null) { + if (gl != null && has_kerning (character.get_name (), right_glyph_name)) { kerning = get_kerning (character.get_name (), right_glyph_name); kl.add_unique ((!) gl , kerning); }
--- a/libbirdfont/OpenFontFormat/GlyfTable.vala +++ b/libbirdfont/OpenFontFormat/GlyfTable.vala @@ -156,7 +156,7 @@ warning ("No glyphs in font."); } - // add glyphs, first all assigned then the unassigned ones + // add glyphs for (indice = 0; (gcn = font.get_glyph_collection_indice (indice)) != null; indice++) { gc = (!) gcn; g = gc.get_current ().copy ();
--- a/libbirdfont/OpenFontFormat/KernList.vala +++ b/libbirdfont/OpenFontFormat/KernList.vala @@ -64,6 +64,14 @@ gid_right = (uint16) glyf_table.get_gid (k.get_glyph ().get_name ()); current_pairs.pairs.add (new Kern (gid_left, gid_right, (int16) Math.rint (k.val * HeadTable.UNITS))); } + + current_pairs.pairs.sort ((a, b) => { + return a.right - b.right; + }); + }); + + pairs.sort ((a, b) => { + return a.left - b.left; }); return num_pairs;