tdf#163948: fix crash when NotesPane is enabled on Tabbed UI
[LibreOffice.git] / lotuswordpro / source / filter / lwpsdwrect.cxx
blob3bc2704ac76f260b86f75be16adc3947976bc6bc
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 * @file
58 * For LWP filter architecture prototype
59 * Implementation file of SdwRectangle.
62 #include "lwpsdwrect.hxx"
63 #include <cmath>
65 /**************************************************************************
66 * @short: Default constructor
67 **************************************************************************/
68 SdwRectangle::SdwRectangle()
69 : m_bRotated(false)
70 // m_nRectCorner array fields are default initialized with Point()
73 /**************************************************************************
74 * @short: Constructor
75 * @param: aPt0~aPt3 four corner points of a rectangle.
76 **************************************************************************/
77 SdwRectangle::SdwRectangle(const Point& rPt0, const Point& rPt1,
78 const Point& rPt2, const Point& rPt3)
79 : m_bRotated(rPt0.Y() != rPt1.Y() || rPt0.Y() >= rPt3.Y())
80 , m_nRectCorner({{rPt0, rPt1, rPt2, rPt3}})
84 /**************************************************************************
85 * @short: Calculate and return center point of the rectangle.
86 * @return: center point
87 **************************************************************************/
88 Point SdwRectangle::GetRectCenter() const
90 tools::Long nX = static_cast<tools::Long>(static_cast<double>(m_nRectCorner[0].X() + m_nRectCorner[2].X())/2 + 0.5);
91 tools::Long nY = static_cast<tools::Long>(static_cast<double>(m_nRectCorner[0].Y() + m_nRectCorner[2].Y())/2 + 0.5);
93 return Point(nX, nY);
95 /**************************************************************************
96 * @short: Calculate width of the rectangle.
97 * @return: rectangle width.
98 **************************************************************************/
99 tools::Long SdwRectangle::GetWidth() const
101 tools::Long nX0 = m_nRectCorner[0].X();
102 tools::Long nY0 = m_nRectCorner[0].Y();
103 tools::Long nX1 = m_nRectCorner[1].X();
104 tools::Long nY1 = m_nRectCorner[1].Y();
106 return static_cast<tools::Long>(CalcDistBetween2Points(nX0, nY0, nX1, nY1));
108 /**************************************************************************
109 * @short: Calculate height of the rectangle.
110 * @return: rectangle height.
111 **************************************************************************/
112 tools::Long SdwRectangle::GetHeight() const
114 tools::Long nX1 = m_nRectCorner[1].X();
115 tools::Long nY1 = m_nRectCorner[1].Y();
116 tools::Long nX2 = m_nRectCorner[2].X();
117 tools::Long nY2 = m_nRectCorner[2].Y();
119 return static_cast<tools::Long>(CalcDistBetween2Points(nX1, nY1, nX2, nY2));
121 /**************************************************************************
122 * @short: Calculate coordinate of the original rectangle.
123 * @return: a prz rectangle
124 **************************************************************************/
125 tools::Rectangle SdwRectangle::GetOriginalRect() const
127 if (m_bRotated)
129 tools::Long nHeight = GetHeight();
130 tools::Long nWidth = GetWidth();
131 Point aCenter = GetRectCenter();
133 Point aLT(aCenter.X()-static_cast<tools::Long>(static_cast<double>(nWidth)/2+0.5),
134 aCenter.Y()-static_cast<tools::Long>(static_cast<double>(nHeight)/2+0.5));
135 Point aRB(aLT.X()+nWidth, aLT.Y()+nHeight);
137 return tools::Rectangle(aLT, aRB);
139 else
141 return tools::Rectangle(m_nRectCorner[3], m_nRectCorner[1]);
144 /**************************************************************************
145 * @short: Calculate rotation angle of the rectangle.
146 * @return: rotation angle.
147 **************************************************************************/
148 double SdwRectangle::GetRotationAngle() const
150 if (!m_bRotated)
152 return 0.00;
155 double fX1 = static_cast<double>(m_nRectCorner[1].X());
156 double fY1 = static_cast<double>(m_nRectCorner[1].Y());
157 double fX2 = static_cast<double>(m_nRectCorner[2].X());
158 double fY2 = static_cast<double>(m_nRectCorner[2].Y());
159 double fMidX = (fX1 + fX2) / 2;
160 double fMidY = (fY1 + fY2) / 2;
162 Point aCenter = GetRectCenter();
163 double fCenterX = static_cast<double>(aCenter.X());
164 double fCenterY = static_cast<double>(aCenter.Y());
166 double fAngle = atan2((fMidY - fCenterY), (fMidX - fCenterX));
168 return -fAngle;
171 double SdwRectangle::CalcDistBetween2Points(tools::Long nX1, tools::Long nY1, tools::Long nX2, tools::Long nY2)
173 return std::hypot(nX1 - nX2, nY1 - nY2);
176 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */