Commit 39fca91
Import SVG folder
Changed files (8)
modifiedbirdfont/GtkWindow.valamodifieddodo.pymodifiedlibbirdfont/BirdFont.valamodifiedlibbirdfont/FileChooser.valamodifiedlibbirdfont/FileDialogTab.valamodifiedlibbirdfont/Menu.valamodifiedlibbirdfont/MenuTab.valamodifiedlibbirdfont/SvgParser.vala
Diff
@@ -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);@@ -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 by@@ -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)) {@@ -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); @@ -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 ());+ } } } @@ -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 ();@@ -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 () {@@ -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') {