Commit 57eace3
Add ligature input
Changed files (3)
modifiedlibbirdfont/LigatureList.valamodifiedlibbirdfont/Ligatures.valamodifiedlibbirdfont/OpenFontFormat/Ligature.vala
Diff
@@ -40,7 +40,7 @@ public class LigatureList : Table { Ligatures ligatures = font.get_ligatures (); if (row.get_index () == NEW_LIGATURE) {- add_ligature (t_("substitute"), t_("ligature"));+ add_ligature (t_("character sequence"), t_("ligature")); MainWindow.native_window.hide_text_input (); } else if (ligatures.count () != 0) { if (delete_button) {@@ -48,14 +48,14 @@ public class LigatureList : Table { 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 ());- } else if (column == 2) {- return_if_fail (0 <= row.get_index () < ligatures.count ());- ligatures.set_substitution (row.get_index ()); } } @@ -68,13 +68,16 @@ public class LigatureList : Table { int i; Font font = BirdFont.get_current_font (); Ligatures ligatures = font.get_ligatures ();+ Row row; rows.clear ();- rows.add (new Row (t_("New Ligature"), NEW_LIGATURE, false));+ row = new Row (t_("New Ligature"), NEW_LIGATURE, false);+ rows.add (row); i = 0; ligatures.get_ligatures ((subst, liga) => {- rows.add (new Row.columns_3 (@"$subst", "->", @"$liga", i));+ row = new Row.columns_3 (@"$liga", "", @"$subst", i);+ rows.add (row); i++; }); @@ -19,8 +19,7 @@ namespace BirdFont { public class Ligatures : GLib.Object { - public Gee.ArrayList<string> ligature = new Gee.ArrayList<string> ();- public Gee.ArrayList<string> substitution = new Gee.ArrayList<string> ();+ Gee.ArrayList<Ligature> ligatures = new Gee.ArrayList<Ligature> (); public delegate void LigatureIterator (string substitution, string ligature); public delegate void SingleLigatureIterator (GlyphSequence substitution, GlyphCollection ligature);@@ -30,9 +29,9 @@ public class Ligatures : GLib.Object { // FIXME: keep ligatures sorted, long strings first public void get_ligatures (LigatureIterator iter) {- iter ("a f", "af");- iter ("f f i", "ffi");- iter ("f i", "fi"); + foreach (Ligature l in ligatures) {+ iter (l.ligature, l.substitution);+ } } public void get_single_substitution_ligatures (SingleLigatureIterator iter) {@@ -67,25 +66,94 @@ public class Ligatures : GLib.Object { } public int count () {- return ligature.size;+ return ligatures.size; } public void remove_at (int i) {- return_if_fail (0 <= i < ligature.size);- return_if_fail (0 <= i < substitution.size);- ligature.remove_at (i);- substitution.remove_at (i);+ return_if_fail (0 <= i < ligatures.size);+ ligatures.remove_at (i); } public void set_ligature (int index) {+ Ligature lig;+ TextListener listener;+ + return_if_fail (0 <= index < ligatures.size);+ + lig = ligatures.get (index);+ listener = new TextListener (t_("Ligature"), "", t_("Set"));+ + listener.signal_text_input.connect ((text) => {+ lig.ligature = text;+ });+ + listener.signal_submit.connect (() => {+ MainWindow.native_window.hide_text_input ();+ });+ + MainWindow.native_window.set_text_listener (listener); } public void set_substitution (int index) {+ Ligature lig;+ TextListener listener;+ + return_if_fail (0 <= index < ligatures.size);+ + lig = ligatures.get (index);+ listener = new TextListener (t_("Text"), "", t_("Set"));+ + listener.signal_text_input.connect ((text) => {+ lig.substitution = text;+ sort_ligatures ();+ });+ + listener.signal_submit.connect (() => {+ MainWindow.native_window.hide_text_input ();+ });+ + MainWindow.native_window.set_text_listener (listener); } public void add_ligature (string subst, string liga) {- substitution.insert (0, subst);- ligature.insert (0, liga);+ ligatures.insert (0, new Ligature (liga, subst));+ sort_ligatures ();+ }+ + void sort_ligatures () {+ print (@"\n");+ ligatures.sort ((a, b) => {+ Ligature first, next;+ bool r;+ int chars_first, chars_next;+ + first = (Ligature) a;+ next = (Ligature) b;+ + chars_first = first.substitution.char_count ();+ chars_next = next.substitution.char_count ();+ + 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;+ }); } } @@ -22,6 +22,10 @@ public class Ligature : GLib.Object { this.ligature = ligature; this.substitution = substitution; }+ + public unichar get_first_char () {+ return substitution.get (0);+ } } }