1*f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*f6e50924SAndrew Rist  * distributed with this work for additional information
6*f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9*f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*f6e50924SAndrew Rist  *
11*f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*f6e50924SAndrew Rist  *
13*f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15*f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17*f6e50924SAndrew Rist  * specific language governing permissions and limitations
18*f6e50924SAndrew Rist  * under the License.
19*f6e50924SAndrew Rist  *
20*f6e50924SAndrew Rist  *************************************************************/
21*f6e50924SAndrew Rist 
22*f6e50924SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svx.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
28cdf0e10cSrcweir #include <svx/svdopath.hxx>
29cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
30cdf0e10cSrcweir #include <basegfx/polygon/b2dpolypolygontools.hxx>
31cdf0e10cSrcweir #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx>
32cdf0e10cSrcweir #include <basegfx/matrix/b2dhommatrixtools.hxx>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace sdr
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	namespace contact
39cdf0e10cSrcweir 	{
40cdf0e10cSrcweir 		ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
41cdf0e10cSrcweir 		:	ViewContactOfTextObj(rPathObj)
42cdf0e10cSrcweir 		{
43cdf0e10cSrcweir 		}
44cdf0e10cSrcweir 
45cdf0e10cSrcweir 		ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
46cdf0e10cSrcweir 		{
47cdf0e10cSrcweir 		}
48cdf0e10cSrcweir 
49cdf0e10cSrcweir 		drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
50cdf0e10cSrcweir 		{
51cdf0e10cSrcweir 			const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
52cdf0e10cSrcweir 			const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
53cdf0e10cSrcweir 				drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
54cdf0e10cSrcweir 					rItemSet,
55cdf0e10cSrcweir 					GetPathObj().getText(0)));
56cdf0e10cSrcweir             basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
57cdf0e10cSrcweir 			sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
58cdf0e10cSrcweir 			sal_uInt32 nPointCount(0);
59cdf0e10cSrcweir 
60cdf0e10cSrcweir 			for(sal_uInt32 a(0); a < nPolyCount; a++)
61cdf0e10cSrcweir 			{
62cdf0e10cSrcweir 				nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
63cdf0e10cSrcweir 			}
64cdf0e10cSrcweir 
65cdf0e10cSrcweir 			if(!nPointCount)
66cdf0e10cSrcweir 			{
67cdf0e10cSrcweir 				OSL_ENSURE(false, "PolyPolygon object without geometry detected, this should not be created (!)");
68cdf0e10cSrcweir 				basegfx::B2DPolygon aFallbackLine;
69cdf0e10cSrcweir 				aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
70cdf0e10cSrcweir 				aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
71cdf0e10cSrcweir 				aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
72cdf0e10cSrcweir 
73cdf0e10cSrcweir 				nPolyCount = 1;
74cdf0e10cSrcweir 			}
75cdf0e10cSrcweir 
76cdf0e10cSrcweir 			// prepare object transformation and unit polygon (direct model data)
77cdf0e10cSrcweir 			basegfx::B2DHomMatrix aObjectMatrix;
78cdf0e10cSrcweir 			const bool bIsLine(
79cdf0e10cSrcweir 				!aUnitPolyPolygon.areControlPointsUsed()
80cdf0e10cSrcweir 				&& 1 == nPolyCount
81cdf0e10cSrcweir 				&& 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
82cdf0e10cSrcweir 
83cdf0e10cSrcweir 			if(bIsLine)
84cdf0e10cSrcweir 			{
85cdf0e10cSrcweir 				// special handling for single line mode (2 points)
86cdf0e10cSrcweir 				const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
87cdf0e10cSrcweir 				const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
88cdf0e10cSrcweir 				const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
89cdf0e10cSrcweir 				const basegfx::B2DVector aLine(aEnd - aStart);
90cdf0e10cSrcweir 
91cdf0e10cSrcweir 				// #i102548# create new unit polygon for line (horizontal)
92cdf0e10cSrcweir 				basegfx::B2DPolygon aNewPolygon;
93cdf0e10cSrcweir 				aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
94cdf0e10cSrcweir 				aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
95cdf0e10cSrcweir 				aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
96cdf0e10cSrcweir 
97cdf0e10cSrcweir 				// #i102548# fill objectMatrix with rotation and offset (no shear for lines)
98cdf0e10cSrcweir 				aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
99cdf0e10cSrcweir 					aLine.getLength(), 1.0,
100cdf0e10cSrcweir 					0.0,
101cdf0e10cSrcweir 					atan2(aLine.getY(), aLine.getX()),
102cdf0e10cSrcweir 					aStart.getX(), aStart.getY());
103cdf0e10cSrcweir 			}
104cdf0e10cSrcweir 			else
105cdf0e10cSrcweir 			{
106cdf0e10cSrcweir 				// #i102548# create unscaled, unsheared, unrotated and untranslated polygon
107cdf0e10cSrcweir 				// (unit polygon) by creating the object matrix and back-transforming the polygon
108cdf0e10cSrcweir 				const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
109cdf0e10cSrcweir 				const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
110cdf0e10cSrcweir 				const double fWidth(aObjectRange.getWidth());
111cdf0e10cSrcweir 				const double fHeight(aObjectRange.getHeight());
112cdf0e10cSrcweir 				const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
113cdf0e10cSrcweir 				const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 				aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
116cdf0e10cSrcweir 					fScaleX, fScaleY,
117cdf0e10cSrcweir 					rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
118cdf0e10cSrcweir 					rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
119cdf0e10cSrcweir 					aObjectRange.getMinX(), aObjectRange.getMinY());
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 				// ceate unit polygon from object's absolute path
122cdf0e10cSrcweir 				basegfx::B2DHomMatrix aInverse(aObjectMatrix);
123cdf0e10cSrcweir 				aInverse.invert();
124cdf0e10cSrcweir 				aUnitPolyPolygon.transform(aInverse);
125cdf0e10cSrcweir 			}
126cdf0e10cSrcweir 
127cdf0e10cSrcweir 			// create primitive. Always create primitives to allow the decomposition of
128cdf0e10cSrcweir 			// SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
129cdf0e10cSrcweir 			const drawinglayer::primitive2d::Primitive2DReference xReference(
130cdf0e10cSrcweir 				new drawinglayer::primitive2d::SdrPathPrimitive2D(
131cdf0e10cSrcweir 					aObjectMatrix,
132cdf0e10cSrcweir 					aAttribute,
133cdf0e10cSrcweir 					aUnitPolyPolygon));
134cdf0e10cSrcweir 
135cdf0e10cSrcweir 			return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
136cdf0e10cSrcweir 		}
137cdf0e10cSrcweir 	} // end of namespace contact
138cdf0e10cSrcweir } // end of namespace sdr
139cdf0e10cSrcweir 
140cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////////////
141cdf0e10cSrcweir // eof
142