summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-09 13:09:35 -0400
committerAshod Nakashian <ashnakash@gmail.com>2019-08-25 13:31:53 +0200
commit9194f019afb0599d5e72476786fabfa996e07f20 (patch)
treee6c1e044e5f2eca5b52cb938d4fd9a13734096e8 /sd
parente4cec56a699b75102c39f4f80879a8080fc5ecc1 (diff)
pdfium: Import PDF with unloaded images.
Reviewed-on: https://gerrit.libreoffice.org/56268 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com> (cherry picked from commit e07561d2ae743b208a0807ef32d7f011614b73e5) Change-Id: I5e4a16ff38b9643127ce16879b35f456c13bcff8 Reviewed-on: https://gerrit.libreoffice.org/77688 Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx36
1 files changed, 14 insertions, 22 deletions
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 3fe38252b626..0cf7baa9dd6c 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -54,37 +54,29 @@ bool SdPdfFilter::Import()
// Rendering resolution.
const double dResolutionDPI = 96.;
- uno::Sequence<sal_Int8> aPdfData;
- std::vector<Bitmap> aBitmaps;
- if (vcl::ImportPDF(aFileName, aBitmaps, aPdfData, dResolutionDPI) == 0)
+ std::vector<std::pair<Graphic, Size>> aGraphics;
+ if (vcl::ImportPDFUnloaded(aFileName, aGraphics, dResolutionDPI) == 0)
return false;
- // Prepare the link with the PDF stream.
- const size_t nGraphicContentSize = aPdfData.getLength();
- std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
- memcpy(pGraphicContent.get(), aPdfData.get(), nGraphicContentSize);
- std::shared_ptr<GfxLink> pGfxLink(std::make_shared<GfxLink>(
- std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf));
- auto pPdfData = std::make_shared<uno::Sequence<sal_Int8>>(aPdfData);
-
+ // Add as many pages as we need up-front.
mrDocument.CreateFirstPages();
- for (size_t i = 0; i < aBitmaps.size() - 1; ++i)
+ for (size_t i = 0; i < aGraphics.size() - 1; ++i)
{
mrDocument.DuplicatePage(0);
}
- size_t nPageNumber = 0;
- for (const Bitmap& aBitmap : aBitmaps)
+ for (const std::pair<Graphic, Size>& aPair : aGraphics)
{
- // Create the Graphic and link the original PDF stream.
- Graphic aGraphic(aBitmap);
- aGraphic.setPdfData(pPdfData);
- aGraphic.setPageNumber(nPageNumber);
- aGraphic.SetGfxLink(pGfxLink);
+ const Graphic& rGraphic = aPair.first;
+ const Size& aSize = aPair.second;
+
+ const sal_Int32 nPageNumber = rGraphic.getPageNumber();
+ if (nPageNumber < 0 || static_cast<size_t>(nPageNumber) >= aGraphics.size())
+ continue; // Page is out of range
// Create the page and insert the Graphic.
- SdPage* pPage = mrDocument.GetSdPage(nPageNumber++, PageKind::Standard);
- Size aGrfSize(OutputDevice::LogicToLogic(aGraphic.GetPrefSize(), aGraphic.GetPrefMapMode(),
+ SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard);
+ Size aGrfSize(OutputDevice::LogicToLogic(aSize, rGraphic.GetPrefMapMode(),
MapMode(MapUnit::Map100thMM)));
// Resize to original size based on 72 dpi to preserve page size.
@@ -95,7 +87,7 @@ bool SdPdfFilter::Import()
pPage->SetSize(aGrfSize);
Point aPos(0, 0);
- pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), aGraphic,
+ pPage->InsertObject(new SdrGrafObj(pPage->getSdrModelFromSdrPage(), rGraphic,
tools::Rectangle(aPos, aGrfSize)));
}