Commit cb5ad1d
Use a directory within the sandbox for exporting fonts on Mac OS X
Changed files (8)
modifiedlibbirdfont/BezierTool.valamodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/ExportCallback.valamodifiedlibbirdfont/ExportSettings.valamodifiedlibbirdfont/ExportTool.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/Preview.valamodifiedlibbirdfont/PreviewTools.vala
Diff
@@ -256,6 +256,7 @@ public class BezierTool : Tool { return; } + convert_zero_length_handles_to_lines (); corner_node = false; // ignore double clicks@@ -387,6 +388,8 @@ public class BezierTool : Tool { 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 () {@@ -94,6 +94,7 @@ public class BirdFont { 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 @@ public class BirdFont { * @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 @@ public class BirdFont { CodePageBits codepage_bits; set_settings_subdir (settings_subdir);-+ sandbox_directory = sandbox_path;+ args = new Argument.command_line (arg); Font.empty = new Font (); @@ -335,6 +337,10 @@ public class BirdFont { return current_font; } + public static string? get_sandbox_directory () {+ return sandbox_directory;+ }+ public static void set_settings_directory (string directory) { settings_subdirectory = directory; }@@ -368,6 +374,9 @@ public class BirdFont { 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 @@ public class BirdFont { } home = File.new_for_path (home_path);+ } #endif if (settings_subdirectory != null) {@@ -17,7 +17,8 @@ namespace BirdFont { public class ExportCallback : GLib.Object { public signal void file_exported ();- + public bool preview = false;+ public ExportCallback () { } @@ -90,7 +90,7 @@ public class ExportSettings : TableLayout { 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);@@ -415,11 +415,44 @@ os.put_string ( } } + 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 @@ os.put_string ( } 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) {@@ -48,6 +48,10 @@ public class MenuTab : FontDisplay { background_thread = false; } + public static ExportCallback get_export_callback () {+ return export_callback;+ }+ public static bool has_suppress_event () { bool suppress; @@ -38,7 +38,7 @@ public class Preview : FontDisplay { 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 class Preview : FontDisplay { } 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 class Preview : FontDisplay { 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 @@ public class Preview : FontDisplay { 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.");@@ -49,6 +49,7 @@ public class PreviewTools : ToolCollection { /** 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 (); }