1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: rect.hxx,v $
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 ************************************************************************/
37 #ifndef _GEN_HXX //autogen
38 #include <tools/gen.hxx>
41 #ifndef _SV_OUTDEV_HXX //autogen
42 #include <vcl/outdev.hxx>
45 #ifndef _SV_METRIC_HXX //autogen
46 #include <vcl/metric.hxx>
49 #ifndef _TOOLS_DEBUG_HXX //autogen
50 #include <tools/debug.hxx>
57 BOOL
SmGetGlyphBoundRect(const OutputDevice
&rDev
,
58 const XubString
&rText
, Rectangle
&rRect
);
60 BOOL
SmIsMathAlpha(const XubString
&rText
);
63 inline long SmFromTo(long nFrom
, long nTo
, double fRelDist
)
65 return nFrom
+ (long) (fRelDist
* (nTo
- nFrom
));
69 ////////////////////////////////////////
72 // This Implementation assumes that the x-axis points to the right and the
73 // y-axis to the bottom.
74 // Note: however, italic spaces can be negative!
77 // possible flags for the 'Draw' function below (just for debugging)
78 #define SM_RECT_CORE 0x0001
79 #define SM_RECT_ITALIC 0x0002
80 #define SM_RECT_LINES 0x0004
81 #define SM_RECT_MID 0x0008
83 // possible positions and alignments for the 'AlignTo' function
85 // (RP_LEFT : align the current object to the left of the argument, ...)
91 { RHA_LEFT
, RHA_CENTER
, RHA_RIGHT
94 { RVA_TOP
, RVA_MID
, RVA_BOTTOM
, RVA_BASELINE
, RVA_CENTERY
,
95 RVA_ATTRIBUT_HI
, RVA_ATTRIBUT_MID
, RVA_ATTRIBUT_LO
98 // different methods of copying baselines and mid's in 'ExtendBy' function
100 { RCP_THIS
, // keep baseline of current object even if it has none
101 RCP_ARG
, // as above but for the argument
102 RCP_NONE
, // result will have no baseline
103 RCP_XOR
// if current object has a baseline keep it else copy
104 // the arguments baseline (even if it has none)
127 void BuildRect (const OutputDevice
&rDev
, const SmFormat
*pFormat
,
128 const XubString
&rText
, USHORT nBorderWidth
);
129 void Init(const OutputDevice
&rDev
, const SmFormat
*pFormat
,
130 const XubString
&rText
, USHORT nBorderWidth
);
132 void ClearBaseline() { bHasBaseline
= FALSE
; };
133 inline void CopyMBL(const SmRect
& rRect
);
134 void CopyAlignInfo(const SmRect
& rRect
);
136 SmRect
& Union(const SmRect
&rRect
);
140 SmRect(const OutputDevice
&rDev
, const SmFormat
*pFormat
,
141 const XubString
&rText
, long nBorderWidth
);
142 SmRect(long nWidth
, long nHeight
);
143 SmRect(const SmRect
&rRect
);
146 USHORT
GetBorderWidth() const { return nBorderWidth
; }
148 void SetItalicSpaces(long nLeftSpace
, long nRightSpace
);
150 void SetWidth(ULONG nWidth
) { aSize
.Width() = nWidth
; }
151 void SetHeight(ULONG nHeight
) { aSize
.Height() = nHeight
; }
153 void SetLeft(long nLeft
);
154 void SetRight(long nRight
);
155 void SetBottom(long nBottom
);
156 void SetTop(long nTop
);
158 const Point
& GetTopLeft() const { return aTopLeft
; }
160 long GetTop() const { return GetTopLeft().Y(); }
161 long GetLeft() const { return GetTopLeft().X(); }
162 long GetBottom() const { return GetTop() + GetHeight() - 1; }
163 long GetRight() const { return GetLeft() + GetWidth() - 1; }
164 long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
165 long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
166 long GetWidth() const { return GetSize().Width(); }
167 long GetHeight() const { return GetSize().Height(); }
169 long GetItalicLeftSpace() const { return nItalicLeftSpace
; }
170 long GetItalicRightSpace() const { return nItalicRightSpace
; }
172 void SetHiAttrFence(long nVal
) { nHiAttrFence
= nVal
; }
173 void SetLoAttrFence(long nVal
) { nLoAttrFence
= nVal
; }
174 long GetHiAttrFence() const { return nHiAttrFence
; }
175 long GetLoAttrFence() const { return nLoAttrFence
; }
177 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
178 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
179 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
180 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
182 BOOL
HasBaseline() const { return bHasBaseline
; }
183 inline long GetBaseline() const;
184 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
186 void SetAlignTop(long nVal
) { nAlignT
= nVal
; }
188 long GetAlignT() const { return nAlignT
; }
189 long GetAlignM() const { return nAlignM
; }
190 long GetAlignB() const { return nAlignB
; }
192 void SetAlignT(long nVal
) { nAlignT
= nVal
; }
194 const Point
GetCenter() const
195 { return Point(GetCenterX(), GetCenterY()); }
197 const Size
& GetSize() const { return aSize
; }
199 const Size
GetItalicSize() const
200 { return Size(GetItalicWidth(), GetHeight()); }
202 void Move (const Point
&rPosition
);
203 void MoveTo(const Point
&rPosition
) { Move(rPosition
- GetTopLeft()); }
207 return GetWidth() == 0 || GetHeight() == 0;
210 BOOL
HasAlignInfo() const { return bHasAlignInfo
; }
212 const Point
AlignTo(const SmRect
&rRect
, RectPos ePos
,
213 RectHorAlign eHor
, RectVerAlign eVer
) const;
215 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
);
216 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
,
218 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
,
219 BOOL bKeepVerAlignParams
);
220 // SmRect & ExtendBy(const Point &rPoint);
222 // long OrientedDist(const Point &rPoint) const;
223 // BOOL IsInsideRect(const Point &rPoint) const;
224 // BOOL IsInsideItalicRect(const Point &rPoint) const;
226 inline SmRect
& operator = (const SmRect
&rRect
);
228 inline Rectangle
AsRectangle() const;
229 SmRect
AsGlyphRect() const;
234 inline void SmRect::SetItalicSpaces(long nLeftSpace
, long nRightSpace
)
235 // set extra spacing to the left and right for (italic)
238 nItalicLeftSpace
= nLeftSpace
;
239 nItalicRightSpace
= nRightSpace
;
243 inline void SmRect::CopyMBL(const SmRect
&rRect
)
244 // copy AlignM baseline and value of 'rRect'
246 nBaseline
= rRect
.nBaseline
;
247 bHasBaseline
= rRect
.bHasBaseline
;
248 nAlignM
= rRect
.nAlignM
;
252 inline long SmRect::GetBaseline() const
254 DBG_ASSERT(HasBaseline(), "Sm: Baseline nicht vorhanden");
259 inline SmRect
& SmRect::operator = (const SmRect
&rRect
)
261 new (this) SmRect(rRect
); // placement new
266 inline Rectangle
SmRect::AsRectangle() const
268 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
273 } //namespace binfilter