fix mismatching gb_Trace_StartRange and gb_Trace_EndRage
[LibreOffice.git] / starmath / inc / rect.hxx
blob0b28581a00f9aec96b957ee2f128d2d3a53ab04d
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 #pragma once
22 #include <rtl/ustring.hxx>
23 #include <sal/log.hxx>
24 #include <tools/gen.hxx>
25 #include <vcl/outdev.hxx>
27 class SmFormat;
30 inline tools::Long SmFromTo(tools::Long nFrom, tools::Long nTo, double fRelDist)
32 return nFrom + static_cast<tools::Long>(fRelDist * (nTo - nFrom));
36 // SmRect
37 // ... (to be done)
38 // This Implementation assumes that the x-axis points to the right and the
39 // y-axis to the bottom.
40 // Note: however, italic spaces can be negative!
43 // possible positions and alignments for the 'AlignTo' function
44 enum class RectPos
46 Left, // align the current object to the left of the argument
47 Right,
48 Top,
49 Bottom,
50 Attribute
53 enum class RectHorAlign
55 Left,
56 Center,
57 Right
60 enum class RectVerAlign
62 Top,
63 Mid,
64 Bottom,
65 Baseline,
66 CenterY,
67 AttributeHi,
68 AttributeMid,
69 AttributeLo
72 // different methods of copying baselines and mid's in 'ExtendBy' function
73 enum class RectCopyMBL
75 This, // keep baseline of current object even if it has none
76 Arg, // as above but for the argument
77 None, // result will have no baseline
78 Xor // if current object has a baseline keep it else copy
79 // the arguments baseline (even if it has none)
83 class SmRect
85 Point aTopLeft;
86 Size aSize;
87 tools::Long nBaseline,
88 nAlignT,
89 nAlignM,
90 nAlignB,
91 nGlyphTop,
92 nGlyphBottom,
93 nItalicLeftSpace,
94 nItalicRightSpace,
95 nLoAttrFence,
96 nHiAttrFence;
97 sal_uInt16 nBorderWidth;
98 bool bHasBaseline,
99 bHasAlignInfo;
101 inline void CopyMBL(const SmRect& rRect);
102 void CopyAlignInfo(const SmRect& rRect);
104 void Union(const SmRect &rRect);
106 public:
107 SmRect();
108 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
109 const OUString &rText, sal_uInt16 nBorderWidth);
110 SmRect(tools::Long nWidth, tools::Long nHeight);
113 sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
115 void SetItalicSpaces(tools::Long nLeftSpace, tools::Long nRightSpace);
117 void SetWidth(sal_uLong nWidth) { aSize.setWidth(nWidth); }
119 void SetLeft(tools::Long nLeft);
120 void SetRight(tools::Long nRight);
121 void SetBottom(tools::Long nBottom);
122 void SetTop(tools::Long nTop);
124 const Point & GetTopLeft() const { return aTopLeft; }
126 tools::Long GetTop() const { return GetTopLeft().Y(); }
127 tools::Long GetLeft() const { return GetTopLeft().X(); }
128 tools::Long GetBottom() const { return GetTop() + GetHeight() - 1; }
129 tools::Long GetRight() const { return GetLeft() + GetWidth() - 1; }
130 tools::Long GetCenterY() const { return (GetTop() + GetBottom()) / 2; }
131 tools::Long GetWidth() const { return GetSize().Width(); }
132 tools::Long GetHeight() const { return GetSize().Height(); }
134 tools::Long GetItalicLeftSpace() const { return nItalicLeftSpace; }
135 tools::Long GetItalicRightSpace() const { return nItalicRightSpace; }
137 tools::Long GetHiAttrFence() const { return nHiAttrFence; }
138 tools::Long GetLoAttrFence() const { return nLoAttrFence; }
140 tools::Long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
141 tools::Long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
142 tools::Long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
143 tools::Long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
145 bool HasBaseline() const { return bHasBaseline; }
146 inline tools::Long GetBaseline() const;
147 tools::Long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
149 tools::Long GetAlignT() const { return nAlignT; }
150 tools::Long GetAlignM() const { return nAlignM; }
151 tools::Long GetAlignB() const { return nAlignB; }
153 const Size & GetSize() const { return aSize; }
155 Size GetItalicSize() const
156 { return Size(GetItalicWidth(), GetHeight()); }
158 void Move (const Point &rPosition);
159 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
161 bool IsEmpty() const
163 return GetWidth() == 0 || GetHeight() == 0;
166 bool HasAlignInfo() const { return bHasAlignInfo; }
168 Point AlignTo(const SmRect &rRect, RectPos ePos,
169 RectHorAlign eHor, RectVerAlign eVer) const;
171 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
172 void ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
173 tools::Long nNewAlignM);
174 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
175 bool bKeepVerAlignParams);
177 tools::Long OrientedDist(const Point &rPoint) const;
178 bool IsInsideRect(const Point &rPoint) const;
179 bool IsInsideItalicRect(const Point &rPoint) const;
181 inline tools::Rectangle AsRectangle() const;
182 SmRect AsGlyphRect() const;
186 inline void SmRect::SetItalicSpaces(tools::Long nLeftSpace, tools::Long nRightSpace)
187 // set extra spacing to the left and right for (italic)
188 // letters/text
190 nItalicLeftSpace = nLeftSpace;
191 nItalicRightSpace = nRightSpace;
195 inline void SmRect::CopyMBL(const SmRect &rRect)
196 // copy AlignM baseline and value of 'rRect'
198 nBaseline = rRect.nBaseline;
199 bHasBaseline = rRect.bHasBaseline;
200 nAlignM = rRect.nAlignM;
204 inline tools::Long SmRect::GetBaseline() const
206 SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
207 return nBaseline;
211 inline tools::Rectangle SmRect::AsRectangle() const
213 return tools::Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
216 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */