The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

ExportSettings.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/ExportSettings.vala.
Update icons
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 using Math; 17 18 namespace BirdFont { 19 20 public class ExportSettings : TableLayout { 21 TextArea file_name; 22 TextArea file_name_mac; 23 TextArea units_per_em; 24 CheckBox ttf; 25 CheckBox eot; 26 CheckBox svg; 27 CheckBox svg_table; 28 CheckBox colr_table; 29 Button export_action; 30 Button name_tab; 31 32 public ExportSettings () { 33 Headline headline; 34 Font font; 35 double margin = 12 * MainWindow.units; 36 double label_size = 20 * MainWindow.units; 37 double label_margin = 4 * MainWindow.units; 38 string fn, folder; 39 40 font = BirdFont.get_current_font (); 41 font.settings.set_setting ("has_export_settings", "true"); 42 43 headline = new Headline (t_("Export Settings")); 44 headline.margin_bottom = 20 * MainWindow.units; 45 widgets.add (headline); 46 47 widgets.add (new Text (t_("File Name"), label_size, label_margin)); 48 49 file_name = new LineTextArea (label_size); 50 file_name.margin_bottom = margin; 51 52 fn = get_file_name (font); 53 file_name.set_text (fn); 54 file_name.text_changed.connect ((t) => { 55 Font f = BirdFont.get_current_font (); 56 f.settings.set_setting ("file_name", t); 57 }); 58 59 widgets.add (file_name); 60 focus_ring.add (file_name); 61 62 widgets.add (new Text (t_("File Name") + " Mac", label_size, label_margin)); 63 64 file_name_mac = new LineTextArea (label_size); 65 file_name_mac.margin_bottom = margin; 66 67 fn = get_file_name_mac (font); 68 file_name_mac.set_text (fn); 69 file_name_mac.text_changed.connect ((t) => { 70 Font f = BirdFont.get_current_font (); 71 f.settings.set_setting ("file_name_mac", t); 72 }); 73 74 widgets.add (file_name_mac); 75 focus_ring.add (file_name_mac); 76 77 widgets.add (new Text (t_("Units Per Em"), label_size, label_margin)); 78 79 units_per_em = new LineTextArea (label_size); 80 units_per_em.margin_bottom = margin; 81 82 units_per_em.set_text (@"$(font.units_per_em)"); 83 units_per_em.text_changed.connect ((t) => { 84 Font f = BirdFont.get_current_font (); 85 int u = int.parse (t); 86 if (u > 0) { 87 f.units_per_em = u; 88 f.touch (); 89 } 90 }); 91 92 widgets.add (units_per_em); 93 focus_ring.add (units_per_em); 94 95 folder = ExportTool.get_export_folder (); 96 Text folder_row = new Text (t_("Folder") + ": " + folder, label_size, label_margin); 97 folder_row.margin_bottom = 20 * MainWindow.units; 98 widgets.add (folder_row); 99 100 widgets.add (new Text (t_("Formats"), label_size, label_margin)); 101 102 CheckBox otf = new CheckBox ("OTF", label_size); 103 104 otf.updated.connect ((c) => { 105 if (c) { 106 MessageDialog dialog; 107 dialog = MainWindow.show_message (t_("You need the plus version to export OTF fonts.")); 108 MainWindow.show_dialog (dialog); 109 110 otf.checked = false; 111 } 112 }); 113 114 otf.checked = false; 115 116 widgets.add (otf); 117 focus_ring.add (otf); 118 119 ttf = new CheckBox ("TTF", label_size); 120 ttf.updated.connect ((c) => { 121 Font f = BirdFont.get_current_font (); 122 string v = c ? "true" : "false"; 123 f.settings.set_setting ("export_ttf", v); 124 }); 125 ttf.checked = export_ttf_setting (font); 126 widgets.add (ttf); 127 focus_ring.add (ttf); 128 129 eot = new CheckBox ("EOT", label_size); 130 eot.updated.connect ((c) => { 131 Font f = BirdFont.get_current_font (); 132 string v = c ? "true" : "false"; 133 f.settings.set_setting ("export_eot", v); 134 }); 135 eot.checked = export_eot_setting (font); 136 widgets.add (eot); 137 focus_ring.add (eot); 138 139 svg = new CheckBox ("SVG", label_size); 140 svg.updated.connect ((c) => { 141 Font f = BirdFont.get_current_font (); 142 string v = c ? "true" : "false"; 143 f.settings.set_setting ("export_svg", v); 144 }); 145 svg.checked = export_svg_setting (font); 146 svg.margin_bottom = margin; 147 widgets.add (svg); 148 focus_ring.add (svg); 149 150 svg.margin_bottom = 20 * MainWindow.units; 151 152 widgets.add (new Text (t_("Color Tables"), label_size, label_margin)); 153 154 svg_table = new CheckBox (t_("Embedded SVG table"), label_size); 155 svg_table.checked = false; 156 157 svg_table.updated.connect ((c) => { 158 show_plus_version_needed_for_color_tables(); 159 svg_table.checked = false; 160 }); 161 162 widgets.add (svg_table); 163 focus_ring.add (svg_table); 164 165 colr_table = new CheckBox (t_("COLR and CPAL tables"), label_size); 166 colr_table.checked = false; 167 168 colr_table.updated.connect ((c) => { 169 show_plus_version_needed_for_color_tables(); 170 colr_table.checked = false; 171 }); 172 173 widgets.add (colr_table); 174 focus_ring.add (colr_table); 175 176 colr_table.margin_bottom = 20 * MainWindow.units; 177 178 name_tab = new Button (t_("Name and Description"), margin); 179 name_tab.action.connect ((c) => { 180 MenuTab.show_description (); 181 }); 182 widgets.add (name_tab); 183 184 export_action = new Button (t_("Export"), margin); 185 export_action.action.connect ((c) => { 186 MenuTab.export_fonts_in_background (); 187 }); 188 widgets.add (export_action); 189 190 set_focus (file_name); 191 } 192 193 public static string get_file_name (Font font) { 194 string n = font.settings.get_setting ("file_name"); 195 196 if (n == "") { 197 n = font.full_name; 198 } 199 200 return n; 201 } 202 203 public static string get_file_name_mac (Font font) { 204 string n = font.settings.get_setting ("file_name_mac"); 205 206 if (n == "") { 207 n = font.full_name + " Mac"; 208 } 209 210 return n; 211 } 212 213 public static bool export_ttf_setting (Font f) { 214 return f.settings.get_setting ("export_ttf") != "false"; 215 } 216 217 public static bool export_eot_setting (Font f) { 218 return f.settings.get_setting ("export_eot") != "false"; 219 } 220 221 public static bool export_svg_setting (Font f) { 222 return f.settings.get_setting ("export_svg") != "false"; 223 } 224 225 public static bool has_export_settings (Font f) { 226 return f.settings.get_setting ("has_export_settings") == "true"; 227 } 228 229 public override string get_label () { 230 return t_("Export Settings"); 231 } 232 233 public override string get_name () { 234 return "Export Settings"; 235 } 236 237 public void paste (string text) { 238 if (0 <= focus_index < focus_ring.size) { 239 Widget widget = focus_ring.get (focus_index); 240 241 if (widget is TextArea) { 242 TextArea text_area = (TextArea) widget; 243 text_area.insert_text (text); 244 } 245 } 246 } 247 248 public string get_copy_selection () { 249 if (0 <= focus_index < focus_ring.size) { 250 Widget widget = focus_ring.get (focus_index); 251 252 if (widget is TextArea) { 253 TextArea text_area = (TextArea) widget; 254 return text_area.get_selected_text (); 255 } 256 } 257 258 return ""; 259 } 260 261 public void show_plus_version_needed_for_color_tables () { 262 MessageDialog dialog; 263 dialog = MainWindow.show_message (t_("You need the plus version to export color fonts.")); 264 MainWindow.show_dialog (dialog); 265 } 266 } 267 268 } 269