diff --git a/src/extension/CMakeLists.txt b/src/extension/CMakeLists.txt index 5708c2ee00a6c7328421b3d6946021ab12aedec8..a304763258657e9d2b34a1ff76decb5cfa47ddbb 100644 --- a/src/extension/CMakeLists.txt +++ b/src/extension/CMakeLists.txt @@ -43,6 +43,7 @@ set(extension_SRC internal/text_reassemble.c internal/wmf-inout.cpp internal/wmf-print.cpp + internal/offset-path.cpp internal/filter/filter-all.cpp internal/filter/filter-file.cpp @@ -131,6 +132,7 @@ set(extension_SRC internal/text_reassemble.h internal/wmf-inout.h internal/wmf-print.h + internal/offset-path.h prefdialog/prefdialog.h prefdialog/parameter.h diff --git a/src/extension/init.cpp b/src/extension/init.cpp index 5a95fb8efa0cb01eb19863187cddc27ae41da701..d49fe24c5260a58d33ec7d07988105df2aa7b07d 100644 --- a/src/extension/init.cpp +++ b/src/extension/init.cpp @@ -50,6 +50,7 @@ #include "internal/latex-pstricks.h" #include "internal/gdkpixbuf-input.h" #include "internal/bluredge.h" +#include "internal/offset-path.h" #include "internal/gimpgrad.h" #include "internal/grid.h" #ifdef WITH_LIBWPG @@ -186,6 +187,7 @@ init() Internal::BlurEdge::init(); Internal::GimpGrad::init(); Internal::Grid::init(); + Internal::OffsetPath::init(); #ifdef WITH_DBUS Dbus::init(); diff --git a/src/extension/internal/bluredge.cpp b/src/extension/internal/bluredge.cpp index 80fa4f2320bd3986335a1a622526e8a0ae67e05d..7fd0f0388da7ec6a358026d2041cdfc65374c8c8 100644 --- a/src/extension/internal/bluredge.cpp +++ b/src/extension/internal/bluredge.cpp @@ -1,6 +1,6 @@ // SPDX-License-Identifier: GPL-2.0-or-later /** - \file bluredge.cpp + \file bluredgr.cpp A plug-in to add an effect to blur the edges of an object. */ diff --git a/src/extension/internal/offset-path.cpp b/src/extension/internal/offset-path.cpp new file mode 100644 index 0000000000000000000000000000000000000000..d302dbbf0179eb5691da1dbba8503179901c6d2d --- /dev/null +++ b/src/extension/internal/offset-path.cpp @@ -0,0 +1,144 @@ +/// SPDX-License-Identifier: GPL-2.0-or-later +/// @auth:sabagara +/// @brief Size Specification Offset Extension + +#include "offset-path.h" + +#include +#include +#include +#include + +#include "desktop.h" +#include "document.h" +#include "extension/effect.h" +#include "extension/system.h" +#include "message-stack.h" +#include "object/sp-item.h" +#include "path-chemistry.h" +#include "selection.h" +#include "splivarot.h" +#include "ui/interface.h" +#include "ui/view/view.h" +#include "util/units.h" + +static char const *const OFFSET_DEFAULT_UNIT_NAME = DEFAULT_UNIT_NAME; + +namespace Inkscape { +namespace Extension { +namespace Internal { + +/// Load Extension +bool OffsetPath::load(Inkscape::Extension::Extension *) +{ + return TRUE; +} + +/// Exec Offset +void OffsetPath::effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *desktop, Inkscape::Extension::Implementation::ImplementationDocumentCache *) +{ + // Get parameter from extension form + std::string offset_str; + try { + offset_str = module->get_param_string("offset"); + } + catch (...) { + g_error("Parameter might not exist"); + return; + } + + // Paser offset (num/unit) + double offset_size = 0.0f; + std::string offset_unit = "px"; + std::regex regexNum("^(-?\\d+\\.?\\d*)\\s*(|px|in|mm|pc|cm|pt)$"); + std::smatch match; + if (std::regex_match(offset_str, match, regexNum)) { + if (match.size() == 3) { + offset_size = boost::lexical_cast(match[1]); + offset_unit = match[2]; + } + } + else { + gchar *const warning_dialog_message = g_strdup_printf("%s (%s)", N_("Invalid Offset Size specification."), offset_str.c_str()); + g_warning("%s", warning_dialog_message); + sp_ui_error_dialog(warning_dialog_message); + g_free(warning_dialog_message); + return; + } + + // Size Unit Change + offset_size = Inkscape::Util::Quantity::convert(offset_size, offset_unit, OFFSET_DEFAULT_UNIT_NAME); + g_debug("new offset_size(mm):%f", offset_size); + + // Put selected item into container + Inkscape::Selection *const selection = static_cast(desktop)->selection; + std::vector items(selection->items().begin(), selection->items().end()); + selection->clear(); + + for (SPItem *const spitem : items) { + // Duplicate target node + Inkscape::XML::Document *const xml_doc = desktop->doc()->getReprDoc(); + Inkscape::XML::Node *const new_item = spitem->getRepr()->duplicate(xml_doc); + spitem->getRepr()->parent()->appendChild(new_item); + selection->add(new_item); + selection->toCurves(); + + // Offset (offset unit is mm) + if (0.0 < offset_size) { + sp_selected_path_do_offset(static_cast(desktop), true, offset_size); + } + else if (offset_size < 0.0) { + sp_selected_path_do_offset(static_cast(desktop), false, -offset_size); + } + + selection->clear(); + } +} + +/// Preference effect +Gtk::Widget *OffsetPath::prefs_effect(Inkscape::Extension::Effect *const module, Inkscape::UI::View::View *, sigc::signal *const changeSignal, Inkscape::Extension::Implementation::ImplementationDocumentCache *) +{ + return module->autogui(nullptr, nullptr, changeSignal); +} + +#include "clear-n_.h" + +/// Extension Setting +void OffsetPath::init() +{ + Inkscape::Preferences *const prefs = Inkscape::Preferences::get(); + double const pref_offset = prefs->getDouble("/options/defaultoffsetwidth/value", 1.0, OFFSET_DEFAULT_UNIT_NAME); + + gchar *const extension_manifest = g_strdup_printf( + "\n" + "" N_("Offset Path") "\n" + "org.inkscape.effect.offset-path\n" + "%.2f mm\n" + "\n" + "all\n" + "\n" + "\n" + "\n" + "\n" + "\n", + pref_offset + ); + + Inkscape::Extension::build_from_mem(extension_manifest, new OffsetPath()); + g_free(extension_manifest); +} + +}; // namespace Internal +}; // namespace Extension +}; // namespace Inkscape + +/* + 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/extension/internal/offset-path.h b/src/extension/internal/offset-path.h new file mode 100644 index 0000000000000000000000000000000000000000..fb77602dd55a7862097af94901dfe64fc3fb02d9 --- /dev/null +++ b/src/extension/internal/offset-path.h @@ -0,0 +1,42 @@ +/// SPDX-License-Identifier: GPL-2.0-or-later +/// @auth:sabagara +/// @brief Size Specification Offset Extension + +#include "extension/implementation/implementation.h" + +namespace Inkscape { +namespace Extension { + +class Effect; +class Extension; + +namespace Internal { + +class OffsetPath : public Inkscape::Extension::Implementation::Implementation { +public: + /// Load Extension + bool load(Inkscape::Extension::Extension *module) override; + + /// Exec Offset + void effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *document, Inkscape::Extension::Implementation::ImplementationDocumentCache *docCache) override; + + /// Extension Setting + Gtk::Widget *prefs_effect(Inkscape::Extension::Effect *module, Inkscape::UI::View::View *view, sigc::signal *changeSignal, Inkscape::Extension::Implementation::ImplementationDocumentCache *docCache) override; + + static void init(); +}; + +}; // namespace Internal +}; // namespace Extension +}; // namespace Inkscape + +/* + 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/splivarot.cpp b/src/splivarot.cpp index ebd6b3c7e872f8a22b54bd10c43447846aac2687..d0d3e9cecabb46bb69f26b8f7bdd68e97493510e 100644 --- a/src/splivarot.cpp +++ b/src/splivarot.cpp @@ -64,7 +64,6 @@ using Inkscape::DocumentUndo; bool Ancetre(Inkscape::XML::Node *a, Inkscape::XML::Node *who); -void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset); void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool updating); bool Inkscape::ObjectSet::pathUnion(const bool skip_undo) { @@ -1834,17 +1833,6 @@ void sp_selected_path_create_offset_object(SPDesktop *desktop, int expand, bool delete orig; } - - - - - - - - - - - void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset) { diff --git a/src/splivarot.h b/src/splivarot.h index 2c09b9160f5f77c7466c531a40609fa9ee400d95..039d0cdd276668cdcba9aa1b7a950ccfe2ac7ca7 100644 --- a/src/splivarot.h +++ b/src/splivarot.h @@ -35,6 +35,7 @@ void sp_selected_path_create_offset (SPDesktop *desktop); void sp_selected_path_create_inset (SPDesktop *desktop); void sp_selected_path_create_updating_offset (SPDesktop *desktop); void sp_selected_path_create_updating_inset (SPDesktop *desktop); +void sp_selected_path_do_offset(SPDesktop *desktop, bool expand, double prefOffset); void sp_selected_path_create_offset_object_zero (SPDesktop *desktop); void sp_selected_path_create_updating_offset_object_zero (SPDesktop *desktop);