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
Circle boundaries heads/master
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 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 (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 int ncontextual; 49 50 ncontextual = ligatures.contextual_ligatures.size; 51 52 if (row.get_index () == NEW_LIGATURE && column == 0) { 53 add_ligature (t_("character sequence"), t_("ligature")); 54 TabContent.hide_text_input (); 55 } else if (row.get_index () == NEW_LIGATURE && column == 1) { 56 add_contextual_ligature (t_("substitution"), t_("beginning"), t_("middle"), t_("end")); 57 TabContent.hide_text_input (); 58 } else if (row.get_index () < ncontextual) { 59 i = row.get_index (); 60 if (i < ligatures.count_contextual_ligatures ()) { 61 return_if_fail (0 <= i < ligatures.count_contextual_ligatures ()); 62 if (delete_button) { 63 ligatures.remove_contextual_ligatures_at (i); 64 TabContent.hide_text_input (); 65 } if (column == 0) { 66 ligatures.set_contextual_ligature (i); 67 } else if (column == 1) { 68 ligatures.set_beginning (i); 69 } else if (column == 2) { 70 ligatures.set_middle (i); 71 } else if (column == 3) { 72 ligatures.set_end (i); 73 } 74 } 75 } else if (row.get_index () >= ncontextual) { 76 i = row.get_index () - ncontextual; 77 78 if (ligatures.count () != 0) { 79 if (delete_button) { 80 return_if_fail (0 <= i < ligatures.count ()); 81 ligatures.remove_at (i); 82 TabContent.hide_text_input (); 83 } else if (column == 0) { 84 return_if_fail (0 <= i < ligatures.count ()); 85 ligatures.set_ligature (i); 86 } else if (column == 2) { 87 return_if_fail (0 <= i < ligatures.count ()); 88 ligatures.set_substitution (i); 89 } 90 } 91 } 92 93 update_rows (); 94 update_scrollbar (); 95 font.touch (); 96 } 97 98 public override void update_rows () { 99 int i; 100 Font font = BirdFont.get_current_font (); 101 Ligatures ligatures = font.get_ligatures (); 102 Row row; 103 104 rows.clear (); 105 106 row = new Row.headline (t_("Add")); 107 rows.add (row); 108 109 row = new Row.columns_2 (t_("New Ligature"), t_("New Contextual Substitution"), NEW_LIGATURE, false); 110 rows.add (row); 111 112 i = 0; 113 114 if (ligatures.contextual_ligatures.size > 0) { 115 row = new Row.headline (t_("Contextual Substitutions")); 116 rows.add (row); 117 } 118 119 ligatures.get_contextual_ligatures ((liga) => { 120 row = new Row.columns_4 (liga.ligatures, liga.backtrack, liga.input, liga.lookahead, i); 121 rows.add (row); 122 i++; 123 }); 124 125 if (ligatures.ligatures.size > 0) { 126 row = new Row.headline (t_("Ligatures")); 127 rows.add (row); 128 } 129 130 ligatures.get_ligatures ((subst, liga) => { 131 row = new Row.columns_3 (liga, "", subst, i); 132 rows.add (row); 133 i++; 134 }); 135 136 GlyphCanvas.redraw (); 137 } 138 139 public override string get_label () { 140 return t_("Ligatures"); 141 } 142 143 public override string get_name () { 144 return "Ligatures"; 145 } 146 } 147 148 } 149