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