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 #ifndef INCLUDED_SVX_SVDTRANS_HXX
21 #define INCLUDED_SVX_SVDTRANS_HXX
22 
23 #include <rtl/ustring.hxx>
24 #include <svx/svxdllapi.h>
25 #include <tools/degree.hxx>
26 #include <tools/fldunit.hxx>
27 #include <tools/fract.hxx>
28 #include <tools/gen.hxx>
29 #include <tools/helpers.hxx>
30 #include <tools/mapunit.hxx>
31 #include <tools/poly.hxx>
32 
33 // The DrawingEngine's angles are specified in 1/100th degrees
34 // We need to convert these angles to radians, in order to be able
35 // to process them with trigonometric functions.
36 // This is done, using the constant F_PI18000.
37 //
38 // Example usage:
39 // nAngle ... is an angle in 1/100 Deg
40 //
41 // Which is converted, by this:
42 // double nSin=sin(nAngle*F_PI18000);
43 //
44 // To convert it back, we use division.
45 
46 // That maximum shear angle
47 constexpr Degree100 SDRMAXSHEAR(8900);
48 
49 class XPolygon;
50 class XPolyPolygon;
51 
52 inline void MovePoly(tools::Polygon& rPoly, const Size& S) { rPoly.Move(S.Width(),S.Height()); }
53 void MoveXPoly(XPolygon& rPoly, const Size& S);
54 
55 SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
56 inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract);
57 void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
58 void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
59 
60 inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs);
61 SVXCORE_DLLPUBLIC void RotatePoly(tools::Polygon& rPoly, const Point& rRef, double sn, double cs);
62 void RotateXPoly(XPolygon& rPoly, const Point& rRef, double sn, double cs);
63 void RotateXPoly(XPolyPolygon& rPoly, const Point& rRef, double sn, double cs);
64 
65 void MirrorPoint(Point& rPnt, const Point& rRef1, const Point& rRef2);
66 void MirrorXPoly(XPolygon& rPoly, const Point& rRef1, const Point& rRef2);
67 
68 inline void ShearPoint(Point& rPnt, const Point& rRef, double tn, bool bVShear = false);
69 SVXCORE_DLLPUBLIC void ShearPoly(tools::Polygon& rPoly, const Point& rRef, double tn);
70 void ShearXPoly(XPolygon& rPoly, const Point& rRef, double tn, bool bVShear = false);
71 
78 inline double GetCrookAngle(Point& rPnt, const Point& rCenter, const Point& rRad, bool bVertical);
79 
87 double CrookRotateXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
88  const Point& rRad, double& rSin, double& rCos, bool bVert);
89 double CrookSlantXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
90  const Point& rRad, double& rSin, double& rCos, bool bVert);
91 double CrookStretchXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
92  const Point& rRad, double& rSin, double& rCos, bool bVert,
93  const tools::Rectangle& rRefRect);
94 
95 void CrookRotatePoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
96 void CrookSlantPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
97 void CrookStretchPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert, const tools::Rectangle& rRefRect);
98 
99 void CrookRotatePoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
100 void CrookSlantPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
101 void CrookStretchPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert, const tools::Rectangle& rRefRect);
102 
103 /**************************************************************************************************/
104 /* Inline */
105 /**************************************************************************************************/
106 
107 inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract)
108 {
109  double nxFract = xFract.IsValid() ? static_cast<double>(xFract) : 1.0;
110  double nyFract = yFract.IsValid() ? static_cast<double>(yFract) : 1.0;
111  rPnt.setX(rRef.X() + FRound( (rPnt.X() - rRef.X()) * nxFract ));
112  rPnt.setY(rRef.Y() + FRound( (rPnt.Y() - rRef.Y()) * nyFract ));
113 }
114 
115 inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs)
116 {
117  tools::Long dx=rPnt.X()-rRef.X();
118  tools::Long dy=rPnt.Y()-rRef.Y();
119  rPnt.setX(FRound(rRef.X()+dx*cs+dy*sn));
120  rPnt.setY(FRound(rRef.Y()+dy*cs-dx*sn));
121 }
122 
123 inline void ShearPoint(Point& rPnt, const Point& rRef, double tn, bool bVShear)
124 {
125  if (!bVShear) { // Horizontal
126  if (rPnt.Y()!=rRef.Y()) { // else not needed
127  rPnt.AdjustX(-FRound((rPnt.Y()-rRef.Y())*tn));
128  }
129  } else { // or else vertical
130  if (rPnt.X()!=rRef.X()) { // else not needed
131  rPnt.AdjustY(-FRound((rPnt.X()-rRef.X())*tn));
132  }
133  }
134 }
135 
136 inline double GetCrookAngle(Point& rPnt, const Point& rCenter, const Point& rRad, bool bVertical)
137 {
138  double nAngle;
139  if (bVertical) {
140  tools::Long dy=rPnt.Y()-rCenter.Y();
141  nAngle=static_cast<double>(dy)/static_cast<double>(rRad.Y());
142  rPnt.setY(rCenter.Y());
143  } else {
144  tools::Long dx=rCenter.X()-rPnt.X();
145  nAngle=static_cast<double>(dx)/static_cast<double>(rRad.X());
146  rPnt.setX(rCenter.X());
147  }
148  return nAngle;
149 }
150 
151 /**************************************************************************************************/
152 /**************************************************************************************************/
153 
163 SVXCORE_DLLPUBLIC Degree100 GetAngle(const Point& rPnt);
164 
166 
168 
169 sal_uInt16 GetAngleSector(Degree100 nAngle);
170 
175 tools::Long GetLen(const Point& rPnt);
176 
215 class GeoStat { // Geometric state for a rect
216 public:
219  double mfTanShearAngle; // tan(nShearAngle)
220  double mfSinRotationAngle; // sin(nRotationAngle)
221  double mfCosRotationAngle; // cos(nRotationAngle)
222 
223  GeoStat(): nRotationAngle(0),nShearAngle(0),mfTanShearAngle(0.0),mfSinRotationAngle(0.0),mfCosRotationAngle(1.0) {}
224  void RecalcSinCos();
225  void RecalcTan();
226 };
227 
228 tools::Polygon Rect2Poly(const tools::Rectangle& rRect, const GeoStat& rGeo);
229 void Poly2Rect(const tools::Polygon& rPol, tools::Rectangle& rRect, GeoStat& rGeo);
230 
231 void OrthoDistance8(const Point& rPt0, Point& rPt, bool bBigOrtho);
232 void OrthoDistance4(const Point& rPt0, Point& rPt, bool bBigOrtho);
233 
234 // Multiplication and subsequent division
235 // Calculation and intermediate values are in BigInt
237 
238 class FrPair {
241 public:
242  FrPair(const Fraction& rBoth) : aX(rBoth),aY(rBoth) {}
243  FrPair(const Fraction& rX, const Fraction& rY) : aX(rX),aY(rY) {}
244  FrPair(tools::Long nMul, tools::Long nDiv) : aX(nMul,nDiv),aY(nMul,nDiv) {}
245  FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv): aX(xMul,xDiv),aY(yMul,yDiv) {}
246  const Fraction& X() const { return aX; }
247  const Fraction& Y() const { return aY; }
248  Fraction& X() { return aX; }
249  Fraction& Y() { return aY; }
250 };
251 
252 // To convert units of measurement
255 
256 inline bool IsMetric(MapUnit eU) {
257  return (eU==MapUnit::Map100thMM || eU==MapUnit::Map10thMM || eU==MapUnit::MapMM || eU==MapUnit::MapCM);
258 }
259 
260 inline bool IsInch(MapUnit eU) {
261  return (eU==MapUnit::Map1000thInch || eU==MapUnit::Map100thInch || eU==MapUnit::Map10thInch || eU==MapUnit::MapInch ||
262  eU==MapUnit::MapPoint || eU==MapUnit::MapTwip);
263 }
264 
265 inline bool IsMetric(FieldUnit eU) {
266  return (eU == FieldUnit::MM || eU == FieldUnit::CM || eU == FieldUnit::M
267  || eU == FieldUnit::KM || eU == FieldUnit::MM_100TH);
268 }
269 
270 inline bool IsInch(FieldUnit eU) {
271  return (eU == FieldUnit::TWIP || eU == FieldUnit::POINT
272  || eU == FieldUnit::PICA || eU == FieldUnit::INCH
273  || eU == FieldUnit::FOOT || eU == FieldUnit::MILE);
274 }
275 
279  short nComma_;
280  bool bDirty;
283 private:
284  SVX_DLLPRIVATE void Undirty();
285 public:
287  : nMul_(0)
288  , nDiv_(0)
289  , nComma_(0)
290  , bDirty(true)
291  , eSrcMU(eSrc)
292  , eDstMU(eDst)
293  {
294  }
295  OUString GetStr(tools::Long nVal) const;
296  static OUString GetUnitStr(MapUnit eUnit);
297  static OUString GetUnitStr(FieldUnit eUnit);
298 };
299 
300 
301 #endif // INCLUDED_SVX_SVDTRANS_HXX
302 
303 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void MoveXPoly(XPolygon &rPoly, const Size &S)
Definition: svdtrans.cxx:32
void OrthoDistance4(const Point &rPt0, Point &rPt, bool bBigOrtho)
Definition: svdtrans.cxx:546
SVXCORE_DLLPUBLIC void RotatePoly(tools::Polygon &rPoly, const Point &rRef, double sn, double cs)
Definition: svdtrans.cxx:80
FieldUnit
FrPair(tools::Long nMul, tools::Long nDiv)
Definition: svdtrans.hxx:244
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:123
tools::Long GetLen(const Point &rPnt)
Determine sector within the cartesian coordinate system.
Definition: svdtrans.cxx:426
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:136
void ResizePoint(Point &rPnt, const Point &rRef, const Fraction &xFract, const Fraction &yFract)
Definition: svdtrans.hxx:107
constexpr Degree100 SDRMAXSHEAR(8900)
long Long
SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle &rRect, const Point &rRef, const Fraction &xFact, const Fraction &yFact)
Definition: svdtrans.cxx:37
double mfSinRotationAngle
Definition: svdtrans.hxx:220
void ResizePoly(tools::Polygon &rPoly, const Point &rRef, const Fraction &xFact, const Fraction &yFact)
Definition: svdtrans.cxx:64
void Move(tools::Long nHorzMove, tools::Long nVertMove)
void ResizeXPoly(XPolygon &rPoly, const Point &rRef, const Fraction &xFact, const Fraction &yFact)
Definition: svdtrans.cxx:72
void RotateXPoly(XPolygon &rPoly, const Point &rRef, double sn, double cs)
Definition: svdtrans.cxx:88
void RecalcTan()
Definition: svdtrans.cxx:464
bool IsMetric(MapUnit eU)
Definition: svdtrans.hxx:256
SVXCORE_DLLPUBLIC tools::Long BigMulDiv(tools::Long nVal, tools::Long nMul, tools::Long nDiv)
Definition: svdtrans.cxx:560
FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv)
Definition: svdtrans.hxx:245
SVXCORE_DLLPUBLIC void ShearPoly(tools::Polygon &rPoly, const Point &rRef, double tn)
Definition: svdtrans.cxx:146
The transformation of a rectangle into a polygon, by using angle parameters from GeoStat.
Definition: svdtrans.hxx:215
double mfTanShearAngle
Definition: svdtrans.hxx:219
void MirrorXPoly(XPolygon &rPoly, const Point &rRef1, const Point &rRef2)
Definition: svdtrans.cxx:138
void ShearXPoly(XPolygon &rPoly, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.cxx:154
Fraction aY
Definition: svdtrans.hxx:240
void MirrorPoint(Point &rPnt, const Point &rRef1, const Point &rRef2)
Definition: svdtrans.cxx:104
void OrthoDistance8(const Point &rPt0, Point &rPt, bool bBigOrtho)
Definition: svdtrans.cxx:530
MapUnit eSrcMU
Definition: svdtrans.hxx:281
SVXCORE_DLLPUBLIC Degree100 NormAngle36000(Degree100 a)
Normalize angle to -180.00..179.99.
Definition: svdtrans.cxx:408
short nComma_
Definition: svdtrans.hxx:279
void Poly2Rect(const tools::Polygon &rPol, tools::Rectangle &rRect, GeoStat &rGeo)
Definition: svdtrans.cxx:488
const Fraction & Y() const
Definition: svdtrans.hxx:247
tools::Long FRound(double fVal)
Degree100 NormAngle18000(Degree100 a)
Definition: svdtrans.cxx:401
Fraction & Y()
Definition: svdtrans.hxx:249
Fraction & X()
Definition: svdtrans.hxx:248
FrPair(const Fraction &rBoth)
Definition: svdtrans.hxx:242
const Fraction & X() const
Definition: svdtrans.hxx:246
void CrookStretchPoly(XPolygon &rPoly, const Point &rCenter, const Point &rRad, bool bVert, const tools::Rectangle &rRefRect)
Definition: svdtrans.cxx:337
tools::Long Width() const
MapUnit eDstMU
Definition: svdtrans.hxx:282
sal_uInt16 GetAngleSector(Degree100 nAngle)
Normalize angle to 0.00..359.99.
Definition: svdtrans.cxx:417
tools::Polygon Rect2Poly(const tools::Rectangle &rRect, const GeoStat &rGeo)
Definition: svdtrans.cxx:475
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:271
void MovePoly(tools::Polygon &rPoly, const Size &S)
Definition: svdtrans.hxx:52
SdrFormatter(MapUnit eSrc, MapUnit eDst)
Definition: svdtrans.hxx:286
SVXCORE_DLLPUBLIC FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:624
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:115
tools::Long nMul_
Definition: svdtrans.hxx:277
FrPair(const Fraction &rX, const Fraction &rY)
Definition: svdtrans.hxx:243
void RecalcSinCos()
Definition: svdtrans.cxx:452
Degree100 nRotationAngle
Definition: svdtrans.hxx:217
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
double mfCosRotationAngle
Definition: svdtrans.hxx:221
tools::Long Height() const
tools::Long nDiv_
Definition: svdtrans.hxx:278
bool IsInch(MapUnit eU)
Definition: svdtrans.hxx:260
double CrookSlantXPoint(Point &rPnt, Point *pC1, Point *pC2, const Point &rCenter, const Point &rRad, double &rSin, double &rCos, bool bVert)
Definition: svdtrans.cxx:216
Fraction aX
Definition: svdtrans.hxx:239
MapUnit
bool IsValid() const
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:162
#define SVX_DLLPRIVATE
Definition: svxdllapi.h:30
Degree100 nShearAngle
Definition: svdtrans.hxx:218
void CrookRotatePoly(XPolygon &rPoly, const Point &rCenter, const Point &rRad, bool bVert)
Definition: svdtrans.cxx:291
void CrookSlantPoly(XPolygon &rPoly, const Point &rCenter, const Point &rRad, bool bVert)
Definition: svdtrans.cxx:314
SVXCORE_DLLPUBLIC Degree100 GetAngle(const Point &rPnt)
The Y axis points down! The function negates the Y axis, when calculating the angle, such that GetAngle(Point(0,-1))=90 deg.
Definition: svdtrans.cxx:386