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 <sdr/contact/viewcontactofsdrpathobj.hxx>
22 : #include <svx/svdopath.hxx>
23 : #include <svx/sdr/primitive2d/sdrattributecreator.hxx>
24 : #include <basegfx/polygon/b2dpolypolygontools.hxx>
25 : #include <sdr/primitive2d/sdrpathprimitive2d.hxx>
26 : #include <basegfx/matrix/b2dhommatrixtools.hxx>
27 :
28 :
29 :
30 : namespace sdr
31 : {
32 : namespace contact
33 : {
34 22030 : ViewContactOfSdrPathObj::ViewContactOfSdrPathObj(SdrPathObj& rPathObj)
35 22030 : : ViewContactOfTextObj(rPathObj)
36 : {
37 22030 : }
38 :
39 43468 : ViewContactOfSdrPathObj::~ViewContactOfSdrPathObj()
40 : {
41 43468 : }
42 :
43 37258 : drawinglayer::primitive2d::Primitive2DSequence ViewContactOfSdrPathObj::createViewIndependentPrimitive2DSequence() const
44 : {
45 37258 : const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
46 : const drawinglayer::attribute::SdrLineFillShadowTextAttribute aAttribute(
47 : drawinglayer::primitive2d::createNewSdrLineFillShadowTextAttribute(
48 : rItemSet,
49 74516 : GetPathObj().getText(0),
50 74516 : false));
51 74516 : basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
52 37258 : 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 37258 : aUnitPolyPolygon.transform( basegfx::tools::createTranslateB2DHomMatrix( aGridOff.X(), aGridOff.Y() ) );
57 37258 : sal_uInt32 nPolyCount(aUnitPolyPolygon.count());
58 37258 : sal_uInt32 nPointCount(0);
59 :
60 126365 : for(sal_uInt32 a(0); a < nPolyCount; a++)
61 : {
62 89107 : nPointCount += aUnitPolyPolygon.getB2DPolygon(a).count();
63 : }
64 :
65 37258 : if(!nPointCount)
66 : {
67 : OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
68 366 : basegfx::B2DPolygon aFallbackLine;
69 366 : aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
70 366 : aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
71 366 : aUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
72 :
73 366 : nPolyCount = 1;
74 : }
75 :
76 : // prepare object transformation and unit polygon (direct model data)
77 74516 : basegfx::B2DHomMatrix aObjectMatrix;
78 : const bool bIsLine(
79 37258 : !aUnitPolyPolygon.areControlPointsUsed()
80 35182 : && 1 == nPolyCount
81 100136 : && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
82 :
83 37258 : if(bIsLine)
84 : {
85 : // special handling for single line mode (2 points)
86 5695 : const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
87 11390 : const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
88 11390 : const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
89 11390 : const basegfx::B2DVector aLine(aEnd - aStart);
90 :
91 : // #i102548# create new unit polygon for line (horizontal)
92 11390 : basegfx::B2DPolygon aNewPolygon;
93 5695 : aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
94 5695 : aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
95 5695 : aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
96 :
97 : // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
98 11390 : aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
99 : aLine.getLength(), 1.0,
100 : 0.0,
101 : atan2(aLine.getY(), aLine.getX()),
102 11390 : aStart.getX(), aStart.getY());
103 : }
104 : else
105 : {
106 : // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
107 : // (unit polygon) by creating the object matrix and back-transforming the polygon
108 31563 : const basegfx::B2DRange aObjectRange(basegfx::tools::getRange(aUnitPolyPolygon));
109 31563 : const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
110 31563 : const double fWidth(aObjectRange.getWidth());
111 31563 : const double fHeight(aObjectRange.getHeight());
112 31563 : const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
113 31563 : const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
114 :
115 64094 : aObjectMatrix = basegfx::tools::createScaleShearXRotateTranslateB2DHomMatrix(
116 : fScaleX, fScaleY,
117 2 : rGeoStat.nShearAngle ? tan((36000 - rGeoStat.nShearAngle) * F_PI18000) : 0.0,
118 966 : rGeoStat.nRotationAngle ? (36000 - rGeoStat.nRotationAngle) * F_PI18000 : 0.0,
119 31563 : aObjectRange.getMinX(), aObjectRange.getMinY());
120 :
121 : // ceate unit polygon from object's absolute path
122 31563 : basegfx::B2DHomMatrix aInverse(aObjectMatrix);
123 31563 : aInverse.invert();
124 31563 : aUnitPolyPolygon.transform(aInverse);
125 : }
126 :
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 74516 : aUnitPolyPolygon));
134 :
135 74516 : return drawinglayer::primitive2d::Primitive2DSequence(&xReference, 1);
136 : }
137 : } // end of namespace contact
138 435 : } // end of namespace sdr
139 :
140 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|