xref: /trunk/main/svx/source/svdraw/svdtrans.cxx (revision 8009be2efa01d939bad715ff6a0615a6151d3b9f)
1f6e50924SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f6e50924SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f6e50924SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f6e50924SAndrew Rist  * distributed with this work for additional information
6f6e50924SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f6e50924SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f6e50924SAndrew Rist  * "License"); you may not use this file except in compliance
9f6e50924SAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11f6e50924SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13f6e50924SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f6e50924SAndrew Rist  * software distributed under the License is distributed on an
15f6e50924SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f6e50924SAndrew Rist  * KIND, either express or implied.  See the License for the
17f6e50924SAndrew Rist  * specific language governing permissions and limitations
18f6e50924SAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20f6e50924SAndrew Rist  *************************************************************/
21f6e50924SAndrew Rist 
22cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
23cdf0e10cSrcweir #include "precompiled_svx.hxx"
24cdf0e10cSrcweir 
25cdf0e10cSrcweir #include <svx/svdtrans.hxx>
26cdf0e10cSrcweir #include <math.h>
27cdf0e10cSrcweir #include <svx/xpoly.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <vcl/virdev.hxx>
30cdf0e10cSrcweir #include <tools/bigint.hxx>
31cdf0e10cSrcweir #include <tools/debug.hxx>
32cdf0e10cSrcweir #include <unotools/syslocale.hxx>
33cdf0e10cSrcweir 
MoveXPoly(XPolygon & rPoly,const Size & S)34cdf0e10cSrcweir void MoveXPoly(XPolygon& rPoly, const Size& S)
35cdf0e10cSrcweir {
36cdf0e10cSrcweir     rPoly.Move(S.Width(),S.Height());
37cdf0e10cSrcweir }
38cdf0e10cSrcweir 
MoveXPoly(XPolyPolygon & rPoly,const Size & S)39cdf0e10cSrcweir void MoveXPoly(XPolyPolygon& rPoly, const Size& S)
40cdf0e10cSrcweir {
41cdf0e10cSrcweir     rPoly.Move(S.Width(),S.Height());
42cdf0e10cSrcweir }
43cdf0e10cSrcweir 
44cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
45cdf0e10cSrcweir 
ResizeRect(Rectangle & rRect,const Point & rRef,const Fraction & rxFact,const Fraction & ryFact,FASTBOOL bNoJustify)46cdf0e10cSrcweir void ResizeRect(Rectangle& rRect, const Point& rRef, const Fraction& rxFact, const Fraction& ryFact, FASTBOOL bNoJustify)
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     Fraction xFact(rxFact);
49cdf0e10cSrcweir     Fraction yFact(ryFact);
50cdf0e10cSrcweir     //long nHgt=rRect.Bottom()-rRect.Top();
51cdf0e10cSrcweir 
52cdf0e10cSrcweir     {
53cdf0e10cSrcweir         if (xFact.GetDenominator()==0) {
54cdf0e10cSrcweir             long nWdt=rRect.Right()-rRect.Left();
55cdf0e10cSrcweir             if (xFact.GetNumerator()>=0) { // DivZero abfangen
56cdf0e10cSrcweir                 xFact=Fraction(xFact.GetNumerator(),1);
57cdf0e10cSrcweir                 if (nWdt==0) rRect.Right()++;
58cdf0e10cSrcweir             } else {
59cdf0e10cSrcweir                 xFact=Fraction(xFact.GetNumerator(),-1);
60cdf0e10cSrcweir                 if (nWdt==0) rRect.Left()--;
61cdf0e10cSrcweir             }
62cdf0e10cSrcweir         }
63cdf0e10cSrcweir         rRect.Left()  =rRef.X()+Round(((double)(rRect.Left()  -rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
64cdf0e10cSrcweir         rRect.Right() =rRef.X()+Round(((double)(rRect.Right() -rRef.X())*xFact.GetNumerator())/xFact.GetDenominator());
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir     {
67cdf0e10cSrcweir         if (yFact.GetDenominator()==0) {
68cdf0e10cSrcweir             long nHgt=rRect.Bottom()-rRect.Top();
69cdf0e10cSrcweir             if (yFact.GetNumerator()>=0) { // DivZero abfangen
70cdf0e10cSrcweir                 yFact=Fraction(yFact.GetNumerator(),1);
71cdf0e10cSrcweir                 if (nHgt==0) rRect.Bottom()++;
72cdf0e10cSrcweir             } else {
73cdf0e10cSrcweir                 yFact=Fraction(yFact.GetNumerator(),-1);
74cdf0e10cSrcweir                 if (nHgt==0) rRect.Top()--;
75cdf0e10cSrcweir             }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir             yFact=Fraction(yFact.GetNumerator(),1); // DivZero abfangen
78cdf0e10cSrcweir         }
79cdf0e10cSrcweir         rRect.Top()   =rRef.Y()+Round(((double)(rRect.Top()   -rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
80cdf0e10cSrcweir         rRect.Bottom()=rRef.Y()+Round(((double)(rRect.Bottom()-rRef.Y())*yFact.GetNumerator())/yFact.GetDenominator());
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir     if (!bNoJustify) rRect.Justify();
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
ResizePoly(Polygon & rPoly,const Point & rRef,const Fraction & xFact,const Fraction & yFact)86cdf0e10cSrcweir void ResizePoly(Polygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetSize();
89cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
90cdf0e10cSrcweir         ResizePoint(rPoly[i],rRef,xFact,yFact);
91cdf0e10cSrcweir     }
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
ResizeXPoly(XPolygon & rPoly,const Point & rRef,const Fraction & xFact,const Fraction & yFact)94cdf0e10cSrcweir void ResizeXPoly(XPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
95cdf0e10cSrcweir {
96cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetPointCount();
97cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
98cdf0e10cSrcweir         ResizePoint(rPoly[i],rRef,xFact,yFact);
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
ResizePoly(PolyPolygon & rPoly,const Point & rRef,const Fraction & xFact,const Fraction & yFact)102cdf0e10cSrcweir void ResizePoly(PolyPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
105cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
106cdf0e10cSrcweir         ResizePoly(rPoly[i],rRef,xFact,yFact);
107cdf0e10cSrcweir     }
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
ResizeXPoly(XPolyPolygon & rPoly,const Point & rRef,const Fraction & xFact,const Fraction & yFact)110cdf0e10cSrcweir void ResizeXPoly(XPolyPolygon& rPoly, const Point& rRef, const Fraction& xFact, const Fraction& yFact)
111cdf0e10cSrcweir {
112cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
113cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
114cdf0e10cSrcweir         ResizeXPoly(rPoly[i],rRef,xFact,yFact);
115cdf0e10cSrcweir     }
116cdf0e10cSrcweir }
117cdf0e10cSrcweir 
118cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
119cdf0e10cSrcweir 
RotatePoly(Polygon & rPoly,const Point & rRef,double sn,double cs)120cdf0e10cSrcweir void RotatePoly(Polygon& rPoly, const Point& rRef, double sn, double cs)
121cdf0e10cSrcweir {
122cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetSize();
123cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
124cdf0e10cSrcweir         RotatePoint(rPoly[i],rRef,sn,cs);
125cdf0e10cSrcweir     }
126cdf0e10cSrcweir }
127cdf0e10cSrcweir 
RotateXPoly(XPolygon & rPoly,const Point & rRef,double sn,double cs)128cdf0e10cSrcweir void RotateXPoly(XPolygon& rPoly, const Point& rRef, double sn, double cs)
129cdf0e10cSrcweir {
130cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetPointCount();
131cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
132cdf0e10cSrcweir         RotatePoint(rPoly[i],rRef,sn,cs);
133cdf0e10cSrcweir     }
134cdf0e10cSrcweir }
135cdf0e10cSrcweir 
RotatePoly(PolyPolygon & rPoly,const Point & rRef,double sn,double cs)136cdf0e10cSrcweir void RotatePoly(PolyPolygon& rPoly, const Point& rRef, double sn, double cs)
137cdf0e10cSrcweir {
138cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
139cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
140cdf0e10cSrcweir         RotatePoly(rPoly[i],rRef,sn,cs);
141cdf0e10cSrcweir     }
142cdf0e10cSrcweir }
143cdf0e10cSrcweir 
RotateXPoly(XPolyPolygon & rPoly,const Point & rRef,double sn,double cs)144cdf0e10cSrcweir void RotateXPoly(XPolyPolygon& rPoly, const Point& rRef, double sn, double cs)
145cdf0e10cSrcweir {
146cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
147cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
148cdf0e10cSrcweir         RotateXPoly(rPoly[i],rRef,sn,cs);
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
153cdf0e10cSrcweir 
MirrorRect(Rectangle & rRect,const Point &,const Point &,FASTBOOL bNoJustify)154cdf0e10cSrcweir void MirrorRect(Rectangle& rRect, const Point& /*rRef1*/, const Point& /*rRef2*/, FASTBOOL bNoJustify)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir     // !!! fehlende Implementation !!!
157cdf0e10cSrcweir     if (!bNoJustify) rRect.Justify();
158cdf0e10cSrcweir }
159cdf0e10cSrcweir 
MirrorPoint(Point & rPnt,const Point & rRef1,const Point & rRef2)160cdf0e10cSrcweir void MirrorPoint(Point& rPnt, const Point& rRef1, const Point& rRef2)
161cdf0e10cSrcweir {
162cdf0e10cSrcweir     long mx=rRef2.X()-rRef1.X();
163cdf0e10cSrcweir     long my=rRef2.Y()-rRef1.Y();
164cdf0e10cSrcweir     if (mx==0) { // Achse senkrecht
165cdf0e10cSrcweir         long dx=rRef1.X()-rPnt.X();
166cdf0e10cSrcweir         rPnt.X()+=2*dx;
167cdf0e10cSrcweir     } else if (my==0) { // Achse waagerecht
168cdf0e10cSrcweir         long dy=rRef1.Y()-rPnt.Y();
169cdf0e10cSrcweir         rPnt.Y()+=2*dy;
170cdf0e10cSrcweir     } else if (mx==my) { // Achse diagonal '\'
171cdf0e10cSrcweir         long dx1=rPnt.X()-rRef1.X();
172cdf0e10cSrcweir         long dy1=rPnt.Y()-rRef1.Y();
173cdf0e10cSrcweir         rPnt.X()=rRef1.X()+dy1;
174cdf0e10cSrcweir         rPnt.Y()=rRef1.Y()+dx1;
175cdf0e10cSrcweir     } else if (mx==-my) { // Achse diagonal '/'
176cdf0e10cSrcweir         long dx1=rPnt.X()-rRef1.X();
177cdf0e10cSrcweir         long dy1=rPnt.Y()-rRef1.Y();
178cdf0e10cSrcweir         rPnt.X()=rRef1.X()-dy1;
179cdf0e10cSrcweir         rPnt.Y()=rRef1.Y()-dx1;
180cdf0e10cSrcweir     } else { // beliebige Achse
181cdf0e10cSrcweir         // mal optimieren !!!
1828d647522Smseidel         // Lot auf der Spiegelachse fällen oder so
183cdf0e10cSrcweir         long nRefWink=GetAngle(rRef2-rRef1);
184cdf0e10cSrcweir         rPnt-=rRef1;
185cdf0e10cSrcweir         long nPntWink=GetAngle(rPnt);
186cdf0e10cSrcweir         long nWink=2*(nRefWink-nPntWink);
187cdf0e10cSrcweir         double a=nWink*nPi180;
188cdf0e10cSrcweir         double nSin=sin(a);
189cdf0e10cSrcweir         double nCos=cos(a);
190cdf0e10cSrcweir         RotatePoint(rPnt,Point(),nSin,nCos);
191cdf0e10cSrcweir         rPnt+=rRef1;
192cdf0e10cSrcweir     }
193cdf0e10cSrcweir }
194cdf0e10cSrcweir 
MirrorPoly(Polygon & rPoly,const Point & rRef1,const Point & rRef2)195cdf0e10cSrcweir void MirrorPoly(Polygon& rPoly, const Point& rRef1, const Point& rRef2)
196cdf0e10cSrcweir {
197cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetSize();
198cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
199cdf0e10cSrcweir         MirrorPoint(rPoly[i],rRef1,rRef2);
200cdf0e10cSrcweir     }
201cdf0e10cSrcweir }
202cdf0e10cSrcweir 
MirrorXPoly(XPolygon & rPoly,const Point & rRef1,const Point & rRef2)203cdf0e10cSrcweir void MirrorXPoly(XPolygon& rPoly, const Point& rRef1, const Point& rRef2)
204cdf0e10cSrcweir {
205cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetPointCount();
206cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
207cdf0e10cSrcweir         MirrorPoint(rPoly[i],rRef1,rRef2);
208cdf0e10cSrcweir     }
209cdf0e10cSrcweir }
210cdf0e10cSrcweir 
MirrorPoly(PolyPolygon & rPoly,const Point & rRef1,const Point & rRef2)211cdf0e10cSrcweir void MirrorPoly(PolyPolygon& rPoly, const Point& rRef1, const Point& rRef2)
212cdf0e10cSrcweir {
213cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
214cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
215cdf0e10cSrcweir         MirrorPoly(rPoly[i],rRef1,rRef2);
216cdf0e10cSrcweir     }
217cdf0e10cSrcweir }
218cdf0e10cSrcweir 
MirrorXPoly(XPolyPolygon & rPoly,const Point & rRef1,const Point & rRef2)219cdf0e10cSrcweir void MirrorXPoly(XPolyPolygon& rPoly, const Point& rRef1, const Point& rRef2)
220cdf0e10cSrcweir {
221cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
222cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
223cdf0e10cSrcweir         MirrorXPoly(rPoly[i],rRef1,rRef2);
224cdf0e10cSrcweir     }
225cdf0e10cSrcweir }
226cdf0e10cSrcweir 
227cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
228cdf0e10cSrcweir 
ShearPoly(Polygon & rPoly,const Point & rRef,double tn,FASTBOOL bVShear)229cdf0e10cSrcweir void ShearPoly(Polygon& rPoly, const Point& rRef, double tn, FASTBOOL bVShear)
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetSize();
232cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
233cdf0e10cSrcweir         ShearPoint(rPoly[i],rRef,tn,bVShear);
234cdf0e10cSrcweir     }
235cdf0e10cSrcweir }
236cdf0e10cSrcweir 
ShearXPoly(XPolygon & rPoly,const Point & rRef,double tn,FASTBOOL bVShear)237cdf0e10cSrcweir void ShearXPoly(XPolygon& rPoly, const Point& rRef, double tn, FASTBOOL bVShear)
238cdf0e10cSrcweir {
239cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.GetPointCount();
240cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
241cdf0e10cSrcweir         ShearPoint(rPoly[i],rRef,tn,bVShear);
242cdf0e10cSrcweir     }
243cdf0e10cSrcweir }
244cdf0e10cSrcweir 
ShearPoly(PolyPolygon & rPoly,const Point & rRef,double tn,FASTBOOL bVShear)245cdf0e10cSrcweir void ShearPoly(PolyPolygon& rPoly, const Point& rRef, double tn, FASTBOOL bVShear)
246cdf0e10cSrcweir {
247cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
248cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
249cdf0e10cSrcweir         ShearPoly(rPoly[i],rRef,tn,bVShear);
250cdf0e10cSrcweir     }
251cdf0e10cSrcweir }
252cdf0e10cSrcweir 
ShearXPoly(XPolyPolygon & rPoly,const Point & rRef,double tn,FASTBOOL bVShear)253cdf0e10cSrcweir void ShearXPoly(XPolyPolygon& rPoly, const Point& rRef, double tn, FASTBOOL bVShear)
254cdf0e10cSrcweir {
255cdf0e10cSrcweir     sal_uInt16 nAnz=rPoly.Count();
256cdf0e10cSrcweir     for (sal_uInt16 i=0; i<nAnz; i++) {
257cdf0e10cSrcweir         ShearXPoly(rPoly[i],rRef,tn,bVShear);
258cdf0e10cSrcweir     }
259cdf0e10cSrcweir }
260cdf0e10cSrcweir 
261cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
2628d647522Smseidel // CROOK
263cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
264cdf0e10cSrcweir 
CrookRotateXPoint(Point & rPnt,Point * pC1,Point * pC2,const Point & rCenter,const Point & rRad,double & rSin,double & rCos,FASTBOOL bVert)265cdf0e10cSrcweir double CrookRotateXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
266cdf0e10cSrcweir                          const Point& rRad, double& rSin, double& rCos, FASTBOOL bVert)
267cdf0e10cSrcweir {
268cdf0e10cSrcweir     FASTBOOL bC1=pC1!=NULL;
269cdf0e10cSrcweir     FASTBOOL bC2=pC2!=NULL;
270cdf0e10cSrcweir     long x0=rPnt.X();
271cdf0e10cSrcweir     long y0=rPnt.Y();
272cdf0e10cSrcweir     long cx=rCenter.X();
273cdf0e10cSrcweir     long cy=rCenter.Y();
274cdf0e10cSrcweir     double nWink=GetCrookAngle(rPnt,rCenter,rRad,bVert);
275cdf0e10cSrcweir     double sn=sin(nWink);
276cdf0e10cSrcweir     double cs=cos(nWink);
277cdf0e10cSrcweir     RotatePoint(rPnt,rCenter,sn,cs);
278cdf0e10cSrcweir     if (bC1) {
279cdf0e10cSrcweir         if (bVert) {
2808d647522Smseidel             // Richtung Zentrum verschieben, als Ausgangsposition für Rotate
281cdf0e10cSrcweir             pC1->Y()-=y0;
282cdf0e10cSrcweir             // Resize, entsprechend der Entfernung vom Zentrum
283cdf0e10cSrcweir             pC1->Y()=Round(((double)pC1->Y()) /rRad.X()*(cx-pC1->X()));
284cdf0e10cSrcweir             pC1->Y()+=cy;
285cdf0e10cSrcweir         } else {
2868d647522Smseidel             // Richtung Zentrum verschieben, als Ausgangsposition für Rotate
287cdf0e10cSrcweir             pC1->X()-=x0;
288cdf0e10cSrcweir             // Resize, entsprechend der Entfernung vom Zentrum
289cdf0e10cSrcweir             long nPntRad=cy-pC1->Y();
290cdf0e10cSrcweir             double nFact=(double)nPntRad/(double)rRad.Y();
291cdf0e10cSrcweir             pC1->X()=Round((double)pC1->X()*nFact);
292cdf0e10cSrcweir             pC1->X()+=cx;
293cdf0e10cSrcweir         }
294cdf0e10cSrcweir         RotatePoint(*pC1,rCenter,sn,cs);
295cdf0e10cSrcweir     }
296cdf0e10cSrcweir     if (bC2) {
297cdf0e10cSrcweir         if (bVert) {
2988d647522Smseidel             // Richtung Zentrum verschieben, als Ausgangsposition für Rotate
299cdf0e10cSrcweir             pC2->Y()-=y0;
300cdf0e10cSrcweir             // Resize, entsprechend der Entfernung vom Zentrum
301cdf0e10cSrcweir             pC2->Y()=Round(((double)pC2->Y()) /rRad.X()*(rCenter.X()-pC2->X()));
302cdf0e10cSrcweir             pC2->Y()+=cy;
303cdf0e10cSrcweir         } else {
3048d647522Smseidel             // Richtung Zentrum verschieben, als Ausgangsposition für Rotate
305cdf0e10cSrcweir             pC2->X()-=x0;
306cdf0e10cSrcweir             // Resize, entsprechend der Entfernung vom Zentrum
307cdf0e10cSrcweir             long nPntRad=rCenter.Y()-pC2->Y();
308cdf0e10cSrcweir             double nFact=(double)nPntRad/(double)rRad.Y();
309cdf0e10cSrcweir             pC2->X()=Round((double)pC2->X()*nFact);
310cdf0e10cSrcweir             pC2->X()+=cx;
311cdf0e10cSrcweir         }
312cdf0e10cSrcweir         RotatePoint(*pC2,rCenter,sn,cs);
313cdf0e10cSrcweir     }
314cdf0e10cSrcweir     rSin=sn;
315cdf0e10cSrcweir     rCos=cs;
316cdf0e10cSrcweir     return nWink;
317cdf0e10cSrcweir }
318cdf0e10cSrcweir 
CrookSlantXPoint(Point & rPnt,Point * pC1,Point * pC2,const Point & rCenter,const Point & rRad,double & rSin,double & rCos,FASTBOOL bVert)319cdf0e10cSrcweir double CrookSlantXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
320cdf0e10cSrcweir                         const Point& rRad, double& rSin, double& rCos, FASTBOOL bVert)
321cdf0e10cSrcweir {
322cdf0e10cSrcweir     FASTBOOL bC1=pC1!=NULL;
323cdf0e10cSrcweir     FASTBOOL bC2=pC2!=NULL;
324cdf0e10cSrcweir     long x0=rPnt.X();
325cdf0e10cSrcweir     long y0=rPnt.Y();
326cdf0e10cSrcweir     long dx1=0,dy1=0;
327cdf0e10cSrcweir     long dxC1=0,dyC1=0;
328cdf0e10cSrcweir     long dxC2=0,dyC2=0;
329cdf0e10cSrcweir     if (bVert) {
330cdf0e10cSrcweir         long nStart=rCenter.X()-rRad.X();
331cdf0e10cSrcweir         dx1=rPnt.X()-nStart;
332cdf0e10cSrcweir         rPnt.X()=nStart;
333cdf0e10cSrcweir         if (bC1) {
334cdf0e10cSrcweir             dxC1=pC1->X()-nStart;
335cdf0e10cSrcweir             pC1->X()=nStart;
336cdf0e10cSrcweir         }
337cdf0e10cSrcweir         if (bC2) {
338cdf0e10cSrcweir             dxC2=pC2->X()-nStart;
339cdf0e10cSrcweir             pC2->X()=nStart;
340cdf0e10cSrcweir         }
341cdf0e10cSrcweir     } else {
342cdf0e10cSrcweir         long nStart=rCenter.Y()-rRad.Y();
343cdf0e10cSrcweir         dy1=rPnt.Y()-nStart;
344cdf0e10cSrcweir         rPnt.Y()=nStart;
345cdf0e10cSrcweir         if (bC1) {
346cdf0e10cSrcweir             dyC1=pC1->Y()-nStart;
347cdf0e10cSrcweir             pC1->Y()=nStart;
348cdf0e10cSrcweir         }
349cdf0e10cSrcweir         if (bC2) {
350cdf0e10cSrcweir             dyC2=pC2->Y()-nStart;
351cdf0e10cSrcweir             pC2->Y()=nStart;
352cdf0e10cSrcweir         }
353cdf0e10cSrcweir     }
354cdf0e10cSrcweir     double nWink=GetCrookAngle(rPnt,rCenter,rRad,bVert);
355cdf0e10cSrcweir     double sn=sin(nWink);
356cdf0e10cSrcweir     double cs=cos(nWink);
357cdf0e10cSrcweir     RotatePoint(rPnt,rCenter,sn,cs);
358cdf0e10cSrcweir     if (bC1) { if (bVert) pC1->Y()-=y0-rCenter.Y(); else pC1->X()-=x0-rCenter.X(); RotatePoint(*pC1,rCenter,sn,cs); }
359cdf0e10cSrcweir     if (bC2) { if (bVert) pC2->Y()-=y0-rCenter.Y(); else pC2->X()-=x0-rCenter.X(); RotatePoint(*pC2,rCenter,sn,cs); }
360cdf0e10cSrcweir     if (bVert) {
361cdf0e10cSrcweir         rPnt.X()+=dx1;
362cdf0e10cSrcweir         if (bC1) pC1->X()+=dxC1;
363cdf0e10cSrcweir         if (bC2) pC2->X()+=dxC2;
364cdf0e10cSrcweir     } else {
365cdf0e10cSrcweir         rPnt.Y()+=dy1;
366cdf0e10cSrcweir         if (bC1) pC1->Y()+=dyC1;
367cdf0e10cSrcweir         if (bC2) pC2->Y()+=dyC2;
368cdf0e10cSrcweir     }
369cdf0e10cSrcweir     rSin=sn;
370cdf0e10cSrcweir     rCos=cs;
371cdf0e10cSrcweir     return nWink;
372cdf0e10cSrcweir }
373cdf0e10cSrcweir 
CrookStretchXPoint(Point & rPnt,Point * pC1,Point * pC2,const Point & rCenter,const Point & rRad,double & rSin,double & rCos,FASTBOOL bVert,const Rectangle rRefRect)374cdf0e10cSrcweir double CrookStretchXPoint(Point& rPnt, Point* pC1, Point* pC2, const Point& rCenter,
375cdf0e10cSrcweir                           const Point& rRad, double& rSin, double& rCos, FASTBOOL bVert,
376cdf0e10cSrcweir                           const Rectangle rRefRect)
377cdf0e10cSrcweir {
378cdf0e10cSrcweir     //FASTBOOL bC1=pC1!=NULL;
379cdf0e10cSrcweir     //FASTBOOL bC2=pC2!=NULL;
380cdf0e10cSrcweir     //long x0=rPnt.X();
381cdf0e10cSrcweir     long y0=rPnt.Y();
382cdf0e10cSrcweir     CrookSlantXPoint(rPnt,pC1,pC2,rCenter,rRad,rSin,rCos,bVert);
383cdf0e10cSrcweir     if (bVert) {
384cdf0e10cSrcweir     } else {
385cdf0e10cSrcweir         //long nBase=rCenter.Y()-rRad.Y();
386cdf0e10cSrcweir         long nTop=rRefRect.Top();
387cdf0e10cSrcweir         long nBtm=rRefRect.Bottom();
388cdf0e10cSrcweir         long nHgt=nBtm-nTop;
389cdf0e10cSrcweir         long dy=rPnt.Y()-y0;
390cdf0e10cSrcweir         //FASTBOOL bOben=rRad.Y()<0;
391cdf0e10cSrcweir         double a=((double)(y0-nTop))/nHgt;
392cdf0e10cSrcweir         a*=dy;
393cdf0e10cSrcweir         rPnt.Y()=y0+Round(a);
394cdf0e10cSrcweir     } return 0.0;
395cdf0e10cSrcweir }
396cdf0e10cSrcweir 
397cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
398cdf0e10cSrcweir 
CrookRotatePoly(XPolygon & rPoly,const Point & rCenter,const Point & rRad,FASTBOOL bVert)399cdf0e10cSrcweir void CrookRotatePoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, FASTBOOL bVert)
400cdf0e10cSrcweir {
401cdf0e10cSrcweir     double nSin,nCos;
4027a060572Smseidel     sal_uInt16 nPointCount=rPoly.GetPointCount();
403cdf0e10cSrcweir     sal_uInt16 i=0;
4047a060572Smseidel     while (i<nPointCount) {
405cdf0e10cSrcweir         Point* pPnt=&rPoly[i];
406cdf0e10cSrcweir         Point* pC1=NULL;
407cdf0e10cSrcweir         Point* pC2=NULL;
4087a060572Smseidel         if (i+1<nPointCount && rPoly.IsControl(i)) { // Kontrollpunkt links
409cdf0e10cSrcweir             pC1=pPnt;
410cdf0e10cSrcweir             i++;
411cdf0e10cSrcweir             pPnt=&rPoly[i];
412cdf0e10cSrcweir         }
413cdf0e10cSrcweir         i++;
4147a060572Smseidel         if (i<nPointCount && rPoly.IsControl(i)) { // Kontrollpunkt rechts
415cdf0e10cSrcweir             pC2=&rPoly[i];
416cdf0e10cSrcweir             i++;
417cdf0e10cSrcweir         }
418cdf0e10cSrcweir         CrookRotateXPoint(*pPnt,pC1,pC2,rCenter,rRad,nSin,nCos,bVert);
419cdf0e10cSrcweir     }
420cdf0e10cSrcweir }
421cdf0e10cSrcweir 
CrookSlantPoly(XPolygon & rPoly,const Point & rCenter,const Point & rRad,FASTBOOL bVert)422cdf0e10cSrcweir void CrookSlantPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, FASTBOOL bVert)
423cdf0e10cSrcweir {
424cdf0e10cSrcweir     double nSin,nCos;
4257a060572Smseidel     sal_uInt16 nPointCount=rPoly.GetPointCount();
426cdf0e10cSrcweir     sal_uInt16 i=0;
4277a060572Smseidel     while (i<nPointCount) {
428cdf0e10cSrcweir         Point* pPnt=&rPoly[i];
429cdf0e10cSrcweir         Point* pC1=NULL;
430cdf0e10cSrcweir         Point* pC2=NULL;
4317a060572Smseidel         if (i+1<nPointCount && rPoly.IsControl(i)) { // Kontrollpunkt links
432cdf0e10cSrcweir             pC1=pPnt;
433cdf0e10cSrcweir             i++;
434cdf0e10cSrcweir             pPnt=&rPoly[i];
435cdf0e10cSrcweir         }
436cdf0e10cSrcweir         i++;
4377a060572Smseidel         if (i<nPointCount && rPoly.IsControl(i)) { // Kontrollpunkt rechts
438cdf0e10cSrcweir             pC2=&rPoly[i];
439cdf0e10cSrcweir             i++;
440cdf0e10cSrcweir         }
441cdf0e10cSrcweir         CrookSlantXPoint(*pPnt,pC1,pC2,rCenter,rRad,nSin,nCos,bVert);
442cdf0e10cSrcweir     }
443cdf0e10cSrcweir }
444cdf0e10cSrcweir 
CrookStretchPoly(XPolygon & rPoly,const Point & rCenter,const Point & rRad,FASTBOOL bVert,const Rectangle rRefRect)445cdf0e10cSrcweir void CrookStretchPoly(XPolygon& rPoly, const Point& rCenter, const Point& rRad, FASTBOOL bVert, const Rectangle rRefRect)
446cdf0e10cSrcweir {
447cdf0e10cSrcweir     double nSin,nCos;
4487a060572Smseidel     sal_uInt16 nPointCount=rPoly.GetPointCount();
449cdf0e10cSrcweir     sal_uInt16 i=0;
4507a060572Smseidel     while (i<nPointCount) {
451cdf0e10cSrcweir         Point* pPnt=&rPoly[i];
452cdf0e10cSrcweir         Point* pC1=NULL;
453cdf0e10cSrcweir         Point* pC2=NULL;
4547a060572Smseidel         if (i+1<nPointCount && rPoly.IsControl(i)) { // Kontrollpunkt links
455cdf0e10cSrcweir             pC1=pPnt;
456cdf0e10cSrcweir             i++;
457cdf0e10cSrcweir             pPnt=&rPoly[i];
458cdf0e10cSrcweir         }
459cdf0e10cSrcweir         i++;
4607a060572Smseidel         if (i<nPointCount && rPoly.IsControl(i)) { // Kontrollpunkt rechts
461cdf0e10cSrcweir             pC2=&rPoly[i];
462cdf0e10cSrcweir             i++;
463cdf0e10cSrcweir         }
464cdf0e10cSrcweir         CrookStretchXPoint(*pPnt,pC1,pC2,rCenter,rRad,nSin,nCos,bVert,rRefRect);
465cdf0e10cSrcweir     }
466cdf0e10cSrcweir }
467cdf0e10cSrcweir 
468cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
469cdf0e10cSrcweir 
CrookRotatePoly(XPolyPolygon & rPoly,const Point & rCenter,const Point & rRad,FASTBOOL bVert)470cdf0e10cSrcweir void CrookRotatePoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, FASTBOOL bVert)
471cdf0e10cSrcweir {
472*3d3dcf63Smseidel     sal_uInt16 nPolyCount=rPoly.Count();
473*3d3dcf63Smseidel     for (sal_uInt16 nPolyNum=0; nPolyNum<nPolyCount; nPolyNum++) {
474cdf0e10cSrcweir         CrookRotatePoly(rPoly[nPolyNum],rCenter,rRad,bVert);
475cdf0e10cSrcweir     }
476cdf0e10cSrcweir }
477cdf0e10cSrcweir 
CrookSlantPoly(XPolyPolygon & rPoly,const Point & rCenter,const Point & rRad,FASTBOOL bVert)478cdf0e10cSrcweir void CrookSlantPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, FASTBOOL bVert)
479cdf0e10cSrcweir {
480*3d3dcf63Smseidel     sal_uInt16 nPolyCount=rPoly.Count();
481*3d3dcf63Smseidel     for (sal_uInt16 nPolyNum=0; nPolyNum<nPolyCount; nPolyNum++) {
482cdf0e10cSrcweir         CrookSlantPoly(rPoly[nPolyNum],rCenter,rRad,bVert);
483cdf0e10cSrcweir     }
484cdf0e10cSrcweir }
485cdf0e10cSrcweir 
CrookStretchPoly(XPolyPolygon & rPoly,const Point & rCenter,const Point & rRad,FASTBOOL bVert,const Rectangle rRefRect)486cdf0e10cSrcweir void CrookStretchPoly(XPolyPolygon& rPoly, const Point& rCenter, const Point& rRad, FASTBOOL bVert, const Rectangle rRefRect)
487cdf0e10cSrcweir {
488*3d3dcf63Smseidel     sal_uInt16 nPolyCount=rPoly.Count();
489*3d3dcf63Smseidel     for (sal_uInt16 nPolyNum=0; nPolyNum<nPolyCount; nPolyNum++) {
490cdf0e10cSrcweir         CrookStretchPoly(rPoly[nPolyNum],rCenter,rRad,bVert,rRefRect);
491cdf0e10cSrcweir     }
492cdf0e10cSrcweir }
493cdf0e10cSrcweir 
494cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
495cdf0e10cSrcweir 
GetAngle(const Point & rPnt)496cdf0e10cSrcweir long GetAngle(const Point& rPnt)
497cdf0e10cSrcweir {
498cdf0e10cSrcweir     long a=0;
499cdf0e10cSrcweir     if (rPnt.Y()==0) {
500cdf0e10cSrcweir         if (rPnt.X()<0) a=-18000;
501cdf0e10cSrcweir     } else if (rPnt.X()==0) {
502cdf0e10cSrcweir         if (rPnt.Y()>0) a=-9000;
503cdf0e10cSrcweir         else a=9000;
504cdf0e10cSrcweir     } else {
505cdf0e10cSrcweir         a=Round((atan2((double)-rPnt.Y(),(double)rPnt.X())/nPi180));
506cdf0e10cSrcweir     }
507cdf0e10cSrcweir     return a;
508cdf0e10cSrcweir }
509cdf0e10cSrcweir 
NormAngle180(long a)510cdf0e10cSrcweir long NormAngle180(long a)
511cdf0e10cSrcweir {
512cdf0e10cSrcweir     while (a<18000) a+=36000;
513cdf0e10cSrcweir     while (a>=18000) a-=36000;
514cdf0e10cSrcweir     return a;
515cdf0e10cSrcweir }
516cdf0e10cSrcweir 
NormAngle360(long a)517cdf0e10cSrcweir long NormAngle360(long a)
518cdf0e10cSrcweir {
519cdf0e10cSrcweir     while (a<0) a+=36000;
520cdf0e10cSrcweir     while (a>=36000) a-=36000;
521cdf0e10cSrcweir     return a;
522cdf0e10cSrcweir }
523cdf0e10cSrcweir 
GetAngleSector(long nWink)524cdf0e10cSrcweir sal_uInt16 GetAngleSector(long nWink)
525cdf0e10cSrcweir {
526cdf0e10cSrcweir     while (nWink<0) nWink+=36000;
527cdf0e10cSrcweir     while (nWink>=36000) nWink-=36000;
528cdf0e10cSrcweir     if (nWink< 9000) return 0;
529cdf0e10cSrcweir     if (nWink<18000) return 1;
530cdf0e10cSrcweir     if (nWink<27000) return 2;
531cdf0e10cSrcweir     return 3;
532cdf0e10cSrcweir }
533cdf0e10cSrcweir 
GetLen(const Point & rPnt)534cdf0e10cSrcweir long GetLen(const Point& rPnt)
535cdf0e10cSrcweir {
536cdf0e10cSrcweir     long x=Abs(rPnt.X());
537cdf0e10cSrcweir     long y=Abs(rPnt.Y());
538cdf0e10cSrcweir     if (x+y<0x8000) { // weil 7FFF * 7FFF * 2 = 7FFE0002
539cdf0e10cSrcweir         x*=x;
540cdf0e10cSrcweir         y*=y;
541cdf0e10cSrcweir         x+=y;
542cdf0e10cSrcweir         x=Round(sqrt((double)x));
543cdf0e10cSrcweir         return x;
544cdf0e10cSrcweir     } else {
545cdf0e10cSrcweir         double nx=x;
546cdf0e10cSrcweir         double ny=y;
547cdf0e10cSrcweir         nx*=nx;
548cdf0e10cSrcweir         ny*=ny;
549cdf0e10cSrcweir         nx+=ny;
550cdf0e10cSrcweir         nx=sqrt(nx);
551cdf0e10cSrcweir         if (nx>0x7FFFFFFF) {
5528d647522Smseidel             return 0x7FFFFFFF; // Überlauf, mehr ist nicht!
553cdf0e10cSrcweir         } else {
554cdf0e10cSrcweir             return Round(nx);
555cdf0e10cSrcweir         }
556cdf0e10cSrcweir     }
557cdf0e10cSrcweir }
558cdf0e10cSrcweir 
559cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
560cdf0e10cSrcweir 
RecalcSinCos()561cdf0e10cSrcweir void GeoStat::RecalcSinCos()
562cdf0e10cSrcweir {
563cdf0e10cSrcweir     if (nDrehWink==0) {
564cdf0e10cSrcweir         nSin=0.0;
565cdf0e10cSrcweir         nCos=1.0;
566cdf0e10cSrcweir     } else {
567cdf0e10cSrcweir         double a=nDrehWink*nPi180;
568cdf0e10cSrcweir         nSin=sin(a);
569cdf0e10cSrcweir         nCos=cos(a);
570cdf0e10cSrcweir     }
571cdf0e10cSrcweir }
572cdf0e10cSrcweir 
RecalcTan()573cdf0e10cSrcweir void GeoStat::RecalcTan()
574cdf0e10cSrcweir {
575cdf0e10cSrcweir     if (nShearWink==0) {
576cdf0e10cSrcweir         nTan=0.0;
577cdf0e10cSrcweir     } else {
578cdf0e10cSrcweir         double a=nShearWink*nPi180;
579cdf0e10cSrcweir         nTan=tan(a);
580cdf0e10cSrcweir     }
581cdf0e10cSrcweir }
582cdf0e10cSrcweir 
583cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
584cdf0e10cSrcweir 
Rect2Poly(const Rectangle & rRect,const GeoStat & rGeo)585cdf0e10cSrcweir Polygon Rect2Poly(const Rectangle& rRect, const GeoStat& rGeo)
586cdf0e10cSrcweir {
587cdf0e10cSrcweir     Polygon aPol(5);
588cdf0e10cSrcweir     aPol[0]=rRect.TopLeft();
589cdf0e10cSrcweir     aPol[1]=rRect.TopRight();
590cdf0e10cSrcweir     aPol[2]=rRect.BottomRight();
591cdf0e10cSrcweir     aPol[3]=rRect.BottomLeft();
592cdf0e10cSrcweir     aPol[4]=rRect.TopLeft();
593cdf0e10cSrcweir     if (rGeo.nShearWink!=0) ShearPoly(aPol,rRect.TopLeft(),rGeo.nTan);
594cdf0e10cSrcweir     if (rGeo.nDrehWink!=0) RotatePoly(aPol,rRect.TopLeft(),rGeo.nSin,rGeo.nCos);
595cdf0e10cSrcweir     return aPol;
596cdf0e10cSrcweir }
597cdf0e10cSrcweir 
Poly2Rect(const Polygon & rPol,Rectangle & rRect,GeoStat & rGeo)598cdf0e10cSrcweir void Poly2Rect(const Polygon& rPol, Rectangle& rRect, GeoStat& rGeo)
599cdf0e10cSrcweir {
600cdf0e10cSrcweir     rGeo.nDrehWink=GetAngle(rPol[1]-rPol[0]);
601cdf0e10cSrcweir     rGeo.nDrehWink=NormAngle360(rGeo.nDrehWink);
602cdf0e10cSrcweir     // Drehung ist damit im Kasten
603cdf0e10cSrcweir     rGeo.RecalcSinCos();
604cdf0e10cSrcweir 
605cdf0e10cSrcweir     Point aPt1(rPol[1]-rPol[0]);
6068d647522Smseidel     if (rGeo.nDrehWink!=0) RotatePoint(aPt1,Point(0,0),-rGeo.nSin,rGeo.nCos); // -Sin für Rückdrehung
607cdf0e10cSrcweir     long nWdt=aPt1.X();
608cdf0e10cSrcweir 
609cdf0e10cSrcweir     Point aPt0(rPol[0]);
610cdf0e10cSrcweir     Point aPt3(rPol[3]-rPol[0]);
6118d647522Smseidel     if (rGeo.nDrehWink!=0) RotatePoint(aPt3,Point(0,0),-rGeo.nSin,rGeo.nCos); // -Sin für Rückdrehung
612cdf0e10cSrcweir     long nHgt=aPt3.Y();
613cdf0e10cSrcweir 
614cdf0e10cSrcweir     if(aPt3.X())
615cdf0e10cSrcweir     {
616cdf0e10cSrcweir         // #i74358# the axes are not orthogonal, so for getting the correct height,
617cdf0e10cSrcweir         // calculate the length of aPt3
618cdf0e10cSrcweir 
619cdf0e10cSrcweir         // #i74358# this change was wrong, in the field of the old geometry stuff
620cdf0e10cSrcweir         // it is not an error. The new height always is the same as before; shear
621cdf0e10cSrcweir         // does not change object height at all. This is different from the interactions,
622cdf0e10cSrcweir         // but obviously wanted in the old versions.
623cdf0e10cSrcweir         //
624cdf0e10cSrcweir         // nHgt = static_cast< long >(sqrt(static_cast< double >(aPt3.X() * aPt3.X() + aPt3.Y() * aPt3.Y())));
625cdf0e10cSrcweir     }
626cdf0e10cSrcweir 
627cdf0e10cSrcweir     long nShW=GetAngle(aPt3);
628cdf0e10cSrcweir     nShW-=27000; // ShearWink wird zur Senkrechten gemessen
629cdf0e10cSrcweir     nShW=-nShW; // Negieren, denn '+' ist Rechtskursivierung
630cdf0e10cSrcweir 
631cdf0e10cSrcweir     FASTBOOL bMirr=aPt3.Y()<0;
632cdf0e10cSrcweir     if (bMirr) { // "Punktetausch" bei Spiegelung
633cdf0e10cSrcweir         nHgt=-nHgt;
634cdf0e10cSrcweir         nShW+=18000;
635cdf0e10cSrcweir         aPt0=rPol[3];
636cdf0e10cSrcweir     }
637cdf0e10cSrcweir     nShW=NormAngle180(nShW);
638cdf0e10cSrcweir     if (nShW<-9000 || nShW>9000) {
639cdf0e10cSrcweir         nShW=NormAngle180(nShW+18000);
640cdf0e10cSrcweir     }
641cdf0e10cSrcweir     if (nShW<-SDRMAXSHEAR) nShW=-SDRMAXSHEAR; // ShearWinkel begrenzen auf +/- 89.00 deg
642cdf0e10cSrcweir     if (nShW>SDRMAXSHEAR)  nShW=SDRMAXSHEAR;
643cdf0e10cSrcweir     rGeo.nShearWink=nShW;
644cdf0e10cSrcweir     rGeo.RecalcTan();
645cdf0e10cSrcweir     Point aRU(aPt0);
646cdf0e10cSrcweir     aRU.X()+=nWdt;
647cdf0e10cSrcweir     aRU.Y()+=nHgt;
648cdf0e10cSrcweir     rRect=Rectangle(aPt0,aRU);
649cdf0e10cSrcweir }
650cdf0e10cSrcweir 
651cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
652cdf0e10cSrcweir 
OrthoDistance8(const Point & rPt0,Point & rPt,FASTBOOL bBigOrtho)653cdf0e10cSrcweir void OrthoDistance8(const Point& rPt0, Point& rPt, FASTBOOL bBigOrtho)
654cdf0e10cSrcweir {
655cdf0e10cSrcweir     long dx=rPt.X()-rPt0.X();
656cdf0e10cSrcweir     long dy=rPt.Y()-rPt0.Y();
657cdf0e10cSrcweir     long dxa=Abs(dx);
658cdf0e10cSrcweir     long dya=Abs(dy);
659cdf0e10cSrcweir     if (dx==0 || dy==0 || dxa==dya) return;
660cdf0e10cSrcweir     if (dxa>=dya*2) { rPt.Y()=rPt0.Y(); return; }
661cdf0e10cSrcweir     if (dya>=dxa*2) { rPt.X()=rPt0.X(); return; }
662cdf0e10cSrcweir     if ((dxa<dya) != bBigOrtho) {
663cdf0e10cSrcweir         rPt.Y()=rPt0.Y()+(dxa* (dy>=0 ? 1 : -1) );
664cdf0e10cSrcweir     } else {
665cdf0e10cSrcweir         rPt.X()=rPt0.X()+(dya* (dx>=0 ? 1 : -1) );
666cdf0e10cSrcweir     }
667cdf0e10cSrcweir }
668cdf0e10cSrcweir 
OrthoDistance4(const Point & rPt0,Point & rPt,FASTBOOL bBigOrtho)669cdf0e10cSrcweir void OrthoDistance4(const Point& rPt0, Point& rPt, FASTBOOL bBigOrtho)
670cdf0e10cSrcweir {
671cdf0e10cSrcweir     long dx=rPt.X()-rPt0.X();
672cdf0e10cSrcweir     long dy=rPt.Y()-rPt0.Y();
673cdf0e10cSrcweir     long dxa=Abs(dx);
674cdf0e10cSrcweir     long dya=Abs(dy);
675cdf0e10cSrcweir     if ((dxa<dya) != bBigOrtho) {
676cdf0e10cSrcweir         rPt.Y()=rPt0.Y()+(dxa* (dy>=0 ? 1 : -1) );
677cdf0e10cSrcweir     } else {
678cdf0e10cSrcweir         rPt.X()=rPt0.X()+(dya* (dx>=0 ? 1 : -1) );
679cdf0e10cSrcweir     }
680cdf0e10cSrcweir }
681cdf0e10cSrcweir 
682cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
683cdf0e10cSrcweir 
BigMulDiv(long nVal,long nMul,long nDiv)684cdf0e10cSrcweir long BigMulDiv(long nVal, long nMul, long nDiv)
685cdf0e10cSrcweir {
686cdf0e10cSrcweir     BigInt aVal(nVal);
687cdf0e10cSrcweir     aVal*=nMul;
688cdf0e10cSrcweir     if (aVal.IsNeg()!=(nDiv<0)) {
6898d647522Smseidel         aVal-=nDiv/2; // für korrektes Runden
690cdf0e10cSrcweir     } else {
6918d647522Smseidel         aVal+=nDiv/2; // für korrektes Runden
692cdf0e10cSrcweir     }
693cdf0e10cSrcweir     if(nDiv)
694cdf0e10cSrcweir     {
695cdf0e10cSrcweir         aVal/=nDiv;
696cdf0e10cSrcweir         return long(aVal);
697cdf0e10cSrcweir     }
698cdf0e10cSrcweir     return 0x7fffffff;
699cdf0e10cSrcweir }
700cdf0e10cSrcweir 
701cdf0e10cSrcweir 
702cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
703cdf0e10cSrcweir // Wieviele eU-Einheiten passen in einen mm bzw. Inch?
7048d647522Smseidel // Oder wie groß ist ein eU in mm bzw. Inch, und davon der Kehrwert
705cdf0e10cSrcweir 
GetInchOrMM(MapUnit eU)706cdf0e10cSrcweir FrPair GetInchOrMM(MapUnit eU)
707cdf0e10cSrcweir {
708cdf0e10cSrcweir     switch (eU) {
709cdf0e10cSrcweir         case MAP_1000TH_INCH: return FrPair(1000,1);
710cdf0e10cSrcweir         case MAP_100TH_INCH : return FrPair( 100,1);
711cdf0e10cSrcweir         case MAP_10TH_INCH  : return FrPair(  10,1);
712cdf0e10cSrcweir         case MAP_INCH       : return FrPair(   1,1);
713cdf0e10cSrcweir         case MAP_POINT      : return FrPair(  72,1);
714cdf0e10cSrcweir         case MAP_TWIP       : return FrPair(1440,1);
715cdf0e10cSrcweir         case MAP_100TH_MM   : return FrPair( 100,1);
716cdf0e10cSrcweir         case MAP_10TH_MM    : return FrPair(  10,1);
717cdf0e10cSrcweir         case MAP_MM         : return FrPair(   1,1);
718cdf0e10cSrcweir         case MAP_CM         : return FrPair(   1,10);
719cdf0e10cSrcweir         case MAP_PIXEL      : {
720cdf0e10cSrcweir             VirtualDevice aVD;
721cdf0e10cSrcweir             aVD.SetMapMode(MapMode(MAP_100TH_MM));
7228d647522Smseidel             Point aP(aVD.PixelToLogic(Point(64,64))); // 64 Pixel für bessere Genauigkeit
723cdf0e10cSrcweir             return FrPair(6400,aP.X(),6400,aP.Y());
724cdf0e10cSrcweir         }
725cdf0e10cSrcweir         case MAP_APPFONT: case MAP_SYSFONT: {
726cdf0e10cSrcweir             VirtualDevice aVD;
727cdf0e10cSrcweir             aVD.SetMapMode(MapMode(eU));
7288d647522Smseidel             Point aP(aVD.LogicToPixel(Point(32,32))); // 32 Einheiten für bessere Genauigkeit
729cdf0e10cSrcweir             aVD.SetMapMode(MapMode(MAP_100TH_MM));
730cdf0e10cSrcweir             aP=aVD.PixelToLogic(aP);
731cdf0e10cSrcweir             return FrPair(3200,aP.X(),3200,aP.Y());
732cdf0e10cSrcweir         }
733cdf0e10cSrcweir         default: break;
734cdf0e10cSrcweir     }
735cdf0e10cSrcweir     return Fraction(1,1);
736cdf0e10cSrcweir }
737cdf0e10cSrcweir 
GetInchOrMM(FieldUnit eU)738cdf0e10cSrcweir FrPair GetInchOrMM(FieldUnit eU)
739cdf0e10cSrcweir {
740cdf0e10cSrcweir     switch (eU) {
741cdf0e10cSrcweir         case FUNIT_INCH       : return FrPair(   1,1);
742cdf0e10cSrcweir         case FUNIT_POINT      : return FrPair(  72,1);
743cdf0e10cSrcweir         case FUNIT_TWIP       : return FrPair(1440,1);
744cdf0e10cSrcweir         case FUNIT_100TH_MM   : return FrPair( 100,1);
745cdf0e10cSrcweir         case FUNIT_MM         : return FrPair(   1,1);
746cdf0e10cSrcweir         case FUNIT_CM         : return FrPair(   1,10);
747cdf0e10cSrcweir         case FUNIT_M          : return FrPair(   1,1000);
748cdf0e10cSrcweir         case FUNIT_KM         : return FrPair(   1,1000000);
749cdf0e10cSrcweir         case FUNIT_PICA       : return FrPair(   6,1);
750cdf0e10cSrcweir         case FUNIT_FOOT       : return FrPair(   1,12);
751cdf0e10cSrcweir         case FUNIT_MILE       : return FrPair(   1,63360);
752cdf0e10cSrcweir         default: break;
753cdf0e10cSrcweir     }
754cdf0e10cSrcweir     return Fraction(1,1);
755cdf0e10cSrcweir }
756cdf0e10cSrcweir 
757cdf0e10cSrcweir // Den Faktor berechnen, der anzuwenden ist um n Einheiten von eS nach
758cdf0e10cSrcweir // eD umzurechnen. Z.B. GetMapFactor(UNIT_MM,UNIT_100TH_MM) => 100.
759cdf0e10cSrcweir 
GetMapFactor(MapUnit eS,MapUnit eD)760cdf0e10cSrcweir FrPair GetMapFactor(MapUnit eS, MapUnit eD)
761cdf0e10cSrcweir {
762cdf0e10cSrcweir     if (eS==eD) return FrPair(1,1,1,1);
763cdf0e10cSrcweir     FrPair aS(GetInchOrMM(eS));
764cdf0e10cSrcweir     FrPair aD(GetInchOrMM(eD));
765cdf0e10cSrcweir     FASTBOOL bSInch=IsInch(eS);
766cdf0e10cSrcweir     FASTBOOL bDInch=IsInch(eD);
767cdf0e10cSrcweir     FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y());
768cdf0e10cSrcweir     if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); }
769cdf0e10cSrcweir     if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); }
770cdf0e10cSrcweir     return aRet;
771cdf0e10cSrcweir };
772cdf0e10cSrcweir 
GetMapFactor(MapUnit eS,FieldUnit eD)773cdf0e10cSrcweir FrPair GetMapFactor(MapUnit eS, FieldUnit eD)
774cdf0e10cSrcweir {
775cdf0e10cSrcweir     FrPair aS(GetInchOrMM(eS));
776cdf0e10cSrcweir     FrPair aD(GetInchOrMM(eD));
777cdf0e10cSrcweir     FASTBOOL bSInch=IsInch(eS);
778cdf0e10cSrcweir     FASTBOOL bDInch=IsInch(eD);
779cdf0e10cSrcweir     FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y());
780cdf0e10cSrcweir     if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); }
781cdf0e10cSrcweir     if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); }
782cdf0e10cSrcweir     return aRet;
783cdf0e10cSrcweir };
784cdf0e10cSrcweir 
GetMapFactor(FieldUnit eS,MapUnit eD)785cdf0e10cSrcweir FrPair GetMapFactor(FieldUnit eS, MapUnit eD)
786cdf0e10cSrcweir {
787cdf0e10cSrcweir     FrPair aS(GetInchOrMM(eS));
788cdf0e10cSrcweir     FrPair aD(GetInchOrMM(eD));
789cdf0e10cSrcweir     FASTBOOL bSInch=IsInch(eS);
790cdf0e10cSrcweir     FASTBOOL bDInch=IsInch(eD);
791cdf0e10cSrcweir     FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y());
792cdf0e10cSrcweir     if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); }
793cdf0e10cSrcweir     if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); }
794cdf0e10cSrcweir     return aRet;
795cdf0e10cSrcweir };
796cdf0e10cSrcweir 
GetMapFactor(FieldUnit eS,FieldUnit eD)797cdf0e10cSrcweir FrPair GetMapFactor(FieldUnit eS, FieldUnit eD)
798cdf0e10cSrcweir {
799cdf0e10cSrcweir     if (eS==eD) return FrPair(1,1,1,1);
800cdf0e10cSrcweir     FrPair aS(GetInchOrMM(eS));
801cdf0e10cSrcweir     FrPair aD(GetInchOrMM(eD));
802cdf0e10cSrcweir     FASTBOOL bSInch=IsInch(eS);
803cdf0e10cSrcweir     FASTBOOL bDInch=IsInch(eD);
804cdf0e10cSrcweir     FrPair aRet(aD.X()/aS.X(),aD.Y()/aS.Y());
805cdf0e10cSrcweir     if (bSInch && !bDInch) { aRet.X()*=Fraction(127,5); aRet.Y()*=Fraction(127,5); }
806cdf0e10cSrcweir     if (!bSInch && bDInch) { aRet.X()*=Fraction(5,127); aRet.Y()*=Fraction(5,127); }
807cdf0e10cSrcweir     return aRet;
808cdf0e10cSrcweir };
809cdf0e10cSrcweir 
810cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////////////////////////////////////
811cdf0e10cSrcweir 
812cdf0e10cSrcweir     // 1 mile    =  8 furlong = 63.360" = 1.609.344,0mm
813cdf0e10cSrcweir     // 1 furlong = 10 chains  =  7.920" =   201.168,0mm
814cdf0e10cSrcweir     // 1 chain   =  4 poles   =    792" =    20.116,8mm
815cdf0e10cSrcweir     // 1 pole    =  5 1/2 yd  =    198" =     5.029,2mm
816cdf0e10cSrcweir     // 1 yd      =  3 ft      =     36" =       914,4mm
817cdf0e10cSrcweir     // 1 ft      = 12 "       =      1" =       304,8mm
818cdf0e10cSrcweir 
GetMeterOrInch(MapUnit eMU,short & rnComma,long & rnMul,long & rnDiv,int & rbMetr,int & rbInch)8198d647522Smseidel void GetMeterOrInch(MapUnit eMU, short& rnComma, long& rnMul, long& rnDiv, int& rbMetr, int& rbInch)
820cdf0e10cSrcweir {
821cdf0e10cSrcweir     rnMul=1; rnDiv=1;
8228d647522Smseidel     short nComma=0;
823cdf0e10cSrcweir     FASTBOOL bMetr=sal_False,bInch=sal_False;
824cdf0e10cSrcweir     switch (eMU) {
825cdf0e10cSrcweir         // Metrisch
8268d647522Smseidel         case MAP_100TH_MM   : bMetr=sal_True; nComma=5; break;
8278d647522Smseidel         case MAP_10TH_MM    : bMetr=sal_True; nComma=4; break;
8288d647522Smseidel         case MAP_MM         : bMetr=sal_True; nComma=3; break;
8298d647522Smseidel         case MAP_CM         : bMetr=sal_True; nComma=2; break;
830cdf0e10cSrcweir         // Inch
8318d647522Smseidel         case MAP_1000TH_INCH: bInch=sal_True; nComma=3; break;
8328d647522Smseidel         case MAP_100TH_INCH : bInch=sal_True; nComma=2; break;
8338d647522Smseidel         case MAP_10TH_INCH  : bInch=sal_True; nComma=1; break;
8348d647522Smseidel         case MAP_INCH       : bInch=sal_True; nComma=0; break;
835cdf0e10cSrcweir         case MAP_POINT      : bInch=sal_True; rnDiv=72; break; // 1Pt = 1/72"
8368d647522Smseidel         case MAP_TWIP       : bInch=sal_True; rnDiv=144; nComma=1; break; // 1Twip = 1/1440"
837cdf0e10cSrcweir         // Sonstiges
838cdf0e10cSrcweir         case MAP_PIXEL      : break;
839cdf0e10cSrcweir         case MAP_SYSFONT    : break;
840cdf0e10cSrcweir         case MAP_APPFONT    : break;
841cdf0e10cSrcweir         case MAP_RELATIVE   : break;
842cdf0e10cSrcweir         default: break;
843cdf0e10cSrcweir     } // switch
8448d647522Smseidel     rnComma=nComma;
845cdf0e10cSrcweir     rbMetr=bMetr;
846cdf0e10cSrcweir     rbInch=bInch;
847cdf0e10cSrcweir }
848cdf0e10cSrcweir 
GetMeterOrInch(FieldUnit eFU,short & rnComma,long & rnMul,long & rnDiv,int & rbMetr,int & rbInch)8498d647522Smseidel void GetMeterOrInch(FieldUnit eFU, short& rnComma, long& rnMul, long& rnDiv, int& rbMetr, int& rbInch)
850cdf0e10cSrcweir {
851cdf0e10cSrcweir     rnMul=1; rnDiv=1;
8528d647522Smseidel     short nComma=0;
853cdf0e10cSrcweir     FASTBOOL bMetr=sal_False,bInch=sal_False;
854cdf0e10cSrcweir     switch (eFU) {
855cdf0e10cSrcweir         case FUNIT_NONE     : break;
856cdf0e10cSrcweir         // Metrisch
8578d647522Smseidel         case FUNIT_100TH_MM : bMetr=sal_True; nComma=5; break;
8588d647522Smseidel         case FUNIT_MM       : bMetr=sal_True; nComma=3; break;
8598d647522Smseidel         case FUNIT_CM       : bMetr=sal_True; nComma=2; break;
8608d647522Smseidel         case FUNIT_M        : bMetr=sal_True; nComma=0; break;
8618d647522Smseidel         case FUNIT_KM       : bMetr=sal_True; nComma=-3; break;
862cdf0e10cSrcweir         // Inch
8638d647522Smseidel         case FUNIT_TWIP     : bInch=sal_True; rnDiv=144; nComma=1; break; // 1Twip = 1/1440"
864cdf0e10cSrcweir         case FUNIT_POINT    : bInch=sal_True; rnDiv=72; break;   // 1Pt = 1/72"
865cdf0e10cSrcweir         case FUNIT_PICA     : bInch=sal_True; rnDiv=6; break;    // 1Pica = 1/6" ?
866cdf0e10cSrcweir         case FUNIT_INCH     : bInch=sal_True; break;             // 1" = 1"
867cdf0e10cSrcweir         case FUNIT_FOOT     : bInch=sal_True; rnMul=12; break;   // 1Ft = 12"
8688d647522Smseidel         case FUNIT_MILE     : bInch=sal_True; rnMul=6336; nComma=-1; break; // 1mile = 63360"
869cdf0e10cSrcweir         // sonstiges
870cdf0e10cSrcweir         case FUNIT_CUSTOM   : break;
8718d647522Smseidel         case FUNIT_PERCENT  : nComma=2; break;
872cdf0e10cSrcweir     } // switch
8738d647522Smseidel     rnComma=nComma;
874cdf0e10cSrcweir     rbMetr=bMetr;
875cdf0e10cSrcweir     rbInch=bInch;
876cdf0e10cSrcweir }
877cdf0e10cSrcweir 
Undirty()878cdf0e10cSrcweir void SdrFormatter::Undirty()
879cdf0e10cSrcweir {
880cdf0e10cSrcweir     if (aScale.GetNumerator()==0 || aScale.GetDenominator()==0) aScale=Fraction(1,1);
881cdf0e10cSrcweir     FASTBOOL bSrcMetr,bSrcInch,bDstMetr,bDstInch;
882cdf0e10cSrcweir     long nMul1,nDiv1,nMul2,nDiv2;
8838d647522Smseidel     short nComma1,nComma2;
8848d647522Smseidel     // Zunächst normalisieren auf m bzw. "
885cdf0e10cSrcweir     if (!bSrcFU) {
8868d647522Smseidel         GetMeterOrInch(eSrcMU,nComma1,nMul1,nDiv1,bSrcMetr,bSrcInch);
887cdf0e10cSrcweir     } else {
8888d647522Smseidel         GetMeterOrInch(eSrcFU,nComma1,nMul1,nDiv1,bSrcMetr,bSrcInch);
889cdf0e10cSrcweir     }
890cdf0e10cSrcweir     if (!bDstFU) {
8918d647522Smseidel         GetMeterOrInch(eDstMU,nComma2,nMul2,nDiv2,bDstMetr,bDstInch);
892cdf0e10cSrcweir     } else {
8938d647522Smseidel         GetMeterOrInch(eDstFU,nComma2,nMul2,nDiv2,bDstMetr,bDstInch);
894cdf0e10cSrcweir     }
895cdf0e10cSrcweir     nMul1*=nDiv2;
896cdf0e10cSrcweir     nDiv1*=nMul2;
8978d647522Smseidel     nComma1=nComma1-nComma2;
898cdf0e10cSrcweir 
899cdf0e10cSrcweir     if (bSrcInch && bDstMetr) {
9008d647522Smseidel         nComma1+=4;
901cdf0e10cSrcweir         nMul1*=254;
902cdf0e10cSrcweir     }
903cdf0e10cSrcweir     if (bSrcMetr && bDstInch) {
9048d647522Smseidel         nComma1-=4;
905cdf0e10cSrcweir         nDiv1*=254;
906cdf0e10cSrcweir     }
907cdf0e10cSrcweir 
9088d647522Smseidel     // Temporäre Fraction zum Kürzen
909cdf0e10cSrcweir     Fraction aTempFract(nMul1,nDiv1);
910cdf0e10cSrcweir     nMul1=aTempFract.GetNumerator();
911cdf0e10cSrcweir     nDiv1=aTempFract.GetDenominator();
912cdf0e10cSrcweir 
913cdf0e10cSrcweir     nMul_=nMul1;
914cdf0e10cSrcweir     nDiv_=nDiv1;
9158d647522Smseidel     nComma_=nComma1;
916cdf0e10cSrcweir     bDirty=sal_False;
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 
TakeStr(long nVal,XubString & rStr) const920cdf0e10cSrcweir void SdrFormatter::TakeStr(long nVal, XubString& rStr) const
921cdf0e10cSrcweir {
922cdf0e10cSrcweir     sal_Unicode aNullCode('0');
923cdf0e10cSrcweir 
924cdf0e10cSrcweir     if(!nVal)
925cdf0e10cSrcweir     {
926cdf0e10cSrcweir         rStr = UniString();
927cdf0e10cSrcweir         rStr += aNullCode;
928cdf0e10cSrcweir         return;
929cdf0e10cSrcweir     }
930cdf0e10cSrcweir 
931cdf0e10cSrcweir     // Hier fallen trotzdem evtl. Nachkommastellen weg, wg. MulDiv statt Real
932cdf0e10cSrcweir     sal_Bool bNeg(nVal < 0);
933cdf0e10cSrcweir     SvtSysLocale aSysLoc;
934cdf0e10cSrcweir     const LocaleDataWrapper& rLoc = aSysLoc.GetLocaleData();
935cdf0e10cSrcweir 
936cdf0e10cSrcweir     ForceUndirty();
937cdf0e10cSrcweir 
9388d647522Smseidel     sal_Int16 nK(nComma_);
939cdf0e10cSrcweir     XubString aStr;
940cdf0e10cSrcweir 
941cdf0e10cSrcweir     if(bNeg)
942cdf0e10cSrcweir         nVal = -nVal;
943cdf0e10cSrcweir 
944cdf0e10cSrcweir     while(nK <= -3)
945cdf0e10cSrcweir     {
946cdf0e10cSrcweir         nVal *= 1000;
947cdf0e10cSrcweir         nK += 3;
948cdf0e10cSrcweir     }
949cdf0e10cSrcweir 
950cdf0e10cSrcweir     while(nK <= -1)
951cdf0e10cSrcweir     {
952cdf0e10cSrcweir         nVal *= 10;
953cdf0e10cSrcweir         nK++;
954cdf0e10cSrcweir     }
955cdf0e10cSrcweir 
956cdf0e10cSrcweir     if(nMul_ != nDiv_)
957cdf0e10cSrcweir         nVal = BigMulDiv(nVal, nMul_, nDiv_);
958cdf0e10cSrcweir 
959cdf0e10cSrcweir     aStr = UniString::CreateFromInt32(nVal);
960cdf0e10cSrcweir 
961cdf0e10cSrcweir     if(nK > 0 && aStr.Len() <= nK )
962cdf0e10cSrcweir     {
963cdf0e10cSrcweir         // Komma erforderlich
964cdf0e10cSrcweir         sal_Int16 nAnz(nK - aStr.Len());
965cdf0e10cSrcweir 
966cdf0e10cSrcweir         if(nAnz >= 0 && rLoc.isNumLeadingZero())
967cdf0e10cSrcweir             nAnz++;
968cdf0e10cSrcweir 
969cdf0e10cSrcweir         for(xub_StrLen i=0; i<nAnz; i++)
970cdf0e10cSrcweir             aStr.Insert(aNullCode, 0);
971cdf0e10cSrcweir 
972cdf0e10cSrcweir         // zu viele Nachkommastellen abhacken
973cdf0e10cSrcweir         xub_StrLen nNumDigits(rLoc.getNumDigits());
974cdf0e10cSrcweir         xub_StrLen nWeg(nK - nNumDigits);
975cdf0e10cSrcweir 
976cdf0e10cSrcweir         if(nWeg > 0)
977cdf0e10cSrcweir         {
9788d647522Smseidel             // hier müsste eigentlich noch gerundet werden!
979cdf0e10cSrcweir             aStr.Erase(aStr.Len() - nWeg);
980cdf0e10cSrcweir             nK = nNumDigits;
981cdf0e10cSrcweir         }
982cdf0e10cSrcweir     }
983cdf0e10cSrcweir 
9848d647522Smseidel     // Vorkommastellen für später merken
9858d647522Smseidel     xub_StrLen nPreComma(aStr.Len() - nK);
986cdf0e10cSrcweir 
987cdf0e10cSrcweir     if(nK > 0)
988cdf0e10cSrcweir     {
9898d647522Smseidel         // KommaChar einfügen
990cdf0e10cSrcweir         // erstmal trailing Zeros abhacken
991cdf0e10cSrcweir         while(nK > 0 && aStr.GetChar(aStr.Len() - 1) == aNullCode)
992cdf0e10cSrcweir         {
993cdf0e10cSrcweir             aStr.Erase(aStr.Len() - 1);
994cdf0e10cSrcweir             nK--;
995cdf0e10cSrcweir         }
996cdf0e10cSrcweir 
997cdf0e10cSrcweir         if(nK > 0)
998cdf0e10cSrcweir         {
999cdf0e10cSrcweir             // na, noch Nachkommastellen da?
1000cdf0e10cSrcweir             sal_Unicode cDec(rLoc.getNumDecimalSep().GetChar(0));
10018d647522Smseidel             aStr.Insert(cDec, nPreComma);
1002cdf0e10cSrcweir         }
1003cdf0e10cSrcweir     }
1004cdf0e10cSrcweir 
10058d647522Smseidel     // ggf. Trennpunkte bei jedem Tausender einfügen
10068d647522Smseidel     if( nPreComma > 3 )
1007cdf0e10cSrcweir     {
1008cdf0e10cSrcweir         String aThoSep( rLoc.getNumThousandSep() );
1009cdf0e10cSrcweir         if ( aThoSep.Len() > 0 )
1010cdf0e10cSrcweir         {
1011cdf0e10cSrcweir             sal_Unicode cTho( aThoSep.GetChar(0) );
10128d647522Smseidel             sal_Int32 i(nPreComma - 3);
1013cdf0e10cSrcweir 
1014cdf0e10cSrcweir             while(i > 0)
1015cdf0e10cSrcweir             {
1016cdf0e10cSrcweir                 rStr.Insert(cTho, (xub_StrLen)i);
1017cdf0e10cSrcweir                 i -= 3;
1018cdf0e10cSrcweir             }
1019cdf0e10cSrcweir         }
1020cdf0e10cSrcweir     }
1021cdf0e10cSrcweir 
1022cdf0e10cSrcweir     if(!aStr.Len())
1023cdf0e10cSrcweir         aStr += aNullCode;
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir     if(bNeg && (aStr.Len() > 1 || aStr.GetChar(0) != aNullCode))
1026cdf0e10cSrcweir     {
1027cdf0e10cSrcweir         rStr.Insert(sal_Unicode('-'), 0);
1028cdf0e10cSrcweir     }
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir     rStr = aStr;
1031cdf0e10cSrcweir }
1032cdf0e10cSrcweir 
TakeUnitStr(MapUnit eUnit,XubString & rStr)1033cdf0e10cSrcweir void SdrFormatter::TakeUnitStr(MapUnit eUnit, XubString& rStr)
1034cdf0e10cSrcweir {
103598d5c9bfSHerbert Dürr     const sal_Char* pText;
103698d5c9bfSHerbert Dürr 
1037cdf0e10cSrcweir     switch(eUnit)
1038cdf0e10cSrcweir     {
103998d5c9bfSHerbert Dürr         // metric units
104098d5c9bfSHerbert Dürr         case MAP_100TH_MM   : pText = "/100mm"; break;
104198d5c9bfSHerbert Dürr         case MAP_10TH_MM    : pText = "/10mm"; break;
104298d5c9bfSHerbert Dürr         case MAP_MM         : pText = "mm"; break;
104398d5c9bfSHerbert Dürr         case MAP_CM         : pText = "cm"; break;
104498d5c9bfSHerbert Dürr 
104598d5c9bfSHerbert Dürr         // imperial units
104698d5c9bfSHerbert Dürr         case MAP_1000TH_INCH: pText = "/1000\""; break;
104798d5c9bfSHerbert Dürr         case MAP_100TH_INCH : pText = "/100\""; break;
104898d5c9bfSHerbert Dürr         case MAP_10TH_INCH  : pText = "/10\""; break;
104998d5c9bfSHerbert Dürr         case MAP_INCH       : pText = "\""; break;
105098d5c9bfSHerbert Dürr         case MAP_POINT      : pText = "pt"; break;
105198d5c9bfSHerbert Dürr         case MAP_TWIP       : pText = "twip"; break;
105298d5c9bfSHerbert Dürr 
105398d5c9bfSHerbert Dürr         // other units
105498d5c9bfSHerbert Dürr         case MAP_PIXEL      : pText = "pixel"; break;
105598d5c9bfSHerbert Dürr         case MAP_SYSFONT    : pText = "sysfont"; break;
105698d5c9bfSHerbert Dürr         case MAP_APPFONT    : pText = "appfont"; break;
105745bcc212SArmin Le Grand         case MAP_RELATIVE   : pText = "%"; break;
105898d5c9bfSHerbert Dürr 
105998d5c9bfSHerbert Dürr         default             : pText = ""; break;
1060cdf0e10cSrcweir     }
1061cdf0e10cSrcweir 
106298d5c9bfSHerbert Dürr     rStr = XubString::CreateFromAscii( pText );
1063cdf0e10cSrcweir }
1064cdf0e10cSrcweir 
TakeUnitStr(FieldUnit eUnit,XubString & rStr)1065cdf0e10cSrcweir void SdrFormatter::TakeUnitStr(FieldUnit eUnit, XubString& rStr)
1066cdf0e10cSrcweir {
106798d5c9bfSHerbert Dürr     const sal_Char* pText;
106898d5c9bfSHerbert Dürr 
1069cdf0e10cSrcweir     switch(eUnit)
1070cdf0e10cSrcweir     {
107198d5c9bfSHerbert Dürr         // metric units
107298d5c9bfSHerbert Dürr         case FUNIT_100TH_MM : pText = "/100mm"; break;
107398d5c9bfSHerbert Dürr         case FUNIT_MM       : pText = "mm"; break;
107498d5c9bfSHerbert Dürr         case FUNIT_CM       : pText = "cm"; break;
107598d5c9bfSHerbert Dürr         case FUNIT_M        : pText = "m"; break;
107698d5c9bfSHerbert Dürr         case FUNIT_KM       : pText = "km"; break;
107798d5c9bfSHerbert Dürr 
107898d5c9bfSHerbert Dürr         // imperial units
107998d5c9bfSHerbert Dürr         case FUNIT_TWIP     : pText = "twip"; break;
108098d5c9bfSHerbert Dürr         case FUNIT_POINT    : pText = "pt"; break;
108198d5c9bfSHerbert Dürr         case FUNIT_PICA     : pText = "pica"; break;
108298d5c9bfSHerbert Dürr         case FUNIT_INCH     : pText = "\""; break;
108398d5c9bfSHerbert Dürr         case FUNIT_FOOT     : pText = "ft"; break;
108498d5c9bfSHerbert Dürr         case FUNIT_MILE     : pText = "mile(s)"; break;
108598d5c9bfSHerbert Dürr 
108698d5c9bfSHerbert Dürr         // other units
108745bcc212SArmin Le Grand         case FUNIT_PERCENT: pText = "%"; break;
108898d5c9bfSHerbert Dürr 
108998d5c9bfSHerbert Dürr //      case FUNIT_NONE     :
109098d5c9bfSHerbert Dürr //      case FUNIT_CUSTOM   :
109198d5c9bfSHerbert Dürr         default             : pText = ""; break;
1092cdf0e10cSrcweir     }
1093cdf0e10cSrcweir 
109498d5c9bfSHerbert Dürr     rStr = XubString::CreateFromAscii( pText );
1095cdf0e10cSrcweir }
1096cdf0e10cSrcweir 
10978d647522Smseidel /* vim: set noet sw=4 ts=4: */
1098