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 _ITRTXT_HXX
20 : #define _ITRTXT_HXX
21 : #include "swtypes.hxx"
22 : #include "itratr.hxx"
23 : #include "inftxt.hxx"
24 :
25 : class SwTxtFrm;
26 : struct SwPosition;
27 : struct SwCrsrMoveState;
28 : class SwMarginPortion;
29 : class SwFlyPortion;
30 :
31 : /*************************************************************************
32 : * class SwTxtIter
33 : *************************************************************************/
34 :
35 48573 : class SwTxtIter : public SwAttrIter
36 : {
37 : protected:
38 : SwLineInfo aLineInf;
39 : SwTxtFrm *pFrm;
40 : SwTxtInfo *pInf;
41 : SwLineLayout *pCurr;
42 : SwLineLayout *pPrev;
43 : SwTwips nFrameStart;
44 : SwTwips nY;
45 : SwTwips nRegStart; // The register's start position (Y)
46 : xub_StrLen nStart; // Start in the text string, end = pCurr->GetLen()
47 : KSHORT nRegDiff; // Register's line distance
48 : MSHORT nLineNr; // Line number
49 : sal_Bool bPrev : 1;
50 : sal_Bool bRegisterOn : 1; // Keep in register
51 : sal_Bool bOneBlock : 1; // Justified text: Dispose single words
52 : sal_Bool bLastBlock : 1; // Justified text: Also the last line
53 : sal_Bool bLastCenter : 1; // Justified text: Center last line
54 :
55 : SwLineLayout *_GetPrev();
56 :
57 : // Reset in the first line
58 : void Init();
59 : void CtorInitTxtIter( SwTxtFrm *pFrm, SwTxtInfo *pInf );
60 48448 : inline SwTxtIter(SwTxtNode* pTxtNode)
61 : : SwAttrIter(pTxtNode)
62 : , pFrm(NULL)
63 : , pInf(NULL)
64 : , pCurr(NULL)
65 48448 : , pPrev(NULL)
66 48448 : {}
67 : public:
68 125 : inline SwTxtIter( SwTxtFrm *pTxtFrm, SwTxtInfo *pTxtInf ) : SwAttrIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
69 125 : { CtorInitTxtIter( pTxtFrm, pTxtInf ); }
70 218878 : inline const SwLineLayout *GetCurr() const { return pCurr; } // NEVER 0!
71 1643 : inline const SwLineLayout *GetNext() const { return pCurr->GetNext(); }
72 : const SwLineLayout *GetPrev();
73 43078 : inline xub_StrLen GetLength() const { return pCurr->GetLen(); }
74 70422 : inline MSHORT GetLineNr() const { return nLineNr; }
75 98677 : inline xub_StrLen GetStart() const { return nStart; }
76 35030 : inline xub_StrLen GetEnd() const { return GetStart() + GetLength(); }
77 169972 : inline SwTwips Y() const { return nY; }
78 :
79 0 : inline SwTwips RegStart() const { return nRegStart; }
80 0 : inline KSHORT RegDiff() const { return nRegDiff; }
81 25669 : inline sal_Bool IsRegisterOn() const { return bRegisterOn; }
82 :
83 1526888 : inline SwTxtInfo &GetInfo() { return *pInf; }
84 286848 : inline const SwTxtInfo &GetInfo() const { return *pInf; }
85 :
86 69 : inline void Top() { Init(); }
87 : void Bottom();
88 : const SwLineLayout *Next();
89 : const SwLineLayout *Prev();
90 :
91 : // Skips the FlyFrms dummy line
92 : const SwLineLayout *NextLine();
93 : const SwLineLayout *PrevLine();
94 : const SwLineLayout *GetNextLine() const;
95 : const SwLineLayout *GetPrevLine();
96 :
97 : void CharToLine( const xub_StrLen );
98 : const SwLineLayout *TwipsToLine(const SwTwips);
99 :
100 : // Truncates all after pCurr
101 : void TruncLines( bool bNoteFollow = false );
102 :
103 540347 : inline KSHORT GetLineHeight() const { return pCurr->GetRealHeight(); }
104 : void CalcAscentAndHeight( KSHORT &rAscent, KSHORT &rHeight ) const;
105 :
106 : // Lots of trouble for querying pCurr == pPara
107 105063 : inline bool IsFirstTxtLine() const
108 181093 : { return nStart == GetInfo().GetTxtStart() &&
109 148952 : !( pCurr->IsDummy() && GetNextLine() ); }
110 :
111 : // Replacement for the old IsFirstLine()
112 25670 : inline bool IsParaLine() const
113 25670 : { return pCurr == pInf->GetParaPortion(); }
114 :
115 38887 : const SwLineInfo &GetLineInfo() const { return aLineInf; }
116 : inline SwTwips GetFirstPos() const { return nFrameStart; }
117 : inline sal_Bool SeekAndChg( SwTxtSizeInfo &rInf );
118 : inline sal_Bool SeekAndChgBefore( SwTxtSizeInfo &rInf );
119 : inline sal_Bool SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara=sal_False );
120 :
121 263102 : inline SwTxtFrm *GetTxtFrm() { return pFrm; }
122 192 : inline const SwTxtFrm *GetTxtFrm() const { return pFrm; }
123 :
124 : // Counts consecutive hyphens in order to be within the boundary given by MaxHyphens
125 : void CntHyphens( sal_uInt8 &nEndCnt, sal_uInt8 &nMidCnt) const;
126 : };
127 :
128 : /*************************************************************************
129 : * class SwTxtMargin
130 : *************************************************************************/
131 :
132 48448 : class SwTxtMargin : public SwTxtIter
133 : {
134 : private:
135 : SwTwips nLeft;
136 : SwTwips nRight;
137 : SwTwips nFirst;
138 : KSHORT nDropLeft;
139 : KSHORT nDropHeight;
140 : KSHORT nDropDescent;
141 : MSHORT nDropLines;
142 : MSHORT nAdjust;
143 : // #i91133#
144 : SwTwips mnTabLeft;
145 :
146 : protected:
147 : // For FormatQuoVadis
148 0 : inline void Right( const SwTwips nNew ) { nRight = nNew; }
149 : // For CalcFlyAdjust
150 : inline void SetDropLeft( const KSHORT nNew ) { nDropLeft = nNew; }
151 :
152 : void CtorInitTxtMargin( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
153 41667 : inline SwTxtMargin(SwTxtNode* pTxtNode) : SwTxtIter(pTxtNode) { }
154 : public:
155 6781 : inline SwTxtMargin( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
156 6781 : { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
157 : inline SwTwips GetLeftMargin() const;
158 : inline SwTwips Left() const;
159 70023 : inline SwTwips Right() const { return nRight; }
160 24348 : inline SwTwips FirstLeft() const { return nFirst; }
161 709 : inline SwTwips CurrWidth() const { return pCurr->PrtWidth(); }
162 : SwTwips GetLineStart() const;
163 110 : inline SwTwips GetLineEnd() const { return GetLineStart() + CurrWidth(); }
164 48901 : inline Point GetTopLeft() const { return Point( GetLineStart(), Y() ); }
165 12 : inline sal_Bool IsOneBlock() const { return bOneBlock; }
166 27 : inline sal_Bool IsLastBlock() const { return bLastBlock; }
167 11 : inline sal_Bool IsLastCenter() const { return bLastCenter; }
168 77493 : inline MSHORT GetAdjust() const { return nAdjust; }
169 1067 : inline KSHORT GetLineWidth() const
170 1067 : { return KSHORT( Right() - GetLeftMargin() + 1 ); }
171 1672 : inline SwTwips GetLeftMin() const { return nFirst < nLeft ? nFirst : nLeft; }
172 32 : inline bool HasNegFirst() const { return nFirst < nLeft; }
173 :
174 : // #i91133#
175 826 : inline SwTwips GetTabLeft() const
176 : {
177 826 : return mnTabLeft;
178 : }
179 : // DropCaps
180 21492 : inline MSHORT GetDropLines() const { return nDropLines; }
181 0 : inline void SetDropLines( const MSHORT nNew ) { nDropLines = nNew; }
182 1672 : inline KSHORT GetDropLeft() const { return nDropLeft; }
183 0 : inline KSHORT GetDropHeight() const { return nDropHeight; }
184 0 : inline void SetDropHeight( const KSHORT nNew ) { nDropHeight = nNew; }
185 0 : inline KSHORT GetDropDescent() const { return nDropDescent; }
186 0 : inline void SetDropDescent( const KSHORT nNew ) { nDropDescent = nNew; }
187 : void DropInit();
188 :
189 : // Returns the TxtPos for start and end of the current line without whitespace
190 : // Implemented in frminf.cxx
191 : xub_StrLen GetTxtStart() const;
192 : xub_StrLen GetTxtEnd() const;
193 :
194 157281 : inline SwTxtSizeInfo &GetInfo()
195 157281 : { return (SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
196 26516 : inline const SwTxtSizeInfo &GetInfo() const
197 26516 : { return (const SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
198 :
199 : };
200 :
201 :
202 : /*************************************************************************
203 : * class SwTxtAdjuster
204 : *************************************************************************/
205 :
206 41667 : class SwTxtAdjuster : public SwTxtMargin
207 : {
208 : // Adjusts the portion, if we have adjustment and FlyFrms
209 : void CalcFlyAdjust( SwLineLayout *pCurr );
210 :
211 : // Calls SplitGlues and CalcBlockAdjust
212 : void FormatBlock( );
213 :
214 : // Creates the glue chain for short lines
215 : SwMarginPortion* CalcRightMargin( SwLineLayout *pCurr, SwTwips nReal = 0 );
216 :
217 : // Calculate the adjustment (FlyPortions)
218 : SwFlyPortion *CalcFlyPortion( const long nRealWidth,
219 : const SwRect &rCurrRect );
220 :
221 : protected:
222 41667 : inline SwTxtAdjuster(SwTxtNode* pTxtNode) : SwTxtMargin(pTxtNode) { }
223 : // Creates the Glues for adjusted paragraphs
224 : void CalcNewBlock( SwLineLayout *pCurr, const SwLinePortion *pStopAt,
225 : SwTwips nReal = 0, bool bSkipKashida = false );
226 : SwTwips CalcKanaAdj( SwLineLayout *pCurr );
227 : public:
228 : inline SwTxtAdjuster( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtMargin(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
229 : { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
230 :
231 : // Is overloaded by SwTxtFormatter due to UpdatePos
232 : void CalcAdjLine( SwLineLayout *pCurr );
233 :
234 : // For adjusting afterwards
235 41567 : inline void GetAdjusted() const
236 : {
237 41567 : if( pCurr->IsFormatAdj() )
238 498 : ((SwTxtAdjuster*)this)->CalcAdjLine( pCurr );
239 41567 : }
240 :
241 : // Special treatment for DropCaps
242 : void CalcDropAdjust();
243 : void CalcDropRepaint();
244 : };
245 :
246 : /*************************************************************************
247 : * class SwTxtCursor
248 : *************************************************************************/
249 :
250 41667 : class SwTxtCursor : public SwTxtAdjuster
251 : {
252 : // A small helper-class to save SwTxtCursor member, manipulate them
253 : // and to restore them
254 : friend class SwTxtCursorSave;
255 :
256 : // Ambiguities
257 : static sal_Bool bRightMargin;
258 : void _GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* );
259 : protected:
260 : void CtorInitTxtCursor( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
261 14294 : inline SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { }
262 : public:
263 27373 : inline SwTxtCursor( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtAdjuster(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
264 27373 : { CtorInitTxtCursor( pTxtFrm, pTxtSizeInf ); }
265 : sal_Bool GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0,
266 : const long nMax = 0 );
267 : sal_Bool GetEndCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0,
268 : const long nMax = 0 );
269 : xub_StrLen GetCrsrOfst( SwPosition *pPos, const Point &rPoint,
270 : const MSHORT nChgNode, SwCrsrMoveState* = 0 ) const;
271 : // Respects ambiguities: For the implementation see below
272 : const SwLineLayout *CharCrsrToLine( const xub_StrLen nPos );
273 :
274 : // calculates baseline for portion rPor
275 : // bAutoToCentered indicates, if AUTOMATIC mode means CENTERED or BASELINE
276 : sal_uInt16 AdjustBaseLine( const SwLineLayout& rLine, const SwLinePortion* pPor,
277 : sal_uInt16 nPorHeight = 0, sal_uInt16 nAscent = 0,
278 : const sal_Bool bAutoToCentered = sal_False ) const;
279 :
280 3 : static inline void SetRightMargin( const sal_Bool bNew ){ bRightMargin = bNew; }
281 44 : static inline sal_Bool IsRightMargin() { return bRightMargin; }
282 : };
283 :
284 : /*************************************************************************
285 : * SwHookOut
286 : *
287 : * Change current output device to printer, this has to be done before
288 : * formatting.
289 : *************************************************************************/
290 :
291 : class SwHookOut
292 : {
293 : SwTxtSizeInfo* pInf;
294 : OutputDevice* pOut;
295 : bool bOnWin;
296 : public:
297 : SwHookOut( SwTxtSizeInfo& rInfo );
298 : ~SwHookOut();
299 : };
300 :
301 : /*************************************************************************
302 : * Inline implementation
303 : *************************************************************************/
304 :
305 87233 : inline sal_Bool SwTxtIter::SeekAndChg( SwTxtSizeInfo &rInf )
306 : {
307 87233 : return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
308 : }
309 :
310 9 : inline sal_Bool SwTxtIter::SeekAndChgBefore( SwTxtSizeInfo &rInf )
311 : {
312 9 : if ( rInf.GetIdx() )
313 1 : return SeekAndChgAttrIter( rInf.GetIdx()-1, rInf.GetOut() );
314 : else
315 8 : return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
316 : }
317 :
318 1241 : inline sal_Bool SwTxtIter::SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara )
319 : {
320 1241 : return SeekStartAndChgAttrIter( rInf.GetOut(), bPara );
321 : }
322 :
323 105031 : inline SwTwips SwTxtMargin::GetLeftMargin() const
324 : {
325 105031 : return IsFirstTxtLine() ? nFirst : Left();
326 : }
327 :
328 93709 : inline SwTwips SwTxtMargin::Left() const
329 : {
330 93709 : return (nDropLines >= nLineNr && 1 != nLineNr) ? nFirst + nDropLeft : nLeft;
331 : }
332 :
333 :
334 :
335 : #endif
336 :
337 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|