1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofsdrobjcustomshape.cxx,v $
10 * $Revision: 1.7.18.1 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
33 #include <svx/sdr/contact/viewcontactofsdrobjcustomshape.hxx>
34 #include <svx/svdoashp.hxx>
35 #include <svx/sdr/contact/displayinfo.hxx>
36 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
37 #include <svx/sdr/attribute/sdrallattribute.hxx>
38 #include <svditer.hxx>
39 #include <svx/sdr/primitive2d/sdrcustomshapeprimitive2d.hxx>
40 #include <basegfx/polygon/b2dpolygontools.hxx>
41 #include <basegfx/polygon/b2dpolygon.hxx>
43 //////////////////////////////////////////////////////////////////////////////
49 ViewContactOfSdrObjCustomShape::ViewContactOfSdrObjCustomShape(SdrObjCustomShape
& rCustomShape
)
50 : ViewContactOfTextObj(rCustomShape
)
54 ViewContactOfSdrObjCustomShape::~ViewContactOfSdrObjCustomShape()
58 basegfx::B2DRange
ViewContactOfSdrObjCustomShape::getCorrectedTextBoundRect() const
60 const Rectangle
aObjectBound(GetCustomShapeObj().GetGeoRect());
61 Rectangle
aTextBound(aObjectBound
);
62 GetCustomShapeObj().GetTextBounds(aTextBound
);
63 basegfx::B2DRange
aTextRange(aTextBound
.Left(), aTextBound
.Top(), aTextBound
.Right(), aTextBound
.Bottom());
64 const basegfx::B2DRange
aObjectRange(aObjectBound
.Left(), aObjectBound
.Top(), aObjectBound
.Right(), aObjectBound
.Bottom());
66 // no need to correct if no extra text range
67 if(aTextRange
!= aObjectRange
)
69 const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
70 const GeoStat
& rGeoStat(GetCustomShapeObj().GetGeoStat());
72 // only correct when rotation and/or shear is used
73 if(rGeoStat
.nShearWink
|| rGeoStat
.nDrehWink
|| !basegfx::fTools::equalZero(fExtraTextRotation
))
75 // text range needs to be corrected by
76 // aObjectRange.getCenter() - aRotObjectRange.getCenter() since it's
77 // defined differenly by using rotation around object center. Start
79 basegfx::B2DVector
aTranslation(aObjectRange
.getCenter());
81 // get rotated and sheared object's range
82 basegfx::B2DRange
aRotObjectRange(aObjectRange
);
83 basegfx::B2DHomMatrix aRotMatrix
;
85 aRotMatrix
.translate(-aObjectRange
.getMinimum().getX(), -aObjectRange
.getMinimum().getY());
87 if(rGeoStat
.nShearWink
)
89 aRotMatrix
.shearX(tan((36000 - rGeoStat
.nShearWink
) * F_PI18000
));
92 if(rGeoStat
.nDrehWink
)
94 aRotMatrix
.rotate((36000 - rGeoStat
.nDrehWink
) * F_PI18000
);
97 if(!basegfx::fTools::equalZero(fExtraTextRotation
))
99 aRotMatrix
.rotate((360.0 - fExtraTextRotation
) * F_PI180
);
102 aRotMatrix
.translate(aObjectRange
.getMinimum().getX(), aObjectRange
.getMinimum().getY());
103 aRotObjectRange
.transform(aRotMatrix
);
105 // add negative translation part
106 aTranslation
-= aRotObjectRange
.getCenter();
109 aTextRange
= basegfx::B2DRange(
110 aTextRange
.getMinX() + aTranslation
.getX(), aTextRange
.getMinY() + aTranslation
.getY(),
111 aTextRange
.getMaxX() + aTranslation
.getX(), aTextRange
.getMaxY() + aTranslation
.getY());
118 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence() const
120 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
121 const SfxItemSet
& rItemSet
= GetCustomShapeObj().GetMergedItemSet();
122 SdrText
* pSdrText
= GetCustomShapeObj().getText(0);
126 // #i98072# Get shandow and text; eventually suppress the text if it's
127 // a TextPath FontworkGallery object
128 drawinglayer::attribute::SdrShadowTextAttribute
* pAttribute
= drawinglayer::primitive2d::createNewSdrShadowTextAttribute(
131 GetCustomShapeObj().IsTextPath());
132 drawinglayer::primitive2d::Primitive2DSequence xGroup
;
133 bool bHasText(pAttribute
&& pAttribute
->getText());
135 // create Primitive2DSequence from sub-geometry
136 const SdrObject
* pSdrObjRepresentation
= GetCustomShapeObj().GetSdrObjectFromCustomShape();
138 if(pSdrObjRepresentation
)
140 SdrObjListIter
aIterator(*pSdrObjRepresentation
);
142 while(aIterator
.IsMore())
144 SdrObject
& rCandidate
= *aIterator
.Next();
145 const drawinglayer::primitive2d::Primitive2DSequence
xNew(rCandidate
.GetViewContact().getViewIndependentPrimitive2DSequence());
146 drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xGroup
, xNew
);
150 if(bHasText
|| xGroup
.hasElements())
152 // prepare text box geometry
153 basegfx::B2DHomMatrix aTextBoxMatrix
;
154 bool bWordWrap(false);
158 // take unrotated snap rect as default, then get the
159 // unrotated text box. Rotation needs to be done centered
160 const Rectangle
aObjectBound(GetCustomShapeObj().GetGeoRect());
161 const basegfx::B2DRange
aObjectRange(aObjectBound
.Left(), aObjectBound
.Top(), aObjectBound
.Right(), aObjectBound
.Bottom());
163 // #i101684# get the text range unrotated and absolute to the object range
164 const basegfx::B2DRange
aTextRange(getCorrectedTextBoundRect());
166 // give text object a size
167 aTextBoxMatrix
.scale(aTextRange
.getWidth(), aTextRange
.getHeight());
169 // check if we have a rotation/shear at all to take care of
170 const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
171 const GeoStat
& rGeoStat(GetCustomShapeObj().GetGeoStat());
173 if(rGeoStat
.nShearWink
|| rGeoStat
.nDrehWink
|| !basegfx::fTools::equalZero(fExtraTextRotation
))
175 if(aObjectRange
!= aTextRange
)
177 // move relative to unrotated object range
178 aTextBoxMatrix
.translate(
179 aTextRange
.getMinX() - aObjectRange
.getMinimum().getX(),
180 aTextRange
.getMinY() - aObjectRange
.getMinimum().getY());
183 if(rGeoStat
.nShearWink
)
185 aTextBoxMatrix
.shearX(tan((36000 - rGeoStat
.nShearWink
) * F_PI18000
));
188 if(rGeoStat
.nDrehWink
)
190 aTextBoxMatrix
.rotate((36000 - rGeoStat
.nDrehWink
) * F_PI18000
);
193 if(!basegfx::fTools::equalZero(fExtraTextRotation
))
195 aTextBoxMatrix
.rotate((360.0 - fExtraTextRotation
) * F_PI180
);
198 // give text it's target position
199 aTextBoxMatrix
.translate(aObjectRange
.getMinimum().getX(), aObjectRange
.getMinimum().getY());
203 aTextBoxMatrix
.translate(aTextRange
.getMinX(), aTextRange
.getMinY());
206 // check if SdrTextWordWrapItem is set
207 bWordWrap
= ((SdrTextWordWrapItem
&)(GetCustomShapeObj().GetMergedItem(SDRATTR_TEXT_WORDWRAP
))).GetValue();
210 // make sure a (even empty) SdrShadowTextAttribute exists for
211 // primitive creation
214 pAttribute
= new drawinglayer::attribute::SdrShadowTextAttribute(0L, 0L);
218 const drawinglayer::primitive2d::Primitive2DReference
xReference(new drawinglayer::primitive2d::SdrCustomShapePrimitive2D(
223 false)); // #SJ# New parameter to force to clipped BlockText for SC
224 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xReference
, 1);
235 } // end of namespace contact
236 } // end of namespace sdr
238 //////////////////////////////////////////////////////////////////////////////