merge the formfield patch from ooo-build
[ooovba.git] / lotuswordpro / source / filter / lwpsdwrect.cxx
blobc5debee659ee37b873fdc26f93a4f54ae6401ac1
1 /*************************************************************************
3 * The Contents of this file are made available subject to the terms of
4 * either of the following licenses
6 * - GNU Lesser General Public License Version 2.1
7 * - Sun Industry Standards Source License Version 1.1
9 * Sun Microsystems Inc., October, 2000
11 * GNU Lesser General Public License Version 2.1
12 * =============================================
13 * Copyright 2000 by Sun Microsystems, Inc.
14 * 901 San Antonio Road, Palo Alto, CA 94303, USA
16 * This library is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU Lesser General Public
18 * License version 2.1, as published by the Free Software Foundation.
20 * This library is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with this library; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
28 * MA 02111-1307 USA
31 * Sun Industry Standards Source License Version 1.1
32 * =================================================
33 * The contents of this file are subject to the Sun Industry Standards
34 * Source License Version 1.1 (the "License"); You may not use this file
35 * except in compliance with the License. You may obtain a copy of the
36 * License at http://www.openoffice.org/license.html.
38 * Software provided under this License is provided on an "AS IS" basis,
39 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
40 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
41 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
42 * See the License for the specific provisions governing your rights and
43 * obligations concerning the Software.
45 * The Initial Developer of the Original Code is: IBM Corporation
47 * Copyright: 2008 by IBM Corporation
49 * All Rights Reserved.
51 * Contributor(s): _______________________________________
54 ************************************************************************/
55 /*****************************************************************************
56 * Change History
57 * Mar 2005 Revised for lwpfilter
58 ****************************************************************************/
59 /**
60 * @file
61 * For LWP filter architecture prototype
62 * Implementation file of SdwRectangle.
64 #include "lwpsdwrect.hxx"
66 /**************************************************************************
67 * @date: 11/19/2004
68 * @short: Default constructor
69 **************************************************************************/
70 SdwRectangle::SdwRectangle() : m_bRotated(sal_False)
72 for (UINT16 i = 0; i < 4; i++)
74 m_nRectCorner[0] = Point(0, 0);
77 /**************************************************************************
78 * @date: 11/19/2004
79 * @short: Constructor
80 * @param: aPt0~aPt3 four corner points of a rectangle.
81 **************************************************************************/
82 SdwRectangle::SdwRectangle(const Point& rPt0, const Point& rPt1,
83 const Point& rPt2, const Point& rPt3) : m_bRotated(sal_True)
85 m_nRectCorner[0] = rPt0;
86 m_nRectCorner[1] = rPt1;
87 m_nRectCorner[2] = rPt2;
88 m_nRectCorner[3] = rPt3;
90 if (rPt0.Y() == rPt1.Y() && rPt0.Y() < rPt3.Y())
92 m_bRotated = sal_False;
96 /**************************************************************************
97 * @date: 12/15/2004
98 * @short: Copy constructor
99 **************************************************************************/
100 SdwRectangle::SdwRectangle(const SdwRectangle& rOther)
102 m_nRectCorner[0] = rOther.m_nRectCorner[0];
103 m_nRectCorner[1] = rOther.m_nRectCorner[1];
104 m_nRectCorner[2] = rOther.m_nRectCorner[2];
105 m_nRectCorner[3] = rOther.m_nRectCorner[3];
107 m_bRotated = rOther.IsRectRotated();
109 /**************************************************************************
110 * @date: 11/19/2004
111 * @short: Destructor
112 **************************************************************************/
113 SdwRectangle::~SdwRectangle()
116 /**************************************************************************
117 * @date: 11/19/2004
118 * @short: Get the flag whether if the rectangle has been rotated.
119 * @return: m_bRotated rotation flag.
120 **************************************************************************/
121 sal_Bool SdwRectangle::IsRectRotated() const
123 return m_bRotated;
125 /**************************************************************************
126 * @date: 11/19/2004
127 * @short: Calculate and return center point of the rectangle.
128 * @return: center point
129 **************************************************************************/
130 Point SdwRectangle::GetRectCenter() const
132 long nX = (long)((double)(m_nRectCorner[0].X() + m_nRectCorner[2].X())/2 + 0.5);
133 long nY = (long)((double)(m_nRectCorner[0].Y() + m_nRectCorner[2].Y())/2 + 0.5);
135 return Point(nX, nY);
137 /**************************************************************************
138 * @date: 11/19/2004
139 * @short: Calculate width of the rectangle.
140 * @return: rectangle width.
141 **************************************************************************/
142 long SdwRectangle::GetWidth() const
144 long nX0 = m_nRectCorner[0].X();
145 long nY0 = m_nRectCorner[0].Y();
146 long nX1 = m_nRectCorner[1].X();
147 long nY1 = m_nRectCorner[1].Y();
149 return (long)CalcDistBetween2Points(nX0, nY0, nX1, nY1);
151 /**************************************************************************
152 * @date: 11/19/2004
153 * @short: Calculate height of the rectangle.
154 * @return: rectangle height.
155 **************************************************************************/
156 long SdwRectangle::GetHeight() const
158 long nX1 = m_nRectCorner[1].X();
159 long nY1 = m_nRectCorner[1].Y();
160 long nX2 = m_nRectCorner[2].X();
161 long nY2 = m_nRectCorner[2].Y();
163 return (long)CalcDistBetween2Points(nX1, nY1, nX2, nY2);
165 /**************************************************************************
166 * @date: 11/19/2004
167 * @short: Calculate coordinate of the original rectangle.
168 * @return: a prz rectangle
169 **************************************************************************/
170 Rectangle SdwRectangle::GetOriginalRect() const
172 if (m_bRotated)
174 long nHeight = GetHeight();
175 long nWidth = GetWidth();
176 Point aCenter = GetRectCenter();
178 Point aLT(aCenter.X()-(long)((double)nWidth/2+0.5),
179 aCenter.Y()-(long)((double)nHeight/2+0.5));
180 Point aRT(aLT.X()+nWidth, aLT.Y());
181 Point aLB(aLT.X(), aLT.Y()-nHeight);
182 Point aRB(aLT.X()+nWidth, aLT.Y()+nHeight);
184 return Rectangle(aLT, aRB);
186 else
188 return Rectangle(m_nRectCorner[3], m_nRectCorner[1]);
191 /**************************************************************************
192 * @date: 11/19/2004
193 * @short: Calculate rotation angle of the rectangle.
194 * @return: rotation angle.
195 **************************************************************************/
196 double SdwRectangle::GetRotationAngle() const
198 if (!m_bRotated)
200 return 0.00;
203 double fX1 = (double)(m_nRectCorner[1].X());
204 double fY1 = (double)(m_nRectCorner[1].Y());
205 double fX2 = (double)(m_nRectCorner[2].X());
206 double fY2 = (double)(m_nRectCorner[2].Y());
207 double fMidX = (fX1 + fX2) / 2;
208 double fMidY = (fY1 + fY2) / 2;
210 Point aCenter = GetRectCenter();
211 double fCenterX = (double)aCenter.X();
212 double fCenterY = (double)aCenter.Y();
214 double fAngle = atan2((fMidY - fCenterY), (fMidX - fCenterX));
216 return -fAngle;
219 double SdwRectangle::CalcDistBetween2Points(long nX1, long nY1, long nX2, long nY2)
221 return sqrt((double)((nX1-nX2)*(nX1-nX2) + (nY1-nY2)*(nY1-nY2)));
224 Rectangle SdwRectangle::GetOriginalRect(const Point& rCenter, long nHalfWidth, long nHalfHeight)
226 Point aLT(rCenter.X()-nHalfWidth, rCenter.Y()-nHalfHeight);
227 Point aRB(rCenter.X()+nHalfWidth, rCenter.Y()+nHalfHeight);
229 return Rectangle(aLT, aRB);