Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : : #ifndef _ITRTXT_HXX
29 : : #define _ITRTXT_HXX
30 : : #include "swtypes.hxx"
31 : : #include "itratr.hxx"
32 : : #include "inftxt.hxx"
33 : :
34 : : class SwTxtFrm;
35 : : struct SwPosition;
36 : : struct SwCrsrMoveState;
37 : : class SwMarginPortion;
38 : : class SwFlyPortion;
39 : :
40 : : /*************************************************************************
41 : : * class SwTxtIter
42 : : *************************************************************************/
43 : :
44 [ + - ][ - + ]: 94498 : class SwTxtIter : public SwAttrIter
45 : : {
46 : : protected:
47 : : SwLineInfo aLineInf;
48 : : SwTxtFrm *pFrm;
49 : : SwTxtInfo *pInf;
50 : : SwLineLayout *pCurr;
51 : : SwLineLayout *pPrev;
52 : : SwTwips nFrameStart;
53 : : SwTwips nY;
54 : : SwTwips nRegStart; // The register's start position (Y)
55 : : xub_StrLen nStart; // Start in the text string, end = pCurr->GetLen()
56 : : KSHORT nRegDiff; // Register's line distance
57 : : MSHORT nLineNr; // Line number
58 : : sal_Bool bPrev : 1;
59 : : sal_Bool bRegisterOn : 1; // Keep in register
60 : : sal_Bool bOneBlock : 1; // Justified text: Dispose single words
61 : : sal_Bool bLastBlock : 1; // Justified text: Also the last line
62 : : sal_Bool bLastCenter : 1; // Justified text: Center last line
63 : :
64 : : SwLineLayout *_GetPrev();
65 : :
66 : : // Reset in the first line
67 : : void Init();
68 : : void CtorInitTxtIter( SwTxtFrm *pFrm, SwTxtInfo *pInf );
69 : 94315 : inline SwTxtIter(SwTxtNode* pTxtNode)
70 : : : SwAttrIter(pTxtNode)
71 : : , pFrm(NULL)
72 : : , pInf(NULL)
73 : : , pCurr(NULL)
74 [ + - ]: 94315 : , pPrev(NULL)
75 : 94315 : {}
76 : : public:
77 [ + - ][ + - ]: 183 : inline SwTxtIter( SwTxtFrm *pTxtFrm, SwTxtInfo *pTxtInf ) : SwAttrIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
78 [ + - ]: 183 : { CtorInitTxtIter( pTxtFrm, pTxtInf ); }
79 : 478547 : inline const SwLineLayout *GetCurr() const { return pCurr; } // NEVER 0!
80 : 2469 : inline const SwLineLayout *GetNext() const { return pCurr->GetNext(); }
81 : : const SwLineLayout *GetPrev();
82 : 82059 : inline xub_StrLen GetLength() const { return pCurr->GetLen(); }
83 : 151331 : inline MSHORT GetLineNr() const { return nLineNr; }
84 : 198569 : inline xub_StrLen GetStart() const { return nStart; }
85 : 66657 : inline xub_StrLen GetEnd() const { return GetStart() + GetLength(); }
86 : 363967 : inline SwTwips Y() const { return nY; }
87 : :
88 : 0 : inline SwTwips RegStart() const { return nRegStart; }
89 : 0 : inline KSHORT RegDiff() const { return nRegDiff; }
90 : 54918 : inline sal_Bool IsRegisterOn() const { return bRegisterOn; }
91 : :
92 : 3307444 : inline SwTxtInfo &GetInfo() { return *pInf; }
93 : 583539 : inline const SwTxtInfo &GetInfo() const { return *pInf; }
94 : :
95 : 202 : inline void Top() { Init(); }
96 : : void Bottom();
97 : : const SwLineLayout *Next();
98 : : const SwLineLayout *Prev();
99 : :
100 : : // Skips the FlyFrms dummy line
101 : : const SwLineLayout *NextLine();
102 : : const SwLineLayout *PrevLine();
103 : : const SwLineLayout *GetNextLine() const;
104 : : const SwLineLayout *GetPrevLine();
105 : :
106 : : void CharToLine( const xub_StrLen );
107 : : const SwLineLayout *TwipsToLine(const SwTwips);
108 : :
109 : : // Truncates all after pCurr
110 : : void TruncLines( sal_Bool bNoteFollow = sal_False );
111 : :
112 : 1254289 : inline KSHORT GetLineHeight() const { return pCurr->GetRealHeight(); }
113 : : void CalcAscentAndHeight( KSHORT &rAscent, KSHORT &rHeight ) const;
114 : :
115 : : // Lots of trouble for querying pCurr == pPara
116 : 212630 : inline sal_Bool IsFirstTxtLine() const
117 : 212630 : { return nStart == GetInfo().GetTxtStart() &&
118 [ + + ][ + + ]: 212630 : !( pCurr->IsDummy() && GetNextLine() ); }
[ + + ]
119 : :
120 : : // Replacement for the old IsFirstLine()
121 : 54918 : inline sal_Bool IsParaLine() const
122 : 54918 : { return pCurr == pInf->GetParaPortion(); }
123 : :
124 : 80233 : const SwLineInfo &GetLineInfo() const { return aLineInf; }
125 : : inline SwTwips GetFirstPos() const { return nFrameStart; }
126 : : inline sal_Bool SeekAndChg( SwTxtSizeInfo &rInf );
127 : : inline sal_Bool SeekAndChgBefore( SwTxtSizeInfo &rInf );
128 : : inline sal_Bool SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara=sal_False );
129 : :
130 : 508521 : inline SwTxtFrm *GetTxtFrm() { return pFrm; }
131 : 240 : inline const SwTxtFrm *GetTxtFrm() const { return pFrm; }
132 : :
133 : : // Counts consecutive hyphens in order to be within the boundary given by MaxHyphens
134 : : void CntHyphens( sal_uInt8 &nEndCnt, sal_uInt8 &nMidCnt) const;
135 : : };
136 : :
137 : : /*************************************************************************
138 : : * class SwTxtMargin
139 : : *************************************************************************/
140 : :
141 [ - + ]: 94315 : class SwTxtMargin : public SwTxtIter
142 : : {
143 : : private:
144 : : SwTwips nLeft;
145 : : SwTwips nRight;
146 : : SwTwips nFirst;
147 : : KSHORT nDropLeft;
148 : : KSHORT nDropHeight;
149 : : KSHORT nDropDescent;
150 : : MSHORT nDropLines;
151 : : MSHORT nAdjust;
152 : : // #i91133#
153 : : SwTwips mnTabLeft;
154 : :
155 : : protected:
156 : : // For FormatQuoVadis
157 : 0 : inline void Right( const SwTwips nNew ) { nRight = nNew; }
158 : : // For CalcFlyAdjust
159 : : inline void SetDropLeft( const KSHORT nNew ) { nDropLeft = nNew; }
160 : :
161 : : void CtorInitTxtMargin( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
162 : 80630 : inline SwTxtMargin(SwTxtNode* pTxtNode) : SwTxtIter(pTxtNode) { }
163 : : public:
164 [ + - ]: 13685 : inline SwTxtMargin( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtIter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
165 [ + - ]: 13685 : { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
166 : : inline SwTwips GetLeftMargin() const;
167 : : inline SwTwips Left() const;
168 : 143051 : inline SwTwips Right() const { return nRight; }
169 : 53368 : inline SwTwips FirstLeft() const { return nFirst; }
170 : 1102 : inline SwTwips CurrWidth() const { return pCurr->PrtWidth(); }
171 : : SwTwips GetLineStart() const;
172 : 222 : inline SwTwips GetLineEnd() const { return GetLineStart() + CurrWidth(); }
173 : 96972 : inline Point GetTopLeft() const { return Point( GetLineStart(), Y() ); }
174 : 20 : inline sal_Bool IsOneBlock() const { return bOneBlock; }
175 : 0 : inline sal_Bool IsLastBlock() const { return bLastBlock; }
176 : 0 : inline sal_Bool IsLastCenter() const { return bLastCenter; }
177 : 157456 : inline MSHORT GetAdjust() const { return nAdjust; }
178 : 1759 : inline KSHORT GetLineWidth() const
179 : 1759 : { return KSHORT( Right() - GetLeftMargin() + 1 ); }
180 [ + + ]: 1698 : inline SwTwips GetLeftMin() const { return nFirst < nLeft ? nFirst : nLeft; }
181 : 38 : inline sal_Bool HasNegFirst() const { return nFirst < nLeft; }
182 : :
183 : : // #i91133#
184 : 1623 : inline SwTwips GetTabLeft() const
185 : : {
186 : 1623 : return mnTabLeft;
187 : : }
188 : : // DropCaps
189 : 47352 : inline MSHORT GetDropLines() const { return nDropLines; }
190 : 0 : inline void SetDropLines( const MSHORT nNew ) { nDropLines = nNew; }
191 : 1698 : inline KSHORT GetDropLeft() const { return nDropLeft; }
192 : 0 : inline KSHORT GetDropHeight() const { return nDropHeight; }
193 : 0 : inline void SetDropHeight( const KSHORT nNew ) { nDropHeight = nNew; }
194 : 0 : inline KSHORT GetDropDescent() const { return nDropDescent; }
195 : 0 : inline void SetDropDescent( const KSHORT nNew ) { nDropDescent = nNew; }
196 : : void DropInit();
197 : :
198 : : // Returns the TxtPos for start and end of the current line without whitespace
199 : : // Implemented in frminf.cxx
200 : : xub_StrLen GetTxtStart() const;
201 : : xub_StrLen GetTxtEnd() const;
202 : :
203 : 302910 : inline SwTxtSizeInfo &GetInfo()
204 : 302910 : { return (SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
205 : 50861 : inline const SwTxtSizeInfo &GetInfo() const
206 : 50861 : { return (const SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
207 : :
208 : : };
209 : :
210 : :
211 : : /*************************************************************************
212 : : * class SwTxtAdjuster
213 : : *************************************************************************/
214 : :
215 [ - + ]: 80630 : class SwTxtAdjuster : public SwTxtMargin
216 : : {
217 : : // Adjusts the portion, if we have adjustment and FlyFrms
218 : : void CalcFlyAdjust( SwLineLayout *pCurr );
219 : :
220 : : // Calls SplitGlues and CalcBlockAdjust
221 : : void FormatBlock( );
222 : :
223 : : // Creates the glue chain for short lines
224 : : SwMarginPortion* CalcRightMargin( SwLineLayout *pCurr, SwTwips nReal = 0 );
225 : :
226 : : // Calculate the adjustment (FlyPortions)
227 : : SwFlyPortion *CalcFlyPortion( const long nRealWidth,
228 : : const SwRect &rCurrRect );
229 : :
230 : : protected:
231 : 80630 : inline SwTxtAdjuster(SwTxtNode* pTxtNode) : SwTxtMargin(pTxtNode) { }
232 : : // Creates the Glues for adjusted paragraphs
233 : : void CalcNewBlock( SwLineLayout *pCurr, const SwLinePortion *pStopAt,
234 : : SwTwips nReal = 0, bool bSkipKashida = false );
235 : : SwTwips CalcKanaAdj( SwLineLayout *pCurr );
236 : : public:
237 : : inline SwTxtAdjuster( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtMargin(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
238 : : { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
239 : :
240 : : // Is overloaded by SwTxtFormatter due to UpdatePos
241 : : void CalcAdjLine( SwLineLayout *pCurr );
242 : :
243 : : // For adjusting afterwards
244 : 85113 : inline void GetAdjusted() const
245 : : {
246 [ + + ]: 85113 : if( pCurr->IsFormatAdj() )
247 : 882 : ((SwTxtAdjuster*)this)->CalcAdjLine( pCurr );
248 : 85113 : }
249 : :
250 : : // Special treatment for DropCaps
251 : : void CalcDropAdjust();
252 : : void CalcDropRepaint();
253 : : };
254 : :
255 : : /*************************************************************************
256 : : * class SwTxtCursor
257 : : *************************************************************************/
258 : :
259 [ - + ]: 80630 : class SwTxtCursor : public SwTxtAdjuster
260 : : {
261 : : // A small helper-class to save SwTxtCursor member, manipulate them
262 : : // and to restore them
263 : : friend class SwTxtCursorSave;
264 : :
265 : : // Ambiguities
266 : : static sal_Bool bRightMargin;
267 : : void _GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* );
268 : : protected:
269 : : void CtorInitTxtCursor( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
270 : 28680 : inline SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { }
271 : : public:
272 [ + - ]: 51950 : inline SwTxtCursor( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtAdjuster(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
273 [ + - ]: 51950 : { CtorInitTxtCursor( pTxtFrm, pTxtSizeInf ); }
274 : : sal_Bool GetCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0,
275 : : const long nMax = 0 );
276 : : sal_Bool GetEndCharRect(SwRect *, const xub_StrLen, SwCrsrMoveState* = 0,
277 : : const long nMax = 0 );
278 : : xub_StrLen GetCrsrOfst( SwPosition *pPos, const Point &rPoint,
279 : : const MSHORT nChgNode, SwCrsrMoveState* = 0 ) const;
280 : : // Respects ambiguities: For the implementation see below
281 : : const SwLineLayout *CharCrsrToLine( const xub_StrLen nPos );
282 : :
283 : : // calculates baseline for portion rPor
284 : : // bAutoToCentered indicates, if AUTOMATIC mode means CENTERED or BASELINE
285 : : sal_uInt16 AdjustBaseLine( const SwLineLayout& rLine, const SwLinePortion* pPor,
286 : : sal_uInt16 nPorHeight = 0, sal_uInt16 nAscent = 0,
287 : : const sal_Bool bAutoToCentered = sal_False ) const;
288 : :
289 : 6 : static inline void SetRightMargin( const sal_Bool bNew ){ bRightMargin = bNew; }
290 : 58 : static inline sal_Bool IsRightMargin() { return bRightMargin; }
291 : : };
292 : :
293 : : /*************************************************************************
294 : : * SwHookOut
295 : : *
296 : : * Change current output device to printer, this has to be done before
297 : : * formatting.
298 : : *************************************************************************/
299 : :
300 : : class SwHookOut
301 : : {
302 : : SwTxtSizeInfo* pInf;
303 : : OutputDevice* pOut;
304 : : sal_Bool bOnWin;
305 : : public:
306 : : SwHookOut( SwTxtSizeInfo& rInfo );
307 : : ~SwHookOut();
308 : : };
309 : :
310 : : /*************************************************************************
311 : : * Inline implementation
312 : : *************************************************************************/
313 : :
314 : 193098 : inline sal_Bool SwTxtIter::SeekAndChg( SwTxtSizeInfo &rInf )
315 : : {
316 : 193098 : return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
317 : : }
318 : :
319 : 0 : inline sal_Bool SwTxtIter::SeekAndChgBefore( SwTxtSizeInfo &rInf )
320 : : {
321 [ # # ]: 0 : if ( rInf.GetIdx() )
322 : 0 : return SeekAndChgAttrIter( rInf.GetIdx()-1, rInf.GetOut() );
323 : : else
324 : 0 : return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
325 : : }
326 : :
327 : 1822 : inline sal_Bool SwTxtIter::SeekStartAndChg( SwTxtSizeInfo &rInf, const sal_Bool bPara )
328 : : {
329 : 1822 : return SeekStartAndChgAttrIter( rInf.GetOut(), bPara );
330 : : }
331 : :
332 : 212592 : inline SwTwips SwTxtMargin::GetLeftMargin() const
333 : : {
334 [ + + ]: 212592 : return IsFirstTxtLine() ? nFirst : Left();
335 : : }
336 : :
337 : 201547 : inline SwTwips SwTxtMargin::Left() const
338 : : {
339 [ - + ][ # # ]: 201547 : return (nDropLines >= nLineNr && 1 != nLineNr) ? nFirst + nDropLeft : nLeft;
340 : : }
341 : :
342 : :
343 : :
344 : : #endif
345 : :
346 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|