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
33 constexpr Degree100 SDRMAXSHEAR(8900);
34 
35 class XPolygon;
36 class XPolyPolygon;
37 
38 inline void MovePoly(tools::Polygon& rPoly, const Size& S) { rPoly.Move(S.Width(),S.Height()); }
39 void MoveXPoly(XPolygon& rPoly, const Size& S);
40 
41 SVXCORE_DLLPUBLIC void ResizeRect(tools::Rectangle& rRect, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
42 inline void ResizePoint(Point& rPnt, const Point& rRef, const Fraction& xFract, const Fraction& yFract);
43 void ResizePoly(tools::Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
44 void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact);
45 
46 inline void RotatePoint(Point& rPnt, const Point& rRef, double sn, double cs);
47 SVXCORE_DLLPUBLIC void RotatePoly(tools::Polygon& rPoly, const Point& rRef, double sn, double cs);
48 void RotateXPoly(XPolygon& rPoly, const Point& rRef, double sn, double cs);
49 void RotateXPoly(XPolyPolygon& rPoly, const Point& rRef, double sn, double cs);
50 
51 void MirrorPoint(Point& rPnt, const Point& rRef1, const Point& rRef2);
52 void MirrorXPoly(XPolygon& rPoly, const Point& rRef1, const Point& rRef2);
53 
54 inline void ShearPoint(Point& rPnt, const Point& rRef, double tn, bool bVShear = false);
55 SVXCORE_DLLPUBLIC void ShearPoly(tools::Polygon& rPoly, const Point& rRef, double tn);
56 void ShearXPoly(XPolygon& rPoly, const Point& rRef, double tn, bool bVShear = false);
57 
64 inline double GetCrookAngle(Point& rPnt, const Point& rCenter, const Point& rRad, bool bVertical);
65 
73 double CrookRotateXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
74  const Point& rRad, double& rSin, double& rCos, bool bVert);
75 double CrookSlantXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
76  const Point& rRad, double& rSin, double& rCos, bool bVert);
77 double 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 
81 void CrookRotatePoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
82 void CrookSlantPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
83 void CrookStretchPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert, const tools::Rectangle& rRefRect);
84 
85 void CrookRotatePoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
86 void CrookSlantPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert);
87 void CrookStretchPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, bool bVert, const tools::Rectangle& rRefRect);
88 
89 /**************************************************************************************************/
90 /* Inline */
91 /**************************************************************************************************/
92 
93 inline 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 
101 inline 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 
109 inline 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 
122 inline 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 
149 SVXCORE_DLLPUBLIC Degree100 GetAngle(const Point& rPnt);
150 
152 
154 
155 sal_uInt16 GetAngleSector(Degree100 nAngle);
156 
161 tools::Long GetLen(const Point& rPnt);
162 
201 class GeoStat { // Geometric state for a rect
202 public:
205  double mfTanShearAngle; // tan(nShearAngle)
206  double mfSinRotationAngle; // sin(nRotationAngle)
207  double mfCosRotationAngle; // cos(nRotationAngle)
208 
209  GeoStat(): nRotationAngle(0),nShearAngle(0),mfTanShearAngle(0.0),mfSinRotationAngle(0.0),mfCosRotationAngle(1.0) {}
210  void RecalcSinCos();
211  void RecalcTan();
212 };
213 
214 tools::Polygon Rect2Poly(const tools::Rectangle& rRect, const GeoStat& rGeo);
215 void Poly2Rect(const tools::Polygon& rPol, tools::Rectangle& rRect, GeoStat& rGeo);
216 
217 void OrthoDistance8(const Point& rPt0, Point& rPt, bool bBigOrtho);
218 void OrthoDistance4(const Point& rPt0, Point& rPt, bool bBigOrtho);
219 
220 // Multiplication and subsequent division
221 // Calculation and intermediate values are in BigInt
223 
224 class FrPair {
227 public:
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 
242 inline bool IsMetric(MapUnit eU) {
243  return (eU==MapUnit::Map100thMM || eU==MapUnit::Map10thMM || eU==MapUnit::MapMM || eU==MapUnit::MapCM);
244 }
245 
246 inline 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 
251 inline 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 
256 inline 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;
269 private:
270  SVX_DLLPRIVATE void Undirty();
271 public:
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: */
void MoveXPoly(XPolygon &rPoly, const Size &S)
Definition: svdtrans.cxx:33
void OrthoDistance4(const Point &rPt0, Point &rPt, bool bBigOrtho)
Definition: svdtrans.cxx:538
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:230
void ShearPoint(Point &rPnt, const Point &rRef, double tn, bool bVShear=false)
Definition: svdtrans.hxx:109
tools::Long GetLen(const Point &rPnt)
Determine sector within the cartesian coordinate system.
Definition: svdtrans.cxx:418
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
void ResizePoint(Point &rPnt, const Point &rRef, const Fraction &xFract, const Fraction &yFract)
Definition: svdtrans.hxx:93
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:206
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:456
bool IsMetric(MapUnit eU)
Definition: svdtrans.hxx:242
SVXCORE_DLLPUBLIC tools::Long BigMulDiv(tools::Long nVal, tools::Long nMul, tools::Long nDiv)
Definition: svdtrans.cxx:552
FrPair(tools::Long xMul, tools::Long xDiv, tools::Long yMul, tools::Long yDiv)
Definition: svdtrans.hxx:231
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:201
double mfTanShearAngle
Definition: svdtrans.hxx:205
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:226
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:522
MapUnit eSrcMU
Definition: svdtrans.hxx:267
SVXCORE_DLLPUBLIC Degree100 NormAngle36000(Degree100 a)
Normalize angle to -180.00..179.99.
Definition: svdtrans.cxx:408
short nComma_
Definition: svdtrans.hxx:265
void Poly2Rect(const tools::Polygon &rPol, tools::Rectangle &rRect, GeoStat &rGeo)
Definition: svdtrans.cxx:480
const Fraction & Y() const
Definition: svdtrans.hxx:233
tools::Long FRound(double fVal)
Degree100 NormAngle18000(Degree100 a)
Definition: svdtrans.cxx:401
Fraction & Y()
Definition: svdtrans.hxx:235
Fraction & X()
Definition: svdtrans.hxx:234
FrPair(const Fraction &rBoth)
Definition: svdtrans.hxx:228
const Fraction & X() const
Definition: svdtrans.hxx:232
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:268
sal_uInt16 GetAngleSector(Degree100 nAngle)
Normalize angle to 0.00..359.99.
Definition: svdtrans.cxx:416
tools::Polygon Rect2Poly(const tools::Rectangle &rRect, const GeoStat &rGeo)
Definition: svdtrans.cxx:467
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:38
SdrFormatter(MapUnit eSrc, MapUnit eDst)
Definition: svdtrans.hxx:272
SVXCORE_DLLPUBLIC FrPair GetMapFactor(MapUnit eS, MapUnit eD)
Definition: svdtrans.cxx:603
void RotatePoint(Point &rPnt, const Point &rRef, double sn, double cs)
Definition: svdtrans.hxx:101
tools::Long nMul_
Definition: svdtrans.hxx:263
constexpr tools::Long Height() const
FrPair(const Fraction &rX, const Fraction &rY)
Definition: svdtrans.hxx:229
void RecalcSinCos()
Definition: svdtrans.cxx:444
Degree100 nRotationAngle
Definition: svdtrans.hxx:203
#define SVXCORE_DLLPUBLIC
Definition: svxdllapi.h:35
double mfCosRotationAngle
Definition: svdtrans.hxx:207
tools::Long nDiv_
Definition: svdtrans.hxx:264
bool IsInch(MapUnit eU)
Definition: svdtrans.hxx:246
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:225
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:204
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