Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #ifndef _PORLAY_HXX
20 : #define _PORLAY_HXX
21 :
22 : #include <tools/string.hxx>
23 : #include <tools/fract.hxx>
24 : #include <scriptinfo.hxx>
25 :
26 : #include "swrect.hxx" // SwRepaint
27 : #include "portxt.hxx"
28 : #include "swfont.hxx"
29 :
30 : #include <vector>
31 : #include <deque>
32 :
33 : class SwMarginPortion;
34 : class SwDropPortion;
35 : class SvStream;
36 : class SwTxtFormatter;
37 :
38 : /*************************************************************************
39 : * class SwCharRange
40 : *************************************************************************/
41 :
42 : class SwCharRange
43 : {
44 : xub_StrLen nStart, nLen;
45 : public:
46 2486 : inline SwCharRange( const xub_StrLen nInitStart = 0,
47 2486 : const xub_StrLen nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
48 1286 : inline xub_StrLen &Start() { return nStart; }
49 1897 : inline const xub_StrLen &Start() const { return nStart; }
50 724 : inline void LeftMove( xub_StrLen nNew )
51 724 : { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
52 : inline xub_StrLen End() const
53 : { return nStart + nLen; }
54 2231 : inline xub_StrLen &Len() { return nLen; }
55 418 : inline const xub_StrLen &Len() const { return nLen; }
56 419 : inline bool operator<(const SwCharRange &rRange) const
57 419 : { return nStart < rRange.nStart; }
58 419 : inline bool operator>(const SwCharRange &rRange) const
59 419 : { return nStart + nLen > rRange.nStart + rRange.nLen; }
60 419 : inline bool operator!=(const SwCharRange &rRange) const
61 419 : { return *this < rRange || *this > rRange; }
62 : SwCharRange &operator+=(const SwCharRange &rRange);
63 : };
64 :
65 : /*************************************************************************
66 : * class SwRepaint
67 : *************************************************************************/
68 :
69 : // SwRepaint is a document-global SwRect
70 : // nOfst states from where in the first line should be painted
71 : // nRightOfst gives the right margin
72 0 : class SwRepaint : public SwRect
73 : {
74 : SwTwips nOfst;
75 : SwTwips nRightOfst;
76 : public:
77 662 : SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
78 0 : SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
79 0 : nRightOfst( rRep.nRightOfst ) {}
80 :
81 3216 : SwTwips GetOfst() const { return nOfst; }
82 4076 : void SetOfst( const SwTwips nNew ) { nOfst = nNew; }
83 734 : SwTwips GetRightOfst() const { return nRightOfst; }
84 1299 : void SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
85 : };
86 :
87 :
88 : /// Collection of SwLinePortion instances, representing one line of text.
89 : class SwLineLayout : public SwTxtPortion
90 : {
91 : private:
92 : SwLineLayout *pNext; // The next Line
93 : std::vector<long>* pLLSpaceAdd; // Used for justified alignment.
94 : std::deque<sal_uInt16>* pKanaComp; // Used for Kana compression.
95 : KSHORT nRealHeight; // The height resulting from line spacing and register
96 : sal_Bool bFormatAdj : 1;
97 : sal_Bool bDummy : 1;
98 : sal_Bool bFntChg : 1;
99 : sal_Bool bEndHyph : 1;
100 : sal_Bool bMidHyph : 1;
101 : sal_Bool bTab : 1;
102 : sal_Bool bFly : 1;
103 : sal_Bool bRest : 1;
104 : sal_Bool bBlinking : 1;
105 : sal_Bool bClipping : 1; // Clipping needed for exact line height
106 : sal_Bool bContent : 1; // Text for line numbering
107 : sal_Bool bRedline : 1; // The Redlining
108 : sal_Bool bForcedLeftMargin : 1; // Left adjustment moved by the Fly
109 : sal_Bool bHanging : 1; // Contains a hanging portion in the margin
110 : sal_Bool bUnderscore : 1;
111 :
112 : SwTwips _GetHangingMargin() const;
113 :
114 : public:
115 : // From SwLinePortion
116 : virtual SwLinePortion *Insert( SwLinePortion *pPortion );
117 : virtual SwLinePortion *Append( SwLinePortion *pPortion );
118 : inline SwLinePortion *GetFirstPortion() const;
119 :
120 : // Flags
121 : inline void ResetFlags();
122 68 : inline void SetFormatAdj( const sal_Bool bNew ) { bFormatAdj = bNew; }
123 2776 : inline sal_Bool IsFormatAdj() const { return bFormatAdj; }
124 : inline void SetFntChg( const sal_Bool bNew ) { bFntChg = bNew; }
125 : inline sal_Bool IsFntChg() const { return bFntChg; }
126 724 : inline void SetEndHyph( const sal_Bool bNew ) { bEndHyph = bNew; }
127 1534 : inline sal_Bool IsEndHyph() const { return bEndHyph; }
128 724 : inline void SetMidHyph( const sal_Bool bNew ) { bMidHyph = bNew; }
129 724 : inline sal_Bool IsMidHyph() const { return bMidHyph; }
130 : inline void SetTab( const sal_Bool bNew ) { bTab = bNew; }
131 : inline sal_Bool IsTab() const { return bTab; }
132 8 : inline void SetFly( const sal_Bool bNew ) { bFly = bNew; }
133 0 : inline sal_Bool IsFly() const { return bFly; }
134 58 : inline void SetRest( const sal_Bool bNew ) { bRest = bNew; }
135 593 : inline sal_Bool IsRest() const { return bRest; }
136 0 : inline void SetBlinking( const sal_Bool bNew = sal_True ) { bBlinking = bNew; }
137 45 : inline sal_Bool IsBlinking() const { return bBlinking; }
138 998 : inline void SetCntnt( const sal_Bool bNew = sal_True ) { bContent = bNew; }
139 860 : inline sal_Bool HasCntnt() const { return bContent; }
140 885 : inline void SetRedline( const sal_Bool bNew = sal_True ) { bRedline = bNew; }
141 3 : inline sal_Bool HasRedline() const { return bRedline; }
142 0 : inline void SetForcedLeftMargin( const sal_Bool bNew = sal_True ) { bForcedLeftMargin = bNew; }
143 414 : inline sal_Bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
144 2333 : inline void SetHanging( const sal_Bool bNew = sal_True ) { bHanging = bNew; }
145 : inline sal_Bool IsHanging() const { return bHanging; }
146 724 : inline void SetUnderscore( const sal_Bool bNew = sal_True ) { bUnderscore = bNew; }
147 792 : inline sal_Bool HasUnderscore() const { return bUnderscore; }
148 :
149 : // Respecting empty dummy lines
150 887 : inline void SetDummy( const sal_Bool bNew ) { bDummy = bNew; }
151 11857 : inline sal_Bool IsDummy() const { return bDummy; }
152 :
153 993 : inline void SetClipping( const sal_Bool bNew ) { bClipping = bNew; }
154 2472 : inline sal_Bool IsClipping() const { return bClipping; }
155 :
156 : inline SwLineLayout();
157 : virtual ~SwLineLayout();
158 :
159 5195 : inline SwLineLayout *GetNext() { return pNext; }
160 2600 : inline const SwLineLayout *GetNext() const { return pNext; }
161 162 : inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
162 :
163 : void Init( SwLinePortion *pNextPortion = NULL);
164 :
165 : // Collects the data for the line
166 : void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
167 :
168 2127 : inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
169 10480 : inline KSHORT GetRealHeight() const { return nRealHeight; }
170 :
171 : // Creates the glue chain for short lines
172 : SwMarginPortion *CalcLeftMargin();
173 :
174 1448 : inline SwTwips GetHangingMargin() const
175 1448 : { return _GetHangingMargin(); }
176 :
177 : // For special treatment for empty lines
178 : virtual sal_Bool Format( SwTxtFormatInfo &rInf );
179 :
180 : //
181 : // STUFF FOR JUSTIFIED ALIGNMENT
182 : //
183 2147 : inline bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
184 : void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
185 : void CreateSpaceAdd( const long nInit = 0 );
186 834 : inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
187 6 : inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
188 4 : inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
189 : {
190 4 : if ( nIdx == GetLLSpaceAddCount() )
191 2 : pLLSpaceAdd->push_back( nNew );
192 : else
193 2 : (*pLLSpaceAdd)[ nIdx ] = nNew;
194 4 : }
195 2 : inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
196 0 : inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
197 1225 : inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
198 :
199 : //
200 : // STUFF FOR KANA COMPRESSION
201 : //
202 0 : inline void SetKanaComp( std::deque<sal_uInt16>* pNew ){ pKanaComp = pNew; }
203 831 : inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
204 3316 : inline std::deque<sal_uInt16>* GetpKanaComp() const { return pKanaComp; }
205 0 : inline std::deque<sal_uInt16>& GetKanaComp() { return *pKanaComp; }
206 :
207 : /** determine ascent and descent for positioning of as-character anchored
208 : object
209 :
210 : OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
211 : Method calculates maximum ascents and descents of the line layout.
212 : One value considering as-character anchored objects, one without these
213 : objects.
214 : Portions for other anchored objects aren't considered.
215 : OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
216 : to control, if the fly content portions and line portion are considered.
217 :
218 : @param _orAscent
219 : output parameter - maximum ascent without as-character anchored objects
220 :
221 : @param _orDescent
222 : output parameter - maximum descent without as-character anchored objects
223 :
224 : @param _orObjAscent
225 : output parameter - maximum ascent with as-character anchored objects
226 :
227 : @param _orObjDescent
228 : output parameter - maximum descent with as-character anchored objects
229 :
230 : @param _pDontConsiderPortion
231 : input parameter - portion, which isn't considered for calculating
232 : <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
233 : as-character anchored object or it isn't as high as the line.
234 :
235 : @param _bNoFlyCntPorAndLinePor
236 : optional input parameter - boolean, indicating that fly content portions
237 : and the line portion are considered or not.
238 :
239 : @author OD
240 : */
241 : void MaxAscentDescent( SwTwips& _orAscent,
242 : SwTwips& _orDescent,
243 : SwTwips& _orObjAscent,
244 : SwTwips& _orObjDescent,
245 : const SwLinePortion* _pDontConsiderPortion = NULL,
246 : const bool _bNoFlyCntPorAndLinePor = false ) const;
247 :
248 : OUTPUT_OPERATOR
249 162 : DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
250 : };
251 :
252 : /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
253 : class SwParaPortion : public SwLineLayout
254 : {
255 : // Area that needs repainting
256 : SwRepaint aRepaint;
257 : // Area that needs reformatting
258 : SwCharRange aReformat;
259 : SwScriptInfo aScriptInfo;
260 : // Fraction aZoom;
261 : long nDelta;
262 :
263 : // If a SwTxtFrm is locked, no changes occur to the formatting data (under
264 : // pLine) (compare with Orphans)
265 : sal_Bool bFlys : 1; // Overlapping Flys?
266 : sal_Bool bPrep : 1; // PREP_*
267 : sal_Bool bPrepWidows : 1; // PREP_WIDOWS
268 : sal_Bool bPrepAdjust : 1; // PREP_ADJUST_FRM
269 : sal_Bool bPrepMustFit : 1; // PREP_MUST_FIT
270 : sal_Bool bFollowField : 1; // We have a bit of field left for the Follow
271 :
272 : sal_Bool bFixLineHeight : 1; // Fixed line height
273 : sal_Bool bFtnNum : 1; // contains a footnotenumberportion
274 : sal_Bool bMargin : 1; // contains a hanging punctuation in the margin
275 :
276 : sal_Bool bFlag00 : 1;
277 : sal_Bool bFlag11 : 1;
278 : sal_Bool bFlag12 : 1;
279 : sal_Bool bFlag13 : 1;
280 : sal_Bool bFlag14 : 1;
281 : sal_Bool bFlag15 : 1;
282 : sal_Bool bFlag16 : 1;
283 :
284 : public:
285 : SwParaPortion();
286 : virtual ~SwParaPortion();
287 :
288 : // Resets all formatting information (except for bFlys)
289 : inline void FormatReset();
290 :
291 : // Resets the Flags
292 : inline void ResetPreps();
293 :
294 : // Get/Set methods
295 5702 : inline SwRepaint *GetRepaint() { return &aRepaint; }
296 1998 : inline const SwRepaint *GetRepaint() const { return &aRepaint; }
297 2613 : inline SwCharRange *GetReformat() { return &aReformat; }
298 1479 : inline const SwCharRange *GetReformat() const { return &aReformat; }
299 2082 : inline long *GetDelta() { return &nDelta; }
300 : inline const long *GetDelta() const { return &nDelta; }
301 7036 : inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
302 2987 : inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
303 :
304 : // For SwTxtFrm::Format: returns the paragraph's current length
305 : xub_StrLen GetParLen() const;
306 :
307 : // For Prepare()
308 : sal_Bool UpdateQuoVadis( const XubString &rQuo );
309 :
310 : // Flags
311 172 : inline void SetFly( const sal_Bool bNew = sal_True ) { bFlys = bNew; }
312 13 : inline sal_Bool HasFly() const { return bFlys; }
313 :
314 : // Preps
315 59 : inline void SetPrep( const sal_Bool bNew = sal_True ) { bPrep = bNew; }
316 153 : inline sal_Bool IsPrep() const { return bPrep; }
317 0 : inline void SetPrepWidows( const sal_Bool bNew = sal_True ) { bPrepWidows = bNew; }
318 153 : inline sal_Bool IsPrepWidows() const { return bPrepWidows; }
319 1680 : inline void SetPrepMustFit( const sal_Bool bNew = sal_True ) { bPrepMustFit = bNew; }
320 1545 : inline sal_Bool IsPrepMustFit() const { return bPrepMustFit; }
321 44 : inline void SetPrepAdjust( const sal_Bool bNew = sal_True ) { bPrepAdjust = bNew; }
322 153 : inline sal_Bool IsPrepAdjust() const { return bPrepAdjust; }
323 0 : inline void SetFollowField( const sal_Bool bNew = sal_True ) { bFollowField = bNew; }
324 0 : inline sal_Bool IsFollowField() const { return bFollowField; }
325 8 : inline void SetFixLineHeight( const sal_Bool bNew = sal_True ) { bFixLineHeight = bNew; }
326 0 : inline sal_Bool IsFixLineHeight() const { return bFixLineHeight; }
327 :
328 673 : inline void SetFtnNum( const sal_Bool bNew = sal_True ) { bFtnNum = bNew; }
329 44 : inline sal_Bool IsFtnNum() const { return bFtnNum; }
330 0 : inline void SetMargin( const sal_Bool bNew = sal_True ) { bMargin = bNew; }
331 1234 : inline sal_Bool IsMargin() const { return bMargin; }
332 : inline void SetFlag00( const sal_Bool bNew = sal_True ) { bFlag00 = bNew; }
333 : inline sal_Bool IsFlag00() const { return bFlag00; }
334 : inline void SetFlag11( const sal_Bool bNew = sal_True ) { bFlag11 = bNew; }
335 : inline sal_Bool IsFlag11() const { return bFlag11; }
336 : inline void SetFlag12( const sal_Bool bNew = sal_True ) { bFlag12 = bNew; }
337 : inline sal_Bool IsFlag12() const { return bFlag12; }
338 : inline void SetFlag13( const sal_Bool bNew = sal_True ) { bFlag13 = bNew; }
339 : inline sal_Bool IsFlag13() const { return bFlag13; }
340 : inline void SetFlag14( const sal_Bool bNew = sal_True ) { bFlag14 = bNew; }
341 : inline sal_Bool IsFlag14() const { return bFlag14; }
342 : inline void SetFlag15( const sal_Bool bNew = sal_True ) { bFlag15 = bNew; }
343 : inline sal_Bool IsFlag15() const { return bFlag15; }
344 : inline void SetFlag16( const sal_Bool bNew = sal_True ) { bFlag16 = bNew; }
345 : inline sal_Bool IsFlag16() const { return bFlag16; }
346 :
347 : // Read/Write methods for the SWG filter
348 : SvStream &ReadSwg ( SvStream& rStream ); //$ istream
349 : SvStream &WriteSwg( SvStream& rStream ); //$ ostream
350 :
351 : // Set nErgo in the QuoVadisPortion
352 : void SetErgoSumNum( const XubString &rErgo );
353 :
354 : const SwDropPortion *FindDropPortion() const;
355 :
356 : #ifdef DBG_UTIL
357 : void dumpAsXml( xmlTextWriter* writer, SwTxtFrm* pTxtFrm );
358 : #endif
359 :
360 : OUTPUT_OPERATOR
361 1324 : DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
362 : };
363 :
364 : /*************************************************************************
365 : * Inline implementations
366 : *************************************************************************/
367 :
368 1575 : inline void SwLineLayout::ResetFlags()
369 : {
370 : bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
371 : = bRest = bBlinking = bClipping = bContent = bRedline
372 1575 : = bForcedLeftMargin = bHanging = sal_False;
373 1575 : }
374 :
375 744 : inline SwLineLayout::SwLineLayout()
376 : : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
377 744 : bUnderscore( sal_False )
378 : {
379 744 : ResetFlags();
380 744 : SetWhichPor( POR_LAY );
381 744 : }
382 :
383 896 : inline void SwParaPortion::ResetPreps()
384 : {
385 896 : bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = sal_False;
386 896 : }
387 :
388 738 : inline void SwParaPortion::FormatReset()
389 : {
390 738 : nDelta = 0;
391 738 : aReformat = SwCharRange( 0, STRING_LEN );
392 : // bFlys needs to be retained in SwTxtFrm::_Format() so that empty
393 : // paragraphs that needed to avoid Frames with no flow, reformat
394 : // when the Frame disappears from the Area
395 : // bFlys = sal_False;
396 738 : ResetPreps();
397 738 : bFollowField = bFixLineHeight = bMargin = sal_False;
398 738 : }
399 :
400 : #ifdef UNX
401 : // The ternary expression is too much for the C30
402 4748 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
403 : {
404 4748 : SwLinePortion *pTmp = pPortion;
405 4748 : if ( !pPortion )
406 2191 : pTmp = (SwLinePortion*)this;
407 4748 : return( pTmp );
408 : }
409 : #else
410 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
411 : { return( pPortion ? pPortion : (SwLinePortion*)this ); }
412 : #endif
413 :
414 : CLASSIO( SwLineLayout )
415 : CLASSIO( SwParaPortion )
416 :
417 : #endif
418 :
419 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|