Clone in a terminal:
Commit 39fca91
Johan Mattsson - 2015-05-17T12:59:15+00:00
39fca9185e64ac2a8c08d53370402a77cedb4d48johan.mattsson.m@gmail.com

Import SVG folder

Changed files (8)

Diff

diff --git a/birdfont/GtkWindow.vala b/birdfont/GtkWindow.valaindex 9ce1c5b..924fee8 100644--- a/birdfont/GtkWindow.vala+++ b/birdfont/GtkWindow.vala@@ -456,11 +456,20 @@ public class GtkWindow : Gtk.Window, NativeWindow { 	 	public void file_chooser (string title, FileChooser fc, uint flags) { 		string? fn = null;-		+		bool folder; 		if (BirdFont.get_arguments () .has_argument ("--windows")) {-			MenuTab.show_file_dialog_tab (title, fc);-		} else {		-			if ((flags & FileChooser.LOAD) > 0) {+			folder = (flags & FileChooser.DIRECTORY) > 0;+			MenuTab.show_file_dialog_tab (title, fc, folder);+		} else {+			if ((flags & FileChooser.DIRECTORY) > 0) { +				if ((flags & FileChooser.LOAD) > 0) {+					fn = show_file_chooser (title, FileChooserAction.SELECT_FOLDER, Stock.OPEN);+				} else if ((flags & FileChooser.SAVE) > 0) {+					fn = show_file_chooser (title, FileChooserAction.SELECT_FOLDER, Stock.SAVE);+				} else {+					warning ("Open or save is not set.");+				}+			} else if ((flags & FileChooser.LOAD) > 0) { 				fn = show_file_chooser (title, FileChooserAction.OPEN, Stock.OPEN); 			} else if ((flags & FileChooser.SAVE) > 0) { 				fn = show_file_chooser (title, FileChooserAction.SAVE, Stock.SAVE);diff --git a/dodo.py b/dodo.pyindex 178183d..4ef47c2 100644--- a/dodo.py+++ b/dodo.py@@ -1,5 +1,5 @@ """-Copyright (C) 2012, 2013, 2014 2015 Eduardo Naufel Schettino and Johan Mattsson+Copyright (C) 2012 2013 2014 2015 Eduardo Naufel Schettino and Johan Mattsson  This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published bydiff --git a/libbirdfont/BirdFont.vala b/libbirdfont/BirdFont.valaindex 42b4e84..b85ba97 100644--- a/libbirdfont/BirdFont.vala+++ b/libbirdfont/BirdFont.vala@@ -767,9 +767,14 @@ public static File get_child (File folder, string file_name) { 	string n;  	// avoid drive letter problems on windows-	+ 	f = (!) folder.get_path ();++#if LINUX+	s = "/"; +#else 	s = (BirdFont.win32) ? "\\" : "/"; +#endif 	 	n = file_name; 	if (unlikely (BirdFont.win32 && file_name.index_of ("\\") != -1)) {diff --git a/libbirdfont/FileChooser.vala b/libbirdfont/FileChooser.valaindex 290f849..f27c83c 100644--- a/libbirdfont/FileChooser.vala+++ b/libbirdfont/FileChooser.vala@@ -19,6 +19,7 @@ public class FileChooser : GLib.Object { 	public static const uint NONE = 0; 	public static const uint SAVE = 1; 	public static const uint LOAD = 1 << 1;+	public static const uint DIRECTORY = 1 << 2; 	 	public signal void file_selected  (string? path); 	diff --git a/libbirdfont/FileDialogTab.vala b/libbirdfont/FileDialogTab.valaindex bab77e1..c53a074 100644--- a/libbirdfont/FileDialogTab.vala+++ b/libbirdfont/FileDialogTab.vala@@ -36,10 +36,19 @@ public class FileDialogTab : Table { 	private static bool has_drive_letters = false; 	private static Gee.ArrayList<string> drive_letters; -	public FileDialogTab (string title, FileChooser action) {+	bool select_folder = false;++#if LINUX+	public static const string path_separator = "/";+#else+	public static const string path_separator = "\\";+#endif++	public FileDialogTab (string title, FileChooser action, bool folder) { 		this.title = title; 		this.action = action; 		+		select_folder = folder; 		rows = new Gee.ArrayList<Row> (); 		files = new Gee.ArrayList<string> (); 		directories = new Gee.ArrayList<string> ();@@ -66,6 +75,10 @@ public class FileDialogTab : Table { 		row = new Row.headline (""); 		rows.add (row);	 	+		if (select_folder) {+			row = new Row.headline (t_("Select a Folder"));+		}+	 		if (directories.size > 0) { 			row = new Row.headline (t_("Folders")); 			rows.add (row);	@@ -99,19 +112,26 @@ public class FileDialogTab : Table { 		SelectedFile f;  		if (row.get_index () == FILE) {-			return_if_fail (row.get_row_data () is SelectedFile);-			f = (SelectedFile) row.get_row_data ();-			selected_filename = f.file_name;+			if (!select_folder) {+				return_if_fail (row.get_row_data () is SelectedFile);+				f = (SelectedFile) row.get_row_data ();+				selected_filename = f.file_name;+			} 		} else if (row.get_index () == DIRECTORY) { 			return_if_fail (row.get_row_data () is SelectedFile); 			f = (SelectedFile) row.get_row_data (); 			-			if (f.file_name.index_of (":") > -1) {-				propagate_files (f.file_name);+			if (select_folder && f.file_name != "..") {+				selected_filename = f.file_name; 			} else {-				propagate_files (((!) current_dir.get_path ()) + "\\" + f.file_name);+				if (f.file_name.index_of (":") > -1) {+					propagate_files (f.file_name);+				} else {+					propagate_files (((!) current_dir.get_path ()) + path_separator + f.file_name);+				}+				+				selected_filename = ""; 			}-			selected_filename = ""; 		} 		 		show_text_area (selected_filename);@@ -211,10 +231,18 @@ public class FileDialogTab : Table { 			warning ("No file."); 			return; 		}-		-		if (selected_filename != "") {-			f = get_child (current_dir, selected_filename);-			action.file_selected ((!) f.get_path ());++		if (select_folder) {+			if (selected_filename.index_of (":") > -1) {+				propagate_files (selected_filename);+			} else {+				propagate_files (((!) current_dir.get_path ()) + path_separator + selected_filename);+			}+		} else {		+			if (selected_filename != "") {+				f = get_child (current_dir, selected_filename);+				action.file_selected ((!) f.get_path ());+			} 		} 	} diff --git a/libbirdfont/Menu.vala b/libbirdfont/Menu.valaindex f416c65..2648d40 100644--- a/libbirdfont/Menu.vala+++ b/libbirdfont/Menu.vala@@ -214,7 +214,14 @@ public class Menu : GLib.Object { 			show_menu = false; 		}); 		edit_menu.items.add (import_svg);-+		+		MenuItem import_svg_folder = add_menu_item (t_("Import SVG folder"), "import svg folder", "");+		import_svg_folder.action.connect (() => {+			SvgParser.import_folder ();+			show_menu = false;+		});+		edit_menu.items.add (import_svg_folder);+		 		MenuItem import_background_image = add_menu_item (t_("Import Background Image"), "import background image"); 		import_background_image.action.connect (() => { 			MenuTab.show_background_tab ();diff --git a/libbirdfont/MenuTab.vala b/libbirdfont/MenuTab.valaindex 4271ed1..4289596 100644--- a/libbirdfont/MenuTab.vala+++ b/libbirdfont/MenuTab.vala@@ -524,8 +524,9 @@ public class MenuTab : FontDisplay { 		DrawingTools.move_tool.move_to_baseline (); 	} -	public static void show_file_dialog_tab (string title, FileChooser action) {-		MainWindow.get_tab_bar ().add_tab (new FileDialogTab (title, action));+	public static void show_file_dialog_tab (string title, FileChooser action, bool folder) {+		FileDialogTab ft = new FileDialogTab (title, action, folder);+		MainWindow.get_tab_bar ().add_tab (ft); 	} 	 	public static void simplify_path () {diff --git a/libbirdfont/SvgParser.vala b/libbirdfont/SvgParser.valaindex 83db359..44fe5ed 100644--- a/libbirdfont/SvgParser.vala+++ b/libbirdfont/SvgParser.vala@@ -50,6 +50,50 @@ public class SvgParser { 		MainWindow.file_chooser (t_("Import"), fc, FileChooser.LOAD); 	} 	+	public static void import_folder () {+		FileChooser fc = new FileChooser ();+		fc.file_selected.connect ((p) => {+			string path;+			File svg_folder;+			File svg;+			bool imported;+			FileEnumerator enumerator;+			FileInfo? file_info;+			string file_name;+			Font font;+			+			if (p == null) {+				return;+			}+			+			path = (!) p;+			svg_folder = File.new_for_path (path);+			font = BirdFont.get_current_font ();+				+			try {+				enumerator = svg_folder.enumerate_children (FileAttribute.STANDARD_NAME, 0);+				while ((file_info = enumerator.next_file ()) != null) {+					file_name = ((!) file_info).get_name ();+					+					if (file_name.has_suffix (".svg")) {+						svg = get_child (svg_folder, file_name);+						imported = import_svg_file (font, svg);+						+						if (!imported) {+							warning ("Can't import %s.", (!) svg.get_path ());+						} else {+							font.touch ();+						}+					}+				}+			} catch (Error e) {+				warning (e.message);+			}+		});+		+		MainWindow.file_chooser (t_("Import"), fc, FileChooser.LOAD | FileChooser.DIRECTORY);+	}+	 	public static void import_svg_data (string xml_data, SvgFormat format = SvgFormat.NONE) { 		PathList path_list = new PathList (); 		Glyph glyph; @@ -1460,7 +1504,6 @@ public class SvgParser { 		return path_list; 	} -	// FIXME: NO END 	PathList create_paths_illustrator (BezierPoints[] b, int num_b) { 		Path path; 		PathList path_list = new PathList ();@@ -1494,19 +1537,30 @@ public class SvgParser { 				path.create_list (); 				 				int first_index = 1;-				for (int j = i; j >= 1; j--) {++				for (int j = i - 1; j >= 1; j--) { 					if (b[j].type == 'z') {-						first_index = j + 2; // skipping M +						first_index = j + 1; // from z to M  					} 				} 				 				if (b[first_index].type == 'C' || b[first_index].type == 'S') { 					return_val_if_fail (path.points.size != 0, path_list); 					ep = path.points.get (path.points.size - 1);-					ep.get_right_handle ().set_point_type (PointType.CUBIC);-					ep.get_right_handle ().move_to_coordinate (b[first_index].x0, b[first_index].y0);+					+					if (b[i - 1].type != 'L' ) {+						ep.get_right_handle ().set_point_type (PointType.CUBIC);+						ep.get_right_handle ().move_to_coordinate (b[first_index].x0, b[first_index].y0);+					}+				} else if (b[first_index].type == 'L') {+					return_val_if_fail (path.points.size != 0, path_list);+					ep = path.points.get (path.points.size - 1);+					ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC);+					ep.recalculate_linear_handles ();+				} else {+					warning ("Unexpected type: %s", (!) b[first_index].type.to_string ()); 				}-+				 				path.recalculate_linear_handles (); 				path_list.add (path); 				@@ -1523,9 +1577,9 @@ public class SvgParser { 				ep = path.add (b[i].x0, b[i].y0); 				ep.set_point_type (PointType.LINE_CUBIC); // TODO: quadratic 				ep.get_right_handle ().set_point_type (PointType.LINE_CUBIC);-				+ 				if (b[i -1].type == 'L' || first_point) {-					//ep.get_left_handle ().set_point_type (PointType.LINE_CUBIC);+					// ep.get_left_handle ().set_point_type (PointType.LINE_CUBIC); 				} 				 				if (b[i + 1].type == 'C' || b[i + 1].type == 'S') {

Contact

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