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