bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / sdr / contact / viewcontactofsdrpathobj.cxx
blobf3cc4e2c4ac5238e043f705049df92dd78e15b6b
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
22 #include <svx/svdopath.hxx>
23 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
24 #include <basegfx/polygon/b2dpolypolygontools.hxx>
25 #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx>
26 #include <basegfx/matrix/b2dhommatrixtools.hxx>
28 //////////////////////////////////////////////////////////////////////////////
30 namespace sdr
32 namespace contact
34 ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
35 : ViewContactOfTextObj(rPathObj)
39 ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
43 drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
45 const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
46 const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
47 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
48 rItemSet,
49 GetPathObj().getText(0),
50 false));
51 basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
52 Point aGridOff = GetPathObj().GetGridOffset();
53 // Hack for calc, transform position of object according
54 // to current zoom so as objects relative position to grid
55 // appears stable
56 aUnitPolyPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
57 sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
58 sal_uInt32 nPointCount(0);
60 for(sal_uInt32 a(0); a < nPolyCount; a++)
62 nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
65 if(!nPointCount)
67 OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
68 basegfx::B2DPolygon aFallbackLine;
69 aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
70 aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
71 aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
73 nPolyCount = 1;
76 // prepare object transformation and unit polygon (direct model data)
77 basegfx::B2DHomMatrix aObjectMatrix;
78 const bool bIsLine(
79 !aUnitPolyPolygon.areControlPointsUsed()
80 && 1 == nPolyCount
81 && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
83 if(bIsLine)
85 // special handling for single line mode (2 points)
86 const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
87 const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
88 const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
89 const basegfx::B2DVector aLine(aEnd - aStart);
91 // #i102548# create new unit polygon for line (horizontal)
92 basegfx::B2DPolygon aNewPolygon;
93 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
94 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
95 aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
97 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
98 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
99 aLine.getLength(), 1.0,
100 0.0,
101 atan2(aLine.getY(), aLine.getX()),
102 aStart.getX(), aStart.getY());
104 else
106 // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
107 // (unit polygon) by creating the object matrix and back-transforming the polygon
108 const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
109 const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
110 const double fWidth(aObjectRange.getWidth());
111 const double fHeight(aObjectRange.getHeight());
112 const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
113 const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
115 aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
116 fScaleX, fScaleY,
117 rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
118 rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
119 aObjectRange.getMinX(), aObjectRange.getMinY());
121 // ceate unit polygon from object's absolute path
122 basegfx::B2DHomMatrix aInverse(aObjectMatrix);
123 aInverse.invert();
124 aUnitPolyPolygon.transform(aInverse);
127 // create primitive. Always create primitives to allow the decomposition of
128 // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
129 const drawinglayer::primitive2d::Primitive2DReference xReference(
130 new drawinglayer::primitive2d::SdrPathPrimitive2D(
131 aObjectMatrix,
132 aAttribute,
133 aUnitPolyPolygon));
135 return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
137 } // end of namespace contact
138 } // end of namespace sdr
140 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */