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 #ifndef _PORLAY_HXX 24 #define _PORLAY_HXX 25 26 #include <tools/string.hxx> 27 #include <tools/fract.hxx> 28 #include <scriptinfo.hxx> 29 30 #include "swrect.hxx" // SwRepaint 31 #include "portxt.hxx" 32 #include "swfont.hxx" 33 34 #include <vector> 35 36 class SwMarginPortion; 37 class SwDropPortion; 38 class SvStream; 39 class SwTxtFormatter; 40 41 /************************************************************************* 42 * class SwCharRange 43 *************************************************************************/ 44 45 class SwCharRange 46 { 47 xub_StrLen nStart, nLen; 48 public: 49 inline SwCharRange( const xub_StrLen nInitStart = 0, 50 const xub_StrLen nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {} 51 inline xub_StrLen &Start() { return nStart; } 52 inline const xub_StrLen &Start() const { return nStart; } 53 inline void LeftMove( xub_StrLen nNew ) 54 { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } } 55 inline xub_StrLen End() const 56 { return nStart + nLen; } 57 inline xub_StrLen &Len() { return nLen; } 58 inline const xub_StrLen &Len() const { return nLen; } 59 inline sal_Bool operator<(const SwCharRange &rRange) const 60 { return nStart < rRange.nStart; } 61 inline sal_Bool operator>(const SwCharRange &rRange) const 62 { return nStart + nLen > rRange.nStart + rRange.nLen; } 63 inline sal_Bool operator!=(const SwCharRange &rRange) const 64 { return *this < rRange || *this > rRange; } 65 SwCharRange &operator+=(const SwCharRange &rRange); 66 }; 67 68 /************************************************************************* 69 * class SwRepaint 70 *************************************************************************/ 71 72 // SwRepaint ist ein dokumentglobales SwRect mit einem nOfst der angibt, 73 // ab wo in der ersten Zeile gepaintet werden soll 74 // und einem nRightOfst, der den rechten Rand bestimmt 75 class SwRepaint : public SwRect 76 { 77 SwTwips nOfst; 78 SwTwips nRightOfst; 79 public: 80 SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {} 81 SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ), 82 nRightOfst( rRep.nRightOfst ) {} 83 84 SwTwips GetOfst() const { return nOfst; } 85 void SetOfst( const SwTwips nNew ) { nOfst = nNew; } 86 SwTwips GetRightOfst() const { return nRightOfst; } 87 void SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; } 88 }; 89 90 /************************************************************************* 91 * class SwLineLayout 92 *************************************************************************/ 93 94 class SwLineLayout : public SwTxtPortion 95 { 96 private: 97 SwLineLayout *pNext; // Die naechste Zeile. 98 std::vector<long>* pLLSpaceAdd; // Used for justified alignment. 99 SvUShorts* pKanaComp; // Used for Kana compression. 100 KSHORT nRealHeight; // Die aus Zeilenabstand/Register resultierende Hoehe. 101 sal_Bool bFormatAdj : 1; 102 sal_Bool bDummy : 1; 103 sal_Bool bFntChg : 1; 104 sal_Bool bEndHyph : 1; 105 sal_Bool bMidHyph : 1; 106 sal_Bool bTab : 1; 107 sal_Bool bFly : 1; 108 sal_Bool bRest : 1; 109 sal_Bool bBlinking : 1; 110 sal_Bool bClipping : 1; // Clipping erforderlich wg. exakter Zeilenhoehe 111 sal_Bool bContent : 1; // enthaelt Text, fuer Zeilennumerierung 112 sal_Bool bRedline : 1; // enthaelt Redlining 113 sal_Bool bForcedLeftMargin : 1; // vom Fly verschobener linker Einzug 114 sal_Bool bHanging : 1; // contents a hanging portion in the margin 115 sal_Bool bUnderscore : 1; 116 117 SwTwips _GetHangingMargin() const; 118 119 public: 120 // von SwLinePortion 121 virtual SwLinePortion *Insert( SwLinePortion *pPortion ); 122 virtual SwLinePortion *Append( SwLinePortion *pPortion ); 123 inline SwLinePortion *GetFirstPortion() const; 124 125 // Flags 126 inline void ResetFlags(); 127 inline void SetFormatAdj( const sal_Bool bNew ) { bFormatAdj = bNew; } 128 inline sal_Bool IsFormatAdj() const { return bFormatAdj; } 129 inline void SetFntChg( const sal_Bool bNew ) { bFntChg = bNew; } 130 inline sal_Bool IsFntChg() const { return bFntChg; } 131 inline void SetEndHyph( const sal_Bool bNew ) { bEndHyph = bNew; } 132 inline sal_Bool IsEndHyph() const { return bEndHyph; } 133 inline void SetMidHyph( const sal_Bool bNew ) { bMidHyph = bNew; } 134 inline sal_Bool IsMidHyph() const { return bMidHyph; } 135 inline void SetTab( const sal_Bool bNew ) { bTab = bNew; } 136 inline sal_Bool IsTab() const { return bTab; } 137 inline void SetFly( const sal_Bool bNew ) { bFly = bNew; } 138 inline sal_Bool IsFly() const { return bFly; } 139 inline void SetRest( const sal_Bool bNew ) { bRest = bNew; } 140 inline sal_Bool IsRest() const { return bRest; } 141 inline void SetBlinking( const sal_Bool bNew = sal_True ) { bBlinking = bNew; } 142 inline sal_Bool IsBlinking() const { return bBlinking; } 143 inline void SetCntnt( const sal_Bool bNew = sal_True ) { bContent = bNew; } 144 inline sal_Bool HasCntnt() const { return bContent; } 145 inline void SetRedline( const sal_Bool bNew = sal_True ) { bRedline = bNew; } 146 inline sal_Bool HasRedline() const { return bRedline; } 147 inline void SetForcedLeftMargin( const sal_Bool bNew = sal_True ) { bForcedLeftMargin = bNew; } 148 inline sal_Bool HasForcedLeftMargin() const { return bForcedLeftMargin; } 149 inline void SetHanging( const sal_Bool bNew = sal_True ) { bHanging = bNew; } 150 inline sal_Bool IsHanging() const { return bHanging; } 151 inline void SetUnderscore( const sal_Bool bNew = sal_True ) { bUnderscore = bNew; } 152 inline sal_Bool HasUnderscore() const { return bUnderscore; } 153 154 // Beruecksichtigung von Dummyleerzeilen 155 // 4147, 8221: 156 inline void SetDummy( const sal_Bool bNew ) { bDummy = bNew; } 157 inline sal_Bool IsDummy() const { return bDummy; } 158 159 inline void SetClipping( const sal_Bool bNew ) { bClipping = bNew; } 160 inline sal_Bool IsClipping() const { return bClipping; } 161 162 inline SwLineLayout(); 163 virtual ~SwLineLayout(); 164 165 inline SwLineLayout *GetNext() { return pNext; } 166 inline const SwLineLayout *GetNext() const { return pNext; } 167 inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; } 168 169 void Init( SwLinePortion *pNextPortion = NULL); 170 171 // Sammelt die Daten fuer die Zeile. 172 void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf ); 173 174 inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; } 175 inline KSHORT GetRealHeight() const { return nRealHeight; } 176 177 // Erstellt bei kurzen Zeilen die Glue-Kette. 178 SwMarginPortion *CalcLeftMargin(); 179 180 inline SwTwips GetHangingMargin() const 181 { return _GetHangingMargin(); } 182 183 // fuer die Sonderbehandlung bei leeren Zeilen 184 virtual sal_Bool Format( SwTxtFormatInfo &rInf ); 185 186 // 187 // STUFF FOR JUSTIFIED ALIGNMENT 188 // 189 inline sal_Bool IsSpaceAdd() { return pLLSpaceAdd != NULL; } 190 void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary 191 void CreateSpaceAdd( const long nInit = 0 ); 192 inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; } 193 inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); } 194 inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx ) 195 { 196 if ( nIdx == GetLLSpaceAddCount() ) 197 pLLSpaceAdd->push_back( nNew ); 198 else 199 (*pLLSpaceAdd)[ nIdx ] = nNew; 200 } 201 inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; } 202 inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); } 203 inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; } 204 205 // 206 // STUFF FOR KANA COMPRESSION 207 // 208 inline void SetKanaComp( SvUShorts* pNew ){ pKanaComp = pNew; } 209 inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; } 210 inline SvUShorts* GetpKanaComp() const { return pKanaComp; } 211 inline SvUShorts& GetKanaComp() { return *pKanaComp; } 212 213 /** determine ascent and descent for positioning of as-character anchored 214 object 215 216 OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent> 217 Method calculates maximum ascents and descents of the line layout. 218 One value considering as-character anchored objects, one without these 219 objects. 220 Portions for other anchored objects aren't considered. 221 OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor> 222 to control, if the fly content portions and line portion are considered. 223 224 @param _orAscent 225 output parameter - maximum ascent without as-character anchored objects 226 227 @param _orDescent 228 output parameter - maximum descent without as-character anchored objects 229 230 @param _orObjAscent 231 output parameter - maximum ascent with as-character anchored objects 232 233 @param _orObjDescent 234 output parameter - maximum descent with as-character anchored objects 235 236 @param _pDontConsiderPortion 237 input parameter - portion, which isn't considered for calculating 238 <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a 239 as-character anchored object or it isn't as high as the line. 240 241 @param _bNoFlyCntPorAndLinePor 242 optional input parameter - boolean, indicating that fly content portions 243 and the line portion are considered or not. 244 245 @author OD 246 */ 247 void MaxAscentDescent( SwTwips& _orAscent, 248 SwTwips& _orDescent, 249 SwTwips& _orObjAscent, 250 SwTwips& _orObjDescent, 251 const SwLinePortion* _pDontConsiderPortion = NULL, 252 const bool _bNoFlyCntPorAndLinePor = false ) const; 253 254 #ifdef DBG_UTIL 255 void DebugPortions( SvStream &rOs, const XubString &rTxt, 256 const xub_StrLen nStart ); //$ ostream 257 #endif 258 259 OUTPUT_OPERATOR 260 DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout) 261 }; 262 263 class SwParaPortion : public SwLineLayout 264 { 265 // neu zu paintender Bereich 266 SwRepaint aRepaint; 267 // neu zu formatierender Bereich 268 SwCharRange aReformat; 269 SwScriptInfo aScriptInfo; 270 // Fraction aZoom; 271 long nDelta; 272 273 // Wenn ein SwTxtFrm gelocked ist, werden keine Veraenderungen an den 274 // Formatierungsdaten (unter pLine) vorgenommen (vgl. ORPHANS) 275 sal_Bool bFlys : 1; // Ueberlappen Flys ? 276 sal_Bool bPrep : 1; // PREP_* 277 sal_Bool bPrepWidows : 1; // PREP_WIDOWS 278 sal_Bool bPrepAdjust : 1; // PREP_ADJUST_FRM 279 sal_Bool bPrepMustFit : 1; // PREP_MUST_FIT 280 sal_Bool bFollowField : 1; // Es steht noch ein Feldrest fuer den Follow an. 281 282 sal_Bool bFixLineHeight : 1; // Feste Zeilenhoehe 283 sal_Bool bFtnNum : 1; // contents a footnotenumberportion 284 sal_Bool bMargin : 1; // contents a hanging punctuation in the margin 285 286 sal_Bool bFlag00 : 1; // 287 sal_Bool bFlag11 : 1; // 288 sal_Bool bFlag12 : 1; // 289 sal_Bool bFlag13 : 1; // 290 sal_Bool bFlag14 : 1; // 291 sal_Bool bFlag15 : 1; // 292 sal_Bool bFlag16 : 1; // 293 294 public: 295 SwParaPortion(); 296 virtual ~SwParaPortion(); 297 298 // setzt alle Formatinformationen zurueck (ausser bFlys wg. 9916) 299 inline void FormatReset(); 300 301 // Setzt die Flags zurueck 302 inline void ResetPreps(); 303 304 // Get/Set-Methoden 305 inline SwRepaint *GetRepaint() { return &aRepaint; } 306 inline const SwRepaint *GetRepaint() const { return &aRepaint; } 307 inline SwCharRange *GetReformat() { return &aReformat; } 308 inline const SwCharRange *GetReformat() const { return &aReformat; } 309 inline long *GetDelta() { return &nDelta; } 310 inline const long *GetDelta() const { return &nDelta; } 311 inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; } 312 inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; } 313 314 // fuer SwTxtFrm::Format: liefert die aktuelle Laenge des Absatzes 315 xub_StrLen GetParLen() const; 316 317 // fuer Prepare() 318 sal_Bool UpdateQuoVadis( const XubString &rQuo ); 319 320 // Flags 321 inline void SetFly( const sal_Bool bNew = sal_True ) { bFlys = bNew; } 322 inline sal_Bool HasFly() const { return bFlys; } 323 324 // Preps 325 inline void SetPrep( const sal_Bool bNew = sal_True ) { bPrep = bNew; } 326 inline sal_Bool IsPrep() const { return bPrep; } 327 inline void SetPrepWidows( const sal_Bool bNew = sal_True ) { bPrepWidows = bNew; } 328 inline sal_Bool IsPrepWidows() const { return bPrepWidows; } 329 inline void SetPrepMustFit( const sal_Bool bNew = sal_True ) { bPrepMustFit = bNew; } 330 inline sal_Bool IsPrepMustFit() const { return bPrepMustFit; } 331 inline void SetPrepAdjust( const sal_Bool bNew = sal_True ) { bPrepAdjust = bNew; } 332 inline sal_Bool IsPrepAdjust() const { return bPrepAdjust; } 333 inline void SetFollowField( const sal_Bool bNew = sal_True ) { bFollowField = bNew; } 334 inline sal_Bool IsFollowField() const { return bFollowField; } 335 inline void SetFixLineHeight( const sal_Bool bNew = sal_True ) { bFixLineHeight = bNew; } 336 inline sal_Bool IsFixLineHeight() const { return bFixLineHeight; } 337 338 inline void SetFtnNum( const sal_Bool bNew = sal_True ) { bFtnNum = bNew; } 339 inline sal_Bool IsFtnNum() const { return bFtnNum; } 340 inline void SetMargin( const sal_Bool bNew = sal_True ) { bMargin = bNew; } 341 inline sal_Bool IsMargin() const { return bMargin; } 342 inline void SetFlag00( const sal_Bool bNew = sal_True ) { bFlag00 = bNew; } 343 inline sal_Bool IsFlag00() const { return bFlag00; } 344 inline void SetFlag11( const sal_Bool bNew = sal_True ) { bFlag11 = bNew; } 345 inline sal_Bool IsFlag11() const { return bFlag11; } 346 inline void SetFlag12( const sal_Bool bNew = sal_True ) { bFlag12 = bNew; } 347 inline sal_Bool IsFlag12() const { return bFlag12; } 348 inline void SetFlag13( const sal_Bool bNew = sal_True ) { bFlag13 = bNew; } 349 inline sal_Bool IsFlag13() const { return bFlag13; } 350 inline void SetFlag14( const sal_Bool bNew = sal_True ) { bFlag14 = bNew; } 351 inline sal_Bool IsFlag14() const { return bFlag14; } 352 inline void SetFlag15( const sal_Bool bNew = sal_True ) { bFlag15 = bNew; } 353 inline sal_Bool IsFlag15() const { return bFlag15; } 354 inline void SetFlag16( const sal_Bool bNew = sal_True ) { bFlag16 = bNew; } 355 inline sal_Bool IsFlag16() const { return bFlag16; } 356 357 // schneller, hoeher, weiter: Read/Write-Methoden fuer den SWG-Filter 358 SvStream &ReadSwg ( SvStream& rStream ); //$ istream 359 SvStream &WriteSwg( SvStream& rStream ); //$ ostream 360 361 // nErgo in der QuoVadisPortion setzen 362 void SetErgoSumNum( const XubString &rErgo ); 363 364 const SwDropPortion *FindDropPortion() const; 365 366 OUTPUT_OPERATOR 367 DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion) 368 }; 369 370 /************************************************************************* 371 * Inline-Implementierungen 372 *************************************************************************/ 373 374 inline void SwLineLayout::ResetFlags() 375 { 376 bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly 377 = bRest = bBlinking = bClipping = bContent = bRedline 378 = bForcedLeftMargin = bHanging = sal_False; 379 } 380 381 inline SwLineLayout::SwLineLayout() 382 : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ), 383 bUnderscore( sal_False ) 384 { 385 ResetFlags(); 386 SetWhichPor( POR_LAY ); 387 } 388 389 inline void SwParaPortion::ResetPreps() 390 { 391 bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = sal_False; 392 } 393 394 inline void SwParaPortion::FormatReset() 395 { 396 nDelta = 0; 397 aReformat = SwCharRange( 0, STRING_LEN ); 398 // AMA 9916: bFlys muss in SwTxtFrm::_Format() erhalten bleiben, damit 399 // leere Absaetze, die Rahmen ohne Umfluss ausweichen mussten, sich 400 // neu formatieren, wenn der Rahmen aus dem Bereich verschwindet. 401 // bFlys = sal_False; 402 ResetPreps(); 403 bFollowField = bFixLineHeight = bMargin = sal_False; 404 } 405 406 #ifdef UNX 407 // C30 ist mit dem ternaeren Ausdruck ueberfordert. 408 inline SwLinePortion *SwLineLayout::GetFirstPortion() const 409 { 410 SwLinePortion *pTmp = pPortion; 411 if ( !pPortion ) 412 pTmp = (SwLinePortion*)this; 413 return( pTmp ); 414 } 415 #else 416 inline SwLinePortion *SwLineLayout::GetFirstPortion() const 417 { return( pPortion ? pPortion : (SwLinePortion*)this ); } 418 #endif 419 420 CLASSIO( SwLineLayout ) 421 CLASSIO( SwParaPortion ) 422 423 #endif 424