The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Use a directory within the sandbox for exporting fonts on Mac OS X

These changes was commited to the Birdfont repository Sun, 01 Nov 2015 18:43:52 +0000.

Contributing

Send patches or pull requests to johan.mattsson.m@gmail.com.
Clone this repository: git clone https://github.com/johanmattssonm/birdfont.git
author Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 01 Nov 2015 18:43:52 +0000 (19:43 +0100)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 01 Nov 2015 19:27:29 +0000 (20:27 +0100)
commit cb5ad1dbcbcb0d84ec33265fa292bd863d39a9ab
tree d29ad2dd9cf42f6bb7b77620ccde21c3e601b2ba
parent 0417863cf3c7b9702d3730895edf08a72201ddc3
Use a directory within the sandbox for exporting fonts on Mac OS X

libbirdfont/BezierTool.vala
libbirdfont/BirdFont.vala
libbirdfont/ExportCallback.vala
libbirdfont/ExportSettings.vala
libbirdfont/ExportTool.vala
libbirdfont/MenuTab.vala
libbirdfont/Preview.vala
libbirdfont/PreviewTools.vala
--- a/libbirdfont/BezierTool.vala +++ b/libbirdfont/BezierTool.vala @@ -256,6 +256,7 @@ return; } + convert_zero_length_handles_to_lines (); corner_node = false; // ignore double clicks @@ -387,6 +388,8 @@ current_path.get_first_point ().set_reflective_handles (false); current_path.get_last_point ().set_reflective_handles (false); } + + convert_zero_length_handles_to_lines (); } public void switch_to_line_mode () {
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -94,6 +94,7 @@ public static Drawing? drawing = null; public static string? settings_subdirectory = null; + public static string? sandbox_directory = null; public BirdFont () { set_defaul_drawing_callbacks (); @@ -110,7 +111,7 @@ * @param program path * @param setting subdirectory */ - public void init (string[] arg, string? program_path, string? settings_subdir) { + public void init (string[] arg, string? program_path, string? settings_subdir, string? sandbox_path) { int i; File font_file; string exec_path; @@ -121,7 +122,8 @@ CodePageBits codepage_bits; set_settings_subdir (settings_subdir); - + sandbox_directory = sandbox_path; + args = new Argument.command_line (arg); Font.empty = new Font (); @@ -333,6 +335,10 @@ KerningTools.update_kerning_classes (); return current_font; + } + + public static string? get_sandbox_directory () { + return sandbox_directory; } public static void set_settings_directory (string directory) { @@ -368,6 +374,9 @@ DirUtils.create ((!) home.get_path (),0755); } #else + if (sandbox_directory != null) { + home = File.new_for_path ((!) sandbox_directory); + } else { home_path = (settings_directory != null) ? (!) settings_directory : Environment.get_user_config_dir (); @@ -377,6 +386,7 @@ } home = File.new_for_path (home_path); + } #endif if (settings_subdirectory != null) {
--- a/libbirdfont/ExportCallback.vala +++ b/libbirdfont/ExportCallback.vala @@ -17,7 +17,8 @@ public class ExportCallback : GLib.Object { public signal void file_exported (); - + public bool preview = false; + public ExportCallback () { }
--- a/libbirdfont/ExportSettings.vala +++ b/libbirdfont/ExportSettings.vala @@ -90,7 +90,7 @@ widgets.add (units_per_em); focus_ring.add (units_per_em); - folder = (!) font.get_folder ().get_path (); + folder = ExportTool.get_export_folder (); Text folder_row = new Text (t_("Folder") + ": " + folder, label_size, label_margin); folder_row.margin_bottom = 20 * MainWindow.units; widgets.add (folder_row);
--- a/libbirdfont/ExportTool.vala +++ b/libbirdfont/ExportTool.vala @@ -415,11 +415,44 @@ } } + public static string get_export_folder () { + Font font = BirdFont.get_current_font (); + string? sandbox = BirdFont.get_sandbox_directory (); + + if (sandbox != null) { + File s = File.new_for_path ((!) sandbox); + File f = get_child (s, "Fonts"); + try { + if (!f.query_exists ()) { + f.make_directory (); + } + } catch (GLib.Error e) { + warning(e.message); + } + return (!) get_child (f, font.full_name).get_path (); + } else { + return (!) font.get_folder ().get_path (); + } + } + + public static File get_export_dir () { + return File.new_for_path (get_export_folder ()); + } + public static bool export_ttf_font () { + File f = get_export_dir (); Font font = BirdFont.get_current_font (); - File f = font.get_folder (); - + + try { + if (!f.query_exists ()) { + f.make_directory (); + } + } catch (GLib.Error e) { + warning(e.message); + } + printd (@"export_ttf_font:\n"); + printd (@"get_export_folder (): $(get_export_folder ())\n"); printd (@"font.get_path (): $(font.get_path ())\n"); printd (@"font.get_folder_path (): $(font.get_folder_path ())\n"); printd (@"font.get_folder (): $((!) f.get_path ())\n"); @@ -483,8 +516,7 @@ } public static bool export_svg_font () { - Font font = BirdFont.get_current_font (); - return export_svg_font_path (font.get_folder ()); + return export_svg_font_path (get_export_dir ()); } public static bool export_svg_font_path (File folder) {
--- a/libbirdfont/MenuTab.vala +++ b/libbirdfont/MenuTab.vala @@ -46,6 +46,10 @@ suppress_event = false; background_thread = false; + } + + public static ExportCallback get_export_callback () { + return export_callback; } public static bool has_suppress_event () {
--- a/libbirdfont/Preview.vala +++ b/libbirdfont/Preview.vala @@ -38,7 +38,7 @@ public static File get_file () { Font font = BirdFont.get_current_font (); string fn = get_html_file_name (); - File dir = font.get_folder (); + File dir = ExportTool.get_export_dir (); File file = get_child (dir, fn); if (!file.query_exists ()) { @@ -49,9 +49,8 @@ } public static bool has_html_document () { - Font font = BirdFont.get_current_font (); string path = get_html_file_name (); - File dir = font.get_folder (); + File dir = ExportTool.get_export_dir (); File file = get_child (dir, path); return file.query_exists (); } @@ -59,7 +58,7 @@ public static void generate_html_document () { Font font = BirdFont.get_current_font (); string path = get_html_file_name (); - File dir = font.get_folder (); + File dir = ExportTool.get_export_dir (); File file = get_child (dir, path); ExportTool.generate_html_document ((!)file.get_path (), font); } @@ -116,9 +115,9 @@ preview_directory = BirdFont.get_preview_directory (); - f_ttf = get_child (font.get_folder (), @"$(ExportSettings.get_file_name (font)).ttf"); - f_eot = get_child (font.get_folder (), @"$(ExportSettings.get_file_name (font)).eot"); - f_svg = get_child (font.get_folder (), @"$(ExportSettings.get_file_name (font)).svg"); + f_ttf = get_child (ExportTool.get_export_dir (), @"$(ExportSettings.get_file_name (font)).ttf"); + f_eot = get_child (ExportTool.get_export_dir (), @"$(ExportSettings.get_file_name (font)).eot"); + f_svg = get_child (ExportTool.get_export_dir (), @"$(ExportSettings.get_file_name (font)).svg"); if (!f_ttf.query_exists ()) { warning ("TTF file does not exist.");
--- a/libbirdfont/PreviewTools.vala +++ b/libbirdfont/PreviewTools.vala @@ -49,6 +49,7 @@ /** Export fonts and update html canvas. */ public static void update_preview () { MenuTab.export_callback = new ExportCallback (); + MenuTab.export_callback.preview = true; MenuTab.export_callback.file_exported.connect (signal_preview_updated); MenuTab.export_callback.export_fonts_in_background (); }