Version 6.4.0.0.beta1, tag libreoffice-6.4.0.0.beta1
[LibreOffice.git] / starmath / inc / rect.hxx
blobce390b19724a23a0f1ebf5bc6b73a98d42668ef7
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>
28 class SmFormat;
31 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
33 return nFrom + static_cast<long>(fRelDist * (nTo - nFrom));
37 // SmRect
38 // ... (to be done)
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
45 enum class RectPos
47 Left, // align the current object to the left of the argument
48 Right,
49 Top,
50 Bottom,
51 Attribute
54 enum class RectHorAlign
56 Left,
57 Center,
58 Right
61 enum class RectVerAlign
63 Top,
64 Mid,
65 Bottom,
66 Baseline,
67 CenterY,
68 AttributeHi,
69 AttributeMid,
70 AttributeLo
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)
84 class SmRect
86 Point aTopLeft;
87 Size aSize;
88 long nBaseline,
89 nAlignT,
90 nAlignM,
91 nAlignB,
92 nGlyphTop,
93 nGlyphBottom,
94 nItalicLeftSpace,
95 nItalicRightSpace,
96 nLoAttrFence,
97 nHiAttrFence;
98 sal_uInt16 nBorderWidth;
99 bool bHasBaseline,
100 bHasAlignInfo;
102 inline void CopyMBL(const SmRect& rRect);
103 void CopyAlignInfo(const SmRect& rRect);
105 void Union(const SmRect &rRect);
107 public:
108 SmRect();
109 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
110 const OUString &rText, sal_uInt16 nBorderWidth);
111 SmRect(long nWidth, long nHeight);
114 sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
116 void SetItalicSpaces(long nLeftSpace, long nRightSpace);
118 void SetWidth(sal_uLong nWidth) { aSize.setWidth(nWidth); }
120 void SetLeft(long nLeft);
121 void SetRight(long nRight);
122 void SetBottom(long nBottom);
123 void SetTop(long nTop);
125 const Point & GetTopLeft() const { return aTopLeft; }
127 long GetTop() const { return GetTopLeft().Y(); }
128 long GetLeft() const { return GetTopLeft().X(); }
129 long GetBottom() const { return GetTop() + GetHeight() - 1; }
130 long GetRight() const { return GetLeft() + GetWidth() - 1; }
131 long GetCenterY() const { return (GetTop() + GetBottom()) / 2; }
132 long GetWidth() const { return GetSize().Width(); }
133 long GetHeight() const { return GetSize().Height(); }
135 long GetItalicLeftSpace() const { return nItalicLeftSpace; }
136 long GetItalicRightSpace() const { return nItalicRightSpace; }
138 long GetHiAttrFence() const { return nHiAttrFence; }
139 long GetLoAttrFence() const { return nLoAttrFence; }
141 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
142 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
143 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
144 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
146 bool HasBaseline() const { return bHasBaseline; }
147 inline long GetBaseline() const;
148 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
150 long GetAlignT() const { return nAlignT; }
151 long GetAlignM() const { return nAlignM; }
152 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()); }
162 bool IsEmpty() const
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 long nNewAlignM);
175 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
176 bool bKeepVerAlignParams);
178 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(long nLeftSpace, long nRightSpace)
188 // set extra spacing to the left and right for (italic)
189 // letters/text
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 long SmRect::GetBaseline() const
207 SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
208 return nBaseline;
212 inline tools::Rectangle SmRect::AsRectangle() const
214 return tools::Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
217 #endif
219 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */