/src/libreoffice/starmath/inc/rect.hxx
Line | Count | Source |
1 | | /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ |
2 | | /* |
3 | | * This file is part of the LibreOffice project. |
4 | | * |
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/. |
8 | | * |
9 | | * This file incorporates work covered by the following license notice: |
10 | | * |
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 . |
18 | | */ |
19 | | |
20 | | #pragma once |
21 | | |
22 | | #include <rtl/ustring.hxx> |
23 | | #include <sal/log.hxx> |
24 | | #include <tools/gen.hxx> |
25 | | #include <vcl/outdev.hxx> |
26 | | |
27 | | class SmFormat; |
28 | | |
29 | | |
30 | | inline tools::Long SmFromTo(tools::Long nFrom, tools::Long nTo, double fRelDist) |
31 | 4.09M | { |
32 | 4.09M | return nFrom + static_cast<tools::Long>(fRelDist * (nTo - nFrom)); |
33 | 4.09M | } |
34 | | |
35 | | |
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! |
41 | | |
42 | | |
43 | | // possible positions and alignments for the 'AlignTo' function |
44 | | enum class RectPos |
45 | | { |
46 | | Left, // align the current object to the left of the argument |
47 | | Right, |
48 | | Top, |
49 | | Bottom, |
50 | | Attribute |
51 | | }; |
52 | | |
53 | | enum class RectHorAlign |
54 | | { |
55 | | Left, |
56 | | Center, |
57 | | Right |
58 | | }; |
59 | | |
60 | | enum class RectVerAlign |
61 | | { |
62 | | Top, |
63 | | Mid, |
64 | | Bottom, |
65 | | Baseline, |
66 | | CenterY, |
67 | | AttributeHi, |
68 | | AttributeMid, |
69 | | AttributeLo |
70 | | }; |
71 | | |
72 | | // different methods of copying baselines and mid's in 'ExtendBy' function |
73 | | enum class RectCopyMBL |
74 | | { |
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) |
80 | | }; |
81 | | |
82 | | |
83 | | class SmRect |
84 | | { |
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; |
100 | | |
101 | | inline void CopyMBL(const SmRect& rRect); |
102 | | void CopyAlignInfo(const SmRect& rRect); |
103 | | |
104 | | void Union(const SmRect &rRect); |
105 | | |
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); |
111 | | |
112 | | |
113 | 0 | sal_uInt16 GetBorderWidth() const { return nBorderWidth; } |
114 | | |
115 | | void SetItalicSpaces(tools::Long nLeftSpace, tools::Long nRightSpace); |
116 | | |
117 | 18.4k | void SetWidth(tools::Long nWidth) { aSize.setWidth(nWidth); } |
118 | | |
119 | | void SetLeft(tools::Long nLeft); |
120 | | void SetRight(tools::Long nRight); |
121 | | void SetBottom(tools::Long nBottom); |
122 | | void SetTop(tools::Long nTop); |
123 | | |
124 | 130M | const Point & GetTopLeft() const { return aTopLeft; } |
125 | | |
126 | 54.4M | tools::Long GetTop() const { return GetTopLeft().Y(); } |
127 | 68.4M | tools::Long GetLeft() const { return GetTopLeft().X(); } |
128 | 28.6M | tools::Long GetBottom() const { return GetTop() + GetHeight() - 1; } |
129 | 36.1M | tools::Long GetRight() const { return GetLeft() + GetWidth() - 1; } |
130 | 29.0k | tools::Long GetCenterY() const { return (GetTop() + GetBottom()) / 2; } |
131 | 45.3M | tools::Long GetWidth() const { return GetSize().Width(); } |
132 | 36.7M | tools::Long GetHeight() const { return GetSize().Height(); } |
133 | | |
134 | 12.2M | tools::Long GetItalicLeftSpace() const { return nItalicLeftSpace; } |
135 | 12.2M | tools::Long GetItalicRightSpace() const { return nItalicRightSpace; } |
136 | | |
137 | 8.05M | tools::Long GetHiAttrFence() const { return nHiAttrFence; } |
138 | 8.05M | tools::Long GetLoAttrFence() const { return nLoAttrFence; } |
139 | | |
140 | 8.19M | tools::Long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); } |
141 | 64.5k | tools::Long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; } |
142 | 12.1M | tools::Long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); } |
143 | 46.4k | tools::Long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); } |
144 | | |
145 | 11.6M | bool HasBaseline() const { return bHasBaseline; } |
146 | | inline tools::Long GetBaseline() const; |
147 | 0 | tools::Long GetBaselineOffset() const { return GetBaseline() - GetTop(); } |
148 | | |
149 | 8.30M | tools::Long GetAlignT() const { return nAlignT; } |
150 | 151k | tools::Long GetAlignM() const { return nAlignM; } |
151 | 12.2M | tools::Long GetAlignB() const { return nAlignB; } |
152 | | |
153 | 82.1M | const Size & GetSize() const { return aSize; } |
154 | | |
155 | | Size GetItalicSize() const |
156 | 0 | { return Size(GetItalicWidth(), GetHeight()); } |
157 | | |
158 | | void Move (const Point &rPosition); |
159 | 22.4k | void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); } |
160 | | |
161 | | bool IsEmpty() const |
162 | 8.04M | { |
163 | 8.04M | return GetWidth() == 0 || GetHeight() == 0; |
164 | 8.04M | } |
165 | | |
166 | 8.15M | bool HasAlignInfo() const { return bHasAlignInfo; } |
167 | | |
168 | | Point AlignTo(const SmRect &rRect, RectPos ePos, |
169 | | RectHorAlign eHor, RectVerAlign eVer) const; |
170 | | |
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); |
176 | | |
177 | | tools::Long OrientedDist(const Point &rPoint) const; |
178 | | bool IsInsideRect(const Point &rPoint) const; |
179 | | bool IsInsideItalicRect(const Point &rPoint) const; |
180 | | |
181 | | inline tools::Rectangle AsRectangle() const; |
182 | | SmRect AsGlyphRect() const; |
183 | | }; |
184 | | |
185 | | |
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 |
189 | 4.05M | { |
190 | 4.05M | nItalicLeftSpace = nLeftSpace; |
191 | 4.05M | nItalicRightSpace = nRightSpace; |
192 | 4.05M | } |
193 | | |
194 | | |
195 | | inline void SmRect::CopyMBL(const SmRect &rRect) |
196 | | // copy AlignM baseline and value of 'rRect' |
197 | 7.11k | { |
198 | 7.11k | nBaseline = rRect.nBaseline; |
199 | 7.11k | bHasBaseline = rRect.bHasBaseline; |
200 | 7.11k | nAlignM = rRect.nAlignM; |
201 | 7.11k | } |
202 | | |
203 | | |
204 | | inline tools::Long SmRect::GetBaseline() const |
205 | 7.79M | { |
206 | 7.79M | SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" ); |
207 | 7.79M | return nBaseline; |
208 | 7.79M | } |
209 | | |
210 | | |
211 | | inline tools::Rectangle SmRect::AsRectangle() const |
212 | 0 | { |
213 | 0 | return tools::Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize()); |
214 | 0 | } |
215 | | |
216 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |