.
1 /*
2 Copyright (C) 2012 2014 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 namespace BirdFont {
15
16 static void print_export_help (string[] arg) {
17 stdout.printf (t_("Usage:"));
18 stdout.printf (arg[0]);
19 stdout.printf (" [" + t_("OPTION") + "...] " + t_("FILE") +"\n");
20 stdout.printf ("-h, --help " + t_("print this message") + "\n");
21 stdout.printf ("-o, --output [DIRECTORY] " + t_("write files to this directory") + "\n");
22 stdout.printf ("-s, --svg " + t_("write svg file") + "\n");
23 stdout.printf ("-t, --ttf " + t_("write ttf and eot file") + "\n");
24 stdout.printf ("\n");
25 }
26
27
28 public static int run_export (string[] arg) {
29 string output_directory = ".";
30 string file_name = "";
31 bool specific_formats = false;
32 bool write_ttf = false;
33 bool write_svg = false;
34 File directory;
35 Font font;
36 MainWindow main_window;
37
38 stdout.printf ("birdfont-export version %s\n", VERSION);
39
40 if (arg.length < 2) {
41 print_export_help (arg);
42 return -1;
43 }
44
45 Theme.set_default_colors ();
46 BirdFont.current_font = BirdFont.new_font ();
47 BirdFont.current_glyph_collection = new GlyphCollection.with_glyph ( '\0', "null");
48 main_window = new MainWindow ();
49
50 // FIXME: create a option for this and add structure the log messages
51
52 if (BirdFont.has_logging ()) {
53 init_logfile ();
54 }
55
56 for (int i = 1; i < arg.length; i++) {
57
58 if (arg[i] == "-f" || arg[i] == "--fatal-warnings") {
59 BirdFont.fatal_wanings = true;
60 return 0;
61 }
62
63 if (arg[i] == "-h" || arg[i] == "--help") {
64 print_export_help (arg);
65 return 0;
66 }
67
68 if ((arg[i] == "-o" || arg[i] == "--output") && i + 1 < arg.length) {
69 output_directory = arg[i + 1];
70 i++;
71 continue;
72 }
73
74 if (arg[i] == "-s" || arg[i] == "--svg") {
75 write_svg = true;
76 specific_formats = true;
77 continue;
78 }
79
80 if (arg[i] == "-t" || arg[i] == "--ttf") {
81 write_ttf = true;
82 specific_formats = true;
83 continue;
84 }
85
86 if (arg[i].has_prefix ("-")) {
87 print_export_help (arg);
88 return 1;
89 }
90
91 if (!arg[i].has_prefix ("-")) {
92 file_name = arg[i];
93
94 if (i != arg.length - 1) {
95 print_export_help (arg);
96 return 1;
97 }
98
99 break;
100 }
101 }
102
103 if (BirdFont.fatal_wanings) {
104 LogLevelFlags levels = LogLevelFlags.LEVEL_ERROR | LogLevelFlags.LEVEL_CRITICAL | LogLevelFlags.LEVEL_WARNING;
105 Log.set_handler (null, levels, BirdFont.fatal_warning);
106 }
107
108 Preferences.load ();
109
110 BirdFont.args = new Argument ("");
111 BirdFont.current_glyph_collection = new GlyphCollection.with_glyph ('\0', "");
112
113 file_name = build_absoulute_path (file_name);
114
115 font = BirdFont.get_current_font ();
116 font.set_file (file_name);
117 if (!font.load ()) {
118 warning (@"Failed to load font $file_name.\n");
119
120 if (!file_name.has_suffix (".bf")) {
121 warning (@"Is it a .bf file?\n");
122 }
123
124 return 1;
125 }
126
127 directory = File.new_for_path (output_directory);
128
129 if (!directory.query_exists ()) {
130 stderr.printf (t_("Can't find output directory") + @"$((!)directory.get_path ())\n");
131 return 1;
132 }
133
134 if (!specific_formats || write_svg) {
135 print (@"Writing $(ExportSettings.get_file_name (font)).svg to $output_directory\n");
136 ExportTool.export_svg_font_path (File.new_for_path (output_directory));
137 }
138
139 if (!specific_formats || write_ttf) {
140 print (@"Writing $(ExportSettings.get_file_name (font)).ttf to $output_directory\n");
141 ExportTool.export_ttf_font_path (File.new_for_path (output_directory));
142 }
143
144 return 0;
145 }
146
147 }
148