1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
25 #include <rtl/ustring.hxx>
26 #include <tools/gen.hxx>
27 #include <vcl/outdev.hxx>
28 #include <vcl/metric.hxx>
33 bool SmGetGlyphBoundRect(const OutputDevice
&rDev
,
34 const OUString
&rText
, Rectangle
&rRect
);
36 bool SmIsMathAlpha(const OUString
&rText
);
39 inline long SmFromTo(long nFrom
, long nTo
, double fRelDist
)
41 return nFrom
+ (long) (fRelDist
* (nTo
- nFrom
));
45 ////////////////////////////////////////
48 // This Implementation assumes that the x-axis points to the right and the
49 // y-axis to the bottom.
50 // Note: however, italic spaces can be negative!
53 // possible flags for the 'Draw' function below (just for debugging)
54 #define SM_RECT_CORE 0x0001
55 #define SM_RECT_ITALIC 0x0002
56 #define SM_RECT_LINES 0x0004
57 #define SM_RECT_MID 0x0008
59 // possible positions and alignments for the 'AlignTo' function
61 // (RP_LEFT : align the current object to the left of the argument, ...)
67 { RHA_LEFT
, RHA_CENTER
, RHA_RIGHT
70 { RVA_TOP
, RVA_MID
, RVA_BOTTOM
, RVA_BASELINE
, RVA_CENTERY
,
71 RVA_ATTRIBUT_HI
, RVA_ATTRIBUT_MID
, RVA_ATTRIBUT_LO
74 // different methods of copying baselines and mid's in 'ExtendBy' function
76 { RCP_THIS
, // keep baseline of current object even if it has none
77 RCP_ARG
, // as above but for the argument
78 RCP_NONE
, // result will have no baseline
79 RCP_XOR
// if current object has a baseline keep it else copy
80 // the arguments baseline (even if it has none)
98 sal_uInt16 nBorderWidth
;
103 void BuildRect (const OutputDevice
&rDev
, const SmFormat
*pFormat
,
104 const OUString
&rText
, sal_uInt16 nBorderWidth
);
105 void Init(const OutputDevice
&rDev
, const SmFormat
*pFormat
,
106 const OUString
&rText
, sal_uInt16 nBorderWidth
);
108 void ClearBaseline() { bHasBaseline
= false; };
109 inline void CopyMBL(const SmRect
& rRect
);
110 void CopyAlignInfo(const SmRect
& rRect
);
112 SmRect
& Union(const SmRect
&rRect
);
116 SmRect(const OutputDevice
&rDev
, const SmFormat
*pFormat
,
117 const OUString
&rText
, long nBorderWidth
);
118 SmRect(long nWidth
, long nHeight
);
119 SmRect(const SmRect
&rRect
);
122 sal_uInt16
GetBorderWidth() const { return nBorderWidth
; }
124 void SetItalicSpaces(long nLeftSpace
, long nRightSpace
);
126 void SetWidth(sal_uLong nWidth
) { aSize
.Width() = nWidth
; }
127 void SetHeight(sal_uLong nHeight
) { aSize
.Height() = nHeight
; }
129 void SetLeft(long nLeft
);
130 void SetRight(long nRight
);
131 void SetBottom(long nBottom
);
132 void SetTop(long nTop
);
134 const Point
& GetTopLeft() const { return aTopLeft
; }
136 long GetTop() const { return GetTopLeft().Y(); }
137 long GetLeft() const { return GetTopLeft().X(); }
138 long GetBottom() const { return GetTop() + GetHeight() - 1; }
139 long GetRight() const { return GetLeft() + GetWidth() - 1; }
140 long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
141 long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
142 long GetWidth() const { return GetSize().Width(); }
143 long GetHeight() const { return GetSize().Height(); }
145 long GetItalicLeftSpace() const { return nItalicLeftSpace
; }
146 long GetItalicRightSpace() const { return nItalicRightSpace
; }
148 void SetHiAttrFence(long nVal
) { nHiAttrFence
= nVal
; }
149 void SetLoAttrFence(long nVal
) { nLoAttrFence
= nVal
; }
150 long GetHiAttrFence() const { return nHiAttrFence
; }
151 long GetLoAttrFence() const { return nLoAttrFence
; }
153 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
154 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
155 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
156 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
158 bool HasBaseline() const { return bHasBaseline
; }
159 inline long GetBaseline() const;
160 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
162 void SetAlignTop(long nVal
) { nAlignT
= nVal
; }
164 long GetAlignT() const { return nAlignT
; }
165 long GetAlignM() const { return nAlignM
; }
166 long GetAlignB() const { return nAlignB
; }
168 void SetAlignT(long nVal
) { nAlignT
= nVal
; }
170 const Point
GetCenter() const
171 { return Point(GetCenterX(), GetCenterY()); }
173 const Size
& GetSize() const { return aSize
; }
175 const Size
GetItalicSize() const
176 { return Size(GetItalicWidth(), GetHeight()); }
178 void Move (const Point
&rPosition
);
179 void MoveTo(const Point
&rPosition
) { Move(rPosition
- GetTopLeft()); }
183 return GetWidth() == 0 || GetHeight() == 0;
186 bool HasAlignInfo() const { return bHasAlignInfo
; }
188 const Point
AlignTo(const SmRect
&rRect
, RectPos ePos
,
189 RectHorAlign eHor
, RectVerAlign eVer
) const;
191 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
);
192 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
,
194 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
,
195 bool bKeepVerAlignParams
);
197 long OrientedDist(const Point
&rPoint
) const;
198 bool IsInsideRect(const Point
&rPoint
) const;
199 bool IsInsideItalicRect(const Point
&rPoint
) const;
201 inline SmRect
& operator = (const SmRect
&rRect
);
203 inline Rectangle
AsRectangle() const;
204 SmRect
AsGlyphRect() const;
208 inline void SmRect::SetItalicSpaces(long nLeftSpace
, long nRightSpace
)
209 // set extra spacing to the left and right for (italic)
212 nItalicLeftSpace
= nLeftSpace
;
213 nItalicRightSpace
= nRightSpace
;
217 inline void SmRect::CopyMBL(const SmRect
&rRect
)
218 // copy AlignM baseline and value of 'rRect'
220 nBaseline
= rRect
.nBaseline
;
221 bHasBaseline
= rRect
.bHasBaseline
;
222 nAlignM
= rRect
.nAlignM
;
226 inline long SmRect::GetBaseline() const
228 OSL_ENSURE(HasBaseline(), "Sm: Baseline nicht vorhanden");
233 inline SmRect
& SmRect::operator = (const SmRect
&rRect
)
235 new (this) SmRect(rRect
); // placement new
240 inline Rectangle
SmRect::AsRectangle() const
242 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
247 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */