diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2020-09-04 17:17:48 +0200 |
---|---|---|
committer | Thorsten Behrens <Thorsten.Behrens@CIB.de> | 2020-09-12 11:24:41 +0200 |
commit | c258db7bea59bd536d71fd91c960d3bd9e1b4bb4 (patch) | |
tree | fb5baa8fa2e5277edb2e3f95bc5e92d80d7905d8 /vcl | |
parent | 12025e528ef50af9e3176a19465f860723e30871 (diff) |
xmlsecurity: pdf incremental updates that are non-commenting are invalid
I.e. it's OK to add incremental updates for annotation/commenting
purposes and that doesn't invalite existing signatures. Everything else
does.
(cherry picked from commit 61834cd574568613f0b0a2ee099a60fa5a8d9804)
Conflicts:
include/vcl/filter/PDFiumLibrary.hxx
vcl/source/pdf/PDFiumLibrary.cxx
Change-Id: I4607c242b3c6f6b01517b02407e9e7a095e2e069
Conflicts:
xmlsecurity/qa/unit/signing/signing.cxx
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/pdf/PDFiumLibrary.cxx | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/vcl/source/pdf/PDFiumLibrary.cxx b/vcl/source/pdf/PDFiumLibrary.cxx index 5f487b15f48b..330c473ac6dc 100644 --- a/vcl/source/pdf/PDFiumLibrary.cxx +++ b/vcl/source/pdf/PDFiumLibrary.cxx @@ -15,6 +15,10 @@ #include <vcl/filter/PDFiumLibrary.hxx> #include <fpdf_doc.h> +#include <vcl/bitmap.hxx> + +#include <bitmapwriteaccess.hxx> + namespace vcl { namespace pdf @@ -31,6 +35,57 @@ PDFium::PDFium() PDFium::~PDFium() { FPDF_DestroyLibrary(); } +PDFiumDocument::PDFiumDocument(FPDF_DOCUMENT pPdfDocument) + : mpPdfDocument(pPdfDocument) +{ +} + +PDFiumDocument::~PDFiumDocument() +{ + if (mpPdfDocument) + FPDF_CloseDocument(mpPdfDocument); +} + +std::unique_ptr<PDFiumPage> PDFiumDocument::openPage(int nIndex) +{ + std::unique_ptr<PDFiumPage> pPDFiumPage; + FPDF_PAGE pPage = FPDF_LoadPage(mpPdfDocument, nIndex); + if (pPage) + { + pPDFiumPage = std::make_unique<PDFiumPage>(pPage); + } + return pPDFiumPage; +} + +int PDFiumDocument::getPageCount() { return FPDF_GetPageCount(mpPdfDocument); } + +BitmapChecksum PDFiumPage::getChecksum() +{ + size_t nPageWidth = FPDF_GetPageWidth(mpPage); + size_t nPageHeight = FPDF_GetPageHeight(mpPage); + FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1); + if (!pPdfBitmap) + { + return 0; + } + + // Intentionally not using FPDF_ANNOT here, annotations/commenting is OK to not affect the + // checksum, signature verification wants this. + FPDF_RenderPageBitmap(pPdfBitmap, mpPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight, + /*rotate=*/0, /*flags=*/0); + Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24); + { + BitmapScopedWriteAccess pWriteAccess(aBitmap); + const auto pPdfBuffer = static_cast<ConstScanline>(FPDFBitmap_GetBuffer(pPdfBitmap)); + const int nStride = FPDFBitmap_GetStride(pPdfBitmap); + for (size_t nRow = 0; nRow < nPageHeight; ++nRow) + { + ConstScanline pPdfLine = pPdfBuffer + (nStride * nRow); + pWriteAccess->CopyScanline(nRow, pPdfLine, ScanlineFormat::N32BitTcBgra, nStride); + } + } + return aBitmap.GetChecksum(); +} } } // end vcl::pdf |