Kaydet (Commit) 33511374 authored tarafından Jan Holesovsky's avatar Jan Holesovsky

pdfium: Avoid unnecessary copying + some warning fixes.

Change-Id: I114fa6b2d3dda86c55eb245d31ca3a1019197ae9
Reviewed-on: https://gerrit.libreoffice.org/56285Reviewed-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
Tested-by: 's avatarAshod Nakashian <ashnakash@gmail.com>
üst 5a1f367b
...@@ -108,7 +108,7 @@ bool SdPdfFilter::Import() ...@@ -108,7 +108,7 @@ bool SdPdfFilter::Import()
// Add as many pages as we need up-front. // Add as many pages as we need up-front.
mrDocument.CreateFirstPages(); mrDocument.CreateFirstPages();
for (int i = 0; i < aGraphics.size() - 1; ++i) for (size_t i = 0; i < aGraphics.size() - 1; ++i)
{ {
mrDocument.DuplicatePage(0); mrDocument.DuplicatePage(0);
} }
...@@ -119,8 +119,7 @@ bool SdPdfFilter::Import() ...@@ -119,8 +119,7 @@ bool SdPdfFilter::Import()
const Size& aSize = aPair.second; const Size& aSize = aPair.second;
const sal_Int32 nPageNumber = aGraphic.getPageNumber(); const sal_Int32 nPageNumber = aGraphic.getPageNumber();
if (nPageNumber < 0 || nPageNumber >= aGraphics.size()) assert(nPageNumber >= 0 && nPageNumber < static_cast<sal_Int32>(aGraphics.size()));
continue; // Page is out of range
// Create the page and insert the Graphic. // Create the page and insert the Graphic.
SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard); SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard);
......
...@@ -301,19 +301,17 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si ...@@ -301,19 +301,17 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
return 0; return 0;
// Copy into PdfData // Copy into PdfData
uno::Sequence<sal_Int8> aPdfData;
aMemoryStream.Seek(STREAM_SEEK_TO_END); aMemoryStream.Seek(STREAM_SEEK_TO_END);
aPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.Tell()); auto pPdfData = std::make_shared<css::uno::Sequence<sal_Int8>>(aMemoryStream.Tell());
aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN); aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
aMemoryStream.ReadBytes(aPdfData.getArray(), aPdfData.getLength()); aMemoryStream.ReadBytes(pPdfData->getArray(), pPdfData->getLength());
// Prepare the link with the PDF stream. // Prepare the link with the PDF stream.
const size_t nGraphicContentSize = aPdfData.getLength(); const size_t nGraphicContentSize = pPdfData->getLength();
std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]); std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
memcpy(pGraphicContent.get(), aPdfData.get(), nGraphicContentSize); memcpy(pGraphicContent.get(), pPdfData->get(), nGraphicContentSize);
std::shared_ptr<GfxLink> pGfxLink(std::make_shared<GfxLink>( std::shared_ptr<GfxLink> pGfxLink(std::make_shared<GfxLink>(
std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf)); std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf));
auto pPdfData = std::make_shared<uno::Sequence<sal_Int8>>(aPdfData);
FPDF_LIBRARY_CONFIG aConfig; FPDF_LIBRARY_CONFIG aConfig;
aConfig.version = 2; aConfig.version = 2;
...@@ -324,7 +322,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si ...@@ -324,7 +322,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
// Load the buffer using pdfium. // Load the buffer using pdfium.
FPDF_DOCUMENT pPdfDocument FPDF_DOCUMENT pPdfDocument
= FPDF_LoadMemDocument(aPdfData.getArray(), aPdfData.getLength(), /*password=*/nullptr); = FPDF_LoadMemDocument(pPdfData->getArray(), pPdfData->getLength(), /*password=*/nullptr);
if (!pPdfDocument) if (!pPdfDocument)
return 0; return 0;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment