bump product version to 5.0.4.1
[LibreOffice.git] / starmath / inc / rect.hxx
blob074ae4cb36fc946ae5674660b5f258199e732fc3
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 <new>
25 #include <rtl/ustring.hxx>
26 #include <sal/log.hxx>
27 #include <tools/gen.hxx>
28 #include <vcl/outdev.hxx>
29 #include <vcl/metric.hxx>
31 #include "format.hxx"
34 bool SmGetGlyphBoundRect(const OutputDevice &rDev,
35 const OUString &rText, Rectangle &rRect);
37 bool SmIsMathAlpha(const OUString &rText);
40 inline long SmFromTo(long nFrom, long nTo, double fRelDist)
42 return nFrom + (long) (fRelDist * (nTo - nFrom));
47 // SmRect
48 // ... (to be done)
49 // This Implementation assumes that the x-axis points to the right and the
50 // y-axis to the bottom.
51 // Note: however, italic spaces can be negative!
54 // possible positions and alignments for the 'AlignTo' function
55 enum RectPos
56 // (RP_LEFT : align the current object to the left of the argument, ...)
57 { RP_LEFT, RP_RIGHT,
58 RP_TOP, RP_BOTTOM,
59 RP_ATTRIBUT
61 enum RectHorAlign
62 { RHA_LEFT, RHA_CENTER, RHA_RIGHT
64 enum RectVerAlign
65 { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
66 RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
69 // different methods of copying baselines and mid's in 'ExtendBy' function
70 enum RectCopyMBL
71 { RCP_THIS, // keep baseline of current object even if it has none
72 RCP_ARG, // as above but for the argument
73 RCP_NONE, // result will have no baseline
74 RCP_XOR // if current object has a baseline keep it else copy
75 // the arguments baseline (even if it has none)
79 class SmRect
81 Point aTopLeft;
82 Size aSize;
83 long nBaseline,
84 nAlignT,
85 nAlignM,
86 nAlignB,
87 nGlyphTop,
88 nGlyphBottom,
89 nItalicLeftSpace,
90 nItalicRightSpace,
91 nLoAttrFence,
92 nHiAttrFence;
93 sal_uInt16 nBorderWidth;
94 bool bHasBaseline,
95 bHasAlignInfo;
97 protected:
98 void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
99 const OUString &rText, sal_uInt16 nBorderWidth);
100 void Init(const OutputDevice &rDev, const SmFormat *pFormat,
101 const OUString &rText, sal_uInt16 nBorderWidth);
103 void ClearBaseline() { bHasBaseline = false; };
104 inline void CopyMBL(const SmRect& rRect);
105 void CopyAlignInfo(const SmRect& rRect);
107 SmRect & Union(const SmRect &rRect);
109 public:
110 SmRect();
111 SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
112 const OUString &rText, long nBorderWidth);
113 SmRect(long nWidth, long nHeight);
114 SmRect(const SmRect &rRect);
117 sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
119 void SetItalicSpaces(long nLeftSpace, long nRightSpace);
121 void SetWidth(sal_uLong nWidth) { aSize.Width() = nWidth; }
122 void SetHeight(sal_uLong nHeight) { aSize.Height() = nHeight; }
124 void SetLeft(long nLeft);
125 void SetRight(long nRight);
126 void SetBottom(long nBottom);
127 void SetTop(long nTop);
129 const Point & GetTopLeft() const { return aTopLeft; }
131 long GetTop() const { return GetTopLeft().Y(); }
132 long GetLeft() const { return GetTopLeft().X(); }
133 long GetBottom() const { return GetTop() + GetHeight() - 1; }
134 long GetRight() const { return GetLeft() + GetWidth() - 1; }
135 long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
136 long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
137 long GetWidth() const { return GetSize().Width(); }
138 long GetHeight() const { return GetSize().Height(); }
140 long GetItalicLeftSpace() const { return nItalicLeftSpace; }
141 long GetItalicRightSpace() const { return nItalicRightSpace; }
143 void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; }
144 void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; }
145 long GetHiAttrFence() const { return nHiAttrFence; }
146 long GetLoAttrFence() const { return nLoAttrFence; }
148 long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
149 long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
150 long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
151 long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
153 bool HasBaseline() const { return bHasBaseline; }
154 inline long GetBaseline() const;
155 long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
157 void SetAlignTop(long nVal) { nAlignT = nVal; }
159 long GetAlignT() const { return nAlignT; }
160 long GetAlignM() const { return nAlignM; }
161 long GetAlignB() const { return nAlignB; }
163 void SetAlignT(long nVal) { nAlignT = nVal; }
165 const Point GetCenter() const
166 { return Point(GetCenterX(), GetCenterY()); }
168 const Size & GetSize() const { return aSize; }
170 const Size GetItalicSize() const
171 { return Size(GetItalicWidth(), GetHeight()); }
173 void Move (const Point &rPosition);
174 void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
176 bool IsEmpty() const
178 return GetWidth() == 0 || GetHeight() == 0;
181 bool HasAlignInfo() const { return bHasAlignInfo; }
183 const Point AlignTo(const SmRect &rRect, RectPos ePos,
184 RectHorAlign eHor, RectVerAlign eVer) const;
186 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
187 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
188 long nNewAlignM);
189 SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
190 bool bKeepVerAlignParams);
192 long OrientedDist(const Point &rPoint) const;
193 bool IsInsideRect(const Point &rPoint) const;
194 bool IsInsideItalicRect(const Point &rPoint) const;
196 inline SmRect & operator = (const SmRect &rRect);
198 inline Rectangle AsRectangle() const;
199 SmRect AsGlyphRect() const;
203 inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
204 // set extra spacing to the left and right for (italic)
205 // letters/text
207 nItalicLeftSpace = nLeftSpace;
208 nItalicRightSpace = nRightSpace;
212 inline void SmRect::CopyMBL(const SmRect &rRect)
213 // copy AlignM baseline and value of 'rRect'
215 nBaseline = rRect.nBaseline;
216 bHasBaseline = rRect.bHasBaseline;
217 nAlignM = rRect.nAlignM;
221 inline long SmRect::GetBaseline() const
223 SAL_WARN_IF( !HasBaseline(), "starmath", "Baseline does not exist" );
224 return nBaseline;
228 inline SmRect & SmRect::operator = (const SmRect &rRect)
230 new (this) SmRect(rRect); // placement new
231 return *this;
235 inline Rectangle SmRect::AsRectangle() const
237 return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
240 #endif
242 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */