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 .
20 #ifndef INCLUDED_STARMATH_INC_RECT_HXX
21 #define INCLUDED_STARMATH_INC_RECT_HXX
23 #include <rtl/ustring.hxx>
24 #include <sal/log.hxx>
25 #include <tools/gen.hxx>
26 #include <vcl/outdev.hxx>
31 inline tools::Long
SmFromTo(tools::Long nFrom
, tools::Long nTo
, double fRelDist
)
33 return nFrom
+ static_cast<tools::Long
>(fRelDist
* (nTo
- nFrom
));
39 // This Implementation assumes that the x-axis points to the right and the
40 // y-axis to the bottom.
41 // Note: however, italic spaces can be negative!
44 // possible positions and alignments for the 'AlignTo' function
47 Left
, // align the current object to the left of the argument
54 enum class RectHorAlign
61 enum class RectVerAlign
73 // different methods of copying baselines and mid's in 'ExtendBy' function
74 enum class RectCopyMBL
76 This
, // keep baseline of current object even if it has none
77 Arg
, // as above but for the argument
78 None
, // result will have no baseline
79 Xor
// if current object has a baseline keep it else copy
80 // the arguments baseline (even if it has none)
88 tools::Long nBaseline
,
98 sal_uInt16 nBorderWidth
;
102 inline void CopyMBL(const SmRect
& rRect
);
103 void CopyAlignInfo(const SmRect
& rRect
);
105 void Union(const SmRect
&rRect
);
109 SmRect(const OutputDevice
&rDev
, const SmFormat
*pFormat
,
110 const OUString
&rText
, sal_uInt16 nBorderWidth
);
111 SmRect(tools::Long nWidth
, tools::Long nHeight
);
114 sal_uInt16
GetBorderWidth() const { return nBorderWidth
; }
116 void SetItalicSpaces(tools::Long nLeftSpace
, tools::Long nRightSpace
);
118 void SetWidth(sal_uLong nWidth
) { aSize
.setWidth(nWidth
); }
120 void SetLeft(tools::Long nLeft
);
121 void SetRight(tools::Long nRight
);
122 void SetBottom(tools::Long nBottom
);
123 void SetTop(tools::Long nTop
);
125 const Point
& GetTopLeft() const { return aTopLeft
; }
127 tools::Long
GetTop() const { return GetTopLeft().Y(); }
128 tools::Long
GetLeft() const { return GetTopLeft().X(); }
129 tools::Long
GetBottom() const { return GetTop() + GetHeight() - 1; }
130 tools::Long
GetRight() const { return GetLeft() + GetWidth() - 1; }
131 tools::Long
GetCenterY() const { return (GetTop() + GetBottom()) / 2; }
132 tools::Long
GetWidth() const { return GetSize().Width(); }
133 tools::Long
GetHeight() const { return GetSize().Height(); }
135 tools::Long
GetItalicLeftSpace() const { return nItalicLeftSpace
; }
136 tools::Long
GetItalicRightSpace() const { return nItalicRightSpace
; }
138 tools::Long
GetHiAttrFence() const { return nHiAttrFence
; }
139 tools::Long
GetLoAttrFence() const { return nLoAttrFence
; }
141 tools::Long
GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
142 tools::Long
GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
143 tools::Long
GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
144 tools::Long
GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
146 bool HasBaseline() const { return bHasBaseline
; }
147 inline tools::Long
GetBaseline() const;
148 tools::Long
GetBaselineOffset() const { return GetBaseline() - GetTop(); }
150 tools::Long
GetAlignT() const { return nAlignT
; }
151 tools::Long
GetAlignM() const { return nAlignM
; }
152 tools::Long
GetAlignB() const { return nAlignB
; }
154 const Size
& GetSize() const { return aSize
; }
156 Size
GetItalicSize() const
157 { return Size(GetItalicWidth(), GetHeight()); }
159 void Move (const Point
&rPosition
);
160 void MoveTo(const Point
&rPosition
) { Move(rPosition
- GetTopLeft()); }
164 return GetWidth() == 0 || GetHeight() == 0;
167 bool HasAlignInfo() const { return bHasAlignInfo
; }
169 Point
AlignTo(const SmRect
&rRect
, RectPos ePos
,
170 RectHorAlign eHor
, RectVerAlign eVer
) const;
172 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
);
173 void ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
,
174 tools::Long nNewAlignM
);
175 SmRect
& ExtendBy(const SmRect
&rRect
, RectCopyMBL eCopyMode
,
176 bool bKeepVerAlignParams
);
178 tools::Long
OrientedDist(const Point
&rPoint
) const;
179 bool IsInsideRect(const Point
&rPoint
) const;
180 bool IsInsideItalicRect(const Point
&rPoint
) const;
182 inline tools::Rectangle
AsRectangle() const;
183 SmRect
AsGlyphRect() const;
187 inline void SmRect::SetItalicSpaces(tools::Long nLeftSpace
, tools::Long nRightSpace
)
188 // set extra spacing to the left and right for (italic)
191 nItalicLeftSpace
= nLeftSpace
;
192 nItalicRightSpace
= nRightSpace
;
196 inline void SmRect::CopyMBL(const SmRect
&rRect
)
197 // copy AlignM baseline and value of 'rRect'
199 nBaseline
= rRect
.nBaseline
;
200 bHasBaseline
= rRect
.bHasBaseline
;
201 nAlignM
= rRect
.nAlignM
;
205 inline tools::Long
SmRect::GetBaseline() const
207 SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
212 inline tools::Rectangle
SmRect::AsRectangle() const
214 return tools::Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */