LibreOffice Module svx (master) 1
svdtrans.hxx
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#pragma once
21
22#include <rtl/ustring.hxx>
23#include <svx/svxdllapi.h>
24#include <tools/degree.hxx>
25#include <tools/fldunit.hxx>
26#include <tools/fract.hxx>
27#include <tools/gen.hxx>
28#include <tools/helpers.hxx>
29#include <tools/mapunit.hxx>
30#include <tools/poly.hxx>
31
32// That maximum shear angle
33constexpr Degree100 SDRMAXSHEAR(8900);
34
35class XPolygon;
36class XPolyPolygon;
37
38inline void MovePoly(tools::Polygon& rPoly, const Size& S) { rPoly.Move(S.Width(),S.Height()); }
39void MoveXPoly(XPolygon& rPoly, const Size& S);
40
41SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
42inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract);
43void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
44void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
45
46inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs);
47SVXCORE_DLLPUBLIC void RotatePoly(tools::Polygon& rPoly, const Point& rRef, double sn, double cs);
48void RotateXPoly(XPolygon& rPoly, const Point& rRef, double sn, double cs);
49void RotateXPoly(XPolyPolygon& rPoly, const Point& rRef, double sn, double cs);
50
51void MirrorPoint(Point& rPnt, const Point& rRef1, const Point& rRef2);
52void MirrorXPoly(XPolygon& rPoly, const Point& rRef1, const Point& rRef2);
53
54inline void ShearPoint(Point& rPnt, const Point& rRef, double tn, bool bVShear = false);
55SVXCORE_DLLPUBLIC void ShearPoly(tools::Polygon& rPoly, const Point& rRef, double tn);
56void ShearXPoly(XPolygon& rPoly, const Point& rRef, double tn, bool bVShear = false);
57
64inline double GetCrookAngle(Point& rPnt, const Point& rCenter, const Point& rRad, bool bVertical);
65
73double CrookRotateXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
74 const Point& rRad, double& rSin, double& rCos, bool bVert);
75double CrookSlantXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
76 const Point& rRad, double& rSin, double& rCos, bool bVert);
77double CrookStretchXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
78 const Point& rRad, double& rSin, double& rCos, bool bVert,
79 const tools::Rectangle& rRefRect);
80
81void CrookRotatePoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
82void CrookSlantPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
83void CrookStretchPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert, const tools::Rectangle& rRefRect);
84
85void CrookRotatePoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
86void CrookSlantPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
87void CrookStretchPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert, const tools::Rectangle& rRefRect);
88
89/**************************************************************************************************/
90/* Inline */
91/**************************************************************************************************/
92
93inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract)
94{
95 double nxFract = xFract.IsValid() ? static_cast<double>(xFract) : 1.0;
96 double nyFract = yFract.IsValid() ? static_cast<double>(yFract) : 1.0;
97 rPnt.setX(rRef.X() + FRound( (rPnt.X() - rRef.X()) * nxFract ));
98 rPnt.setY(rRef.Y() + FRound( (rPnt.Y() - rRef.Y()) * nyFract ));
99}
100
101inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs)
102{
103 tools::Long dx=rPnt.X()-rRef.X();
104 tools::Long dy=rPnt.Y()-rRef.Y();
105 rPnt.setX(FRound(rRef.X()+dx*cs+dy*sn));
106 rPnt.setY(FRound(rRef.Y()+dy*cs-dx*sn));
107}
108
109inline void ShearPoint(Point& rPnt, const Point& rRef, double tn, bool bVShear)
110{
111 if (!bVShear) { // Horizontal
112 if (rPnt.Y()!=rRef.Y()) { // else not needed
113 rPnt.AdjustX(-FRound((rPnt.Y()-rRef.Y())*tn));
114 }
115 } else { // or else vertical
116 if (rPnt.X()!=rRef.X()) { // else not needed
117 rPnt.AdjustY(-FRound((rPnt.X()-rRef.X())*tn));
118 }
119 }
120}
121
122inline double GetCrookAngle(Point& rPnt, const Point& rCenter, const Point& rRad, bool bVertical)
123{
124 double nAngle;
125 if (bVertical) {
126 tools::Long dy=rPnt.Y()-rCenter.Y();
127 nAngle=static_cast<double>(dy)/static_cast<double>(rRad.Y());
128 rPnt.setY(rCenter.Y());
129 } else {
130 tools::Long dx=rCenter.X()-rPnt.X();
131 nAngle=static_cast<double>(dx)/static_cast<double>(rRad.X());
132 rPnt.setX(rCenter.X());
133 }
134 return nAngle;
135}
136
137/**************************************************************************************************/
138/**************************************************************************************************/
139
150
152
154
155sal_uInt16 GetAngleSector(Degree100 nAngle);
156
161tools::Long GetLen(const Point& rPnt);
162
201class GeoStat { // Geometric state for a rect
202public:
205 double mfTanShearAngle; // tan(nShearAngle)
206 double mfSinRotationAngle; // sin(nRotationAngle)
207 double mfCosRotationAngle; // cos(nRotationAngle)
208
210 void RecalcSinCos();
211 void RecalcTan();
212};
213
214tools::Polygon Rect2Poly(const tools::Rectangle& rRect, const GeoStat& rGeo);
215
216namespace svx
217{
219}
220
221void OrthoDistance8(const Point& rPt0, Point& rPt, bool bBigOrtho);
222void OrthoDistance4(const Point& rPt0, Point& rPt, bool bBigOrtho);
223
224// Multiplication and subsequent division
225// Calculation and intermediate values are in BigInt
227
228class FrPair {
231public:
232 FrPair(const Fraction& rBoth) : m_aX(rBoth),m_aY(rBoth) {}
233 FrPair(const Fraction& rX, const Fraction& rY) : m_aX(rX),m_aY(rY) {}
234 FrPair(tools::Long nMul, tools::Long nDiv) : m_aX(nMul,nDiv),m_aY(nMul,nDiv) {}
235 FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv): m_aX(xMul,xDiv),m_aY(yMul,yDiv) {}
236 const Fraction& X() const { return m_aX; }
237 const Fraction& Y() const { return m_aY; }
238 Fraction& X() { return m_aX; }
239 Fraction& Y() { return m_aY; }
240};
241
242// To convert units of measurement
245
246inline bool IsMetric(MapUnit eU) {
247 return (eU==MapUnit::Map100thMM || eU==MapUnit::Map10thMM || eU==MapUnit::MapMM || eU==MapUnit::MapCM);
248}
249
250inline bool IsInch(MapUnit eU) {
251 return (eU==MapUnit::Map1000thInch || eU==MapUnit::Map100thInch || eU==MapUnit::Map10thInch || eU==MapUnit::MapInch ||
252 eU==MapUnit::MapPoint || eU==MapUnit::MapTwip);
253}
254
255inline bool IsMetric(FieldUnit eU) {
256 return (eU == FieldUnit::MM || eU == FieldUnit::CM || eU == FieldUnit::M
257 || eU == FieldUnit::KM || eU == FieldUnit::MM_100TH);
258}
259
260inline bool IsInch(FieldUnit eU) {
261 return (eU == FieldUnit::TWIP || eU == FieldUnit::POINT
262 || eU == FieldUnit::PICA || eU == FieldUnit::INCH
263 || eU == FieldUnit::FOOT || eU == FieldUnit::MILE);
264}
265
269 short m_nComma;
273private:
274 SVX_DLLPRIVATE void Undirty();
275public:
277 : m_nMul(0)
278 , m_nDiv(0)
279 , m_nComma(0)
280 , m_bDirty(true)
281 , m_eSrcMU(eSrc)
282 , m_eDstMU(eDst)
283 {
284 }
285 OUString GetStr(tools::Long nVal) const;
286 static OUString GetUnitStr(MapUnit eUnit);
287 static OUString GetUnitStr(FieldUnit eUnit);
288};
289
290/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv)
Definition: svdtrans.hxx:235
const Fraction & X() const
Definition: svdtrans.hxx:236
const Fraction & Y() const
Definition: svdtrans.hxx:237
Fraction m_aY
Definition: svdtrans.hxx:230
Fraction & X()
Definition: svdtrans.hxx:238
Fraction & Y()
Definition: svdtrans.hxx:239
FrPair(const Fraction &rBoth)
Definition: svdtrans.hxx:232
FrPair(tools::Long nMul, tools::Long nDiv)
Definition: svdtrans.hxx:234
FrPair(const Fraction &rX, const Fraction &rY)
Definition: svdtrans.hxx:233
Fraction m_aX
Definition: svdtrans.hxx:229
bool IsValid() const
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:201
double mfTanShearAngle
Definition: svdtrans.hxx:205
double mfCosRotationAngle
Definition: svdtrans.hxx:207
double mfSinRotationAngle
Definition: svdtrans.hxx:206
void RecalcTan()
Definition: svdtrans.cxx:456
void RecalcSinCos()
Definition: svdtrans.cxx:444
Degree100 m_nShearAngle
Definition: svdtrans.hxx:204
Degree100 m_nRotationAngle
Definition: svdtrans.hxx:203
constexpr tools::Long Y() const
void setX(tools::Long nX)
void setY(tools::Long nY)
tools::Long AdjustY(tools::Long nVertMove)
tools::Long AdjustX(tools::Long nHorzMove)
constexpr tools::Long X() const
tools::Long m_nDiv
Definition: svdtrans.hxx:268
tools::Long m_nMul
Definition: svdtrans.hxx:267
SdrFormatter(MapUnit eSrc, MapUnit eDst)
Definition: svdtrans.hxx:276
MapUnit m_eDstMU
Definition: svdtrans.hxx:272
MapUnit m_eSrcMU
Definition: svdtrans.hxx:271
short m_nComma
Definition: svdtrans.hxx:269
void Move(tools::Long nHorzMove, tools::Long nVertMove)
FieldUnit
tools::Long FRound(double fVal)
MapUnit
tools::Rectangle polygonToRectangle(const tools::Polygon &rPolygon, GeoStat &rGeo)
Definition: svdtrans.cxx:482
long Long
void CrookStretchPoly(XPolygon &rPoly, const Point &rCenter, const Point &rRad, bool bVert, const tools::Rectangle &rRefRect)
Definition: svdtrans.cxx:338
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:109
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:101
void CrookRotatePoly(XPolygon &rPoly, const Point &rCenter, const Point &rRad, bool bVert)
Definition: svdtrans.cxx:292
void ResizeXPoly(XPolygon &rPoly, const Point &rRef, const Fraction &xFact, const Fraction &yFact)
Definition: svdtrans.cxx:73
double CrookRotateXPoint(Point &rPnt, Point *pC1, Point *pC2, const Point &rCenter, const Point &rRad, double &rSin, double &rCos, bool bVert)
The following methods accept a point of an XPolygon, whereas the neighbouring control points of the a...
Definition: svdtrans.cxx:163
void OrthoDistance4(const Point &rPt0, Point &rPt, bool bBigOrtho)
Definition: svdtrans.cxx:553
tools::Polygon Rect2Poly(const tools::Rectangle &rRect, const GeoStat &rGeo)
Definition: svdtrans.cxx:467
void RotateXPoly(XPolygon &rPoly, const Point &rRef, double sn, double cs)
Definition: svdtrans.cxx:89
constexpr Degree100 SDRMAXSHEAR(8900)
SVXCORE_DLLPUBLIC Degree100 GetAngle(const Point &rPnt)
The Y axis points down! The function negates the Y axis, when calculating the angle,...
Definition: svdtrans.cxx:387
double CrookSlantXPoint(Point &rPnt, Point *pC1, Point *pC2, const Point &rCenter, const Point &rRad, double &rSin, double &rCos, bool bVert)
Definition: svdtrans.cxx:217
SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle &rRect, const Point &rRef, const Fraction &xFact, const Fraction &yFact)
Definition: svdtrans.cxx:38
void OrthoDistance8(const Point &rPt0, Point &rPt, bool bBigOrtho)
Definition: svdtrans.cxx:537
SVXCORE_DLLPUBLIC void ShearPoly(tools::Polygon &rPoly, const Point &rRef, double tn)
Definition: svdtrans.cxx:147
double CrookStretchXPoint(Point &rPnt, Point *pC1, Point *pC2, const Point &rCenter, const Point &rRad, double &rSin, double &rCos, bool bVert, const tools::Rectangle &rRefRect)
Definition: svdtrans.cxx:272
sal_uInt16 GetAngleSector(Degree100 nAngle)
Normalize angle to 0.00..359.99.
Definition: svdtrans.cxx:416
void MovePoly(tools::Polygon &rPoly, const Size &S)
Definition: svdtrans.hxx:38
void CrookSlantPoly(XPolygon &rPoly, const Point &rCenter, const Point &rRad, bool bVert)
Definition: svdtrans.cxx:315
SVXCORE_DLLPUBLIC void RotatePoly(tools::Polygon &rPoly, const Point &rRef, double sn, double cs)
Definition: svdtrans.cxx:81
double GetCrookAngle(Point &rPnt, const Point &rCenter, const Point &rRad, bool bVertical)
rPnt.X/rPnt.Y is set to rCenter.X or rCenter.Y! We then only need to rotate rPnt by rCenter.
Definition: svdtrans.hxx:122
SVXCORE_DLLPUBLIC FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:618
void MirrorPoint(Point &rPnt, const Point &rRef1, const Point &rRef2)
Definition: svdtrans.cxx:105
void ResizePoint(Point &rPnt, const Point &rRef, const Fraction &xFract, const Fraction &yFract)
Definition: svdtrans.hxx:93
tools::Long GetLen(const Point &rPnt)
Determine sector within the cartesian coordinate system.
Definition: svdtrans.cxx:418
void ResizePoly(tools::Polygon &rPoly, const Point &rRef, const Fraction &xFact, const Fraction &yFact)
Definition: svdtrans.cxx:65
void ShearXPoly(XPolygon &rPoly, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.cxx:155
bool IsInch(MapUnit eU)
Definition: svdtrans.hxx:250
void MoveXPoly(XPolygon &rPoly, const Size &S)
Definition: svdtrans.cxx:33
SVXCORE_DLLPUBLIC Degree100 NormAngle18000(Degree100 a)
Definition: svdtrans.cxx:401
SVXCORE_DLLPUBLIC Degree100 NormAngle36000(Degree100 a)
Normalize angle to -180.00..179.99.
Definition: svdtrans.cxx:408
SVXCORE_DLLPUBLIC tools::Long BigMulDiv(tools::Long nVal, tools::Long nMul, tools::Long nDiv)
Definition: svdtrans.cxx:567
bool IsMetric(MapUnit eU)
Definition: svdtrans.hxx:246
void MirrorXPoly(XPolygon &rPoly, const Point &rRef1, const Point &rRef2)
Definition: svdtrans.cxx:139
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35