update dev300-m58
[ooovba.git] / starmath / inc / rect.hxx
blob472b03b2f4540f96ea73526bf28d82844539d6a9
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rect.hxx,v $
10 * $Revision: 1.7 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #ifndef RECT_HXX
32 #define RECT_HXX
34 #include <new>
37 #include <tools/gen.hxx>
38 #include <vcl/outdev.hxx>
39 #include <vcl/metric.hxx>
40 #include <tools/debug.hxx>
42 #include "format.hxx"
45 BOOL SmGetGlyphBoundRect(const OutputDevice &rDev,
46 const XubString &rText, Rectangle &rRect);
48 BOOL SmIsMathAlpha(const XubString &rText);
51 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
53 return nFrom + (long) (fRelDist * (nTo - nFrom));
57 ////////////////////////////////////////
58 // SmRect
59 // ... (to be done)
60 // This Implementation assumes that the x-axis points to the right and the
61 // y-axis to the bottom.
62 // Note: however, italic spaces can be negative!
65 // possible flags for the 'Draw' function below (just for debugging)
66 #define SM_RECT_CORE 0x0001
67 #define SM_RECT_ITALIC 0x0002
68 #define SM_RECT_LINES 0x0004
69 #define SM_RECT_MID 0x0008
71 // possible positions and alignments for the 'AlignTo' function
72 enum RectPos
73 // (RP_LEFT : align the current object to the left of the argument, ...)
74 { RP_LEFT, RP_RIGHT,
75 RP_TOP, RP_BOTTOM,
76 RP_ATTRIBUT
78 enum RectHorAlign
79 { RHA_LEFT, RHA_CENTER, RHA_RIGHT
81 enum RectVerAlign
82 { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
83 RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
86 // different methods of copying baselines and mid's in 'ExtendBy' function
87 enum RectCopyMBL
88 { RCP_THIS, // keep baseline of current object even if it has none
89 RCP_ARG, // as above but for the argument
90 RCP_NONE, // result will have no baseline
91 RCP_XOR // if current object has a baseline keep it else copy
92 // the arguments baseline (even if it has none)
96 class SmRect
98 Point aTopLeft;
99 Size aSize;
100 long nBaseline,
101 nAlignT,
102 nAlignM,
103 nAlignB,
104 nGlyphTop,
105 nGlyphBottom,
106 nItalicLeftSpace,
107 nItalicRightSpace,
108 nLoAttrFence,
109 nHiAttrFence;
110 USHORT nBorderWidth;
111 BOOL bHasBaseline,
112 bHasAlignInfo;
114 protected:
115 void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
116 const XubString &rText, USHORT nBorderWidth);
117 void Init(const OutputDevice &rDev, const SmFormat *pFormat,
118 const XubString &rText, USHORT nBorderWidth);
120 void ClearBaseline() { bHasBaseline = FALSE; };
121 inline void CopyMBL(const SmRect& rRect);
122 void CopyAlignInfo(const SmRect& rRect);
124 SmRect & Union(const SmRect &rRect);
126 public:
127 SmRect();
128 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
129 const XubString &rText, long nBorderWidth);
130 SmRect(long nWidth, long nHeight);
131 SmRect(const SmRect &rRect);
134 USHORT GetBorderWidth() const { return nBorderWidth; }
136 void SetItalicSpaces(long nLeftSpace, long nRightSpace);
138 void SetWidth(ULONG nWidth) { aSize.Width() = nWidth; }
139 void SetHeight(ULONG nHeight) { aSize.Height() = nHeight; }
141 void SetLeft(long nLeft);
142 void SetRight(long nRight);
143 void SetBottom(long nBottom);
144 void SetTop(long nTop);
146 const Point & GetTopLeft() const { return aTopLeft; }
148 long GetTop() const { return GetTopLeft().Y(); }
149 long GetLeft() const { return GetTopLeft().X(); }
150 long GetBottom() const { return GetTop() + GetHeight() - 1; }
151 long GetRight() const { return GetLeft() + GetWidth() - 1; }
152 long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
153 long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
154 long GetWidth() const { return GetSize().Width(); }
155 long GetHeight() const { return GetSize().Height(); }
157 long GetItalicLeftSpace() const { return nItalicLeftSpace; }
158 long GetItalicRightSpace() const { return nItalicRightSpace; }
160 void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; }
161 void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; }
162 long GetHiAttrFence() const { return nHiAttrFence; }
163 long GetLoAttrFence() const { return nLoAttrFence; }
165 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
166 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
167 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
168 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
170 BOOL HasBaseline() const { return bHasBaseline; }
171 inline long GetBaseline() const;
172 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
174 void SetAlignTop(long nVal) { nAlignT = nVal; }
176 long GetAlignT() const { return nAlignT; }
177 long GetAlignM() const { return nAlignM; }
178 long GetAlignB() const { return nAlignB; }
180 void SetAlignT(long nVal) { nAlignT = nVal; }
182 const Point GetCenter() const
183 { return Point(GetCenterX(), GetCenterY()); }
185 const Size & GetSize() const { return aSize; }
187 const Size GetItalicSize() const
188 { return Size(GetItalicWidth(), GetHeight()); }
190 void Move (const Point &rPosition);
191 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
193 BOOL IsEmpty() const
195 return GetWidth() == 0 || GetHeight() == 0;
198 BOOL HasAlignInfo() const { return bHasAlignInfo; }
200 const Point AlignTo(const SmRect &rRect, RectPos ePos,
201 RectHorAlign eHor, RectVerAlign eVer) const;
203 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
204 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
205 long nNewAlignM);
206 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
207 BOOL bKeepVerAlignParams);
209 long OrientedDist(const Point &rPoint) const;
210 BOOL IsInsideRect(const Point &rPoint) const;
211 BOOL IsInsideItalicRect(const Point &rPoint) const;
213 inline SmRect & operator = (const SmRect &rRect);
215 inline Rectangle AsRectangle() const;
216 SmRect AsGlyphRect() const;
218 #ifdef SM_RECT_DEBUG
219 void Draw(OutputDevice &rDev, const Point &rPosition, int nFlags) const;
220 #endif
224 inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
225 // set extra spacing to the left and right for (italic)
226 // letters/text
228 nItalicLeftSpace = nLeftSpace;
229 nItalicRightSpace = nRightSpace;
233 inline void SmRect::CopyMBL(const SmRect &rRect)
234 // copy AlignM baseline and value of 'rRect'
236 nBaseline = rRect.nBaseline;
237 bHasBaseline = rRect.bHasBaseline;
238 nAlignM = rRect.nAlignM;
242 inline long SmRect::GetBaseline() const
244 DBG_ASSERT(HasBaseline(), "Sm: Baseline nicht vorhanden");
245 return nBaseline;
249 inline SmRect & SmRect::operator = (const SmRect &rRect)
251 new (this) SmRect(rRect); // placement new
252 return *this;
256 inline Rectangle SmRect::AsRectangle() const
258 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
263 #endif