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 INCLUDED_SW_SOURCE_CORE_TEXT_PORLAY_HXX
20 : #define INCLUDED_SW_SOURCE_CORE_TEXT_PORLAY_HXX
21 :
22 : #include <tools/fract.hxx>
23 : #include <scriptinfo.hxx>
24 :
25 : #include "swrect.hxx"
26 : #include "portxt.hxx"
27 : #include "swfont.hxx"
28 :
29 : #include <vector>
30 : #include <deque>
31 :
32 : class SwMarginPortion;
33 : class SwDropPortion;
34 : class SvStream;
35 : class SwTxtFormatter;
36 :
37 : class SwCharRange
38 : {
39 : sal_Int32 nStart, nLen;
40 : public:
41 305364 : inline SwCharRange( const sal_Int32 nInitStart = 0,
42 305364 : const sal_Int32 nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
43 203718 : inline sal_Int32 &Start() { return nStart; }
44 328849 : inline const sal_Int32 &Start() const { return nStart; }
45 136772 : inline void LeftMove( sal_Int32 nNew )
46 136772 : { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
47 : inline sal_Int32 End() const
48 : { return nStart + nLen; }
49 322990 : inline sal_Int32 &Len() { return nLen; }
50 12839 : inline const sal_Int32 &Len() const { return nLen; }
51 20189 : inline bool operator<(const SwCharRange &rRange) const
52 20189 : { return nStart < rRange.nStart; }
53 19941 : inline bool operator>(const SwCharRange &rRange) const
54 19941 : { return nStart + nLen > rRange.nStart + rRange.nLen; }
55 20189 : inline bool operator!=(const SwCharRange &rRange) const
56 20189 : { return *this < rRange || *this > rRange; }
57 : SwCharRange &operator+=(const SwCharRange &rRange);
58 : };
59 :
60 : // SwRepaint is a document-global SwRect
61 : // nOfst states from where in the first line should be painted
62 : // nRightOfst gives the right margin
63 134 : class SwRepaint : public SwRect
64 : {
65 : SwTwips nOfst;
66 : SwTwips nRightOfst;
67 : public:
68 76601 : SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
69 134 : SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
70 134 : nRightOfst( rRep.nRightOfst ) {}
71 :
72 590429 : SwTwips GetOfst() const { return nOfst; }
73 626769 : void SetOfst( const SwTwips nNew ) { nOfst = nNew; }
74 145508 : SwTwips GetRightOfst() const { return nRightOfst; }
75 171842 : void SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
76 : };
77 :
78 : /// Collection of SwLinePortion instances, representing one line of text
79 : class SwLineLayout : public SwTxtPortion
80 : {
81 : private:
82 : SwLineLayout *pNext; // The next Line
83 : std::vector<long>* pLLSpaceAdd; // Used for justified alignment
84 : std::deque<sal_uInt16>* pKanaComp; // Used for Kana compression
85 : sal_uInt16 nRealHeight; // The height resulting from line spacing and register
86 : bool bFormatAdj : 1;
87 : bool bDummy : 1;
88 : bool bFntChg : 1;
89 : bool bEndHyph : 1;
90 : bool bMidHyph : 1;
91 : bool bTab : 1;
92 : bool bFly : 1;
93 : bool bRest : 1;
94 : bool bBlinking : 1;
95 : bool bClipping : 1; // Clipping needed for exact line height
96 : bool bContent : 1; // Text for line numbering
97 : bool bRedline : 1; // The Redlining
98 : bool bForcedLeftMargin : 1; // Left adjustment moved by the Fly
99 : bool bHanging : 1; // Contains a hanging portion in the margin
100 : bool bUnderscore : 1;
101 :
102 : SwTwips _GetHangingMargin() const;
103 :
104 : public:
105 : // From SwLinePortion
106 : virtual SwLinePortion *Insert( SwLinePortion *pPortion ) SAL_OVERRIDE;
107 : virtual SwLinePortion *Append( SwLinePortion *pPortion ) SAL_OVERRIDE;
108 : inline SwLinePortion *GetFirstPortion() const;
109 :
110 : // Flags
111 : inline void ResetFlags();
112 33394 : inline void SetFormatAdj( const bool bNew ) { bFormatAdj = bNew; }
113 163797 : inline bool IsFormatAdj() const { return bFormatAdj; }
114 : inline void SetFntChg( const bool bNew ) { bFntChg = bNew; }
115 : inline bool IsFntChg() const { return bFntChg; }
116 136772 : inline void SetEndHyph( const bool bNew ) { bEndHyph = bNew; }
117 318454 : inline bool IsEndHyph() const { return bEndHyph; }
118 136772 : inline void SetMidHyph( const bool bNew ) { bMidHyph = bNew; }
119 136774 : inline bool IsMidHyph() const { return bMidHyph; }
120 : inline void SetTab( const bool bNew ) { bTab = bNew; }
121 : inline bool IsTab() const { return bTab; }
122 820 : inline void SetFly( const bool bNew ) { bFly = bNew; }
123 6586 : inline bool IsFly() const { return bFly; }
124 8380 : inline void SetRest( const bool bNew ) { bRest = bNew; }
125 106855 : inline bool IsRest() const { return bRest; }
126 12 : inline void SetBlinking( const bool bNew = true ) { bBlinking = bNew; }
127 25928 : inline bool IsBlinking() const { return bBlinking; }
128 180232 : inline void SetCntnt( const bool bNew = true ) { bContent = bNew; }
129 187866 : inline bool HasCntnt() const { return bContent; }
130 147384 : inline void SetRedline( const bool bNew = true ) { bRedline = bNew; }
131 2849 : inline bool HasRedline() const { return bRedline; }
132 0 : inline void SetForcedLeftMargin( const bool bNew = true ) { bForcedLeftMargin = bNew; }
133 66290 : inline bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
134 419775 : inline void SetHanging( const bool bNew = true ) { bHanging = bNew; }
135 : inline bool IsHanging() const { return bHanging; }
136 135619 : inline void SetUnderscore( const bool bNew = true ) { bUnderscore = bNew; }
137 147930 : inline bool HasUnderscore() const { return bUnderscore; }
138 :
139 : // Respecting empty dummy lines
140 147476 : inline void SetDummy( const bool bNew ) { bDummy = bNew; }
141 1235275 : inline bool IsDummy() const { return bDummy; }
142 :
143 183511 : inline void SetClipping( const bool bNew ) { bClipping = bNew; }
144 360031 : inline bool IsClipping() const { return bClipping; }
145 :
146 : inline SwLineLayout();
147 : virtual ~SwLineLayout();
148 :
149 2514445 : inline SwLineLayout *GetNext() { return pNext; }
150 593448 : inline const SwLineLayout *GetNext() const { return pNext; }
151 59127 : inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
152 :
153 : void Init( SwLinePortion *pNextPortion = NULL);
154 :
155 : // Collects the data for the line
156 : void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
157 :
158 371051 : inline void SetRealHeight( sal_uInt16 nNew ) { nRealHeight = nNew; }
159 2150008 : inline sal_uInt16 GetRealHeight() const { return nRealHeight; }
160 :
161 : // Creates the glue chain for short lines
162 : SwMarginPortion *CalcLeftMargin();
163 :
164 272391 : inline SwTwips GetHangingMargin() const
165 272391 : { return _GetHangingMargin(); }
166 :
167 : // For special treatment for empty lines
168 : virtual bool Format( SwTxtFormatInfo &rInf ) SAL_OVERRIDE;
169 :
170 : // Stuff for justified alignment
171 110223 : inline bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
172 : void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
173 : void CreateSpaceAdd( const long nInit = 0 );
174 165709 : inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
175 1822 : inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
176 1212 : inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
177 : {
178 1212 : if ( nIdx == GetLLSpaceAddCount() )
179 630 : pLLSpaceAdd->push_back( nNew );
180 : else
181 582 : (*pLLSpaceAdd)[ nIdx ] = nNew;
182 1212 : }
183 664 : inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
184 0 : inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
185 145242 : inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
186 :
187 : // Stuff for Kana compression
188 0 : inline void SetKanaComp( std::deque<sal_uInt16>* pNew ){ pKanaComp = pNew; }
189 165093 : inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
190 251649 : inline std::deque<sal_uInt16>* GetpKanaComp() const { return pKanaComp; }
191 0 : inline std::deque<sal_uInt16>& GetKanaComp() { return *pKanaComp; }
192 :
193 : /** determine ascent and descent for positioning of as-character anchored
194 : object
195 :
196 : OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
197 : Method calculates maximum ascents and descents of the line layout.
198 : One value considering as-character anchored objects, one without these
199 : objects.
200 : Portions for other anchored objects aren't considered.
201 : OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
202 : to control, if the fly content portions and line portion are considered.
203 :
204 : @param _orAscent
205 : output parameter - maximum ascent without as-character anchored objects
206 :
207 : @param _orDescent
208 : output parameter - maximum descent without as-character anchored objects
209 :
210 : @param _orObjAscent
211 : output parameter - maximum ascent with as-character anchored objects
212 :
213 : @param _orObjDescent
214 : output parameter - maximum descent with as-character anchored objects
215 :
216 : @param _pDontConsiderPortion
217 : input parameter - portion, which isn't considered for calculating
218 : <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
219 : as-character anchored object or it isn't as high as the line.
220 :
221 : @param _bNoFlyCntPorAndLinePor
222 : optional input parameter - boolean, indicating that fly content portions
223 : and the line portion are considered or not.
224 : */
225 : void MaxAscentDescent( SwTwips& _orAscent,
226 : SwTwips& _orDescent,
227 : SwTwips& _orObjAscent,
228 : SwTwips& _orObjDescent,
229 : const SwLinePortion* _pDontConsiderPortion = NULL,
230 : const bool _bNoFlyCntPorAndLinePor = false ) const;
231 :
232 : OUTPUT_OPERATOR_OVERRIDE
233 57936 : DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
234 : };
235 :
236 : /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
237 : class SwParaPortion : public SwLineLayout
238 : {
239 : // Area that needs repainting
240 : SwRepaint aRepaint;
241 : // Area that needs reformatting
242 : SwCharRange aReformat;
243 : SwScriptInfo aScriptInfo;
244 : // Fraction aZoom;
245 : long nDelta;
246 :
247 : // If a SwTxtFrm is locked, no changes occur to the formatting data (under
248 : // pLine) (compare with Orphans)
249 : bool bFlys : 1; // Overlapping Flys?
250 : bool bPrep : 1; // PREP_*
251 : bool bPrepWidows : 1; // PREP_WIDOWS
252 : bool bPrepAdjust : 1; // PREP_ADJUST_FRM
253 : bool bPrepMustFit : 1; // PREP_MUST_FIT
254 : bool bFollowField : 1; // We have a bit of field left for the Follow
255 :
256 : bool bFixLineHeight : 1; // Fixed line height
257 : bool bFtnNum : 1; // contains a footnotenumberportion
258 : bool bMargin : 1; // contains a hanging punctuation in the margin
259 :
260 : bool bFlag00 : 1;
261 : bool bFlag11 : 1;
262 : bool bFlag12 : 1;
263 : bool bFlag13 : 1;
264 : bool bFlag14 : 1;
265 : bool bFlag15 : 1;
266 : bool bFlag16 : 1;
267 :
268 : public:
269 : SwParaPortion();
270 : virtual ~SwParaPortion();
271 :
272 : // Resets all formatting information (except for bFlys)
273 : inline void FormatReset();
274 :
275 : // Resets the Flags
276 : inline void ResetPreps();
277 :
278 : // Get/Set methods
279 841836 : inline SwRepaint& GetRepaint() { return aRepaint; }
280 421781 : inline const SwRepaint& GetRepaint() const { return aRepaint; }
281 428053 : inline SwCharRange& GetReformat() { return aReformat; }
282 316010 : inline const SwCharRange& GetReformat() const { return aReformat; }
283 347180 : inline long& GetDelta() { return nDelta; }
284 : inline const long& GetDelta() const { return nDelta; }
285 878849 : inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
286 367220 : inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
287 :
288 : // For SwTxtFrm::Format: returns the paragraph's current length
289 : sal_Int32 GetParLen() const;
290 :
291 : // For Prepare()
292 : bool UpdateQuoVadis( const OUString &rQuo );
293 :
294 : // Flags
295 4754 : inline void SetFly( const bool bNew = true ) { bFlys = bNew; }
296 26168 : inline bool HasFly() const { return bFlys; }
297 :
298 : // Preps
299 29329 : inline void SetPrep( const bool bNew = true ) { bPrep = bNew; }
300 29268 : inline bool IsPrep() const { return bPrep; }
301 338 : inline void SetPrepWidows( const bool bNew = true ) { bPrepWidows = bNew; }
302 31422 : inline bool IsPrepWidows() const { return bPrepWidows; }
303 243823 : inline void SetPrepMustFit( const bool bNew = true ) { bPrepMustFit = bNew; }
304 228951 : inline bool IsPrepMustFit() const { return bPrepMustFit; }
305 20369 : inline void SetPrepAdjust( const bool bNew = true ) { bPrepAdjust = bNew; }
306 29268 : inline bool IsPrepAdjust() const { return bPrepAdjust; }
307 606 : inline void SetFollowField( const bool bNew = true ) { bFollowField = bNew; }
308 2081 : inline bool IsFollowField() const { return bFollowField; }
309 6346 : inline void SetFixLineHeight( const bool bNew = true ) { bFixLineHeight = bNew; }
310 2 : inline bool IsFixLineHeight() const { return bFixLineHeight; }
311 :
312 82954 : inline void SetFtnNum( const bool bNew = true ) { bFtnNum = bNew; }
313 17958 : inline bool IsFtnNum() const { return bFtnNum; }
314 0 : inline void SetMargin( const bool bNew = true ) { bMargin = bNew; }
315 127537 : inline bool IsMargin() const { return bMargin; }
316 : inline void SetFlag00( const bool bNew = true ) { bFlag00 = bNew; }
317 : inline bool IsFlag00() const { return bFlag00; }
318 : inline void SetFlag11( const bool bNew = true ) { bFlag11 = bNew; }
319 : inline bool IsFlag11() const { return bFlag11; }
320 : inline void SetFlag12( const bool bNew = true ) { bFlag12 = bNew; }
321 : inline bool IsFlag12() const { return bFlag12; }
322 : inline void SetFlag13( const bool bNew = true ) { bFlag13 = bNew; }
323 : inline bool IsFlag13() const { return bFlag13; }
324 : inline void SetFlag14( const bool bNew = true ) { bFlag14 = bNew; }
325 : inline bool IsFlag14() const { return bFlag14; }
326 : inline void SetFlag15( const bool bNew = true ) { bFlag15 = bNew; }
327 : inline bool IsFlag15() const { return bFlag15; }
328 : inline void SetFlag16( const bool bNew = true ) { bFlag16 = bNew; }
329 : inline bool IsFlag16() const { return bFlag16; }
330 :
331 : // Read/Write methods for the SWG filter
332 : SvStream &ReadSwg ( SvStream& rStream ); //$ istream
333 : SvStream &WriteSwg( SvStream& rStream ); //$ ostream
334 :
335 : // Set nErgo in the QuoVadisPortion
336 : void SetErgoSumNum( const OUString &rErgo );
337 :
338 : const SwDropPortion *FindDropPortion() const;
339 :
340 : #ifdef DBG_UTIL
341 : void dumpAsXml( xmlTextWriter* writer, SwTxtFrm* pTxtFrm );
342 : #endif
343 :
344 : OUTPUT_OPERATOR_OVERRIDE
345 153202 : DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
346 : };
347 :
348 271162 : inline void SwLineLayout::ResetFlags()
349 : {
350 : bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
351 : = bRest = bBlinking = bClipping = bContent = bRedline
352 271162 : = bForcedLeftMargin = bHanging = false;
353 271162 : }
354 :
355 106069 : inline SwLineLayout::SwLineLayout()
356 : : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
357 106069 : bUnderscore( false )
358 : {
359 106069 : ResetFlags();
360 106069 : SetWhichPor( POR_LAY );
361 106069 : }
362 :
363 128292 : inline void SwParaPortion::ResetPreps()
364 : {
365 128292 : bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = false;
366 128292 : }
367 :
368 98856 : inline void SwParaPortion::FormatReset()
369 : {
370 98856 : nDelta = 0;
371 98856 : aReformat = SwCharRange(0, COMPLETE_STRING);
372 : // bFlys needs to be retained in SwTxtFrm::_Format() so that empty
373 : // paragraphs that needed to avoid Frames with no flow, reformat
374 : // when the Frame disappears from the Area
375 : // bFlys = false;
376 98856 : ResetPreps();
377 98856 : bFollowField = bFixLineHeight = bMargin = false;
378 98856 : }
379 :
380 506325 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
381 506325 : { return( pPortion ? pPortion : (SwLinePortion*)this ); }
382 :
383 : #endif
384 :
385 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|