From 7257cd8b5420e398f14456e6713de61850223dba Mon Sep 17 00:00:00 2001 From: Tomaž Vajngerl Date: Fri, 22 Nov 2024 21:19:41 +0900 Subject: pdf: get rid of PDFWriter::AppendUnicodeTextString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It's not needed when we have COSWriter instead that could be used. Needed to change IPDFEncryptor from unique_ptr to shared_ptr so we can share it with COSWriter, but without the need to be set. Also rename the string literal and unicode methods that take a key to writeKeyAnd... methods to be mroe explicit. We will need methods that don't write a key sooner or later. Change-Id: I15c5d347c6658f7ded2de940acc968dee053d460 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/177037 Tested-by: Jenkins CollaboraOffice Reviewed-by: Miklos Vajna Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178763 Tested-by: Tomaž Vajngerl Reviewed-by: Tomaž Vajngerl --- vcl/source/filter/ipdf/pdfdocument.cxx | 8 +++--- vcl/source/gdi/pdfwriter_impl.cxx | 49 +++++++++++++--------------------- 2 files changed, 23 insertions(+), 34 deletions(-) (limited to 'vcl/source') diff --git a/vcl/source/filter/ipdf/pdfdocument.cxx b/vcl/source/filter/ipdf/pdfdocument.cxx index 65faa176c8a8..5b2b9ca412e0 100644 --- a/vcl/source/filter/ipdf/pdfdocument.cxx +++ b/vcl/source/filter/ipdf/pdfdocument.cxx @@ -31,6 +31,7 @@ #include #include +#include using namespace com::sun::star; @@ -133,6 +134,7 @@ sal_Int32 PDFDocument::WriteSignatureObject(svl::crypto::SigningContext& rSignin aSignatureEntry.SetOffset(m_aEditBuffer.Tell()); aSignatureEntry.SetDirty(true); m_aXRef[nSignatureId] = aSignatureEntry; + OStringBuffer aSigBuffer(OString::number(nSignatureId) + " 0 obj\n" "<"); + pdf::COSWriter aWriter(nullptr); + aWriter.writeKeyAndUnicode("/Reason", rDescription); + aSigBuffer.append(aWriter.getLine()); } aSigBuffer.append(" >>\nendobj\n\n"); diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index a4c2a501443b..ae63f2844d37 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -311,19 +311,6 @@ void removePlaceholderSE(std::vector & rStructure, PDFStruc } // end anonymous namespace -void PDFWriter::AppendUnicodeTextString(const OUString& rString, OStringBuffer& rBuffer) -{ - rBuffer.append( "FEFF" ); - const sal_Unicode* pStr = rString.getStr(); - sal_Int32 nLen = rString.getLength(); - for( int i = 0; i < nLen; i++ ) - { - sal_Unicode aChar = pStr[i]; - appendHex( static_cast(aChar >> 8), rBuffer ); - appendHex( static_cast(aChar & 255 ), rBuffer ); - } -} - void PDFWriterImpl::createWidgetFieldName( sal_Int32 i_nWidgetIndex, const PDFWriter::AnyWidget& i_rControl ) { /* #i80258# previously we use appendName here @@ -663,17 +650,17 @@ void computeDocumentIdentifier(std::vector& o_rIdentifier, OString aInfoValuesOut; OStringBuffer aID(1024); if (!i_rDocInfo.Title.isEmpty()) - PDFWriter::AppendUnicodeTextString(i_rDocInfo.Title, aID); + COSWriter::appendUnicodeTextString(i_rDocInfo.Title, aID); if (!i_rDocInfo.Author.isEmpty()) - PDFWriter::AppendUnicodeTextString(i_rDocInfo.Author, aID); + COSWriter::appendUnicodeTextString(i_rDocInfo.Author, aID); if (!i_rDocInfo.Subject.isEmpty()) - PDFWriter::AppendUnicodeTextString(i_rDocInfo.Subject, aID); + COSWriter::appendUnicodeTextString(i_rDocInfo.Subject, aID); if (!i_rDocInfo.Keywords.isEmpty()) - PDFWriter::AppendUnicodeTextString(i_rDocInfo.Keywords, aID); + COSWriter::appendUnicodeTextString(i_rDocInfo.Keywords, aID); if (!i_rDocInfo.Creator.isEmpty()) - PDFWriter::AppendUnicodeTextString(i_rDocInfo.Creator, aID); + COSWriter::appendUnicodeTextString(i_rDocInfo.Creator, aID); if (!i_rDocInfo.Producer.isEmpty()) - PDFWriter::AppendUnicodeTextString(i_rDocInfo.Producer, aID); + COSWriter::appendUnicodeTextString(i_rDocInfo.Producer, aID); TimeValue aTVal, aGMT; oslDateTime aDT; @@ -1557,7 +1544,7 @@ inline void PDFWriterImpl::appendUnicodeTextStringEncrypt( const OUString& rInSt appendHexArray(aNewBuffer.data(), aNewBuffer.size(), rOutBuffer); } else - PDFWriter::AppendUnicodeTextString(rInString, rOutBuffer); + COSWriter::appendUnicodeTextString(rInString, rOutBuffer); rOutBuffer.append( ">" ); } @@ -5373,18 +5360,18 @@ bool PDFWriterImpl::emitCatalog() appendObjectID(rAttachedFile.mnObjectId, aLine); aLine.append("< "); if (PDFWriter::PDFVersion::PDF_1_7 <= m_aContext.Version) { aLine.append("/UF<"); - PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine); + COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, aLine); aLine.append("> "); } if (!rAttachedFile.maDescription.isEmpty()) { aLine.append("/Desc <"); - PDFWriter::AppendUnicodeTextString(rAttachedFile.maDescription, aLine); + COSWriter::appendUnicodeTextString(rAttachedFile.maDescription, aLine); aLine.append("> "); } aLine.append("/EF <'); aLine.append(' '); appendObjectReference(rAttachedFile.mnObjectId, aLine); @@ -5816,31 +5803,31 @@ sal_Int32 PDFWriterImpl::emitInfoDict( ) { if (!m_aContext.DocumentInfo.Title.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Title", m_aContext.DocumentInfo.Title, nObject, bEncrypt, rKey); + aWriter.writeKeyAndUnicodeEncrypt("/Title", m_aContext.DocumentInfo.Title, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Author.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Author", m_aContext.DocumentInfo.Author, nObject, bEncrypt, rKey); + aWriter.writeKeyAndUnicodeEncrypt("/Author", m_aContext.DocumentInfo.Author, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Subject.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Subject", m_aContext.DocumentInfo.Subject, nObject, bEncrypt, rKey); + aWriter.writeKeyAndUnicodeEncrypt("/Subject", m_aContext.DocumentInfo.Subject, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Keywords.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Keywords", m_aContext.DocumentInfo.Keywords, nObject, bEncrypt, rKey); + aWriter.writeKeyAndUnicodeEncrypt("/Keywords", m_aContext.DocumentInfo.Keywords, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Creator.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Creator", m_aContext.DocumentInfo.Creator, nObject, bEncrypt, rKey); + aWriter.writeKeyAndUnicodeEncrypt("/Creator", m_aContext.DocumentInfo.Creator, nObject, bEncrypt, rKey); } if (!m_aContext.DocumentInfo.Producer.isEmpty()) { - aWriter.writeUnicodeEncrypt("/Producer", m_aContext.DocumentInfo.Producer, nObject, bEncrypt, rKey); + aWriter.writeKeyAndUnicodeEncrypt("/Producer", m_aContext.DocumentInfo.Producer, nObject, bEncrypt, rKey); } } // Allowed in PDF 2.0 - aWriter.writeLiteralEncrypt("/CreationDate", m_aCreationDateString, nObject, bEncrypt, rKey); + aWriter.writeKeyAndLiteralEncrypt("/CreationDate", m_aCreationDateString, nObject, bEncrypt, rKey); aWriter.endDict(); aWriter.endObject(); -- cgit