Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 :
20 :
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>
27 :
28 : //////////////////////////////////////////////////////////////////////////////
29 :
30 : namespace sdr
31 : {
32 : namespace contact
33 : {
34 1355 : ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
35 1355 : : ViewContactOfTextObj(rPathObj)
36 : {
37 1355 : }
38 :
39 2690 : ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
40 : {
41 2690 : }
42 :
43 106 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
44 : {
45 106 : const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
46 : const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
47 : drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
48 : rItemSet,
49 106 : GetPathObj().getText(0)));
50 106 : basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
51 106 : Point aGridOff = GetPathObj().GetGridOffset();
52 : // Hack for calc, transform position of object according
53 : // to current zoom so as objects relative position to grid
54 : // appears stable
55 106 : aUnitPolyPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
56 106 : sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
57 106 : sal_uInt32 nPointCount(0);
58 :
59 216 : for(sal_uInt32 a(0); a < nPolyCount; a++)
60 : {
61 110 : nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
62 : }
63 :
64 106 : if(!nPointCount)
65 : {
66 : OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
67 2 : basegfx::B2DPolygon aFallbackLine;
68 2 : aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
69 2 : aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
70 2 : aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
71 :
72 2 : nPolyCount = 1;
73 : }
74 :
75 : // prepare object transformation and unit polygon (direct model data)
76 106 : basegfx::B2DHomMatrix aObjectMatrix;
77 : const bool bIsLine(
78 106 : !aUnitPolyPolygon.areControlPointsUsed()
79 : && 1 == nPolyCount
80 212 : && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
81 :
82 106 : if(bIsLine)
83 : {
84 : // special handling for single line mode (2 points)
85 103 : const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
86 103 : const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
87 103 : const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
88 103 : const basegfx::B2DVector aLine(aEnd - aStart);
89 :
90 : // #i102548# create new unit polygon for line (horizontal)
91 103 : basegfx::B2DPolygon aNewPolygon;
92 103 : aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
93 103 : aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
94 103 : aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
95 :
96 : // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
97 : aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
98 : aLine.getLength(), 1.0,
99 : 0.0,
100 : atan2(aLine.getY(), aLine.getX()),
101 103 : aStart.getX(), aStart.getY());
102 : }
103 : else
104 : {
105 : // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
106 : // (unit polygon) by creating the object matrix and back-transforming the polygon
107 3 : const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
108 3 : const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
109 3 : const double fWidth(aObjectRange.getWidth());
110 3 : const double fHeight(aObjectRange.getHeight());
111 3 : const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
112 3 : const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
113 :
114 : aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
115 : fScaleX, fScaleY,
116 0 : rGeoStat.nShearWink ? tan((36000 - rGeoStat.nShearWink) * F_PI18000) : 0.0,
117 : rGeoStat.nDrehWink ? (36000 - rGeoStat.nDrehWink) * F_PI18000 : 0.0,
118 3 : aObjectRange.getMinX(), aObjectRange.getMinY());
119 :
120 : // ceate unit polygon from object's absolute path
121 3 : basegfx::B2DHomMatrix aInverse(aObjectMatrix);
122 3 : aInverse.invert();
123 3 : aUnitPolyPolygon.transform(aInverse);
124 : }
125 :
126 : // create primitive. Always create primitives to allow the decomposition of
127 : // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
128 : const drawinglayer::primitive2d::Primitive2DReference xReference(
129 : new drawinglayer::primitive2d::SdrPathPrimitive2D(
130 : aObjectMatrix,
131 : aAttribute,
132 106 : aUnitPolyPolygon));
133 :
134 106 : return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
135 : }
136 : } // end of namespace contact
137 : } // end of namespace sdr
138 :
139 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|