1*f6a9d5caSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*f6a9d5caSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*f6a9d5caSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*f6a9d5caSAndrew Rist * distributed with this work for additional information
6*f6a9d5caSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*f6a9d5caSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*f6a9d5caSAndrew Rist * "License"); you may not use this file except in compliance
9*f6a9d5caSAndrew Rist * with the License. You may obtain a copy of the License at
10*f6a9d5caSAndrew Rist *
11*f6a9d5caSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*f6a9d5caSAndrew Rist *
13*f6a9d5caSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*f6a9d5caSAndrew Rist * software distributed under the License is distributed on an
15*f6a9d5caSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*f6a9d5caSAndrew Rist * KIND, either express or implied. See the License for the
17*f6a9d5caSAndrew Rist * specific language governing permissions and limitations
18*f6a9d5caSAndrew Rist * under the License.
19*f6a9d5caSAndrew Rist *
20*f6a9d5caSAndrew Rist *************************************************************/
21*f6a9d5caSAndrew Rist
22*f6a9d5caSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir #ifndef RECT_HXX
25cdf0e10cSrcweir #define RECT_HXX
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <new>
28cdf0e10cSrcweir
29cdf0e10cSrcweir
30cdf0e10cSrcweir #include <tools/gen.hxx>
31cdf0e10cSrcweir #include <vcl/outdev.hxx>
32cdf0e10cSrcweir #include <vcl/metric.hxx>
33cdf0e10cSrcweir #include <tools/debug.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir #include "format.hxx"
36cdf0e10cSrcweir
37cdf0e10cSrcweir
38cdf0e10cSrcweir sal_Bool SmGetGlyphBoundRect(const OutputDevice &rDev,
39cdf0e10cSrcweir const XubString &rText, Rectangle &rRect);
40cdf0e10cSrcweir
41cdf0e10cSrcweir sal_Bool SmIsMathAlpha(const XubString &rText);
42cdf0e10cSrcweir
43cdf0e10cSrcweir
SmFromTo(long nFrom,long nTo,double fRelDist)44cdf0e10cSrcweir inline long SmFromTo(long nFrom, long nTo, double fRelDist)
45cdf0e10cSrcweir {
46cdf0e10cSrcweir return nFrom + (long) (fRelDist * (nTo - nFrom));
47cdf0e10cSrcweir }
48cdf0e10cSrcweir
49cdf0e10cSrcweir
50cdf0e10cSrcweir ////////////////////////////////////////
51cdf0e10cSrcweir // SmRect
52cdf0e10cSrcweir // ... (to be done)
53cdf0e10cSrcweir // This Implementation assumes that the x-axis points to the right and the
54cdf0e10cSrcweir // y-axis to the bottom.
55cdf0e10cSrcweir // Note: however, italic spaces can be negative!
56cdf0e10cSrcweir //
57cdf0e10cSrcweir
58cdf0e10cSrcweir // possible flags for the 'Draw' function below (just for debugging)
59cdf0e10cSrcweir #define SM_RECT_CORE 0x0001
60cdf0e10cSrcweir #define SM_RECT_ITALIC 0x0002
61cdf0e10cSrcweir #define SM_RECT_LINES 0x0004
62cdf0e10cSrcweir #define SM_RECT_MID 0x0008
63cdf0e10cSrcweir
64cdf0e10cSrcweir // possible positions and alignments for the 'AlignTo' function
65cdf0e10cSrcweir enum RectPos
66cdf0e10cSrcweir // (RP_LEFT : align the current object to the left of the argument, ...)
67cdf0e10cSrcweir { RP_LEFT, RP_RIGHT,
68cdf0e10cSrcweir RP_TOP, RP_BOTTOM,
69cdf0e10cSrcweir RP_ATTRIBUT
70cdf0e10cSrcweir };
71cdf0e10cSrcweir enum RectHorAlign
72cdf0e10cSrcweir { RHA_LEFT, RHA_CENTER, RHA_RIGHT
73cdf0e10cSrcweir };
74cdf0e10cSrcweir enum RectVerAlign
75cdf0e10cSrcweir { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY,
76cdf0e10cSrcweir RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO
77cdf0e10cSrcweir };
78cdf0e10cSrcweir
79cdf0e10cSrcweir // different methods of copying baselines and mid's in 'ExtendBy' function
80cdf0e10cSrcweir enum RectCopyMBL
81cdf0e10cSrcweir { RCP_THIS, // keep baseline of current object even if it has none
82cdf0e10cSrcweir RCP_ARG, // as above but for the argument
83cdf0e10cSrcweir RCP_NONE, // result will have no baseline
84cdf0e10cSrcweir RCP_XOR // if current object has a baseline keep it else copy
85cdf0e10cSrcweir // the arguments baseline (even if it has none)
86cdf0e10cSrcweir };
87cdf0e10cSrcweir
88cdf0e10cSrcweir
89cdf0e10cSrcweir class SmRect
90cdf0e10cSrcweir {
91cdf0e10cSrcweir Point aTopLeft;
92cdf0e10cSrcweir Size aSize;
93cdf0e10cSrcweir long nBaseline,
94cdf0e10cSrcweir nAlignT,
95cdf0e10cSrcweir nAlignM,
96cdf0e10cSrcweir nAlignB,
97cdf0e10cSrcweir nGlyphTop,
98cdf0e10cSrcweir nGlyphBottom,
99cdf0e10cSrcweir nItalicLeftSpace,
100cdf0e10cSrcweir nItalicRightSpace,
101cdf0e10cSrcweir nLoAttrFence,
102cdf0e10cSrcweir nHiAttrFence;
103cdf0e10cSrcweir sal_uInt16 nBorderWidth;
104cdf0e10cSrcweir sal_Bool bHasBaseline,
105cdf0e10cSrcweir bHasAlignInfo;
106cdf0e10cSrcweir
107cdf0e10cSrcweir protected:
108cdf0e10cSrcweir void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat,
109cdf0e10cSrcweir const XubString &rText, sal_uInt16 nBorderWidth);
110cdf0e10cSrcweir void Init(const OutputDevice &rDev, const SmFormat *pFormat,
111cdf0e10cSrcweir const XubString &rText, sal_uInt16 nBorderWidth);
112cdf0e10cSrcweir
ClearBaseline()113cdf0e10cSrcweir void ClearBaseline() { bHasBaseline = sal_False; };
114cdf0e10cSrcweir inline void CopyMBL(const SmRect& rRect);
115cdf0e10cSrcweir void CopyAlignInfo(const SmRect& rRect);
116cdf0e10cSrcweir
117cdf0e10cSrcweir SmRect & Union(const SmRect &rRect);
118cdf0e10cSrcweir
119cdf0e10cSrcweir public:
120cdf0e10cSrcweir SmRect();
121cdf0e10cSrcweir SmRect(const OutputDevice &rDev, const SmFormat *pFormat,
122cdf0e10cSrcweir const XubString &rText, long nBorderWidth);
123cdf0e10cSrcweir SmRect(long nWidth, long nHeight);
124cdf0e10cSrcweir SmRect(const SmRect &rRect);
125cdf0e10cSrcweir
126cdf0e10cSrcweir
GetBorderWidth() const127cdf0e10cSrcweir sal_uInt16 GetBorderWidth() const { return nBorderWidth; }
128cdf0e10cSrcweir
129cdf0e10cSrcweir void SetItalicSpaces(long nLeftSpace, long nRightSpace);
130cdf0e10cSrcweir
SetWidth(sal_uLong nWidth)131cdf0e10cSrcweir void SetWidth(sal_uLong nWidth) { aSize.Width() = nWidth; }
SetHeight(sal_uLong nHeight)132cdf0e10cSrcweir void SetHeight(sal_uLong nHeight) { aSize.Height() = nHeight; }
133cdf0e10cSrcweir
134cdf0e10cSrcweir void SetLeft(long nLeft);
135cdf0e10cSrcweir void SetRight(long nRight);
136cdf0e10cSrcweir void SetBottom(long nBottom);
137cdf0e10cSrcweir void SetTop(long nTop);
138cdf0e10cSrcweir
GetTopLeft() const139cdf0e10cSrcweir const Point & GetTopLeft() const { return aTopLeft; }
140cdf0e10cSrcweir
GetTop() const141cdf0e10cSrcweir long GetTop() const { return GetTopLeft().Y(); }
GetLeft() const142cdf0e10cSrcweir long GetLeft() const { return GetTopLeft().X(); }
GetBottom() const143cdf0e10cSrcweir long GetBottom() const { return GetTop() + GetHeight() - 1; }
GetRight() const144cdf0e10cSrcweir long GetRight() const { return GetLeft() + GetWidth() - 1; }
GetCenterX() const145cdf0e10cSrcweir long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; }
GetCenterY() const146cdf0e10cSrcweir long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; }
GetWidth() const147cdf0e10cSrcweir long GetWidth() const { return GetSize().Width(); }
GetHeight() const148cdf0e10cSrcweir long GetHeight() const { return GetSize().Height(); }
149cdf0e10cSrcweir
GetItalicLeftSpace() const150cdf0e10cSrcweir long GetItalicLeftSpace() const { return nItalicLeftSpace; }
GetItalicRightSpace() const151cdf0e10cSrcweir long GetItalicRightSpace() const { return nItalicRightSpace; }
152cdf0e10cSrcweir
SetHiAttrFence(long nVal)153cdf0e10cSrcweir void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; }
SetLoAttrFence(long nVal)154cdf0e10cSrcweir void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; }
GetHiAttrFence() const155cdf0e10cSrcweir long GetHiAttrFence() const { return nHiAttrFence; }
GetLoAttrFence() const156cdf0e10cSrcweir long GetLoAttrFence() const { return nLoAttrFence; }
157cdf0e10cSrcweir
GetItalicLeft() const158cdf0e10cSrcweir long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); }
GetItalicCenterX() const159cdf0e10cSrcweir long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; }
GetItalicRight() const160cdf0e10cSrcweir long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); }
GetItalicWidth() const161cdf0e10cSrcweir long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); }
162cdf0e10cSrcweir
HasBaseline() const163cdf0e10cSrcweir sal_Bool HasBaseline() const { return bHasBaseline; }
164cdf0e10cSrcweir inline long GetBaseline() const;
GetBaselineOffset() const165cdf0e10cSrcweir long GetBaselineOffset() const { return GetBaseline() - GetTop(); }
166cdf0e10cSrcweir
SetAlignTop(long nVal)167cdf0e10cSrcweir void SetAlignTop(long nVal) { nAlignT = nVal; }
168cdf0e10cSrcweir
GetAlignT() const169cdf0e10cSrcweir long GetAlignT() const { return nAlignT; }
GetAlignM() const170cdf0e10cSrcweir long GetAlignM() const { return nAlignM; }
GetAlignB() const171cdf0e10cSrcweir long GetAlignB() const { return nAlignB; }
172cdf0e10cSrcweir
SetAlignT(long nVal)173cdf0e10cSrcweir void SetAlignT(long nVal) { nAlignT = nVal; }
174cdf0e10cSrcweir
GetCenter() const175cdf0e10cSrcweir const Point GetCenter() const
176cdf0e10cSrcweir { return Point(GetCenterX(), GetCenterY()); }
177cdf0e10cSrcweir
GetSize() const178cdf0e10cSrcweir const Size & GetSize() const { return aSize; }
179cdf0e10cSrcweir
GetItalicSize() const180cdf0e10cSrcweir const Size GetItalicSize() const
181cdf0e10cSrcweir { return Size(GetItalicWidth(), GetHeight()); }
182cdf0e10cSrcweir
183cdf0e10cSrcweir void Move (const Point &rPosition);
MoveTo(const Point & rPosition)184cdf0e10cSrcweir void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); }
185cdf0e10cSrcweir
IsEmpty() const186cdf0e10cSrcweir sal_Bool IsEmpty() const
187cdf0e10cSrcweir {
188cdf0e10cSrcweir return GetWidth() == 0 || GetHeight() == 0;
189cdf0e10cSrcweir }
190cdf0e10cSrcweir
HasAlignInfo() const191cdf0e10cSrcweir sal_Bool HasAlignInfo() const { return bHasAlignInfo; }
192cdf0e10cSrcweir
193cdf0e10cSrcweir const Point AlignTo(const SmRect &rRect, RectPos ePos,
194cdf0e10cSrcweir RectHorAlign eHor, RectVerAlign eVer) const;
195cdf0e10cSrcweir
196cdf0e10cSrcweir SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode);
197cdf0e10cSrcweir SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
198cdf0e10cSrcweir long nNewAlignM);
199cdf0e10cSrcweir SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode,
200cdf0e10cSrcweir sal_Bool bKeepVerAlignParams);
201cdf0e10cSrcweir
202cdf0e10cSrcweir long OrientedDist(const Point &rPoint) const;
203cdf0e10cSrcweir sal_Bool IsInsideRect(const Point &rPoint) const;
204cdf0e10cSrcweir sal_Bool IsInsideItalicRect(const Point &rPoint) const;
205cdf0e10cSrcweir
206cdf0e10cSrcweir inline SmRect & operator = (const SmRect &rRect);
207cdf0e10cSrcweir
208cdf0e10cSrcweir inline Rectangle AsRectangle() const;
209cdf0e10cSrcweir SmRect AsGlyphRect() const;
210cdf0e10cSrcweir
211cdf0e10cSrcweir #ifdef SM_RECT_DEBUG
212cdf0e10cSrcweir void Draw(OutputDevice &rDev, const Point &rPosition, int nFlags) const;
213cdf0e10cSrcweir #endif
214cdf0e10cSrcweir };
215cdf0e10cSrcweir
216cdf0e10cSrcweir
SetItalicSpaces(long nLeftSpace,long nRightSpace)217cdf0e10cSrcweir inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace)
218cdf0e10cSrcweir // set extra spacing to the left and right for (italic)
219cdf0e10cSrcweir // letters/text
220cdf0e10cSrcweir {
221cdf0e10cSrcweir nItalicLeftSpace = nLeftSpace;
222cdf0e10cSrcweir nItalicRightSpace = nRightSpace;
223cdf0e10cSrcweir }
224cdf0e10cSrcweir
225cdf0e10cSrcweir
CopyMBL(const SmRect & rRect)226cdf0e10cSrcweir inline void SmRect::CopyMBL(const SmRect &rRect)
227cdf0e10cSrcweir // copy AlignM baseline and value of 'rRect'
228cdf0e10cSrcweir {
229cdf0e10cSrcweir nBaseline = rRect.nBaseline;
230cdf0e10cSrcweir bHasBaseline = rRect.bHasBaseline;
231cdf0e10cSrcweir nAlignM = rRect.nAlignM;
232cdf0e10cSrcweir }
233cdf0e10cSrcweir
234cdf0e10cSrcweir
GetBaseline() const235cdf0e10cSrcweir inline long SmRect::GetBaseline() const
236cdf0e10cSrcweir {
237cdf0e10cSrcweir DBG_ASSERT(HasBaseline(), "Sm: Baseline nicht vorhanden");
238cdf0e10cSrcweir return nBaseline;
239cdf0e10cSrcweir }
240cdf0e10cSrcweir
241cdf0e10cSrcweir
operator =(const SmRect & rRect)242cdf0e10cSrcweir inline SmRect & SmRect::operator = (const SmRect &rRect)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir new (this) SmRect(rRect); // placement new
245cdf0e10cSrcweir return *this;
246cdf0e10cSrcweir }
247cdf0e10cSrcweir
248cdf0e10cSrcweir
AsRectangle() const249cdf0e10cSrcweir inline Rectangle SmRect::AsRectangle() const
250cdf0e10cSrcweir {
251cdf0e10cSrcweir return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize());
252cdf0e10cSrcweir }
253cdf0e10cSrcweir
254cdf0e10cSrcweir
255cdf0e10cSrcweir
256cdf0e10cSrcweir #endif
257