Line data Source code
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 : #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>
31 :
32 :
33 :
34 : namespace sdr
35 : {
36 : namespace contact
37 : {
38 3446 : ViewContactOfSdrObjCustomShape::ViewContactOfSdrObjCustomShape(SdrObjCustomShape& rCustomShape)
39 3446 : : ViewContactOfTextObj(rCustomShape)
40 : {
41 3446 : }
42 :
43 6886 : ViewContactOfSdrObjCustomShape::~ViewContactOfSdrObjCustomShape()
44 : {
45 6886 : }
46 :
47 1356 : basegfx::B2DRange ViewContactOfSdrObjCustomShape::getCorrectedTextBoundRect() const
48 : {
49 1356 : Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
50 1356 : aObjectBound += GetCustomShapeObj().GetGridOffset();
51 1356 : Rectangle aTextBound(aObjectBound);
52 1356 : GetCustomShapeObj().GetTextBounds(aTextBound);
53 1356 : aTextBound += GetCustomShapeObj().GetGridOffset();
54 1356 : basegfx::B2DRange aTextRange(aTextBound.Left(), aTextBound.Top(), aTextBound.Right(), aTextBound.Bottom());
55 1356 : const basegfx::B2DRange aObjectRange(aObjectBound.Left(), aObjectBound.Top(), aObjectBound.Right(), aObjectBound.Bottom());
56 :
57 : // no need to correct if no extra text range
58 1356 : if(aTextRange != aObjectRange)
59 : {
60 723 : const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
61 :
62 : // only correct when rotation and/or shear is used
63 723 : if(rGeoStat.nShearAngle || rGeoStat.nRotationAngle )
64 : {
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
68 : // with positive part
69 18 : basegfx::B2DVector aTranslation(aObjectRange.getCenter());
70 :
71 : // get rotated and sheared object's range
72 18 : basegfx::B2DRange aRotObjectRange(aObjectRange);
73 36 : basegfx::B2DHomMatrix aRotMatrix;
74 :
75 18 : aRotMatrix.translate(-aObjectRange.getMinimum().getX(), -aObjectRange.getMinimum().getY());
76 :
77 18 : if(rGeoStat.nShearAngle)
78 : {
79 0 : aRotMatrix.shearX(tan((36000 - rGeoStat.nShearAngle) * F_PI18000));
80 : }
81 :
82 18 : if(rGeoStat.nRotationAngle)
83 : {
84 18 : aRotMatrix.rotate((36000 - rGeoStat.nRotationAngle) * F_PI18000);
85 : }
86 :
87 18 : aRotMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
88 18 : aRotObjectRange.transform(aRotMatrix);
89 :
90 : // add negative translation part
91 18 : aTranslation -= aRotObjectRange.getCenter();
92 :
93 : // create new range
94 : aTextRange = basegfx::B2DRange(
95 36 : aTextRange.getMinX() + aTranslation.getX(), aTextRange.getMinY() + aTranslation.getY(),
96 72 : aTextRange.getMaxX() + aTranslation.getX(), aTextRange.getMaxY() + aTranslation.getY());
97 : }
98 : }
99 :
100 1356 : return aTextRange;
101 : }
102 :
103 7429 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrObjCustomShape::createViewIndependentPrimitive2DSequence() const
104 : {
105 7429 : drawinglayer::primitive2d::Primitive2DSequence xRetval;
106 7429 : const SfxItemSet& rItemSet = GetCustomShapeObj().GetMergedItemSet();
107 :
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(
112 : rItemSet,
113 14858 : GetCustomShapeObj().getText(0),
114 29716 : GetCustomShapeObj().IsTextPath()));
115 14858 : drawinglayer::primitive2d::Primitive2DSequence xGroup;
116 7429 : bool bHasText(!aAttribute.getText().isDefault());
117 :
118 : // create Primitive2DSequence from sub-geometry
119 7429 : const SdrObject* pSdrObjRepresentation = GetCustomShapeObj().GetSdrObjectFromCustomShape();
120 7429 : bool b3DShape(false);
121 :
122 7429 : Point aGridOff = GetCustomShapeObj().GetGridOffset();
123 :
124 7429 : if(pSdrObjRepresentation)
125 : {
126 : // Hack for calc, transform position of object according
127 : // to current zoom so as objects relative position to grid
128 : // appears stable
129 4530 : const_cast< SdrObject* >( pSdrObjRepresentation )->SetGridOffset( aGridOff );
130 4530 : SdrObjListIter aIterator(*pSdrObjRepresentation);
131 :
132 15129 : while(aIterator.IsMore())
133 : {
134 6069 : SdrObject& rCandidate = *aIterator.Next();
135 : // apply offset to each part
136 6069 : rCandidate.SetGridOffset( aGridOff );
137 6069 : if(!b3DShape && dynamic_cast< E3dObject* >(&rCandidate))
138 : {
139 0 : b3DShape = true;
140 : }
141 :
142 6069 : const drawinglayer::primitive2d::Primitive2DSequence xNew(rCandidate.GetViewContact().getViewIndependentPrimitive2DSequence());
143 6069 : drawinglayer::primitive2d::appendPrimitive2DSequenceToPrimitive2DSequence(xGroup, xNew);
144 10599 : }
145 : }
146 :
147 7429 : if(bHasText || xGroup.hasElements())
148 : {
149 : // prepare text box geometry
150 4973 : basegfx::B2DHomMatrix aTextBoxMatrix;
151 4973 : bool bWordWrap(false);
152 :
153 4973 : if(bHasText)
154 : {
155 : // take unrotated snap rect as default, then get the
156 : // unrotated text box. Rotation needs to be done centered
157 1356 : Rectangle aObjectBound(GetCustomShapeObj().GetGeoRect());
158 : // hack for calc grid sync
159 1356 : aObjectBound += GetCustomShapeObj().GetGridOffset();
160 1356 : const basegfx::B2DRange aObjectRange(aObjectBound.Left(), aObjectBound.Top(), aObjectBound.Right(), aObjectBound.Bottom());
161 :
162 : // #i101684# get the text range unrotated and absolute to the object range
163 1356 : const basegfx::B2DRange aTextRange(getCorrectedTextBoundRect());
164 :
165 : // Rotation before scaling
166 1356 : if(!basegfx::fTools::equalZero(GetCustomShapeObj().GetExtraTextRotation(true)))
167 : {
168 33 : basegfx::B2DVector aTranslation(0.5, 0.5);
169 33 : aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
170 33 : aTextBoxMatrix.rotate((360.0 - GetCustomShapeObj().GetExtraTextRotation(true)) * F_PI180);
171 33 : aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
172 : }
173 : // give text object a size
174 1356 : aTextBoxMatrix.scale(aTextRange.getWidth(), aTextRange.getHeight());
175 :
176 : // check if we have a rotation/shear at all to take care of
177 1356 : const double fExtraTextRotation(GetCustomShapeObj().GetExtraTextRotation());
178 1356 : const GeoStat& rGeoStat(GetCustomShapeObj().GetGeoStat());
179 :
180 1356 : if(rGeoStat.nShearAngle || rGeoStat.nRotationAngle || !basegfx::fTools::equalZero(fExtraTextRotation))
181 : {
182 102 : if(aObjectRange != aTextRange)
183 : {
184 : // move relative to unrotated object range
185 : aTextBoxMatrix.translate(
186 36 : aTextRange.getMinX() - aObjectRange.getMinimum().getX(),
187 54 : aTextRange.getMinY() - aObjectRange.getMinimum().getY());
188 : }
189 :
190 102 : if(!basegfx::fTools::equalZero(fExtraTextRotation))
191 : {
192 : basegfx::B2DVector aTranslation(
193 0 : ( aTextRange.getWidth() / 2 ) + ( aTextRange.getMinX() - aObjectRange.getMinimum().getX() ),
194 0 : ( aTextRange.getHeight() / 2 ) + ( aTextRange.getMinY() - aObjectRange.getMinimum().getY() ) );
195 0 : aTextBoxMatrix.translate( -aTranslation.getX(), -aTranslation.getY() );
196 0 : aTextBoxMatrix.rotate((360.0 - fExtraTextRotation) * F_PI180);
197 0 : aTextBoxMatrix.translate( aTranslation.getX(), aTranslation.getY() );
198 : }
199 :
200 102 : if(rGeoStat.nShearAngle)
201 : {
202 0 : aTextBoxMatrix.shearX(tan((36000 - rGeoStat.nShearAngle) * F_PI18000));
203 : }
204 :
205 102 : if(rGeoStat.nRotationAngle)
206 : {
207 102 : aTextBoxMatrix.rotate((36000 - rGeoStat.nRotationAngle) * F_PI18000);
208 : }
209 :
210 : // give text it's target position
211 102 : aTextBoxMatrix.translate(aObjectRange.getMinimum().getX(), aObjectRange.getMinimum().getY());
212 : }
213 : else
214 : {
215 1254 : aTextBoxMatrix.translate(aTextRange.getMinX(), aTextRange.getMinY());
216 : }
217 :
218 : // check if SdrTextWordWrapItem is set
219 1356 : bWordWrap = (static_cast<const SdrOnOffItem&>(GetCustomShapeObj().GetMergedItem(SDRATTR_TEXT_WORDWRAP))).GetValue();
220 : }
221 :
222 : // create primitive
223 : const drawinglayer::primitive2d::Primitive2DReference xReference(
224 : new drawinglayer::primitive2d::SdrCustomShapePrimitive2D(
225 : aAttribute,
226 : xGroup,
227 : aTextBoxMatrix,
228 : bWordWrap,
229 : b3DShape,
230 9946 : false)); // #SJ# New parameter to force to clipped BlockText for SC
231 9946 : xRetval = drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
232 : }
233 :
234 14858 : return xRetval;
235 : }
236 : } // end of namespace contact
237 435 : } // end of namespace sdr
238 :
239 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|