Kaydet (Commit) 17407f80 authored tarafından Miklos Vajna's avatar Miklos Vajna

Turn on clang-format for these files

I (tried to) keep these files consistent locally with astyle in the past,
switching to clang-format makes sure that the recent problem with introducing
inconsistencies in these files doesn't happen again.

(On the flip side, it's great to see that now others also touch this
PDF/pdfium code. :-) )

Change-Id: I6065eab77c584197a82fe48e7d3e81b445106efd
Reviewed-on: https://gerrit.libreoffice.org/51701Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
üst 45ea6ebd
...@@ -25,7 +25,6 @@ namespace vcl ...@@ -25,7 +25,6 @@ namespace vcl
{ {
namespace filter namespace filter
{ {
class PDFTrailerElement; class PDFTrailerElement;
class PDFHexStringElement; class PDFHexStringElement;
class PDFReferenceElement; class PDFReferenceElement;
...@@ -67,9 +66,9 @@ class VCL_DLLPUBLIC PDFObjectElement : public PDFElement ...@@ -67,9 +66,9 @@ class VCL_DLLPUBLIC PDFObjectElement : public PDFElement
/// The stream of this object, used when this is an object stream. /// The stream of this object, used when this is an object stream.
PDFStreamElement* m_pStreamElement; PDFStreamElement* m_pStreamElement;
/// Objects of an object stream. /// Objects of an object stream.
std::vector< std::unique_ptr<PDFObjectElement> > m_aStoredElements; std::vector<std::unique_ptr<PDFObjectElement>> m_aStoredElements;
/// Elements of an object in an object stream. /// Elements of an object in an object stream.
std::vector< std::unique_ptr<PDFElement> > m_aElements; std::vector<std::unique_ptr<PDFElement>> m_aElements;
/// Uncompressed buffer of an object in an object stream. /// Uncompressed buffer of an object in an object stream.
std::unique_ptr<SvMemoryStream> m_pStreamBuffer; std::unique_ptr<SvMemoryStream> m_pStreamBuffer;
/// List of all reference elements inside this object's dictionary and /// List of all reference elements inside this object's dictionary and
...@@ -105,7 +104,7 @@ public: ...@@ -105,7 +104,7 @@ public:
PDFArrayElement* GetArray() const; PDFArrayElement* GetArray() const;
/// Parse objects stored in this object stream. /// Parse objects stored in this object stream.
void ParseStoredObjects(); void ParseStoredObjects();
std::vector< std::unique_ptr<PDFElement> >& GetStoredElements(); std::vector<std::unique_ptr<PDFElement>>& GetStoredElements();
SvMemoryStream* GetStreamBuffer() const; SvMemoryStream* GetStreamBuffer() const;
void SetStreamBuffer(std::unique_ptr<SvMemoryStream>& pStreamBuffer); void SetStreamBuffer(std::unique_ptr<SvMemoryStream>& pStreamBuffer);
PDFDocument& GetDocument(); PDFDocument& GetDocument();
...@@ -117,6 +116,7 @@ class VCL_DLLPUBLIC PDFArrayElement : public PDFElement ...@@ -117,6 +116,7 @@ class VCL_DLLPUBLIC PDFArrayElement : public PDFElement
std::vector<PDFElement*> m_aElements; std::vector<PDFElement*> m_aElements;
/// The object that contains this array. /// The object that contains this array.
PDFObjectElement* m_pObject; PDFObjectElement* m_pObject;
public: public:
PDFArrayElement(PDFObjectElement* pObject); PDFArrayElement(PDFObjectElement* pObject);
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
...@@ -136,7 +136,8 @@ class VCL_DLLPUBLIC PDFReferenceElement : public PDFElement ...@@ -136,7 +136,8 @@ class VCL_DLLPUBLIC PDFReferenceElement : public PDFElement
PDFNumberElement& m_rObject; PDFNumberElement& m_rObject;
public: public:
PDFReferenceElement(PDFDocument& rDoc, PDFNumberElement& rObject, PDFNumberElement const& rGeneration); PDFReferenceElement(PDFDocument& rDoc, PDFNumberElement& rObject,
PDFNumberElement const& rGeneration);
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
/// Assuming the reference points to a number object, return its value. /// Assuming the reference points to a number object, return its value.
double LookupNumber(SvStream& rStream) const; double LookupNumber(SvStream& rStream) const;
...@@ -171,6 +172,7 @@ class VCL_DLLPUBLIC PDFNameElement : public PDFElement ...@@ -171,6 +172,7 @@ class VCL_DLLPUBLIC PDFNameElement : public PDFElement
sal_uInt64 m_nLocation = 0; sal_uInt64 m_nLocation = 0;
/// Length till the next token start. /// Length till the next token start.
sal_uInt64 m_nLength = 0; sal_uInt64 m_nLength = 0;
public: public:
PDFNameElement(); PDFNameElement();
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
...@@ -195,8 +197,10 @@ public: ...@@ -195,8 +197,10 @@ public:
PDFDictionaryElement(); PDFDictionaryElement();
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
static size_t Parse(const std::vector< std::unique_ptr<PDFElement> >& rElements, PDFElement* pThis, std::map<OString, PDFElement*>& rDictionary); static size_t Parse(const std::vector<std::unique_ptr<PDFElement>>& rElements,
static PDFElement* Lookup(const std::map<OString, PDFElement*>& rDictionary, const OString& rKey); PDFElement* pThis, std::map<OString, PDFElement*>& rDictionary);
static PDFElement* Lookup(const std::map<OString, PDFElement*>& rDictionary,
const OString& rKey);
void SetKeyOffset(const OString& rKey, sal_uInt64 nOffset); void SetKeyOffset(const OString& rKey, sal_uInt64 nOffset);
sal_uInt64 GetKeyOffset(const OString& rKey) const; sal_uInt64 GetKeyOffset(const OString& rKey) const;
void SetKeyValueLength(const OString& rKey, sal_uInt64 nLength); void SetKeyValueLength(const OString& rKey, sal_uInt64 nLength);
...@@ -252,6 +256,7 @@ struct XRefEntry ...@@ -252,6 +256,7 @@ struct XRefEntry
class VCL_DLLPUBLIC PDFHexStringElement : public PDFElement class VCL_DLLPUBLIC PDFHexStringElement : public PDFElement
{ {
OString m_aValue; OString m_aValue;
public: public:
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
const OString& GetValue() const; const OString& GetValue() const;
...@@ -261,6 +266,7 @@ public: ...@@ -261,6 +266,7 @@ public:
class VCL_DLLPUBLIC PDFLiteralStringElement : public PDFElement class VCL_DLLPUBLIC PDFLiteralStringElement : public PDFElement
{ {
OString m_aValue; OString m_aValue;
public: public:
bool Read(SvStream& rStream) override; bool Read(SvStream& rStream) override;
const OString& GetValue() const; const OString& GetValue() const;
...@@ -293,7 +299,7 @@ public: ...@@ -293,7 +299,7 @@ public:
class VCL_DLLPUBLIC PDFDocument class VCL_DLLPUBLIC PDFDocument
{ {
/// This vector owns all elements. /// This vector owns all elements.
std::vector< std::unique_ptr<PDFElement> > m_aElements; std::vector<std::unique_ptr<PDFElement>> m_aElements;
/// Object ID <-> object offset map. /// Object ID <-> object offset map.
std::map<size_t, XRefEntry> m_aXRef; std::map<size_t, XRefEntry> m_aXRef;
/// Object offset <-> Object pointer map. /// Object offset <-> Object pointer map.
...@@ -317,11 +323,13 @@ class VCL_DLLPUBLIC PDFDocument ...@@ -317,11 +323,13 @@ class VCL_DLLPUBLIC PDFDocument
/// Suggest a minimal, yet free signature ID to use for the next signature. /// Suggest a minimal, yet free signature ID to use for the next signature.
sal_uInt32 GetNextSignature(); sal_uInt32 GetNextSignature();
/// Write the signature object as part of signing. /// Write the signature object as part of signing.
sal_Int32 WriteSignatureObject(const OUString& rDescription, bool bAdES, sal_uInt64& rLastByteRangeOffset, sal_Int64& rContentOffset); sal_Int32 WriteSignatureObject(const OUString& rDescription, bool bAdES,
sal_uInt64& rLastByteRangeOffset, sal_Int64& rContentOffset);
/// Write the appearance object as part of signing. /// Write the appearance object as part of signing.
sal_Int32 WriteAppearanceObject(); sal_Int32 WriteAppearanceObject();
/// Write the annot object as part of signing. /// Write the annot object as part of signing.
sal_Int32 WriteAnnotObject(PDFObjectElement const& rFirstPage, sal_Int32 nSignatureId, sal_Int32 nAppearanceId); sal_Int32 WriteAnnotObject(PDFObjectElement const& rFirstPage, sal_Int32 nSignatureId,
sal_Int32 nAppearanceId);
/// Write the updated Page object as part of signing. /// Write the updated Page object as part of signing.
bool WritePageObject(PDFObjectElement& rFirstPage, sal_Int32 nAnnotId); bool WritePageObject(PDFObjectElement& rFirstPage, sal_Int32 nAnnotId);
/// Write the updated Catalog object as part of signing. /// Write the updated Catalog object as part of signing.
...@@ -345,7 +353,7 @@ public: ...@@ -345,7 +353,7 @@ public:
/// Instead of all whitespace, just skip CR and NL characters. /// Instead of all whitespace, just skip CR and NL characters.
static void SkipLineBreaks(SvStream& rStream); static void SkipLineBreaks(SvStream& rStream);
size_t GetObjectOffset(size_t nIndex) const; size_t GetObjectOffset(size_t nIndex) const;
const std::vector< std::unique_ptr<PDFElement> >& GetElements(); const std::vector<std::unique_ptr<PDFElement>>& GetElements();
std::vector<PDFObjectElement*> GetPages(); std::vector<PDFObjectElement*> GetPages();
/// Remember the end location of an EOF token. /// Remember the end location of an EOF token.
void PushBackEOF(size_t nOffset); void PushBackEOF(size_t nOffset);
...@@ -354,7 +362,9 @@ public: ...@@ -354,7 +362,9 @@ public:
/// Access to the input document, even after the input stream is gone. /// Access to the input document, even after the input stream is gone.
SvMemoryStream& GetEditBuffer(); SvMemoryStream& GetEditBuffer();
/// Tokenize elements from current offset. /// Tokenize elements from current offset.
bool Tokenize(SvStream& rStream, TokenizeMode eMode, std::vector< std::unique_ptr<PDFElement> >& rElements, PDFObjectElement* pObjectElement); bool Tokenize(SvStream& rStream, TokenizeMode eMode,
std::vector<std::unique_ptr<PDFElement>>& rElements,
PDFObjectElement* pObjectElement);
/// Register an object (owned directly or indirectly by m_aElements) as a provider for a given ID. /// Register an object (owned directly or indirectly by m_aElements) as a provider for a given ID.
void SetIDObject(size_t nID, PDFObjectElement* pObject); void SetIDObject(size_t nID, PDFObjectElement* pObject);
//@} //@}
...@@ -364,7 +374,8 @@ public: ...@@ -364,7 +374,8 @@ public:
/// Read elements from the start of the stream till its end. /// Read elements from the start of the stream till its end.
bool Read(SvStream& rStream); bool Read(SvStream& rStream);
/// Sign the read document with xCertificate in the edit buffer. /// Sign the read document with xCertificate in the edit buffer.
bool Sign(const css::uno::Reference<css::security::XCertificate>& xCertificate, const OUString& rDescription, bool bAdES); bool Sign(const css::uno::Reference<css::security::XCertificate>& xCertificate,
const OUString& rDescription, bool bAdES);
/// Serializes the contents of the edit buffer. /// Serializes the contents of the edit buffer.
bool Write(SvStream& rStream); bool Write(SvStream& rStream);
/// Get a list of signatures embedded into this document. /// Get a list of signatures embedded into this document.
......
...@@ -8009,7 +8009,6 @@ include/vcl/evntpost.hxx ...@@ -8009,7 +8009,6 @@ include/vcl/evntpost.hxx
include/vcl/exceptiontypes.hxx include/vcl/exceptiontypes.hxx
include/vcl/extoutdevdata.hxx include/vcl/extoutdevdata.hxx
include/vcl/field.hxx include/vcl/field.hxx
include/vcl/filter/pdfdocument.hxx
include/vcl/fixed.hxx include/vcl/fixed.hxx
include/vcl/fixedhyper.hxx include/vcl/fixedhyper.hxx
include/vcl/floatwin.hxx include/vcl/floatwin.hxx
...@@ -17652,7 +17651,6 @@ vcl/inc/outdev.h ...@@ -17652,7 +17651,6 @@ vcl/inc/outdev.h
vcl/inc/outdevstatestack.hxx vcl/inc/outdevstatestack.hxx
vcl/inc/pch/precompiled_vcl.cxx vcl/inc/pch/precompiled_vcl.cxx
vcl/inc/pch/precompiled_vcl.hxx vcl/inc/pch/precompiled_vcl.hxx
vcl/inc/pdfread.hxx
vcl/inc/print.h vcl/inc/print.h
vcl/inc/printdlg.hxx vcl/inc/printdlg.hxx
vcl/inc/printerinfomanager.hxx vcl/inc/printerinfomanager.hxx
...@@ -18098,8 +18096,6 @@ vcl/source/filter/igif/decode.cxx ...@@ -18098,8 +18096,6 @@ vcl/source/filter/igif/decode.cxx
vcl/source/filter/igif/decode.hxx vcl/source/filter/igif/decode.hxx
vcl/source/filter/igif/gifread.cxx vcl/source/filter/igif/gifread.cxx
vcl/source/filter/igif/gifread.hxx vcl/source/filter/igif/gifread.hxx
vcl/source/filter/ipdf/pdfdocument.cxx
vcl/source/filter/ipdf/pdfread.cxx
vcl/source/filter/ixbm/xbmread.cxx vcl/source/filter/ixbm/xbmread.cxx
vcl/source/filter/ixbm/xbmread.hxx vcl/source/filter/ixbm/xbmread.hxx
vcl/source/filter/ixpm/rgbtable.hxx vcl/source/filter/ixpm/rgbtable.hxx
...@@ -19669,7 +19665,6 @@ xmlsecurity/inc/pch/precompiled_xsec_gpg.cxx ...@@ -19669,7 +19665,6 @@ xmlsecurity/inc/pch/precompiled_xsec_gpg.cxx
xmlsecurity/inc/pch/precompiled_xsec_gpg.hxx xmlsecurity/inc/pch/precompiled_xsec_gpg.hxx
xmlsecurity/inc/pch/precompiled_xsec_xmlsec.cxx xmlsecurity/inc/pch/precompiled_xsec_xmlsec.cxx
xmlsecurity/inc/pch/precompiled_xsec_xmlsec.hxx xmlsecurity/inc/pch/precompiled_xsec_xmlsec.hxx
xmlsecurity/inc/pdfio/pdfdocument.hxx
xmlsecurity/inc/resourcemanager.hxx xmlsecurity/inc/resourcemanager.hxx
xmlsecurity/inc/xmlsec-wrapper.h xmlsecurity/inc/xmlsec-wrapper.h
xmlsecurity/inc/xmlsec/errorcallback.hxx xmlsecurity/inc/xmlsec/errorcallback.hxx
...@@ -19685,7 +19680,6 @@ xmlsecurity/inc/xsecfwdllapi.h ...@@ -19685,7 +19680,6 @@ xmlsecurity/inc/xsecfwdllapi.h
xmlsecurity/inc/xsecgpgdllapi.h xmlsecurity/inc/xsecgpgdllapi.h
xmlsecurity/inc/xsecxmlsecdllapi.h xmlsecurity/inc/xsecxmlsecdllapi.h
xmlsecurity/qa/certext/SanCertExt.cxx xmlsecurity/qa/certext/SanCertExt.cxx
xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx
xmlsecurity/qa/unit/signing/signing.cxx xmlsecurity/qa/unit/signing/signing.cxx
xmlsecurity/qa/unit/xmlsecurity-dialogs-test.cxx xmlsecurity/qa/unit/xmlsecurity-dialogs-test.cxx
xmlsecurity/source/component/certificatecontainer.cxx xmlsecurity/source/component/certificatecontainer.cxx
...@@ -19736,7 +19730,6 @@ xmlsecurity/source/helper/xsecparser.cxx ...@@ -19736,7 +19730,6 @@ xmlsecurity/source/helper/xsecparser.cxx
xmlsecurity/source/helper/xsecparser.hxx xmlsecurity/source/helper/xsecparser.hxx
xmlsecurity/source/helper/xsecsign.cxx xmlsecurity/source/helper/xsecsign.cxx
xmlsecurity/source/helper/xsecverify.cxx xmlsecurity/source/helper/xsecverify.cxx
xmlsecurity/source/pdfio/pdfdocument.cxx
xmlsecurity/source/xmlsec/biginteger.cxx xmlsecurity/source/xmlsec/biginteger.cxx
xmlsecurity/source/xmlsec/certificateextension_certextn.cxx xmlsecurity/source/xmlsec/certificateextension_certextn.cxx
xmlsecurity/source/xmlsec/certificateextension_certextn.hxx xmlsecurity/source/xmlsec/certificateextension_certextn.hxx
...@@ -19789,4 +19782,3 @@ xmlsecurity/source/xmlsec/xmlsec_init.cxx ...@@ -19789,4 +19782,3 @@ xmlsecurity/source/xmlsec/xmlsec_init.cxx
xmlsecurity/source/xmlsec/xmlstreamio.cxx xmlsecurity/source/xmlsec/xmlstreamio.cxx
xmlsecurity/source/xmlsec/xsec_xmlsec.cxx xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
xmlsecurity/source/xmlsec/xsec_xmlsec.hxx xmlsecurity/source/xmlsec/xsec_xmlsec.hxx
xmlsecurity/workben/pdfverify.cxx
...@@ -18,14 +18,12 @@ class Graphic; ...@@ -18,14 +18,12 @@ class Graphic;
namespace vcl namespace vcl
{ {
/// Imports a PDF stream into rGraphic as a GDIMetaFile. /// Imports a PDF stream into rGraphic as a GDIMetaFile.
VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap,
css::uno::Sequence<sal_Int8>& rPdfData, css::uno::Sequence<sal_Int8>& rPdfData,
sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN, sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN,
sal_uInt64 nSize = STREAM_SEEK_TO_END); sal_uInt64 nSize = STREAM_SEEK_TO_END);
VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic); VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic);
} }
#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX #endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
......
...@@ -25,7 +25,6 @@ using namespace com::sun::star; ...@@ -25,7 +25,6 @@ using namespace com::sun::star;
namespace namespace
{ {
#if HAVE_FEATURE_PDFIUM #if HAVE_FEATURE_PDFIUM
/// Callback class to be used with FPDF_SaveWithVersion(). /// Callback class to be used with FPDF_SaveWithVersion().
...@@ -33,7 +32,8 @@ struct CompatibleWriter : public FPDF_FILEWRITE ...@@ -33,7 +32,8 @@ struct CompatibleWriter : public FPDF_FILEWRITE
{ {
public: public:
CompatibleWriter(); CompatibleWriter();
static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* pData, unsigned long nSize); static int WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* pData,
unsigned long nSize);
SvMemoryStream m_aStream; SvMemoryStream m_aStream;
}; };
...@@ -44,7 +44,8 @@ CompatibleWriter::CompatibleWriter() ...@@ -44,7 +44,8 @@ CompatibleWriter::CompatibleWriter()
FPDF_FILEWRITE::WriteBlock = CompatibleWriter::WriteBlockCallback; FPDF_FILEWRITE::WriteBlock = CompatibleWriter::WriteBlockCallback;
} }
int CompatibleWriter::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* pData, unsigned long nSize) int CompatibleWriter::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* pData,
unsigned long nSize)
{ {
auto pImpl = static_cast<CompatibleWriter*>(pFileWrite); auto pImpl = static_cast<CompatibleWriter*>(pFileWrite);
pImpl->m_aStream.WriteBytes(pData, nSize); pImpl->m_aStream.WriteBytes(pData, nSize);
...@@ -52,15 +53,11 @@ int CompatibleWriter::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void* ...@@ -52,15 +53,11 @@ int CompatibleWriter::WriteBlockCallback(FPDF_FILEWRITE* pFileWrite, const void*
} }
/// Convert to inch, then assume 96 DPI. /// Convert to inch, then assume 96 DPI.
double pointToPixel(double fPoint) double pointToPixel(double fPoint) { return fPoint / 72 * 96; }
{
return fPoint / 72 * 96;
}
/// Does PDF to bitmap conversion using pdfium. /// Does PDF to bitmap conversion using pdfium.
size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, sal_uInt64 nPos,
sal_uInt64 nPos, sal_uInt64 nSize, sal_uInt64 nSize, const size_t nFirstPage = 0, int nPages = 1)
const size_t nFirstPage = 0, int nPages = 1)
{ {
FPDF_LIBRARY_CONFIG aConfig; FPDF_LIBRARY_CONFIG aConfig;
aConfig.version = 2; aConfig.version = 2;
...@@ -75,7 +72,8 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, ...@@ -75,7 +72,8 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps,
aInBuffer.WriteStream(rStream, nSize); aInBuffer.WriteStream(rStream, nSize);
// Load the buffer using pdfium. // Load the buffer using pdfium.
FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(aInBuffer.GetData(), aInBuffer.GetSize(), /*password=*/nullptr); FPDF_DOCUMENT pPdfDocument
= FPDF_LoadMemDocument(aInBuffer.GetData(), aInBuffer.GetSize(), /*password=*/nullptr);
if (!pPdfDocument) if (!pPdfDocument)
return 0; return 0;
...@@ -99,7 +97,8 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps, ...@@ -99,7 +97,8 @@ size_t generatePreview(SvStream& rStream, std::vector<Bitmap>& rBitmaps,
const FPDF_DWORD nColor = FPDFPage_HasTransparency(pPdfPage) ? 0x00000000 : 0xFFFFFFFF; const FPDF_DWORD nColor = FPDFPage_HasTransparency(pPdfPage) ? 0x00000000 : 0xFFFFFFFF;
FPDFBitmap_FillRect(pPdfBitmap, 0, 0, nPageWidth, nPageHeight, nColor); FPDFBitmap_FillRect(pPdfBitmap, 0, 0, nPageWidth, nPageHeight, nColor);
FPDF_RenderPageBitmap(pPdfBitmap, pPdfPage, /*start_x=*/0, /*start_y=*/0, nPageWidth, nPageHeight, /*rotate=*/0, /*flags=*/0); FPDF_RenderPageBitmap(pPdfBitmap, pPdfPage, /*start_x=*/0, /*start_y=*/0, nPageWidth,
nPageHeight, /*rotate=*/0, /*flags=*/0);
// Save the buffer as a bitmap. // Save the buffer as a bitmap.
Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24); Bitmap aBitmap(Size(nPageWidth, nPageHeight), 24);
...@@ -139,7 +138,8 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize) ...@@ -139,7 +138,8 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize)
if (nRead < 8) if (nRead < 8)
return false; return false;
if (aFirstBytes[0] != '%' || aFirstBytes[1] != 'P' || aFirstBytes[2] != 'D' || aFirstBytes[3] != 'F' || aFirstBytes[4] != '-') if (aFirstBytes[0] != '%' || aFirstBytes[1] != 'P' || aFirstBytes[2] != 'D'
|| aFirstBytes[3] != 'F' || aFirstBytes[4] != '-')
return false; return false;
sal_Int32 nMajor = OString(aFirstBytes[5]).toInt32(); sal_Int32 nMajor = OString(aFirstBytes[5]).toInt32();
...@@ -149,8 +149,8 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize) ...@@ -149,8 +149,8 @@ bool isCompatible(SvStream& rInStream, sal_uInt64 nPos, sal_uInt64 nSize)
/// Takes care of transparently downgrading the version of the PDF stream in /// Takes care of transparently downgrading the version of the PDF stream in
/// case it's too new for our PDF export. /// case it's too new for our PDF export.
bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 nPos,
sal_uInt64 nPos, sal_uInt64 nSize) sal_uInt64 nSize)
{ {
bool bCompatible = isCompatible(rInStream, nPos, nSize); bool bCompatible = isCompatible(rInStream, nPos, nSize);
rInStream.Seek(nPos); rInStream.Seek(nPos);
...@@ -172,7 +172,8 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, ...@@ -172,7 +172,8 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream,
aInBuffer.WriteStream(rInStream, nSize); aInBuffer.WriteStream(rInStream, nSize);
// Load the buffer using pdfium. // Load the buffer using pdfium.
FPDF_DOCUMENT pPdfDocument = FPDF_LoadMemDocument(aInBuffer.GetData(), aInBuffer.GetSize(), /*password=*/nullptr); FPDF_DOCUMENT pPdfDocument
= FPDF_LoadMemDocument(aInBuffer.GetData(), aInBuffer.GetSize(), /*password=*/nullptr);
if (!pPdfDocument) if (!pPdfDocument)
return false; return false;
...@@ -191,29 +192,25 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, ...@@ -191,29 +192,25 @@ bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream,
return rOutStream.good(); return rOutStream.good();
} }
#else #else
size_t generatePreview(SvStream&, std::vector<Bitmap>&, size_t generatePreview(SvStream&, std::vector<Bitmap>&, sal_uInt64 nPos, sal_uInt64 nSize,
sal_uInt64 nPos, sal_uInt64 nSize, size_t nFirstPage = 0, int nLastPage = 0)
size_t nFirstPage = 0, int nLastPage = 0)
{ {
return false; return false;
} }
bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, bool getCompatibleStream(SvStream& rInStream, SvStream& rOutStream, sal_uInt64 nPos,
sal_uInt64 nPos, sal_uInt64 nSize) sal_uInt64 nSize)
{ {
rInStream.Seek(nPos); rInStream.Seek(nPos);
rOutStream.WriteStream(rInStream, nSize); rOutStream.WriteStream(rInStream, nSize);
return rOutStream.good(); return rOutStream.good();
} }
#endif // HAVE_FEATURE_PDFIUM #endif // HAVE_FEATURE_PDFIUM
} }
namespace vcl namespace vcl
{ {
bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, css::uno::Sequence<sal_Int8>& rPdfData,
bool ImportPDF(SvStream& rStream, Bitmap& rBitmap,
css::uno::Sequence<sal_Int8>& rPdfData,
sal_uInt64 nPos, sal_uInt64 nSize) sal_uInt64 nPos, sal_uInt64 nSize)
{ {
// Get the preview of the first page. // Get the preview of the first page.
...@@ -236,7 +233,6 @@ bool ImportPDF(SvStream& rStream, Bitmap& rBitmap, ...@@ -236,7 +233,6 @@ bool ImportPDF(SvStream& rStream, Bitmap& rBitmap,
return true; return true;
} }
bool ImportPDF(SvStream& rStream, Graphic& rGraphic) bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
{ {
uno::Sequence<sal_Int8> aPdfData; uno::Sequence<sal_Int8> aPdfData;
...@@ -246,7 +242,6 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic) ...@@ -246,7 +242,6 @@ bool ImportPDF(SvStream& rStream, Graphic& rGraphic)
rGraphic.setPdfData(aPdfData); rGraphic.setPdfData(aPdfData);
return bRet; return bRet;
} }
} }
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -27,13 +27,14 @@ namespace xmlsecurity ...@@ -27,13 +27,14 @@ namespace xmlsecurity
{ {
namespace pdfio namespace pdfio
{ {
/** /**
* @param rInformation The actual result. * @param rInformation The actual result.
* @param bLast If this is the last signature in the file, so it covers the whole file physically. * @param bLast If this is the last signature in the file, so it covers the whole file physically.
* @return If we can determinate a result. * @return If we can determinate a result.
*/ */
XMLSECURITY_DLLPUBLIC bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignature, SignatureInformation& rInformation, bool bLast); XMLSECURITY_DLLPUBLIC bool ValidateSignature(SvStream& rStream,
vcl::filter::PDFObjectElement* pSignature,
SignatureInformation& rInformation, bool bLast);
} // namespace pdfio } // namespace pdfio
} // namespace xmlsecurity } // namespace xmlsecurity
......
...@@ -27,8 +27,8 @@ namespace xmlsecurity ...@@ -27,8 +27,8 @@ namespace xmlsecurity
{ {
namespace pdfio namespace pdfio
{ {
bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignature,
bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignature, SignatureInformation& rInformation, bool bLast) SignatureInformation& rInformation, bool bLast)
{ {
vcl::filter::PDFObjectElement* pValue = pSignature->LookupObject("V"); vcl::filter::PDFObjectElement* pValue = pSignature->LookupObject("V");
if (!pValue) if (!pValue)
...@@ -53,12 +53,15 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat ...@@ -53,12 +53,15 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat
auto pSubFilter = dynamic_cast<vcl::filter::PDFNameElement*>(pValue->Lookup("SubFilter")); auto pSubFilter = dynamic_cast<vcl::filter::PDFNameElement*>(pValue->Lookup("SubFilter"));
const bool bNonDetached = pSubFilter && pSubFilter->GetValue() == "adbe.pkcs7.sha1"; const bool bNonDetached = pSubFilter && pSubFilter->GetValue() == "adbe.pkcs7.sha1";
if (!pSubFilter || (pSubFilter->GetValue() != "adbe.pkcs7.detached" && !bNonDetached && pSubFilter->GetValue() != "ETSI.CAdES.detached")) if (!pSubFilter
|| (pSubFilter->GetValue() != "adbe.pkcs7.detached" && !bNonDetached
&& pSubFilter->GetValue() != "ETSI.CAdES.detached"))
{ {
if (!pSubFilter) if (!pSubFilter)
SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: missing sub-filter"); SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: missing sub-filter");
else else
SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: unsupported sub-filter: '"<<pSubFilter->GetValue()<<"'"); SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: unsupported sub-filter: '"
<< pSubFilter->GetValue() << "'");
return false; return false;
} }
...@@ -114,7 +117,8 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat ...@@ -114,7 +117,8 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat
auto pNumber = dynamic_cast<vcl::filter::PDFNumberElement*>(rByteRangeElements[i]); auto pNumber = dynamic_cast<vcl::filter::PDFNumberElement*>(rByteRangeElements[i]);
if (!pNumber) if (!pNumber)
{ {
SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: signature offset and length has to be a number"); SAL_WARN("xmlsecurity.pdfio",
"ValidateSignature: signature offset and length has to be a number");
return false; return false;
} }
...@@ -142,7 +146,8 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat ...@@ -142,7 +146,8 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat
size_t nSignatureLength = static_cast<size_t>(pContents->GetValue().getLength()) + 2; size_t nSignatureLength = static_cast<size_t>(pContents->GetValue().getLength()) + 2;
if (aByteRanges[1].first != (aByteRanges[0].second + nSignatureLength)) if (aByteRanges[1].first != (aByteRanges[0].second + nSignatureLength))
{ {
SAL_WARN("xmlsecurity.pdfio", "ValidateSignature: second range start is not the end of the signature"); SAL_WARN("xmlsecurity.pdfio",
"ValidateSignature: second range start is not the end of the signature");
return false; return false;
} }
rStream.Seek(STREAM_SEEK_TO_END); rStream.Seek(STREAM_SEEK_TO_END);
...@@ -160,7 +165,8 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat ...@@ -160,7 +165,8 @@ bool ValidateSignature(SvStream& rStream, vcl::filter::PDFObjectElement* pSignat
return false; return false;
} }
return svl::crypto::Signing::Verify(rStream, aByteRanges, bNonDetached, aSignature, rInformation); return svl::crypto::Signing::Verify(rStream, aByteRanges, bNonDetached, aSignature,
rInformation);
} }
} // namespace pdfio } // namespace pdfio
......
...@@ -39,7 +39,9 @@ void generatePreview(const OString& rPdfPath, const OString& rPngPath) ...@@ -39,7 +39,9 @@ void generatePreview(const OString& rPdfPath, const OString& rPngPath)
osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(rPdfPath), aInURL); osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(rPdfPath), aInURL);
SvFileStream aInStream(aInURL, StreamMode::READ); SvFileStream aInStream(aInURL, StreamMode::READ);
WmfExternal* pExtHeader = nullptr; WmfExternal* pExtHeader = nullptr;
if (rFilter.ImportGraphic(aGraphic, OUString(), aInStream, GRFILTER_FORMAT_DONTKNOW, nullptr, GraphicFilterImportFlags::NONE, pExtHeader) != ERRCODE_NONE) if (rFilter.ImportGraphic(aGraphic, OUString(), aInStream, GRFILTER_FORMAT_DONTKNOW, nullptr,
GraphicFilterImportFlags::NONE, pExtHeader)
!= ERRCODE_NONE)
return; return;
BitmapEx aBitmapEx = aGraphic.GetBitmapEx(); BitmapEx aBitmapEx = aGraphic.GetBitmapEx();
...@@ -66,11 +68,14 @@ int pdfVerify(int nArgc, char** pArgv) ...@@ -66,11 +68,14 @@ int pdfVerify(int nArgc, char** pArgv)
} }
catch (const uno::RuntimeException& rException) catch (const uno::RuntimeException& rException)
{ {
SAL_WARN("xmlsecurity.pdfio", "cppu::defaultBootstrap_InitialComponentContext() failed: " << rException); SAL_WARN("xmlsecurity.pdfio",
"cppu::defaultBootstrap_InitialComponentContext() failed: " << rException);
return 1; return 1;
} }
uno::Reference<lang::XMultiComponentFactory> xMultiComponentFactory = xComponentContext->getServiceManager(); uno::Reference<lang::XMultiComponentFactory> xMultiComponentFactory
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xMultiComponentFactory, uno::UNO_QUERY); = xComponentContext->getServiceManager();
uno::Reference<lang::XMultiServiceFactory> xMultiServiceFactory(xMultiComponentFactory,
uno::UNO_QUERY);
comphelper::setProcessServiceFactory(xMultiServiceFactory); comphelper::setProcessServiceFactory(xMultiServiceFactory);
if (nArgc > 3 && OString(pArgv[3]) == "-p") if (nArgc > 3 && OString(pArgv[3]) == "-p")
...@@ -88,10 +93,12 @@ int pdfVerify(int nArgc, char** pArgv) ...@@ -88,10 +93,12 @@ int pdfVerify(int nArgc, char** pArgv)
} }
catch (const uno::DeploymentException& rException) catch (const uno::DeploymentException& rException)
{ {
SAL_WARN("xmlsecurity.pdfio", "DeploymentException while creating SEInitializer: " << rException); SAL_WARN("xmlsecurity.pdfio",
"DeploymentException while creating SEInitializer: " << rException);
return 1; return 1;
} }
uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext = xSEInitializer->createSecurityContext(OUString()); uno::Reference<xml::crypto::XXMLSecurityContext> xSecurityContext
= xSEInitializer->createSecurityContext(OUString());
OUString aInURL; OUString aInURL;
osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(pArgv[1]), aInURL); osl::FileBase::getFileURLFromSystemPath(OUString::fromUtf8(pArgv[1]), aInURL);
...@@ -157,7 +164,8 @@ int pdfVerify(int nArgc, char** pArgv) ...@@ -157,7 +164,8 @@ int pdfVerify(int nArgc, char** pArgv)
return 1; return 1;
} }
bool bSuccess = aInfo.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; bool bSuccess
= aInfo.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED;
std::cerr << "signature #" << i << ": digest match? " << bSuccess << std::endl; std::cerr << "signature #" << i << ": digest match? " << bSuccess << std::endl;
} }
} }
...@@ -166,8 +174,10 @@ int pdfVerify(int nArgc, char** pArgv) ...@@ -166,8 +174,10 @@ int pdfVerify(int nArgc, char** pArgv)
} }
std::cerr << "adding a new signature" << std::endl; std::cerr << "adding a new signature" << std::endl;
uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment = xSecurityContext->getSecurityEnvironment(); uno::Reference<xml::crypto::XSecurityEnvironment> xSecurityEnvironment
uno::Sequence<uno::Reference<security::XCertificate>> aCertificates = xSecurityEnvironment->getPersonalCertificates();