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.
Merge branch 'master' of https://github.com/johanmattssonm/birdfont into HEAD
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 TabContent.hide_text_input (); 53 } else if (row.get_index () == NEW_LIGATURE && column == 1) { 54 if (BirdFont.has_argument ("--test")) { 55 add_contextual_ligature (t_("beginning"), t_("middle"), t_("end")); 56 TabContent.hide_text_input (); 57 } 58 } else if (row.has_row_data ()) { 59 i = row.get_index (); 60 cl = (ContextualLigature) ((!) row.get_row_data ()); 61 62 if (delete_button) { 63 cl.remove_ligature_at (i); 64 } else if (column == 0) { 65 cl.set_ligature (i); 66 } else if (column == 2) { 67 cl.set_substitution (i); 68 } 69 } else if (row.get_index () < ligatures.count ()) { 70 if (ligatures.count () != 0) { 71 if (delete_button) { 72 return_if_fail (0 <= row.get_index () < ligatures.count ()); 73 ligatures.remove_at (row.get_index ()); 74 TabContent.hide_text_input (); 75 } else if (column == 0) { 76 return_if_fail (0 <= row.get_index () < ligatures.count ()); 77 ligatures.set_ligature (row.get_index ()); 78 } else if (column == 2) { 79 return_if_fail (0 <= row.get_index () < ligatures.count ()); 80 ligatures.set_substitution (row.get_index ()); 81 } 82 } 83 } else { 84 i = row.get_index () - ligatures.count (); 85 if (i < ligatures.count_contextual_ligatures ()) { 86 return_if_fail (0 <= i < ligatures.count_contextual_ligatures ()); 87 if (delete_button) { 88 ligatures.remove_contextual_ligatures_at (i); 89 TabContent.hide_text_input (); 90 } else if (column == 0) { 91 ligatures.set_beginning (i); 92 } else if (column == 1) { 93 ligatures.set_middle (i); 94 } else if (column == 2) { 95 ligatures.set_end (i); 96 } else if (column == 3) { 97 ligatures.add_substitution_at (i); 98 } 99 } 100 } 101 102 update_rows (); 103 update_scrollbar (); 104 font.touch (); 105 } 106 107 public override void update_rows () { 108 int i; 109 Font font = BirdFont.get_current_font (); 110 Ligatures ligatures = font.get_ligatures (); 111 Row row; 112 113 rows.clear (); 114 if (BirdFont.has_argument ("--test")) { 115 row = new Row.columns_2 (t_("New Ligature"), t_("New Contextual Substitution"), NEW_LIGATURE, false); 116 rows.add (row); 117 } else { 118 row = new Row.columns_1 (t_("New Ligature"), NEW_LIGATURE, false); 119 rows.add (row); 120 } 121 122 i = 0; 123 ligatures.get_ligatures ((subst, liga) => { 124 row = new Row.columns_3 (liga, "", subst, i); 125 rows.add (row); 126 i++; 127 }); 128 129 ligatures.get_contextual_ligatures ((liga) => { 130 int j; 131 132 row = new Row.columns_4 (liga.backtrack, liga.input, liga.lookahead, 133 t_("Add Ligature"), i); 134 rows.add (row); 135 136 j = 0; 137 foreach (Ligature l in liga.ligatures) { 138 row = new Row.columns_3 (l.ligature, "", l.substitution, j); 139 row.set_row_data (liga); 140 rows.add (row); 141 j++; 142 } 143 144 i++; 145 }); 146 147 GlyphCanvas.redraw (); 148 } 149 150 public override string get_label () { 151 return t_("Ligatures"); 152 } 153 154 public override string get_name () { 155 return "Ligatures"; 156 } 157 } 158 159 } 160