From 9bba313d56fd87fc0a5033f566c3d63fe3c3d53e Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Tue, 28 May 2019 13:48:16 +0300 Subject: Fix segfault for bad `--pdf-page` argument values pdf-page value sanitization should be done after total number of pages is available, so it's can't be done in inkscape.h On negative or greater-than-number-of-pages values 1) the error message is printed to stderr 2) first page gets import pdf-page==0 sanitized elsewhere, so no error message is printed in this case --- src/extension/internal/pdfinput/pdf-input.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src/extension') diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index 3ff599ebf..5e0bb16e2 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -62,6 +62,19 @@ #include + +namespace { + void sanitize_page_number(int& page_num, const int num_pages){ + if (page_num < 1 || page_num > num_pages){ + std::cerr << "Inkscape::Extension::Internal::PdfInput::open: Bad page number " + << page_num + << ". Import first page instead." + << std::endl; + page_num = 1; + } + } +} + namespace Inkscape { namespace Extension { namespace Internal { @@ -815,6 +828,8 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { sp_repr_get_double(prefs, "cropTo", &crop_setting); Catalog *catalog = pdf_doc->getCatalog(); + int const num_pages = catalog->getNumPages(); + sanitize_page_number(page_num, num_pages); Page *page = catalog->getPage(page_num); if ( crop_setting >= 0.0 ) { // Do page clipping @@ -899,6 +914,8 @@ PdfInput::open(::Inkscape::Extension::Input * /*mod*/, const gchar * uri) { if (document != NULL) { double width, height; + int const num_pages = poppler_document_get_n_pages(document); + sanitize_page_number(page_num, num_pages); PopplerPage* page = poppler_document_get_page(document, page_num - 1); poppler_page_get_size(page, &width, &height); -- cgit v1.2.3 From a290421b993dd260112ddc86fc8ba3496bcbaef8 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Tue, 28 May 2019 14:14:18 +0300 Subject: Fix formatting --- src/extension/internal/pdfinput/pdf-input.cpp | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'src/extension') diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index 5e0bb16e2..0a543ca1a 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -64,15 +64,17 @@ namespace { - void sanitize_page_number(int& page_num, const int num_pages){ - if (page_num < 1 || page_num > num_pages){ - std::cerr << "Inkscape::Extension::Internal::PdfInput::open: Bad page number " - << page_num - << ". Import first page instead." - << std::endl; - page_num = 1; - } - } + +void sanitize_page_number(int &page_num, const int num_pages) { + if (page_num < 1 || page_num > num_pages) { + std::cerr << "Inkscape::Extension::Internal::PdfInput::open: Bad page number " + << page_num + << ". Import first page instead." + << std::endl; + page_num = 1; + } +} + } namespace Inkscape { -- cgit v1.2.3 From 437e28d328fd12bc757245cb8aa5039172811661 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Mon, 27 May 2019 00:59:36 +0300 Subject: feature: Allow effect extensions to disable working dialog Effect extensions with custom GUI don't need 'effect is working' dialog window which distracts from effect main window. New "suppress-working-dialog" optional attribute added to effect node of `.inx` file. --- src/extension/effect.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'src/extension') diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index f69ece42f..618b6f84a 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -63,6 +63,9 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) { no_live_preview = true; } + if (child->attribute("suppress-working-dialog") && !strcmp(child->attribute("suppress-working-dialog"), "true")) { + _workingDialog = false; + } for (Inkscape::XML::Node *effect_child = child->firstChild(); effect_child != nullptr; effect_child = effect_child->next()) { if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "effects-menu")) { // printf("Found local effects menu in %s\n", this->get_name()); @@ -269,7 +272,7 @@ Effect::effect (Inkscape::UI::View::View * doc) if (!loaded()) set_state(Extension::STATE_LOADED); if (!loaded()) return; - ExecutionEnv executionEnv(this, doc); + ExecutionEnv executionEnv(this, doc, nullptr, _workingDialog, true); execution_env = &executionEnv; timer->lock(); executionEnv.run(); -- cgit v1.2.3 From 40b26e345fc729d5cc89105c437c2b934da8dd0e Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Mon, 27 May 2019 20:13:14 +0300 Subject: Rename "suppress-working-dialog" effect attribute to "application" --- src/extension/effect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/extension') diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 618b6f84a..d0079e7cc 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -63,7 +63,7 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) { no_live_preview = true; } - if (child->attribute("suppress-working-dialog") && !strcmp(child->attribute("suppress-working-dialog"), "true")) { + if (child->attribute("application") && !strcmp(child->attribute("application"), "true")) { _workingDialog = false; } for (Inkscape::XML::Node *effect_child = child->firstChild(); effect_child != nullptr; effect_child = effect_child->next()) { -- cgit v1.2.3 From 9317c612c998b18b2334ea17ca89d9b9e2a97085 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Mon, 27 May 2019 20:14:01 +0300 Subject: Fix indentation --- src/extension/effect.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/extension') diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index d0079e7cc..2b08e4da1 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -58,13 +58,13 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * for (Inkscape::XML::Node *child = repr->firstChild(); child != nullptr; child = child->next()) { if (!strcmp(child->name(), INKSCAPE_EXTENSION_NS "effect")) { if (child->attribute("needs-document") && !strcmp(child->attribute("needs-document"), "false")) { - no_doc = true; + no_doc = true; } if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) { - no_live_preview = true; + no_live_preview = true; } if (child->attribute("application") && !strcmp(child->attribute("application"), "true")) { - _workingDialog = false; + _workingDialog = false; } for (Inkscape::XML::Node *effect_child = child->firstChild(); effect_child != nullptr; effect_child = effect_child->next()) { if (!strcmp(effect_child->name(), INKSCAPE_EXTENSION_NS "effects-menu")) { -- cgit v1.2.3 From c79a9bc365eb0b1f638e7ffa670dffb61c665e22 Mon Sep 17 00:00:00 2001 From: Sergei Izmailov Date: Wed, 29 May 2019 02:59:11 +0300 Subject: Rename effect attribute to "implements-custom-gui" Effect with `implements-custom-gui="true"` MUST implement custom GUI --- src/extension/effect.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/extension') diff --git a/src/extension/effect.cpp b/src/extension/effect.cpp index 2b08e4da1..3c9940240 100644 --- a/src/extension/effect.cpp +++ b/src/extension/effect.cpp @@ -63,7 +63,7 @@ Effect::Effect (Inkscape::XML::Node * in_repr, Implementation::Implementation * if (child->attribute("needs-live-preview") && !strcmp(child->attribute("needs-live-preview"), "false")) { no_live_preview = true; } - if (child->attribute("application") && !strcmp(child->attribute("application"), "true")) { + if (child->attribute("implements-custom-gui") && !strcmp(child->attribute("implements-custom-gui"), "true")) { _workingDialog = false; } for (Inkscape::XML::Node *effect_child = child->firstChild(); effect_child != nullptr; effect_child = effect_child->next()) { -- cgit v1.2.3