1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <svx/sdr/contact/viewcontactofsdrobjcustomshape.hxx>
21 #include <svx/svdoashp.hxx>
22 #include <svx/sdr/contact/displayinfo.hxx>
23 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
24 #include <svx/svditer.hxx>
25 #include <svx/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx>
26 #include <basegfx/polygon/b2dpolygontools.hxx>
27 #include <basegfx/polygon/b2dpolygon.hxx>
28 #include <basegfx/matrix/b2dhommatrixtools.hxx>
29 #include <svx/obj3d.hxx>
30 #include <drawinglayer/primitive2d/sdrdecompositiontools2d.hxx>
32 //////////////////////////////////////////////////////////////////////////////
38 ViewContactOfSdrObjCustomShape::ViewContactOfSdrObjCustomShape(SdrObjCustomShape
& rCustomShape
)
39 : ViewContactOfTextObj(rCustomShape
)
43 ViewContactOfSdrObjCustomShape::~ViewContactOfSdrObjCustomShape()
47 basegfx::B2DRange
ViewContactOfSdrObjCustomShape::getCorrectedTextBoundRect() const
49 Rectangle
aObjectBound(GetCustomShapeObj().GetGeoRect());
50 aObjectBound
+= GetCustomShapeObj().GetGridOffset();
51 Rectangle
aTextBound(aObjectBound
);
52 GetCustomShapeObj().GetTextBounds(aTextBound
);
53 aTextBound
+= GetCustomShapeObj().GetGridOffset();
54 basegfx::B2DRange
aTextRange(aTextBound
.Left(), aTextBound
.Top(), aTextBound
.Right(), aTextBound
.Bottom());
55 const basegfx::B2DRange
aObjectRange(aObjectBound
.Left(), aObjectBound
.Top(), aObjectBound
.Right(), aObjectBound
.Bottom());
57 // no need to correct if no extra text range
58 if(aTextRange
!= aObjectRange
)
60 const GeoStat
& rGeoStat(GetCustomShapeObj().GetGeoStat());
62 // only correct when rotation and/or shear is used
63 if(rGeoStat
.nShearWink
|| rGeoStat
.nDrehWink
)
65 // text range needs to be corrected by
66 // aObjectRange.getCenter() - aRotObjectRange.getCenter() since it's
67 // defined differenly by using rotation around object center. Start
69 basegfx::B2DVector
aTranslation(aObjectRange
.getCenter());
71 // get rotated and sheared object's range
72 basegfx::B2DRange
aRotObjectRange(aObjectRange
);
73 basegfx::B2DHomMatrix aRotMatrix
;
75 aRotMatrix
.translate(-aObjectRange
.getMinimum().getX(), -aObjectRange
.getMinimum().getY());
77 if(rGeoStat
.nShearWink
)
79 aRotMatrix
.shearX(tan((36000 - rGeoStat
.nShearWink
) * F_PI18000
));
82 if(rGeoStat
.nDrehWink
)
84 aRotMatrix
.rotate((36000 - rGeoStat
.nDrehWink
) * F_PI18000
);
87 aRotMatrix
.translate(aObjectRange
.getMinimum().getX(), aObjectRange
.getMinimum().getY());
88 aRotObjectRange
.transform(aRotMatrix
);
90 // add negative translation part
91 aTranslation
-= aRotObjectRange
.getCenter();
94 aTextRange
= basegfx::B2DRange(
95 aTextRange
.getMinX() + aTranslation
.getX(), aTextRange
.getMinY() + aTranslation
.getY(),
96 aTextRange
.getMaxX() + aTranslation
.getX(), aTextRange
.getMaxY() + aTranslation
.getY());
103 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence() const
105 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
106 const SfxItemSet
& rItemSet
= GetCustomShapeObj().GetMergedItemSet();
108 // #i98072# Get shandow and text; eventually suppress the text if it's
109 // a TextPath FontworkGallery object
110 const drawinglayer::attribute::SdrShadowTextAttribute
aAttribute(
111 drawinglayer::primitive2d::createNewSdrShadowTextAttribute(
113 GetCustomShapeObj().getText(0),
114 GetCustomShapeObj().IsTextPath()));
115 drawinglayer::primitive2d::Primitive2DSequence xGroup
;
116 bool bHasText(!aAttribute
.getText().isDefault());
118 // create Primitive2DSequence from sub-geometry
119 const SdrObject
* pSdrObjRepresentation
= GetCustomShapeObj().GetSdrObjectFromCustomShape();
120 bool b3DShape(false);
122 Point aGridOff
= GetCustomShapeObj().GetGridOffset();
124 if(pSdrObjRepresentation
)
126 // Hack for calc, transform position of object according
127 // to current zoom so as objects relative position to grid
129 const_cast< SdrObject
* >( pSdrObjRepresentation
)->SetGridOffset( aGridOff
);
130 SdrObjListIter
aIterator(*pSdrObjRepresentation
);
132 while(aIterator
.IsMore())
134 SdrObject
& rCandidate
= *aIterator
.Next();
135 // apply offset to each part
136 rCandidate
.SetGridOffset( aGridOff
);
137 if(!b3DShape
&& dynamic_cast< E3dObject
* >(&rCandidate
))
142 const drawinglayer::primitive2d::Primitive2DSequence
xNew(rCandidate
.GetViewContact().getViewIndependentPrimitive2DSequence());
143 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xGroup
, xNew
);
147 if(bHasText
|| xGroup
.hasElements())
149 // prepare text box geometry
150 basegfx::B2DHomMatrix aTextBoxMatrix
;
151 bool bWordWrap(false);
155 // take unrotated snap rect as default, then get the
156 // unrotated text box. Rotation needs to be done centered
157 Rectangle
aObjectBound(GetCustomShapeObj().GetGeoRect());
158 // hack for calc grid sync
159 aObjectBound
+= GetCustomShapeObj().GetGridOffset();
160 const basegfx::B2DRange
aObjectRange(aObjectBound
.Left(), aObjectBound
.Top(), aObjectBound
.Right(), aObjectBound
.Bottom());
162 // #i101684# get the text range unrotated and absolute to the object range
163 const basegfx::B2DRange
aTextRange(getCorrectedTextBoundRect());
165 // Rotation before scaling
166 if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)))
168 basegfx::B2DVector
aTranslation(0.5, 0.5);
169 aTextBoxMatrix
.translate( -aTranslation
.getX(), -aTranslation
.getY() );
170 aTextBoxMatrix
.rotate((360.0 - GetCustomShapeObj().GetExtraTextRotation(true)) * F_PI180
);
171 aTextBoxMatrix
.translate( aTranslation
.getX(), aTranslation
.getY() );
173 // give text object a size
174 aTextBoxMatrix
.scale(aTextRange
.getWidth(), aTextRange
.getHeight());
176 // check if we have a rotation/shear at all to take care of
177 const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
178 const GeoStat
& rGeoStat(GetCustomShapeObj().GetGeoStat());
180 if(rGeoStat
.nShearWink
|| rGeoStat
.nDrehWink
|| !basegfx::fTools::equalZero(fExtraTextRotation
))
182 if(aObjectRange
!= aTextRange
)
184 // move relative to unrotated object range
185 aTextBoxMatrix
.translate(
186 aTextRange
.getMinX() - aObjectRange
.getMinimum().getX(),
187 aTextRange
.getMinY() - aObjectRange
.getMinimum().getY());
190 if(!basegfx::fTools::equalZero(fExtraTextRotation
))
192 basegfx::B2DVector
aTranslation(
193 ( aTextRange
.getWidth() / 2 ) + ( aTextRange
.getMinX() - aObjectRange
.getMinimum().getX() ),
194 ( aTextRange
.getHeight() / 2 ) + ( aTextRange
.getMinY() - aObjectRange
.getMinimum().getY() ) );
195 aTextBoxMatrix
.translate( -aTranslation
.getX(), -aTranslation
.getY() );
196 aTextBoxMatrix
.rotate((360.0 - fExtraTextRotation
) * F_PI180
);
197 aTextBoxMatrix
.translate( aTranslation
.getX(), aTranslation
.getY() );
200 if(rGeoStat
.nShearWink
)
202 aTextBoxMatrix
.shearX(tan((36000 - rGeoStat
.nShearWink
) * F_PI18000
));
205 if(rGeoStat
.nDrehWink
)
207 aTextBoxMatrix
.rotate((36000 - rGeoStat
.nDrehWink
) * F_PI18000
);
210 // give text it's target position
211 aTextBoxMatrix
.translate(aObjectRange
.getMinimum().getX(), aObjectRange
.getMinimum().getY());
215 aTextBoxMatrix
.translate(aTextRange
.getMinX(), aTextRange
.getMinY());
218 // check if SdrTextWordWrapItem is set
219 bWordWrap
= ((SdrTextWordWrapItem
&)(GetCustomShapeObj().GetMergedItem(SDRATTR_TEXT_WORDWRAP
))).GetValue();
223 const drawinglayer::primitive2d::Primitive2DReference
xReference(
224 new drawinglayer::primitive2d::SdrCustomShapePrimitive2D(
230 false)); // #SJ# New parameter to force to clipped BlockText for SC
231 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xReference
, 1);
236 } // end of namespace contact
237 } // end of namespace sdr
239 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */