1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #ifndef RECT_HXX 29*cdf0e10cSrcweir #define RECT_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include <new> 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir 34*cdf0e10cSrcweir #include <tools/gen.hxx> 35*cdf0e10cSrcweir #include <vcl/outdev.hxx> 36*cdf0e10cSrcweir #include <vcl/metric.hxx> 37*cdf0e10cSrcweir #include <tools/debug.hxx> 38*cdf0e10cSrcweir 39*cdf0e10cSrcweir #include "format.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir 42*cdf0e10cSrcweir sal_Bool SmGetGlyphBoundRect(const OutputDevice &rDev, 43*cdf0e10cSrcweir const XubString &rText, Rectangle &rRect); 44*cdf0e10cSrcweir 45*cdf0e10cSrcweir sal_Bool SmIsMathAlpha(const XubString &rText); 46*cdf0e10cSrcweir 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir inline long SmFromTo(long nFrom, long nTo, double fRelDist) 49*cdf0e10cSrcweir { 50*cdf0e10cSrcweir return nFrom + (long) (fRelDist * (nTo - nFrom)); 51*cdf0e10cSrcweir } 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir 54*cdf0e10cSrcweir //////////////////////////////////////// 55*cdf0e10cSrcweir // SmRect 56*cdf0e10cSrcweir // ... (to be done) 57*cdf0e10cSrcweir // This Implementation assumes that the x-axis points to the right and the 58*cdf0e10cSrcweir // y-axis to the bottom. 59*cdf0e10cSrcweir // Note: however, italic spaces can be negative! 60*cdf0e10cSrcweir // 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir // possible flags for the 'Draw' function below (just for debugging) 63*cdf0e10cSrcweir #define SM_RECT_CORE 0x0001 64*cdf0e10cSrcweir #define SM_RECT_ITALIC 0x0002 65*cdf0e10cSrcweir #define SM_RECT_LINES 0x0004 66*cdf0e10cSrcweir #define SM_RECT_MID 0x0008 67*cdf0e10cSrcweir 68*cdf0e10cSrcweir // possible positions and alignments for the 'AlignTo' function 69*cdf0e10cSrcweir enum RectPos 70*cdf0e10cSrcweir // (RP_LEFT : align the current object to the left of the argument, ...) 71*cdf0e10cSrcweir { RP_LEFT, RP_RIGHT, 72*cdf0e10cSrcweir RP_TOP, RP_BOTTOM, 73*cdf0e10cSrcweir RP_ATTRIBUT 74*cdf0e10cSrcweir }; 75*cdf0e10cSrcweir enum RectHorAlign 76*cdf0e10cSrcweir { RHA_LEFT, RHA_CENTER, RHA_RIGHT 77*cdf0e10cSrcweir }; 78*cdf0e10cSrcweir enum RectVerAlign 79*cdf0e10cSrcweir { RVA_TOP, RVA_MID, RVA_BOTTOM, RVA_BASELINE, RVA_CENTERY, 80*cdf0e10cSrcweir RVA_ATTRIBUT_HI, RVA_ATTRIBUT_MID, RVA_ATTRIBUT_LO 81*cdf0e10cSrcweir }; 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir // different methods of copying baselines and mid's in 'ExtendBy' function 84*cdf0e10cSrcweir enum RectCopyMBL 85*cdf0e10cSrcweir { RCP_THIS, // keep baseline of current object even if it has none 86*cdf0e10cSrcweir RCP_ARG, // as above but for the argument 87*cdf0e10cSrcweir RCP_NONE, // result will have no baseline 88*cdf0e10cSrcweir RCP_XOR // if current object has a baseline keep it else copy 89*cdf0e10cSrcweir // the arguments baseline (even if it has none) 90*cdf0e10cSrcweir }; 91*cdf0e10cSrcweir 92*cdf0e10cSrcweir 93*cdf0e10cSrcweir class SmRect 94*cdf0e10cSrcweir { 95*cdf0e10cSrcweir Point aTopLeft; 96*cdf0e10cSrcweir Size aSize; 97*cdf0e10cSrcweir long nBaseline, 98*cdf0e10cSrcweir nAlignT, 99*cdf0e10cSrcweir nAlignM, 100*cdf0e10cSrcweir nAlignB, 101*cdf0e10cSrcweir nGlyphTop, 102*cdf0e10cSrcweir nGlyphBottom, 103*cdf0e10cSrcweir nItalicLeftSpace, 104*cdf0e10cSrcweir nItalicRightSpace, 105*cdf0e10cSrcweir nLoAttrFence, 106*cdf0e10cSrcweir nHiAttrFence; 107*cdf0e10cSrcweir sal_uInt16 nBorderWidth; 108*cdf0e10cSrcweir sal_Bool bHasBaseline, 109*cdf0e10cSrcweir bHasAlignInfo; 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir protected: 112*cdf0e10cSrcweir void BuildRect (const OutputDevice &rDev, const SmFormat *pFormat, 113*cdf0e10cSrcweir const XubString &rText, sal_uInt16 nBorderWidth); 114*cdf0e10cSrcweir void Init(const OutputDevice &rDev, const SmFormat *pFormat, 115*cdf0e10cSrcweir const XubString &rText, sal_uInt16 nBorderWidth); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir void ClearBaseline() { bHasBaseline = sal_False; }; 118*cdf0e10cSrcweir inline void CopyMBL(const SmRect& rRect); 119*cdf0e10cSrcweir void CopyAlignInfo(const SmRect& rRect); 120*cdf0e10cSrcweir 121*cdf0e10cSrcweir SmRect & Union(const SmRect &rRect); 122*cdf0e10cSrcweir 123*cdf0e10cSrcweir public: 124*cdf0e10cSrcweir SmRect(); 125*cdf0e10cSrcweir SmRect(const OutputDevice &rDev, const SmFormat *pFormat, 126*cdf0e10cSrcweir const XubString &rText, long nBorderWidth); 127*cdf0e10cSrcweir SmRect(long nWidth, long nHeight); 128*cdf0e10cSrcweir SmRect(const SmRect &rRect); 129*cdf0e10cSrcweir 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir sal_uInt16 GetBorderWidth() const { return nBorderWidth; } 132*cdf0e10cSrcweir 133*cdf0e10cSrcweir void SetItalicSpaces(long nLeftSpace, long nRightSpace); 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir void SetWidth(sal_uLong nWidth) { aSize.Width() = nWidth; } 136*cdf0e10cSrcweir void SetHeight(sal_uLong nHeight) { aSize.Height() = nHeight; } 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir void SetLeft(long nLeft); 139*cdf0e10cSrcweir void SetRight(long nRight); 140*cdf0e10cSrcweir void SetBottom(long nBottom); 141*cdf0e10cSrcweir void SetTop(long nTop); 142*cdf0e10cSrcweir 143*cdf0e10cSrcweir const Point & GetTopLeft() const { return aTopLeft; } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir long GetTop() const { return GetTopLeft().Y(); } 146*cdf0e10cSrcweir long GetLeft() const { return GetTopLeft().X(); } 147*cdf0e10cSrcweir long GetBottom() const { return GetTop() + GetHeight() - 1; } 148*cdf0e10cSrcweir long GetRight() const { return GetLeft() + GetWidth() - 1; } 149*cdf0e10cSrcweir long GetCenterX() const { return (GetLeft() + GetRight()) / 2L; } 150*cdf0e10cSrcweir long GetCenterY() const { return (GetTop() + GetBottom()) / 2L; } 151*cdf0e10cSrcweir long GetWidth() const { return GetSize().Width(); } 152*cdf0e10cSrcweir long GetHeight() const { return GetSize().Height(); } 153*cdf0e10cSrcweir 154*cdf0e10cSrcweir long GetItalicLeftSpace() const { return nItalicLeftSpace; } 155*cdf0e10cSrcweir long GetItalicRightSpace() const { return nItalicRightSpace; } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir void SetHiAttrFence(long nVal) { nHiAttrFence = nVal; } 158*cdf0e10cSrcweir void SetLoAttrFence(long nVal) { nLoAttrFence = nVal; } 159*cdf0e10cSrcweir long GetHiAttrFence() const { return nHiAttrFence; } 160*cdf0e10cSrcweir long GetLoAttrFence() const { return nLoAttrFence; } 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir long GetItalicLeft() const { return GetLeft() - GetItalicLeftSpace(); } 163*cdf0e10cSrcweir long GetItalicCenterX() const { return (GetItalicLeft() + GetItalicRight()) / 2; } 164*cdf0e10cSrcweir long GetItalicRight() const { return GetRight() + GetItalicRightSpace(); } 165*cdf0e10cSrcweir long GetItalicWidth() const { return GetWidth() + GetItalicLeftSpace() + GetItalicRightSpace(); } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir sal_Bool HasBaseline() const { return bHasBaseline; } 168*cdf0e10cSrcweir inline long GetBaseline() const; 169*cdf0e10cSrcweir long GetBaselineOffset() const { return GetBaseline() - GetTop(); } 170*cdf0e10cSrcweir 171*cdf0e10cSrcweir void SetAlignTop(long nVal) { nAlignT = nVal; } 172*cdf0e10cSrcweir 173*cdf0e10cSrcweir long GetAlignT() const { return nAlignT; } 174*cdf0e10cSrcweir long GetAlignM() const { return nAlignM; } 175*cdf0e10cSrcweir long GetAlignB() const { return nAlignB; } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir void SetAlignT(long nVal) { nAlignT = nVal; } 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir const Point GetCenter() const 180*cdf0e10cSrcweir { return Point(GetCenterX(), GetCenterY()); } 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir const Size & GetSize() const { return aSize; } 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir const Size GetItalicSize() const 185*cdf0e10cSrcweir { return Size(GetItalicWidth(), GetHeight()); } 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir void Move (const Point &rPosition); 188*cdf0e10cSrcweir void MoveTo(const Point &rPosition) { Move(rPosition - GetTopLeft()); } 189*cdf0e10cSrcweir 190*cdf0e10cSrcweir sal_Bool IsEmpty() const 191*cdf0e10cSrcweir { 192*cdf0e10cSrcweir return GetWidth() == 0 || GetHeight() == 0; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir sal_Bool HasAlignInfo() const { return bHasAlignInfo; } 196*cdf0e10cSrcweir 197*cdf0e10cSrcweir const Point AlignTo(const SmRect &rRect, RectPos ePos, 198*cdf0e10cSrcweir RectHorAlign eHor, RectVerAlign eVer) const; 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode); 201*cdf0e10cSrcweir SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode, 202*cdf0e10cSrcweir long nNewAlignM); 203*cdf0e10cSrcweir SmRect & ExtendBy(const SmRect &rRect, RectCopyMBL eCopyMode, 204*cdf0e10cSrcweir sal_Bool bKeepVerAlignParams); 205*cdf0e10cSrcweir 206*cdf0e10cSrcweir long OrientedDist(const Point &rPoint) const; 207*cdf0e10cSrcweir sal_Bool IsInsideRect(const Point &rPoint) const; 208*cdf0e10cSrcweir sal_Bool IsInsideItalicRect(const Point &rPoint) const; 209*cdf0e10cSrcweir 210*cdf0e10cSrcweir inline SmRect & operator = (const SmRect &rRect); 211*cdf0e10cSrcweir 212*cdf0e10cSrcweir inline Rectangle AsRectangle() const; 213*cdf0e10cSrcweir SmRect AsGlyphRect() const; 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir #ifdef SM_RECT_DEBUG 216*cdf0e10cSrcweir void Draw(OutputDevice &rDev, const Point &rPosition, int nFlags) const; 217*cdf0e10cSrcweir #endif 218*cdf0e10cSrcweir }; 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir 221*cdf0e10cSrcweir inline void SmRect::SetItalicSpaces(long nLeftSpace, long nRightSpace) 222*cdf0e10cSrcweir // set extra spacing to the left and right for (italic) 223*cdf0e10cSrcweir // letters/text 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir nItalicLeftSpace = nLeftSpace; 226*cdf0e10cSrcweir nItalicRightSpace = nRightSpace; 227*cdf0e10cSrcweir } 228*cdf0e10cSrcweir 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir inline void SmRect::CopyMBL(const SmRect &rRect) 231*cdf0e10cSrcweir // copy AlignM baseline and value of 'rRect' 232*cdf0e10cSrcweir { 233*cdf0e10cSrcweir nBaseline = rRect.nBaseline; 234*cdf0e10cSrcweir bHasBaseline = rRect.bHasBaseline; 235*cdf0e10cSrcweir nAlignM = rRect.nAlignM; 236*cdf0e10cSrcweir } 237*cdf0e10cSrcweir 238*cdf0e10cSrcweir 239*cdf0e10cSrcweir inline long SmRect::GetBaseline() const 240*cdf0e10cSrcweir { 241*cdf0e10cSrcweir DBG_ASSERT(HasBaseline(), "Sm: Baseline nicht vorhanden"); 242*cdf0e10cSrcweir return nBaseline; 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir inline SmRect & SmRect::operator = (const SmRect &rRect) 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir new (this) SmRect(rRect); // placement new 249*cdf0e10cSrcweir return *this; 250*cdf0e10cSrcweir } 251*cdf0e10cSrcweir 252*cdf0e10cSrcweir 253*cdf0e10cSrcweir inline Rectangle SmRect::AsRectangle() const 254*cdf0e10cSrcweir { 255*cdf0e10cSrcweir return Rectangle(Point(GetItalicLeft(), GetTop()), GetItalicSize()); 256*cdf0e10cSrcweir } 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir 260*cdf0e10cSrcweir #endif 261