filter: handle ooxml shapes in EscherPropertyContainer::GetCustomShapeType()

The problem was that the shapes produced by the drawingML import had
types like ooxml-triangle, and EnhancedCustomShapeTypeNames::Get() only
handles VML/binary MSO shapes (e.g. isosceles-triangle). Add an OOXML
mode, and in that case use msfilter::util::GETVMLShapeType() instead,
and only fall back to EnhancedCustomShapeTypeNames::Get() if necessary.

Change-Id: Ic93ba4719133dd3e96c17d2562642a03e559fefa
This commit is contained in:
Miklos Vajna
2013-12-03 10:50:44 +01:00
parent f5e2d31331
commit a44e42b9cd
7 changed files with 46 additions and 13 deletions

View File

@@ -22,6 +22,7 @@
#include <svx/svdomedia.hxx> #include <svx/svdomedia.hxx>
#include <svx/xflftrit.hxx> #include <svx/xflftrit.hxx>
#include <filter/msfilter/escherex.hxx> #include <filter/msfilter/escherex.hxx>
#include <filter/msfilter/util.hxx>
#include <svx/unoapi.hxx> #include <svx/unoapi.hxx>
#include <svx/svdobj.hxx> #include <svx/svdobj.hxx>
#include <svx/svdoashp.hxx> #include <svx/svdoashp.hxx>
@@ -3761,7 +3762,7 @@ void EscherPropertyContainer::CreateCustomShapeProperties( const MSO_SPT eShapeT
} }
} }
MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawing::XShape > & rXShape, sal_uInt32& nMirrorFlags, OUString& rShapeType ) MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawing::XShape > & rXShape, sal_uInt32& nMirrorFlags, OUString& rShapeType, bool bOOXML )
{ {
MSO_SPT eShapeType = mso_sptNil; MSO_SPT eShapeType = mso_sptNil;
nMirrorFlags = 0; nMirrorFlags = 0;
@@ -3782,8 +3783,21 @@ MSO_SPT EscherPropertyContainer::GetCustomShapeType( const uno::Reference< drawi
if ( rProp.Name == "Type" ) if ( rProp.Name == "Type" )
{ {
if ( rProp.Value >>= rShapeType ) if ( rProp.Value >>= rShapeType )
{
if (bOOXML)
{
// In case of VML export, try to handle the
// ooxml- prefix in rShapeType. If that fails,
// just do the same as the binary export.
OString aType = OUStringToOString(rShapeType, RTL_TEXTENCODING_UTF8);
eShapeType = msfilter::util::GETVMLShapeType(aType);
if (eShapeType == mso_sptNil)
eShapeType = EnhancedCustomShapeTypeNames::Get(rShapeType); eShapeType = EnhancedCustomShapeTypeNames::Get(rShapeType);
} }
else
eShapeType = EnhancedCustomShapeTypeNames::Get( rShapeType );
}
}
else if ( rProp.Name == "MirroredX" ) else if ( rProp.Name == "MirroredX" )
{ {
sal_Bool bMirroredX = sal_Bool(); sal_Bool bMirroredX = sal_Bool();
@@ -4933,7 +4947,7 @@ public:
virtual ~SvNullStream() {} virtual ~SvNullStream() {}
}; };
EscherEx::EscherEx( const EscherExGlobalRef& rxGlobal, SvStream* pOutStrm ) : EscherEx::EscherEx( const EscherExGlobalRef& rxGlobal, SvStream* pOutStrm, bool bOOXML ) :
mxGlobal ( rxGlobal ), mxGlobal ( rxGlobal ),
mpOutStrm ( pOutStrm ), mpOutStrm ( pOutStrm ),
mbOwnsStrm ( false ), mbOwnsStrm ( false ),
@@ -4944,7 +4958,8 @@ EscherEx::EscherEx( const EscherExGlobalRef& rxGlobal, SvStream* pOutStrm ) :
mnHellLayerId ( USHRT_MAX ), mnHellLayerId ( USHRT_MAX ),
mbEscherSpgr ( sal_False ), mbEscherSpgr ( sal_False ),
mbEscherDg ( sal_False ) mbEscherDg ( sal_False ),
mbOOXML(bOOXML)
{ {
if (!mpOutStrm) if (!mpOutStrm)
{ {

View File

@@ -254,7 +254,7 @@ sal_uInt32 ImplEESdrWriter::ImplWriteShape( ImplEESdrObject& rObj,
sal_uInt32 nMirrorFlags; sal_uInt32 nMirrorFlags;
OUString sCustomShapeType; OUString sCustomShapeType;
MSO_SPT eShapeType = aPropOpt.GetCustomShapeType( rObj.GetShapeRef(), nMirrorFlags, sCustomShapeType ); MSO_SPT eShapeType = aPropOpt.GetCustomShapeType( rObj.GetShapeRef(), nMirrorFlags, sCustomShapeType, rObj.GetOOXML() );
if ( sCustomShapeType == "col-502ad400" || sCustomShapeType == "col-60da8460" ) if ( sCustomShapeType == "col-502ad400" || sCustomShapeType == "col-60da8460" )
{ {
ADD_SHAPE( ESCHER_ShpInst_PictureFrame, 0xa00 ); ADD_SHAPE( ESCHER_ShpInst_PictureFrame, 0xa00 );
@@ -953,7 +953,7 @@ void EscherEx::AddUnoShapes( const Reference< XShapes >& rxShapes )
sal_uInt32 EscherEx::AddSdrObject( const SdrObject& rObj ) sal_uInt32 EscherEx::AddSdrObject( const SdrObject& rObj )
{ {
ImplEESdrObject aObj( *mpImplEscherExSdr, rObj ); ImplEESdrObject aObj( *mpImplEscherExSdr, rObj, mbOOXML );
if( aObj.IsValid() ) if( aObj.IsValid() )
return mpImplEscherExSdr->ImplWriteTheShape( aObj ); return mpImplEscherExSdr->ImplWriteTheShape( aObj );
return 0; return 0;
@@ -1006,13 +1006,14 @@ const SdrObject* EscherEx::GetSdrObject( const Reference< XShape >& rShape )
ImplEESdrObject::ImplEESdrObject( ImplEscherExSdr& rEx, ImplEESdrObject::ImplEESdrObject( ImplEscherExSdr& rEx,
const SdrObject& rObj ) : const SdrObject& rObj, bool bOOXML ) :
mnShapeId( 0 ), mnShapeId( 0 ),
mnTextSize( 0 ), mnTextSize( 0 ),
mnAngle( 0 ), mnAngle( 0 ),
mbValid( sal_False ), mbValid( sal_False ),
mbPresObj( sal_False ), mbPresObj( sal_False ),
mbEmptyPresObj( sal_False ) mbEmptyPresObj( sal_False ),
mbOOXML(bOOXML)
{ {
SdrPage* pPage = rObj.GetPage(); SdrPage* pPage = rObj.GetPage();
DBG_ASSERT( pPage, "ImplEESdrObject::ImplEESdrObject: no SdrPage" ); DBG_ASSERT( pPage, "ImplEESdrObject::ImplEESdrObject: no SdrPage" );
@@ -1033,7 +1034,8 @@ ImplEESdrObject::ImplEESdrObject( ImplEESdrWriter& rEx,
mnAngle( 0 ), mnAngle( 0 ),
mbValid( sal_False ), mbValid( sal_False ),
mbPresObj( sal_False ), mbPresObj( sal_False ),
mbEmptyPresObj( sal_False ) mbEmptyPresObj( sal_False ),
mbOOXML(false)
{ {
Init( rEx ); Init( rEx );
} }
@@ -1255,4 +1257,9 @@ sal_Bool ImplEESdrObject::ImplHasText() const
return xXText.is() && !xXText->getString().isEmpty(); return xXText.is() && !xXText->getString().isEmpty();
} }
bool ImplEESdrObject::GetOOXML() const
{
return mbOOXML;
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

View File

@@ -43,12 +43,13 @@ class ImplEESdrObject
sal_Bool mbValid : 1; sal_Bool mbValid : 1;
sal_Bool mbPresObj : 1; sal_Bool mbPresObj : 1;
sal_Bool mbEmptyPresObj : 1; sal_Bool mbEmptyPresObj : 1;
bool mbOOXML;
void Init( ImplEESdrWriter& rEx ); void Init( ImplEESdrWriter& rEx );
public: public:
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > mXPropSet; ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > mXPropSet;
ImplEESdrObject( ImplEscherExSdr& rEx, const SdrObject& rObj ); ImplEESdrObject( ImplEscherExSdr& rEx, const SdrObject& rObj, bool bOOXML = false );
ImplEESdrObject( ImplEESdrWriter& rEx, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rShape ); ImplEESdrObject( ImplEESdrWriter& rEx, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape >& rShape );
~ImplEESdrObject(); ~ImplEESdrObject();
@@ -85,6 +86,7 @@ public:
sal_uInt32 ImplGetText(); sal_uInt32 ImplGetText();
sal_Bool ImplHasText() const; sal_Bool ImplHasText() const;
bool GetOOXML() const;
}; };

View File

@@ -1337,7 +1337,8 @@ public:
static MSO_SPT GetCustomShapeType( static MSO_SPT GetCustomShapeType(
const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape, const ::com::sun::star::uno::Reference< ::com::sun::star::drawing::XShape > & rXShape,
sal_uInt32& nMirrorFlags, sal_uInt32& nMirrorFlags,
OUString& rShapeType OUString& rShapeType,
bool bOOXML = false
); );
// helper functions which are also used in ooxml export // helper functions which are also used in ooxml export
@@ -1584,12 +1585,13 @@ class MSFILTER_DLLPUBLIC EscherEx : public EscherPersistTable
sal_Bool mbEscherSpgr; sal_Bool mbEscherSpgr;
sal_Bool mbEscherDg; sal_Bool mbEscherDg;
sal_Bool mbOleEmf; // OLE is EMF instead of WMF sal_Bool mbOleEmf; // OLE is EMF instead of WMF
bool mbOOXML;
virtual sal_Bool DoSeek( sal_uInt32 nKey ); virtual sal_Bool DoSeek( sal_uInt32 nKey );
public: public:
explicit EscherEx( const EscherExGlobalRef& rxGlobal, SvStream* pOutStrm ); explicit EscherEx( const EscherExGlobalRef& rxGlobal, SvStream* pOutStrm, bool bOOXML = false );
virtual ~EscherEx(); virtual ~EscherEx();
/** Creates and returns a new shape identifier, updates the internal shape /** Creates and returns a new shape identifier, updates the internal shape

View File

@@ -42,7 +42,7 @@ using namespace oox::vml;
using namespace com::sun::star; using namespace com::sun::star;
VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr pSerializer, VMLTextExport* pTextExport ) VMLExport::VMLExport( ::sax_fastparser::FSHelperPtr pSerializer, VMLTextExport* pTextExport )
: EscherEx( EscherExGlobalRef(new EscherExGlobal(0)), 0 ) : EscherEx( EscherExGlobalRef(new EscherExGlobal(0)), 0, /*bOOXML=*/true )
, m_pSerializer( pSerializer ) , m_pSerializer( pSerializer )
, m_pTextExport( pTextExport ) , m_pTextExport( pTextExport )
, m_eHOri( 0 ) , m_eHOri( 0 )

Binary file not shown.

View File

@@ -2034,6 +2034,13 @@ DECLARE_OOXMLEXPORT_TEST(testTableLineSpacing, "table_atleast.docx")
assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p/w:pPr/w:spacing", "line", "320"); assertXPath(pXmlDoc, "/w:document/w:body/w:tbl/w:tr/w:tc/w:p/w:pPr/w:spacing", "line", "320");
} }
DECLARE_OOXMLEXPORT_TEST(testOoxmlTriangle, "ooxml-triangle.docx")
{
// The problem was that ooxml-triangle shape type wasn't handled by VML
// export (only isosceles-triangle), leading to a missing shape.
getShape(1);
}
#endif #endif
CPPUNIT_PLUGIN_IMPLEMENT(); CPPUNIT_PLUGIN_IMPLEMENT();