LibreOffice Module starmath (master) 1
rect.hxx
Go to the documentation of this file.
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
27class SmFormat;
28
29
30inline tools::Long SmFromTo(tools::Long nFrom, tools::Long nTo, double fRelDist)
31{
32 return nFrom + static_cast<tools::Long>(fRelDist * (nTo - nFrom));
33}
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
44enum class RectPos
45{
46 Left, // align the current object to the left of the argument
47 Right,
48 Top,
49 Bottom,
51};
52
53enum class RectHorAlign
54{
55 Left,
56 Center,
57 Right
58};
59
60enum class RectVerAlign
61{
62 Top,
63 Mid,
64 Bottom,
66 CenterY,
70};
71
72// different methods of copying baselines and mid's in 'ExtendBy' function
73enum 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
83class SmRect
84{
97 sal_uInt16 nBorderWidth;
100
101 inline void CopyMBL(const SmRect& rRect);
102 void CopyAlignInfo(const SmRect& rRect);
103
104 void Union(const SmRect &rRect);
105
106public:
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 sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
114
115 void SetItalicSpaces(tools::Long nLeftSpace, tools::Long nRightSpace);
116
117 void SetWidth(sal_uLong 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 const Point & GetTopLeft() const { return aTopLeft; }
125
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(); }
133
136
139
144
145 bool HasBaseline() const { return bHasBaseline; }
146 inline tools::Long GetBaseline() const;
148
149 tools::Long GetAlignT() const { return nAlignT; }
150 tools::Long GetAlignM() const { return nAlignM; }
151 tools::Long GetAlignB() const { return nAlignB; }
152
153 const Size & GetSize() const { return aSize; }
154
156 { return Size(GetItalicWidth(), GetHeight()); }
157
158 void Move (const Point &rPosition);
159 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
160
161 bool IsEmpty() const
162 {
163 return GetWidth() == 0 || GetHeight() == 0;
164 }
165
166 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
186inline void SmRect::SetItalicSpaces(tools::Long nLeftSpace, tools::Long nRightSpace)
187 // set extra spacing to the left and right for (italic)
188 // letters/text
189{
190 nItalicLeftSpace = nLeftSpace;
191 nItalicRightSpace = nRightSpace;
192}
193
194
195inline void SmRect::CopyMBL(const SmRect &rRect)
196 // copy AlignM baseline and value of 'rRect'
197{
198 nBaseline = rRect.nBaseline;
200 nAlignM = rRect.nAlignM;
201}
202
203
205{
206 SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
207 return nBaseline;
208}
209
210
212{
214}
215
216/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
constexpr tools::Long Y() const
constexpr tools::Long X() const
constexpr tools::Long Height() const
void setWidth(tools::Long nWidth)
constexpr tools::Long Width() const
Definition: rect.hxx:84
bool IsEmpty() const
Definition: rect.hxx:161
tools::Long GetItalicLeft() const
Definition: rect.hxx:140
void SetTop(tools::Long nTop)
Definition: rect.cxx:308
tools::Long GetItalicLeftSpace() const
Definition: rect.hxx:134
const Point & GetTopLeft() const
Definition: rect.hxx:124
tools::Long GetItalicWidth() const
Definition: rect.hxx:143
bool IsInsideRect(const Point &rPoint) const
Definition: rect.cxx:596
Point aTopLeft
Definition: rect.hxx:85
tools::Long GetBaselineOffset() const
Definition: rect.hxx:147
tools::Long nBaseline
Definition: rect.hxx:87
void SetBottom(tools::Long nBottom)
Definition: rect.cxx:301
tools::Long nItalicLeftSpace
Definition: rect.hxx:93
tools::Long nGlyphTop
Definition: rect.hxx:91
tools::Long nLoAttrFence
Definition: rect.hxx:95
Size GetItalicSize() const
Definition: rect.hxx:155
tools::Long nAlignT
Definition: rect.hxx:88
SmRect()
Definition: rect.cxx:144
tools::Long GetCenterY() const
Definition: rect.hxx:130
tools::Long GetItalicRight() const
Definition: rect.hxx:142
tools::Long nAlignM
Definition: rect.hxx:89
SmRect AsGlyphRect() const
Definition: rect.cxx:613
tools::Long GetAlignT() const
Definition: rect.hxx:149
tools::Long GetHeight() const
Definition: rect.hxx:132
tools::Long nGlyphBottom
Definition: rect.hxx:92
tools::Long OrientedDist(const Point &rPoint) const
Definition: rect.cxx:552
tools::Long GetHiAttrFence() const
Definition: rect.hxx:137
tools::Long GetItalicCenterX() const
Definition: rect.hxx:141
bool HasBaseline() const
Definition: rect.hxx:145
void SetLeft(tools::Long nLeft)
Definition: rect.cxx:285
void Move(const Point &rPosition)
Definition: rect.cxx:317
void CopyAlignInfo(const SmRect &rRect)
Definition: rect.cxx:165
tools::Long nAlignB
Definition: rect.hxx:90
sal_uInt16 nBorderWidth
Definition: rect.hxx:97
tools::Long GetTop() const
Definition: rect.hxx:126
bool IsInsideItalicRect(const Point &rPoint) const
Definition: rect.cxx:605
tools::Long GetBottom() const
Definition: rect.hxx:128
Size aSize
Definition: rect.hxx:86
sal_uInt16 GetBorderWidth() const
Definition: rect.hxx:113
SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode)
Definition: rect.cxx:461
tools::Long nItalicRightSpace
Definition: rect.hxx:94
tools::Long GetBaseline() const
Definition: rect.hxx:204
void Union(const SmRect &rRect)
Italic correction is NOT taken into account here!
Definition: rect.cxx:420
Point AlignTo(const SmRect &rRect, RectPos ePos, RectHorAlign eHor, RectVerAlign eVer) const
Definition: rect.cxx:334
tools::Long GetLoAttrFence() const
Definition: rect.hxx:138
void SetRight(tools::Long nRight)
Definition: rect.cxx:294
tools::Long GetAlignB() const
Definition: rect.hxx:151
tools::Long GetWidth() const
Definition: rect.hxx:131
bool bHasBaseline
Definition: rect.hxx:98
tools::Long GetAlignM() const
Definition: rect.hxx:150
void SetItalicSpaces(tools::Long nLeftSpace, tools::Long nRightSpace)
Definition: rect.hxx:186
void MoveTo(const Point &rPosition)
Definition: rect.hxx:159
bool bHasAlignInfo
Definition: rect.hxx:99
bool HasAlignInfo() const
Definition: rect.hxx:166
tools::Long GetLeft() const
Definition: rect.hxx:127
void SetWidth(sal_uLong nWidth)
Definition: rect.hxx:117
tools::Long nHiAttrFence
Definition: rect.hxx:96
const Size & GetSize() const
Definition: rect.hxx:153
void CopyMBL(const SmRect &rRect)
Definition: rect.hxx:195
tools::Long GetRight() const
Definition: rect.hxx:129
tools::Rectangle AsRectangle() const
Definition: rect.hxx:211
tools::Long GetItalicRightSpace() const
Definition: rect.hxx:135
#define SAL_WARN_IF(condition, area, stream)
None
long Long
RectCopyMBL
Definition: rect.hxx:74
RectHorAlign
Definition: rect.hxx:54
RectVerAlign
Definition: rect.hxx:61
RectPos
Definition: rect.hxx:45
tools::Long SmFromTo(tools::Long nFrom, tools::Long nTo, double fRelDist)
Definition: rect.hxx:30
sal_uIntPtr sal_uLong
Left
Center
Right