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