The Birdfont Source Code


All Repositories / birdfont.git / commitdiff – RSS feed

Export kerning pairs from kerning classes

These changes was commited to the Birdfont repository Mon, 13 Apr 2015 21:48:22 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
[Mon, 13 Apr 2015 21:48:22 +0000]

Updated Files

libbirdfont/KerningClasses.vala
libbirdfont/OpenFontFormat/KerningPair.vala
--- a/libbirdfont/KerningClasses.vala +++ b/libbirdfont/KerningClasses.vala @@ -230,32 +230,37 @@ string f = ""; string n = ""; GlyphRange gf, gn; - + GlyphRange gr; + GlyphRange gl; + int len; + foreach (string l in get_spacing_class (first)) { foreach (string r in get_spacing_class (next)) { - f = GlyphRange.serialize (l); + f = GlyphRange.serialize (f); n = GlyphRange.serialize (r); if (single_kerning.has_key (@"$f - $n")) { return true; } } } - - gf = new GlyphRange (); - gn = new GlyphRange (); - try { - gf.parse_ranges (f); - gn.parse_ranges (n); - } catch (MarkupError e) { - warning (e.message); - } + len = (int) classes_first.size; - if (!(gf.is_class () || gn.is_class ())) { - return false; + return_val_if_fail (len == classes_last.size, false); + return_val_if_fail (len == classes_kerning.size, false); + + for (int i = len - 1; i >= 0; i--) { + gl = classes_first.get (i); + gr = classes_last.get (i); + + if (gl.has_character (first) + && gr.has_character (next)) { + + return true; + } } - return get_kerning_item_index (gf, gn) != -1; + return false; } public double get_kerning_for_range (GlyphRange range_first, GlyphRange range_last) { @@ -272,7 +277,7 @@ return 0; } - for (int i = len - 1; i >= 0; i--) { + for (int i = len - 1; i >= 0; i--) { // last class is applied first l = classes_first.get (i); r = classes_last.get (i); @@ -422,12 +427,20 @@ warning ("Map is protected."); return; } + foreach (string key in single_kerning.keys) { print (key); print ("\t\t"); print (@"$((!) single_kerning.get (key))\n"); } + set_protect_map (false); + + print ("\n"); + print ("Generated table:\n"); + all_pairs ((k) => { + k.print (); + }); } public void get_classes (KerningClassIterator kerningIterator) { @@ -521,6 +534,8 @@ foreach (UniRange u in r.ranges) { for (unichar c = u.start; c <= u.stop; c++) { right = (!)c.to_string (); + + print (@"has? $(character.get_name ()) $right $( has_kerning (character.get_name (), right))\n"); if (font.has_glyph (right) && has_kerning (character.get_name (), right)) { kerning = get_kerning (character.get_name (), right); @@ -540,6 +555,7 @@ // 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); + print (@"has? $(character.get_name ()) $right_glyph_name $( has_kerning (character.get_name (), right_glyph_name))\n"); 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); @@ -553,20 +569,20 @@ if (kl.kerning.size == 0) { warning (@"No kerning pairs for character: $((kl.character.get_name ()))"); } - - + kl.sort (); } // obtain the kerning value foreach (KerningPair p in pairs) { + p.print (); kerningIterator (p); } } private bool set_protect_map (bool p) { if (unlikely (p && protect_map)) { - warning ("Map is already protected, this is a criticl error."); + warning ("Map is already protected."); return false; }
--- a/libbirdfont/OpenFontFormat/KerningPair.vala +++ b/libbirdfont/OpenFontFormat/KerningPair.vala @@ -44,8 +44,20 @@ next = (Kerning) b; return strcmp (((!)first.glyph).get_unichar_string (), ((!)next.glyph).get_unichar_string ()); }); + } + + public void print () { + if (kerning.size == 0) { + warning ("No pairs."); + } + + foreach (Kerning k in kerning) { + if (k.glyph != null) { + stdout.printf (@"$(character.get_name ()) <-> $(((!) k.glyph).get_name ()): $(k.val)\n"); + } + } } } }