merged tag ooo/OOO330_m14
[LibreOffice.git] / starmath / inc / rect.hxx
blobf1af81c5c163b3a85b76bfdc6285b783ecb02f04
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
28 #ifndef RECT_HXX
29 #define RECT_HXX
31 #include <new>
34 #include <tools/gen.hxx>
35 #include <vcl/outdev.hxx>
36 #include <vcl/metric.hxx>
37 #include <tools/debug.hxx>
39 #include "format.hxx"
42 BOOL SmGetGlyphBoundRect(const OutputDevice &rDev,
43 const XubString &rText, Rectangle &rRect);
45 BOOL SmIsMathAlpha(const XubString &rText);
48 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
50 return nFrom + (long) (fRelDist * (nTo - nFrom));
54 ////////////////////////////////////////
55 // SmRect
56 // ... (to be done)
57 // This Implementation assumes that the x-axis points to the right and the
58 // y-axis to the bottom.
59 // Note: however, italic spaces can be negative!
62 // possible flags for the 'Draw' function below (just for debugging)
63 #define SM_RECT_CORE 0x0001
64 #define SM_RECT_ITALIC 0x0002
65 #define SM_RECT_LINES 0x0004
66 #define SM_RECT_MID 0x0008
68 // possible positions and alignments for the 'AlignTo' function
69 enum RectPos
70 // (RP_LEFT : align the current object to the left of the argument, ...)
71 { RP_LEFT, RP_RIGHT,
72 RP_TOP, RP_BOTTOM,
73 RP_ATTRIBUT
75 enum RectHorAlign
76 { RHA_LEFT, RHA_CENTER, RHA_RIGHT
78 enum RectVerAlign
79 { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
80 RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
83 // different methods of copying baselines and mid's in 'ExtendBy' function
84 enum RectCopyMBL
85 { RCP_THIS, // keep baseline of current object even if it has none
86 RCP_ARG, // as above but for the argument
87 RCP_NONE, // result will have no baseline
88 RCP_XOR // if current object has a baseline keep it else copy
89 // the arguments baseline (even if it has none)
93 class SmRect
95 Point aTopLeft;
96 Size aSize;
97 long nBaseline,
98 nAlignT,
99 nAlignM,
100 nAlignB,
101 nGlyphTop,
102 nGlyphBottom,
103 nItalicLeftSpace,
104 nItalicRightSpace,
105 nLoAttrFence,
106 nHiAttrFence;
107 USHORT nBorderWidth;
108 BOOL bHasBaseline,
109 bHasAlignInfo;
111 protected:
112 void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
113 const XubString &rText, USHORT nBorderWidth);
114 void Init(const OutputDevice &rDev, const SmFormat *pFormat,
115 const XubString &rText, USHORT nBorderWidth);
117 void ClearBaseline() { bHasBaseline = FALSE; };
118 inline void CopyMBL(const SmRect& rRect);
119 void CopyAlignInfo(const SmRect& rRect);
121 SmRect & Union(const SmRect &rRect);
123 public:
124 SmRect();
125 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
126 const XubString &rText, long nBorderWidth);
127 SmRect(long nWidth, long nHeight);
128 SmRect(const SmRect &rRect);
131 USHORT GetBorderWidth() const { return nBorderWidth; }
133 void SetItalicSpaces(long nLeftSpace, long nRightSpace);
135 void SetWidth(ULONG nWidth) { aSize.Width() = nWidth; }
136 void SetHeight(ULONG nHeight) { aSize.Height() = nHeight; }
138 void SetLeft(long nLeft);
139 void SetRight(long nRight);
140 void SetBottom(long nBottom);
141 void SetTop(long nTop);
143 const Point & GetTopLeft() const { return aTopLeft; }
145 long GetTop() const { return GetTopLeft().Y(); }
146 long GetLeft() const { return GetTopLeft().X(); }
147 long GetBottom() const { return GetTop() + GetHeight() - 1; }
148 long GetRight() const { return GetLeft() + GetWidth() - 1; }
149 long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
150 long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
151 long GetWidth() const { return GetSize().Width(); }
152 long GetHeight() const { return GetSize().Height(); }
154 long GetItalicLeftSpace() const { return nItalicLeftSpace; }
155 long GetItalicRightSpace() const { return nItalicRightSpace; }
157 void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; }
158 void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; }
159 long GetHiAttrFence() const { return nHiAttrFence; }
160 long GetLoAttrFence() const { return nLoAttrFence; }
162 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
163 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
164 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
165 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
167 BOOL HasBaseline() const { return bHasBaseline; }
168 inline long GetBaseline() const;
169 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
171 void SetAlignTop(long nVal) { nAlignT = nVal; }
173 long GetAlignT() const { return nAlignT; }
174 long GetAlignM() const { return nAlignM; }
175 long GetAlignB() const { return nAlignB; }
177 void SetAlignT(long nVal) { nAlignT = nVal; }
179 const Point GetCenter() const
180 { return Point(GetCenterX(), GetCenterY()); }
182 const Size & GetSize() const { return aSize; }
184 const Size GetItalicSize() const
185 { return Size(GetItalicWidth(), GetHeight()); }
187 void Move (const Point &rPosition);
188 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
190 BOOL IsEmpty() const
192 return GetWidth() == 0 || GetHeight() == 0;
195 BOOL HasAlignInfo() const { return bHasAlignInfo; }
197 const Point AlignTo(const SmRect &rRect, RectPos ePos,
198 RectHorAlign eHor, RectVerAlign eVer) const;
200 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
201 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
202 long nNewAlignM);
203 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
204 BOOL bKeepVerAlignParams);
206 long OrientedDist(const Point &rPoint) const;
207 BOOL IsInsideRect(const Point &rPoint) const;
208 BOOL IsInsideItalicRect(const Point &rPoint) const;
210 inline SmRect & operator = (const SmRect &rRect);
212 inline Rectangle AsRectangle() const;
213 SmRect AsGlyphRect() const;
215 #ifdef SM_RECT_DEBUG
216 void Draw(OutputDevice &rDev, const Point &rPosition, int nFlags) const;
217 #endif
221 inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
222 // set extra spacing to the left and right for (italic)
223 // letters/text
225 nItalicLeftSpace = nLeftSpace;
226 nItalicRightSpace = nRightSpace;
230 inline void SmRect::CopyMBL(const SmRect &rRect)
231 // copy AlignM baseline and value of 'rRect'
233 nBaseline = rRect.nBaseline;
234 bHasBaseline = rRect.bHasBaseline;
235 nAlignM = rRect.nAlignM;
239 inline long SmRect::GetBaseline() const
241 DBG_ASSERT(HasBaseline(), "Sm: Baseline nicht vorhanden");
242 return nBaseline;
246 inline SmRect & SmRect::operator = (const SmRect &rRect)
248 new (this) SmRect(rRect); // placement new
249 return *this;
253 inline Rectangle SmRect::AsRectangle() const
255 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
260 #endif