1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewcontactofsdrpathobj.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #include <svx/sdr/contact/viewcontactofsdrpathobj.hxx>
36 #include <svx/svdopath.hxx>
37 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
38 #include <svx/sdr/attribute/sdrallattribute.hxx>
39 #include <basegfx/polygon/b2dpolypolygontools.hxx>
40 #include <svx/sdr/primitive2d/sdrpathprimitive2d.hxx>
42 //////////////////////////////////////////////////////////////////////////////
48 ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj
& rPathObj
)
49 : ViewContactOfTextObj(rPathObj
)
53 ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
57 drawinglayer::primitive2d::Primitive2DSequence
ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
59 drawinglayer::primitive2d::Primitive2DSequence xRetval
;
60 const SfxItemSet
& rItemSet
= GetPathObj().GetMergedItemSet();
61 SdrText
* pSdrText
= GetPathObj().getText(0);
65 drawinglayer::attribute::SdrLineFillShadowTextAttribute
* pAttribute
=
66 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
72 if(pAttribute
->isVisible())
74 basegfx::B2DPolyPolygon
aUnitPolyPolygon(GetPathObj().GetPathPoly());
75 const sal_uInt32
nPolyCount(aUnitPolyPolygon
.count());
79 // prepare object transformation and unit polygon (direct model data)
80 basegfx::B2DHomMatrix aObjectMatrix
;
82 !aUnitPolyPolygon
.areControlPointsUsed()
84 && 2 == aUnitPolyPolygon
.getB2DPolygon(0).count());
88 // special handling for single line mode (2 points)
89 const basegfx::B2DPolygon
aSubPolygon(aUnitPolyPolygon
.getB2DPolygon(0));
90 const basegfx::B2DPoint
aStart(aSubPolygon
.getB2DPoint(0));
91 const basegfx::B2DPoint
aEnd(aSubPolygon
.getB2DPoint(1));
92 const basegfx::B2DVector
aLine(aEnd
- aStart
);
94 // #i102548# create new unit polygon for line (horizontal)
95 basegfx::B2DPolygon aNewPolygon
;
96 aNewPolygon
.append(basegfx::B2DPoint(0.0, 0.0));
97 aNewPolygon
.append(basegfx::B2DPoint(1.0, 0.0));
98 aUnitPolyPolygon
.setB2DPolygon(0, aNewPolygon
);
100 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
101 aObjectMatrix
.scale(aLine
.getLength(), 1.0);
102 aObjectMatrix
.rotate(atan2(aLine
.getY(), aLine
.getX()));
103 aObjectMatrix
.translate(aStart
.getX(), aStart
.getY());
107 // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
108 // (unit polygon) by creating the object matrix and back-transforming the polygon
109 const basegfx::B2DRange
aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon
));
110 const GeoStat
& rGeoStat(GetPathObj().GetGeoStat());
111 const double fWidth(aObjectRange
.getWidth());
112 const double fHeight(aObjectRange
.getHeight());
115 basegfx::fTools::equalZero(fWidth
) ? 1.0 : fWidth
,
116 basegfx::fTools::equalZero(fHeight
) ? 1.0 : fHeight
);
118 if(rGeoStat
.nShearWink
)
120 aObjectMatrix
.shearX(tan((36000 - rGeoStat
.nShearWink
) * F_PI18000
));
123 if(rGeoStat
.nDrehWink
)
125 aObjectMatrix
.rotate((36000 - rGeoStat
.nDrehWink
) * F_PI18000
);
128 aObjectMatrix
.translate(aObjectRange
.getMinX(), aObjectRange
.getMinY());
130 // ceate unit polygon from object's absolute path
131 basegfx::B2DHomMatrix
aInverse(aObjectMatrix
);
133 aUnitPolyPolygon
.transform(aInverse
);
137 const drawinglayer::primitive2d::Primitive2DReference
xReference(
138 new drawinglayer::primitive2d::SdrPathPrimitive2D(
143 xRetval
= drawinglayer::primitive2d::Primitive2DSequence(&xReference
, 1);
153 } // end of namespace contact
154 } // end of namespace sdr
156 //////////////////////////////////////////////////////////////////////////////