1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _DRAWFONT_HXX 28 #define _DRAWFONT_HXX 29 30 #include <tools/solar.h> 31 #include <tools/string.hxx> 32 #include <errhdl.hxx> 33 34 class SwTxtFrm; 35 class OutputDevice; 36 class ViewShell; 37 class SwScriptInfo; 38 class Point; 39 class SwWrongList; 40 class Size; 41 class SwFont; 42 class Font; 43 class SwUnderlineFont; 44 45 /************************************************************************* 46 * class SwDrawTextInfo 47 * 48 * encapsulates information for drawing text 49 *************************************************************************/ 50 51 class SwDrawTextInfo 52 { 53 const SwTxtFrm* pFrm; 54 OutputDevice* pOut; 55 ViewShell* pSh; 56 const SwScriptInfo* pScriptInfo; 57 const Point* pPos; 58 const XubString* pText; 59 const SwWrongList* pWrong; 60 const SwWrongList* pGrammarCheck; 61 const SwWrongList* pSmartTags; // SMARTTAGS 62 const Size* pSize; 63 SwFont *pFnt; 64 SwUnderlineFont* pUnderFnt; 65 xub_StrLen* pHyphPos; 66 long nLeft; 67 long nRight; 68 long nKanaDiff; 69 xub_StrLen nIdx; 70 xub_StrLen nLen; 71 xub_StrLen nOfst; 72 sal_uInt16 nWidth; 73 sal_uInt16 nAscent; 74 sal_uInt16 nCompress; 75 long nSperren; 76 long nSpace; 77 long nKern; 78 xub_StrLen nNumberOfBlanks; 79 sal_uInt8 nCursorBidiLevel; 80 sal_Bool bBullet : 1; 81 sal_Bool bUpper : 1; // Fuer Kapitaelchen: Grossbuchstaben-Flag 82 sal_Bool bDrawSpace : 1; // Fuer Kapitaelchen: Unter/Durchstreichung 83 sal_Bool bGreyWave : 1; // Graue Wellenlinie beim extended TextInput 84 sal_Bool bSpaceStop : 1; // For underlining we need to know, if a portion 85 // is right in front of a hole portion or a 86 // fix margin portion. 87 sal_Bool bSnapToGrid : 1; // Does paragraph snap to grid? 88 sal_Bool bIgnoreFrmRTL : 1; // Paint text as if text has LTR direction, used for 89 // line numbering 90 sal_Bool bPosMatchesBounds :1; // GetCrsrOfst should not return the next 91 // position if screen position is inside second 92 // half of bound rect, used for Accessibility 93 94 SwDrawTextInfo(); // nicht zulaessig 95 public: 96 97 #ifdef DBG_UTIL 98 sal_Bool bPos : 1; // These flags should control, that the appropriate 99 sal_Bool bWrong : 1; // Set-function has been called before calling 100 sal_Bool bGrammarCheck : 1; // the Get-function of a member 101 sal_Bool bSize : 1; 102 sal_Bool bFnt : 1; 103 sal_Bool bHyph : 1; 104 sal_Bool bLeft : 1; 105 sal_Bool bRight : 1; 106 sal_Bool bKana : 1; 107 sal_Bool bOfst : 1; 108 sal_Bool bAscent: 1; 109 sal_Bool bSperr : 1; 110 sal_Bool bSpace : 1; 111 sal_Bool bNumberOfBlanks : 1; 112 sal_Bool bUppr : 1; 113 sal_Bool bDrawSp: 1; 114 #endif 115 116 SwDrawTextInfo( ViewShell *pS, OutputDevice &rO, const SwScriptInfo* pSI, 117 const XubString &rSt, xub_StrLen nI, xub_StrLen nL, 118 sal_uInt16 nW = 0, sal_Bool bB = sal_False ) 119 { 120 pFrm = NULL; 121 pSh = pS; 122 pOut = &rO; 123 pScriptInfo = pSI; 124 pText = &rSt; 125 nIdx = nI; 126 nLen = nL; 127 nKern = 0; 128 nCompress = 0; 129 nWidth = nW; 130 nNumberOfBlanks = 0; 131 nCursorBidiLevel = 0; 132 bBullet = bB; 133 pUnderFnt = 0; 134 bGreyWave = sal_False; 135 bSpaceStop = sal_False; 136 bSnapToGrid = sal_False; 137 bIgnoreFrmRTL = sal_False; 138 bPosMatchesBounds = sal_False; 139 140 // These values are initialized but, they have to be 141 // set explicitly via their Set-function before they may 142 // be accessed by their Get-function: 143 pPos = 0; 144 pWrong = 0; 145 pGrammarCheck = 0; 146 pSmartTags = 0; 147 pSize = 0; 148 pFnt = 0; 149 pHyphPos = 0; 150 nLeft = 0; 151 nRight = 0; 152 nKanaDiff = 0; 153 nOfst = 0; 154 nAscent = 0; 155 nSperren = 0; 156 nSpace = 0; 157 bUpper = sal_False; 158 bDrawSpace = sal_False; 159 160 #ifdef DBG_UTIL 161 // these flags control, whether the matching member variables have 162 // been set by using the Set-function before they may be accessed 163 // by their Get-function: 164 bPos = bWrong = bGrammarCheck = bSize = bFnt = bAscent = bSpace = bNumberOfBlanks = bUppr = 165 bDrawSp = bLeft = bRight = bKana = bOfst = bHyph = bSperr = sal_False; 166 #endif 167 } 168 169 const SwTxtFrm* GetFrm() const 170 { 171 return pFrm; 172 } 173 174 void SetFrm( const SwTxtFrm* pNewFrm ) 175 { 176 pFrm = pNewFrm; 177 } 178 179 ViewShell *GetShell() const 180 { 181 return pSh; 182 } 183 184 OutputDevice& GetOut() const 185 { 186 return *pOut; 187 } 188 189 OutputDevice *GetpOut() const 190 { 191 return pOut; 192 } 193 194 const SwScriptInfo* GetScriptInfo() const 195 { 196 return pScriptInfo; 197 } 198 199 const Point &GetPos() const 200 { 201 ASSERT( bPos, "DrawTextInfo: Undefined Position" ); 202 return *pPos; 203 } 204 205 xub_StrLen *GetHyphPos() const 206 { 207 ASSERT( bHyph, "DrawTextInfo: Undefined Hyph Position" ); 208 return pHyphPos; 209 } 210 211 const XubString &GetText() const 212 { 213 return *pText; 214 } 215 216 const SwWrongList* GetWrong() const 217 { 218 ASSERT( bWrong, "DrawTextInfo: Undefined WrongList" ); 219 return pWrong; 220 } 221 222 const SwWrongList* GetGrammarCheck() const 223 { 224 ASSERT( bGrammarCheck, "DrawTextInfo: Undefined GrammarCheck List" ); 225 return pGrammarCheck; 226 } 227 228 const SwWrongList* GetSmartTags() const 229 { 230 return pSmartTags; 231 } 232 233 const Size &GetSize() const 234 { 235 ASSERT( bSize, "DrawTextInfo: Undefined Size" ); 236 return *pSize; 237 } 238 239 SwFont* GetFont() const 240 { 241 ASSERT( bFnt, "DrawTextInfo: Undefined Font" ); 242 return pFnt; 243 } 244 245 SwUnderlineFont* GetUnderFnt() const 246 { 247 return pUnderFnt; 248 } 249 250 xub_StrLen GetIdx() const 251 { 252 return nIdx; 253 } 254 255 xub_StrLen GetLen() const 256 { 257 return nLen; 258 } 259 260 xub_StrLen GetOfst() const 261 { 262 ASSERT( bOfst, "DrawTextInfo: Undefined Offset" ); 263 return nOfst; 264 } 265 266 xub_StrLen GetEnd() const 267 { 268 return nIdx + nLen; 269 } 270 271 long GetLeft() const 272 { 273 ASSERT( bLeft, "DrawTextInfo: Undefined left range" ); 274 return nLeft; 275 } 276 277 long GetRight() const 278 { 279 ASSERT( bRight, "DrawTextInfo: Undefined right range" ); 280 return nRight; 281 } 282 283 long GetKanaDiff() const 284 { 285 ASSERT( bKana, "DrawTextInfo: Undefined kana difference" ); 286 return nKanaDiff; 287 } 288 289 sal_uInt16 GetWidth() const 290 { 291 return nWidth; 292 } 293 294 sal_uInt16 GetAscent() const 295 { 296 ASSERT( bAscent, "DrawTextInfo: Undefined Ascent" ); 297 return nAscent; 298 } 299 300 sal_uInt16 GetKanaComp() const 301 { 302 return nCompress; 303 } 304 305 long GetSperren() const 306 { 307 ASSERT( bSperr, "DrawTextInfo: Undefined >Sperren<" ); 308 return nSperren; 309 } 310 311 long GetKern() const 312 { 313 return nKern; 314 } 315 316 long GetSpace() const 317 { 318 ASSERT( bSpace, "DrawTextInfo: Undefined Spacing" ); 319 return nSpace; 320 } 321 322 xub_StrLen GetNumberOfBlanks() const 323 { 324 ASSERT( bNumberOfBlanks, "DrawTextInfo::Undefined NumberOfBlanks" ); 325 return nNumberOfBlanks; 326 } 327 328 sal_uInt8 GetCursorBidiLevel() const 329 { 330 return nCursorBidiLevel; 331 } 332 333 sal_Bool GetBullet() const 334 { 335 return bBullet; 336 } 337 338 sal_Bool GetUpper() const 339 { 340 ASSERT( bUppr, "DrawTextInfo: Undefined Upperflag" ); 341 return bUpper; 342 } 343 344 sal_Bool GetDrawSpace() const 345 { 346 ASSERT( bDrawSp, "DrawTextInfo: Undefined DrawSpaceflag" ); 347 return bDrawSpace; 348 } 349 350 sal_Bool GetGreyWave() const 351 { 352 return bGreyWave; 353 } 354 355 sal_Bool IsSpaceStop() const 356 { 357 return bSpaceStop; 358 } 359 360 sal_Bool SnapToGrid() const 361 { 362 return bSnapToGrid; 363 } 364 365 sal_Bool IsIgnoreFrmRTL() const 366 { 367 return bIgnoreFrmRTL; 368 } 369 370 sal_Bool IsPosMatchesBounds() const 371 { 372 return bPosMatchesBounds; 373 } 374 375 void SetOut( OutputDevice &rNew ) 376 { 377 pOut = &rNew; 378 } 379 380 void SetPos( const Point &rNew ) 381 { 382 pPos = &rNew; 383 #ifdef DBG_UTIL 384 bPos = sal_True; 385 #endif 386 } 387 388 void SetHyphPos( xub_StrLen *pNew ) 389 { 390 pHyphPos = pNew; 391 #ifdef DBG_UTIL 392 bHyph = sal_True; 393 #endif 394 } 395 396 void SetText( const XubString &rNew ) 397 { 398 pText = &rNew; 399 } 400 401 void SetWrong( const SwWrongList* pNew ) 402 { 403 pWrong = pNew; 404 #ifdef DBG_UTIL 405 bWrong = sal_True; 406 #endif 407 } 408 409 void SetGrammarCheck( const SwWrongList* pNew ) 410 { 411 pGrammarCheck = pNew; 412 #ifdef DBG_UTIL 413 bGrammarCheck = sal_True; 414 #endif 415 } 416 417 void SetSmartTags( const SwWrongList* pNew ) 418 { 419 pSmartTags = pNew; 420 } 421 422 void SetSize( const Size &rNew ) 423 { 424 pSize = &rNew; 425 #ifdef DBG_UTIL 426 bSize = sal_True; 427 #endif 428 } 429 430 void SetFont( SwFont* pNew ) 431 { 432 pFnt = pNew; 433 #ifdef DBG_UTIL 434 bFnt = sal_True; 435 #endif 436 } 437 438 void SetIdx( xub_StrLen nNew ) 439 { 440 nIdx = nNew; 441 } 442 443 void SetLen( xub_StrLen nNew ) 444 { 445 nLen = nNew; 446 } 447 448 void SetOfst( xub_StrLen nNew ) 449 { 450 nOfst = nNew; 451 #ifdef DBG_UTIL 452 bOfst = sal_True; 453 #endif 454 } 455 456 void SetLeft( long nNew ) 457 { 458 nLeft = nNew; 459 #ifdef DBG_UTIL 460 bLeft = sal_True; 461 #endif 462 } 463 464 void SetRight( long nNew ) 465 { 466 nRight = nNew; 467 #ifdef DBG_UTIL 468 bRight = sal_True; 469 #endif 470 } 471 472 void SetKanaDiff( long nNew ) 473 { 474 nKanaDiff = nNew; 475 #ifdef DBG_UTIL 476 bKana = sal_True; 477 #endif 478 } 479 480 void SetWidth( sal_uInt16 nNew ) 481 { 482 nWidth = nNew; 483 } 484 485 void SetAscent( sal_uInt16 nNew ) 486 { 487 nAscent = nNew; 488 #ifdef DBG_UTIL 489 bAscent = sal_True; 490 #endif 491 } 492 493 void SetKern( long nNew ) 494 { 495 nKern = nNew; 496 } 497 498 void SetSpace( long nNew ) 499 { 500 if( nNew < 0 ) 501 { 502 nSperren = -nNew; 503 nSpace = 0; 504 } 505 else 506 { 507 nSpace = nNew; 508 nSperren = 0; 509 } 510 #ifdef DBG_UTIL 511 bSpace = sal_True; 512 bSperr = sal_True; 513 #endif 514 } 515 516 void SetNumberOfBlanks( xub_StrLen nNew ) 517 { 518 #ifdef DBG_UTIL 519 bNumberOfBlanks = sal_True; 520 #endif 521 nNumberOfBlanks = nNew; 522 } 523 524 void SetCursorBidiLevel( sal_uInt8 nNew ) 525 { 526 nCursorBidiLevel = nNew; 527 } 528 529 void SetKanaComp( short nNew ) 530 { 531 nCompress = nNew; 532 } 533 534 void SetBullet( sal_Bool bNew ) 535 { 536 bBullet = bNew; 537 } 538 539 void SetUnderFnt( SwUnderlineFont* pULFnt ) 540 { 541 pUnderFnt = pULFnt; 542 } 543 544 void SetUpper( sal_Bool bNew ) 545 { 546 bUpper = bNew; 547 #ifdef DBG_UTIL 548 bUppr = sal_True; 549 #endif 550 } 551 552 void SetDrawSpace( sal_Bool bNew ) 553 { 554 bDrawSpace = bNew; 555 #ifdef DBG_UTIL 556 bDrawSp = sal_True; 557 #endif 558 } 559 560 void SetGreyWave( sal_Bool bNew ) 561 { 562 bGreyWave = bNew; 563 } 564 565 void SetSpaceStop( sal_Bool bNew ) 566 { 567 bSpaceStop = bNew; 568 } 569 570 void SetSnapToGrid( sal_Bool bNew ) 571 { 572 bSnapToGrid = bNew; 573 } 574 575 void SetIgnoreFrmRTL( sal_Bool bNew ) 576 { 577 bIgnoreFrmRTL = bNew; 578 } 579 580 void SetPosMatchesBounds( sal_Bool bNew ) 581 { 582 bPosMatchesBounds = bNew; 583 } 584 585 void Shift( sal_uInt16 nDir ); 586 587 // sets a new color at the output device if necessary 588 // if a font is passed as argument, the change if made to the font 589 // otherwise the font at the output device is changed 590 // returns if the font has been changed 591 sal_Bool ApplyAutoColor( Font* pFnt = 0 ); 592 }; 593 594 #endif 595