diff options
| author | Tavmjong Bah <tavmjong@free.fr> | 2018-11-25 17:31:30 +0000 |
|---|---|---|
| committer | Tavmjong Bah <tavmjong@free.fr> | 2018-11-25 17:31:30 +0000 |
| commit | 4ccd87725f22c8ea5fff4ef865b11e3c564d7520 (patch) | |
| tree | 87dd8ba211f412a12d7d68eb2fa4f210f2493f07 /src | |
| parent | Remove unused variable. (diff) | |
| download | inkscape-4ccd87725f22c8ea5fff4ef865b11e3c564d7520.tar.gz inkscape-4ccd87725f22c8ea5fff4ef865b11e3c564d7520.zip | |
Add file export actions.
Diffstat (limited to 'src')
| -rw-r--r-- | src/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/actions/actions-output.cpp | 262 | ||||
| -rw-r--r-- | src/actions/actions-output.h | 29 | ||||
| -rw-r--r-- | src/inkscape-application.cpp | 20 | ||||
| -rw-r--r-- | src/inkscape-application.h | 1 |
5 files changed, 311 insertions, 3 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 9117122df..ae27d0953 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -287,6 +287,8 @@ set(main_SRC actions/actions-base.cpp actions/actions-helper.h actions/actions-helper.cpp + actions/actions-output.h + actions/actions-output.cpp actions/actions-selection.h actions/actions-selection.cpp ) diff --git a/src/actions/actions-output.cpp b/src/actions/actions-output.cpp new file mode 100644 index 000000000..f6a108acb --- /dev/null +++ b/src/actions/actions-output.cpp @@ -0,0 +1,262 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Gio::Actions for output tied to the application and without GUI. + * + * Copyright (C) 2018 Tavmjong Bah + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#include <iostream> + +#include <giomm.h> // Not <gtkmm.h>! To eventually allow a headless version! + +#include "actions-output.h" +#include "actions-helper.h" +#include "inkscape-application.h" + +#include "inkscape.h" // Inkscape::Application + +// Actions for command line output (should be intergrated with file dialog). + +// These actions are currently stateless and result in changes to an instance of the +// InkFileExportCmd class owned by the application. + +void +export_type(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<Glib::ustring> s = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring> >(value); + app->file_export()->export_type = s.get(); + std::cout << "export-type: " << s.get() << std::endl; +} + +void +export_filename(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<std::string> s = Glib::VariantBase::cast_dynamic<Glib::Variant<std::string> >(value); + app->file_export()->export_filename = s.get(); + std::cout << "export-filename: " << s.get() << std::endl; +} + +void +export_overwrite(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_overwrite = b.get(); + std::cout << "export-overwrite: " << std::boolalpha << b.get() << std::endl; +} + +void +export_area(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<std::string> s = Glib::VariantBase::cast_dynamic<Glib::Variant<std::string> >(value); + app->file_export()->export_area = s.get(); + std::cout << "export-area: " << s.get() << std::endl; +} + +void +export_area_drawing(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_area_drawing = b.get(); + std::cout << "export-area-drawing: " << std::boolalpha << b.get() << std::endl; +} + +void +export_area_page(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_area_page = b.get(); + std::cout << "export-area-page: " << std::boolalpha << b.get() << std::endl; +} + +void +export_margin(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<int> i = Glib::VariantBase::cast_dynamic<Glib::Variant<int> >(value); + app->file_export()->export_margin = i.get(); + std::cout << "export-margin: " << i.get() << std::endl; +} + +void +export_area_snap(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_area_snap = b.get(); + std::cout << "export-area-snap: " << std::boolalpha << b.get() << std::endl; +} + +void +export_width(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<int> i = Glib::VariantBase::cast_dynamic<Glib::Variant<int> >(value); + app->file_export()->export_width = i.get(); + std::cout << "export-width: " << i.get() << std::endl; +} + +void +export_height(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<int> i = Glib::VariantBase::cast_dynamic<Glib::Variant<int> >(value); + app->file_export()->export_height = i.get(); + std::cout << "export-height: " << i.get() << std::endl; +} + +void +export_id(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<std::string> s = Glib::VariantBase::cast_dynamic<Glib::Variant<std::string> >(value); + app->file_export()->export_id = s.get(); + std::cout << "export-id: " << s.get() << std::endl; +} + +void +export_id_only(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_id_only = b.get(); + std::cout << "export-id-only: " << std::boolalpha << b.get() << std::endl; +} + +void +export_plain_svg(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_plain_svg = b.get(); + std::cout << "export-plain-svg: " << std::boolalpha << b.get() << std::endl; +} + +void +export_dpi(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<int> i = Glib::VariantBase::cast_dynamic<Glib::Variant<int> >(value); + app->file_export()->export_dpi = i.get(); + std::cout << "export-dpi: " << i.get() << std::endl; +} + +void +export_ignore_filters(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_ignore_filters = b.get(); + std::cout << "export-ignore-filters: " << std::boolalpha << b.get() << std::endl; +} + +void +export_text_to_path(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_text_to_path = b.get(); + std::cout << "export-text-to-path: " << std::boolalpha << b.get() << std::endl; +} + +void +export_ps_level(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<int> i = Glib::VariantBase::cast_dynamic<Glib::Variant<int> >(value); + app->file_export()->export_ps_level = i.get(); + std::cout << "export-dpi: " << i.get() << std::endl; +} + +void +export_pdf_level(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<Glib::ustring> s = Glib::VariantBase::cast_dynamic<Glib::Variant<Glib::ustring> >(value); + app->file_export()->export_pdf_level = s.get(); + std::cout << "export-pdf-level" << s.get() << std::endl; +} + +void +export_latex(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_latex = b.get(); + std::cout << "export-latex: " << std::boolalpha << b.get() << std::endl; +} + +void +export_use_hints(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<bool> b = Glib::VariantBase::cast_dynamic<Glib::Variant<bool> >(value); + app->file_export()->export_use_hints = b.get(); + std::cout << "export-use-hints: " << std::boolalpha << b.get() << std::endl; +} + +void +export_background(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<std::string> s = Glib::VariantBase::cast_dynamic<Glib::Variant<std::string> >(value); + app->file_export()->export_background = s.get(); + std::cout << "export-background: " << s.get() << std::endl; +} + +void +export_background_opacity(const Glib::VariantBase& value, InkscapeApplication *app) +{ + Glib::Variant<double> d = Glib::VariantBase::cast_dynamic<Glib::Variant<double> >(value); + app->file_export()->export_background_opacity = d.get(); + std::cout << d.get() << std::endl; +} + +void +export_do(InkscapeApplication *app) +{ + SPDocument* document = app->get_active_document(); + std::string filename; + if (document->getURI()) { + filename = document->getURI(); + } + app->file_export()->do_export(document, filename); +} + +void +add_actions_output(InkscapeApplication* app) +{ + std::cout << "add_actions_output!" << std::endl; + Glib::VariantType Bool( Glib::VARIANT_TYPE_BOOL); + Glib::VariantType Int( Glib::VARIANT_TYPE_INT32); + Glib::VariantType Double(Glib::VARIANT_TYPE_DOUBLE); + Glib::VariantType String(Glib::VARIANT_TYPE_STRING); + Glib::VariantType BString(Glib::VARIANT_TYPE_BYTESTRING); + + // Matches command line options + app->add_action_with_parameter( "export-type", String, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_type), app)); + app->add_action_with_parameter( "export-filename", String, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_filename), app)); // MAY NOT WORK DUE TO std::string + app->add_action_with_parameter( "export-overwrite", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_overwrite), app)); + + app->add_action_with_parameter( "export-area", String, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_area), app)); + app->add_action_with_parameter( "export-area-drawing", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_area_drawing), app)); + app->add_action_with_parameter( "export-area-page", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_area_page), app)); + app->add_action_with_parameter( "export-margin", Int, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_margin), app)); + app->add_action_with_parameter( "export-area-snap", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_area_snap), app)); + app->add_action_with_parameter( "export-width", Int, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_width), app)); + app->add_action_with_parameter( "export-height", Int, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_height), app)); + + app->add_action_with_parameter( "export-id", String, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_id), app)); + app->add_action_with_parameter( "export-id-only", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_id_only), app)); + app->add_action_with_parameter( "export-plain-svg", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_plain_svg), app)); + app->add_action_with_parameter( "export-dpi", Int, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_dpi), app)); + app->add_action_with_parameter( "export-ignore-filters", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_plain_svg), app)); + app->add_action_with_parameter( "export-text-to-path", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_text_to_path), app)); + app->add_action_with_parameter( "export-ps-level", Int, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_ps_level), app)); + app->add_action_with_parameter( "export-pdf-level", String, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_pdf_level), app)); + app->add_action_with_parameter( "export-latex", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_latex), app)); + app->add_action_with_parameter( "export-use-hints", Bool, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_use_hints), app)); + app->add_action_with_parameter( "export-background", String, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_background), app)); + app->add_action_with_parameter( "export-background-opacity",Double, sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_background_opacity), app)); + + // Extra + app->add_action( "export-do", sigc::bind<InkscapeApplication*>(sigc::ptr_fun(&export_do), app)); +} + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/actions/actions-output.h b/src/actions/actions-output.h new file mode 100644 index 000000000..fffe1842d --- /dev/null +++ b/src/actions/actions-output.h @@ -0,0 +1,29 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Gio::Actions for output tied to the application and without GUI. + * + * Copyright (C) 2018 Tavmjong Bah + * + * The contents of this file may be used under the GNU General Public License Version 2 or later. + * + */ + +#ifndef INK_ACTIONS_OUTPUT_H +#define INK_ACTIONS_OUTPUT_H + +class InkscapeApplication; + +void add_actions_output(InkscapeApplication* app); + +#endif // INK_ACTIONS_OUTPUT_H + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 : diff --git a/src/inkscape-application.cpp b/src/inkscape-application.cpp index 7b3200dae..0a46e57dd 100644 --- a/src/inkscape-application.cpp +++ b/src/inkscape-application.cpp @@ -22,6 +22,7 @@ #include "desktop.h" // Access to window #include "actions/actions-base.h" // Actions +#include "actions/actions-output.h" // Actions #include "actions/actions-selection.h" // Actions #ifdef WITH_DBUS @@ -61,7 +62,8 @@ InkscapeApplication::InkscapeApplication() Glib::set_application_name(N_("Inkscape - A Vector Drawing Program")); // After gettext() init. // ======================== Actions ========================= - add_actions_base(this); // actions that are GUI independent + add_actions_base(this); // actions that are GUI independent + add_actions_output(this); // actions for file export add_actions_selection(this); // actions for object selection // ====================== Command Line ====================== @@ -330,15 +332,27 @@ InkscapeApplication::parse_actions(const Glib::ustring& input, action_vector_t& if (gtype) { // With value. Glib::VariantType type = action_ptr->get_parameter_type(); - if (type.get_string() == "s") { + if (type.get_string() == "b") { + bool b = false; + if (value == "0" || value == "true" || value.empty()) { + b = true; + } else if (value =="1" || value == "false") { + b = false; + } else { + std::cerr << "InkscapeApplication::parse_actions: Invalid boolean value: " << action << ":" << value << std::endl; + } + std::cout << "parse_actions boolean: " << value << ":" << std::boolalpha << b << std::endl; action_vector.push_back( - std::make_pair( action, Glib::Variant<Glib::ustring>::create(value) )); + std::make_pair( action, Glib::Variant<bool>::create(b))); } else if (type.get_string() == "i") { action_vector.push_back( std::make_pair( action, Glib::Variant<int>::create(std::stoi(value)))); } else if (type.get_string() == "d") { action_vector.push_back( std::make_pair( action, Glib::Variant<double>::create(std::stod(value)))); + } else if (type.get_string() == "s") { + action_vector.push_back( + std::make_pair( action, Glib::Variant<Glib::ustring>::create(value) )); } else { std::cerr << "InkscapeApplication::parse_actions: unhandled action value: " << action << ": " << type.get_string() << std::endl; diff --git a/src/inkscape-application.h b/src/inkscape-application.h index 28c89810a..1385d2bb2 100644 --- a/src/inkscape-application.h +++ b/src/inkscape-application.h @@ -37,6 +37,7 @@ public: static Glib::RefPtr<InkscapeApplication> create(); SPDocument* get_active_document(); + InkFileExportCmd* file_export() { return &_file_export; } protected: void on_startup() override; |
