Version 6.1.4.1, tag libreoffice-6.1.4.1
[LibreOffice.git] / starmath / inc / rect.hxx
blobf48cc60554bda9027abe99b27220645523295442
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
27 #include <vcl/metric.hxx>
29 #include "format.hxx"
32 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
34 return nFrom + static_cast<long>(fRelDist * (nTo - nFrom));
38 // SmRect
39 // ... (to be done)
40 // This Implementation assumes that the x-axis points to the right and the
41 // y-axis to the bottom.
42 // Note: however, italic spaces can be negative!
45 // possible positions and alignments for the 'AlignTo' function
46 enum class RectPos
48 Left, // align the current object to the left of the argument
49 Right,
50 Top,
51 Bottom,
52 Attribute
55 enum class RectHorAlign
57 Left,
58 Center,
59 Right
62 enum class RectVerAlign
64 Top,
65 Mid,
66 Bottom,
67 Baseline,
68 CenterY,
69 AttributeHi,
70 AttributeMid,
71 AttributeLo
74 // different methods of copying baselines and mid's in 'ExtendBy' function
75 enum class RectCopyMBL
77 This, // keep baseline of current object even if it has none
78 Arg, // as above but for the argument
79 None, // result will have no baseline
80 Xor // if current object has a baseline keep it else copy
81 // the arguments baseline (even if it has none)
85 class SmRect
87 Point aTopLeft;
88 Size aSize;
89 long nBaseline,
90 nAlignT,
91 nAlignM,
92 nAlignB,
93 nGlyphTop,
94 nGlyphBottom,
95 nItalicLeftSpace,
96 nItalicRightSpace,
97 nLoAttrFence,
98 nHiAttrFence;
99 sal_uInt16 nBorderWidth;
100 bool bHasBaseline,
101 bHasAlignInfo;
103 inline void CopyMBL(const SmRect& rRect);
104 void CopyAlignInfo(const SmRect& rRect);
106 void Union(const SmRect &rRect);
108 public:
109 SmRect();
110 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
111 const OUString &rText, sal_uInt16 nBorderWidth);
112 SmRect(long nWidth, long nHeight);
115 sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
117 void SetItalicSpaces(long nLeftSpace, long nRightSpace);
119 void SetWidth(sal_uLong nWidth) { aSize.setWidth(nWidth); }
121 void SetLeft(long nLeft);
122 void SetRight(long nRight);
123 void SetBottom(long nBottom);
124 void SetTop(long nTop);
126 const Point & GetTopLeft() const { return aTopLeft; }
128 long GetTop() const { return GetTopLeft().Y(); }
129 long GetLeft() const { return GetTopLeft().X(); }
130 long GetBottom() const { return GetTop() + GetHeight() - 1; }
131 long GetRight() const { return GetLeft() + GetWidth() - 1; }
132 long GetCenterY() const { return (GetTop() + GetBottom()) / 2; }
133 long GetWidth() const { return GetSize().Width(); }
134 long GetHeight() const { return GetSize().Height(); }
136 long GetItalicLeftSpace() const { return nItalicLeftSpace; }
137 long GetItalicRightSpace() const { return nItalicRightSpace; }
139 long GetHiAttrFence() const { return nHiAttrFence; }
140 long GetLoAttrFence() const { return nLoAttrFence; }
142 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
143 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
144 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
145 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
147 bool HasBaseline() const { return bHasBaseline; }
148 inline long GetBaseline() const;
149 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
151 long GetAlignT() const { return nAlignT; }
152 long GetAlignM() const { return nAlignM; }
153 long GetAlignB() const { return nAlignB; }
155 const Size & GetSize() const { return aSize; }
157 const Size GetItalicSize() const
158 { return Size(GetItalicWidth(), GetHeight()); }
160 void Move (const Point &rPosition);
161 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
163 bool IsEmpty() const
165 return GetWidth() == 0 || GetHeight() == 0;
168 bool HasAlignInfo() const { return bHasAlignInfo; }
170 const Point AlignTo(const SmRect &rRect, RectPos ePos,
171 RectHorAlign eHor, RectVerAlign eVer) const;
173 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
174 void ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
175 long nNewAlignM);
176 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
177 bool bKeepVerAlignParams);
179 long OrientedDist(const Point &rPoint) const;
180 bool IsInsideRect(const Point &rPoint) const;
181 bool IsInsideItalicRect(const Point &rPoint) const;
183 inline tools::Rectangle AsRectangle() const;
184 SmRect AsGlyphRect() const;
188 inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
189 // set extra spacing to the left and right for (italic)
190 // letters/text
192 nItalicLeftSpace = nLeftSpace;
193 nItalicRightSpace = nRightSpace;
197 inline void SmRect::CopyMBL(const SmRect &rRect)
198 // copy AlignM baseline and value of 'rRect'
200 nBaseline = rRect.nBaseline;
201 bHasBaseline = rRect.bHasBaseline;
202 nAlignM = rRect.nAlignM;
206 inline long SmRect::GetBaseline() const
208 SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
209 return nBaseline;
213 inline tools::Rectangle SmRect::AsRectangle() const
215 return tools::Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
218 #endif
220 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */