From 31427786778946b9d6f0f23731fdaae40e967e21 Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 22 Nov 2024 15:21:34 +0900 Subject: pdf: move PDFStructureWriter into own file, rename to COSWriter MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This needs to duplicate some functions from pdfwriter_impl to make this possible. Change-Id: Ie738c9690306d6498c883f034a3fcd6483f24eef Reviewed-on: https://gerrit.libreoffice.org/c/core/+/176985 Tested-by: Jenkins CollaboraOffice Reviewed-by: Miklos Vajna Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178762 Tested-by: Jenkins Reviewed-by: Tomaž Vajngerl --- vcl/source/gdi/pdfwriter_impl.cxx | 98 +++++---------------------------------- 1 file changed, 12 insertions(+), 86 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 56311e7f2791..a4c2a501443b 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -85,6 +85,7 @@ #include #include +#include #include #include #include @@ -308,83 +309,6 @@ GEOMETRY lcl_convert( const MapMode& _rSource, const MapMode& _rDest, OutputDevi void removePlaceholderSE(std::vector & rStructure, PDFStructureElement& rEle); -/** Writes the PDF structure to the string buffer. - * - * Structure elements like: objects, IDs, dictionaries, key/values, ... - */ -class PDFStructureWriter -{ - OStringBuffer maLine; - PDFWriterImpl& mrWriterImpl; -public: - PDFStructureWriter(PDFWriterImpl& rWriterImpl) - : maLine(1024) - , mrWriterImpl(rWriterImpl) - { - } - - void startObject(sal_Int32 nID) - { - appendObjectID(nID, maLine); - } - - void endObject() - { - maLine.append("endobj\n\n"); - } - - OStringBuffer& getLine() - { - return maLine; - } - - void startDict() - { - maLine.append("<<"); - } - - void endDict() - { - maLine.append(">>\n"); - } - - void write(std::string_view key, std::string_view value) - { - maLine.append(key); - maLine.append(value); - } - - void write(std::string_view key, sal_Int32 value) - { - maLine.append(key); - maLine.append(" "); - maLine.append(value); - } - - void writeUnicodeEncrypt(std::string_view key, OUString const& rString, sal_Int32 nObject) - { - maLine.append(key); - mrWriterImpl.appendUnicodeTextStringEncrypt(rString, nObject, maLine); - } - - void writeLiteralEncrypt(std::string_view key, std::string_view value, sal_Int32 nObject) - { - maLine.append(key); - mrWriterImpl.appendLiteralStringEncrypt(value, nObject, maLine); - } - - void writeHexArray(std::string_view key, sal_uInt8* pData, size_t nSize) - { - maLine.append(key); - maLine.append(" <"); - for (size_t i = 0; i < nSize; i++) - { - appendHex(sal_Int8(pData[i]), maLine); - } - maLine.append(">"); - } -}; - } // end anonymous namespace void PDFWriter::AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer) @@ -5880,7 +5804,9 @@ sal_Int32 PDFWriterImpl::emitInfoDict( ) if (!updateObject(nObject)) return 0; - PDFStructureWriter aWriter(*this); + COSWriter aWriter(m_pPDFEncryptor); + bool bEncrypt = m_aContext.Encryption.canEncrypt(); + auto& rKey = m_aContext.Encryption.EncryptionKey; aWriter.startObject(nObject); aWriter.startDict(); @@ -5890,31 +5816,31 @@ sal_Int32 PDFWriterImpl::emitInfoDict( ) { if (!m_aContext.DocumentInfo.Title.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Title", m_aContext.DocumentInfo.Title, nObject); + aWriter.writeUnicodeEncrypt("/Title", m_aContext.DocumentInfo.Title, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Author.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Author", m_aContext.DocumentInfo.Author, nObject); + aWriter.writeUnicodeEncrypt("/Author", m_aContext.DocumentInfo.Author, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Subject.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Subject", m_aContext.DocumentInfo.Subject, nObject); + aWriter.writeUnicodeEncrypt("/Subject", m_aContext.DocumentInfo.Subject, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Keywords.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Keywords", m_aContext.DocumentInfo.Keywords, nObject); + aWriter.writeUnicodeEncrypt("/Keywords", m_aContext.DocumentInfo.Keywords, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Creator.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Creator", m_aContext.DocumentInfo.Creator, nObject); + aWriter.writeUnicodeEncrypt("/Creator", m_aContext.DocumentInfo.Creator, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Producer.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Producer", m_aContext.DocumentInfo.Producer, nObject); + aWriter.writeUnicodeEncrypt("/Producer", m_aContext.DocumentInfo.Producer, nObject, bEncrypt, rKey); } } // Allowed in PDF 2.0 - aWriter.writeLiteralEncrypt("/CreationDate", m_aCreationDateString, nObject); + aWriter.writeLiteralEncrypt("/CreationDate", m_aCreationDateString, nObject, bEncrypt, rKey); aWriter.endDict(); aWriter.endObject(); @@ -6173,7 +6099,7 @@ sal_Int32 PDFWriterImpl::emitEncrypt() if (updateObject(nObject)) { PDFEncryptionProperties& rProperties = m_aContext.Encryption; - PDFStructureWriter aWriter(*this); + COSWriter aWriter(m_pPDFEncryptor); aWriter.startObject(nObject); aWriter.startDict(); aWriter.write("/Filter", "/Standard"); -- cgit