LibreOffice Module svx (master) 1
viewcontactofsdrpathobj.cxx
Go to the documentation of this file.
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
22#include <svx/svdopath.hxx>
28#include <osl/diagnose.h>
30#include <vcl/canvastools.hxx>
31
32namespace sdr::contact
33{
35 : ViewContactOfTextObj(rPathObj)
36 {
37 }
38
40 {
41 }
42
44 static bool ensureGeometry(basegfx::B2DPolyPolygon& rUnitPolyPolygon)
45 {
46 sal_uInt32 nPolyCount(rUnitPolyPolygon.count());
47 sal_uInt32 nPointCount(0);
48
49 for(auto const& rPolygon : std::as_const(rUnitPolyPolygon))
50 {
51 nPointCount += rPolygon.count();
52 if (nPointCount > 1)
53 return false;
54 }
55
56 if(!nPointCount)
57 {
58 OSL_FAIL("PolyPolygon object without geometry detected, this should not be created (!)");
59 basegfx::B2DPolygon aFallbackLine;
60 aFallbackLine.append(basegfx::B2DPoint(0.0, 0.0));
61 aFallbackLine.append(basegfx::B2DPoint(1000.0, 1000.0));
62 rUnitPolyPolygon = basegfx::B2DPolyPolygon(aFallbackLine);
63
64 nPolyCount = 1;
65 }
66
67 return nPolyCount == 1;
68 }
69
71 {
72 const SfxItemSet& rItemSet = GetPathObj().GetMergedItemSet();
75 rItemSet,
76 GetPathObj().getText(0),
77 false));
78 basegfx::B2DPolyPolygon aUnitPolyPolygon(GetPathObj().GetPathPoly());
79 bool bPolyCountIsOne(ensureGeometry(aUnitPolyPolygon));
80
81 // prepare object transformation and unit polygon (direct model data)
82 basegfx::B2DHomMatrix aObjectMatrix;
83 basegfx::B2DPolyPolygon aUnitDefinitionPolyPolygon;
84 const bool bIsLine(
85 !aUnitPolyPolygon.areControlPointsUsed()
86 && bPolyCountIsOne
87 && 2 == aUnitPolyPolygon.getB2DPolygon(0).count());
88
89 if(bIsLine)
90 {
91 // special handling for single line mode (2 points)
92 const basegfx::B2DPolygon aSubPolygon(aUnitPolyPolygon.getB2DPolygon(0));
93 const basegfx::B2DPoint aStart(aSubPolygon.getB2DPoint(0));
94 const basegfx::B2DPoint aEnd(aSubPolygon.getB2DPoint(1));
95 const basegfx::B2DVector aLine(aEnd - aStart);
96
97 // #i102548# create new unit polygon for line (horizontal)
98 basegfx::B2DPolygon aNewPolygon;
99 aNewPolygon.append(basegfx::B2DPoint(0.0, 0.0));
100 aNewPolygon.append(basegfx::B2DPoint(1.0, 0.0));
101 aUnitPolyPolygon.setB2DPolygon(0, aNewPolygon);
102
103 // #i102548# fill objectMatrix with rotation and offset (no shear for lines)
105 aLine.getLength(), 1.0,
106 0.0,
107 atan2(aLine.getY(), aLine.getX()),
108 aStart.getX(), aStart.getY());
109 }
110 else
111 {
112 // #i102548# create unscaled, unsheared, unrotated and untranslated polygon
113 // (unit polygon) by creating the object matrix and back-transforming the polygon
114 const basegfx::B2DRange aObjectRange(basegfx::utils::getRange(aUnitPolyPolygon));
115 const GeoStat& rGeoStat(GetPathObj().GetGeoStat());
116 const double fWidth(aObjectRange.getWidth());
117 const double fHeight(aObjectRange.getHeight());
118 const double fScaleX(basegfx::fTools::equalZero(fWidth) ? 1.0 : fWidth);
119 const double fScaleY(basegfx::fTools::equalZero(fHeight) ? 1.0 : fHeight);
120
122 fScaleX, fScaleY,
123 -rGeoStat.mfTanShearAngle,
124 rGeoStat.nRotationAngle ? toRadians(36000_deg100 - rGeoStat.nRotationAngle) : 0.0,
125 aObjectRange.getMinX(), aObjectRange.getMinY());
126
127 // create unit polygon from object's absolute path
128 basegfx::B2DHomMatrix aInverse(aObjectMatrix);
129 aInverse.invert();
130 aUnitPolyPolygon.transform(aInverse);
131
132 // OperationSmiley: Check if a FillGeometryDefiningShape is set
133 const SdrObject* pFillGeometryDefiningShape(GetPathObj().getFillGeometryDefiningShape());
134
135 if(nullptr != pFillGeometryDefiningShape)
136 {
137 // If yes, get it's BoundRange and use as defining Geometry for the FillStyle.
138 // If no, aUnitDefinitionPolyPolygon will just be empty and thus be interpreted
139 // as unused.
140 // Using SnapRect will make the FillDefinition to always be extended e.g.
141 // for rotated/sheared objects.
142 const tools::Rectangle& rSnapRect(pFillGeometryDefiningShape->GetSnapRect());
143
144 aUnitDefinitionPolyPolygon.append(
147
148 // use same coordinate system as the shape geometry -> this
149 // makes it relative to shape's unit geometry and thus freely
150 // transformable with the shape
151 aUnitDefinitionPolyPolygon.transform(aInverse);
152 }
153 }
154
155 // create primitive. Always create primitives to allow the decomposition of
156 // SdrPathPrimitive2D to create needed invisible elements for HitTest and/or BoundRect
159 aObjectMatrix,
160 aAttribute,
161 std::move(aUnitPolyPolygon),
162 std::move(aUnitDefinitionPolyPolygon)));
163
164 rVisitor.visit(xReference);
165 }
166
167} // end of namespace
168
169/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:201
double mfTanShearAngle
Definition: svdtrans.hxx:205
Degree100 nRotationAngle
Definition: svdtrans.hxx:203
Abstract DrawObject.
Definition: svdobj.hxx:260
virtual const tools::Rectangle & GetSnapRect() const
Definition: svdobj.cxx:1626
const SfxItemSet & GetMergedItemSet() const
Definition: svdobj.cxx:1938
B2DPolygon const & getB2DPolygon(sal_uInt32 nIndex) const
void append(const B2DPolygon &rPolygon, sal_uInt32 nCount=1)
void setB2DPolygon(sal_uInt32 nIndex, const B2DPolygon &rPolygon)
void transform(const basegfx::B2DHomMatrix &rMatrix)
bool areControlPointsUsed() const
sal_uInt32 count() const
basegfx::B2DPoint const & getB2DPoint(sal_uInt32 nIndex) const
void append(const basegfx::B2DPoint &rPoint, sal_uInt32 nCount)
sal_uInt32 count() const
double getLength() const
TYPE getWidth() const
TYPE getMinX() const
TYPE getMinY() const
TYPE getHeight() const
TYPE getX() const
TYPE getY() const
virtual void visit(const Primitive2DReference &)=0
virtual void createViewIndependentPrimitive2DSequence(drawinglayer::primitive2d::Primitive2DDecompositionVisitor &rVisitor) const override
double toRadians(D x)
bool equalZero(const T &rfVal)
B2DPolygon createPolygonFromRect(const B2DRectangle &rRect, double fRadiusX, double fRadiusY)
B2DHomMatrix createScaleShearXRotateTranslateB2DHomMatrix(double fScaleX, double fScaleY, double fShearX, double fRadiant, double fTranslateX, double fTranslateY)
B2DRange getRange(const B2DPolygon &rCandidate)
attribute::SdrLineFillEffectsTextAttribute createNewSdrLineFillEffectsTextAttribute(const SfxItemSet &rSet, const SdrText *pText, bool bHasContent)
static bool ensureGeometry(basegfx::B2DPolyPolygon &rUnitPolyPolygon)
return true if polycount == 1
basegfx::B2DRange b2DRectangleFromRectangle(const ::tools::Rectangle &rRect)