Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _PORLAY_HXX
29 : : #define _PORLAY_HXX
30 : :
31 : : #include <tools/string.hxx>
32 : : #include <tools/fract.hxx>
33 : : #include <scriptinfo.hxx>
34 : :
35 : : #include "swrect.hxx" // SwRepaint
36 : : #include "portxt.hxx"
37 : : #include "swfont.hxx"
38 : :
39 : : #include <vector>
40 : : #include <deque>
41 : :
42 : : class SwMarginPortion;
43 : : class SwDropPortion;
44 : : class SvStream;
45 : : class SwTxtFormatter;
46 : :
47 : : /*************************************************************************
48 : : * class SwCharRange
49 : : *************************************************************************/
50 : :
51 : : class SwCharRange
52 : : {
53 : : xub_StrLen nStart, nLen;
54 : : public:
55 : 39801 : inline SwCharRange( const xub_StrLen nInitStart = 0,
56 : 39801 : const xub_StrLen nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
57 : 73043 : inline xub_StrLen &Start() { return nStart; }
58 : 117043 : inline const xub_StrLen &Start() const { return nStart; }
59 : 52762 : inline void LeftMove( xub_StrLen nNew )
60 [ + + ]: 52762 : { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
61 : : inline xub_StrLen End() const
62 : : { return nStart + nLen; }
63 : 91842 : inline xub_StrLen &Len() { return nLen; }
64 : 2938 : inline const xub_StrLen &Len() const { return nLen; }
65 : 11370 : inline sal_Bool operator<(const SwCharRange &rRange) const
66 : 11370 : { return nStart < rRange.nStart; }
67 : 11360 : inline sal_Bool operator>(const SwCharRange &rRange) const
68 : 11360 : { return nStart + nLen > rRange.nStart + rRange.nLen; }
69 : 11370 : inline sal_Bool operator!=(const SwCharRange &rRange) const
70 [ + + ][ + + ]: 11370 : { return *this < rRange || *this > rRange; }
71 : : SwCharRange &operator+=(const SwCharRange &rRange);
72 : : };
73 : :
74 : : /*************************************************************************
75 : : * class SwRepaint
76 : : *************************************************************************/
77 : :
78 : : // SwRepaint is a document-global SwRect
79 : : // nOfst states from where in the first line should be painted
80 : : // nRightOfst gives the right margin
81 : 70 : class SwRepaint : public SwRect
82 : : {
83 : : SwTwips nOfst;
84 : : SwTwips nRightOfst;
85 : : public:
86 : 5091 : SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
87 : 70 : SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
88 : 70 : nRightOfst( rRep.nRightOfst ) {}
89 : :
90 : 203230 : SwTwips GetOfst() const { return nOfst; }
91 : 190459 : void SetOfst( const SwTwips nNew ) { nOfst = nNew; }
92 : 60869 : SwTwips GetRightOfst() const { return nRightOfst; }
93 : 31898 : void SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
94 : : };
95 : :
96 : :
97 : : /// Collection of SwLinePortion instances, representing one line of text.
98 : : class SwLineLayout : public SwTxtPortion
99 : : {
100 : : private:
101 : : SwLineLayout *pNext; // The next Line
102 : : std::vector<long>* pLLSpaceAdd; // Used for justified alignment.
103 : : std::deque<sal_uInt16>* pKanaComp; // Used for Kana compression.
104 : : KSHORT nRealHeight; // The height resulting from line spacing and register
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 needed for exact line height
115 : : sal_Bool bContent : 1; // Text for line numbering
116 : : sal_Bool bRedline : 1; // The Redlining
117 : : sal_Bool bForcedLeftMargin : 1; // Left adjustment moved by the Fly
118 : : sal_Bool bHanging : 1; // Contains a hanging portion in the margin
119 : : sal_Bool bUnderscore : 1;
120 : :
121 : : SwTwips _GetHangingMargin() const;
122 : :
123 : : public:
124 : : // From 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 : 1838 : inline void SetFormatAdj( const sal_Bool bNew ) { bFormatAdj = bNew; }
132 : 85113 : 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 : 52762 : inline void SetEndHyph( const sal_Bool bNew ) { bEndHyph = bNew; }
136 : 132290 : inline sal_Bool IsEndHyph() const { return bEndHyph; }
137 : 52762 : inline void SetMidHyph( const sal_Bool bNew ) { bMidHyph = bNew; }
138 : 52765 : 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 : 119 : inline void SetFly( const sal_Bool bNew ) { bFly = bNew; }
142 : 6422 : inline sal_Bool IsFly() const { return bFly; }
143 : 510 : inline void SetRest( const sal_Bool bNew ) { bRest = bNew; }
144 : 76360 : inline sal_Bool IsRest() const { return bRest; }
145 : 12 : inline void SetBlinking( const sal_Bool bNew = sal_True ) { bBlinking = bNew; }
146 : 4320 : inline sal_Bool IsBlinking() const { return bBlinking; }
147 : 59087 : inline void SetCntnt( const sal_Bool bNew = sal_True ) { bContent = bNew; }
148 : 13669 : inline sal_Bool HasCntnt() const { return bContent; }
149 : 55335 : inline void SetRedline( const sal_Bool bNew = sal_True ) { bRedline = bNew; }
150 : 26 : inline sal_Bool HasRedline() const { return bRedline; }
151 : 0 : inline void SetForcedLeftMargin( const sal_Bool bNew = sal_True ) { bForcedLeftMargin = bNew; }
152 : 3027 : inline sal_Bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
153 : 159647 : inline void SetHanging( const sal_Bool bNew = sal_True ) { bHanging = bNew; }
154 : : inline sal_Bool IsHanging() const { return bHanging; }
155 : 51550 : inline void SetUnderscore( const sal_Bool bNew = sal_True ) { bUnderscore = bNew; }
156 : 60648 : inline sal_Bool HasUnderscore() const { return bUnderscore; }
157 : :
158 : : // Respecting empty dummy lines
159 : 55349 : inline void SetDummy( const sal_Bool bNew ) { bDummy = bNew; }
160 : 250941 : inline sal_Bool IsDummy() const { return bDummy; }
161 : :
162 : 54963 : inline void SetClipping( const sal_Bool bNew ) { bClipping = bNew; }
163 : 164342 : inline sal_Bool IsClipping() const { return bClipping; }
164 : :
165 : : inline SwLineLayout();
166 : : virtual ~SwLineLayout();
167 : :
168 : 2102991 : inline SwLineLayout *GetNext() { return pNext; }
169 : 308073 : inline const SwLineLayout *GetNext() const { return pNext; }
170 : 15123 : inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
171 : :
172 : : void Init( SwLinePortion *pNextPortion = NULL);
173 : :
174 : : // Collects the data for the line
175 : : void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
176 : :
177 : 115669 : inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
178 : 1378247 : inline KSHORT GetRealHeight() const { return nRealHeight; }
179 : :
180 : : // Creates the glue chain for short lines
181 : : SwMarginPortion *CalcLeftMargin();
182 : :
183 : 104312 : inline SwTwips GetHangingMargin() const
184 : 104312 : { return _GetHangingMargin(); }
185 : :
186 : : // For special treatment for empty lines
187 : : virtual sal_Bool Format( SwTxtFormatInfo &rInf );
188 : :
189 : : //
190 : : // STUFF FOR JUSTIFIED ALIGNMENT
191 : : //
192 : 54794 : inline sal_Bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
193 : : void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
194 : : void CreateSpaceAdd( const long nInit = 0 );
195 [ - + ]: 55176 : inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
196 : 40 : inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
197 : 20 : inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
198 : : {
199 [ + - ]: 20 : if ( nIdx == GetLLSpaceAddCount() )
200 : 20 : pLLSpaceAdd->push_back( nNew );
201 : : else
202 : 0 : (*pLLSpaceAdd)[ nIdx ] = nNew;
203 : 20 : }
204 : 50 : inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
205 : 0 : inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
206 : 42765 : inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
207 : :
208 : : //
209 : : // STUFF FOR KANA COMPRESSION
210 : : //
211 : 0 : inline void SetKanaComp( std::deque<sal_uInt16>* pNew ){ pKanaComp = pNew; }
212 [ - + ]: 55176 : inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
213 : 96286 : inline std::deque<sal_uInt16>* GetpKanaComp() const { return pKanaComp; }
214 : 0 : inline std::deque<sal_uInt16>& GetKanaComp() { return *pKanaComp; }
215 : :
216 : : /** determine ascent and descent for positioning of as-character anchored
217 : : object
218 : :
219 : : OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
220 : : Method calculates maximum ascents and descents of the line layout.
221 : : One value considering as-character anchored objects, one without these
222 : : objects.
223 : : Portions for other anchored objects aren't considered.
224 : : OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
225 : : to control, if the fly content portions and line portion are considered.
226 : :
227 : : @param _orAscent
228 : : output parameter - maximum ascent without as-character anchored objects
229 : :
230 : : @param _orDescent
231 : : output parameter - maximum descent without as-character anchored objects
232 : :
233 : : @param _orObjAscent
234 : : output parameter - maximum ascent with as-character anchored objects
235 : :
236 : : @param _orObjDescent
237 : : output parameter - maximum descent with as-character anchored objects
238 : :
239 : : @param _pDontConsiderPortion
240 : : input parameter - portion, which isn't considered for calculating
241 : : <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
242 : : as-character anchored object or it isn't as high as the line.
243 : :
244 : : @param _bNoFlyCntPorAndLinePor
245 : : optional input parameter - boolean, indicating that fly content portions
246 : : and the line portion are considered or not.
247 : :
248 : : @author OD
249 : : */
250 : : void MaxAscentDescent( SwTwips& _orAscent,
251 : : SwTwips& _orDescent,
252 : : SwTwips& _orObjAscent,
253 : : SwTwips& _orObjDescent,
254 : : const SwLinePortion* _pDontConsiderPortion = NULL,
255 : : const bool _bNoFlyCntPorAndLinePor = false ) const;
256 : :
257 : : OUTPUT_OPERATOR
258 [ + - ][ + - ]: 14764 : DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
259 : : };
260 : :
261 : : /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
262 : : class SwParaPortion : public SwLineLayout
263 : : {
264 : : // Area that needs repainting
265 : : SwRepaint aRepaint;
266 : : // Area that needs reformatting
267 : : SwCharRange aReformat;
268 : : SwScriptInfo aScriptInfo;
269 : : // Fraction aZoom;
270 : : long nDelta;
271 : :
272 : : // If a SwTxtFrm is locked, no changes occur to the formatting data (under
273 : : // pLine) (compare with Orphans)
274 : : sal_Bool bFlys : 1; // Overlapping Flys?
275 : : sal_Bool bPrep : 1; // PREP_*
276 : : sal_Bool bPrepWidows : 1; // PREP_WIDOWS
277 : : sal_Bool bPrepAdjust : 1; // PREP_ADJUST_FRM
278 : : sal_Bool bPrepMustFit : 1; // PREP_MUST_FIT
279 : : sal_Bool bFollowField : 1; // We have a bit of field left for the Follow
280 : :
281 : : sal_Bool bFixLineHeight : 1; // Fixed line height
282 : : sal_Bool bFtnNum : 1; // contains a footnotenumberportion
283 : : sal_Bool bMargin : 1; // contains a hanging punctuation in the margin
284 : :
285 : : sal_Bool bFlag00 : 1;
286 : : sal_Bool bFlag11 : 1;
287 : : sal_Bool bFlag12 : 1;
288 : : sal_Bool bFlag13 : 1;
289 : : sal_Bool bFlag14 : 1;
290 : : sal_Bool bFlag15 : 1;
291 : : sal_Bool bFlag16 : 1;
292 : :
293 : : public:
294 : : SwParaPortion();
295 : : virtual ~SwParaPortion();
296 : :
297 : : // Resets all formatting information (except for bFlys)
298 : : inline void FormatReset();
299 : :
300 : : // Resets the Flags
301 : : inline void ResetPreps();
302 : :
303 : : // Get/Set methods
304 : 262204 : inline SwRepaint *GetRepaint() { return &aRepaint; }
305 : 114487 : inline const SwRepaint *GetRepaint() const { return &aRepaint; }
306 : 175579 : inline SwCharRange *GetReformat() { return &aReformat; }
307 : 114105 : inline const SwCharRange *GetReformat() const { return &aReformat; }
308 : 114626 : inline long *GetDelta() { return &nDelta; }
309 : : inline const long *GetDelta() const { return &nDelta; }
310 : 293698 : inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
311 : 109474 : inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
312 : :
313 : : // For SwTxtFrm::Format: returns the paragraph's current length
314 : : xub_StrLen GetParLen() const;
315 : :
316 : : // For Prepare()
317 : : sal_Bool UpdateQuoVadis( const XubString &rQuo );
318 : :
319 : : // Flags
320 : 1385 : inline void SetFly( const sal_Bool bNew = sal_True ) { bFlys = bNew; }
321 : 2309 : inline sal_Bool HasFly() const { return bFlys; }
322 : :
323 : : // Preps
324 : 1545 : inline void SetPrep( const sal_Bool bNew = sal_True ) { bPrep = bNew; }
325 : 10306 : inline sal_Bool IsPrep() const { return bPrep; }
326 : 0 : inline void SetPrepWidows( const sal_Bool bNew = sal_True ) { bPrepWidows = bNew; }
327 : 10930 : inline sal_Bool IsPrepWidows() const { return bPrepWidows; }
328 : 42141 : inline void SetPrepMustFit( const sal_Bool bNew = sal_True ) { bPrepMustFit = bNew; }
329 : 41352 : inline sal_Bool IsPrepMustFit() const { return bPrepMustFit; }
330 : 1333 : inline void SetPrepAdjust( const sal_Bool bNew = sal_True ) { bPrepAdjust = bNew; }
331 : 10306 : inline sal_Bool IsPrepAdjust() const { return bPrepAdjust; }
332 : 4 : inline void SetFollowField( const sal_Bool bNew = sal_True ) { bFollowField = bNew; }
333 : 692 : inline sal_Bool IsFollowField() const { return bFollowField; }
334 : 0 : inline void SetFixLineHeight( const sal_Bool bNew = sal_True ) { bFixLineHeight = bNew; }
335 : 0 : inline sal_Bool IsFixLineHeight() const { return bFixLineHeight; }
336 : :
337 : 10651 : inline void SetFtnNum( const sal_Bool bNew = sal_True ) { bFtnNum = bNew; }
338 : 500 : inline sal_Bool IsFtnNum() const { return bFtnNum; }
339 : 0 : inline void SetMargin( const sal_Bool bNew = sal_True ) { bMargin = bNew; }
340 : 42341 : inline sal_Bool IsMargin() const { return bMargin; }
341 : : inline void SetFlag00( const sal_Bool bNew = sal_True ) { bFlag00 = bNew; }
342 : : inline sal_Bool IsFlag00() const { return bFlag00; }
343 : : inline void SetFlag11( const sal_Bool bNew = sal_True ) { bFlag11 = bNew; }
344 : : inline sal_Bool IsFlag11() const { return bFlag11; }
345 : : inline void SetFlag12( const sal_Bool bNew = sal_True ) { bFlag12 = bNew; }
346 : : inline sal_Bool IsFlag12() const { return bFlag12; }
347 : : inline void SetFlag13( const sal_Bool bNew = sal_True ) { bFlag13 = bNew; }
348 : : inline sal_Bool IsFlag13() const { return bFlag13; }
349 : : inline void SetFlag14( const sal_Bool bNew = sal_True ) { bFlag14 = bNew; }
350 : : inline sal_Bool IsFlag14() const { return bFlag14; }
351 : : inline void SetFlag15( const sal_Bool bNew = sal_True ) { bFlag15 = bNew; }
352 : : inline sal_Bool IsFlag15() const { return bFlag15; }
353 : : inline void SetFlag16( const sal_Bool bNew = sal_True ) { bFlag16 = bNew; }
354 : : inline sal_Bool IsFlag16() const { return bFlag16; }
355 : :
356 : : // Read/Write methods for the SWG filter
357 : : SvStream &ReadSwg ( SvStream& rStream ); //$ istream
358 : : SvStream &WriteSwg( SvStream& rStream ); //$ ostream
359 : :
360 : : // Set nErgo in the QuoVadisPortion
361 : : void SetErgoSumNum( const XubString &rErgo );
362 : :
363 : : const SwDropPortion *FindDropPortion() const;
364 : :
365 : : #ifdef DBG_UTIL
366 : : void dumpAsXml( xmlTextWriter* writer, SwTxtFrm* pTxtFrm );
367 : : #endif
368 : :
369 : : OUTPUT_OPERATOR
370 [ + - ][ + - ]: 10182 : DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
371 : : };
372 : :
373 : : /*************************************************************************
374 : : * Inline implementations
375 : : *************************************************************************/
376 : :
377 : 68005 : inline void SwLineLayout::ResetFlags()
378 : : {
379 : : bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
380 : : = bRest = bBlinking = bClipping = bContent = bRedline
381 : 68005 : = bForcedLeftMargin = bHanging = sal_False;
382 : 68005 : }
383 : :
384 : 12829 : inline SwLineLayout::SwLineLayout()
385 : : : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
386 : 12829 : bUnderscore( sal_False )
387 : : {
388 : 12829 : ResetFlags();
389 : 12829 : SetWhichPor( POR_LAY );
390 : 12829 : }
391 : :
392 : 17274 : inline void SwParaPortion::ResetPreps()
393 : : {
394 : 17274 : bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = sal_False;
395 : 17274 : }
396 : :
397 : 6899 : inline void SwParaPortion::FormatReset()
398 : : {
399 : 6899 : nDelta = 0;
400 : 6899 : aReformat = SwCharRange( 0, STRING_LEN );
401 : : // bFlys needs to be retained in SwTxtFrm::_Format() so that empty
402 : : // paragraphs that needed to avoid Frames with no flow, reformat
403 : : // when the Frame disappears from the Area
404 : : // bFlys = sal_False;
405 : 6899 : ResetPreps();
406 : 6899 : bFollowField = bFixLineHeight = bMargin = sal_False;
407 : 6899 : }
408 : :
409 : : #ifdef UNX
410 : : // The ternary expression is too much for the C30
411 : 180630 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
412 : : {
413 : 180630 : SwLinePortion *pTmp = pPortion;
414 [ + + ]: 180630 : if ( !pPortion )
415 : 139929 : pTmp = (SwLinePortion*)this;
416 : 180630 : return( pTmp );
417 : : }
418 : : #else
419 : : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
420 : : { return( pPortion ? pPortion : (SwLinePortion*)this ); }
421 : : #endif
422 : :
423 : : CLASSIO( SwLineLayout )
424 : : CLASSIO( SwParaPortion )
425 : :
426 : : #endif
427 : :
428 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|