The Birdfont Source Code


All Repositories / birdfont.git / commit – RSS feed

Import SVG folder

These changes was commited to the Birdfont repository Sun, 17 May 2015 11:49:02 +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, 17 May 2015 11:49:02 +0000 (13:49 +0200)
committer Johan Mattsson <johan.mattsson.m@gmail.com>
Sun, 17 May 2015 12:59:15 +0000 (14:59 +0200)
commit 39fca9185e64ac2a8c08d53370402a77cedb4d48
tree f84a5be3c40b9344c4214df7ba2fdb95cc7e56df
parent be40ed834a9fb563f98e986154195208c724932b
Import SVG folder

birdfont/GtkWindow.vala
dodo.py
libbirdfont/BirdFont.vala
libbirdfont/FileChooser.vala
libbirdfont/FileDialogTab.vala
libbirdfont/Menu.vala
libbirdfont/MenuTab.vala
libbirdfont/SvgParser.vala
--- a/birdfont/GtkWindow.vala +++ b/birdfont/GtkWindow.vala @@ -456,11 +456,20 @@ 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.py
--- 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 by
--- a/libbirdfont/BirdFont.vala +++ b/libbirdfont/BirdFont.vala @@ -767,9 +767,14 @@ 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)) {
--- a/libbirdfont/FileChooser.vala +++ b/libbirdfont/FileChooser.vala @@ -19,6 +19,7 @@ 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);
--- a/libbirdfont/FileDialogTab.vala +++ b/libbirdfont/FileDialogTab.vala @@ -36,10 +36,19 @@ 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> (); @@ -65,6 +74,10 @@ // add empty rows under the text area 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")); @@ -99,19 +112,26 @@ 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 @@ 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 ()); + } } }
--- a/libbirdfont/Menu.vala +++ b/libbirdfont/Menu.vala @@ -214,7 +214,14 @@ 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 ();
--- a/libbirdfont/MenuTab.vala +++ b/libbirdfont/MenuTab.vala @@ -524,8 +524,9 @@ 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 () {
--- a/libbirdfont/SvgParser.vala +++ b/libbirdfont/SvgParser.vala @@ -48,6 +48,50 @@ }); 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) { @@ -1460,7 +1504,6 @@ 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 @@ 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 @@ 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') {