.
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 ttf = new CheckBox ("TTF", label_size);
101 ttf.updated.connect ((c) => {
102 Font f = BirdFont.get_current_font ();
103 string v = c ? "true" : "false";
104 f.settings.set_setting ("export_ttf", v);
105 });
106 ttf.checked = export_ttf_setting (font);
107 widgets.add (ttf);
108 focus_ring.add (ttf);
109
110 eot = new CheckBox ("EOT", label_size);
111 eot.updated.connect ((c) => {
112 Font f = BirdFont.get_current_font ();
113 string v = c ? "true" : "false";
114 f.settings.set_setting ("export_eot", v);
115 });
116 eot.checked = export_eot_setting (font);
117 widgets.add (eot);
118 focus_ring.add (eot);
119
120 svg = new CheckBox ("SVG", label_size);
121 svg.updated.connect ((c) => {
122 Font f = BirdFont.get_current_font ();
123 string v = c ? "true" : "false";
124 f.settings.set_setting ("export_svg", v);
125 });
126 svg.checked = export_svg_setting (font);
127 svg.margin_bottom = margin;
128 widgets.add (svg);
129 focus_ring.add (svg);
130
131 svg.margin_bottom = 20 * MainWindow.units;
132
133 name_tab = new Button (t_("Name and Description"), margin);
134 name_tab.action.connect ((c) => {
135 MenuTab.show_description ();
136 });
137 widgets.add (name_tab);
138
139 export_action = new Button (t_("Export"), margin);
140 export_action.action.connect ((c) => {
141 MenuTab.export_fonts_in_background ();
142 });
143 widgets.add (export_action);
144
145 set_focus (file_name);
146 }
147
148 public static string get_file_name (Font font) {
149 string n = font.settings.get_setting ("file_name");
150
151 if (n == "") {
152 n = font.full_name;
153 }
154
155 return n;
156 }
157
158 public static string get_file_name_mac (Font font) {
159 string n = font.settings.get_setting ("file_name_mac");
160
161 if (n == "") {
162 n = font.full_name + " Mac";
163 }
164
165 return n;
166 }
167
168 public static bool export_ttf_setting (Font f) {
169 return f.settings.get_setting ("export_ttf") != "false";
170 }
171
172 public static bool export_eot_setting (Font f) {
173 return f.settings.get_setting ("export_eot") != "false";
174 }
175
176 public static bool export_svg_setting (Font f) {
177 return f.settings.get_setting ("export_svg") != "false";
178 }
179
180 public static bool has_export_settings (Font f) {
181 return f.settings.get_setting ("has_export_settings") == "true";
182 }
183
184 public override string get_label () {
185 return t_("Export Settings");
186 }
187
188 public override string get_name () {
189 return "Export Settings";
190 }
191 }
192
193 }
194