summaryrefslogtreecommitdiff
path: root/vcl/source
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2024-11-22 21:19:41 +0900
committerTomaž Vajngerl <quikee@gmail.com>2024-12-24 07:28:18 +0100
commit7257cd8b5420e398f14456e6713de61850223dba (patch)
treed34bef60957ebec882386c2df8a0c780f8b2aca7 /vcl/source
parentad714ad52c49d8fdf6da4a227307130b14841f79 (diff)
pdf: get rid of PDFWriter::AppendUnicodeTextString
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 <jenkinscollaboraoffice@gmail.com> Reviewed-by: Miklos Vajna <vmiklos@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/178763 Tested-by: Tomaž Vajngerl <quikee@gmail.com> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'vcl/source')
-rw-r--r--vcl/source/filter/ipdf/pdfdocument.cxx8
-rw-r--r--vcl/source/gdi/pdfwriter_impl.cxx49
2 files changed, 23 insertions, 34 deletions
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 <o3tl/safeint.hxx>
#include <pdf/objectcopier.hxx>
+#include <pdf/COSWriter.hxx>
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"
"<</Contents <");
@@ -167,9 +169,9 @@ sal_Int32 PDFDocument::WriteSignatureObject(svl::crypto::SigningContext& rSignin
if (!rDescription.isEmpty())
{
- aSigBuffer.append("/Reason<");
- vcl::PDFWriter::AppendUnicodeTextString(rDescription, aSigBuffer);
- aSigBuffer.append(">");
+ 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<PDFStructureElement> & 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<sal_Int8>(aChar >> 8), rBuffer );
- appendHex( static_cast<sal_Int8>(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<sal_uInt8>& 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("<</Type /Filespec");
aLine.append("/F<");
- PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine);
+ COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, 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 <</F ");
@@ -5420,7 +5407,7 @@ bool PDFWriterImpl::emitCatalog()
for (auto & rAttachedFile : m_aDocumentAttachedFiles)
{
aLine.append('<');
- PDFWriter::AppendUnicodeTextString(rAttachedFile.maFilename, aLine);
+ COSWriter::appendUnicodeTextString(rAttachedFile.maFilename, aLine);
aLine.append('>');
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();