Line data Source code
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 : #ifndef RECT_HXX
21 : #define RECT_HXX
22 :
23 : #include <new>
24 :
25 : #include <rtl/ustring.hxx>
26 : #include <tools/gen.hxx>
27 : #include <vcl/outdev.hxx>
28 : #include <vcl/metric.hxx>
29 :
30 : #include "format.hxx"
31 :
32 :
33 : bool SmGetGlyphBoundRect(const OutputDevice &rDev,
34 : const OUString &rText, Rectangle &rRect);
35 :
36 : bool SmIsMathAlpha(const OUString &rText);
37 :
38 :
39 6158 : inline long SmFromTo(long nFrom, long nTo, double fRelDist)
40 : {
41 6158 : return nFrom + (long) (fRelDist * (nTo - nFrom));
42 : }
43 :
44 :
45 : ////////////////////////////////////////
46 : // SmRect
47 : // ... (to be done)
48 : // This Implementation assumes that the x-axis points to the right and the
49 : // y-axis to the bottom.
50 : // Note: however, italic spaces can be negative!
51 : //
52 :
53 : // possible flags for the 'Draw' function below (just for debugging)
54 : #define SM_RECT_CORE 0x0001
55 : #define SM_RECT_ITALIC 0x0002
56 : #define SM_RECT_LINES 0x0004
57 : #define SM_RECT_MID 0x0008
58 :
59 : // possible positions and alignments for the 'AlignTo' function
60 : enum RectPos
61 : // (RP_LEFT : align the current object to the left of the argument, ...)
62 : { RP_LEFT, RP_RIGHT,
63 : RP_TOP, RP_BOTTOM,
64 : RP_ATTRIBUT
65 : };
66 : enum RectHorAlign
67 : { RHA_LEFT, RHA_CENTER, RHA_RIGHT
68 : };
69 : enum RectVerAlign
70 : { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
71 : RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
72 : };
73 :
74 : // different methods of copying baselines and mid's in 'ExtendBy' function
75 : enum RectCopyMBL
76 : { RCP_THIS, // keep baseline of current object even if it has none
77 : RCP_ARG, // as above but for the argument
78 : RCP_NONE, // result will have no baseline
79 : RCP_XOR // if current object has a baseline keep it else copy
80 : // the arguments baseline (even if it has none)
81 : };
82 :
83 :
84 : class SmRect
85 : {
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;
101 :
102 : protected:
103 : void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
104 : const OUString &rText, sal_uInt16 nBorderWidth);
105 : void Init(const OutputDevice &rDev, const SmFormat *pFormat,
106 : const OUString &rText, sal_uInt16 nBorderWidth);
107 :
108 566 : void ClearBaseline() { bHasBaseline = false; };
109 : inline void CopyMBL(const SmRect& rRect);
110 : void CopyAlignInfo(const SmRect& rRect);
111 :
112 : SmRect & Union(const SmRect &rRect);
113 :
114 : public:
115 : SmRect();
116 : SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
117 : const OUString &rText, long nBorderWidth);
118 : SmRect(long nWidth, long nHeight);
119 : SmRect(const SmRect &rRect);
120 :
121 :
122 432 : sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
123 :
124 : void SetItalicSpaces(long nLeftSpace, long nRightSpace);
125 :
126 63 : void SetWidth(sal_uLong nWidth) { aSize.Width() = nWidth; }
127 : void SetHeight(sal_uLong nHeight) { aSize.Height() = nHeight; }
128 :
129 : void SetLeft(long nLeft);
130 : void SetRight(long nRight);
131 : void SetBottom(long nBottom);
132 : void SetTop(long nTop);
133 :
134 303139 : const Point & GetTopLeft() const { return aTopLeft; }
135 :
136 109240 : long GetTop() const { return GetTopLeft().Y(); }
137 95956 : long GetLeft() const { return GetTopLeft().X(); }
138 43718 : long GetBottom() const { return GetTop() + GetHeight() - 1; }
139 48763 : long GetRight() const { return GetLeft() + GetWidth() - 1; }
140 : long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
141 1326 : long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
142 89124 : long GetWidth() const { return GetSize().Width(); }
143 57846 : long GetHeight() const { return GetSize().Height(); }
144 :
145 21264 : long GetItalicLeftSpace() const { return nItalicLeftSpace; }
146 20044 : long GetItalicRightSpace() const { return nItalicRightSpace; }
147 :
148 : void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; }
149 : void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; }
150 10614 : long GetHiAttrFence() const { return nHiAttrFence; }
151 10480 : long GetLoAttrFence() const { return nLoAttrFence; }
152 :
153 15130 : long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
154 2738 : long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
155 16798 : long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
156 2675 : long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
157 :
158 8656 : bool HasBaseline() const { return bHasBaseline; }
159 : inline long GetBaseline() const;
160 24973 : long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
161 :
162 : void SetAlignTop(long nVal) { nAlignT = nVal; }
163 :
164 12123 : long GetAlignT() const { return nAlignT; }
165 1744 : long GetAlignM() const { return nAlignM; }
166 17588 : long GetAlignB() const { return nAlignB; }
167 :
168 : void SetAlignT(long nVal) { nAlignT = nVal; }
169 :
170 : const Point GetCenter() const
171 : { return Point(GetCenterX(), GetCenterY()); }
172 :
173 147689 : const Size & GetSize() const { return aSize; }
174 :
175 1172 : const Size GetItalicSize() const
176 1172 : { return Size(GetItalicWidth(), GetHeight()); }
177 :
178 : void Move (const Point &rPosition);
179 282 : void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
180 :
181 10558 : bool IsEmpty() const
182 : {
183 10558 : return GetWidth() == 0 || GetHeight() == 0;
184 : }
185 :
186 11274 : bool HasAlignInfo() const { return bHasAlignInfo; }
187 :
188 : const Point AlignTo(const SmRect &rRect, RectPos ePos,
189 : RectHorAlign eHor, RectVerAlign eVer) const;
190 :
191 : SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
192 : SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
193 : long nNewAlignM);
194 : SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
195 : bool bKeepVerAlignParams);
196 :
197 : long OrientedDist(const Point &rPoint) const;
198 : bool IsInsideRect(const Point &rPoint) const;
199 : bool IsInsideItalicRect(const Point &rPoint) const;
200 :
201 : inline SmRect & operator = (const SmRect &rRect);
202 :
203 : inline Rectangle AsRectangle() const;
204 : SmRect AsGlyphRect() const;
205 : };
206 :
207 :
208 5363 : inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
209 : // set extra spacing to the left and right for (italic)
210 : // letters/text
211 : {
212 5363 : nItalicLeftSpace = nLeftSpace;
213 5363 : nItalicRightSpace = nRightSpace;
214 5363 : }
215 :
216 :
217 637 : inline void SmRect::CopyMBL(const SmRect &rRect)
218 : // copy AlignM baseline and value of 'rRect'
219 : {
220 637 : nBaseline = rRect.nBaseline;
221 637 : bHasBaseline = rRect.bHasBaseline;
222 637 : nAlignM = rRect.nAlignM;
223 637 : }
224 :
225 :
226 30584 : inline long SmRect::GetBaseline() const
227 : {
228 : OSL_ENSURE(HasBaseline(), "Sm: Baseline nicht vorhanden");
229 30584 : return nBaseline;
230 : }
231 :
232 :
233 9229 : inline SmRect & SmRect::operator = (const SmRect &rRect)
234 : {
235 9229 : new (this) SmRect(rRect); // placement new
236 9229 : return *this;
237 : }
238 :
239 :
240 1165 : inline Rectangle SmRect::AsRectangle() const
241 : {
242 1165 : return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
243 : }
244 :
245 : #endif
246 :
247 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|