1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: porlay.hxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
33 #include <tools/string.hxx>
34 #include <tools/fract.hxx>
35 #include <scriptinfo.hxx>
37 #include "swrect.hxx" // SwRepaint
43 class SwMarginPortion
;
48 /*************************************************************************
50 *************************************************************************/
54 xub_StrLen nStart
, nLen
;
56 inline SwCharRange( const xub_StrLen nInitStart
= 0,
57 const xub_StrLen nInitLen
= 0): nStart( nInitStart
), nLen(nInitLen
) {}
58 inline xub_StrLen
&Start() { return nStart
; }
59 inline const xub_StrLen
&Start() const { return nStart
; }
60 inline void LeftMove( xub_StrLen nNew
)
61 { if ( nNew
< nStart
) { nLen
+= nStart
-nNew
; nStart
= nNew
; } }
62 inline xub_StrLen
End() const
63 { return nStart
+ nLen
; }
64 inline xub_StrLen
&Len() { return nLen
; }
65 inline const xub_StrLen
&Len() const { return nLen
; }
66 inline sal_Bool
operator<(const SwCharRange
&rRange
) const
67 { return nStart
< rRange
.nStart
; }
68 inline sal_Bool
operator>(const SwCharRange
&rRange
) const
69 { return nStart
+ nLen
> rRange
.nStart
+ rRange
.nLen
; }
70 inline sal_Bool
operator!=(const SwCharRange
&rRange
) const
71 { return *this < rRange
|| *this > rRange
; }
72 SwCharRange
&operator+=(const SwCharRange
&rRange
);
75 /*************************************************************************
77 *************************************************************************/
79 // SwRepaint ist ein dokumentglobales SwRect mit einem nOfst der angibt,
80 // ab wo in der ersten Zeile gepaintet werden soll
81 // und einem nRightOfst, der den rechten Rand bestimmt
82 class SwRepaint
: public SwRect
87 SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
88 SwRepaint( const SwRepaint
& rRep
) : SwRect( rRep
), nOfst( rRep
.nOfst
),
89 nRightOfst( rRep
.nRightOfst
) {}
91 SwTwips
GetOfst() const { return nOfst
; }
92 void SetOfst( const SwTwips nNew
) { nOfst
= nNew
; }
93 SwTwips
GetRightOfst() const { return nRightOfst
; }
94 void SetRightOfst( const SwTwips nNew
) { nRightOfst
= nNew
; }
97 /*************************************************************************
99 *************************************************************************/
101 class SwLineLayout
: public SwTxtPortion
104 SwLineLayout
*pNext
; // Die naechste Zeile.
105 std::vector
<long>* pLLSpaceAdd
; // Used for justified alignment.
106 SvUShorts
* pKanaComp
; // Used for Kana compression.
107 KSHORT nRealHeight
; // Die aus Zeilenabstand/Register resultierende Hoehe.
108 sal_Bool bFormatAdj
: 1;
110 sal_Bool bFntChg
: 1;
111 sal_Bool bEndHyph
: 1;
112 sal_Bool bMidHyph
: 1;
116 sal_Bool bBlinking
: 1;
117 sal_Bool bClipping
: 1; // Clipping erforderlich wg. exakter Zeilenhoehe
118 sal_Bool bContent
: 1; // enthaelt Text, fuer Zeilennumerierung
119 sal_Bool bRedline
: 1; // enthaelt Redlining
120 sal_Bool bForcedLeftMargin
: 1; // vom Fly verschobener linker Einzug
121 sal_Bool bHanging
: 1; // contents a hanging portion in the margin
122 sal_Bool bUnderscore
: 1;
124 SwTwips
_GetHangingMargin() const;
128 virtual SwLinePortion
*Insert( SwLinePortion
*pPortion
);
129 virtual SwLinePortion
*Append( SwLinePortion
*pPortion
);
130 inline SwLinePortion
*GetFirstPortion() const;
133 inline void ResetFlags();
134 inline void SetFormatAdj( const sal_Bool bNew
) { bFormatAdj
= bNew
; }
135 inline sal_Bool
IsFormatAdj() const { return bFormatAdj
; }
136 inline void SetFntChg( const sal_Bool bNew
) { bFntChg
= bNew
; }
137 inline sal_Bool
IsFntChg() const { return bFntChg
; }
138 inline void SetEndHyph( const sal_Bool bNew
) { bEndHyph
= bNew
; }
139 inline sal_Bool
IsEndHyph() const { return bEndHyph
; }
140 inline void SetMidHyph( const sal_Bool bNew
) { bMidHyph
= bNew
; }
141 inline sal_Bool
IsMidHyph() const { return bMidHyph
; }
142 inline void SetTab( const sal_Bool bNew
) { bTab
= bNew
; }
143 inline sal_Bool
IsTab() const { return bTab
; }
144 inline void SetFly( const sal_Bool bNew
) { bFly
= bNew
; }
145 inline sal_Bool
IsFly() const { return bFly
; }
146 inline void SetRest( const sal_Bool bNew
) { bRest
= bNew
; }
147 inline sal_Bool
IsRest() const { return bRest
; }
148 inline void SetBlinking( const sal_Bool bNew
= sal_True
) { bBlinking
= bNew
; }
149 inline sal_Bool
IsBlinking() const { return bBlinking
; }
150 inline void SetCntnt( const sal_Bool bNew
= sal_True
) { bContent
= bNew
; }
151 inline sal_Bool
HasCntnt() const { return bContent
; }
152 inline void SetRedline( const sal_Bool bNew
= sal_True
) { bRedline
= bNew
; }
153 inline sal_Bool
HasRedline() const { return bRedline
; }
154 inline void SetForcedLeftMargin( const sal_Bool bNew
= sal_True
) { bForcedLeftMargin
= bNew
; }
155 inline sal_Bool
HasForcedLeftMargin() const { return bForcedLeftMargin
; }
156 inline void SetHanging( const sal_Bool bNew
= sal_True
) { bHanging
= bNew
; }
157 inline sal_Bool
IsHanging() const { return bHanging
; }
158 inline void SetUnderscore( const sal_Bool bNew
= sal_True
) { bUnderscore
= bNew
; }
159 inline sal_Bool
HasUnderscore() const { return bUnderscore
; }
161 // Beruecksichtigung von Dummyleerzeilen
163 inline void SetDummy( const sal_Bool bNew
) { bDummy
= bNew
; }
164 inline sal_Bool
IsDummy() const { return bDummy
; }
166 inline void SetClipping( const sal_Bool bNew
) { bClipping
= bNew
; }
167 inline sal_Bool
IsClipping() const { return bClipping
; }
169 inline SwLineLayout();
170 virtual ~SwLineLayout();
172 inline SwLineLayout
*GetNext() { return pNext
; }
173 inline const SwLineLayout
*GetNext() const { return pNext
; }
174 inline void SetNext( SwLineLayout
*pNew
) { pNext
= pNew
; }
176 void Init( SwLinePortion
*pNextPortion
= NULL
);
178 // Sammelt die Daten fuer die Zeile.
179 void CalcLine( SwTxtFormatter
&rLine
, SwTxtFormatInfo
&rInf
);
181 inline void SetRealHeight( KSHORT nNew
) { nRealHeight
= nNew
; }
182 inline KSHORT
GetRealHeight() const { return nRealHeight
; }
184 // Erstellt bei kurzen Zeilen die Glue-Kette.
185 SwMarginPortion
*CalcLeftMargin();
187 inline SwTwips
GetHangingMargin() const
188 { return _GetHangingMargin(); }
190 // fuer die Sonderbehandlung bei leeren Zeilen
191 virtual sal_Bool
Format( SwTxtFormatInfo
&rInf
);
194 // STUFF FOR JUSTIFIED ALIGNMENT
196 inline sal_Bool
IsSpaceAdd() { return pLLSpaceAdd
!= NULL
; }
197 void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
198 void CreateSpaceAdd( const long nInit
= 0 );
199 inline void FinishSpaceAdd() { delete pLLSpaceAdd
; pLLSpaceAdd
= NULL
; }
200 inline USHORT
GetLLSpaceAddCount() const { return sal::static_int_cast
< USHORT
>(pLLSpaceAdd
->size()); }
201 inline void SetLLSpaceAdd( long nNew
, USHORT nIdx
)
203 if ( nIdx
== GetLLSpaceAddCount() )
204 pLLSpaceAdd
->push_back( nNew
);
206 (*pLLSpaceAdd
)[ nIdx
] = nNew
;
208 inline long GetLLSpaceAdd( USHORT nIdx
) { return (*pLLSpaceAdd
)[ nIdx
]; }
209 inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd
->erase( pLLSpaceAdd
->begin() ); }
210 inline std::vector
<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd
; }
213 // STUFF FOR KANA COMPRESSION
215 inline void SetKanaComp( SvUShorts
* pNew
){ pKanaComp
= pNew
; }
216 inline void FinishKanaComp() { delete pKanaComp
; pKanaComp
= NULL
; }
217 inline SvUShorts
* GetpKanaComp() const { return pKanaComp
; }
218 inline SvUShorts
& GetKanaComp() { return *pKanaComp
; }
220 /** determine ascent and descent for positioning of as-character anchored
223 OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
224 Method calculates maximum ascents and descents of the line layout.
225 One value considering as-character anchored objects, one without these
227 Portions for other anchored objects aren't considered.
228 OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
229 to control, if the fly content portions and line portion are considered.
232 output parameter - maximum ascent without as-character anchored objects
235 output parameter - maximum descent without as-character anchored objects
238 output parameter - maximum ascent with as-character anchored objects
241 output parameter - maximum descent with as-character anchored objects
243 @param _pDontConsiderPortion
244 input parameter - portion, which isn't considered for calculating
245 <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
246 as-character anchored object or it isn't as high as the line.
248 @param _bNoFlyCntPorAndLinePor
249 optional input parameter - boolean, indicating that fly content portions
250 and the line portion are considered or not.
254 void MaxAscentDescent( SwTwips
& _orAscent
,
256 SwTwips
& _orObjAscent
,
257 SwTwips
& _orObjDescent
,
258 const SwLinePortion
* _pDontConsiderPortion
= NULL
,
259 const bool _bNoFlyCntPorAndLinePor
= false ) const;
262 void DebugPortions( SvStream
&rOs
, const XubString
&rTxt
,
263 const xub_StrLen nStart
); //$ ostream
267 DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout
)
270 class SwParaPortion
: public SwLineLayout
272 // neu zu paintender Bereich
274 // neu zu formatierender Bereich
275 SwCharRange aReformat
;
276 SwScriptInfo aScriptInfo
;
280 // Wenn ein SwTxtFrm gelocked ist, werden keine Veraenderungen an den
281 // Formatierungsdaten (unter pLine) vorgenommen (vgl. ORPHANS)
282 sal_Bool bFlys
: 1; // Ueberlappen Flys ?
283 sal_Bool bPrep
: 1; // PREP_*
284 sal_Bool bPrepWidows
: 1; // PREP_WIDOWS
285 sal_Bool bPrepAdjust
: 1; // PREP_ADJUST_FRM
286 sal_Bool bPrepMustFit
: 1; // PREP_MUST_FIT
287 sal_Bool bFollowField
: 1; // Es steht noch ein Feldrest fuer den Follow an.
289 sal_Bool bFixLineHeight
: 1; // Feste Zeilenhoehe
290 sal_Bool bFtnNum
: 1; // contents a footnotenumberportion
291 sal_Bool bMargin
: 1; // contents a hanging punctuation in the margin
293 sal_Bool bFlag00
: 1; //
294 sal_Bool bFlag11
: 1; //
295 sal_Bool bFlag12
: 1; //
296 sal_Bool bFlag13
: 1; //
297 sal_Bool bFlag14
: 1; //
298 sal_Bool bFlag15
: 1; //
299 sal_Bool bFlag16
: 1; //
303 virtual ~SwParaPortion();
305 // setzt alle Formatinformationen zurueck (ausser bFlys wg. 9916)
306 inline void FormatReset();
308 // Setzt die Flags zurueck
309 inline void ResetPreps();
312 inline SwRepaint
*GetRepaint() { return &aRepaint
; }
313 inline const SwRepaint
*GetRepaint() const { return &aRepaint
; }
314 inline SwCharRange
*GetReformat() { return &aReformat
; }
315 inline const SwCharRange
*GetReformat() const { return &aReformat
; }
316 inline long *GetDelta() { return &nDelta
; }
317 inline const long *GetDelta() const { return &nDelta
; }
318 inline SwScriptInfo
& GetScriptInfo() { return aScriptInfo
; }
319 inline const SwScriptInfo
& GetScriptInfo() const { return aScriptInfo
; }
321 // fuer SwTxtFrm::Format: liefert die aktuelle Laenge des Absatzes
322 xub_StrLen
GetParLen() const;
325 sal_Bool
UpdateQuoVadis( const XubString
&rQuo
);
328 inline void SetFly( const sal_Bool bNew
= sal_True
) { bFlys
= bNew
; }
329 inline sal_Bool
HasFly() const { return bFlys
; }
332 inline void SetPrep( const sal_Bool bNew
= sal_True
) { bPrep
= bNew
; }
333 inline sal_Bool
IsPrep() const { return bPrep
; }
334 inline void SetPrepWidows( const sal_Bool bNew
= sal_True
) { bPrepWidows
= bNew
; }
335 inline sal_Bool
IsPrepWidows() const { return bPrepWidows
; }
336 inline void SetPrepMustFit( const sal_Bool bNew
= sal_True
) { bPrepMustFit
= bNew
; }
337 inline sal_Bool
IsPrepMustFit() const { return bPrepMustFit
; }
338 inline void SetPrepAdjust( const sal_Bool bNew
= sal_True
) { bPrepAdjust
= bNew
; }
339 inline sal_Bool
IsPrepAdjust() const { return bPrepAdjust
; }
340 inline void SetFollowField( const sal_Bool bNew
= sal_True
) { bFollowField
= bNew
; }
341 inline sal_Bool
IsFollowField() const { return bFollowField
; }
342 inline void SetFixLineHeight( const sal_Bool bNew
= sal_True
) { bFixLineHeight
= bNew
; }
343 inline sal_Bool
IsFixLineHeight() const { return bFixLineHeight
; }
345 inline void SetFtnNum( const sal_Bool bNew
= sal_True
) { bFtnNum
= bNew
; }
346 inline sal_Bool
IsFtnNum() const { return bFtnNum
; }
347 inline void SetMargin( const sal_Bool bNew
= sal_True
) { bMargin
= bNew
; }
348 inline sal_Bool
IsMargin() const { return bMargin
; }
349 inline void SetFlag00( const sal_Bool bNew
= sal_True
) { bFlag00
= bNew
; }
350 inline sal_Bool
IsFlag00() const { return bFlag00
; }
351 inline void SetFlag11( const sal_Bool bNew
= sal_True
) { bFlag11
= bNew
; }
352 inline sal_Bool
IsFlag11() const { return bFlag11
; }
353 inline void SetFlag12( const sal_Bool bNew
= sal_True
) { bFlag12
= bNew
; }
354 inline sal_Bool
IsFlag12() const { return bFlag12
; }
355 inline void SetFlag13( const sal_Bool bNew
= sal_True
) { bFlag13
= bNew
; }
356 inline sal_Bool
IsFlag13() const { return bFlag13
; }
357 inline void SetFlag14( const sal_Bool bNew
= sal_True
) { bFlag14
= bNew
; }
358 inline sal_Bool
IsFlag14() const { return bFlag14
; }
359 inline void SetFlag15( const sal_Bool bNew
= sal_True
) { bFlag15
= bNew
; }
360 inline sal_Bool
IsFlag15() const { return bFlag15
; }
361 inline void SetFlag16( const sal_Bool bNew
= sal_True
) { bFlag16
= bNew
; }
362 inline sal_Bool
IsFlag16() const { return bFlag16
; }
364 // schneller, hoeher, weiter: Read/Write-Methoden fuer den SWG-Filter
365 SvStream
&ReadSwg ( SvStream
& rStream
); //$ istream
366 SvStream
&WriteSwg( SvStream
& rStream
); //$ ostream
368 // nErgo in der QuoVadisPortion setzen
369 void SetErgoSumNum( const XubString
&rErgo
);
371 const SwDropPortion
*FindDropPortion() const;
374 DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion
)
377 /*************************************************************************
378 * Inline-Implementierungen
379 *************************************************************************/
381 inline void SwLineLayout::ResetFlags()
383 bFormatAdj
= bDummy
= bFntChg
= bTab
= bEndHyph
= bMidHyph
= bFly
384 = bRest
= bBlinking
= bClipping
= bContent
= bRedline
385 = bForcedLeftMargin
= bHanging
= sal_False
;
388 inline SwLineLayout::SwLineLayout()
389 : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
390 bUnderscore( sal_False
)
393 SetWhichPor( POR_LAY
);
396 inline void SwParaPortion::ResetPreps()
398 bPrep
= bPrepWidows
= bPrepAdjust
= bPrepMustFit
= sal_False
;
401 inline void SwParaPortion::FormatReset()
404 aReformat
= SwCharRange( 0, STRING_LEN
);
405 // AMA 9916: bFlys muss in SwTxtFrm::_Format() erhalten bleiben, damit
406 // leere Absaetze, die Rahmen ohne Umfluss ausweichen mussten, sich
407 // neu formatieren, wenn der Rahmen aus dem Bereich verschwindet.
408 // bFlys = sal_False;
410 bFollowField
= bFixLineHeight
= bMargin
= sal_False
;
414 // C30 ist mit dem ternaeren Ausdruck ueberfordert.
415 inline SwLinePortion
*SwLineLayout::GetFirstPortion() const
417 SwLinePortion
*pTmp
= pPortion
;
419 pTmp
= (SwLinePortion
*)this;
423 inline SwLinePortion
*SwLineLayout::GetFirstPortion() const
424 { return( pPortion
? pPortion
: (SwLinePortion
*)this ); }
427 CLASSIO( SwLineLayout
)
428 CLASSIO( SwParaPortion
)