diff options
| author | Alexander Valavanis <valavanisalex@gmail.com> | 2019-06-05 19:33:55 +0000 |
|---|---|---|
| committer | Alexander Valavanis <valavanisalex@gmail.com> | 2019-06-05 19:33:55 +0000 |
| commit | 2e40143d6e75d50bf659abddc5c7c25fb1bc2436 (patch) | |
| tree | e2fa747c95569dc3f77fcdfa770b3d404ff065cc /src/extension/internal/pdfinput/pdf-input.cpp | |
| parent | Hackfest2019: Rm tautological tests (diff) | |
| parent | Use a flowbox when there are more than two options for font feature settings. (diff) | |
| download | inkscape-2e40143d6e75d50bf659abddc5c7c25fb1bc2436.tar.gz inkscape-2e40143d6e75d50bf659abddc5c7c25fb1bc2436.zip | |
Merge changes
Diffstat (limited to 'src/extension/internal/pdfinput/pdf-input.cpp')
| -rw-r--r-- | src/extension/internal/pdfinput/pdf-input.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/extension/internal/pdfinput/pdf-input.cpp b/src/extension/internal/pdfinput/pdf-input.cpp index ed6af682e..2a3947ec1 100644 --- a/src/extension/internal/pdfinput/pdf-input.cpp +++ b/src/extension/internal/pdfinput/pdf-input.cpp @@ -62,6 +62,21 @@ #include <gdkmm/general.h> + +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 { @@ -788,6 +803,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 @@ -872,6 +889,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); |
