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