summaryrefslogtreecommitdiff
path: root/sd
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2018-06-09 13:09:35 -0400
committerJan Holesovsky <kendy@collabora.com>2019-04-03 17:54:00 +0200
commit5a1f367b5573293cf3b2e8dbdffc7de22e99c058 (patch)
treecc43148087a3c2317905b4b0aa4c493cc024bd07 /sd
parent81ac2da0d0325fc74fafd09bc4f3c85a75fab352 (diff)
pdfium: Import PDF with unloaded images.
Change-Id: I5e4a16ff38b9643127ce16879b35f456c13bcff8 Reviewed-on: https://gerrit.libreoffice.org/56268 Reviewed-by: Ashod Nakashian <ashnakash@gmail.com> Tested-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'sd')
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx35
1 files changed, 13 insertions, 22 deletions
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 95daaeb479f1..3ef639853184 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -102,38 +102,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 (int i = 0; i < aGraphics.size() - 1; ++i)
{
mrDocument.DuplicatePage(0);
}
- size_t nPageNumber = 0;
- for (Bitmap& aBitmap : aBitmaps)
+ for (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.SetSharedLink(pGfxLink);
- aGraphic.setOriginURL(aFileName);
+ const Graphic& aGraphic = aPair.first;
+ const Size& aSize = aPair.second;
+
+ const sal_Int32 nPageNumber = aGraphic.getPageNumber();
+ if (nPageNumber < 0 || 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, aGraphic.GetPrefMapMode(),
MapMode(MapUnit::Map100thMM)));
// Resize to original size based on 72 dpi to preserve page size.