1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ 2 /* 3 * This file is part of the LibreOffice project. 4 * 5 * This Source Code Form is subject to the terms of the Mozilla Public 6 * License, v. 2.0. If a copy of the MPL was not distributed with this 7 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 8 * 9 * This file incorporates work covered by the following license notice: 10 * 11 * Licensed to the Apache Software Foundation (ASF) under one or more 12 * contributor license agreements. See the NOTICE file distributed 13 * with this work for additional information regarding copyright 14 * ownership. The ASF licenses this file to you under the Apache 15 * License, Version 2.0 (the "License"); you may not use this file 16 * except in compliance with the License. You may obtain a copy of 17 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 18 */ 19 20 #ifndef INCLUDED_SVX_ENHANCEDCUSTOMSHAPE2D_HXX 21 #define INCLUDED_SVX_ENHANCEDCUSTOMSHAPE2D_HXX 22 23 #include <svx/msdffdef.hxx> 24 #include <svx/sdasitm.hxx> 25 #include <com/sun/star/awt/Size.hpp> 26 #include <com/sun/star/uno/Sequence.h> 27 #include <com/sun/star/beans/PropertyValues.hpp> 28 #include <svl/itemset.hxx> 29 #include <com/sun/star/drawing/EnhancedCustomShapeParameterPair.hpp> 30 #include <com/sun/star/drawing/EnhancedCustomShapeSegment.hpp> 31 #include <com/sun/star/drawing/EnhancedCustomShapeParameter.hpp> 32 #include <com/sun/star/drawing/EnhancedCustomShapeTextFrame.hpp> 33 #include <com/sun/star/drawing/EnhancedCustomShapeAdjustmentValue.hpp> 34 35 #include <svx/EnhancedCustomShapeFunctionParser.hxx> 36 #include <tools/gen.hxx> 37 #include <o3tl/typed_flags_set.hxx> 38 #include <basegfx/point/b2dpoint.hxx> 39 40 #include <memory> 41 #include <vector> 42 43 namespace com::sun::star::awt { struct Point; } 44 45 class Color; 46 class SdrObject; 47 class SdrPathObj; 48 class SdrObjCustomShape; 49 50 enum class HandleFlags 51 { 52 NONE = 0x0000, 53 MIRRORED_X = 0x0001, 54 MIRRORED_Y = 0x0002, 55 SWITCHED = 0x0004, 56 POLAR = 0x0008, 57 RANGE_X_MINIMUM = 0x0020, 58 RANGE_X_MAXIMUM = 0x0040, 59 RANGE_Y_MINIMUM = 0x0080, 60 RANGE_Y_MAXIMUM = 0x0100, 61 RADIUS_RANGE_MINIMUM = 0x0200, 62 RADIUS_RANGE_MAXIMUM = 0x0400, 63 REFX = 0x0800, 64 REFY = 0x1000, 65 REFANGLE = 0x2000, 66 REFR = 0x4000, 67 }; 68 namespace o3tl 69 { 70 template<> struct typed_flags<HandleFlags> : is_typed_flags<HandleFlags, 0x7fef> {}; 71 } 72 73 // MSDFF_HANDLE_FLAGS_RANGE_Y seems to be not defined in 74 // escher, but we are using it internally in to differentiate 75 // between X_RANGE and Y_RANGE 76 77 class SVX_DLLPUBLIC EnhancedCustomShape2d : public SfxItemSet 78 { 79 SdrObjCustomShape& mrSdrObjCustomShape; 80 MSO_SPT eSpType; 81 82 sal_Int32 nCoordLeft; 83 sal_Int32 nCoordTop; 84 sal_Int32 nCoordWidthG; 85 sal_Int32 nCoordHeightG; 86 sal_Int32 nCoordWidth; 87 sal_Int32 nCoordHeight; 88 tools::Rectangle aLogicRect; 89 90 double fXScale; 91 double fYScale; 92 double fXRatio; 93 double fYRatio; 94 95 bool bOOXMLShape; 96 97 sal_Int32 nXRef; 98 sal_Int32 nYRef; 99 sal_uInt32 nColorData; 100 101 /* 102 103 */ 104 struct SAL_DLLPRIVATE EquationResult { 105 bool bReady; 106 double fValue; 107 }; 108 css::uno::Sequence< OUString > seqEquations; 109 std::vector< std::shared_ptr< EnhancedCustomShape::ExpressionNode > > vNodesSharedPtr; 110 std::vector< EquationResult > vEquationResults; 111 112 css::uno::Sequence< css::drawing::EnhancedCustomShapeSegment > seqSegments; 113 css::uno::Sequence< css::drawing::EnhancedCustomShapeParameterPair> seqCoordinates; 114 css::uno::Sequence< css::drawing::EnhancedCustomShapeTextFrame > seqTextFrames; 115 css::uno::Sequence< css::drawing::EnhancedCustomShapeParameterPair> seqGluePoints; 116 css::uno::Sequence< css::drawing::EnhancedCustomShapeAdjustmentValue > seqAdjustmentValues; 117 css::uno::Sequence< css::beans::PropertyValues > seqHandles; 118 css::uno::Sequence< css::awt::Size > seqSubViewSize; 119 120 bool const bFilled : 1; 121 bool const bStroked : 1; 122 123 bool bFlipH; 124 bool bFlipV; 125 sal_Int32 nRotateAngle; 126 127 SAL_DLLPRIVATE bool SetAdjustValueAsDouble( const double& rValue, const sal_Int32 nIndex ); 128 SAL_DLLPRIVATE sal_Int32 GetLuminanceChange( sal_uInt32 nIndex ) const; 129 SAL_DLLPRIVATE Color GetColorData( const Color& rFillColor, sal_uInt32 nIndex, double dBrightness ) const; 130 SAL_DLLPRIVATE void AdaptObjColor( 131 SdrPathObj& rObj, 132 double dBrightness, 133 const SfxItemSet& rCustomShapeSet, 134 sal_uInt32& nColorIndex, 135 sal_uInt32 nColorCount); 136 SAL_DLLPRIVATE Point GetPoint( const css::drawing::EnhancedCustomShapeParameterPair&, 137 const bool bScale = true, const bool bReplaceGeoSize = false ) const; 138 SAL_DLLPRIVATE basegfx::B2DPoint GetPointAsB2DPoint(const css::drawing::EnhancedCustomShapeParameterPair&, 139 const bool bScale = true, const bool bReplaceGeoSize = false ) const; 140 141 SAL_DLLPRIVATE void CreateSubPath( 142 sal_Int32& rSrcPt, 143 sal_Int32& rSegmentInd, 144 std::vector< std::pair< SdrPathObj*, double> >& rObjectList, 145 bool bLineGeometryNeededOnly, 146 bool bSortFilledObjectsToBack, 147 sal_Int32 nIndex); 148 SAL_DLLPRIVATE SdrObject* CreatePathObj( bool bLineGeometryNeededOnly ); 149 SAL_DLLPRIVATE void ApplyShapeAttributes( const SdrCustomShapeGeometryItem& rItem ); 150 151 SAL_DLLPRIVATE void SetPathSize( sal_Int32 nIndex = 0 ); 152 153 public: 154 155 struct SAL_DLLPRIVATE Handle 156 { 157 HandleFlags nFlags; 158 159 css::drawing::EnhancedCustomShapeParameterPair aPosition; 160 css::drawing::EnhancedCustomShapeParameterPair aPolar; 161 162 sal_Int32 nRefX; 163 sal_Int32 nRefY; 164 sal_Int32 nRefAngle; 165 sal_Int32 nRefR; 166 167 css::drawing::EnhancedCustomShapeParameter aRadiusRangeMinimum; 168 css::drawing::EnhancedCustomShapeParameter aRadiusRangeMaximum; 169 css::drawing::EnhancedCustomShapeParameter aXRangeMinimum; 170 css::drawing::EnhancedCustomShapeParameter aXRangeMaximum; 171 css::drawing::EnhancedCustomShapeParameter aYRangeMinimum; 172 css::drawing::EnhancedCustomShapeParameter aYRangeMaximum; 173 HandleEnhancedCustomShape2d::Handle174 Handle() 175 : nFlags(HandleFlags::NONE) 176 , nRefX( -1 ) 177 , nRefY( -1 ) 178 , nRefAngle( -1 ) 179 , nRefR( -1 ) 180 { 181 } 182 }; 183 IsFlipVert() const184 SAL_DLLPRIVATE bool IsFlipVert() const { return bFlipV; }; IsFlipHorz() const185 SAL_DLLPRIVATE bool IsFlipHorz() const { return bFlipH; }; GetRotateAngle() const186 SAL_DLLPRIVATE sal_Int32 GetRotateAngle() const { return nRotateAngle; }; 187 188 SdrObject* CreateLineGeometry(); 189 SdrObject* CreateObject( bool bLineGeometryNeededOnly ); 190 void ApplyGluePoints( SdrObject* pObj ); 191 tools::Rectangle GetTextRect() const; GetLogicRect() const192 const tools::Rectangle& GetLogicRect() const { return aLogicRect; } 193 194 sal_uInt32 GetHdlCount() const; 195 bool GetHandlePosition( const sal_uInt32 nIndex, Point& rReturnPosition ) const; 196 bool SetHandleControllerPosition( const sal_uInt32 nIndex, const css::awt::Point& rPosition ); 197 198 EnhancedCustomShape2d(SdrObjCustomShape& rSdrObjCustomShape); 199 virtual ~EnhancedCustomShape2d() override; 200 201 SAL_DLLPRIVATE double GetEnumFunc( const EnhancedCustomShape::ExpressionFunct eVal ) const; 202 203 void GetParameter( double& rParameterReturnValue, const css::drawing::EnhancedCustomShapeParameter&, 204 const bool bReplaceGeoWidth, const bool bReplaceGeoHeight ) const; 205 SAL_DLLPRIVATE double GetAdjustValueAsDouble( const sal_Int32 nIndex ) const; 206 SAL_DLLPRIVATE double GetEquationValueAsDouble( const sal_Int32 nIndex ) const; 207 208 static OUString GetEquation( const sal_uInt16 nFlags, sal_Int32 nPara1, sal_Int32 nPara2, sal_Int32 nPara3 ); 209 210 SAL_DLLPRIVATE static void AppendEnhancedCustomShapeEquationParameter( OUString& rParameter, const sal_Int32 nPara, const bool bIsSpecialValue ); 211 212 static void SetEnhancedCustomShapeParameter( css::drawing::EnhancedCustomShapeParameter& 213 rParameter, const sal_Int32 nValue ); 214 static void SetEnhancedCustomShapeHandleParameter( css::drawing::EnhancedCustomShapeParameter& 215 rParameter, const sal_Int32 nPara, const bool bIsSpecialValue, bool bHorz ); 216 SAL_DLLPRIVATE static bool ConvertSequenceToEnhancedCustomShape2dHandle( const css::beans::PropertyValues& rHandleProperties, 217 EnhancedCustomShape2d::Handle& rDestinationHandle ); 218 SAL_DLLPRIVATE static void SwapStartAndEndArrow( SdrObject* pObj ); 219 }; 220 #endif 221 222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ 223