bump product version to 4.1.6.2
[LibreOffice.git] / lotuswordpro / source / filter / lwpsdwrect.cxx
blob221b4edbb74d35d527882232c9064058738f324a
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * The Contents of this file are made available subject to the terms of
5 * either of the following licenses
7 * - GNU Lesser General Public License Version 2.1
8 * - Sun Industry Standards Source License Version 1.1
10 * Sun Microsystems Inc., October, 2000
12 * GNU Lesser General Public License Version 2.1
13 * =============================================
14 * Copyright 2000 by Sun Microsystems, Inc.
15 * 901 San Antonio Road, Palo Alto, CA 94303, USA
17 * This library is free software; you can redistribute it and/or
18 * modify it under the terms of the GNU Lesser General Public
19 * License version 2.1, as published by the Free Software Foundation.
21 * This library is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
24 * Lesser General Public License for more details.
26 * You should have received a copy of the GNU Lesser General Public
27 * License along with this library; if not, write to the Free Software
28 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
29 * MA 02111-1307 USA
32 * Sun Industry Standards Source License Version 1.1
33 * =================================================
34 * The contents of this file are subject to the Sun Industry Standards
35 * Source License Version 1.1 (the "License"); You may not use this file
36 * except in compliance with the License. You may obtain a copy of the
37 * License at http://www.openoffice.org/license.html.
39 * Software provided under this License is provided on an "AS IS" basis,
40 * WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING,
41 * WITHOUT LIMITATION, WARRANTIES THAT THE SOFTWARE IS FREE OF DEFECTS,
42 * MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE, OR NON-INFRINGING.
43 * See the License for the specific provisions governing your rights and
44 * obligations concerning the Software.
46 * The Initial Developer of the Original Code is: IBM Corporation
48 * Copyright: 2008 by IBM Corporation
50 * All Rights Reserved.
52 * Contributor(s): _______________________________________
55 ************************************************************************/
56 /*****************************************************************************
57 * Change History
58 * Mar 2005 Revised for lwpfilter
59 ****************************************************************************/
60 /**
61 * @file
62 * For LWP filter architecture prototype
63 * Implementation file of SdwRectangle.
65 #include "lwpsdwrect.hxx"
67 /**************************************************************************
68 * @date: 11/19/2004
69 * @short: Default constructor
70 **************************************************************************/
71 SdwRectangle::SdwRectangle() : m_bRotated(sal_False)
73 for (sal_uInt16 i = 0; i < 4; i++)
75 m_nRectCorner[0] = Point(0, 0);
78 /**************************************************************************
79 * @date: 11/19/2004
80 * @short: Constructor
81 * @param: aPt0~aPt3 four corner points of a rectangle.
82 **************************************************************************/
83 SdwRectangle::SdwRectangle(const Point& rPt0, const Point& rPt1,
84 const Point& rPt2, const Point& rPt3) : m_bRotated(sal_True)
86 m_nRectCorner[0] = rPt0;
87 m_nRectCorner[1] = rPt1;
88 m_nRectCorner[2] = rPt2;
89 m_nRectCorner[3] = rPt3;
91 if (rPt0.Y() == rPt1.Y() && rPt0.Y() < rPt3.Y())
93 m_bRotated = sal_False;
97 /**************************************************************************
98 * @date: 12/15/2004
99 * @short: Copy constructor
100 **************************************************************************/
101 SdwRectangle::SdwRectangle(const SdwRectangle& rOther)
103 m_nRectCorner[0] = rOther.m_nRectCorner[0];
104 m_nRectCorner[1] = rOther.m_nRectCorner[1];
105 m_nRectCorner[2] = rOther.m_nRectCorner[2];
106 m_nRectCorner[3] = rOther.m_nRectCorner[3];
108 m_bRotated = rOther.IsRectRotated();
110 /**************************************************************************
111 * @date: 11/19/2004
112 * @short: Destructor
113 **************************************************************************/
114 SdwRectangle::~SdwRectangle()
117 /**************************************************************************
118 * @date: 11/19/2004
119 * @short: Get the flag whether if the rectangle has been rotated.
120 * @return: m_bRotated rotation flag.
121 **************************************************************************/
122 sal_Bool SdwRectangle::IsRectRotated() const
124 return m_bRotated;
126 /**************************************************************************
127 * @date: 11/19/2004
128 * @short: Calculate and return center point of the rectangle.
129 * @return: center point
130 **************************************************************************/
131 Point SdwRectangle::GetRectCenter() const
133 long nX = (long)((double)(m_nRectCorner[0].X() + m_nRectCorner[2].X())/2 + 0.5);
134 long nY = (long)((double)(m_nRectCorner[0].Y() + m_nRectCorner[2].Y())/2 + 0.5);
136 return Point(nX, nY);
138 /**************************************************************************
139 * @date: 11/19/2004
140 * @short: Calculate width of the rectangle.
141 * @return: rectangle width.
142 **************************************************************************/
143 long SdwRectangle::GetWidth() const
145 long nX0 = m_nRectCorner[0].X();
146 long nY0 = m_nRectCorner[0].Y();
147 long nX1 = m_nRectCorner[1].X();
148 long nY1 = m_nRectCorner[1].Y();
150 return (long)CalcDistBetween2Points(nX0, nY0, nX1, nY1);
152 /**************************************************************************
153 * @date: 11/19/2004
154 * @short: Calculate height of the rectangle.
155 * @return: rectangle height.
156 **************************************************************************/
157 long SdwRectangle::GetHeight() const
159 long nX1 = m_nRectCorner[1].X();
160 long nY1 = m_nRectCorner[1].Y();
161 long nX2 = m_nRectCorner[2].X();
162 long nY2 = m_nRectCorner[2].Y();
164 return (long)CalcDistBetween2Points(nX1, nY1, nX2, nY2);
166 /**************************************************************************
167 * @date: 11/19/2004
168 * @short: Calculate coordinate of the original rectangle.
169 * @return: a prz rectangle
170 **************************************************************************/
171 Rectangle SdwRectangle::GetOriginalRect() const
173 if (m_bRotated)
175 long nHeight = GetHeight();
176 long nWidth = GetWidth();
177 Point aCenter = GetRectCenter();
179 Point aLT(aCenter.X()-(long)((double)nWidth/2+0.5),
180 aCenter.Y()-(long)((double)nHeight/2+0.5));
181 Point aRB(aLT.X()+nWidth, aLT.Y()+nHeight);
183 return Rectangle(aLT, aRB);
185 else
187 return Rectangle(m_nRectCorner[3], m_nRectCorner[1]);
190 /**************************************************************************
191 * @date: 11/19/2004
192 * @short: Calculate rotation angle of the rectangle.
193 * @return: rotation angle.
194 **************************************************************************/
195 double SdwRectangle::GetRotationAngle() const
197 if (!m_bRotated)
199 return 0.00;
202 double fX1 = (double)(m_nRectCorner[1].X());
203 double fY1 = (double)(m_nRectCorner[1].Y());
204 double fX2 = (double)(m_nRectCorner[2].X());
205 double fY2 = (double)(m_nRectCorner[2].Y());
206 double fMidX = (fX1 + fX2) / 2;
207 double fMidY = (fY1 + fY2) / 2;
209 Point aCenter = GetRectCenter();
210 double fCenterX = (double)aCenter.X();
211 double fCenterY = (double)aCenter.Y();
213 double fAngle = atan2((fMidY - fCenterY), (fMidX - fCenterX));
215 return -fAngle;
218 double SdwRectangle::CalcDistBetween2Points(long nX1, long nY1, long nX2, long nY2)
220 return sqrt((double)((nX1-nX2)*(nX1-nX2) + (nY1-nY2)*(nY1-nY2)));
223 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */