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
{
namespace filter
{
class PDFTrailerElement;
class PDFHexStringElement;
class PDFReferenceElement;
......@@ -67,9 +66,9 @@ class VCL_DLLPUBLIC PDFObjectElement : public PDFElement
/// The stream of this object, used when this is an object stream.
PDFStreamElement* m_pStreamElement;
/// 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.
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.
std::unique_ptr<SvMemoryStream> m_pStreamBuffer;
/// List of all reference elements inside this object's dictionary and
......@@ -105,7 +104,7 @@ public:
PDFArrayElement* GetArray() const;
/// Parse objects stored in this object stream.
void ParseStoredObjects();
std::vector< std::unique_ptr<PDFElement> >& GetStoredElements();
std::vector<std::unique_ptr<PDFElement>>& GetStoredElements();
SvMemoryStream* GetStreamBuffer() const;
void SetStreamBuffer(std::unique_ptr<SvMemoryStream>& pStreamBuffer);
PDFDocument& GetDocument();
......@@ -117,6 +116,7 @@ class VCL_DLLPUBLIC PDFArrayElement : public PDFElement
std::vector<PDFElement*> m_aElements;
/// The object that contains this array.
PDFObjectElement* m_pObject;
public:
PDFArrayElement(PDFObjectElement* pObject);
bool Read(SvStream& rStream) override;
......@@ -136,7 +136,8 @@ class VCL_DLLPUBLIC PDFReferenceElement : public PDFElement
PDFNumberElement& m_rObject;
public:
PDFReferenceElement(PDFDocument& rDoc, PDFNumberElement& rObject, PDFNumberElement const& rGeneration);
PDFReferenceElement(PDFDocument& rDoc, PDFNumberElement& rObject,
PDFNumberElement const& rGeneration);
bool Read(SvStream& rStream) override;
/// Assuming the reference points to a number object, return its value.
double LookupNumber(SvStream& rStream) const;
......@@ -171,6 +172,7 @@ class VCL_DLLPUBLIC PDFNameElement : public PDFElement
sal_uInt64 m_nLocation = 0;
/// Length till the next token start.
sal_uInt64 m_nLength = 0;
public:
PDFNameElement();
bool Read(SvStream& rStream) override;
......@@ -195,8 +197,10 @@ public:
PDFDictionaryElement();
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 PDFElement* Lookup(const std::map<OString, PDFElement*>& rDictionary, const OString& rKey);
static size_t Parse(const std::vector<std::unique_ptr<PDFElement>>& rElements,
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);
sal_uInt64 GetKeyOffset(const OString& rKey) const;
void SetKeyValueLength(const OString& rKey, sal_uInt64 nLength);
......@@ -252,6 +256,7 @@ struct XRefEntry
class VCL_DLLPUBLIC PDFHexStringElement : public PDFElement
{
OString m_aValue;
public:
bool Read(SvStream& rStream) override;
const OString& GetValue() const;
......@@ -261,6 +266,7 @@ public:
class VCL_DLLPUBLIC PDFLiteralStringElement : public PDFElement
{
OString m_aValue;
public:
bool Read(SvStream& rStream) override;
const OString& GetValue() const;
......@@ -293,7 +299,7 @@ public:
class VCL_DLLPUBLIC PDFDocument
{
/// 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.
std::map<size_t, XRefEntry> m_aXRef;
/// Object offset <-> Object pointer map.
......@@ -317,11 +323,13 @@ class VCL_DLLPUBLIC PDFDocument
/// Suggest a minimal, yet free signature ID to use for the next signature.
sal_uInt32 GetNextSignature();
/// 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.
sal_Int32 WriteAppearanceObject();
/// 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.
bool WritePageObject(PDFObjectElement& rFirstPage, sal_Int32 nAnnotId);
/// Write the updated Catalog object as part of signing.
......@@ -345,7 +353,7 @@ public:
/// Instead of all whitespace, just skip CR and NL characters.
static void SkipLineBreaks(SvStream& rStream);
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();
/// Remember the end location of an EOF token.
void PushBackEOF(size_t nOffset);
......@@ -354,7 +362,9 @@ public:
/// Access to the input document, even after the input stream is gone.
SvMemoryStream& GetEditBuffer();
/// 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.
void SetIDObject(size_t nID, PDFObjectElement* pObject);
//@}
......@@ -364,7 +374,8 @@ public:
/// Read elements from the start of the stream till its end.
bool Read(SvStream& rStream);
/// 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.
bool Write(SvStream& rStream);
/// Get a list of signatures embedded into this document.
......
......@@ -8009,7 +8009,6 @@ include/vcl/evntpost.hxx
include/vcl/exceptiontypes.hxx
include/vcl/extoutdevdata.hxx
include/vcl/field.hxx
include/vcl/filter/pdfdocument.hxx
include/vcl/fixed.hxx
include/vcl/fixedhyper.hxx
include/vcl/floatwin.hxx
......@@ -17652,7 +17651,6 @@ vcl/inc/outdev.h
vcl/inc/outdevstatestack.hxx
vcl/inc/pch/precompiled_vcl.cxx
vcl/inc/pch/precompiled_vcl.hxx
vcl/inc/pdfread.hxx
vcl/inc/print.h
vcl/inc/printdlg.hxx
vcl/inc/printerinfomanager.hxx
......@@ -18098,8 +18096,6 @@ vcl/source/filter/igif/decode.cxx
vcl/source/filter/igif/decode.hxx
vcl/source/filter/igif/gifread.cxx
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.hxx
vcl/source/filter/ixpm/rgbtable.hxx
......@@ -19669,7 +19665,6 @@ xmlsecurity/inc/pch/precompiled_xsec_gpg.cxx
xmlsecurity/inc/pch/precompiled_xsec_gpg.hxx
xmlsecurity/inc/pch/precompiled_xsec_xmlsec.cxx
xmlsecurity/inc/pch/precompiled_xsec_xmlsec.hxx
xmlsecurity/inc/pdfio/pdfdocument.hxx
xmlsecurity/inc/resourcemanager.hxx
xmlsecurity/inc/xmlsec-wrapper.h
xmlsecurity/inc/xmlsec/errorcallback.hxx
......@@ -19685,7 +19680,6 @@ xmlsecurity/inc/xsecfwdllapi.h
xmlsecurity/inc/xsecgpgdllapi.h
xmlsecurity/inc/xsecxmlsecdllapi.h
xmlsecurity/qa/certext/SanCertExt.cxx
xmlsecurity/qa/unit/pdfsigning/pdfsigning.cxx
xmlsecurity/qa/unit/signing/signing.cxx
xmlsecurity/qa/unit/xmlsecurity-dialogs-test.cxx
xmlsecurity/source/component/certificatecontainer.cxx
......@@ -19736,7 +19730,6 @@ xmlsecurity/source/helper/xsecparser.cxx
xmlsecurity/source/helper/xsecparser.hxx
xmlsecurity/source/helper/xsecsign.cxx
xmlsecurity/source/helper/xsecverify.cxx
xmlsecurity/source/pdfio/pdfdocument.cxx
xmlsecurity/source/xmlsec/biginteger.cxx
xmlsecurity/source/xmlsec/certificateextension_certextn.cxx
xmlsecurity/source/xmlsec/certificateextension_certextn.hxx
......@@ -19789,4 +19782,3 @@ xmlsecurity/source/xmlsec/xmlsec_init.cxx
xmlsecurity/source/xmlsec/xmlstreamio.cxx
xmlsecurity/source/xmlsec/xsec_xmlsec.cxx
xmlsecurity/source/xmlsec/xsec_xmlsec.hxx
xmlsecurity/workben/pdfverify.cxx
......@@ -18,14 +18,12 @@ class Graphic;
namespace vcl
{
/// Imports a PDF stream into rGraphic as a GDIMetaFile.
VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Bitmap& rBitmap,
css::uno::Sequence<sal_Int8>& rPdfData,
sal_uInt64 nPos = STREAM_SEEK_TO_BEGIN,
sal_uInt64 nSize = STREAM_SEEK_TO_END);
VCL_DLLPUBLIC bool ImportPDF(SvStream& rStream, Graphic& rGraphic);
}
#endif // INCLUDED_VCL_SOURCE_FILTER_IPDF_PDFREAD_HXX
......
......@@ -33,7 +33,6 @@ namespace vcl
{
namespace filter
{
const int MAX_SIGNATURE_CONTENT_LENGTH = 50000;
class PDFTrailerElement;
......@@ -56,6 +55,7 @@ class PDFEndDictionaryElement : public PDFElement
{
/// Offset before the '>>' token.
sal_uInt64 m_nLocation = 0;
public:
PDFEndDictionaryElement();
bool Read(SvStream& rStream) override;
......@@ -81,6 +81,7 @@ class PDFEndArrayElement : public PDFElement
{
/// Location before the ']' token.
sal_uInt64 m_nOffset = 0;
public:
PDFEndArrayElement();
bool Read(SvStream& rStream) override;
......@@ -132,7 +133,8 @@ bool PDFDocument::RemoveSignature(size_t nPosition)
if (aSignatures.size() != m_aEOFs.size() - 1)
{
SAL_WARN("vcl.filter", "PDFDocument::RemoveSignature: no 1:1 mapping between signatures and incremental updates");
SAL_WARN("vcl.filter", "PDFDocument::RemoveSignature: no 1:1 mapping between signatures "
"and incremental updates");
return false;
}
......@@ -165,7 +167,9 @@ sal_uInt32 PDFDocument::GetNextSignature()
return nRet + 1;
}
sal_Int32 PDFDocument::WriteSignatureObject(const OUString& rDescription, bool bAdES, sal_uInt64& rLastByteRangeOffset, sal_Int64& rContentOffset)
sal_Int32 PDFDocument::WriteSignatureObject(const OUString& rDescription, bool bAdES,
sal_uInt64& rLastByteRangeOffset,
sal_Int64& rContentOffset)
{
// Write signature object.
sal_Int32 nSignatureId = m_aXRef.size();
......@@ -240,7 +244,8 @@ sal_Int32 PDFDocument::WriteAppearanceObject()
return nAppearanceId;
}
sal_Int32 PDFDocument::WriteAnnotObject(PDFObjectElement const& rFirstPage, sal_Int32 nSignatureId, sal_Int32 nAppearanceId)
sal_Int32 PDFDocument::WriteAnnotObject(PDFObjectElement const& rFirstPage, sal_Int32 nSignatureId,
sal_Int32 nAppearanceId)
{
// Decide what identifier to use for the new signature.
sal_uInt32 nNextSignature = GetNextSignature();
......@@ -341,7 +346,9 @@ bool PDFDocument::WritePageObject(PDFObjectElement& rFirstPage, sal_Int32 nAnnot
if (!pAnnotsArray)
{
// No Annots key, just write the key with a single reference.
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + rFirstPage.GetDictionaryOffset(), rFirstPage.GetDictionaryLength());
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ rFirstPage.GetDictionaryOffset(),
rFirstPage.GetDictionaryLength());
m_aEditBuffer.WriteCharPtr("/Annots[");
m_aEditBuffer.WriteUInt32AsString(nAnnotId);
m_aEditBuffer.WriteCharPtr(" 0 R]");
......@@ -352,16 +359,23 @@ bool PDFDocument::WritePageObject(PDFObjectElement& rFirstPage, sal_Int32 nAnnot
PDFDictionaryElement* pDictionary = rFirstPage.GetDictionary();
// Offset right before the end of the Annots array.
sal_uInt64 nAnnotsEndOffset = pDictionary->GetKeyOffset("Annots") + pDictionary->GetKeyValueLength("Annots") - 1;
sal_uInt64 nAnnotsEndOffset = pDictionary->GetKeyOffset("Annots")
+ pDictionary->GetKeyValueLength("Annots") - 1;
// Length of beginning of the dictionary -> Annots end.
sal_uInt64 nAnnotsBeforeEndLength = nAnnotsEndOffset - rFirstPage.GetDictionaryOffset();
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + rFirstPage.GetDictionaryOffset(), nAnnotsBeforeEndLength);
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ rFirstPage.GetDictionaryOffset(),
nAnnotsBeforeEndLength);
m_aEditBuffer.WriteCharPtr(" ");
m_aEditBuffer.WriteUInt32AsString(nAnnotId);
m_aEditBuffer.WriteCharPtr(" 0 R");
// Length of Annots end -> end of the dictionary.
sal_uInt64 nAnnotsAfterEndLength = rFirstPage.GetDictionaryOffset() + rFirstPage.GetDictionaryLength() - nAnnotsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + nAnnotsEndOffset, nAnnotsAfterEndLength);
sal_uInt64 nAnnotsAfterEndLength = rFirstPage.GetDictionaryOffset()
+ rFirstPage.GetDictionaryLength()
- nAnnotsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ nAnnotsEndOffset,
nAnnotsAfterEndLength);
}
m_aEditBuffer.WriteCharPtr(">>");
m_aEditBuffer.WriteCharPtr("\nendobj\n\n");
......@@ -424,7 +438,8 @@ bool PDFDocument::WriteCatalogObject(sal_Int32 nAnnotId, PDFReferenceElement*& p
if (!pAcroFormObject->Lookup("Fields"))
{
SAL_WARN("vcl.filter", "PDFDocument::Sign: AcroForm object without required Fields key");
SAL_WARN("vcl.filter",
"PDFDocument::Sign: AcroForm object without required Fields key");
return false;
}
......@@ -436,7 +451,9 @@ bool PDFDocument::WriteCatalogObject(sal_Int32 nAnnotId, PDFReferenceElement*& p
}
// Offset right before the end of the Fields array.
sal_uInt64 nFieldsEndOffset = pAcroFormDictionary->GetKeyOffset("Fields") + pAcroFormDictionary->GetKeyValueLength("Fields") - strlen("]");
sal_uInt64 nFieldsEndOffset = pAcroFormDictionary->GetKeyOffset("Fields")
+ pAcroFormDictionary->GetKeyValueLength("Fields")
- strlen("]");
// Length of beginning of the object dictionary -> Fields end.
sal_uInt64 nFieldsBeforeEndLength = nFieldsEndOffset;
if (pStreamBuffer)
......@@ -445,7 +462,9 @@ bool PDFDocument::WriteCatalogObject(sal_Int32 nAnnotId, PDFReferenceElement*& p
{
nFieldsBeforeEndLength -= pAcroFormObject->GetDictionaryOffset();
m_aEditBuffer.WriteCharPtr("<<");
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + pAcroFormObject->GetDictionaryOffset(), nFieldsBeforeEndLength);
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ pAcroFormObject->GetDictionaryOffset(),
nFieldsBeforeEndLength);
}
// Append our reference at the end of the Fields array.
......@@ -457,12 +476,18 @@ bool PDFDocument::WriteCatalogObject(sal_Int32 nAnnotId, PDFReferenceElement*& p
if (pStreamBuffer)
{
sal_uInt64 nFieldsAfterEndLength = pStreamBuffer->GetSize() - nFieldsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(pStreamBuffer->GetData()) + nFieldsEndOffset, nFieldsAfterEndLength);
m_aEditBuffer.WriteBytes(static_cast<const char*>(pStreamBuffer->GetData())
+ nFieldsEndOffset,
nFieldsAfterEndLength);
}
else
{
sal_uInt64 nFieldsAfterEndLength = pAcroFormObject->GetDictionaryOffset() + pAcroFormObject->GetDictionaryLength() - nFieldsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + nFieldsEndOffset, nFieldsAfterEndLength);
sal_uInt64 nFieldsAfterEndLength = pAcroFormObject->GetDictionaryOffset()
+ pAcroFormObject->GetDictionaryLength()
- nFieldsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ nFieldsEndOffset,
nFieldsAfterEndLength);
m_aEditBuffer.WriteCharPtr(">>");
}
......@@ -480,7 +505,9 @@ bool PDFDocument::WriteCatalogObject(sal_Int32 nAnnotId, PDFReferenceElement*& p
if (!pAcroFormDictionary)
{
// No AcroForm key, assume no signatures.
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + pCatalog->GetDictionaryOffset(), pCatalog->GetDictionaryLength());
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ pCatalog->GetDictionaryOffset(),
pCatalog->GetDictionaryLength());
m_aEditBuffer.WriteCharPtr("/AcroForm<</Fields[\n");
m_aEditBuffer.WriteUInt32AsString(nAnnotId);
m_aEditBuffer.WriteCharPtr(" 0 R\n]/SigFlags 3>>\n");
......@@ -503,16 +530,22 @@ bool PDFDocument::WriteCatalogObject(sal_Int32 nAnnotId, PDFReferenceElement*& p
}
// Offset right before the end of the Fields array.
sal_uInt64 nFieldsEndOffset = pAcroFormDictionary->GetKeyOffset("Fields") + pAcroFormDictionary->GetKeyValueLength("Fields") - 1;
sal_uInt64 nFieldsEndOffset = pAcroFormDictionary->GetKeyOffset("Fields")
+ pAcroFormDictionary->GetKeyValueLength("Fields") - 1;
// Length of beginning of the Catalog dictionary -> Fields end.
sal_uInt64 nFieldsBeforeEndLength = nFieldsEndOffset - pCatalog->GetDictionaryOffset();
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + pCatalog->GetDictionaryOffset(), nFieldsBeforeEndLength);
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ pCatalog->GetDictionaryOffset(),
nFieldsBeforeEndLength);
m_aEditBuffer.WriteCharPtr(" ");
m_aEditBuffer.WriteUInt32AsString(nAnnotId);
m_aEditBuffer.WriteCharPtr(" 0 R");
// Length of Fields end -> end of the Catalog dictionary.
sal_uInt64 nFieldsAfterEndLength = pCatalog->GetDictionaryOffset() + pCatalog->GetDictionaryLength() - nFieldsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData()) + nFieldsEndOffset, nFieldsAfterEndLength);
sal_uInt64 nFieldsAfterEndLength = pCatalog->GetDictionaryOffset()
+ pCatalog->GetDictionaryLength() - nFieldsEndOffset;
m_aEditBuffer.WriteBytes(static_cast<const char*>(m_aEditBuffer.GetData())
+ nFieldsEndOffset,
nFieldsAfterEndLength);
}
m_aEditBuffer.WriteCharPtr(">>\nendobj\n\n");
}
......@@ -559,15 +592,15 @@ void PDFDocument::WriteXRef(sal_uInt64 nXRefOffset, PDFReferenceElement const* p
unsigned char nType = 0;
switch (rEntry.m_eType)
{
case XRefEntryType::FREE:
nType = 0;
break;
case XRefEntryType::NOT_COMPRESSED:
nType = 1;
break;
case XRefEntryType::COMPRESSED:
nType = 2;
break;
case XRefEntryType::FREE:
nType = 0;
break;
case XRefEntryType::NOT_COMPRESSED:
nType = 1;
break;
case XRefEntryType::COMPRESSED:
nType = 2;
break;
}
aOrigLine[nPos++] = nType;
......@@ -598,7 +631,8 @@ void PDFDocument::WriteXRef(sal_uInt64 nXRefOffset, PDFReferenceElement const* p
}
m_aEditBuffer.WriteUInt32AsString(nXRefStreamId);
m_aEditBuffer.WriteCharPtr(" 0 obj\n<</DecodeParms<</Columns 5/Predictor 12>>/Filter/FlateDecode");
m_aEditBuffer.WriteCharPtr(
" 0 obj\n<</DecodeParms<</Columns 5/Predictor 12>>/Filter/FlateDecode");
// ID.
auto pID = dynamic_cast<PDFArrayElement*>(m_pXRefStream->Lookup("ID"));
......@@ -751,14 +785,16 @@ void PDFDocument::WriteXRef(sal_uInt64 nXRefOffset, PDFReferenceElement const* p
}
}
bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate, const OUString& rDescription, bool bAdES)
bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificate,
const OUString& rDescription, bool bAdES)
{
m_aEditBuffer.Seek(STREAM_SEEK_TO_END);
m_aEditBuffer.WriteCharPtr("\n");
sal_uInt64 nSignatureLastByteRangeOffset = 0;
sal_Int64 nSignatureContentOffset = 0;
sal_Int32 nSignatureId = WriteSignatureObject(rDescription, bAdES, nSignatureLastByteRangeOffset, nSignatureContentOffset);
sal_Int32 nSignatureId = WriteSignatureObject(
rDescription, bAdES, nSignatureLastByteRangeOffset, nSignatureContentOffset);
sal_Int32 nAppearanceId = WriteAppearanceObject();
......@@ -796,7 +832,8 @@ bool PDFDocument::Sign(const uno::Reference<security::XCertificate>& xCertificat
// Finalize the signature, now that we know the total file size.
// Calculate the length of the last byte range.
sal_uInt64 nFileEnd = m_aEditBuffer.Tell();
sal_Int64 nLastByteRangeLength = nFileEnd - (nSignatureContentOffset + MAX_SIGNATURE_CONTENT_LENGTH + 1);
sal_Int64 nLastByteRangeLength
= nFileEnd - (nSignatureContentOffset + MAX_SIGNATURE_CONTENT_LENGTH + 1);
// Write the length to the buffer.
m_aEditBuffer.Seek(nSignatureLastByteRangeOffset);
OStringBuffer aByteRangeBuffer;
......@@ -847,7 +884,9 @@ bool PDFDocument::Write(SvStream& rStream)
return rStream.good();
}
bool PDFDocument::Tokenize(SvStream& rStream, TokenizeMode eMode, std::vector< std::unique_ptr<PDFElement> >& rElements, PDFObjectElement* pObjectElement)
bool PDFDocument::Tokenize(SvStream& rStream, TokenizeMode eMode,
std::vector<std::unique_ptr<PDFElement>>& rElements,
PDFObjectElement* pObjectElement)
{
// Last seen object token.
PDFObjectElement* pObject = pObjectElement;
......@@ -873,322 +912,346 @@ bool PDFDocument::Tokenize(SvStream& rStream, TokenizeMode eMode, std::vector< s
switch (ch)
{
case '%':
{
auto pComment = new PDFCommentElement(*this);
rElements.push_back(std::unique_ptr<PDFElement>(pComment));
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFCommentElement::Read() failed");
return false;
}
if (eMode == TokenizeMode::EOF_TOKEN && !m_aEOFs.empty() && m_aEOFs.back() == rStream.Tell())
{
// Found EOF and partial parsing requested, we're done.
return true;
}
break;
}
case '<':
{
// Dictionary or hex string.
rStream.ReadChar(ch);
rStream.SeekRel(-2);
if (ch == '<')
{
rElements.push_back(std::unique_ptr<PDFElement>(new PDFDictionaryElement()));
++nDictionaryDepth;
}
else
rElements.push_back(std::unique_ptr<PDFElement>(new PDFHexStringElement));
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFDictionaryElement::Read() failed");
return false;
}
break;
}
case '>':
{
rElements.push_back(std::unique_ptr<PDFElement>(new PDFEndDictionaryElement()));
--nDictionaryDepth;
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFEndDictionaryElement::Read() failed");
return false;
}
break;
}
case '[':
{
auto pArr = new PDFArrayElement(pObject);
rElements.push_back(std::unique_ptr<PDFElement>(pArr));
if (nDictionaryDepth == 0 && nArrayDepth == 0)
case '%':
{
// The array is attached directly, inform the object.
pArray = pArr;
if (pObject)
auto pComment = new PDFCommentElement(*this);
rElements.push_back(std::unique_ptr<PDFElement>(pComment));
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
{
pObject->SetArray(pArray);
pObject->SetArrayOffset(rStream.Tell());
SAL_WARN("vcl.filter",
"PDFDocument::Tokenize: PDFCommentElement::Read() failed");
return false;
}
if (eMode == TokenizeMode::EOF_TOKEN && !m_aEOFs.empty()
&& m_aEOFs.back() == rStream.Tell())
{
// Found EOF and partial parsing requested, we're done.
return true;
}
break;
}
++nArrayDepth;
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
case '<':
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFArrayElement::Read() failed");
return false;
}
break;
}
case ']':
{
rElements.push_back(std::unique_ptr<PDFElement>(new PDFEndArrayElement()));
--nArrayDepth;
if (nArrayDepth == 0)
pArray = nullptr;
rStream.SeekRel(-1);
if (nDictionaryDepth == 0 && nArrayDepth == 0)
{
if (pObject)
// Dictionary or hex string.
rStream.ReadChar(ch);
rStream.SeekRel(-2);
if (ch == '<')
{
pObject->SetArrayLength(rStream.Tell() - pObject->GetArrayOffset());
rElements.push_back(std::unique_ptr<PDFElement>(new PDFDictionaryElement()));
++nDictionaryDepth;
}
else
rElements.push_back(std::unique_ptr<PDFElement>(new PDFHexStringElement));
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter",
"PDFDocument::Tokenize: PDFDictionaryElement::Read() failed");
return false;
}
break;
}
if (!rElements.back()->Read(rStream))
case '>':
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFEndArrayElement::Read() failed");
return false;
rElements.push_back(std::unique_ptr<PDFElement>(new PDFEndDictionaryElement()));
--nDictionaryDepth;
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter",
"PDFDocument::Tokenize: PDFEndDictionaryElement::Read() failed");
return false;
}
break;
}
break;
}
case '/':
{
auto pNameElement = new PDFNameElement();
rElements.push_back(std::unique_ptr<PDFElement>(pNameElement));
rStream.SeekRel(-1);
if (!pNameElement->Read(rStream))
case '[':
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFNameElement::Read() failed");
return false;
auto pArr = new PDFArrayElement(pObject);
rElements.push_back(std::unique_ptr<PDFElement>(pArr));
if (nDictionaryDepth == 0 && nArrayDepth == 0)
{
// The array is attached directly, inform the object.
pArray = pArr;
if (pObject)
{
pObject->SetArray(pArray);
pObject->SetArrayOffset(rStream.Tell());
}
}
++nArrayDepth;
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFArrayElement::Read() failed");
return false;
}
break;
}
if (pObject && pObjectKey && pObjectKey->GetValue() == "Type" && pNameElement->GetValue() == "ObjStm")
pObjectStream = pObject;
else
pObjectKey = pNameElement;
break;
}
case '(':
{
rElements.push_back(std::unique_ptr<PDFElement>(new PDFLiteralStringElement));
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
case ']':
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFLiteralStringElement::Read() failed");
return false;
rElements.push_back(std::unique_ptr<PDFElement>(new PDFEndArrayElement()));
--nArrayDepth;
if (nArrayDepth == 0)
pArray = nullptr;
rStream.SeekRel(-1);
if (nDictionaryDepth == 0 && nArrayDepth == 0)
{
if (pObject)
{
pObject->SetArrayLength(rStream.Tell() - pObject->GetArrayOffset());
}
}
if (!rElements.back()->Read(rStream))
{
SAL_WARN("vcl.filter",
"PDFDocument::Tokenize: PDFEndArrayElement::Read() failed");
return false;
}
break;
}
break;
}
default:
{
if (rtl::isAsciiDigit(static_cast<unsigned char>(ch)) || ch == '-')
case '/':
{
// Numbering object: an integer or a real.
auto pNumberElement = new PDFNumberElement();
rElements.push_back(std::unique_ptr<PDFElement>(pNumberElement));
auto pNameElement = new PDFNameElement();
rElements.push_back(std::unique_ptr<PDFElement>(pNameElement));
rStream.SeekRel(-1);
if (!pNumberElement->Read(rStream))
if (!pNameElement->Read(rStream))
{
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFNumberElement::Read() failed");
SAL_WARN("vcl.filter", "PDFDocument::Tokenize: PDFNameElement::Read() failed");
return false;
}
if (bInStartXRef)
if (pObject && pObjectKey && pObjectKey->GetValue() == "Type"
&& pNameElement->GetValue() == "ObjStm")
pObjectStream = pObject;
else
pObjectKey = pNameElement;
break;
}
case '(':
{
rElements.push_back(std::unique_ptr<PDFElement>(new PDFLiteralStringElement));
rStream.SeekRel(-1);
if (!rElements.back()->Read(rStream))
{
bInStartXRef = false;
m_aStartXRefs.push_back(pNumberElement->GetValue());
auto it = m_aOffsetObjects.find(pNumberElement->GetValue());
if (it != m_aOffsetObjects.end())
m_pXRefStream = it->second;
SAL_WARN("vcl.filter",
"PDFDocument::Tokenize: PDFLiteralStringElement::Read() failed");
return false;
}
else if (bInObject && !nDictionaryDepth && !nArrayDepth && pObject)
// Number element inside an object, but outside a
// dictionary / array: remember it.