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 #include <tools/gen.hxx>
38 #include <vcl/outdev.hxx>
39 #include <vcl/metric.hxx>
40 #include <tools/debug.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 ////////////////////////////////////////
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
73 // (RP_LEFT : align the current object to the left of the argument, ...)
79 { RHA_LEFT
, RHA_CENTER
, RHA_RIGHT
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
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)
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
);
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()); }
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
,
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;
219 void Draw(OutputDevice
&rDev
, const Point
&rPosition
, int nFlags
) const;
224 inline void SmRect::SetItalicSpaces(long nLeftSpace
, long nRightSpace
)
225 // set extra spacing to the left and right for (italic)
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");
249 inline SmRect
& SmRect::operator = (const SmRect
&rRect
)
251 new (this) SmRect(rRect
); // placement new
256 inline Rectangle
SmRect::AsRectangle() const
258 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());