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 <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 <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>
37 ViewContactOfSdrObjCustomShape::ViewContactOfSdrObjCustomShape(SdrObjCustomShape
& rCustomShape
)
38 : ViewContactOfTextObj(rCustomShape
)
42 ViewContactOfSdrObjCustomShape::~ViewContactOfSdrObjCustomShape()
46 basegfx::B2DRange
ViewContactOfSdrObjCustomShape::getCorrectedTextBoundRect() const
48 tools::Rectangle
aObjectBound(GetCustomShapeObj().GetGeoRect());
49 aObjectBound
+= GetCustomShapeObj().GetGridOffset();
50 tools::Rectangle
aTextBound(aObjectBound
);
51 GetCustomShapeObj().GetTextBounds(aTextBound
);
52 aTextBound
+= GetCustomShapeObj().GetGridOffset();
53 basegfx::B2DRange
aTextRange(aTextBound
.Left(), aTextBound
.Top(), aTextBound
.Right(), aTextBound
.Bottom());
54 const basegfx::B2DRange
aObjectRange(aObjectBound
.Left(), aObjectBound
.Top(), aObjectBound
.Right(), aObjectBound
.Bottom());
56 // no need to correct if no extra text range
57 if(aTextRange
!= aObjectRange
)
59 const GeoStat
& rGeoStat(GetCustomShapeObj().GetGeoStat());
61 // only correct when rotation and/or shear is used
62 if(rGeoStat
.nShearAngle
|| rGeoStat
.nRotationAngle
)
64 // text range needs to be corrected by
65 // aObjectRange.getCenter() - aRotObjectRange.getCenter() since it's
66 // defined differently by using rotation around object center. Start
68 basegfx::B2DVector
aTranslation(aObjectRange
.getCenter());
70 // get rotated and sheared object's range
71 basegfx::B2DRange
aRotObjectRange(aObjectRange
);
72 basegfx::B2DHomMatrix aRotMatrix
;
74 aRotMatrix
.translate(-aObjectRange
.getMinimum().getX(), -aObjectRange
.getMinimum().getY());
76 if(rGeoStat
.nShearAngle
)
78 aRotMatrix
.shearX(tan((36000 - rGeoStat
.nShearAngle
) * F_PI18000
));
81 if(rGeoStat
.nRotationAngle
)
83 aRotMatrix
.rotate((36000 - rGeoStat
.nRotationAngle
) * F_PI18000
);
86 aRotMatrix
.translate(aObjectRange
.getMinimum().getX(), aObjectRange
.getMinimum().getY());
87 aRotObjectRange
.transform(aRotMatrix
);
89 // add negative translation part
90 aTranslation
-= aRotObjectRange
.getCenter();
93 aTextRange
= basegfx::B2DRange(
94 aTextRange
.getMinX() + aTranslation
.getX(), aTextRange
.getMinY() + aTranslation
.getY(),
95 aTextRange
.getMaxX() + aTranslation
.getX(), aTextRange
.getMaxY() + aTranslation
.getY());
102 drawinglayer::primitive2d::Primitive2DContainer
ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence() const
104 drawinglayer::primitive2d::Primitive2DContainer xRetval
;
105 const SfxItemSet
& rItemSet
= GetCustomShapeObj().GetMergedItemSet();
107 // #i98072# Get shadow and text; eventually suppress the text if it's
108 // a TextPath FontworkGallery object
109 const drawinglayer::attribute::SdrShadowTextAttribute
aAttribute(
110 drawinglayer::primitive2d::createNewSdrShadowTextAttribute(
112 GetCustomShapeObj().getText(0),
113 GetCustomShapeObj().IsTextPath()));
114 drawinglayer::primitive2d::Primitive2DContainer xGroup
;
115 bool bHasText(!aAttribute
.getText().isDefault());
117 // create Primitive2DContainer from sub-geometry
118 const SdrObject
* pSdrObjRepresentation
= GetCustomShapeObj().GetSdrObjectFromCustomShape();
119 bool b3DShape(false);
121 Point aGridOff
= GetCustomShapeObj().GetGridOffset();
123 if(pSdrObjRepresentation
)
125 // Hack for calc, transform position of object according
126 // to current zoom so as objects relative position to grid
128 const_cast< SdrObject
* >( pSdrObjRepresentation
)->SetGridOffset( aGridOff
);
129 SdrObjListIter
aIterator(*pSdrObjRepresentation
);
131 while(aIterator
.IsMore())
133 SdrObject
& rCandidate
= *aIterator
.Next();
134 // apply offset to each part
135 rCandidate
.SetGridOffset( aGridOff
);
136 if(!b3DShape
&& dynamic_cast< E3dObject
* >(&rCandidate
))
141 const drawinglayer::primitive2d::Primitive2DContainer
xNew(rCandidate
.GetViewContact().getViewIndependentPrimitive2DContainer());
142 xGroup
.insert(xGroup
.end(), xNew
.begin(), xNew
.end());
146 if(bHasText
|| !xGroup
.empty())
148 // prepare text box geometry
149 basegfx::B2DHomMatrix aTextBoxMatrix
;
150 bool bWordWrap(false);
154 // take unrotated snap rect as default, then get the
155 // unrotated text box. Rotation needs to be done centered
156 tools::Rectangle
aObjectBound(GetCustomShapeObj().GetGeoRect());
157 // hack for calc grid sync
158 aObjectBound
+= GetCustomShapeObj().GetGridOffset();
159 const basegfx::B2DRange
aObjectRange(aObjectBound
.Left(), aObjectBound
.Top(), aObjectBound
.Right(), aObjectBound
.Bottom());
161 // #i101684# get the text range unrotated and absolute to the object range
162 const basegfx::B2DRange
aTextRange(getCorrectedTextBoundRect());
164 // Rotation before scaling
165 if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)))
167 basegfx::B2DVector
aTranslation(0.5, 0.5);
168 aTextBoxMatrix
.translate( -aTranslation
.getX(), -aTranslation
.getY() );
169 aTextBoxMatrix
.rotate((360.0 - GetCustomShapeObj().GetExtraTextRotation(true)) * F_PI180
);
170 aTextBoxMatrix
.translate( aTranslation
.getX(), aTranslation
.getY() );
172 // give text object a size
173 aTextBoxMatrix
.scale(aTextRange
.getWidth(), aTextRange
.getHeight());
175 // check if we have a rotation/shear at all to take care of
176 const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
177 const GeoStat
& rGeoStat(GetCustomShapeObj().GetGeoStat());
179 if(rGeoStat
.nShearAngle
|| rGeoStat
.nRotationAngle
|| !basegfx::fTools::equalZero(fExtraTextRotation
))
181 if(aObjectRange
!= aTextRange
)
183 // move relative to unrotated object range
184 aTextBoxMatrix
.translate(
185 aTextRange
.getMinX() - aObjectRange
.getMinimum().getX(),
186 aTextRange
.getMinY() - aObjectRange
.getMinimum().getY());
189 if(!basegfx::fTools::equalZero(fExtraTextRotation
))
191 basegfx::B2DVector
aTranslation(
192 ( aTextRange
.getWidth() / 2 ) + ( aTextRange
.getMinX() - aObjectRange
.getMinimum().getX() ),
193 ( aTextRange
.getHeight() / 2 ) + ( aTextRange
.getMinY() - aObjectRange
.getMinimum().getY() ) );
194 aTextBoxMatrix
.translate( -aTranslation
.getX(), -aTranslation
.getY() );
195 aTextBoxMatrix
.rotate((360.0 - fExtraTextRotation
) * F_PI180
);
196 aTextBoxMatrix
.translate( aTranslation
.getX(), aTranslation
.getY() );
199 if(rGeoStat
.nShearAngle
)
201 aTextBoxMatrix
.shearX(tan((36000 - rGeoStat
.nShearAngle
) * F_PI18000
));
204 if(rGeoStat
.nRotationAngle
)
206 aTextBoxMatrix
.rotate((36000 - rGeoStat
.nRotationAngle
) * F_PI18000
);
209 // give text it's target position
210 aTextBoxMatrix
.translate(aObjectRange
.getMinimum().getX(), aObjectRange
.getMinimum().getY());
214 aTextBoxMatrix
.translate(aTextRange
.getMinX(), aTextRange
.getMinY());
217 // check if SdrTextWordWrapItem is set
218 bWordWrap
= (static_cast<const SdrOnOffItem
&>(GetCustomShapeObj().GetMergedItem(SDRATTR_TEXT_WORDWRAP
))).GetValue();
222 const drawinglayer::primitive2d::Primitive2DReference
xReference(
223 new drawinglayer::primitive2d::SdrCustomShapePrimitive2D(
229 xRetval
= drawinglayer::primitive2d::Primitive2DContainer
{ xReference
};
234 } // end of namespace contact
235 } // end of namespace sdr
237 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */