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
149SVXCORE_DLLPUBLIC Degree100 GetAngle(const Point& rPnt);
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);
215void Poly2Rect(const tools::Polygon& rPol, tools::Rectangle& rRect, GeoStat& rGeo);
216
217void OrthoDistance8(const Point& rPt0, Point& rPt, bool bBigOrtho);
218void OrthoDistance4(const Point& rPt0, Point& rPt, bool bBigOrtho);
219
220// Multiplication and subsequent division
221// Calculation and intermediate values are in BigInt
223
224class FrPair {
227public:
228 FrPair(const Fraction& rBoth) : aX(rBoth),aY(rBoth) {}
229 FrPair(const Fraction& rX, const Fraction& rY) : aX(rX),aY(rY) {}
230 FrPair(tools::Long nMul, tools::Long nDiv) : aX(nMul,nDiv),aY(nMul,nDiv) {}
231 FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv): aX(xMul,xDiv),aY(yMul,yDiv) {}
232 const Fraction& X() const { return aX; }
233 const Fraction& Y() const { return aY; }
234 Fraction& X() { return aX; }
235 Fraction& Y() { return aY; }
236};
237
238// To convert units of measurement
241
242inline bool IsMetric(MapUnit eU) {
243 return (eU==MapUnit::Map100thMM || eU==MapUnit::Map10thMM || eU==MapUnit::MapMM || eU==MapUnit::MapCM);
244}
245
246inline bool IsInch(MapUnit eU) {
247 return (eU==MapUnit::Map1000thInch || eU==MapUnit::Map100thInch || eU==MapUnit::Map10thInch || eU==MapUnit::MapInch ||
248 eU==MapUnit::MapPoint || eU==MapUnit::MapTwip);
249}
250
251inline bool IsMetric(FieldUnit eU) {
252 return (eU == FieldUnit::MM || eU == FieldUnit::CM || eU == FieldUnit::M
253 || eU == FieldUnit::KM || eU == FieldUnit::MM_100TH);
254}
255
256inline bool IsInch(FieldUnit eU) {
257 return (eU == FieldUnit::TWIP || eU == FieldUnit::POINT
258 || eU == FieldUnit::PICA || eU == FieldUnit::INCH
259 || eU == FieldUnit::FOOT || eU == FieldUnit::MILE);
260}
261
265 short nComma_;
266 bool bDirty;
269private:
270 SVX_DLLPRIVATE void Undirty();
271public:
273 : nMul_(0)
274 , nDiv_(0)
275 , nComma_(0)
276 , bDirty(true)
277 , eSrcMU(eSrc)
278 , eDstMU(eDst)
279 {
280 }
281 OUString GetStr(tools::Long nVal) const;
282 static OUString GetUnitStr(MapUnit eUnit);
283 static OUString GetUnitStr(FieldUnit eUnit);
284};
285
286/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv)
Definition: svdtrans.hxx:231
const Fraction & X() const
Definition: svdtrans.hxx:232
Fraction aX
Definition: svdtrans.hxx:225
const Fraction & Y() const
Definition: svdtrans.hxx:233
Fraction & X()
Definition: svdtrans.hxx:234
Fraction & Y()
Definition: svdtrans.hxx:235
FrPair(const Fraction &rBoth)
Definition: svdtrans.hxx:228
FrPair(tools::Long nMul, tools::Long nDiv)
Definition: svdtrans.hxx:230
FrPair(const Fraction &rX, const Fraction &rY)
Definition: svdtrans.hxx:229
Fraction aY
Definition: svdtrans.hxx:226
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
Degree100 nShearAngle
Definition: svdtrans.hxx:204
double mfSinRotationAngle
Definition: svdtrans.hxx:206
void RecalcTan()
Definition: svdtrans.cxx:456
void RecalcSinCos()
Definition: svdtrans.cxx:444
Degree100 nRotationAngle
Definition: svdtrans.hxx:203
tools::Long nDiv_
Definition: svdtrans.hxx:264
short nComma_
Definition: svdtrans.hxx:265
tools::Long nMul_
Definition: svdtrans.hxx:263
SdrFormatter(MapUnit eSrc, MapUnit eDst)
Definition: svdtrans.hxx:272
MapUnit eSrcMU
Definition: svdtrans.hxx:267
MapUnit eDstMU
Definition: svdtrans.hxx:268
void Move(tools::Long nHorzMove, tools::Long nVertMove)
FieldUnit
tools::Long FRound(double fVal)
MapUnit
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:538
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:522
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
void Poly2Rect(const tools::Polygon &rPol, tools::Rectangle &rRect, GeoStat &rGeo)
Definition: svdtrans.cxx:480
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:603
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:246
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:552
bool IsMetric(MapUnit eU)
Definition: svdtrans.hxx:242
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