From 727938b395693be2bf0956fff687193cff95f028 Mon Sep 17 00:00:00 2001 From: Jacobo Aragunde Pérez Date: Tue, 20 May 2014 20:11:13 +0200 Subject: oox, writerfilter: Support for artistic effects on pictures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Bitmaps can define artistic effects like in the following example: They are defined in the MS-ODRAWXML extension. Ref: http://msdn.microsoft.com/en-us/library/dd905216(v=office.12).aspx LO core doesn't support them, but I'm preserving them using the shape grab bag. Bitmaps must not be transformed to a SwXTextGraphicObject so the grab bag of the XShape is not discarded. Added several Context and Properties objects on the import side to traverse and save the relevant tags, and added the corresponding code on the export side to extract the grab bag and output the effect back. When Word applies an artistic effect, it creates two embedded files; one contains the bitmap with the effect and the other one contains the original bitmap to be able to undo the effect. We also read the original bitmap, store it in the shape grab bag and save it back to the docx file. When two pictures apply different effects to the same picture, it is only saved once in the original document. Added a cache to DrawingML to know if the picture has already been exported. Finally, added unit tests for a selection of artistic effects. [Squashing commits from master: 21d4cfe19e2796ebf89c408e292c4473924b2bc4 642a252cf1a2f1d08c4bbfcae15527bb82c7664d 2e68a1468c035fc3bb4d02ad0b3187872fe1e67b b5f6a5cfc517ecd8aa6ba96471d854b07b92ebaa 38d7b82c277599f2e613256c4353aa7dfdc219ec] Change-Id: I39327a8118e23829c029122154a31ce3af5b48cd Reviewed-on: https://gerrit.libreoffice.org/9495 Reviewed-by: Miklos Vajna Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- include/oox/drawingml/fillproperties.hxx | 26 ++++++++++++++ .../oox/drawingml/fillpropertiesgroupcontext.hxx | 42 ++++++++++++++++++++++ include/oox/export/drawingml.hxx | 4 +++ include/oox/ole/oleobjecthelper.hxx | 3 +- 4 files changed, 74 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/oox/drawingml/fillproperties.hxx b/include/oox/drawingml/fillproperties.hxx index 447cba2fa76c..dcf3afbfd230 100644 --- a/include/oox/drawingml/fillproperties.hxx +++ b/include/oox/drawingml/fillproperties.hxx @@ -26,6 +26,7 @@ #include #include #include +#include namespace oox { class GraphicHelper; @@ -65,6 +66,29 @@ struct PatternFillProperties void assignUsed( const PatternFillProperties& rSourceProps ); }; +struct ArtisticEffectProperties +{ + OUString msName; + std::map< OUString, css::uno::Any > + maAttribs; + ::oox::ole::OleObjectInfo mrOleObjectInfo; /// The original graphic as embedded object. + + bool isEmpty() const; + + /** Returns the struct as a PropertyValue with Name = msName and + * Value = maAttribs as a Sequence< PropertyValue >. */ + css::beans::PropertyValue getEffect(); + + /** Overwrites all members that are explicitly set in rSourceProps. */ + void assignUsed( const ArtisticEffectProperties& rSourceProps ); + + /** Translate effect tokens to strings. */ + static OUString getEffectString( sal_Int32 nToken ); + + /** Translate effect strings to tokens. */ + static sal_Int32 getEffectToken( OUString sName ); +}; + struct BlipFillProperties { ::com::sun::star::uno::Reference< ::com::sun::star::graphic::XGraphic > @@ -89,6 +113,8 @@ struct BlipFillProperties Color maColorChangeTo; /// Destination color of color transformation. Color maDuotoneColors[2]; /// Duotone Colors + ArtisticEffectProperties maEffect; /// Artistic effect, not supported by core. + /** Overwrites all members that are explicitly set in rSourceProps. */ void assignUsed( const BlipFillProperties& rSourceProps ); }; diff --git a/include/oox/drawingml/fillpropertiesgroupcontext.hxx b/include/oox/drawingml/fillpropertiesgroupcontext.hxx index bbeed0837903..aae88df408be 100644 --- a/include/oox/drawingml/fillpropertiesgroupcontext.hxx +++ b/include/oox/drawingml/fillpropertiesgroupcontext.hxx @@ -78,6 +78,48 @@ private: +/** Context handler that imports a14:imgProps, a14:imgLayer, a14:imgEffect containers + and the a14:artistic* effect tags defined in the MS-ODRAWXML extension. */ +class ArtisticEffectContext : public ::oox::core::ContextHandler2 +{ +public: + explicit ArtisticEffectContext( + ::oox::core::ContextHandler2Helper& rParent, + ArtisticEffectProperties& rEffect ); + virtual ~ArtisticEffectContext(); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( + sal_Int32 nElement, + const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE; + +private: + ArtisticEffectProperties& maEffect; +}; + + + +/** Context handler that imports the a:extLst element inside a:blip and its + children a:ext, which can contain transformations to the bitmap. */ +class BlipExtensionContext : public ::oox::core::ContextHandler2 +{ +public: + explicit BlipExtensionContext( + ::oox::core::ContextHandler2Helper& rParent, + BlipFillProperties& rBlipProps ); + virtual ~BlipExtensionContext(); + + virtual ::oox::core::ContextHandlerRef + onCreateContext( + sal_Int32 nElement, + const ::oox::AttributeList& rAttribs ) SAL_OVERRIDE; + +private: + BlipFillProperties& mrBlipProps; +}; + + + /** Context handler that imports the a:duotone element containing the colors of a bitmap duotone transformation. */ class DuotoneContext : public ::oox::core::ContextHandler2 diff --git a/include/oox/export/drawingml.hxx b/include/oox/export/drawingml.hxx index 86e3d0769449..e97f05da8cf5 100644 --- a/include/oox/export/drawingml.hxx +++ b/include/oox/export/drawingml.hxx @@ -82,6 +82,8 @@ public: private: static int mnImageCounter; + static int mnWdpImageCounter; + static std::map maWdpCache; /// To specify where write eg. the images to (like 'ppt', or 'word' - according to the OPC). DocumentType meDocumentType; @@ -176,6 +178,8 @@ public: void WriteShapeEffects( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); void WriteShapeEffect( const OUString& sName, const css::uno::Sequence< css::beans::PropertyValue >& aEffectProps ); void WriteShape3DEffects( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); + void WriteArtisticEffect( ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > rXPropSet ); + OString WriteWdpPicture( const OUString& rFileId, const ::com::sun::star::uno::Sequence< sal_Int8 >& rPictureData ); static void ResetCounters(); diff --git a/include/oox/ole/oleobjecthelper.hxx b/include/oox/ole/oleobjecthelper.hxx index a723949f539c..ef32483d74ab 100644 --- a/include/oox/ole/oleobjecthelper.hxx +++ b/include/oox/ole/oleobjecthelper.hxx @@ -20,6 +20,7 @@ #ifndef INCLUDED_OOX_OLE_OLEOBJECTHELPER_HXX #define INCLUDED_OOX_OLE_OLEOBJECTHELPER_HXX +#include #include namespace com { namespace sun { namespace star { @@ -36,7 +37,7 @@ namespace ole { /** Contains generic information about an OLE object. */ -struct OleObjectInfo +struct OOX_DLLPUBLIC OleObjectInfo { StreamDataSequence maEmbeddedData; ///< Data of an embedded OLE object. OUString maTargetLink; ///< Path to external data for linked OLE object. -- cgit