summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorJan Holesovsky <kendy@collabora.com>2019-04-02 22:12:28 +0200
committerAshod Nakashian <ashnakash@gmail.com>2019-08-25 13:42:06 +0200
commiteb581eff6ac41b938299b4c154ded6891bdd0c11 (patch)
tree8cc33a7850cc65d754667d7d1dfb3376b2428f1c /vcl
parent81f73f1c1706d790c010e8fc0abcb2a0e9e86ace (diff)
pdfium: Use std::vector to hold the PdfData.
This fixes the destruction of the static cache of the PDF data; without this, there were already missing uno runtime info. (cherry picked from commit 20055ebe1b27f716a2acf1f0f4dda2864ae811bf) Change-Id: I877c9ccf96c4b7eabf3d643e17f324d86d987f94 Reviewed-on: https://gerrit.libreoffice.org/77691 Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnakash@gmail.com>
Diffstat (limited to 'vcl')
-rw-r--r--vcl/inc/impgraph.hxx8
-rw-r--r--vcl/source/filter/ipdf/pdfread.cxx27
-rw-r--r--vcl/source/gdi/graph.cxx8
-rw-r--r--vcl/source/gdi/impgraph.cxx20
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx10
-rw-r--r--vcl/source/gdi/pdfwriter_impl.hxx4
6 files changed, 39 insertions, 38 deletions
diff --git a/vcl/inc/impgraph.hxx b/vcl/inc/impgraph.hxx
index 8837dc63903c..1a1d2f283f1c 100644
--- a/vcl/inc/impgraph.hxx
+++ b/vcl/inc/impgraph.hxx
@@ -91,7 +91,7 @@ private:
/// The PDF stream from which this Graphic is rendered,
/// as converted (version downgraded) from the original,
/// which should be in GfxLink.
- std::shared_ptr<css::uno::Sequence<sal_Int8>> mpPdfData;
+ std::shared_ptr<std::vector<sal_Int8>> mpPdfData;
std::unique_ptr<GraphicID> mpGraphicID;
GraphicExternalLink maGraphicExternalLink;
@@ -143,7 +143,7 @@ private:
bool hasPdfData() const
{
- return mpPdfData && mpPdfData->hasElements();
+ return mpPdfData && !mpPdfData->empty();
}
void ImplCreateSwapInfo();
@@ -227,9 +227,9 @@ private:
const VectorGraphicDataPtr& getVectorGraphicData() const;
- const std::shared_ptr<css::uno::Sequence<sal_Int8>>& getPdfData() const;
+ const std::shared_ptr<std::vector<sal_Int8>>& getPdfData() const;
- void setPdfData(const std::shared_ptr<css::uno::Sequence<sal_Int8>>& rPdfData);
+ void setPdfData(const std::shared_ptr<std::vector<sal_Int8>>& rPdfData);
bool ensureAvailable () const;
diff --git a/vcl/source/filter/ipdf/pdfread.cxx b/vcl/source/filter/ipdf/pdfread.cxx
index b7b43c1d0d4d..bd406deac93e 100644
--- a/vcl/source/filter/ipdf/pdfread.cxx
+++ b/vcl/source/filter/ipdf/pdfread.cxx
@@ -18,6 +18,7 @@
#endif
#include <impgraph.hxx>
+
#include <vcl/graph.hxx>
#include <bitmapwriteaccess.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -213,7 +214,7 @@ size_t RenderPDFBitmaps(const void* pBuffer, int nSize, std::vector<Bitmap>& rBi
}
bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
- css::uno::Sequence<sal_Int8>& rPdfData, sal_uInt64 nPos, sal_uInt64 nSize,
+ std::vector<sal_Int8>& rPdfData, sal_uInt64 nPos, sal_uInt64 nSize,
const double fResolutionDPI)
{
// Get the preview of the first page.
@@ -229,27 +230,27 @@ bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, size_t nPageIndex,
if (!getCompatibleStream(rStream, aMemoryStream, nPos, nSize))
return false;
- rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.TellEnd());
+ rPdfData = std::vector<sal_Int8>(aMemoryStream.TellEnd());
aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
- aMemoryStream.ReadBytes(rPdfData.getArray(), rPdfData.getLength());
+ aMemoryStream.ReadBytes(rPdfData.data(), rPdfData.size());
return true;
}
bool ImportPDF(SvStream& rStream, Graphic& rGraphic, const double fResolutionDPI)
{
- uno::Sequence<sal_Int8> aPdfData;
+ std::vector<sal_Int8> aPdfData;
Bitmap aBitmap;
const bool bRet = ImportPDF(rStream, aBitmap, 0, aPdfData, STREAM_SEEK_TO_BEGIN,
STREAM_SEEK_TO_END, fResolutionDPI);
rGraphic = aBitmap;
- rGraphic.setPdfData(std::make_shared<css::uno::Sequence<sal_Int8>>(aPdfData));
+ rGraphic.setPdfData(std::make_shared<std::vector<sal_Int8>>(aPdfData));
rGraphic.setPageNumber(0); // We currently import only the first page.
return bRet;
}
size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
- css::uno::Sequence<sal_Int8>& rPdfData, const double fResolutionDPI)
+ std::vector<sal_Int8>& rPdfData, const double fResolutionDPI)
{
std::unique_ptr<SvStream> xStream(
::utl::UcbStreamHelper::CreateStream(rURL, StreamMode::READ | StreamMode::SHARE_DENYNONE));
@@ -264,9 +265,9 @@ size_t ImportPDF(const OUString& rURL, std::vector<Bitmap>& rBitmaps,
if (!getCompatibleStream(*xStream, aMemoryStream, STREAM_SEEK_TO_BEGIN, STREAM_SEEK_TO_END))
return 0;
- rPdfData = css::uno::Sequence<sal_Int8>(aMemoryStream.TellEnd());
+ rPdfData = std::vector<sal_Int8>(aMemoryStream.TellEnd());
aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
- aMemoryStream.ReadBytes(rPdfData.getArray(), rPdfData.getLength());
+ aMemoryStream.ReadBytes(rPdfData.data(), rPdfData.size());
return rBitmaps.size();
}
@@ -284,14 +285,14 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
// Copy into PdfData
aMemoryStream.Seek(STREAM_SEEK_TO_END);
- auto pPdfData = std::make_shared<css::uno::Sequence<sal_Int8>>(aMemoryStream.Tell());
+ auto pPdfData = std::make_shared<std::vector<sal_Int8>>(aMemoryStream.Tell());
aMemoryStream.Seek(STREAM_SEEK_TO_BEGIN);
- aMemoryStream.ReadBytes(pPdfData->getArray(), pPdfData->getLength());
+ aMemoryStream.ReadBytes(pPdfData->data(), pPdfData->size());
// Prepare the link with the PDF stream.
- const size_t nGraphicContentSize = pPdfData->getLength();
+ const size_t nGraphicContentSize = pPdfData->size();
std::unique_ptr<sal_uInt8[]> pGraphicContent(new sal_uInt8[nGraphicContentSize]);
- memcpy(pGraphicContent.get(), pPdfData->get(), nGraphicContentSize);
+ memcpy(pGraphicContent.get(), pPdfData->data(), nGraphicContentSize);
std::shared_ptr<GfxLink> pGfxLink(std::make_shared<GfxLink>(
std::move(pGraphicContent), nGraphicContentSize, GfxLinkType::NativePdf));
@@ -304,7 +305,7 @@ size_t ImportPDFUnloaded(const OUString& rURL, std::vector<std::pair<Graphic, Si
// Load the buffer using pdfium.
FPDF_DOCUMENT pPdfDocument
- = FPDF_LoadMemDocument(pPdfData->getArray(), pPdfData->getLength(), /*password=*/nullptr);
+ = FPDF_LoadMemDocument(pPdfData->data(), pPdfData->size(), /*password=*/nullptr);
if (!pPdfDocument)
return 0;
diff --git a/vcl/source/gdi/graph.cxx b/vcl/source/gdi/graph.cxx
index 06d9c80d321a..5159145cb055 100644
--- a/vcl/source/gdi/graph.cxx
+++ b/vcl/source/gdi/graph.cxx
@@ -547,21 +547,21 @@ const VectorGraphicDataPtr& Graphic::getVectorGraphicData() const
return mxImpGraphic->getVectorGraphicData();
}
-void Graphic::setPdfData(const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData)
+void Graphic::setPdfData(const std::shared_ptr<std::vector<sal_Int8>>& rPdfData)
{
ImplTestRefCount();
mxImpGraphic->setPdfData(rPdfData);
}
-const std::shared_ptr<uno::Sequence<sal_Int8>>& Graphic::getPdfData() const
+const std::shared_ptr<std::vector<sal_Int8>>& Graphic::getPdfData() const
{
return mxImpGraphic->getPdfData();
}
bool Graphic::hasPdfData() const
{
- std::shared_ptr<uno::Sequence<sal_Int8>> pPdfData = getPdfData();
- return pPdfData && pPdfData->hasElements();
+ std::shared_ptr<std::vector<sal_Int8>> pPdfData = getPdfData();
+ return pPdfData && !pPdfData->empty();
}
void Graphic::setPageNumber(sal_Int32 nPageNumber)
diff --git a/vcl/source/gdi/impgraph.cxx b/vcl/source/gdi/impgraph.cxx
index 7547853eba2a..8a1936020051 100644
--- a/vcl/source/gdi/impgraph.cxx
+++ b/vcl/source/gdi/impgraph.cxx
@@ -125,13 +125,13 @@ GraphicID::GraphicID(ImpGraphic const & rGraphic)
}
else if (rGraphic.hasPdfData())
{
- std::shared_ptr<css::uno::Sequence<sal_Int8>> pPdfData = rGraphic.getPdfData();
+ std::shared_ptr<std::vector<sal_Int8>> pPdfData = rGraphic.getPdfData();
const BitmapEx& rBmpEx = rGraphic.ImplGetBitmapExRef();
mnID1 |= (rGraphic.mnPageNumber & 0x0fffffff);
mnID2 = rBmpEx.GetSizePixel().Width();
mnID3 = rBmpEx.GetSizePixel().Height();
- mnID4 = vcl_get_checksum(0, pPdfData->getConstArray(), pPdfData->getLength());
+ mnID4 = vcl_get_checksum(0, pPdfData->data(), pPdfData->size());
}
else if (rGraphic.ImplIsAnimated())
{
@@ -439,7 +439,7 @@ bool ImpGraphic::operator==( const ImpGraphic& rImpGraphic ) const
bRet = (*maVectorGraphicData) == (*rImpGraphic.maVectorGraphicData);
}
}
- else if (mpPdfData && mpPdfData->hasElements())
+ else if (mpPdfData && !mpPdfData->empty())
{
bRet = (rImpGraphic.mpPdfData && *mpPdfData == *rImpGraphic.mpPdfData);
}
@@ -470,14 +470,14 @@ const VectorGraphicDataPtr& ImpGraphic::getVectorGraphicData() const
return maVectorGraphicData;
}
-void ImpGraphic::setPdfData(const std::shared_ptr<uno::Sequence<sal_Int8>>& rPdfData)
+void ImpGraphic::setPdfData(const std::shared_ptr<std::vector<sal_Int8>>& rPdfData)
{
ensureAvailable();
mpPdfData = rPdfData;
}
-const std::shared_ptr<uno::Sequence<sal_Int8>>& ImpGraphic::getPdfData() const
+const std::shared_ptr<std::vector<sal_Int8>>& ImpGraphic::getPdfData() const
{
ensureAvailable();
@@ -1696,10 +1696,10 @@ BitmapChecksum ImpGraphic::ImplGetChecksum() const
{
if(maVectorGraphicData)
nRet = maVectorGraphicData->GetChecksum();
- else if (mpPdfData && mpPdfData->hasElements())
+ else if (mpPdfData && !mpPdfData->empty())
// Include the PDF data in the checksum, so a metafile with
// and without PDF data is considered to be different.
- nRet = vcl_get_checksum(nRet, mpPdfData->getConstArray(), mpPdfData->getLength());
+ nRet = vcl_get_checksum(nRet, mpPdfData->data(), mpPdfData->size());
else if( mpAnimation )
nRet = mpAnimation->GetChecksum();
else
@@ -1742,7 +1742,7 @@ bool ImpGraphic::ImplExportNative( SvStream& rOStm ) const
return bResult;
}
-static std::map<BitmapChecksum, std::shared_ptr<css::uno::Sequence<sal_Int8>>> sPdfDataCache;
+static std::map<BitmapChecksum, std::shared_ptr<std::vector<sal_Int8>>> sPdfDataCache;
void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
{
@@ -1906,7 +1906,7 @@ void ReadImpGraphic( SvStream& rIStm, ImpGraphic& rImpGraphic )
rImpGraphic.maEx = aBitmap;
std::vector<Bitmap> aBitmaps;
- if (vcl::RenderPDFBitmaps(rImpGraphic.mpPdfData->getConstArray(), rImpGraphic.mpPdfData->getLength(), aBitmaps, rImpGraphic.mnPageNumber, 1) == 1)
+ if (vcl::RenderPDFBitmaps(rImpGraphic.mpPdfData->data(), rImpGraphic.mpPdfData->size(), aBitmaps, rImpGraphic.mnPageNumber, 1) == 1)
rImpGraphic.maEx = aBitmaps[0];
rImpGraphic.meType = GraphicType::Bitmap;
@@ -2002,7 +2002,7 @@ void WriteImpGraphic(SvStream& rOStm, const ImpGraphic& rImpGraphic)
}
else if (rImpGraphic.hasPdfData())
{
- BitmapChecksum nPdfId = vcl_get_checksum(0, rImpGraphic.mpPdfData->getConstArray(), rImpGraphic.mpPdfData->getLength());
+ BitmapChecksum nPdfId = vcl_get_checksum(0, rImpGraphic.mpPdfData->data(), rImpGraphic.mpPdfData->size());
if (sPdfDataCache.find(nPdfId) == sPdfDataCache.end())
sPdfDataCache.emplace(nPdfId, rImpGraphic.mpPdfData);
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index 1bcc180a0863..dc9e4f249b6a 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -4516,12 +4516,12 @@ bool PDFWriterImpl::emitEmbeddedFiles()
aLine.append(rEmbeddedFile.m_nObject);
aLine.append(" 0 obj\n");
aLine.append("<< /Type /EmbeddedFile /Length ");
- aLine.append(static_cast<sal_Int64>(rEmbeddedFile.m_aData.getLength()));
+ aLine.append(static_cast<sal_Int64>(rEmbeddedFile.m_aData.size()));
aLine.append(" >>\nstream\n");
CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
aLine.setLength(0);
- CHECK_RETURN(writeBuffer(rEmbeddedFile.m_aData.getArray(), rEmbeddedFile.m_aData.getLength()));
+ CHECK_RETURN(writeBuffer(rEmbeddedFile.m_aData.data(), rEmbeddedFile.m_aData.size()));
aLine.append("\nendstream\nendobj\n\n");
CHECK_RETURN(writeBuffer(aLine.getStr(), aLine.getLength()));
@@ -8473,7 +8473,7 @@ bool PDFWriterImpl::writeGradientFunction( GradientEmit const & rObject )
void PDFWriterImpl::writeJPG( JPGEmit& rObject )
{
- if (rObject.m_aReferenceXObject.m_aPDFData.hasElements() && !m_aContext.UseReferenceXObject)
+ if (!rObject.m_aReferenceXObject.m_aPDFData.empty() && !m_aContext.UseReferenceXObject)
{
writeReferenceXObject(rObject.m_aReferenceXObject);
return;
@@ -8787,7 +8787,7 @@ void PDFWriterImpl::writeReferenceXObject(ReferenceXObjectEmit& rEmit)
// Parse the PDF data, we need that to write the PDF dictionary of our
// object.
SvMemoryStream aPDFStream;
- aPDFStream.WriteBytes(rEmit.m_aPDFData.getArray(), rEmit.m_aPDFData.getLength());
+ aPDFStream.WriteBytes(rEmit.m_aPDFData.data(), rEmit.m_aPDFData.size());
aPDFStream.Seek(0);
filter::PDFDocument aPDFDocument;
if (!aPDFDocument.Read(aPDFStream))
@@ -9023,7 +9023,7 @@ namespace
bool PDFWriterImpl::writeBitmapObject( BitmapEmit& rObject, bool bMask )
{
- if (rObject.m_aReferenceXObject.m_aPDFData.hasElements() && !m_aContext.UseReferenceXObject)
+ if (!rObject.m_aReferenceXObject.m_aPDFData.empty() && !m_aContext.UseReferenceXObject)
{
writeReferenceXObject(rObject.m_aReferenceXObject);
return true;
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 7dd40d96e039..68d2cbce80e9 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -203,7 +203,7 @@ public:
/// Size of the bitmap replacement, in pixels.
Size m_aPixelSize;
/// PDF data from the graphic object, if not writing a reference XObject.
- css::uno::Sequence<sal_Int8> m_aPDFData;
+ std::vector<sal_Int8> m_aPDFData;
ReferenceXObjectEmit()
: m_nFormObject(0),
@@ -423,7 +423,7 @@ public:
/// ID of the file.
sal_Int32 m_nObject;
/// Contents of the file.
- css::uno::Sequence<sal_Int8> m_aData;
+ std::vector<sal_Int8> m_aData;
PDFEmbeddedFile()
: m_nObject(0)