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>2018-06-22 14:43:48 +0200
commit204353d270b8df4659a2f854efc636955e9e2ef9 (patch)
tree7819f77c4e470efb616c37a097af508a4b028738 /sd
parentf2ea104c48965ff2c3dbc6fd9d3e231c4c4b1459 (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.cxx34
1 files changed, 13 insertions, 21 deletions
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 8ca237fd6345..62dbc3964f35 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -102,37 +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.