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 <sdr/contact/viewcontactofsdrpathobj.hxx>
22 #include <svx/svdopath.hxx>
23 #include <svx/svdpage.hxx>
24 #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
25 #include <basegfx/polygon/b2dpolypolygontools.hxx>
26 #include <basegfx/polygon/b2dpolygonclipper.hxx>
27 #include <sdr/primitive2d/sdrpathprimitive2d.hxx>
28 #include <basegfx/matrix/b2dhommatrixtools.hxx>
35 ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj
& rPathObj
)
36 : ViewContactOfTextObj(rPathObj
)
40 ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
44 static sal_uInt32
ensureGeometry(basegfx::B2DPolyPolygon
& rUnitPolyPolygon
)
46 sal_uInt32
nPolyCount(rUnitPolyPolygon
.count());
47 sal_uInt32
nPointCount(0);
49 for(sal_uInt32
a(0); a
< nPolyCount
; a
++)
51 nPointCount
+= rUnitPolyPolygon
.getB2DPolygon(a
).count();
56 OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
57 basegfx::B2DPolygon aFallbackLine
;
58 aFallbackLine
.append(basegfx::B2DPoint(0.0, 0.0));
59 aFallbackLine
.append(basegfx::B2DPoint(1000.0, 1000.0));
60 rUnitPolyPolygon
= basegfx::B2DPolyPolygon(aFallbackLine
);
68 drawinglayer::primitive2d::Primitive2DContainer
ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
70 const SfxItemSet
& rItemSet
= GetPathObj().GetMergedItemSet();
71 const drawinglayer::attribute::SdrLineFillShadowTextAttribute
aAttribute(
72 drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
74 GetPathObj().getText(0),
76 basegfx::B2DPolyPolygon
aUnitPolyPolygon(GetPathObj().GetPathPoly());
77 Point aGridOff
= GetPathObj().GetGridOffset();
78 // Hack for calc, transform position of object according
79 // to current zoom so as objects relative position to grid
81 aUnitPolyPolygon
.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff
.X(), aGridOff
.Y() ) );
82 sal_uInt32
nPolyCount(ensureGeometry(aUnitPolyPolygon
));
84 // prepare object transformation and unit polygon (direct model data)
85 basegfx::B2DHomMatrix aObjectMatrix
;
87 !aUnitPolyPolygon
.areControlPointsUsed()
89 && 2 == aUnitPolyPolygon
.getB2DPolygon(0).count());
93 //tdf#63955 if we have an extremely long line then clip it to a
94 //very generous range of -1 page width/height vs +1 page
95 //width/height to avoid oom and massive churn generating a huge
96 //polygon chain to cover the length in applyLineDashing if this
98 const SdrPage
* pPage
= GetPathObj().GetPage();
99 sal_Int32 nPageWidth
= pPage
? pPage
->GetWdt() : 0;
100 sal_Int32 nPageHeight
= pPage
? pPage
->GetHgt() : 0;
102 //But, see tdf#101187, only do this if our generous clip region
103 //would not over flow into a tiny clip region
104 if (nPageWidth
< SAL_MAX_INT32
/2 && nPageHeight
< SAL_MAX_INT32
/2)
106 //But, see tdf#97276 and tdf#98366. Don't clip too much if the
107 //underlying page dimension is unknown or a paste document
108 //where the page sizes use the odd default of 10x10
109 nPageWidth
= std::max
<sal_Int32
>(21000, nPageWidth
);
110 nPageHeight
= std::max
<sal_Int32
>(29700, nPageHeight
);
111 basegfx::B2DRange
aClipRange(-nPageWidth
, -nPageHeight
,
112 nPageWidth
*2, nPageHeight
*2);
114 aUnitPolyPolygon
= basegfx::tools::clipPolyPolygonOnRange(aUnitPolyPolygon
,
115 aClipRange
, true, true);
116 nPolyCount
= ensureGeometry(aUnitPolyPolygon
);
118 // re-check that we have't been clipped out to oblivion
120 !aUnitPolyPolygon
.areControlPointsUsed()
122 && 2 == aUnitPolyPolygon
.getB2DPolygon(0).count();
129 // special handling for single line mode (2 points)
130 const basegfx::B2DPolygon
aSubPolygon(aUnitPolyPolygon
.getB2DPolygon(0));
131 const basegfx::B2DPoint
aStart(aSubPolygon
.getB2DPoint(0));
132 const basegfx::B2DPoint
aEnd(aSubPolygon
.getB2DPoint(1));
133 const basegfx::B2DVector
aLine(aEnd
- aStart
);
135 // #i102548# create new unit polygon for line (horizontal)
136 basegfx::B2DPolygon aNewPolygon
;
137 aNewPolygon
.append(basegfx::B2DPoint(0.0, 0.0));
138 aNewPolygon
.append(basegfx::B2DPoint(1.0, 0.0));
139 aUnitPolyPolygon
.setB2DPolygon(0, aNewPolygon
);
141 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
142 aObjectMatrix
= basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
143 aLine
.getLength(), 1.0,
145 atan2(aLine
.getY(), aLine
.getX()),
146 aStart
.getX(), aStart
.getY());
150 // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
151 // (unit polygon) by creating the object matrix and back-transforming the polygon
152 const basegfx::B2DRange
aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon
));
153 const GeoStat
& rGeoStat(GetPathObj().GetGeoStat());
154 const double fWidth(aObjectRange
.getWidth());
155 const double fHeight(aObjectRange
.getHeight());
156 const double fScaleX(basegfx::fTools::equalZero(fWidth
) ? 1.0 : fWidth
);
157 const double fScaleY(basegfx::fTools::equalZero(fHeight
) ? 1.0 : fHeight
);
159 aObjectMatrix
= basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
161 rGeoStat
.nShearAngle
? tan((36000 - rGeoStat
.nShearAngle
) * F_PI18000
) : 0.0,
162 rGeoStat
.nRotationAngle
? (36000 - rGeoStat
.nRotationAngle
) * F_PI18000
: 0.0,
163 aObjectRange
.getMinX(), aObjectRange
.getMinY());
165 // create unit polygon from object's absolute path
166 basegfx::B2DHomMatrix
aInverse(aObjectMatrix
);
168 aUnitPolyPolygon
.transform(aInverse
);
171 // create primitive. Always create primitives to allow the decomposition of
172 // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
173 const drawinglayer::primitive2d::Primitive2DReference
xReference(
174 new drawinglayer::primitive2d::SdrPathPrimitive2D(
179 return drawinglayer::primitive2d::Primitive2DContainer
{ xReference
};
181 } // end of namespace contact
182 } // end of namespace sdr
184 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */