Clone in a terminal:
Commit 211190f
Johan Mattsson - 2016-12-19T15:08:00+00:00
211190fbd18ae8d6553d2c494dbcb9599cf7fe78johan.mattsson.m@gmail.com

Export font files to user directories Fixes a bug in BirdFont on Mac OS

Changed files (5)

Diff

diff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 47da2e4..979e0a5 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -345,14 +345,17 @@ public class BirdFont { 	}  	public static File get_preview_directory () {-		File settings = get_settings_directory ();-		File backup = get_child(settings, "preview");--		if (!backup.query_exists ()) {-			DirUtils.create ((!) backup.get_path (), 0755);+		string? export = BirdFont.get_current_font ().get_export_directory ();+		+		if (export == null) {+			warning ("No export directory is set.");+			export = ""; 		} -		return backup;+		File e = File.new_for_path ((!) export);+		File p = get_child(e, "preview");+		+		return p; 	}  	public static void set_settings_subdir (string? subdir) {diff --git a/libbirdfont/ExportTool.vala b/libbirdfont/ExportTool.valaindex c11f602..c7c1533 100644--- a/libbirdfont/ExportTool.vala+++ b/libbirdfont/ExportTool.vala@@ -23,6 +23,28 @@ public class ExportTool : GLib.Object { 	public ExportTool (string n) { 	} +	public static void set_output_directory () {+#if MAC+		Font font = BirdFont.get_current_font ();+		string? path = font.get_export_directory ();+			+		FileChooser fc = new FileChooser ();+		fc.file_selected.connect ((p) => {+			 path = p;+		});+		+		if (path == null) {+			File export_path_handle = File.new_for_path (path);+		+			if (!can_write (export_path_handle)) {+				MainWindow.file_chooser (t_("Export"), fc, FileChooser.LOAD | FileChooser.DIRECTORY);+			}+		}+		+		font.export_directory = path;+#endif+	}+ 	public static string export_selected_paths_to_svg () { 		return export_current_glyph_to_string (true);		 	}@@ -434,22 +456,31 @@ os.put_string (  	public static string get_export_folder () { 		Font font = BirdFont.get_current_font ();-		string? sandbox = BirdFont.get_sandbox_directory ();+		string? d = font.get_export_directory ();+		+		if (d == null) {+			warning ("No export path is not set");+			return "";+		}+		+		return (!) d;+	} -		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);+	static bool can_write (File folder) {+		File test = get_child (folder, "text.tmp");+		bool writable = false;+		+		try {+			writable = FileUtils.set_contents (test.get_path (), "test");+			+			if (writable) {+				FileUtils.remove (test.get_path ()); 			}-			return (!) get_child (f, font.full_name).get_path ();-		} else {-			return (!) font.get_folder ().get_path ();+		} catch (GLib.Error e) {+			writable = false; 		}+		+		return writable; 	}  	public static File get_export_dir () {@@ -577,7 +608,8 @@ os.put_string ( 		} catch (Error e) { 			warning (@"Can't create TTF font to $ttf"); 			critical (@"$(e.message)");-			error_message = e.message;			+			error_message = e.message;+			f.export_directory = null; 		}		 	} 	diff --git a/libbirdfont/Font.vala b/libbirdfont/Font.valaindex 78e7526..4da17a6 100644--- a/libbirdfont/Font.vala+++ b/libbirdfont/Font.vala@@ -63,6 +63,7 @@ public class Font : GLib.Object { 	public Gee.ArrayList<Line> custom_guides = new Gee.ArrayList<Line> (); 	 	public string? font_file = null;+	public string? export_directory = null; 	 	bool modified = false; 	@@ -187,6 +188,13 @@ public class Font : GLib.Object { 		font_deleted (); 	} +	public string? get_export_directory () {+#if MAC+		return export_directory;+#endif+		return get_path ();+	}+ 	public void add_default_characters () { 		add_glyph_collection (get_notdef_character ()); 		add_glyph_collection (get_space ());diff --git a/libbirdfont/Preview.vala b/libbirdfont/Preview.valaindex 5f1a125..bdff830 100644--- a/libbirdfont/Preview.vala+++ b/libbirdfont/Preview.vala@@ -28,7 +28,7 @@ public class Preview : FontDisplay { 	}  	public override void selected_canvas () {-	MainWindow.set_scrollbar_size (0);+		MainWindow.set_scrollbar_size (0); 	}  	public static string get_html_path () {@@ -113,11 +113,26 @@ public class Preview : FontDisplay { 		try { 			dis = new DataInputStream (get_file ().read ()); -			preview_directory = BirdFont.get_preview_directory ();+			string? d = font.get_export_directory ();+			+			if (d == null) {+				warning ("Export dir is not set.");+				ExportTool.set_output_directory ();+				d = font.get_export_directory ();+			}+			+			preview_directory = File.new_for_path ((!) d);+			+			warning (@"previwdir $((!) d)");+			+			if (ExportTool.get_export_dir () == null) {+				ExportTool.set_output_directory ();+			} -			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");+			File dir = File.new_for_path ((!) d);+			f_ttf = get_child (dir, @"$(ExportSettings.get_file_name (font)).ttf");+			f_eot = get_child (dir, @"$(ExportSettings.get_file_name (font)).eot");+			f_svg = get_child (dir, @"$(ExportSettings.get_file_name (font)).svg");  			if (!f_ttf.query_exists ()) { 				warning ("TTF file does not exist.");@@ -127,10 +142,14 @@ public class Preview : FontDisplay { 				warning ("SVG file does not exist."); 			} +			string name = ExportSettings.get_file_name_mac (font);+			 			while ((line = dis.read_line (null)) != null) {-				line = ((!) line).replace (@"$(ExportSettings.get_file_name (font)).ttf", @"$(TabContent.path_to_uri ((!) f_ttf.get_path ()))?$rid");-				line = ((!) line).replace (@"$(ExportSettings.get_file_name (font)).eot", @"$(TabContent.path_to_uri ((!) f_eot.get_path ()))?$rid");-				line = ((!) line).replace (@"$(ExportSettings.get_file_name (font)).svg", @"$(TabContent.path_to_uri ((!) f_svg.get_path ()))?$rid");+				warning (@"PRE $line     name $name rep $(TabContent.path_to_uri ((!) f_ttf.get_path ()))");+				line = ((!) line).replace (@"$name.ttf", @"$(TabContent.path_to_uri ((!) f_ttf.get_path ()))?$rid");+				line = ((!) line).replace (@"$name.eot", @"$(TabContent.path_to_uri ((!) f_eot.get_path ()))?$rid");+				line = ((!) line).replace (@"$name.svg", @"$(TabContent.path_to_uri ((!) f_svg.get_path ()))?$rid");+				warning (@"POST $line"); 				sb.append ((!) line); 			} diff --git a/scripts/version.py b/scripts/version.pyindex d652232..6a79c4c 100644--- a/scripts/version.py+++ b/scripts/version.py@@ -13,7 +13,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details. """ -VERSION = '2.18.3'+VERSION = '2.18.4' SO_VERSION_MAJOR = '36' SO_VERSION_MINOR = '0' SO_VERSION = SO_VERSION_MAJOR + '.' + SO_VERSION_MINOR

Contact

Email: johan.mattsson.m@gmail.com
Mastodon: typo.social/@birdfont
GitHub: johanmattssonm
LinkedIn: johan-mattsson-2ab324112