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 SwTextFormatter;
36 :
37 : class SwCharRange
38 : {
39 : sal_Int32 nStart, nLen;
40 : public:
41 168553 : inline SwCharRange( const sal_Int32 nInitStart = 0,
42 168553 : const sal_Int32 nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
43 118972 : inline sal_Int32 &Start() { return nStart; }
44 188934 : inline const sal_Int32 &Start() const { return nStart; }
45 80170 : inline void LeftMove( sal_Int32 nNew )
46 80170 : { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
47 : inline sal_Int32 End() const
48 : { return nStart + nLen; }
49 186587 : inline sal_Int32 &Len() { return nLen; }
50 6668 : inline const sal_Int32 &Len() const { return nLen; }
51 11707 : inline bool operator<(const SwCharRange &rRange) const
52 11707 : { return nStart < rRange.nStart; }
53 11450 : inline bool operator>(const SwCharRange &rRange) const
54 11450 : { return nStart + nLen > rRange.nStart + rRange.nLen; }
55 11707 : inline bool operator!=(const SwCharRange &rRange) const
56 11707 : { 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 82 : class SwRepaint : public SwRect
64 : {
65 : SwTwips nOfst;
66 : SwTwips nRightOfst;
67 : public:
68 43044 : SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
69 82 : SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
70 82 : nRightOfst( rRep.nRightOfst ) {}
71 :
72 367618 : SwTwips GetOfst() const { return nOfst; }
73 357311 : void SetOfst( const SwTwips nNew ) { nOfst = nNew; }
74 87757 : SwTwips GetRightOfst() const { return nRightOfst; }
75 96763 : void SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
76 : };
77 :
78 : /// Collection of SwLinePortion instances, representing one line of text
79 : class SwLineLayout : public SwTextPortion
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 17498 : inline void SetFormatAdj( const bool bNew ) { bFormatAdj = bNew; }
113 90672 : inline bool IsFormatAdj() const { return bFormatAdj; }
114 : inline void SetFntChg( const bool bNew ) { bFntChg = bNew; }
115 : inline bool IsFntChg() const { return bFntChg; }
116 80170 : inline void SetEndHyph( const bool bNew ) { bEndHyph = bNew; }
117 185329 : inline bool IsEndHyph() const { return bEndHyph; }
118 80170 : inline void SetMidHyph( const bool bNew ) { bMidHyph = bNew; }
119 80157 : inline bool IsMidHyph() const { return bMidHyph; }
120 : inline void SetTab( const bool bNew ) { bTab = bNew; }
121 : inline bool IsTab() const { return bTab; }
122 472 : inline void SetFly( const bool bNew ) { bFly = bNew; }
123 3483 : inline bool IsFly() const { return bFly; }
124 8911 : inline void SetRest( const bool bNew ) { bRest = bNew; }
125 60188 : inline bool IsRest() const { return bRest; }
126 3 : inline void SetBlinking( const bool bNew = true ) { bBlinking = bNew; }
127 12897 : inline bool IsBlinking() const { return bBlinking; }
128 108689 : inline void SetContent( const bool bNew = true ) { bContent = bNew; }
129 125880 : inline bool HasContent() const { return bContent; }
130 86792 : inline void SetRedline( const bool bNew = true ) { bRedline = bNew; }
131 1831 : inline bool HasRedline() const { return bRedline; }
132 24 : inline void SetForcedLeftMargin( const bool bNew = true ) { bForcedLeftMargin = bNew; }
133 35588 : inline bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
134 246465 : inline void SetHanging( const bool bNew = true ) { bHanging = bNew; }
135 : inline bool IsHanging() const { return bHanging; }
136 79517 : inline void SetUnderscore( const bool bNew = true ) { bUnderscore = bNew; }
137 86691 : inline bool HasUnderscore() const { return bUnderscore; }
138 :
139 : // Respecting empty dummy lines
140 86886 : inline void SetDummy( const bool bNew ) { bDummy = bNew; }
141 696700 : inline bool IsDummy() const { return bDummy; }
142 :
143 105571 : inline void SetClipping( const bool bNew ) { bClipping = bNew; }
144 202540 : inline bool IsClipping() const { return bClipping; }
145 :
146 : inline SwLineLayout();
147 : virtual ~SwLineLayout();
148 :
149 1278670 : inline SwLineLayout *GetNext() { return pNext; }
150 356728 : inline const SwLineLayout *GetNext() const { return pNext; }
151 31724 : 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( SwTextFormatter &rLine, SwTextFormatInfo &rInf );
157 :
158 216887 : inline void SetRealHeight( sal_uInt16 nNew ) { nRealHeight = nNew; }
159 1152982 : inline sal_uInt16 GetRealHeight() const { return nRealHeight; }
160 :
161 : // Creates the glue chain for short lines
162 : SwMarginPortion *CalcLeftMargin();
163 :
164 159673 : inline SwTwips GetHangingMargin() const
165 159673 : { return _GetHangingMargin(); }
166 :
167 : // For special treatment for empty lines
168 : virtual bool Format( SwTextFormatInfo &rInf ) SAL_OVERRIDE;
169 :
170 : // Stuff for justified alignment
171 65703 : inline bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
172 : void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
173 : void CreateSpaceAdd( const long nInit = 0 );
174 95997 : inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
175 888 : inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
176 589 : inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
177 : {
178 589 : if ( nIdx == GetLLSpaceAddCount() )
179 304 : pLLSpaceAdd->push_back( nNew );
180 : else
181 285 : (*pLLSpaceAdd)[ nIdx ] = nNew;
182 589 : }
183 332 : inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
184 0 : inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
185 75936 : 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 95671 : inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
190 137874 : 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 30744 : 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 SwTextFrm 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 bFootnoteNum : 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 481663 : inline SwRepaint& GetRepaint() { return aRepaint; }
280 265618 : inline const SwRepaint& GetRepaint() const { return aRepaint; }
281 253937 : inline SwCharRange& GetReformat() { return aReformat; }
282 182266 : inline const SwCharRange& GetReformat() const { return aReformat; }
283 199261 : inline long& GetDelta() { return nDelta; }
284 : inline const long& GetDelta() const { return nDelta; }
285 516541 : inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
286 226612 : inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
287 :
288 : // For SwTextFrm::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 2561 : inline void SetFly( const bool bNew = true ) { bFlys = bNew; }
296 10273 : inline bool HasFly() const { return bFlys; }
297 :
298 : // Preps
299 15798 : inline void SetPrep( const bool bNew = true ) { bPrep = bNew; }
300 17071 : inline bool IsPrep() const { return bPrep; }
301 170 : inline void SetPrepWidows( const bool bNew = true ) { bPrepWidows = bNew; }
302 18338 : inline bool IsPrepWidows() const { return bPrepWidows; }
303 135589 : inline void SetPrepMustFit( const bool bNew = true ) { bPrepMustFit = bNew; }
304 127583 : inline bool IsPrepMustFit() const { return bPrepMustFit; }
305 10948 : inline void SetPrepAdjust( const bool bNew = true ) { bPrepAdjust = bNew; }
306 17071 : inline bool IsPrepAdjust() const { return bPrepAdjust; }
307 257 : inline void SetFollowField( const bool bNew = true ) { bFollowField = bNew; }
308 1271 : inline bool IsFollowField() const { return bFollowField; }
309 3795 : inline void SetFixLineHeight( const bool bNew = true ) { bFixLineHeight = bNew; }
310 2 : inline bool IsFixLineHeight() const { return bFixLineHeight; }
311 :
312 47766 : inline void SetFootnoteNum( const bool bNew = true ) { bFootnoteNum = bNew; }
313 9530 : inline bool IsFootnoteNum() const { return bFootnoteNum; }
314 0 : inline void SetMargin( const bool bNew = true ) { bMargin = bNew; }
315 76411 : 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, SwTextFrm* pTextFrm );
342 : #endif
343 :
344 : OUTPUT_OPERATOR_OVERRIDE
345 86088 : DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
346 : };
347 :
348 154333 : inline void SwLineLayout::ResetFlags()
349 : {
350 : bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
351 : = bRest = bBlinking = bClipping = bContent = bRedline
352 154333 : = bForcedLeftMargin = bHanging = false;
353 154333 : }
354 :
355 58662 : inline SwLineLayout::SwLineLayout()
356 : : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
357 58662 : bUnderscore( false )
358 : {
359 58662 : ResetFlags();
360 58662 : SetWhichPor( POR_LAY );
361 58662 : }
362 :
363 71377 : inline void SwParaPortion::ResetPreps()
364 : {
365 71377 : bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = false;
366 71377 : }
367 :
368 54199 : inline void SwParaPortion::FormatReset()
369 : {
370 54199 : nDelta = 0;
371 54199 : aReformat = SwCharRange(0, COMPLETE_STRING);
372 : // bFlys needs to be retained in SwTextFrm::_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 54199 : ResetPreps();
377 54199 : bFollowField = bFixLineHeight = bMargin = false;
378 54199 : }
379 :
380 273590 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
381 : {
382 273590 : const SwLinePortion *pRet = pPortion ? pPortion : this;
383 273590 : return const_cast<SwLinePortion*>(pRet);
384 : }
385 :
386 :
387 : #endif
388 :
389 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|