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 .
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 //////////////////////////////////////////////////////////////////////////////
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(
49 GetPathObj().getText(0),
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
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();
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
);
76 // prepare object transformation and unit polygon (direct model data)
77 basegfx::B2DHomMatrix aObjectMatrix
;
79 !aUnitPolyPolygon
.areControlPointsUsed()
81 && 2 == aUnitPolyPolygon
.getB2DPolygon(0).count());
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,
101 atan2(aLine
.getY(), aLine
.getX()),
102 aStart
.getX(), aStart
.getY());
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(
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
);
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(
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: */