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