The Birdfont Source Code


All Repositories / birdfont.git / blob – RSS feed

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