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 0 : inline SwCharRange( const sal_Int32 nInitStart = 0,
42 0 : const sal_Int32 nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
43 0 : inline sal_Int32 &Start() { return nStart; }
44 0 : inline const sal_Int32 &Start() const { return nStart; }
45 0 : inline void LeftMove( sal_Int32 nNew )
46 0 : { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
47 : inline sal_Int32 End() const
48 : { return nStart + nLen; }
49 0 : inline sal_Int32 &Len() { return nLen; }
50 0 : inline const sal_Int32 &Len() const { return nLen; }
51 0 : inline bool operator<(const SwCharRange &rRange) const
52 0 : { return nStart < rRange.nStart; }
53 0 : inline bool operator>(const SwCharRange &rRange) const
54 0 : { return nStart + nLen > rRange.nStart + rRange.nLen; }
55 0 : inline bool operator!=(const SwCharRange &rRange) const
56 0 : { 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 0 : class SwRepaint : public SwRect
64 : {
65 : SwTwips nOfst;
66 : SwTwips nRightOfst;
67 : public:
68 0 : SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
69 0 : SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
70 0 : nRightOfst( rRep.nRightOfst ) {}
71 :
72 0 : SwTwips GetOfst() const { return nOfst; }
73 0 : void SetOfst( const SwTwips nNew ) { nOfst = nNew; }
74 0 : SwTwips GetRightOfst() const { return nRightOfst; }
75 0 : 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 : KSHORT 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 0 : inline void SetFormatAdj( const bool bNew ) { bFormatAdj = bNew; }
113 0 : inline bool IsFormatAdj() const { return bFormatAdj; }
114 : inline void SetFntChg( const bool bNew ) { bFntChg = bNew; }
115 : inline bool IsFntChg() const { return bFntChg; }
116 0 : inline void SetEndHyph( const bool bNew ) { bEndHyph = bNew; }
117 0 : inline bool IsEndHyph() const { return bEndHyph; }
118 0 : inline void SetMidHyph( const bool bNew ) { bMidHyph = bNew; }
119 0 : inline bool IsMidHyph() const { return bMidHyph; }
120 : inline void SetTab( const bool bNew ) { bTab = bNew; }
121 : inline bool IsTab() const { return bTab; }
122 0 : inline void SetFly( const bool bNew ) { bFly = bNew; }
123 0 : inline bool IsFly() const { return bFly; }
124 0 : inline void SetRest( const bool bNew ) { bRest = bNew; }
125 0 : inline bool IsRest() const { return bRest; }
126 0 : inline void SetBlinking( const bool bNew = true ) { bBlinking = bNew; }
127 0 : inline bool IsBlinking() const { return bBlinking; }
128 0 : inline void SetCntnt( const bool bNew = true ) { bContent = bNew; }
129 0 : inline bool HasCntnt() const { return bContent; }
130 0 : inline void SetRedline( const bool bNew = true ) { bRedline = bNew; }
131 0 : inline bool HasRedline() const { return bRedline; }
132 0 : inline void SetForcedLeftMargin( const bool bNew = true ) { bForcedLeftMargin = bNew; }
133 0 : inline bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
134 0 : inline void SetHanging( const bool bNew = true ) { bHanging = bNew; }
135 : inline bool IsHanging() const { return bHanging; }
136 0 : inline void SetUnderscore( const bool bNew = true ) { bUnderscore = bNew; }
137 0 : inline bool HasUnderscore() const { return bUnderscore; }
138 :
139 : // Respecting empty dummy lines
140 0 : inline void SetDummy( const bool bNew ) { bDummy = bNew; }
141 0 : inline bool IsDummy() const { return bDummy; }
142 :
143 0 : inline void SetClipping( const bool bNew ) { bClipping = bNew; }
144 0 : inline bool IsClipping() const { return bClipping; }
145 :
146 : inline SwLineLayout();
147 : virtual ~SwLineLayout();
148 :
149 0 : inline SwLineLayout *GetNext() { return pNext; }
150 0 : inline const SwLineLayout *GetNext() const { return pNext; }
151 0 : 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 0 : inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
159 0 : inline KSHORT GetRealHeight() const { return nRealHeight; }
160 :
161 : // Creates the glue chain for short lines
162 : SwMarginPortion *CalcLeftMargin();
163 :
164 0 : inline SwTwips GetHangingMargin() const
165 0 : { 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 0 : inline bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
172 : void InitSpaceAdd(); // Creates pLLSpaceAdd if necessary
173 : void CreateSpaceAdd( const long nInit = 0 );
174 0 : inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
175 0 : inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
176 0 : inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
177 : {
178 0 : if ( nIdx == GetLLSpaceAddCount() )
179 0 : pLLSpaceAdd->push_back( nNew );
180 : else
181 0 : (*pLLSpaceAdd)[ nIdx ] = nNew;
182 0 : }
183 0 : inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
184 0 : inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
185 0 : 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 0 : inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
190 0 : 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 0 : 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 0 : inline SwRepaint *GetRepaint() { return &aRepaint; }
280 0 : inline const SwRepaint *GetRepaint() const { return &aRepaint; }
281 0 : inline SwCharRange *GetReformat() { return &aReformat; }
282 0 : inline const SwCharRange *GetReformat() const { return &aReformat; }
283 0 : inline long *GetDelta() { return &nDelta; }
284 : inline const long *GetDelta() const { return &nDelta; }
285 0 : inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
286 0 : 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 0 : inline void SetFly( const bool bNew = true ) { bFlys = bNew; }
296 0 : inline bool HasFly() const { return bFlys; }
297 :
298 : // Preps
299 0 : inline void SetPrep( const bool bNew = true ) { bPrep = bNew; }
300 0 : inline bool IsPrep() const { return bPrep; }
301 0 : inline void SetPrepWidows( const bool bNew = true ) { bPrepWidows = bNew; }
302 0 : inline bool IsPrepWidows() const { return bPrepWidows; }
303 0 : inline void SetPrepMustFit( const bool bNew = true ) { bPrepMustFit = bNew; }
304 0 : inline bool IsPrepMustFit() const { return bPrepMustFit; }
305 0 : inline void SetPrepAdjust( const bool bNew = true ) { bPrepAdjust = bNew; }
306 0 : inline bool IsPrepAdjust() const { return bPrepAdjust; }
307 0 : inline void SetFollowField( const bool bNew = true ) { bFollowField = bNew; }
308 0 : inline bool IsFollowField() const { return bFollowField; }
309 0 : inline void SetFixLineHeight( const bool bNew = true ) { bFixLineHeight = bNew; }
310 0 : inline bool IsFixLineHeight() const { return bFixLineHeight; }
311 :
312 0 : inline void SetFtnNum( const bool bNew = true ) { bFtnNum = bNew; }
313 0 : inline bool IsFtnNum() const { return bFtnNum; }
314 0 : inline void SetMargin( const bool bNew = true ) { bMargin = bNew; }
315 0 : 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 0 : DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
346 : };
347 :
348 : /*************************************************************************
349 : * Inline implementations
350 : *************************************************************************/
351 :
352 0 : inline void SwLineLayout::ResetFlags()
353 : {
354 : bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
355 : = bRest = bBlinking = bClipping = bContent = bRedline
356 0 : = bForcedLeftMargin = bHanging = false;
357 0 : }
358 :
359 0 : inline SwLineLayout::SwLineLayout()
360 : : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
361 0 : bUnderscore( false )
362 : {
363 0 : ResetFlags();
364 0 : SetWhichPor( POR_LAY );
365 0 : }
366 :
367 0 : inline void SwParaPortion::ResetPreps()
368 : {
369 0 : bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = false;
370 0 : }
371 :
372 0 : inline void SwParaPortion::FormatReset()
373 : {
374 0 : nDelta = 0;
375 0 : aReformat = SwCharRange(0, COMPLETE_STRING);
376 : // bFlys needs to be retained in SwTxtFrm::_Format() so that empty
377 : // paragraphs that needed to avoid Frames with no flow, reformat
378 : // when the Frame disappears from the Area
379 : // bFlys = false;
380 0 : ResetPreps();
381 0 : bFollowField = bFixLineHeight = bMargin = false;
382 0 : }
383 :
384 0 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
385 0 : { return( pPortion ? pPortion : (SwLinePortion*)this ); }
386 :
387 : #endif
388 :
389 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|