The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

OverviewTools.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/OverviewTools.vala.
Save stylistic alternatives to bf fonts and make gsub features optional
1 /* 2 Copyright (C) 2014 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 public class OverviewTools : ToolCollection { 20 21 static LabelTool all_glyphs; 22 static LabelTool default_glyphs; 23 static LabelTool unicode; 24 25 static Gee.ArrayList<LabelTool> custom_character_sets; 26 27 public static Gee.ArrayList<Expander> expanders; 28 public ZoomBar zoom_bar; 29 30 public static Expander zoom_expander; 31 32 public static SpinButton skew; 33 public static SpinButton resize; 34 35 private string alternate_name = ""; 36 37 public OverviewTools () { 38 Expander font_name = new Expander (); 39 Expander character_sets = new Expander (t_("Character Sets")); 40 Expander zoom_expander = new Expander (t_("Zoom")); 41 Expander transform_expander = new Expander (t_("Transform")); 42 Expander glyph_expander = new Expander (t_("Glyph")); 43 44 expanders = new Gee.ArrayList<Expander> (); 45 custom_character_sets = new Gee.ArrayList<LabelTool> (); 46 47 font_name.add_tool (new FontName ()); 48 49 zoom_bar = new ZoomBar (); 50 zoom_bar.new_zoom.connect ((z) => { 51 get_overview ().set_zoom (z); 52 }); 53 zoom_expander.add_tool (zoom_bar); 54 55 all_glyphs = new LabelTool (t_("All Glyphs")); 56 all_glyphs.has_counter = true; 57 all_glyphs.select_action.connect ((self) => { 58 OverView overview = get_overview (); 59 overview.display_all_available_glyphs (); 60 update_overview_characterset (overview); 61 FontDisplay.dirty_scrollbar = true; 62 }); 63 character_sets.add_tool (all_glyphs); 64 65 default_glyphs = new LabelTool (t_("Default")); 66 default_glyphs.has_counter = true; 67 default_glyphs.select_action.connect ((self) => { 68 OverView overview = get_overview (); 69 GlyphRange gr = new GlyphRange (); 70 DefaultCharacterSet.use_default_range (gr); 71 overview.set_current_glyph_range (gr); 72 update_overview_characterset (overview); 73 FontDisplay.dirty_scrollbar = true; 74 }); 75 character_sets.add_tool (default_glyphs); 76 77 unicode = new LabelTool (t_("Unicode")); 78 unicode.has_counter = true; 79 unicode.select_action.connect ((self) => { 80 OverView overview = get_overview (); 81 GlyphRange gr = new GlyphRange (); 82 DefaultCharacterSet.use_full_unicode_range (gr); 83 overview.set_current_glyph_range (gr); 84 update_overview_characterset (overview); 85 FontDisplay.dirty_scrollbar = true; 86 }); 87 character_sets.add_tool (unicode); 88 89 character_sets.set_persistent (true); 90 character_sets.set_unique (false); 91 92 skew = new SpinButton ("skew_overview", t_("Skew")); 93 skew.set_big_number (true); 94 skew.set_int_value ("0.000"); 95 skew.set_int_step (1); 96 skew.set_min (-100); 97 skew.set_max (100); 98 skew.show_icon (true); 99 skew.set_persistent (false); 100 skew.new_value_action.connect ((self) => { 101 resize.set_value_round (100, false, false); 102 }); 103 transform_expander.add_tool (skew); 104 105 resize = new SpinButton ("resize_overview", t_("Resize")); 106 resize.set_big_number (true); 107 resize.set_int_value ("0.000"); 108 resize.set_int_step (1); 109 resize.set_min (0); 110 resize.set_max (300); 111 resize.show_icon (true); 112 resize.set_persistent (false); 113 resize.new_value_action.connect ((self) => { 114 skew.set_value_round (0, false, false); 115 }); 116 transform_expander.add_tool (resize); 117 118 Tool transform = new Tool ("transform", t_("Transform")); 119 transform.select_action.connect ((self) => { 120 FontSettings fs = BirdFont.get_current_font ().settings; 121 122 fs.set_setting ("skew_overview", @"$(skew.get_value ())"); 123 transform.selected = false; 124 125 process_transform (); 126 127 BirdFont.get_current_font ().touch (); 128 }); 129 transform.selected = false; 130 transform.set_persistent (false); 131 transform_expander.add_tool (transform); 132 133 Tool alternate = new Tool ("alternate", t_("Create alternate")); 134 alternate.select_action.connect (add_new_alternate); 135 glyph_expander.add_tool (alternate); 136 137 expanders.add (font_name); 138 expanders.add (zoom_expander); 139 expanders.add (character_sets); 140 expanders.add (transform_expander); 141 expanders.add (glyph_expander); 142 } 143 144 public void add_new_alternate (Tool tool) { 145 TextListener listener; 146 OverView o = MainWindow.get_overview (); 147 OverViewItem oi = o.selected_item; 148 GlyphCollection gc; 149 150 if (oi.glyphs == null) { 151 return; 152 } 153 154 gc = (!) oi.glyphs; 155 156 listener = new TextListener (t_("Alternate"), "", t_("Add")); 157 158 listener.signal_text_input.connect ((text) => { 159 alternate_name = text; 160 }); 161 162 listener.signal_submit.connect (() => { 163 GlyphCollection alt; 164 Font font; 165 OverView overview = MainWindow.get_overview (); 166 167 font = BirdFont.get_current_font (); 168 169 if (alternate_name == "") { 170 return; 171 } 172 173 if (font.glyph_name.has_key (alternate_name)) { 174 MainWindow.show_message (t_("All glyphs must have unique names.")); 175 } else { 176 alt = new GlyphCollection.with_glyph ('\0', alternate_name); 177 alt.set_unassigned (true); 178 font.add_new_alternate (gc, alt); 179 MainWindow.get_overview ().update_item_list (); 180 overview.open_glyph_signal (alt); 181 } 182 }); 183 184 tool.set_selected (false); 185 TabContent.show_text_input (listener); 186 } 187 188 public void process_transform () { 189 OverView o; 190 Glyph g; 191 OverView.OverViewUndoItem ui; 192 193 o = get_overview (); 194 ui = new OverView.OverViewUndoItem (); 195 196 foreach (GlyphCollection gc in o.selected_items) { 197 if (gc.length () > 0) { 198 g = gc.get_current (); 199 ui.glyphs.add (gc.copy_deep ()); 200 g.add_help_lines (); 201 202 if (skew.get_value () != 0) { 203 DrawingTools.resize_tool.skew_glyph (g, -skew.get_value (), 0, false); 204 } 205 206 if (resize.get_value () != 100) { 207 double scale = resize.get_value () / 100; 208 DrawingTools.resize_tool.resize_glyph (g, scale, false); 209 } 210 } 211 } 212 213 o.undo_items.add (ui); 214 GlyphCanvas.redraw (); 215 } 216 217 public OverView get_overview () { 218 FontDisplay fd = MainWindow.get_current_display (); 219 220 if (fd is OverView || fd is GlyphSelection) { 221 return (OverView) fd; 222 } 223 224 warning ("Current tab is not overview."); 225 226 return new OverView (); 227 } 228 229 public static void show_all_available_characters () { 230 all_glyphs.select_action (all_glyphs); 231 } 232 233 public static void update_overview_characterset (OverView? tab = null) { 234 GlyphRange gr; 235 uint size; 236 OverView overview; 237 238 // All characters 239 size = BirdFont.get_current_font ().length (); 240 all_glyphs.number = get_display_value (size); 241 242 // Default 243 gr = new GlyphRange (); 244 DefaultCharacterSet.use_default_range (gr); 245 size = gr.get_length (); 246 default_glyphs.number = get_display_value (size); 247 248 // Unicode 249 gr = new GlyphRange (); 250 DefaultCharacterSet.use_full_unicode_range (gr); 251 size = gr.get_length (); 252 unicode.number = get_display_value (size); 253 254 overview = (tab == null) ? MainWindow.get_overview () : (!) tab; 255 256 // set selected item 257 all_glyphs.set_selected (false); 258 default_glyphs.set_selected (false); 259 unicode.set_selected (false); 260 261 if (overview.all_available) { 262 all_glyphs.set_selected (true); 263 } else if (overview.glyph_range.name == "Default") { 264 default_glyphs.set_selected (true); 265 } else if (overview.glyph_range.name == "Unicode") { 266 unicode.set_selected (true); 267 } 268 269 Toolbox.redraw_tool_box (); 270 } 271 272 static string get_display_value (uint size) { 273 double k; 274 string display_size; 275 276 if (size >= 1000) { 277 k = size / 1000.0; 278 size = (uint) Math.rint (k); 279 display_size = @"$(size)k"; 280 } else { 281 display_size = @"$(size)"; 282 } 283 284 return display_size; 285 } 286 287 public override Gee.ArrayList<Expander> get_expanders () { 288 return expanders; 289 } 290 291 public override Gee.ArrayList<string> get_displays () { 292 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 293 d.add ("Overview"); 294 return d; 295 } 296 } 297 298 } 299