diff options
author | Daniel Rentz <dr@openoffice.org> | 2010-06-21 15:39:04 +0200 |
---|---|---|
committer | Daniel Rentz <dr@openoffice.org> | 2010-06-21 15:39:04 +0200 |
commit | d90bbc5dd13e751ec630871eab55ac333841c241 (patch) | |
tree | e475de770106d05ebf7b47c9b7e711a375d8d9a3 /oox | |
parent | 74721a30a80c06fac3d51dbe9da54344b60542ab (diff) | |
parent | 33750471297793a14d19f783208f7d8019903570 (diff) |
mib16: rebase to m83
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/oox/drawingml/customshapegeometry.hxx | 4 | ||||
-rw-r--r-- | oox/inc/oox/drawingml/customshapeproperties.hxx | 81 | ||||
-rw-r--r-- | oox/inc/oox/drawingml/shape.hxx | 4 | ||||
-rw-r--r-- | oox/source/drawingml/chart/axisconverter.cxx | 3 | ||||
-rw-r--r-- | oox/source/drawingml/customshapegeometry.cxx | 1120 | ||||
-rw-r--r-- | oox/source/drawingml/customshapeproperties.cxx | 201 | ||||
-rw-r--r-- | oox/source/drawingml/shape.cxx | 39 | ||||
-rw-r--r-- | oox/source/drawingml/shapecontext.cxx | 5 | ||||
-rw-r--r-- | oox/source/drawingml/shapepropertiescontext.cxx | 2 | ||||
-rw-r--r-- | oox/source/token/properties.txt | 17 | ||||
-rw-r--r-- | oox/source/token/tokens.txt | 26 |
11 files changed, 1321 insertions, 181 deletions
diff --git a/oox/inc/oox/drawingml/customshapegeometry.hxx b/oox/inc/oox/drawingml/customshapegeometry.hxx index 75a788acb609..4fec38cf09eb 100644 --- a/oox/inc/oox/drawingml/customshapegeometry.hxx +++ b/oox/inc/oox/drawingml/customshapegeometry.hxx @@ -41,11 +41,11 @@ namespace oox { namespace drawingml { class CustomShapeGeometryContext : public ::oox::core::ContextHandler { public: - CustomShapeGeometryContext( ::oox::core::ContextHandler& rParent, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes, Shape& rShape ); + CustomShapeGeometryContext( ::oox::core::ContextHandler& rParent, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttributes, CustomShapeProperties& rCustomShapeProperties ); virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); private: - Shape& mrShape; + CustomShapeProperties& mrCustomShapeProperties; }; // --------------------------------------------------------------------- diff --git a/oox/inc/oox/drawingml/customshapeproperties.hxx b/oox/inc/oox/drawingml/customshapeproperties.hxx index ff1f26533036..171437095f03 100644 --- a/oox/inc/oox/drawingml/customshapeproperties.hxx +++ b/oox/inc/oox/drawingml/customshapeproperties.hxx @@ -30,9 +30,10 @@ #include "oox/helper/propertymap.hxx" #include "oox/drawingml/color.hxx" +#include "oox/core/xmlfilterbase.hxx" #include <com/sun/star/graphic/XGraphic.hpp> #include <boost/shared_ptr.hpp> -#include <basegfx/polygon/b2dpolypolygon.hxx> +#include "oox/helper/helper.hxx" #include "tokens.hxx" #include <vector> #include <map> @@ -44,7 +45,9 @@ #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp> +#ifndef __com_sun_star_beans_PropertyValues_hpp__ #include <com/sun/star/beans/PropertyValues.hpp> +#endif #include <com/sun/star/drawing/ProjectionMode.hpp> #include <com/sun/star/drawing/XShape.hpp> @@ -60,6 +63,55 @@ struct CustomShapeGuide rtl::OUString maFormula; }; +struct AdjustHandle +{ + sal_Bool polar; + com::sun::star::drawing::EnhancedCustomShapeParameterPair + pos; + + // depending to the type (polar or not): + OptValue< rtl::OUString > gdRef1; // gdRefX or gdRefR + OptValue< com::sun::star::drawing::EnhancedCustomShapeParameter > + min1; // minX or minR + OptValue< com::sun::star::drawing::EnhancedCustomShapeParameter > + max1; // maxX or maxR + OptValue< rtl::OUString > gdRef2; // gdRefY or gdRefAng + OptValue< com::sun::star::drawing::EnhancedCustomShapeParameter > + min2; // minX or minAng + OptValue< com::sun::star::drawing::EnhancedCustomShapeParameter > + max2; // maxY or maxAng + + AdjustHandle( sal_Bool bPolar ) : polar( bPolar ) {}; +}; + +struct ConnectionSite +{ + com::sun::star::drawing::EnhancedCustomShapeParameterPair + pos; + com::sun::star::drawing::EnhancedCustomShapeParameter + ang; +}; + +struct GeomRect +{ + com::sun::star::drawing::EnhancedCustomShapeParameter l; + com::sun::star::drawing::EnhancedCustomShapeParameter t; + com::sun::star::drawing::EnhancedCustomShapeParameter r; + com::sun::star::drawing::EnhancedCustomShapeParameter b; +}; + +struct Path2D +{ + sal_Int64 w; + sal_Int64 h; + sal_Int32 fill; + sal_Bool stroke; + sal_Bool extrusionOk; + std::vector< com::sun::star::drawing::EnhancedCustomShapeParameterPair > parameter; + + Path2D() : w( 0 ), h( 0 ), fill( XML_norm ), stroke( sal_True ), extrusionOk( sal_True ) {}; +}; + class CustomShapeProperties { public: @@ -68,19 +120,36 @@ public: virtual ~CustomShapeProperties(); void apply( const CustomShapePropertiesPtr& ); - void pushToPropSet( const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > & xPropSet, + void pushToPropSet( const ::oox::core::FilterBase& rFilterBase, + const ::com::sun::star::uno::Reference < ::com::sun::star::beans::XPropertySet > & xPropSet, const ::com::sun::star::uno::Reference < ::com::sun::star::drawing::XShape > & xShape) const; void setShapePresetType( const rtl::OUString& rShapePresetType ){ maShapePresetType = rShapePresetType; }; - std::vector< CustomShapeGuide >& getAdjustmentValues(){ return maAdjustmentValues; }; + + std::vector< CustomShapeGuide >& getAdjustmentGuideList(){ return maAdjustmentGuideList; }; + std::vector< CustomShapeGuide >& getGuideList(){ return maGuideList; }; + std::vector< AdjustHandle >& getAdjustHandleList(){ return maAdjustHandleList; }; + std::vector< ConnectionSite >& getConnectionSiteList(){ return maConnectionSiteList; }; + OptValue< GeomRect >& getTextRect(){ return maTextRect; }; + std::vector< Path2D >& getPath2DList(){ return maPath2DList; }; + std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& getSegments(){ return maSegments; }; double getValue( const std::vector< CustomShapeGuide >&, sal_uInt32 nIndex ) const; - ::basegfx::B2DPolyPolygon& getPolygon() { return maPolygon; } + static sal_Int32 SetCustomShapeGuideValue( std::vector< CustomShapeGuide >& rGuideList, const CustomShapeGuide& rGuide ); + static sal_Int32 GetCustomShapeGuideValue( const std::vector< CustomShapeGuide >& rGuideList, const rtl::OUString& rFormulaName ); + private: rtl::OUString maShapePresetType; - std::vector< CustomShapeGuide > maAdjustmentValues; - ::basegfx::B2DPolyPolygon maPolygon; + std::vector< CustomShapeGuide > maAdjustmentGuideList; + std::vector< CustomShapeGuide > maGuideList; + std::vector< AdjustHandle > maAdjustHandleList; + std::vector< ConnectionSite > maConnectionSiteList; + OptValue< GeomRect > maTextRect; + std::vector< Path2D > maPath2DList; + + std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment > + maSegments; }; } } diff --git a/oox/inc/oox/drawingml/shape.hxx b/oox/inc/oox/drawingml/shape.hxx index c951369dbf78..f4228ab24790 100644 --- a/oox/inc/oox/drawingml/shape.hxx +++ b/oox/inc/oox/drawingml/shape.hxx @@ -30,7 +30,7 @@ #include "oox/helper/propertymap.hxx" #include "oox/drawingml/drawingmltypes.hxx" -//#include "oox/drawingml/customshapeproperties.hxx" +#include "oox/drawingml/customshapeproperties.hxx" #include "oox/drawingml/textliststyle.hxx" #include <com/sun/star/frame/XModel.hpp> @@ -126,6 +126,7 @@ public: void setName( const rtl::OUString& rName ) { msName = rName; } ::rtl::OUString getName( ) { return msName; } void setId( const rtl::OUString& rId ) { msId = rId; } + void setHidden( sal_Bool bHidden ) { mbHidden = bHidden; } void setSubType( sal_Int32 nSubType ) { mnSubType = nSubType; } sal_Int32 getSubType() const { return mnSubType; } void setSubTypeIndex( sal_uInt32 nSubTypeIndex ) { mnSubTypeIndex = nSubTypeIndex; } @@ -206,6 +207,7 @@ private: sal_Int32 mnRotation; sal_Bool mbFlipH; sal_Bool mbFlipV; + sal_Bool mbHidden; }; ::rtl::OUString GetShapeType( sal_Int32 nType ); diff --git a/oox/source/drawingml/chart/axisconverter.cxx b/oox/source/drawingml/chart/axisconverter.cxx index 77cf21698c62..da4fc3e5b83f 100644 --- a/oox/source/drawingml/chart/axisconverter.cxx +++ b/oox/source/drawingml/chart/axisconverter.cxx @@ -241,7 +241,8 @@ void AxisConverter::convertFromModel( const Reference< XCoordinateSystem >& rxCo Any& rIntervalCount = rSubIncrementSeq[ 0 ].IntervalCount; if( bLogScale ) { - rIntervalCount <<= sal_Int32( 10 ); + if( mrModel.mofMinorUnit.has() ) + rIntervalCount <<= sal_Int32( 9 ); } else { diff --git a/oox/source/drawingml/customshapegeometry.cxx b/oox/source/drawingml/customshapegeometry.cxx index 79c0c2e28d99..a0fcc3142f51 100644 --- a/oox/source/drawingml/customshapegeometry.cxx +++ b/oox/source/drawingml/customshapegeometry.cxx @@ -26,22 +26,22 @@ ************************************************************************/ #include "oox/drawingml/customshapegeometry.hxx" -#include "oox/drawingml/customshapeproperties.hxx" #include <com/sun/star/xml/sax/FastToken.hpp> #include <comphelper/stl_types.hxx> #include <hash_map> -#include <basegfx/polygon/b2dpolygon.hxx> - #include "oox/helper/helper.hxx" +#include "oox/helper/attributelist.hxx" +#include "oox/token/tokenmap.hxx" #include "oox/helper/propertymap.hxx" #include "oox/core/namespaces.hxx" #include "tokens.hxx" using ::rtl::OUString; -using namespace ::basegfx; using namespace ::oox::core; using namespace ::com::sun::star::uno; +using namespace ::com::sun::star::beans; +using namespace ::com::sun::star::drawing; using namespace ::com::sun::star::xml::sax; namespace oox { namespace drawingml { @@ -97,25 +97,374 @@ typedef std::hash_map< rtl::OUString, FormularCommand, comphelper::UStringHash, static const FormulaCommandHMap* pCommandHashMap; +// +rtl::OUString GetFormulaParameter( const EnhancedCustomShapeParameter& rParameter ) +{ + rtl::OUString aRet; + switch( rParameter.Type ) + { + case EnhancedCustomShapeParameterType::NORMAL : + { + if ( rParameter.Value.getValueTypeClass() == TypeClass_DOUBLE ) + { + double fValue = 0.0; + if ( rParameter.Value >>= fValue ) + aRet = rtl::OUString::valueOf( fValue ); + } + else + { + sal_Int32 nValue = 0; + if ( rParameter.Value >>= nValue ) + aRet = rtl::OUString::valueOf( nValue ); + } + } + break; + case EnhancedCustomShapeParameterType::EQUATION : + { + if ( rParameter.Value.getValueTypeClass() == TypeClass_LONG ) + { + sal_Int32 nFormulaIndex; + if ( rParameter.Value >>= nFormulaIndex ) + { + aRet = CREATE_OUSTRING( "?" ) + + rtl::OUString::valueOf( nFormulaIndex ) + + CREATE_OUSTRING( " " ); + } + } + else + { + // ups... we should have an index here and not the formula name + } + } + break; + case EnhancedCustomShapeParameterType::ADJUSTMENT : + { + if ( rParameter.Value.getValueTypeClass() == TypeClass_LONG ) + { + sal_Int32 nAdjustmentIndex; + if ( rParameter.Value >>= nAdjustmentIndex ) + { + aRet = CREATE_OUSTRING( "$" ) + + rtl::OUString::valueOf( nAdjustmentIndex ) + + CREATE_OUSTRING( " " ); + } + } + else + { + // ups... we should have an index here and not the formula name + } + } + break; + case EnhancedCustomShapeParameterType::LEFT : + { + const rtl::OUString sLeft( CREATE_OUSTRING( "left" ) ); + aRet = sLeft; + } + break; + case EnhancedCustomShapeParameterType::TOP : + { + const rtl::OUString sTop( CREATE_OUSTRING( "top" ) ); + aRet = sTop; + } + break; + case EnhancedCustomShapeParameterType::RIGHT : + { + const rtl::OUString sRight( CREATE_OUSTRING( "right" ) ); + aRet = sRight; + } + break; + case EnhancedCustomShapeParameterType::BOTTOM : + { + const rtl::OUString sBottom( CREATE_OUSTRING( "bottom" ) ); + aRet = sBottom; + } + break; + case EnhancedCustomShapeParameterType::XSTRETCH : + { + const rtl::OUString sXStretch( CREATE_OUSTRING( "xstretch" ) ); + aRet = sXStretch; + } + break; + case EnhancedCustomShapeParameterType::YSTRETCH : + { + const rtl::OUString sYStretch( CREATE_OUSTRING( "ystretch" ) ); + aRet = sYStretch; + } + break; + case EnhancedCustomShapeParameterType::HASSTROKE : + { + const rtl::OUString sHasStroke( CREATE_OUSTRING( "hasstroke" ) ); + aRet = sHasStroke; + } + break; + case EnhancedCustomShapeParameterType::HASFILL : + { + const rtl::OUString sHasFill( CREATE_OUSTRING( "hasfill" ) ); + aRet = sHasFill; + } + break; + case EnhancedCustomShapeParameterType::WIDTH : + { + const rtl::OUString sWidth( CREATE_OUSTRING( "width" ) ); + aRet = sWidth; + } + break; + case EnhancedCustomShapeParameterType::HEIGHT : + { + const rtl::OUString sHeight( CREATE_OUSTRING( "height" ) ); + aRet = sHeight; + } + break; + case EnhancedCustomShapeParameterType::LOGWIDTH : + { + const rtl::OUString sLogWidth( CREATE_OUSTRING( "logwidth" ) ); + aRet = sLogWidth; + } + break; + case EnhancedCustomShapeParameterType::LOGHEIGHT : + { + const rtl::OUString sLogHeight( CREATE_OUSTRING( "logheight" ) ); + aRet = sLogHeight; + } + break; + } + return aRet; +} + +// --------------------------------------------------------------------- + +static EnhancedCustomShapeParameter GetAdjCoordinate( CustomShapeProperties& rCustomShapeProperties, const::rtl::OUString& rValue, sal_Bool bNoSymbols ) +{ + com::sun::star::drawing::EnhancedCustomShapeParameter aRet; + if ( rValue.getLength() ) + { + sal_Bool bConstant = sal_True; + sal_Int32 nConstant = 0; + sal_Char nVal = 0; + + // first check if its a constant value + switch( StaticTokenMap::get().getTokenFromUnicode( rValue ) ) + { + case XML_3cd4 : nConstant = 270 * 60000; break; + case XML_3cd8 : nConstant = 135 * 60000; break; + case XML_5cd8 : nConstant = 225 * 60000; break; + case XML_7cd8 : nConstant = 315 * 60000; break; + case XML_cd2 : nConstant = 180 * 60000; break; + case XML_cd4 : nConstant = 90 * 60000; break; + case XML_cd8 : nConstant = 45 * 60000; break; + + case XML_b : // variable height of the shape defined in spPr + case XML_h : + { + if ( bNoSymbols ) + { + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "height" ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + else + aRet.Type = EnhancedCustomShapeParameterType::HEIGHT; // TODO: HEIGHT needs to be implemented + } + break; + + + case XML_hd8 : // !!PASSTHROUGH INTENDED + nVal += 2; // */ h 1.0 8.0 + case XML_hd6 : // */ h 1.0 6.0 + nVal++; + case XML_hd5 : // */ h 1.0 5.0 + nVal++; + case XML_hd4 : // */ h 1.0 4.0 + nVal += 2; + case XML_hd2 : // */ h 1.0 2.0 + case XML_vc : // */ h 1.0 2.0 + { + nVal += '2'; + + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "height/" ) + rtl::OUString( nVal ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + break; + + case XML_t : + case XML_l : + { + nConstant = 0; + aRet.Type = EnhancedCustomShapeParameterType::NORMAL; + } + break; + + case XML_ls : // longest side: max w h + { + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "max(width,height)" ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + break; + case XML_ss : // shortest side: min w h + { + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "min(width,height)" ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + break; + case XML_ssd8 : // */ ss 1.0 8.0 + nVal += 2; + case XML_ssd6 : // */ ss 1.0 6.0 + nVal += 2; + case XML_ssd4 : // */ ss 1.0 4.0 + nVal += 2; + case XML_ssd2 : // */ ss 1.0 2.0 + { + nVal += '2'; + + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "min(width,height)/" ) + rtl::OUString( nVal ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + break; + + case XML_r : // variable width of the shape defined in spPr + case XML_w : + { + if ( bNoSymbols ) + { + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "width" ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + else + aRet.Type = EnhancedCustomShapeParameterType::WIDTH; + } + break; + + case XML_wd10 : // */ w 1.0 10.0 + nVal += 2; + case XML_wd8 : // */ w 1.0 8.0 + nVal += 2; + case XML_wd6 : // */ w 1.0 6.0 + nVal++; + case XML_wd5 : // */ w 1.0 5.0 + nVal++; + case XML_wd4 : // */ w 1.0 4.0 + nVal += 2; + case XML_hc : // */ w 1.0 2.0 + case XML_wd2 : // */ w 1.0 2.0 + { + nVal += '2'; + + CustomShapeGuide aGuide; + aGuide.maName = rValue; + aGuide.maFormula = CREATE_OUSTRING( "width/" ) + rtl::OUString( nVal ); + + aRet.Value = Any( CustomShapeProperties::SetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), aGuide ) ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + break; + + default: + bConstant = sal_False; + break; + } + if ( bConstant ) + { + if ( nConstant ) + { + aRet.Value = Any( nConstant ); + aRet.Type = EnhancedCustomShapeParameterType::NORMAL; + } + } + else + { + sal_Unicode n = rValue[ 0 ]; + if ( ( n == '+' ) || ( n == '-' ) ) + { + if ( rValue.getLength() > 0 ) + n = rValue[ 1 ]; + } + if ( ( n >= '0' ) && ( n <= '9' ) ) + { // seems to be a ST_Coordinate + aRet.Value = Any( rValue.toInt32() ); + aRet.Type = EnhancedCustomShapeParameterType::NORMAL; + } + else + { + sal_Int32 nGuideIndex = CustomShapeProperties::GetCustomShapeGuideValue( rCustomShapeProperties.getAdjustmentGuideList(), rValue ); + if ( nGuideIndex >= 0 ) + { + aRet.Value = Any( nGuideIndex ); + aRet.Type = EnhancedCustomShapeParameterType::ADJUSTMENT; + } + else + { + nGuideIndex = CustomShapeProperties::GetCustomShapeGuideValue( rCustomShapeProperties.getGuideList(), rValue ); + if ( nGuideIndex >= 0 ) + { + aRet.Value = Any( nGuideIndex ); + aRet.Type = EnhancedCustomShapeParameterType::EQUATION; + } + else + aRet.Value = Any( rValue ); + } + } + } + } + return aRet; +} + +static EnhancedCustomShapeParameter GetAdjAngle( CustomShapeProperties& rCustomShapeProperties, const ::rtl::OUString& rValue ) +{ + EnhancedCustomShapeParameter aAngle( GetAdjCoordinate( rCustomShapeProperties, rValue, sal_True ) ); + if ( aAngle.Type == EnhancedCustomShapeParameterType::NORMAL ) + { + sal_Int32 nValue = 0; + aAngle.Value >>= nValue; + double fValue = ( static_cast< double >( nValue ) / 60000.0 ) * 360.0; + aAngle.Value <<= fValue; + } + return aAngle; +} + // --------------------------------------------------------------------- // CT_GeomGuideList -class AdjustmentValueContext : public ContextHandler +class GeomGuideListContext : public ContextHandler { public: - AdjustmentValueContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + GeomGuideListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< CustomShapeGuide >& rGuideList ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); protected: - CustomShapeProperties& mrCustomShapeProperties; + std::vector< CustomShapeGuide >& mrGuideList; + CustomShapeProperties& mrCustomShapeProperties; }; -AdjustmentValueContext::AdjustmentValueContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties ) +GeomGuideListContext::GeomGuideListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< CustomShapeGuide >& rGuideList ) : ContextHandler( rParent ) +, mrGuideList( rGuideList ) , mrCustomShapeProperties( rCustomShapeProperties ) { } -static rtl::OUString convertToOOEquation( const rtl::OUString& rSource ) +static rtl::OUString convertToOOEquation( CustomShapeProperties& rCustomShapeProperties, const rtl::OUString& rSource ) { if ( !pCommandHashMap ) { @@ -138,28 +487,140 @@ static rtl::OUString convertToOOEquation( const rtl::OUString& rSource ) rtl::OUString aEquation; if ( aTokens.size() ) { + sal_Int32 i, nParameters = aTokens.size() - 1; + if ( nParameters > 3 ) + nParameters = 3; + + rtl::OUString sParameters[ 3 ]; + + for ( i = 0; i < nParameters; i++ ) + sParameters[ i ] = GetFormulaParameter( GetAdjCoordinate( rCustomShapeProperties, aTokens[ i + 1 ], sal_False ) ); + const FormulaCommandHMap::const_iterator aIter( pCommandHashMap->find( aTokens[ 0 ] ) ); if ( aIter != pCommandHashMap->end() ) { switch( aIter->second ) { case FC_MULDIV : + { + if ( nParameters == 3 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "*" ) + sParameters[ 1 ] + + CREATE_OUSTRING( "/" ) + sParameters[ 2 ]; + } + break; case FC_PLUSMINUS : + { + if ( nParameters == 3 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "+" ) + sParameters[ 1 ] + + CREATE_OUSTRING( "-" ) + sParameters[ 2 ]; + } + break; case FC_PLUSDIV : + { + if ( nParameters == 3 ) + aEquation = CREATE_OUSTRING( "(" ) + sParameters[ 0 ] + CREATE_OUSTRING( "+" ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")/" ) + sParameters[ 2 ]; + } + break; case FC_IFELSE : + { + if ( nParameters == 3 ) + aEquation = CREATE_OUSTRING( "if(" ) + sParameters[ 0 ] + CREATE_OUSTRING( "," ) + + sParameters[ 1 ] + CREATE_OUSTRING( "," ) + sParameters[ 2 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_ABS : + { + if ( nParameters == 1 ) + aEquation = CREATE_OUSTRING( "abs(" ) + sParameters[ 0 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_AT2 : + { + if ( nParameters == 2 ) + aEquation = CREATE_OUSTRING( "atan2(" ) + sParameters[ 0 ] + CREATE_OUSTRING( "," ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_CAT2 : + { + if ( nParameters == 3 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "*(cos(arctan(" ) + + sParameters[ 1 ] + CREATE_OUSTRING( "," ) + sParameters[ 2 ] + CREATE_OUSTRING( ")))" ); + } + break; case FC_COS : + { + if ( nParameters == 2 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "*cos(" ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_MAX : + { + if ( nParameters == 2 ) + aEquation = CREATE_OUSTRING( "max(" ) + sParameters[ 0 ] + CREATE_OUSTRING( "," ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_MIN : + { + if ( nParameters == 2 ) + aEquation = CREATE_OUSTRING( "min(" ) + sParameters[ 0 ] + CREATE_OUSTRING( "," ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_MOD : + { + if ( nParameters == 3 ) + aEquation = CREATE_OUSTRING( "sqrt(" ) + + sParameters[ 0 ] + CREATE_OUSTRING( "*" ) + sParameters[ 0 ] + CREATE_OUSTRING( "+" ) + + sParameters[ 1 ] + CREATE_OUSTRING( "*" ) + sParameters[ 1 ] + CREATE_OUSTRING( "+" ) + + sParameters[ 2 ] + CREATE_OUSTRING( "*" ) + sParameters[ 2 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_PIN : + { + if ( nParameters == 3 ) // if(x-y,x,if(y-z,z,y)) + aEquation = CREATE_OUSTRING( "if(" ) + sParameters[ 0 ] + CREATE_OUSTRING( "-" ) + sParameters[ 1 ] + + CREATE_OUSTRING( "," ) + sParameters[ 0 ] + CREATE_OUSTRING( ",if(" ) + sParameters[ 2 ] + + CREATE_OUSTRING( "-" ) + sParameters[ 1 ] + CREATE_OUSTRING( "," ) + sParameters[ 1 ] + + CREATE_OUSTRING( "," ) + sParameters[ 2 ] + CREATE_OUSTRING( "))" ); + } + break; case FC_SAT2 : + { + if ( nParameters == 3 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "*(sin(arctan(" ) + + sParameters[ 1 ] + CREATE_OUSTRING( "," ) + sParameters[ 2 ] + CREATE_OUSTRING( ")))" ); + } + break; case FC_SIN : + { + if ( nParameters == 2 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "*sin(" ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_SQRT : + { + if ( nParameters == 1 ) + aEquation = CREATE_OUSTRING( "sqrt(" ) + sParameters[ 0 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_TAN : + { + if ( nParameters == 2 ) + aEquation = sParameters[ 0 ] + CREATE_OUSTRING( "*tan(" ) + + sParameters[ 1 ] + CREATE_OUSTRING( ")" ); + } + break; case FC_VAL : + { + if ( nParameters == 1 ) + aEquation = sParameters[ 0 ]; + } + break; default : break; } @@ -168,99 +629,544 @@ static rtl::OUString convertToOOEquation( const rtl::OUString& rSource ) return aEquation; } -Reference< XFastContextHandler > AdjustmentValueContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +Reference< XFastContextHandler > GeomGuideListContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) { if ( aElementToken == ( NMSP_DRAWINGML | XML_gd ) ) // CT_GeomGuide { CustomShapeGuide aGuide; aGuide.maName = xAttribs->getOptionalValue( XML_name ); - aGuide.maFormula = convertToOOEquation( xAttribs->getOptionalValue( XML_fmla ) ); - std::vector< CustomShapeGuide >& rAdjustmentValues( mrCustomShapeProperties.getAdjustmentValues() ); - rAdjustmentValues.push_back( aGuide ); + aGuide.maFormula = convertToOOEquation( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_fmla ) ); + mrGuideList.push_back( aGuide ); } return this; } // --------------------------------------------------------------------- -class PathListContext : public ContextHandler +static const rtl::OUString GetGeomGuideName( const ::rtl::OUString& rValue ) +{ + return rValue; +} + +// --------------------------------------------------------------------- +// CT_AdjPoint2D +class AdjPoint2DContext : public ContextHandler +{ +public: + AdjPoint2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D ); +}; + +AdjPoint2DContext::AdjPoint2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D ) +: ContextHandler( rParent ) +{ + rAdjPoint2D.First = GetAdjCoordinate( rCustomShapeProperties, xAttribs->getOptionalValue( XML_x ), sal_True ); + rAdjPoint2D.Second = GetAdjCoordinate( rCustomShapeProperties, xAttribs->getOptionalValue( XML_y ), sal_True ); +} + +// --------------------------------------------------------------------- +// CT_XYAdjustHandle +class XYAdjustHandleContext : public ContextHandler { public: - PathListContext( ContextHandler& rParent, Shape& rShape ); - virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( ::sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); - virtual void SAL_CALL endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException); + XYAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); protected: - Shape& mrShape; - sal_Int32 maPointToken; - ::basegfx::B2DPolygon maPolygon; + AdjustHandle& mrAdjustHandle; + CustomShapeProperties& mrCustomShapeProperties; }; -PathListContext::PathListContext( ContextHandler& rParent, Shape& rShape ) +XYAdjustHandleContext::XYAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle ) : ContextHandler( rParent ) -, mrShape( rShape ) +, mrAdjustHandle( rAdjustHandle ) +, mrCustomShapeProperties( rCustomShapeProperties ) { + const rtl::OUString aEmptyDefault; + AttributeList aAttribs( xAttribs ); + if ( aAttribs.hasAttribute( XML_gdRefX ) ) + { + mrAdjustHandle.gdRef1 = GetGeomGuideName( aAttribs.getString( XML_gdRefX, aEmptyDefault ) ); + } + if ( aAttribs.hasAttribute( XML_minX ) ) + { + mrAdjustHandle.min1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minX, aEmptyDefault ), sal_True ); + } + if ( aAttribs.hasAttribute( XML_maxX ) ) + { + mrAdjustHandle.max1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxX, aEmptyDefault ), sal_True ); + } + if ( aAttribs.hasAttribute( XML_gdRefY ) ) + { + mrAdjustHandle.gdRef2 = GetGeomGuideName( aAttribs.getString( XML_gdRefY, aEmptyDefault ) ); + } + if ( aAttribs.hasAttribute( XML_minY ) ) + { + mrAdjustHandle.min2 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minY, aEmptyDefault ), sal_True ); + } + if ( aAttribs.hasAttribute( XML_maxY ) ) + { + mrAdjustHandle.max2 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxY, aEmptyDefault ), sal_True ); + } } -Reference< XFastContextHandler > PathListContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +Reference< XFastContextHandler > XYAdjustHandleContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) { - switch( aElementToken ) { - case NMSP_DRAWINGML | XML_path: - maPolygon.clear(); - break; - case NMSP_DRAWINGML | XML_close: - maPolygon.setClosed( true ); - break; - case NMSP_DRAWINGML | XML_pt: - { - OUString sX, sY; - - sX = xAttribs->getOptionalValue( XML_x ); - sY = xAttribs->getOptionalValue( XML_y ); - - double dX, dY; - - dX = sX.toDouble(); - dY = sY.toDouble(); - - maPolygon.append( B2DPoint ( dX, dY ) ); - break; - } - case NMSP_DRAWINGML | XML_lnTo: - case NMSP_DRAWINGML | XML_moveTo: - maPointToken = aElementToken; - break; - } - - return this; + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pos ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandle.pos ); // CT_AdjPoint2D + return xContext; } -void PathListContext::endFastElement( sal_Int32 aElementToken ) throw (SAXException, RuntimeException) +// --------------------------------------------------------------------- +// CT_PolarAdjustHandle +class PolarAdjustHandleContext : public ContextHandler +{ +public: + PolarAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + AdjustHandle& mrAdjustHandle; + CustomShapeProperties& mrCustomShapeProperties; +}; + +PolarAdjustHandleContext::PolarAdjustHandleContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, AdjustHandle& rAdjustHandle ) +: ContextHandler( rParent ) +, mrAdjustHandle( rAdjustHandle ) +, mrCustomShapeProperties( rCustomShapeProperties ) { - switch( aElementToken ) { - case NMSP_DRAWINGML|XML_pathLst: + const rtl::OUString aEmptyDefault; + AttributeList aAttribs( xAttribs ); + if ( aAttribs.hasAttribute( XML_gdRefR ) ) + { + mrAdjustHandle.gdRef1 = GetGeomGuideName( aAttribs.getString( XML_gdRefR, aEmptyDefault ) ); + } + if ( aAttribs.hasAttribute( XML_minR ) ) + { + mrAdjustHandle.min1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_minR, aEmptyDefault ), sal_True ); + } + if ( aAttribs.hasAttribute( XML_maxR ) ) { - B2DPolyPolygon& rPoly = mrShape.getCustomShapeProperties()->getPolygon(); - if( rPoly.count() ) { - if( rPoly.areControlPointsUsed() ) { - if( rPoly.isClosed() ) - mrShape.setServiceName( "com.sun.star.drawing.ClosedBezierShape" ); + mrAdjustHandle.max1 = GetAdjCoordinate( mrCustomShapeProperties, aAttribs.getString( XML_maxR, aEmptyDefault ), sal_True ); + } + if ( aAttribs.hasAttribute( XML_gdRefAng ) ) + { + mrAdjustHandle.gdRef2 = GetGeomGuideName( aAttribs.getString( XML_gdRefAng, aEmptyDefault ) ); + } + if ( aAttribs.hasAttribute( XML_minAng ) ) + { + mrAdjustHandle.min2 = GetAdjAngle( mrCustomShapeProperties, aAttribs.getString( XML_minAng, aEmptyDefault ) ); + } + if ( aAttribs.hasAttribute( XML_maxAng ) ) + { + mrAdjustHandle.max2 = GetAdjAngle( mrCustomShapeProperties, aAttribs.getString( XML_maxAng, aEmptyDefault ) ); + } +} + +Reference< XFastContextHandler > PolarAdjustHandleContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pos ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandle.pos ); // CT_AdjPoint2D + return xContext; +} + +// --------------------------------------------------------------------- +// CT_AdjustHandleList +class AdjustHandleListContext : public ContextHandler +{ +public: + AdjustHandleListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< AdjustHandle >& rAdjustHandleList ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + std::vector< AdjustHandle >& mrAdjustHandleList; + CustomShapeProperties& mrCustomShapeProperties; +}; + +AdjustHandleListContext::AdjustHandleListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< AdjustHandle >& rAdjustHandleList ) +: ContextHandler( rParent ) +, mrAdjustHandleList( rAdjustHandleList ) +, mrCustomShapeProperties( rCustomShapeProperties ) +{ +} + +Reference< XFastContextHandler > AdjustHandleListContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_ahXY ) ) // CT_XYAdjustHandle + { + AdjustHandle aAdjustHandle( sal_False ); + mrAdjustHandleList.push_back( aAdjustHandle ); + xContext = new XYAdjustHandleContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandleList.back() ); + } + else if ( aElementToken == ( NMSP_DRAWINGML | XML_ahPolar ) ) // CT_PolarAdjustHandle + { + AdjustHandle aAdjustHandle( sal_True ); + mrAdjustHandleList.push_back( aAdjustHandle ); + xContext = new PolarAdjustHandleContext( *this, xAttribs, mrCustomShapeProperties, mrAdjustHandleList.back() ); + } + return xContext; +} + +// --------------------------------------------------------------------- +// CT_ConnectionSite +class ConnectionSiteContext : public ContextHandler +{ +public: + ConnectionSiteContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, ConnectionSite& rConnectionSite ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + ConnectionSite& mrConnectionSite; + CustomShapeProperties& mrCustomShapeProperties; +}; + +ConnectionSiteContext::ConnectionSiteContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, ConnectionSite& rConnectionSite ) +: ContextHandler( rParent ) +, mrConnectionSite( rConnectionSite ) +, mrCustomShapeProperties( rCustomShapeProperties ) +{ + mrConnectionSite.ang = GetAdjAngle( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_ang ) ); +} + +Reference< XFastContextHandler > ConnectionSiteContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pos ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrConnectionSite.pos ); // CT_AdjPoint2D + return xContext; +} + +// --------------------------------------------------------------------- +// CT_Path2DMoveTo +class Path2DMoveToContext : public ContextHandler +{ +public: + Path2DMoveToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + EnhancedCustomShapeParameterPair& mrAdjPoint2D; + CustomShapeProperties& mrCustomShapeProperties; +}; + +Path2DMoveToContext::Path2DMoveToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D ) +: ContextHandler( rParent ) +, mrAdjPoint2D( rAdjPoint2D ) +, mrCustomShapeProperties( rCustomShapeProperties ) +{ +} + +Reference< XFastContextHandler > Path2DMoveToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pt ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjPoint2D ); // CT_AdjPoint2D + return xContext; +} + +// --------------------------------------------------------------------- +// CT_Path2DLineTo +class Path2DLineToContext : public ContextHandler +{ +public: + Path2DLineToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + EnhancedCustomShapeParameterPair& mrAdjPoint2D; + CustomShapeProperties& mrCustomShapeProperties; +}; + +Path2DLineToContext::Path2DLineToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rAdjPoint2D ) +: ContextHandler( rParent ) +, mrAdjPoint2D( rAdjPoint2D ) +, mrCustomShapeProperties( rCustomShapeProperties ) +{ +} + +Reference< XFastContextHandler > Path2DLineToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pt ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, mrAdjPoint2D ); // CT_AdjPoint2D + return xContext; +} + +// --------------------------------------------------------------------- +// CT_Path2DQuadBezierTo +class Path2DQuadBezierToContext : public ContextHandler +{ +public: + Path2DQuadBezierToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, EnhancedCustomShapeParameterPair& rPt1, EnhancedCustomShapeParameterPair& rPt2 ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + EnhancedCustomShapeParameterPair& mrPt1; + EnhancedCustomShapeParameterPair& mrPt2; + int nCount; + CustomShapeProperties& mrCustomShapeProperties; +}; + +Path2DQuadBezierToContext::Path2DQuadBezierToContext( ContextHandler& rParent, + CustomShapeProperties& rCustomShapeProperties, + EnhancedCustomShapeParameterPair& rPt1, + EnhancedCustomShapeParameterPair& rPt2 ) +: ContextHandler( rParent ) +, mrPt1( rPt1 ) +, mrPt2( rPt2 ) +, nCount( 0 ) +, mrCustomShapeProperties( rCustomShapeProperties ) +{ +} + +Reference< XFastContextHandler > Path2DQuadBezierToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pt ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, nCount++ ? mrPt2 : mrPt1 ); // CT_AdjPoint2D + return xContext; +} + +// --------------------------------------------------------------------- +// CT_Path2DCubicBezierTo +class Path2DCubicBezierToContext : public ContextHandler +{ +public: + Path2DCubicBezierToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, + EnhancedCustomShapeParameterPair&, EnhancedCustomShapeParameterPair&, EnhancedCustomShapeParameterPair& ); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + CustomShapeProperties& mrCustomShapeProperties; + EnhancedCustomShapeParameterPair& mrControlPt1; + EnhancedCustomShapeParameterPair& mrControlPt2; + EnhancedCustomShapeParameterPair& mrEndPt; + int nCount; +}; + +Path2DCubicBezierToContext::Path2DCubicBezierToContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, + EnhancedCustomShapeParameterPair& rControlPt1, + EnhancedCustomShapeParameterPair& rControlPt2, + EnhancedCustomShapeParameterPair& rEndPt ) +: ContextHandler( rParent ) +, mrCustomShapeProperties( rCustomShapeProperties ) +, mrControlPt1( rControlPt1 ) +, mrControlPt2( rControlPt2 ) +, mrEndPt( rEndPt ) +, nCount( 0 ) +{ +} + +Reference< XFastContextHandler > Path2DCubicBezierToContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_pt ) ) + xContext = new AdjPoint2DContext( *this, xAttribs, mrCustomShapeProperties, + nCount++ ? nCount == 2 ? mrControlPt2 : mrEndPt : mrControlPt1 ); // CT_AdjPoint2D + return xContext; +} + +// --------------------------------------------------------------------- +// CT_Path2DContext +class Path2DContext : public ContextHandler +{ +public: + Path2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& rSegments, Path2D& rPath2D ); + virtual ~Path2DContext(); + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL + createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) + throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + Path2D& mrPath2D; + std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& mrSegments; + CustomShapeProperties& mrCustomShapeProperties; +}; + +Path2DContext::Path2DContext( ContextHandler& rParent, const Reference< XFastAttributeList >& xAttribs, CustomShapeProperties& rCustomShapeProperties, std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& rSegments, Path2D& rPath2D ) +: ContextHandler( rParent ) +, mrPath2D( rPath2D ) +, mrSegments( rSegments ) +, mrCustomShapeProperties( rCustomShapeProperties ) +{ + const rtl::OUString aEmptyString; + + AttributeList aAttribs( xAttribs ); + rPath2D.w = aAttribs.getString( XML_w, aEmptyString ).toInt64(); + rPath2D.h = aAttribs.getString( XML_h, aEmptyString ).toInt64(); + rPath2D.fill = aAttribs.getToken( XML_fill, XML_norm ); + rPath2D.stroke = aAttribs.getBool( XML_stroke, sal_True ); + rPath2D.extrusionOk = aAttribs.getBool( XML_extrusionOk, sal_True ); +} + +Path2DContext::~Path2DContext() +{ + EnhancedCustomShapeSegment aNewSegment; + if ( mrPath2D.fill == XML_none ) + { + aNewSegment.Command = EnhancedCustomShapeSegmentCommand::NOFILL; + aNewSegment.Count = 0; + mrSegments.push_back( aNewSegment ); + } + aNewSegment.Command = EnhancedCustomShapeSegmentCommand::ENDSUBPATH; + aNewSegment.Count = 0; + mrSegments.push_back( aNewSegment ); +} + +Reference< XFastContextHandler > Path2DContext::createFastChildContext( sal_Int32 aElementToken, + const Reference< XFastAttributeList >& xAttribs ) throw ( SAXException, RuntimeException ) +{ + Reference< XFastContextHandler > xContext; + switch( aElementToken ) + { + case NMSP_DRAWINGML | XML_close : + { + EnhancedCustomShapeSegment aNewSegment; + aNewSegment.Command = EnhancedCustomShapeSegmentCommand::CLOSESUBPATH; + aNewSegment.Count = 0; + mrSegments.push_back( aNewSegment ); + } + break; + case NMSP_DRAWINGML | XML_moveTo : + { + EnhancedCustomShapeSegment aNewSegment; + aNewSegment.Command = EnhancedCustomShapeSegmentCommand::MOVETO; + aNewSegment.Count = 1; + mrSegments.push_back( aNewSegment ); + + EnhancedCustomShapeParameterPair aAdjPoint2D; + mrPath2D.parameter.push_back( aAdjPoint2D ); + xContext = new Path2DMoveToContext( *this, mrCustomShapeProperties, mrPath2D.parameter.back() ); + } + break; + case NMSP_DRAWINGML | XML_lnTo : + { + + if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::LINETO ) ) + mrSegments.back().Count++; + else + { + EnhancedCustomShapeSegment aSegment; + aSegment.Command = EnhancedCustomShapeSegmentCommand::LINETO; + aSegment.Count = 1; + mrSegments.push_back( aSegment ); + } + EnhancedCustomShapeParameterPair aAdjPoint2D; + mrPath2D.parameter.push_back( aAdjPoint2D ); + xContext = new Path2DLineToContext( *this, mrCustomShapeProperties, mrPath2D.parameter.back() ); + } + break; + case NMSP_DRAWINGML | XML_arcTo : // CT_Path2DArcTo + { + if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::ARCTO ) ) + mrSegments.back().Count++; else - mrShape.setServiceName( "com.sun.star.drawing.OpenBezierShape" ); - } else { - if( rPoly.isClosed() ) - mrShape.setServiceName( "com.sun.star.drawing.PolyPolygonPathShape" ); + { + EnhancedCustomShapeSegment aSegment; + aSegment.Command = EnhancedCustomShapeSegmentCommand::ARCTO; + aSegment.Count = 1; + mrSegments.push_back( aSegment ); + } + EnhancedCustomShapeParameter aWidth = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_wR ), sal_True ); + EnhancedCustomShapeParameter aHeight = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_hR ), sal_True ); + EnhancedCustomShapeParameter aStartAngle = GetAdjAngle( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_stAng ) ); + EnhancedCustomShapeParameter swAngle = GetAdjAngle( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_swAng ) ); + + EnhancedCustomShapeParameterPair aPt1; // TODO: conversion from (wr hr stAng swAng) + EnhancedCustomShapeParameterPair aPt2; // to (x1 y1 x2 y2 x3 y3 x y) needed + EnhancedCustomShapeParameterPair aPt3; + EnhancedCustomShapeParameterPair aPt; + mrPath2D.parameter.push_back( aPt1 ); + mrPath2D.parameter.push_back( aPt2 ); + mrPath2D.parameter.push_back( aPt3 ); + mrPath2D.parameter.push_back( aPt ); + } + break; + case NMSP_DRAWINGML | XML_quadBezTo : + { + if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO ) ) + mrSegments.back().Count++; else - mrShape.setServiceName( "com.sun.star.drawing.PolyLinePathShape" ); + { + EnhancedCustomShapeSegment aSegment; + aSegment.Command = EnhancedCustomShapeSegmentCommand::QUADRATICCURVETO; + aSegment.Count = 1; + mrSegments.push_back( aSegment ); + } + EnhancedCustomShapeParameterPair aPt1; + EnhancedCustomShapeParameterPair aPt2; + mrPath2D.parameter.push_back( aPt1 ); + mrPath2D.parameter.push_back( aPt2 ); + xContext = new Path2DQuadBezierToContext( *this, mrCustomShapeProperties, + mrPath2D.parameter[ mrPath2D.parameter.size() - 2 ], + mrPath2D.parameter.back() ); } + break; + case NMSP_DRAWINGML | XML_cubicBezTo : + { + if ( !mrSegments.empty() && ( mrSegments.back().Command == EnhancedCustomShapeSegmentCommand::CURVETO ) ) + mrSegments.back().Count++; + else + { + EnhancedCustomShapeSegment aSegment; + aSegment.Command = EnhancedCustomShapeSegmentCommand::CURVETO; + aSegment.Count = 1; + mrSegments.push_back( aSegment ); + } + EnhancedCustomShapeParameterPair aControlPt1; + EnhancedCustomShapeParameterPair aControlPt2; + EnhancedCustomShapeParameterPair aEndPt; + mrPath2D.parameter.push_back( aControlPt1 ); + mrPath2D.parameter.push_back( aControlPt2 ); + mrPath2D.parameter.push_back( aEndPt ); + xContext = new Path2DCubicBezierToContext( *this, mrCustomShapeProperties, + mrPath2D.parameter[ mrPath2D.parameter.size() - 3 ], + mrPath2D.parameter[ mrPath2D.parameter.size() - 2 ], + mrPath2D.parameter.back() ); } break; } - case NMSP_DRAWINGML|XML_path: - if( maPolygon.count() > 0 ) - mrShape.getCustomShapeProperties()->getPolygon().append( maPolygon ); - break; + return xContext; +} + +// --------------------------------------------------------------------- +// CT_Path2DList +class Path2DListContext : public ContextHandler +{ +public: + Path2DListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< EnhancedCustomShapeSegment >& rSegments, + std::vector< Path2D >& rPath2DList ); + + virtual ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException); + +protected: + + CustomShapeProperties& mrCustomShapeProperties; + std::vector< com::sun::star::drawing::EnhancedCustomShapeSegment >& mrSegments; + std::vector< Path2D >& mrPath2DList; +}; + +Path2DListContext::Path2DListContext( ContextHandler& rParent, CustomShapeProperties& rCustomShapeProperties, std::vector< EnhancedCustomShapeSegment >& rSegments, + std::vector< Path2D >& rPath2DList ) +: ContextHandler( rParent ) +, mrCustomShapeProperties( rCustomShapeProperties ) +, mrSegments( rSegments ) +, mrPath2DList( rPath2DList ) +{ +} + +::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastContextHandler > SAL_CALL Path2DListContext::createFastChildContext( sal_Int32 aElementToken, const ::com::sun::star::uno::Reference< ::com::sun::star::xml::sax::XFastAttributeList >& xAttribs ) throw (::com::sun::star::xml::sax::SAXException, ::com::sun::star::uno::RuntimeException) +{ + Reference< XFastContextHandler > xContext; + if ( aElementToken == ( NMSP_DRAWINGML | XML_path ) ) + { + Path2D aPath2D; + mrPath2DList.push_back( aPath2D ); + xContext = new Path2DContext( *this, xAttribs, mrCustomShapeProperties, mrSegments, mrPath2DList.back() ); } + return xContext; } // --------------------------------------------------------------------- @@ -1066,29 +1972,53 @@ static OUString GetTextShapeType( sal_Int32 nType ) // --------------------------------------------------------------------- // CT_CustomGeometry2D -CustomShapeGeometryContext::CustomShapeGeometryContext( ContextHandler& rParent, const Reference< XFastAttributeList >& /* xAttribs */, Shape& rShape ) +CustomShapeGeometryContext::CustomShapeGeometryContext( ContextHandler& rParent, const Reference< XFastAttributeList >& /* xAttribs */, CustomShapeProperties& rCustomShapeProperties ) : ContextHandler( rParent ) -, mrShape( rShape ) +, mrCustomShapeProperties( rCustomShapeProperties ) { } -Reference< XFastContextHandler > CustomShapeGeometryContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException) +Reference< XFastContextHandler > CustomShapeGeometryContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& xAttribs ) throw (SAXException, RuntimeException) { + Reference< XFastContextHandler > xContext; switch( aElementToken ) { - // todo - case NMSP_DRAWINGML|XML_avLst: // CT_GeomGuideList adjust value list - case NMSP_DRAWINGML|XML_gdLst: // CT_GeomGuideList guide list - case NMSP_DRAWINGML|XML_ahLst: // CT_AdjustHandleList adjust handle list - case NMSP_DRAWINGML|XML_cxnLst: // CT_ConnectionSiteList connection site list - case NMSP_DRAWINGML|XML_rect: // CT_GeomRectList geometry rect list - break; - case NMSP_DRAWINGML|XML_pathLst: // CT_Path2DList 2d path list - return new PathListContext( *this, mrShape ); - } + case NMSP_DRAWINGML|XML_avLst: // CT_GeomGuideList adjust value list + xContext = new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() ); + break; + case NMSP_DRAWINGML|XML_gdLst: // CT_GeomGuideList guide list + xContext = new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getGuideList() ); + break; + case NMSP_DRAWINGML|XML_ahLst: // CT_AdjustHandleList adjust handle list + xContext = new AdjustHandleListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustHandleList() ); + break; + case NMSP_DRAWINGML|XML_cxnLst: // CT_ConnectionSiteList connection site list + xContext = this; + break; + case NMSP_DRAWINGML|XML_rect: // CT_GeomRectList geometry rect list + { + GeomRect aGeomRect; + aGeomRect.l = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_l ), sal_True ); + aGeomRect.t = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_t ), sal_True ); + aGeomRect.r = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_r ), sal_True ); + aGeomRect.b = GetAdjCoordinate( mrCustomShapeProperties, xAttribs->getOptionalValue( XML_b ), sal_True ); + mrCustomShapeProperties.getTextRect() = aGeomRect; + } + break; + case NMSP_DRAWINGML|XML_pathLst: // CT_Path2DList 2d path list + xContext = new Path2DListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getSegments(), mrCustomShapeProperties.getPath2DList() ); + break; - Reference< XFastContextHandler > xEmpty; - return xEmpty; + // from cxnLst: + case NMSP_DRAWINGML|XML_cxn: // CT_ConnectionSite + { + ConnectionSite aConnectionSite; + mrCustomShapeProperties.getConnectionSiteList().push_back( aConnectionSite ); + xContext = new ConnectionSiteContext( *this, xAttribs, mrCustomShapeProperties, mrCustomShapeProperties.getConnectionSiteList().back() ); + } + break; + } + return xContext; } // --------------------------------------------------------------------- @@ -1108,7 +2038,7 @@ PresetShapeGeometryContext::PresetShapeGeometryContext( ContextHandler& rParent, Reference< XFastContextHandler > PresetShapeGeometryContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException) { if ( aElementToken == ( NMSP_DRAWINGML | XML_avLst ) ) - return new AdjustmentValueContext( *this, mrCustomShapeProperties ); + return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() ); else return this; } @@ -1129,20 +2059,10 @@ PresetTextShapeContext::PresetTextShapeContext( ContextHandler& rParent, const R Reference< XFastContextHandler > PresetTextShapeContext::createFastChildContext( sal_Int32 aElementToken, const Reference< XFastAttributeList >& ) throw (SAXException, RuntimeException) { - switch( aElementToken ) - { - // todo - case NMSP_DRAWINGML|XML_avLst: // CT_GeomGuideList adjust value list - case NMSP_DRAWINGML|XML_gdLst: // CT_GeomGuideList guide list - case NMSP_DRAWINGML|XML_ahLst: // CT_AdjustHandleList adjust handle list - case NMSP_DRAWINGML|XML_cxnLst: // CT_ConnectionSiteList connection site list - case NMSP_DRAWINGML|XML_rect: // CT_GeomRectList geometry rect list - case NMSP_DRAWINGML|XML_pathLst: // CT_Path2DList 2d path list - break; - } - - Reference< XFastContextHandler > xEmpty; - return xEmpty; + if ( aElementToken == ( NMSP_DRAWINGML | XML_avLst ) ) + return new GeomGuideListContext( *this, mrCustomShapeProperties, mrCustomShapeProperties.getAdjustmentGuideList() ); + else + return this; } } } diff --git a/oox/source/drawingml/customshapeproperties.cxx b/oox/source/drawingml/customshapeproperties.cxx index 4459c5936cfa..62e42701b273 100644 --- a/oox/source/drawingml/customshapeproperties.cxx +++ b/oox/source/drawingml/customshapeproperties.cxx @@ -32,6 +32,7 @@ #include "oox/core/namespaces.hxx" #include "properties.hxx" #include "tokens.hxx" +#include <com/sun/star/awt/Rectangle.hpp> #include <com/sun/star/beans/XMultiPropertySet.hpp> #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/graphic/XGraphicTransformer.hpp> @@ -39,6 +40,7 @@ #include <com/sun/star/drawing/XEnhancedCustomShapeDefaulter.hpp> using rtl::OUString; +using namespace ::oox::core; using namespace ::com::sun::star; using namespace ::com::sun::star::uno; using namespace ::com::sun::star::beans; @@ -54,13 +56,41 @@ CustomShapeProperties::~CustomShapeProperties() { } +sal_Int32 CustomShapeProperties::SetCustomShapeGuideValue( std::vector< CustomShapeGuide >& rGuideList, const CustomShapeGuide& rGuide ) +{ + sal_uInt32 nIndex = 0; + for( ; nIndex < rGuideList.size(); nIndex++ ) + { + if ( rGuideList[ nIndex ].maName == rGuide.maName ) + break; + } + if ( nIndex == rGuideList.size() ) + rGuideList.push_back( rGuide ); + return static_cast< sal_Int32 >( nIndex ); +} + +// returns the index into the guidelist for a given formula name, +// if the return value is < 0 then the guide value could not be found +sal_Int32 CustomShapeProperties::GetCustomShapeGuideValue( const std::vector< CustomShapeGuide >& rGuideList, const rtl::OUString& rFormulaName ) +{ + sal_Int32 nIndex = 0; + for( ; nIndex < static_cast< sal_Int32 >( rGuideList.size() ); nIndex++ ) + { + if ( rGuideList[ nIndex ].maName == rFormulaName ) + break; + } + if ( nIndex == static_cast< sal_Int32 >( rGuideList.size() ) ) + nIndex = -1; + return nIndex; +} + void CustomShapeProperties::apply( const CustomShapePropertiesPtr& /* rSourceCustomShapeProperties */ ) { // not sure if this needs to be implemented } -void CustomShapeProperties::pushToPropSet( - const Reference < XPropertySet >& xPropSet, const Reference < XShape > & xShape ) const +void CustomShapeProperties::pushToPropSet( const ::oox::core::FilterBase& /* rFilterBase */, + const Reference < XPropertySet >& xPropSet, const Reference < XShape > & xShape ) const { if ( maShapePresetType.getLength() ) { @@ -69,64 +99,155 @@ void CustomShapeProperties::pushToPropSet( if( xDefaulter.is() ) xDefaulter->createCustomShapeDefaults( maShapePresetType ); - const OUString sType = CREATE_OUSTRING( "Type" ); - const OUString sCustomShapeGeometry( RTL_CONSTASCII_USTRINGPARAM( "CustomShapeGeometry" ) ); - uno::Any aGeoPropSet = xPropSet->getPropertyValue( sCustomShapeGeometry ); - uno::Sequence< beans::PropertyValue > aGeoPropSeq; - if ( aGeoPropSet >>= aGeoPropSeq ) + if ( maAdjustmentGuideList.size() ) { - sal_Int32 i, nCount = aGeoPropSeq.getLength(); - for ( i = 0; i < nCount; i++ ) + const OUString sType = CREATE_OUSTRING( "Type" ); + const OUString sCustomShapeGeometry( RTL_CONSTASCII_USTRINGPARAM( "CustomShapeGeometry" ) ); + uno::Any aGeoPropSet = xPropSet->getPropertyValue( sCustomShapeGeometry ); + uno::Sequence< beans::PropertyValue > aGeoPropSeq; + if ( aGeoPropSet >>= aGeoPropSeq ) { - const rtl::OUString sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM( "AdjustmentValues" ) ); - if ( aGeoPropSeq[ i ].Name.equals( sAdjustmentValues ) ) + sal_Int32 i, nCount = aGeoPropSeq.getLength(); + for ( i = 0; i < nCount; i++ ) { - uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > aAdjustmentSeq; - if ( aGeoPropSeq[ i ].Value >>= aAdjustmentSeq ) + const rtl::OUString sAdjustmentValues( RTL_CONSTASCII_USTRINGPARAM( "AdjustmentValues" ) ); + if ( aGeoPropSeq[ i ].Name.equals( sAdjustmentValues ) ) { - sal_uInt32 j, nHighest = 0; - for( j = 0; j < maAdjustmentValues.size(); j++ ) + uno::Sequence< com::sun::star::drawing::EnhancedCustomShapeAdjustmentValue > aAdjustmentSeq; + if ( aGeoPropSeq[ i ].Value >>= aAdjustmentSeq ) { - const rtl::OUString& rS( maAdjustmentValues[ j ].maName ); - if ( rS.getLength() > 3 ) + std::vector< CustomShapeGuide >::const_iterator aIter( maAdjustmentGuideList.begin() ); + while( aIter != maAdjustmentGuideList.end() ) { - sal_uInt32 nVal = rS.copy( 3 ).toInt32(); - if ( ( nVal < 10 ) && ( nVal > nHighest ) ) - nHighest = nVal; - } - } - if ( nHighest > static_cast< sal_uInt32 >( aAdjustmentSeq.getLength() ) ) - aAdjustmentSeq.realloc( nHighest ); - - for ( j = 0; j < maAdjustmentValues.size(); j++ ) - { - if( maAdjustmentValues[ j ].maName.getLength() > 3 ) - { - sal_uInt32 nVal = maAdjustmentValues[ j ].maName.copy( 3 ).toInt32(); - if ( nVal-- ) + if ( (*aIter).maName.getLength() > 3 ) { - double fNewAdj = getValue( maAdjustmentValues, nVal ); - aAdjustmentSeq[ nVal ].State = beans::PropertyState_DIRECT_VALUE; - aAdjustmentSeq[ nVal ].Value <<= fNewAdj; + sal_Int32 nAdjustmentIndex = (*aIter).maName.copy( 3 ).toInt32() - 1; + if ( ( nAdjustmentIndex >= 0 ) && ( nAdjustmentIndex < aAdjustmentSeq.getLength() ) ) + { + EnhancedCustomShapeAdjustmentValue aAdjustmentVal; + aAdjustmentVal.Value <<= (*aIter).maFormula.toInt32(); + aAdjustmentVal.State = PropertyState_DIRECT_VALUE; + aAdjustmentSeq[ nAdjustmentIndex ] = aAdjustmentVal; + } } + aIter++; } + aGeoPropSeq[ i ].Value <<= aAdjustmentSeq; + xPropSet->setPropertyValue( sCustomShapeGeometry, Any( aGeoPropSeq ) ); } - aGeoPropSeq[ i ].Value <<= aAdjustmentSeq; - xPropSet->setPropertyValue( sCustomShapeGeometry, Any( aGeoPropSeq ) ); } - } - else if ( aGeoPropSeq[ i ].Name.equals( sType ) ) - { - aGeoPropSeq[ i ].Value <<= maShapePresetType; + else if ( aGeoPropSeq[ i ].Name.equals( sType ) ) + { + aGeoPropSeq[ i ].Value <<= maShapePresetType; + } } } } } else { + sal_uInt32 i; PropertyMap aPropertyMap; aPropertyMap[ PROP_Type ] <<= CREATE_OUSTRING( "non-primitive" ); + awt::Size aSize( xShape->getSize() ); + awt::Rectangle aViewBox( 0, 0, aSize.Width * 360, aSize.Height * 360 ); + if ( maPath2DList.size() ) + { // TODO: each polygon may have its own size, but I think it is rather been used + // so we are only taking care of the first + if ( maPath2DList[ 0 ].w ) + aViewBox.Width = static_cast< sal_Int32 >( maPath2DList[ 0 ].w ); + if ( maPath2DList[ 0 ].h ) + aViewBox.Height = static_cast< sal_Int32 >( maPath2DList[ 0 ].h ); + } + aPropertyMap[ PROP_ViewBox ] <<= aViewBox; + + Sequence< EnhancedCustomShapeAdjustmentValue > aAdjustmentValues( maAdjustmentGuideList.size() ); + for ( i = 0; i < maAdjustmentGuideList.size(); i++ ) + { + EnhancedCustomShapeAdjustmentValue aAdjustmentVal; + aAdjustmentVal.Value <<= maAdjustmentGuideList[ i ].maFormula.toInt32(); + aAdjustmentVal.State = PropertyState_DIRECT_VALUE; + aAdjustmentValues[ i ] = aAdjustmentVal; + } + aPropertyMap[ PROP_AdjustmentValues ] <<= aAdjustmentValues; + + Sequence< rtl::OUString > aEquations( maGuideList.size() ); + for ( i = 0; i < maGuideList.size(); i++ ) + aEquations[ i ] = maGuideList[ i ].maFormula; + aPropertyMap[ PROP_Equations ] <<= aEquations; + + PropertyMap aPath; + Sequence< EnhancedCustomShapeSegment > aSegments( maSegments.size() ); + for ( i = 0; i < maSegments.size(); i++ ) + aSegments[ i ] = maSegments[ i ]; + aPath[ PROP_Segments ] <<= aSegments; + sal_uInt32 j, k, nParameterPairs = 0; + for ( i = 0; i < maPath2DList.size(); i++ ) + nParameterPairs += maPath2DList[ i ].parameter.size(); + Sequence< EnhancedCustomShapeParameterPair > aParameterPairs( nParameterPairs ); + for ( i = 0, k = 0; i < maPath2DList.size(); i++ ) + for ( j = 0; j < maPath2DList[ i ].parameter.size(); j++ ) + aParameterPairs[ k++ ] = maPath2DList[ i ].parameter[ j ]; + aPath[ PROP_Coordinates ] <<= aParameterPairs; + Sequence< PropertyValue > aPathSequence = aPath.makePropertyValueSequence(); + aPropertyMap[ PROP_Path ] <<= aPathSequence; + + Sequence< PropertyValues > aHandles( maAdjustHandleList.size() ); + for ( i = 0; i < maAdjustHandleList.size(); i++ ) + { + PropertyMap aHandle; + // maAdjustmentHandle[ i ].gdRef1 ... maAdjustmentHandle[ i ].gdRef2 ... :( + // gdRef1 && gdRef2 -> we do not offer such reference, so it is difficult + // to determine the correct adjustment handle that should be updated with the adjustment + // position. here is the solution: the adjustment value that is used within the position + // has to be updated, in case the position is a formula the first usage of a + // adjument value is decisive + if ( maAdjustHandleList[ i ].polar ) + { + aHandle[ PROP_Position ] <<= maAdjustHandleList[ i ].pos; + if ( maAdjustHandleList[ i ].min1.has() ) + aHandle[ PROP_RadiusRangeMinimum ] <<= maAdjustHandleList[ i ].min1.get(); + if ( maAdjustHandleList[ i ].max1.has() ) + aHandle[ PROP_RadiusRangeMaximum ] <<= maAdjustHandleList[ i ].max1.get(); + + /* TODO: AngleMin & AngleMax + if ( maAdjustHandleList[ i ].min2.has() ) + aHandle[ PROP_ ] = maAdjustHandleList[ i ].min2.get(); + if ( maAdjustHandleList[ i ].max2.has() ) + aHandle[ PROP_ ] = maAdjustHandleList[ i ].max2.get(); + */ + } + else + { + aHandle[ PROP_Position ] <<= maAdjustHandleList[ i ].pos; + if ( maAdjustHandleList[ i ].gdRef1.has() ) + { + // TODO: PROP_RefX and PROP_RefY are not yet part of our file format, + // so the handles will not work after save/reload + sal_Int32 nIndex = GetCustomShapeGuideValue( maAdjustmentGuideList, maAdjustHandleList[ i ].gdRef1.get() ); + if ( nIndex >= 0 ) + aHandle[ PROP_RefX ] <<= nIndex; + } + if ( maAdjustHandleList[ i ].gdRef2.has() ) + { + sal_Int32 nIndex = GetCustomShapeGuideValue( maAdjustmentGuideList, maAdjustHandleList[ i ].gdRef2.get() ); + if ( nIndex >= 0 ) + aHandle[ PROP_RefY ] <<= nIndex; + } + if ( maAdjustHandleList[ i ].min1.has() ) + aHandle[ PROP_RangeXMinimum ] <<= maAdjustHandleList[ i ].min1.get(); + if ( maAdjustHandleList[ i ].max1.has() ) + aHandle[ PROP_RangeXMaximum ] <<= maAdjustHandleList[ i ].max1.get(); + if ( maAdjustHandleList[ i ].min2.has() ) + aHandle[ PROP_RangeYMinimum ] <<= maAdjustHandleList[ i ].min2.get(); + if ( maAdjustHandleList[ i ].max2.has() ) + aHandle[ PROP_RangeYMaximum ] <<= maAdjustHandleList[ i ].max2.get(); + } + aHandles[ i ] = aHandle.makePropertyValueSequence(); + } + aPropertyMap[ PROP_Handles ] <<= aHandles; + // converting the vector to a sequence Sequence< PropertyValue > aSeq = aPropertyMap.makePropertyValueSequence(); PropertySet aPropSet( xPropSet ); diff --git a/oox/source/drawingml/shape.cxx b/oox/source/drawingml/shape.cxx index 1a32d6a206a0..50ded9b2753b 100644 --- a/oox/source/drawingml/shape.cxx +++ b/oox/source/drawingml/shape.cxx @@ -95,6 +95,7 @@ Shape::Shape( const sal_Char* pServiceName ) , mnRotation( 0 ) , mbFlipH( false ) , mbFlipV( false ) +, mbHidden( false ) { if ( pServiceName ) msServiceName = OUString::createFromAscii( pServiceName ); @@ -183,6 +184,7 @@ void Shape::applyShapeReference( const Shape& rReferencedShape ) mnRotation = rReferencedShape.mnRotation; mbFlipH = rReferencedShape.mbFlipH; mbFlipV = rReferencedShape.mbFlipV; + mbHidden = rReferencedShape.mbHidden; } // for group shapes, the following method is also adding each child @@ -299,35 +301,6 @@ Reference< XShape > Shape::createAndInsert( aTransformation.translate( aPosition.X / 360.0, aPosition.Y / 360.0 ); } - if ( mpCustomShapePropertiesPtr && mpCustomShapePropertiesPtr->getPolygon().count() ) - { - ::basegfx::B2DPolyPolygon& rPolyPoly = mpCustomShapePropertiesPtr->getPolygon(); - - if( rPolyPoly.count() > 0 ) { - if( rPolyPoly.areControlPointsUsed() ) { - // TODO Beziers - } else { - uno::Sequence< uno::Sequence< awt::Point > > aPolyPolySequence( rPolyPoly.count() ); - - for (sal_uInt32 j = 0; j < rPolyPoly.count(); j++ ) { - ::basegfx::B2DPolygon aPoly = rPolyPoly.getB2DPolygon( j ); - - // now creating the corresponding PolyPolygon - sal_Int32 i, nNumPoints = aPoly.count(); - uno::Sequence< awt::Point > aPointSequence( nNumPoints ); - awt::Point* pPoints = aPointSequence.getArray(); - for( i = 0; i < nNumPoints; ++i ) - { - const ::basegfx::B2DPoint aPoint( aPoly.getB2DPoint( i ) ); - pPoints[ i ] = awt::Point( static_cast< sal_Int32 >( aPoint.getX() ), static_cast< sal_Int32 >( aPoint.getY() ) ); - } - aPolyPolySequence.getArray()[ j ] = aPointSequence; - } - maShapeProperties[ PROP_PolyPolygon ] <<= aPolyPolySequence; - } - } - } - // special for lineshape if ( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.LineShape" ) ) { @@ -399,6 +372,12 @@ Reference< XShape > Shape::createAndInsert( } rxShapes->add( mxShape ); + if ( mbHidden ) + { + const OUString sHidden( CREATE_OUSTRING( "NumberingLevel" ) ); + xSet->setPropertyValue( sHidden, Any( mbHidden ) ); + } + Reference< document::XActionLockable > xLockable( mxShape, UNO_QUERY ); if( xLockable.is() ) xLockable->addActionLock(); @@ -491,7 +470,7 @@ Reference< XShape > Shape::createAndInsert( aPropSet.setProperties( aShapeProperties ); if( aServiceName == OUString::createFromAscii( "com.sun.star.drawing.CustomShape" ) ) - mpCustomShapePropertiesPtr->pushToPropSet( xSet, mxShape ); + mpCustomShapePropertiesPtr->pushToPropSet( rFilterBase, xSet, mxShape ); // in some cases, we don't have any text body. if( getTextBody() ) diff --git a/oox/source/drawingml/shapecontext.cxx b/oox/source/drawingml/shapecontext.cxx index a5a1f16f5935..a5f3b1598447 100644 --- a/oox/source/drawingml/shapecontext.cxx +++ b/oox/source/drawingml/shapecontext.cxx @@ -31,6 +31,7 @@ #include <com/sun/star/lang/XMultiServiceFactory.hpp> #include <com/sun/star/container/XNamed.hpp> +#include "oox/helper/attributelist.hxx" #include "oox/drawingml/shapecontext.hxx" #include "oox/drawingml/shapestylecontext.hxx" #include "oox/core/namespaces.hxx" @@ -85,9 +86,13 @@ Reference< XFastContextHandler > ShapeContext::createFastChildContext( sal_Int32 // case XML_drElemPr: // break; case XML_cNvPr: + { + AttributeList aAttribs( xAttribs ); + mpShapePtr->setHidden( aAttribs.getBool( XML_hidden, false ) ); mpShapePtr->setId( xAttribs->getOptionalValue( XML_id ) ); mpShapePtr->setName( xAttribs->getOptionalValue( XML_name ) ); break; + } case XML_ph: mpShapePtr->setSubType( xAttribs->getOptionalValueToken( XML_type, XML_obj ) ); mpShapePtr->setSubTypeIndex( xAttribs->getOptionalValue( XML_idx ).toInt32() ); diff --git a/oox/source/drawingml/shapepropertiescontext.cxx b/oox/source/drawingml/shapepropertiescontext.cxx index 7724ba9b44b2..dd1814ac23cf 100644 --- a/oox/source/drawingml/shapepropertiescontext.cxx +++ b/oox/source/drawingml/shapepropertiescontext.cxx @@ -74,7 +74,7 @@ Reference< XFastContextHandler > ShapePropertiesContext::createFastChildContext( // GeometryGroup case NMSP_DRAWINGML|XML_custGeom: // custom geometry "CT_CustomGeometry2D" - xRet.set( new CustomShapeGeometryContext( *this, xAttribs, mrShape ) ); + xRet.set( new CustomShapeGeometryContext( *this, xAttribs, *(mrShape.getCustomShapeProperties()) ) ); break; diff --git a/oox/source/token/properties.txt b/oox/source/token/properties.txt index 56606a289a6e..eae0fb154afc 100644 --- a/oox/source/token/properties.txt +++ b/oox/source/token/properties.txt @@ -5,6 +5,7 @@ ActiveTable Adjust AdjustContrast AdjustLuminance +AdjustmentValues Align AnchorPosition ArrangeOrder @@ -83,6 +84,7 @@ CompileEnglish ConditionalFormat ConnectBars ContainsHeader +Coordinates CopyBack CopyFormulas CopyStyles @@ -117,6 +119,7 @@ EchoChar EnableVisible Enabled EndPosition +Equations ErrorAlertStyle ErrorBarStyle ErrorBarX @@ -168,6 +171,7 @@ GraphicURL GridColor GroupInfo HScroll +Handles HasAutoShowInfo HasColumnRowHeaders HasHorizontalScrollBar @@ -287,6 +291,7 @@ ParaLineSpacing ParaRightMargin ParaTabStops ParaTopMargin +Path PercentageNumberFormat PersistName Perspective @@ -309,6 +314,16 @@ Printable ProgressValueMax ProgressValueMin Protected +RadiusRangeMaximum +RadiusRangeMinimum +RangeXMaximum +RangeXMinimum +RangeYMaximum +RangeYMinimum +RefAngle +RefR +RefX +RefY Reference ReferenceDevice RegularExpressions @@ -337,6 +352,7 @@ ScaleToPagesY ScrollValue ScrollValueMax ScrollValueMin +Segments SelectedPage Show ShowBorder @@ -427,6 +443,7 @@ VertJustify VerticalAlign VerticalSplitMode VerticalSplitPositionTwips +ViewBox Visible VisibleSize VisualArea diff --git a/oox/source/token/tokens.txt b/oox/source/token/tokens.txt index 4bf407747d95..b05a21152722 100644 --- a/oox/source/token/tokens.txt +++ b/oox/source/token/tokens.txt @@ -13,6 +13,10 @@ 3Symbols2 3TrafficLights1 3TrafficLights2 +3cd4 +3cd8 +5cd8 +7cd8 3dDkShadow 3dLight 4Arrows @@ -1045,6 +1049,9 @@ categoryIdx ccw ccwIn ccwOut +cd2 +cd4 +cd8 cell cell3D cellColor @@ -2495,6 +2502,12 @@ harsh hasCustomPrompt hash hashData +hc +hd2 +hd4 +hd5 +hd6 +hd8 hdr hdrShapeDefaults hdrs @@ -3077,6 +3090,7 @@ lpstr lpwstr lrTb lrTbV +ls lsdException lstStyle lt @@ -4730,6 +4744,11 @@ srcNode srcOrd srcRect srgbClr +ss +ssd2 +ssd4 +ssd6 +ssd8 sst st stA @@ -5434,6 +5453,7 @@ variant varp varyColors vbProcedure +vc vector vendorID venn @@ -5498,6 +5518,12 @@ wavyDbl wavyDouble wavyHeavy wd +wd10 +wd2 +wd4 +wd5 +wd6 +wd8 wdDnDiag wdUpDiag weave |