[Libreoffice-commits] .: Branch 'feature/pdf-signing' - filter/source vcl/inc vcl/source
Gökcen Eraslan
gokcen at kemper.freedesktop.org
Sat Jun 30 14:36:30 PDT 2012
filter/source/pdf/impdialog.cxx | 11 +++-----
filter/source/pdf/impdialog.hxx | 6 ++--
filter/source/pdf/pdfexport.cxx | 14 ++++++++++
filter/source/pdf/pdfexport.hxx | 6 ++++
vcl/inc/vcl/pdfwriter.hxx | 6 ++++
vcl/source/gdi/pdfwriter_impl.cxx | 50 +++++++++++++++++++++++++++++---------
6 files changed, 72 insertions(+), 21 deletions(-)
New commits:
commit 7a2a0dc0327b130da93ab52151a1aa1da1d4ac34
Author: Gökçen Eraslan <gokcen.eraslan at gmail.com>
Date: Sun Jul 1 00:33:03 2012 +0300
Make PDF Signing GUI operative.
Now, PDFWriterContext is used for signing information. GUI elements are
recorded to PDFWriterContext and used during signing process. Sign PDF
checkbox and Location/Contact Info/Reason boxes are all working now.
Change-Id: I1d0cb53323707efa7e460431dd1519bcd34e8b29
diff --git a/filter/source/pdf/impdialog.cxx b/filter/source/pdf/impdialog.cxx
index 6740143..1ca8a9a 100644
--- a/filter/source/pdf/impdialog.cxx
+++ b/filter/source/pdf/impdialog.cxx
@@ -127,10 +127,7 @@ ImpPDFTabDialog::ImpPDFTabDialog( Window* pParent,
mbConvertOOoTargets( sal_False ),
mbExportBmkToPDFDestination( sal_False ),
- mbSignPDF( sal_False ),
- msSignLocation ( ' ' ),
- msSignContact( ' ' ),
- msSignReason( ' ' )
+ mbSignPDF( sal_False )
{
FreeResource();
@@ -462,15 +459,15 @@ Sequence< PropertyValue > ImpPDFTabDialog::GetFilterData()
}
aRet[ nLength - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureLocation" ) );
- aRet[ nLength - nElementAdded ].Value <<= OUString( msSignLocation );
+ aRet[ nLength - nElementAdded ].Value <<= msSignLocation;
nElementAdded--;
aRet[ nLength - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureReason" ) );
- aRet[ nLength - nElementAdded ].Value <<= OUString( msSignReason );
+ aRet[ nLength - nElementAdded ].Value <<= msSignReason;
nElementAdded--;
aRet[ nLength - nElementAdded ].Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "SignatureContactInfo" ) );
- aRet[ nLength - nElementAdded ].Value <<= OUString( msSignContact );
+ aRet[ nLength - nElementAdded ].Value <<= msSignContact;
nElementAdded--;
return aRet;
diff --git a/filter/source/pdf/impdialog.hxx b/filter/source/pdf/impdialog.hxx
index f227c14..b83343b 100644
--- a/filter/source/pdf/impdialog.hxx
+++ b/filter/source/pdf/impdialog.hxx
@@ -151,9 +151,9 @@ protected:
sal_Bool mbExportBmkToPDFDestination;
sal_Bool mbSignPDF;
- String msSignLocation;
- String msSignContact;
- String msSignReason;
+ ::rtl::OUString msSignLocation;
+ ::rtl::OUString msSignContact;
+ ::rtl::OUString msSignReason;
::rtl::OUString maWatermarkText;
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index db93010..a137cee 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -554,6 +554,14 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
rFilterData[ nData ].Value >>= mbExportHiddenSlides;
else if ( rFilterData[ nData ].Name == "OpenBookmarkLevels" )
rFilterData[ nData ].Value >>= mnOpenBookmarkLevels;
+ else if ( rFilterData[ nData ].Name == "SignPDF" )
+ rFilterData[ nData ].Value >>= mbSignPDF;
+ else if ( rFilterData[ nData ].Name == "SignatureLocation" )
+ rFilterData[ nData ].Value >>= msSignLocation;
+ else if ( rFilterData[ nData ].Name == "SignatureReason" )
+ rFilterData[ nData ].Value >>= msSignReason;
+ else if ( rFilterData[ nData ].Name == "SignatureContactInfo" )
+ rFilterData[ nData ].Value >>= msSignContact;
}
aContext.URL = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
@@ -781,6 +789,12 @@ sal_Bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue
aContext.ForcePDFAction = sal_False;
}
}
+
+ aContext.SignPDF = mbSignPDF;
+ aContext.SignLocation = msSignLocation;
+ aContext.SignContact = msSignContact;
+ aContext.SignReason = msSignReason;
+
// all context data set, time to create the printing device
PDFWriter* pPDFWriter = new PDFWriter( aContext, xEnc );
OutputDevice* pOut = pPDFWriter->GetReferenceDevice();
diff --git a/filter/source/pdf/pdfexport.hxx b/filter/source/pdf/pdfexport.hxx
index 3374d0a..baa996e 100644
--- a/filter/source/pdf/pdfexport.hxx
+++ b/filter/source/pdf/pdfexport.hxx
@@ -117,6 +117,12 @@ private:
sal_Bool mbExportBmkToDest;
sal_Bool ImplExportPage( ::vcl::PDFWriter& rWriter, ::vcl::PDFExtOutDevData& rPDFExtOutDevData,
const GDIMetaFile& rMtf );
+
+ sal_Bool mbSignPDF;
+ OUString msSignLocation;
+ OUString msSignContact;
+ OUString msSignReason;
+
void ImplWriteWatermark( ::vcl::PDFWriter& rWriter, const Size& rPageSize );
public:
diff --git a/vcl/inc/vcl/pdfwriter.hxx b/vcl/inc/vcl/pdfwriter.hxx
index 8ffab09..535c2b3 100644
--- a/vcl/inc/vcl/pdfwriter.hxx
+++ b/vcl/inc/vcl/pdfwriter.hxx
@@ -629,6 +629,11 @@ The following structure describes the permissions used in PDF security
PDFWriter::PDFEncryptionProperties Encryption;
PDFWriter::PDFDocInfo DocumentInfo;
+ bool SignPDF;
+ rtl::OUString SignLocation;
+ rtl::OUString SignReason;
+ rtl::OUString SignContact;
+
com::sun::star::lang::Locale DocumentLocale; // defines the document default language
sal_uInt32 DPIx, DPIy; // how to handle MapMode( MAP_PIXEL )
// 0 here specifies a default handling
@@ -660,6 +665,7 @@ The following structure describes the permissions used in PDF security
InitialPage( 1 ),
OpenBookmarkLevels( -1 ),
Encryption(),
+ SignPDF( false ),
DPIx( 0 ),
DPIy( 0 ),
ColorMode( PDFWriter::DrawColor )
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index f12f973..6438271 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -138,6 +138,11 @@ void doTestCode()
aContext.DocumentInfo.Title = OUString( "PDF export test document" );
aContext.DocumentInfo.Producer = OUString( "VCL" );
+ aContext.SignPDF = true;
+ aContext.SignLocation = OUString( "Burdur" );
+ aContext.SignReason = OUString( "Some valid reason to sign" );
+ aContext.SignContact = OUString( "signer at example.com" );
+
com::sun::star::uno::Reference< com::sun::star::beans::XMaterialHolder > xEnc;
PDFWriter aWriter( aContext, xEnc );
aWriter.NewPage( 595, 842 );
@@ -524,11 +529,6 @@ void doTestCode()
aWriter.EndStructureElement(); // close document
- // sign the document
- PDFWriter::SignatureWidget aSignature;
- aSignature.Name = OUString("Signature1");
- aWriter.CreateControl( aSignature, 0);
-
aWriter.Emit();
}
#endif
@@ -6099,13 +6099,13 @@ bool PDFWriterImpl::emitSignature()
OStringBuffer aContentFiller( MAX_SIGNATURE_CONTENT_LENGTH );
comphelper::string::padToLength(aContentFiller, MAX_SIGNATURE_CONTENT_LENGTH, '0');
aLine.append( aContentFiller.makeStringAndClear() );
- aLine.append( ">\n/Type/Sig/SubFilter/adbe.pkcs7.sha1/Location()"
- "/Name ");
+ aLine.append( ">\n/Type/Sig/SubFilter/adbe.pkcs7.sha1");
if( m_aContext.DocumentInfo.Author.Len() )
+ {
+ aLine.append( "/Name" );
appendUnicodeTextStringEncrypt( m_aContext.DocumentInfo.Author, m_nSignatureObject, aLine );
- else
- aLine.append("()");
+ }
aLine.append( " /M ");
appendLiteralStringEncrypt( m_aCreationDateString, m_nSignatureObject, aLine );
@@ -6124,8 +6124,28 @@ bool PDFWriterImpl::emitSignature()
OStringBuffer aByteRangeFiller( 100 );
comphelper::string::padToLength(aByteRangeFiller, 100, ' ');
aLine.append( aByteRangeFiller.makeStringAndClear() );
- aLine.append(" /Filter/Adobe.PPKMS/Reason()>>"
- "\nendobj\n\n" );
+ aLine.append(" /Filter/Adobe.PPKMS");
+
+ //emit reason, location and contactinfo
+ if ( !m_aContext.SignReason.isEmpty() )
+ {
+ aLine.append("/Reason");
+ appendUnicodeTextStringEncrypt( m_aContext.SignReason, m_nSignatureObject, aLine );
+ }
+
+ if ( !m_aContext.SignLocation.isEmpty() )
+ {
+ aLine.append("/Location");
+ appendUnicodeTextStringEncrypt( m_aContext.SignLocation, m_nSignatureObject, aLine );
+ }
+
+ if ( !m_aContext.SignContact.isEmpty() )
+ {
+ aLine.append("/ContactInfo");
+ appendUnicodeTextStringEncrypt( m_aContext.SignContact, m_nSignatureObject, aLine );
+ }
+
+ aLine.append(" >>\nendobj\n\n" );
if (!writeBuffer( aLine.getStr(), aLine.getLength() ))
return false;
@@ -6946,6 +6966,14 @@ bool PDFWriterImpl::emit()
// needed for widget tab order
sortWidgets();
+ if( m_aContext.SignPDF )
+ {
+ // sign the document
+ PDFWriter::SignatureWidget aSignature;
+ aSignature.Name = OUString("Signature1");
+ createControl( aSignature, 0 );
+ }
+
// emit additional streams
CHECK_RETURN( emitAdditionalStreams() );
More information about the Libreoffice-commits
mailing list