diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-04-27 09:14:26 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2017-04-27 12:57:21 +0200 |
commit | 834df8b3d10fb15e9bf2ef657a7fac4747544852 (patch) | |
tree | 3e3f5b521efd2a7d3223f1786402c14ec69aefa0 /xmlsecurity | |
parent | 327eb92b4f2a6cc08a837d5427d360cb0cc16635 (diff) |
xmlsecurity pdfverify: go via vcl graphic filter
Initially some proof of concept code was implemented here, but then I
copied that to VCL and it got fixes there, so call into vcl from here
instead of invoking pdfium directly.
Change-Id: I8590cbe94876ff6aff3f870535a99062304f3996
Reviewed-on: https://gerrit.libreoffice.org/37016
Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Tested-by: Jenkins <ci@libreoffice.org>
Diffstat (limited to 'xmlsecurity')
-rw-r--r-- | xmlsecurity/Module_xmlsecurity.mk | 2 | ||||
-rw-r--r-- | xmlsecurity/workben/pdfverify.cxx | 86 |
2 files changed, 6 insertions, 82 deletions
diff --git a/xmlsecurity/Module_xmlsecurity.mk b/xmlsecurity/Module_xmlsecurity.mk index cb68c595f82d..d3fafeb7e4ec 100644 --- a/xmlsecurity/Module_xmlsecurity.mk +++ b/xmlsecurity/Module_xmlsecurity.mk @@ -46,14 +46,12 @@ $(eval $(call gb_Module_add_screenshot_targets,xmlsecurity,\ )) ifneq (,$(filter DESKTOP,$(BUILD_TYPE))) -ifeq ($(ENABLE_PDFIUM),TRUE) $(eval $(call gb_Module_add_targets,xmlsecurity,\ Executable_pdfverify \ )) endif -endif endif diff --git a/xmlsecurity/workben/pdfverify.cxx b/xmlsecurity/workben/pdfverify.cxx index 7746a6e7b716..7b64e42c2a49 100644 --- a/xmlsecurity/workben/pdfverify.cxx +++ b/xmlsecurity/workben/pdfverify.cxx @@ -9,15 +9,6 @@ #include <iostream> -#ifdef WNT -#include <prewin.h> -#endif -#include <fpdfview.h> -#include <fpdf_edit.h> -#ifdef WNT -#include <postwin.h> -#endif - #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/uno/XComponentContext.hpp> #include <com/sun/star/xml/crypto/SEInitializer.hpp> @@ -26,10 +17,9 @@ #include <cppuhelper/bootstrap.hxx> #include <osl/file.hxx> #include <sal/main.h> -#include <vcl/bitmap.hxx> -#include <vcl/bitmapaccess.hxx> #include <vcl/pngwrite.hxx> #include <vcl/svapp.hxx> +#include <vcl/graphicfilter.hxx> #include <xmlsecurity/pdfio/pdfdocument.hxx> @@ -39,88 +29,24 @@ using namespace com::sun::star; namespace { -/// Convert to inch, then assume 96 DPI. -double pointToPixel(double fPoint) -{ - return fPoint / 72 * 96; -} - /// Does PDF to PNG conversion using pdfium. void generatePreview(const OString& rPdfPath, const OString& rPngPath) { - FPDF_LIBRARY_CONFIG aConfig; - aConfig.version = 2; - aConfig.m_pUserFontPaths = nullptr; - aConfig.m_pIsolate = nullptr; - aConfig.m_v8EmbedderSlot = 0; - FPDF_InitLibraryWithConfig(&aConfig); - - // Read input into a buffer. + GraphicFilter& rFilter = GraphicFilter::GetGraphicFilter(); + Graphic aGraphic; OUString aInURL; osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(rPdfPath), aInURL); SvFileStream aInStream(aInURL, StreamMode::READ); - SvMemoryStream aInBuffer; - aInBuffer.WriteStream(aInStream); - - // Load the buffer using pdfium. - FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(aInBuffer.GetData(), aInBuffer.GetSize(), /*password=*/nullptr); - if (!pPdfDocument) - return; - - // Render the first page. - FPDF_PAGE pPdfPage = FPDF_LoadPage(pPdfDocument, /*page_index=*/0); - if (!pPdfPage) - return; - - // Returned unit is points, convert that to pixel. - int nPageWidth = pointToPixel(FPDF_GetPageWidth(pPdfPage)); - int nPageHeight = pointToPixel(FPDF_GetPageHeight(pPdfPage)); - FPDF_BITMAP pPdfBitmap = FPDFBitmap_Create(nPageWidth, nPageHeight, /*alpha=*/1); - if (!pPdfBitmap) + WMF_EXTERNALHEADER* pExtHeader = nullptr; + if (rFilter.ImportGraphic(aGraphic, OUString(), aInStream, GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::NONE, pExtHeader) != GRFILTER_OK) return; - FPDF_DWORD nColor = FPDFPage_HasTransparency(pPdfPage) ? 0x00000000 : 0xFFFFFFFF; - FPDFBitmap_FillRect(pPdfBitmap, 0, 0, nPageWidth, nPageHeight, nColor); - FPDF_RenderPageBitmap(pPdfBitmap, pPdfPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight, /*rotate=*/0, /*flags=*/0); - - // Save the buffer as a PNG file. - Bitmap aBitmap(Size(nPageWidth, nPageHeight), 32); - { - Bitmap::ScopedWriteAccess pWriteAccess(aBitmap); - const char* pPdfBuffer = static_cast<const char*>(FPDFBitmap_GetBuffer(pPdfBitmap)); -#ifndef MACOSX - std::memcpy(pWriteAccess->GetBuffer(), pPdfBuffer, nPageWidth * nPageHeight * 4); -#else - // ARGB -> BGRA - for (int nRow = 0; nRow < nPageHeight; ++nRow) - { - int nStride = FPDFBitmap_GetStride(pPdfBitmap); - const char* pPdfLine = pPdfBuffer + (nStride * nRow); - Scanline pRow = pWriteAccess->GetBuffer() + (nPageWidth * nRow * 4); - for (int nCol = 0; nCol < nPageWidth; ++nCol) - { - pRow[nCol * 4] = pPdfLine[(nCol * 4) + 3]; - pRow[(nCol * 4) + 1] = pPdfLine[(nCol * 4) + 2]; - pRow[(nCol * 4) + 2] = pPdfLine[(nCol * 4) + 1]; - pRow[(nCol * 4) + 3] = pPdfLine[nCol * 4]; - } - } -#endif - } - BitmapEx aBitmapEx(aBitmap); -#if defined(WNT) || defined(MACOSX) - aBitmapEx.Mirror(BmpMirrorFlags::Vertical); -#endif + BitmapEx aBitmapEx = aGraphic.GetBitmapEx(); vcl::PNGWriter aWriter(aBitmapEx); OUString aOutURL; osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(rPngPath), aOutURL); SvFileStream aOutStream(aOutURL, StreamMode::WRITE); aWriter.Write(aOutStream); - - FPDFBitmap_Destroy(pPdfBitmap); - FPDF_ClosePage(pPdfPage); - FPDF_CloseDocument(pPdfDocument); - FPDF_DestroyLibrary(); } int pdfVerify(int nArgc, char** pArgv) |