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