diff options
author | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2017-08-08 16:23:07 +0200 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2017-11-03 13:57:00 +0100 |
commit | bd3c5c4c234e3dc6b89cd235321945a41a08d562 (patch) | |
tree | 8592e2a2088f7c46877aa746695a257bc3877fae /oox/source | |
parent | c4abbb6e10ecd382fd4fe6816cd4f29ea7d931a5 (diff) |
[API CHANGE] tdf#65393 Import signature line images from ooxml
showing whether the signature behind the signature line is valid or not.
Change-Id: Ia6cca62812019f26d55d234cac767a9b4b7c8175
Reviewed-on: https://gerrit.libreoffice.org/40980
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 74 | ||||
-rw-r--r-- | oox/source/vml/vmlshapecontext.cxx | 7 |
2 files changed, 72 insertions, 9 deletions
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index 74ae15f848f3..7679ca838f67 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -44,9 +44,11 @@ #include <com/sun/star/text/XTextContent.hpp> #include <com/sun/star/text/XTextDocument.hpp> #include <com/sun/star/text/XTextFrame.hpp> - #include <com/sun/star/lang/XServiceInfo.hpp> +#include <com/sun/star/lang/XServiceInfo.hpp> #include <com/sun/star/text/TextContentAnchorType.hpp> #include <com/sun/star/text/GraphicCrop.hpp> +#include <com/sun/star/security/DocumentDigitalSignatures.hpp> +#include <com/sun/star/security/XDocumentDigitalSignatures.hpp> #include <rtl/math.hxx> #include <rtl/ustrbuf.hxx> #include <svx/svdtrans.hxx> @@ -67,7 +69,9 @@ #include <svx/unoapi.hxx> #include <svx/svdoashp.hxx> #include <comphelper/sequence.hxx> +#include <comphelper/processfactory.hxx> #include <comphelper/propertyvalue.hxx> +#include <comphelper/storagehelper.hxx> using ::com::sun::star::beans::XPropertySet; using ::com::sun::star::uno::Any; @@ -249,7 +253,8 @@ ClientData::ClientData() : { } -ShapeModel::ShapeModel() +ShapeModel::ShapeModel() : + mbIsSignatureLine(false) { } @@ -852,17 +857,23 @@ Reference< XShape > SimpleShape::implConvertAndInsert( const Reference< XShapes return xShape; } -Reference< XShape > SimpleShape::createPictureObject( const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const +Reference< XShape > SimpleShape::createEmbeddedPictureObject( const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect, OUString const & rGraphicPath ) const +{ + XmlFilterBase& rFilter = mrDrawing.getFilter(); + OUString aGraphicUrl = rFilter.getGraphicHelper().importEmbeddedGraphicObject( rGraphicPath ); + return SimpleShape::createPictureObject(rxShapes, rShapeRect, aGraphicUrl); +} + +Reference< XShape > SimpleShape::createPictureObject( const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect, OUString const & rGraphicUrl ) const { Reference< XShape > xShape = mrDrawing.createAndInsertXShape( "com.sun.star.drawing.GraphicObjectShape", rxShapes, rShapeRect ); if( xShape.is() ) { - XmlFilterBase& rFilter = mrDrawing.getFilter(); - OUString aGraphicUrl = rFilter.getGraphicHelper().importEmbeddedGraphicObject( rGraphicPath ); + PropertySet aPropSet( xShape ); - if( !aGraphicUrl.isEmpty() ) + if( !rGraphicUrl.isEmpty() ) { - aPropSet.setProperty( PROP_GraphicURL, aGraphicUrl ); + aPropSet.setProperty( PROP_GraphicURL, rGraphicUrl ); } uno::Reference< lang::XServiceInfo > xServiceInfo(rxShapes, uno::UNO_QUERY); // If the shape has an absolute position, set the properties accordingly, unless we're inside a group shape. @@ -912,7 +923,7 @@ Reference<XShape> RectangleShape::implConvertAndInsert(const Reference<XShapes>& // try to create a picture object if(!aGraphicPath.isEmpty()) - return SimpleShape::createPictureObject(rxShapes, rShapeRect, aGraphicPath); + return SimpleShape::createEmbeddedPictureObject(rxShapes, rShapeRect, aGraphicPath); // default: try to create a rectangle shape Reference<XShape> xShape = SimpleShape::implConvertAndInsert(rxShapes, rShapeRect); @@ -1231,15 +1242,60 @@ Reference< XShape > ComplexShape::implConvertAndInsert( const Reference< XShapes return xShape; } + + if( getShapeModel().mbIsSignatureLine ) + { + // Get the document signatures + Reference< security::XDocumentDigitalSignatures > xSignatures( + security::DocumentDigitalSignatures::createWithVersion( + comphelper::getProcessComponentContext(), "1.2" ) ); + + uno::Reference<embed::XStorage> xStorage = comphelper::OStorageHelper::GetStorageOfFormatFromURL( + ZIP_STORAGE_FORMAT_STRING, mrDrawing.getFilter().getFileUrl(), embed::ElementModes::READ); + SAL_WARN_IF(!xStorage.is(), "oox.vml", "No xStorage!"); + + uno::Sequence< security::DocumentSignatureInformation > xSignatureInfo = + xSignatures->verifyScriptingContentSignatures(xStorage, uno::Reference< io::XInputStream >()); + + for (int i=0; i<xSignatureInfo.getLength(); i++) + { + // Try to find matching signature line image - if none exists that is fine, + // then the signature line is not digitally signed. + if (xSignatureInfo[i].SignatureLineId == getShapeModel().maSignatureId) + { + OUString aGraphicUrl; + if (xSignatureInfo[i].SignatureIsValid) + { + // Signature is valid, use the 'valid' image + SAL_WARN_IF(!xSignatureInfo[i].ValidSignatureLineImage.is(), "oox.vml", "No ValidSignatureLineImage!"); + aGraphicUrl = rFilter.getGraphicHelper().createGraphicObject(xSignatureInfo[i].ValidSignatureLineImage); + } + else + { + // Signature is invalid, use the 'invalid' image + SAL_WARN_IF(!xSignatureInfo[i].InvalidSignatureLineImage.is(), "oox.vml", "No InvalidSignatureLineImage!"); + aGraphicUrl = rFilter.getGraphicHelper().createGraphicObject(xSignatureInfo[i].InvalidSignatureLineImage); + } + Reference< XShape > xShape = SimpleShape::createPictureObject(rxShapes, rShapeRect, aGraphicUrl); + PropertySet aPropSet(xShape); + aPropSet.setProperty(PROP_GraphicURL, aGraphicUrl); + + return xShape; + } + } + // In case no matching signature line is found, render the unsigned signature line image (next if branch) + } + // try to create a picture object if( !aGraphicPath.isEmpty() ) { - Reference< XShape > xShape = SimpleShape::createPictureObject(rxShapes, rShapeRect, aGraphicPath); + Reference< XShape > xShape = SimpleShape::createEmbeddedPictureObject(rxShapes, rShapeRect, aGraphicPath); // AS_CHARACTER shape: vertical orientation default is bottom, MSO default is top. if ( maTypeModel.maPosition != "absolute" && maTypeModel.maPosition != "relative" ) PropertySet( xShape ).setAnyProperty( PROP_VertOrient, makeAny(text::VertOrientation::TOP)); return xShape; } + // default: try to create a custom shape return CustomShape::implConvertAndInsert( rxShapes, rShapeRect ); } diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx index 1d1851d87ef1..151f28585a70 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -491,6 +491,13 @@ ContextHandlerRef ShapeContext::onCreateContext( sal_Int32 nElement, const Attri "com.sun.star.drawing.RectangleShape"); mrShapeModel.maLegacyDiagramPath = getFragmentPathFromRelId(rAttribs.getString(XML_id, OUString())); break; + case O_TOKEN( signatureline ): + mrShapeModel.mbIsSignatureLine = true; + mrShapeModel.maSignatureId = rAttribs.getString(XML_id, OUString()); + break; + case O_TOKEN( lock ): + // TODO + break; } // handle remaining stuff in base class return ShapeTypeContext::onCreateContext( nElement, rAttribs ); |