The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

LigatureList.vala in libbirdfont

This file is a part of the Birdfont project.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git

Revisions

View the latest version of libbirdfont/LigatureList.vala.
Add contextual ligatures to the GUI and fix directory privileges
1 /* 2 Copyright (C) 2014 Johan Mattsson 3 4 This library is free software; you can redistribute it and/or modify 5 it under the terms of the GNU Lesser General Public License as 6 published by the Free Software Foundation; either version 3 of the 7 License, or (at your option) any later version. 8 9 This library is distributed in the hope that it will be useful, but 10 WITHOUT ANY WARRANTY; without even the implied warranty of 11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 12 Lesser General Public License for more details. 13 */ 14 15 using Cairo; 16 using Math; 17 18 namespace BirdFont { 19 20 public class LigatureList : Table { 21 Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); 22 23 public const int NEW_LIGATURE = -1; 24 25 public LigatureList () { 26 } 27 28 public override Gee.ArrayList<Row> get_rows () { 29 return rows; 30 } 31 32 void add_contextual_ligature (string backtrack, string input, string lookahead) { 33 Font font = BirdFont.get_current_font (); 34 Ligatures ligatures = font.get_ligatures (); 35 ligatures.add_contextual_ligature (backtrack, input, lookahead); 36 } 37 38 void add_ligature (string subst, string liga) { 39 Font font = BirdFont.get_current_font (); 40 Ligatures ligatures = font.get_ligatures (); 41 ligatures.add_ligature (subst, liga); 42 } 43 44 public override void selected_row (Row row, int column, bool delete_button) { 45 Font font = BirdFont.get_current_font (); 46 Ligatures ligatures = font.get_ligatures (); 47 int i; 48 ContextualLigature cl; 49 50 if (row.get_index () == NEW_LIGATURE && column == 0) { 51 add_ligature (t_("character sequence"), t_("ligature")); 52 MainWindow.native_window.hide_text_input (); 53 } else if (row.get_index () == NEW_LIGATURE && column == 1) { 54 add_contextual_ligature (t_("beginning"), t_("middle"), t_("end")); 55 MainWindow.native_window.hide_text_input (); 56 } else if (row.has_row_data ()) { 57 i = row.get_index (); 58 cl = (ContextualLigature) ((!) row.get_row_data ()); 59 60 if (delete_button) { 61 cl.remove_ligature_at (i); 62 } else if (column == 0) { 63 cl.set_ligature (i); 64 } else if (column == 2) { 65 cl.set_substitution (i); 66 } 67 } else if (row.get_index () < ligatures.count ()) { 68 if (ligatures.count () != 0) { 69 if (delete_button) { 70 return_if_fail (0 <= row.get_index () < ligatures.count ()); 71 ligatures.remove_at (row.get_index ()); 72 MainWindow.native_window.hide_text_input (); 73 } else if (column == 0) { 74 return_if_fail (0 <= row.get_index () < ligatures.count ()); 75 ligatures.set_ligature (row.get_index ()); 76 } else if (column == 2) { 77 return_if_fail (0 <= row.get_index () < ligatures.count ()); 78 ligatures.set_substitution (row.get_index ()); 79 } 80 } 81 } else { 82 i = row.get_index () - ligatures.count (); 83 if (i < ligatures.count_contextual_ligatures ()) { 84 return_if_fail (0 <= i < ligatures.count_contextual_ligatures ()); 85 if (delete_button) { 86 ligatures.remove_contextual_ligatures_at (i); 87 MainWindow.native_window.hide_text_input (); 88 } else if (column == 0) { 89 ligatures.set_beginning (i); 90 } else if (column == 1) { 91 ligatures.set_middle (i); 92 } else if (column == 2) { 93 ligatures.set_end (i); 94 } else if (column == 3) { 95 ligatures.add_substitution_at (i); 96 } 97 } 98 } 99 100 update_rows (); 101 update_scrollbar (); 102 font.touch (); 103 } 104 105 public override void update_rows () { 106 int i; 107 Font font = BirdFont.get_current_font (); 108 Ligatures ligatures = font.get_ligatures (); 109 Row row; 110 111 rows.clear (); 112 row = new Row.columns_2 (t_("New Ligature"), t_("New Contextual Substitution"), NEW_LIGATURE, false); 113 rows.add (row); 114 115 i = 0; 116 ligatures.get_ligatures ((subst, liga) => { 117 row = new Row.columns_3 (liga, "", subst, i); 118 rows.add (row); 119 i++; 120 }); 121 122 ligatures.get_contextual_ligatures ((liga) => { 123 int j; 124 125 row = new Row.columns_4 (liga.backtrack, liga.input, liga.lookahead, 126 t_("Add Ligature"), i); 127 rows.add (row); 128 129 j = 0; 130 foreach (Ligature l in liga.ligatures) { 131 row = new Row.columns_3 (l.ligature, "", l.substitution, j); 132 row.set_row_data (liga); 133 rows.add (row); 134 j++; 135 } 136 137 i++; 138 }); 139 140 GlyphCanvas.redraw (); 141 } 142 143 public override string get_label () { 144 return t_("Ligatures"); 145 } 146 147 public override string get_name () { 148 return "Ligatures"; 149 } 150 } 151 152 } 153