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.
Merge branch 'master' of github.com:johanmattssonm/birdfont
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 public static double current_master_size; 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 Expander multi_master = new Expander (t_("Multi-Master")); 44 45 expanders = new Gee.ArrayList<Expander> (); 46 custom_character_sets = new Gee.ArrayList<LabelTool> (); 47 48 font_name.add_tool (new FontName ()); 49 50 zoom_bar = new ZoomBar (); 51 zoom_bar.new_zoom.connect ((z) => { 52 get_overview ().set_zoom (z); 53 }); 54 zoom_expander.add_tool (zoom_bar); 55 56 all_glyphs = new LabelTool (t_("All Glyphs")); 57 all_glyphs.has_counter = true; 58 all_glyphs.select_action.connect ((self) => { 59 OverView overview = get_overview (); 60 overview.display_all_available_glyphs (); 61 update_overview_characterset (overview); 62 FontDisplay.dirty_scrollbar = true; 63 }); 64 character_sets.add_tool (all_glyphs); 65 66 default_glyphs = new LabelTool (t_("Default")); 67 default_glyphs.has_counter = true; 68 default_glyphs.select_action.connect ((self) => { 69 OverView overview = get_overview (); 70 GlyphRange gr = new GlyphRange (); 71 DefaultCharacterSet.use_default_range (gr); 72 overview.set_current_glyph_range (gr); 73 update_overview_characterset (overview); 74 FontDisplay.dirty_scrollbar = true; 75 }); 76 character_sets.add_tool (default_glyphs); 77 78 unicode = new LabelTool (t_("Unicode")); 79 unicode.has_counter = true; 80 unicode.select_action.connect ((self) => { 81 OverView overview = get_overview (); 82 GlyphRange gr = new GlyphRange (); 83 DefaultCharacterSet.use_full_unicode_range (gr); 84 overview.set_current_glyph_range (gr); 85 update_overview_characterset (overview); 86 FontDisplay.dirty_scrollbar = true; 87 }); 88 character_sets.add_tool (unicode); 89 90 character_sets.set_persistent (true); 91 character_sets.set_unique (false); 92 93 skew = new SpinButton ("skew_overview", t_("Skew")); 94 skew.set_big_number (true); 95 skew.set_int_value ("0.000"); 96 skew.set_int_step (1); 97 skew.set_min (-100); 98 skew.set_max (100); 99 skew.show_icon (true); 100 skew.set_persistent (false); 101 skew.new_value_action.connect ((self) => { 102 resize.set_value_round (100, false, false); 103 }); 104 transform_expander.add_tool (skew); 105 106 resize = new SpinButton ("resize_overview", t_("Resize")); 107 resize.set_big_number (true); 108 resize.set_int_value ("0.000"); 109 resize.set_int_step (1); 110 resize.set_min (0); 111 resize.set_max (300); 112 resize.show_icon (true); 113 resize.set_persistent (false); 114 resize.new_value_action.connect ((self) => { 115 skew.set_value_round (0, false, false); 116 }); 117 transform_expander.add_tool (resize); 118 119 Tool transform = new Tool ("transform", t_("Transform")); 120 transform.select_action.connect ((self) => { 121 FontSettings fs = BirdFont.get_current_font ().settings; 122 123 fs.set_setting ("skew_overview", @"$(skew.get_value ())"); 124 transform.selected = false; 125 126 process_transform (); 127 128 BirdFont.get_current_font ().touch (); 129 }); 130 transform.selected = false; 131 transform.set_persistent (false); 132 transform_expander.add_tool (transform); 133 134 Tool alternate = new Tool ("alternate", t_("Create alternate")); 135 alternate.select_action.connect (add_new_alternate); 136 glyph_expander.add_tool (alternate); 137 138 Tool curve_orientation = new Tool ("curve_orientation", t_("Set curve orientation")); 139 curve_orientation.select_action.connect ((self) => { 140 Task t = new Task (fix_curve_orientation); 141 142 MainWindow.run_blocking_task (t); 143 144 IdleSource idle = new IdleSource (); 145 idle.set_callback (() => { 146 self.set_selected (false); 147 BirdFont.get_current_font ().touch (); 148 return false; 149 }); 150 idle.attach (null); 151 }); 152 glyph_expander.add_tool (curve_orientation); 153 154 SpinButton master_size; 155 current_master_size = 0; 156 master_size = new SpinButton ("master_size", t_("Master Size")); /// Master refers to a glyph master in a multi-master font. 157 master_size.set_big_number (false); 158 master_size.set_int_value ("0.000"); 159 master_size.set_int_step (1); 160 master_size.set_min (-1); 161 master_size.set_max (1); 162 master_size.show_icon (true); 163 master_size.set_persistent (false); 164 master_size.new_value_action.connect ((self) => { 165 current_master_size = self.get_value (); 166 MainWindow.get_overview ().update_item_list (); 167 GlyphCanvas.redraw (); 168 }); 169 multi_master.add_tool (master_size); 170 171 Tool create_new_master = new Tool ("new_master", t_("Create new master font")); /// Master is a master in a multi-master font. 172 create_new_master.select_action.connect (create_master); 173 multi_master.add_tool (create_new_master); 174 175 expanders.add (font_name); 176 expanders.add (zoom_expander); 177 expanders.add (character_sets); 178 expanders.add (transform_expander); 179 expanders.add (glyph_expander); 180 181 if (BirdFont.has_argument ("--test")) { 182 expanders.add (multi_master); 183 } 184 } 185 186 void create_master () { 187 Font font = BirdFont.get_current_font (); 188 int i = 0; 189 GlyphCollection glyph_collection; 190 GlyphCollection? gc = font.get_glyph_collection_index (i); 191 Glyph g; 192 193 while (gc != null) { 194 glyph_collection = (!) gc; 195 196 // FIXME: MASTER NAME 197 GlyphMaster master = new GlyphMaster.for_id("Master 2"); 198 g = glyph_collection.get_interpolated (current_master_size); 199 master.add_glyph(g); 200 glyph_collection.add_master (master); 201 glyph_collection.set_selected_master (master); 202 203 i++; 204 gc = font.get_glyph_collection_index (i); 205 } 206 207 MainWindow.get_overview ().update_item_list (); 208 GlyphCanvas.redraw (); 209 } 210 211 void fix_curve_orientation () { 212 OverView o; 213 Glyph g; 214 OverView.OverViewUndoItem ui; 215 216 o = get_overview (); 217 ui = new OverView.OverViewUndoItem (); 218 219 Font f = BirdFont.get_current_font (); 220 ui.alternate_sets = f.alternates.copy (); 221 222 foreach (GlyphCollection gc in o.selected_items) { 223 if (gc.length () > 0) { 224 g = gc.get_current (); 225 ui.glyphs.add (gc.copy_deep ()); 226 g.add_help_lines (); 227 g.fix_curve_orientation (); 228 } 229 } 230 231 o.undo_items.add (ui); 232 GlyphCanvas.redraw (); 233 } 234 235 public void add_new_alternate (Tool tool) { 236 OverView o = MainWindow.get_overview (); 237 OverViewItem oi = o.selected_item; 238 GlyphCollection gc; 239 240 tool.set_selected (false); 241 242 if (oi.glyphs == null || ((!) oi.glyphs).is_unassigned ()) { 243 return; 244 } 245 246 gc = (!) oi.glyphs; 247 MainWindow.tabs.add_tab (new OtfFeatureTable (gc)); 248 } 249 250 public void process_transform () { 251 OverView o; 252 Glyph g; 253 OverView.OverViewUndoItem ui; 254 255 o = get_overview (); 256 ui = new OverView.OverViewUndoItem (); 257 258 Font f = BirdFont.get_current_font (); 259 ui.alternate_sets = f.alternates.copy (); 260 261 foreach (GlyphCollection gc in o.selected_items) { 262 if (gc.length () > 0) { 263 g = gc.get_current (); 264 ui.glyphs.add (gc.copy_deep ()); 265 g.add_help_lines (); 266 267 if (skew.get_value () != 0) { 268 DrawingTools.resize_tool.skew_glyph (g, -skew.get_value (), 0, false); 269 } 270 271 if (resize.get_value () != 100) { 272 double scale = resize.get_value () / 100; 273 DrawingTools.resize_tool.resize_glyph (g, scale, false); 274 } 275 } 276 } 277 278 o.undo_items.add (ui); 279 GlyphCanvas.redraw (); 280 } 281 282 public OverView get_overview () { 283 FontDisplay fd = MainWindow.get_current_display (); 284 285 if (fd is OverView || fd is GlyphSelection) { 286 return (OverView) fd; 287 } 288 289 warning ("Current tab is not overview."); 290 291 return new OverView (); 292 } 293 294 public static void show_all_available_characters () { 295 all_glyphs.select_action (all_glyphs); 296 } 297 298 public static void update_overview_characterset (OverView? tab = null) { 299 GlyphRange gr; 300 uint size; 301 OverView overview; 302 303 // All characters 304 size = BirdFont.get_current_font ().length (); 305 all_glyphs.number = get_display_value (size); 306 307 // Default 308 gr = new GlyphRange (); 309 DefaultCharacterSet.use_default_range (gr); 310 size = gr.get_length (); 311 default_glyphs.number = get_display_value (size); 312 313 // Unicode 314 gr = new GlyphRange (); 315 DefaultCharacterSet.use_full_unicode_range (gr); 316 size = gr.get_length (); 317 unicode.number = get_display_value (size); 318 319 overview = (tab == null) ? MainWindow.get_overview () : (!) tab; 320 321 // set selected item 322 all_glyphs.set_selected (false); 323 default_glyphs.set_selected (false); 324 unicode.set_selected (false); 325 326 if (overview.all_available) { 327 all_glyphs.set_selected (true); 328 } else if (overview.glyph_range.name == "Default") { 329 default_glyphs.set_selected (true); 330 } else if (overview.glyph_range.name == "Unicode") { 331 unicode.set_selected (true); 332 } 333 334 Toolbox.redraw_tool_box (); 335 } 336 337 static string get_display_value (uint size) { 338 double k; 339 string display_size; 340 341 if (size >= 1000) { 342 k = size / 1000.0; 343 size = (uint) Math.rint (k); 344 display_size = @"$(size)k"; 345 } else { 346 display_size = @"$(size)"; 347 } 348 349 return display_size; 350 } 351 352 public override Gee.ArrayList<Expander> get_expanders () { 353 return expanders; 354 } 355 356 public override Gee.ArrayList<string> get_displays () { 357 Gee.ArrayList<string> d = new Gee.ArrayList<string> (); 358 d.add ("Overview"); 359 return d; 360 } 361 } 362 363 } 364