The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Fix ligature substitution in spaving and kerning tab

These changes was commited to the Birdfont repository Wed, 25 Mar 2015 19:54:02 +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>
Wed, 25 Mar 2015 19:54:02 +0000 (20:54 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Wed, 25 Mar 2015 19:54:02 +0000 (20:54 +0100)
commit fd63e9b4179887adf9d6061ccb8677bb0ac853d8
tree ba042dea1e9858a003f50ef4971a12c0120d5efd
parent 068054100b01fbba90eba9b42a74945181bcddf4
Fix ligature substitution in spaving and kerning tab

libbirdfont/Font.vala
libbirdfont/GlyphSequence.vala
--- a/libbirdfont/Font.vala +++ b/libbirdfont/Font.vala @@ -845,6 +845,14 @@ foreach (string p in parts) { if (p.has_prefix ("U+") || p.has_prefix ("u+")) { p = (!) to_unichar (p).to_string (); + } + + if (p == "space") { + p = " "; + } + + if (p == "divis") { + p = " "; } if (!has_glyph (p)) {
--- a/libbirdfont/GlyphSequence.vala +++ b/libbirdfont/GlyphSequence.vala @@ -69,13 +69,14 @@ if (has_range) { return ligature_sequence; } + + ligatures = font.get_ligatures (); foreach (ContextualLigature c in ligatures.contextual_ligatures) { ligature_sequence.replace_contextual (c.get_backtrack (), c.get_input (), c.get_lookahead (), c.get_ligature_sequence ()); } - ligatures = font.get_ligatures (); ligatures.get_single_substitution_ligatures ((substitute, ligature) => { ligature_sequence.replace (substitute, ligature); }); @@ -92,7 +93,7 @@ int i = 0; while (i < glyph.size) { if (starts_with (old, i)) { - substitute (i, old.glyph.size, replacement); + glyph = substitute (i, old.glyph.size, replacement); i += replacement.length (); } else { i++; @@ -100,17 +101,28 @@ } } - void replace_contextual (GlyphSequence backtrack, GlyphSequence input, GlyphSequence lookahead, GlyphSequence replacement) { + void replace_contextual (GlyphSequence backtrack, GlyphSequence input, GlyphSequence lookahead, + GlyphSequence replacement) { + bool start, middle, end; int i = 0; + int advance = 0; + while (i < glyph.size) { start = starts_with (backtrack, i); middle = starts_with (input, i + backtrack.length ()); end = starts_with (lookahead, i + backtrack.length () + input.length ()); if (start && middle && end) { - substitute (i + backtrack.length (), input.length (), replacement); - i += i + backtrack.length () + input.length (); + glyph = substitute (i + backtrack.length (), input.length (), replacement); + + advance = backtrack.length () + replacement.length (); + i += advance; + + if (advance <= 0) { + warning ("No advancement."); + return; + } } else { i++; } @@ -137,7 +149,7 @@ return true; } - void substitute (uint index, uint length, GlyphSequence substitute) { + Gee.ArrayList<Glyph?> substitute (uint index, uint length, GlyphSequence substitute) { Gee.ArrayList<Glyph?> new_list = new Gee.ArrayList<Glyph?> (); int i = 0; @@ -155,9 +167,9 @@ i++; } - glyph = new_list; + return new_list; } } }