The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OtfFeatureTable.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/OtfFeatureTable.vala.
Merge branch 'master' of github.com:johanmattssonm/birdfont
1 /* 2 Copyright (C) 2015 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 17 namespace BirdFont { 18 19 /** A table for managing feature tags in Open Type tables. */ 20 public class OtfFeatureTable : Table { 21 Gee.ArrayList<Row> rows = new Gee.ArrayList<Row> (); 22 23 static const int NONE = 0; 24 static const int OTF_FEATURE = 1; 25 26 GlyphCollection glyph_collection; 27 string alternate_name = ""; 28 TextListener listener; 29 30 public OtfFeatureTable (GlyphCollection gc) { 31 glyph_collection = gc; 32 } 33 34 public override Gee.ArrayList<Row> get_rows () { 35 return rows; 36 } 37 38 public override void selected_row (Row row, int column, bool delete_button) { 39 if (row.get_index () == OTF_FEATURE) { 40 String s = (String) row.get_row_data (); 41 add_new_alternate (s.data); 42 } 43 } 44 45 public override void update_rows () { 46 Row row; 47 48 rows.clear (); 49 50 row = new Row.headline (t_("OTF Features")); 51 rows.add (row); 52 53 row = new Row.columns_1 (t_("Glyph") + ": " + glyph_collection.get_name (), NONE, false); 54 rows.add (row); 55 56 // FIXME: reuse parts of this for fractions etc. 57 58 row = new Row.headline (t_("Tag")); 59 rows.add (row); 60 61 row = new Row.columns_1 (t_("Stylistic Alternate") + " (salt)", OTF_FEATURE, false); 62 row.set_row_data (new String ("salt")); 63 rows.add (row); 64 65 row = new Row.columns_1 (t_("Small Caps") + " (smcp)", OTF_FEATURE, false); 66 row.set_row_data (new String ("smcp")); 67 rows.add (row); 68 69 row = new Row.columns_1 (t_("Capitals to Small Caps") + " (c2sc)", OTF_FEATURE, false); 70 row.set_row_data (new String ("c2sc")); 71 rows.add (row); 72 73 row = new Row.columns_1 (t_("Swashes") + " (swsh)", OTF_FEATURE, false); 74 row.set_row_data (new String ("swsh")); 75 rows.add (row); 76 77 GlyphCanvas.redraw (); 78 } 79 80 public override string get_label () { 81 return t_("OTF Feature Tags"); 82 } 83 84 public override string get_name () { 85 return "OTF Feature Tags"; 86 } 87 88 public override void draw (WidgetAllocation allocation, Context cr) { 89 base.draw (allocation, cr); 90 } 91 92 public void add_new_alternate (string tag) { 93 GlyphCollection gc = glyph_collection; 94 95 listener = new TextListener (t_("Glyph name"), "", t_("Add")); 96 97 listener.signal_text_input.connect ((text) => { 98 alternate_name = text; 99 }); 100 101 listener.signal_submit.connect (() => { 102 GlyphCollection alt; 103 Font font; 104 OverView overview = MainWindow.get_overview (); 105 106 font = BirdFont.get_current_font (); 107 108 if (alternate_name == "" || gc.is_unassigned ()) { 109 MainWindow.tabs.close_display (this); 110 return; 111 } 112 113 if (font.glyph_name.has_key (alternate_name)) { 114 MainWindow.show_message (t_("All glyphs must have unique names.")); 115 } else { 116 alt = new GlyphCollection.with_glyph ('\0', alternate_name); 117 alt.set_unassigned (true); 118 font.add_new_alternate (gc, alt, tag); 119 MainWindow.tabs.close_display (this); 120 MainWindow.get_overview ().update_item_list (); 121 overview.open_glyph_signal (alt); 122 } 123 }); 124 125 TabContent.show_text_input (listener); 126 } 127 } 128 129 } 130