diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-10-21 21:01:57 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2020-10-22 09:06:33 +0200 |
commit | ff79f6fa9b09f0b501e8096999b7a16c57070388 (patch) | |
tree | 9d5556d493afa1dc0dd230dfdc8c48da1b1d906c /vcl/source/pdf | |
parent | 3935a0bd3bcf747aa9bede59b045d23ab598f2d4 (diff) |
pdfium: add a wrapper for FPDF_SaveWithVersion()
And use it in getCompatibleStream().
Change-Id: I48ab2a17c0780b78c6af6dbff50dba81f8041f43
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104642
Tested-by: Jenkins
Reviewed-by: Miklos Vajna <vmiklos@collabora.com>
Diffstat (limited to 'vcl/source/pdf')
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 41e061bb1f6c..10fa42f143cf 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -18,12 +18,35 @@ #include <fpdf_annot.h> #include <fpdf_edit.h> #include <fpdf_text.h> +#include <fpdf_save.h> #include <osl/endian.h> #include <vcl/bitmap.hxx> +#include <tools/stream.hxx> #include <bitmapwriteaccess.hxx> +namespace +{ +/// Callback class to be used with FPDF_SaveWithVersion(). +struct CompatibleWriter : public FPDF_FILEWRITE +{ + CompatibleWriter(SvMemoryStream& rStream) + : m_rStream(rStream) + { + } + + SvMemoryStream& m_rStream; +}; + +int CompatibleWriterCallback(FPDF_FILEWRITE* pFileWrite, const void* pData, unsigned long nSize) +{ + auto pImpl = static_cast<CompatibleWriter*>(pFileWrite); + pImpl->m_rStream.WriteBytes(pData, nSize); + return 1; +} +} + namespace vcl::pdf { OUString convertPdfDateToISO8601(OUString const& rInput) @@ -196,6 +219,19 @@ int PDFiumDocument::getFileVersion() return nFileVersion; } +bool PDFiumDocument::saveWithVersion(SvMemoryStream& rStream, int nFileVersion) +{ + CompatibleWriter aWriter(rStream); + aWriter.version = 1; + aWriter.WriteBlock = &CompatibleWriterCallback; + if (!FPDF_SaveWithVersion(mpPdfDocument, &aWriter, 0, nFileVersion)) + { + return false; + } + + return true; +} + int PDFiumPage::getObjectCount() { return FPDFPage_CountObjects(mpPage); } std::unique_ptr<PDFiumPageObject> PDFiumPage::getObject(int nIndex) |