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 _ITRFORM2_HXX
29 : : #define _ITRFORM2_HXX
30 : : #include "itrpaint.hxx"
31 : :
32 : : class SwFlyCntPortion;
33 : : class SwInterHyphInfo;
34 : : class SwDropPortion;
35 : : class SwFmtDrop;
36 : : class SwTxtAttr;
37 : : class SwNumberPortion;
38 : : class SwErgoSumPortion;
39 : : class SwExpandPortion;
40 : : class SwMultiPortion;
41 : : class SwFtnPortion;
42 : :
43 : :
44 : : class SwTxtFormatter : public SwTxtPainter
45 : : {
46 : : const SwFmtDrop *pDropFmt;
47 : : SwMultiPortion* pMulti; // during formatting a multi-portion
48 : : sal_uInt8 nCntEndHyph; // Counts consecutive hyphens at the line end
49 : : sal_uInt8 nCntMidHyph; // Counts consecutive hyphens before flies
50 : : xub_StrLen nLeftScanIdx; // for increasing performance during
51 : : xub_StrLen nRightScanIdx; // scanning for portion ends
52 : : sal_Bool bOnceMore : 1; // Another round?
53 : : sal_Bool bFlyInCntBase : 1; // Base reference that sets a character-bound frame
54 : : sal_Bool bChanges : 1; // Flag for calculating the repaint rectangle
55 : : sal_Bool bTruncLines : 1; // Flag for extending the repaint rect, if needed
56 : : sal_Bool bUnclipped : 1; // Flag whether repaint is larger than the fixed line height
57 : : sal_uInt16 m_nHintEndIndex; // HACK for TryNewNoLengthPortion
58 : : SwLinePortion *NewPortion( SwTxtFormatInfo &rInf );
59 : : SwTxtPortion *NewTxtPortion( SwTxtFormatInfo &rInf );
60 : : SwLinePortion *NewExtraPortion( SwTxtFormatInfo &rInf );
61 : : SwTabPortion *NewTabPortion( SwTxtFormatInfo &rInf, bool bAuto ) const;
62 : : SwNumberPortion *NewNumberPortion( SwTxtFormatInfo &rInf ) const;
63 : : SwDropPortion *NewDropPortion( SwTxtFormatInfo &rInf );
64 : : SwNumberPortion *NewFtnNumPortion( SwTxtFormatInfo &rInf ) const;
65 : : SwErgoSumPortion *NewErgoSumPortion( SwTxtFormatInfo &rInf ) const;
66 : : SwExpandPortion *NewFldPortion( SwTxtFormatInfo &rInf,
67 : : const SwTxtAttr *pHt ) const;
68 : : SwFtnPortion *NewFtnPortion( SwTxtFormatInfo &rInf, SwTxtAttr *pHt );
69 : :
70 : : /**
71 : : Sets a new portion for an object anchored as character
72 : : */
73 : : SwFlyCntPortion *NewFlyCntPortion( SwTxtFormatInfo &rInf,
74 : : SwTxtAttr *pHt ) const;
75 : : SwLinePortion *WhichFirstPortion( SwTxtFormatInfo &rInf );
76 : : SwTxtPortion *WhichTxtPor( SwTxtFormatInfo &rInf ) const;
77 : : SwExpandPortion * TryNewNoLengthPortion( SwTxtFormatInfo & rInfo );
78 : :
79 : : // The center pice of formatting
80 : : void BuildPortions( SwTxtFormatInfo &rInf );
81 : :
82 : : sal_Bool BuildMultiPortion( SwTxtFormatInfo &rInf, SwMultiPortion& rMulti );
83 : :
84 : : /**
85 : : Calculation of the emulated right side.
86 : :
87 : : Determines the next object, that reaches into the rest of the line and
88 : : constructs the appropriate FlyPortion.
89 : : SwTxtFly::GetFrm(const SwRect&, sal_Bool) will be needed for this.
90 : :
91 : : The right edge can be shortened by flys
92 : : */
93 : : void CalcFlyWidth( SwTxtFormatInfo &rInf );
94 : :
95 : : // Is overloaded by SwTxtFormatter because of UpdatePos
96 : : void CalcAdjustLine( SwLineLayout *pCurr );
97 : :
98 : : // consideres line spacing attributes
99 : : void CalcRealHeight( sal_Bool bNewLine = sal_False );
100 : :
101 : : // Transfers the data to rInf
102 : : void FeedInf( SwTxtFormatInfo &rInf ) const;
103 : :
104 : : // Treats underflow situations
105 : : SwLinePortion *UnderFlow( SwTxtFormatInfo &rInf );
106 : :
107 : : // Calculates the ascent and the height from the fontmetric
108 : : void CalcAscent( SwTxtFormatInfo &rInf, SwLinePortion *pPor );
109 : :
110 : : // determines, if a optimized repaint rectange is allowed
111 : : sal_Bool AllowRepaintOpt() const;
112 : :
113 : : // Is called by by FormatLine
114 : : void FormatReset( SwTxtFormatInfo &rInf );
115 : :
116 : : /**
117 : : The position of the portions changes with the adjustment.
118 : :
119 : : This method updates the reference point of the anchored as character objects,
120 : : for example after adjustment change (right alignment, justified, etc.)
121 : : Mainly to correct the X position.
122 : : */
123 : : void UpdatePos( SwLineLayout *pCurr, Point aStart, xub_StrLen nStartIdx,
124 : : sal_Bool bAllWays = sal_False ) const;
125 : :
126 : : /**
127 : : Set all anchored as character objects to the passed BaseLine
128 : : (in Y direction).
129 : : */
130 : : void AlignFlyInCntBase( long nBaseLine ) const;
131 : :
132 : : /**
133 : : This is called after the real height of the line has been calculated
134 : : Therefore it is possible, that more flys from below intersect with the
135 : : line, or that flys from above do not intersect with the line anymore.
136 : : We check this and return true, meaning that the line has to be
137 : : formatted again.
138 : : */
139 : : sal_Bool ChkFlyUnderflow( SwTxtFormatInfo &rInf ) const;
140 : :
141 : : // Insert portion
142 : : void InsertPortion( SwTxtFormatInfo &rInf, SwLinePortion *pPor ) const;
143 : :
144 : : // Guess height for the DropPortion
145 : : void GuessDropHeight( const MSHORT nLines );
146 : :
147 : : public:
148 : : // Calculate the height for the DropPortion
149 : : void CalcDropHeight( const MSHORT nLines );
150 : :
151 : : // Calculates the paragraphs bottom, takes anchored objects within it into
152 : : // account which have a wrap setting of "wrap at 1st paragraph"
153 : : SwTwips CalcBottomLine() const;
154 : :
155 : : // Takes character-bound objects into account when calculating the
156 : : // repaint rect in lines with fixed line height
157 : : void CalcUnclipped( SwTwips& rTop, SwTwips& rBottom );
158 : :
159 : : // Amongst others for DropCaps
160 : : sal_Bool CalcOnceMore();
161 : :
162 : : void CtorInitTxtFormatter( SwTxtFrm *pFrm, SwTxtFormatInfo *pInf );
163 [ + - ]: 14873 : inline SwTxtFormatter( SwTxtFrm *pTxtFrm, SwTxtFormatInfo *pTxtFmtInf ) : SwTxtPainter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
164 [ + - ]: 14873 : { CtorInitTxtFormatter( pTxtFrm, pTxtFmtInf ); }
165 : : ~SwTxtFormatter();
166 : :
167 : : xub_StrLen FormatLine( const xub_StrLen nStart );
168 : :
169 : : void RecalcRealHeight();
170 : :
171 : : // We format a line for interactive hyphenation
172 : : sal_Bool Hyphenate( SwInterHyphInfo &rInf );
173 : :
174 : : // A special method for QuoVadis texts:
175 : : // nErgo is the page number of the ErgoSum Ftn
176 : : // At 0 it's still unclear
177 : : xub_StrLen FormatQuoVadis( const xub_StrLen nStart );
178 : :
179 : : // The emergency break: Cancel formatting, discard line
180 : 93550 : inline sal_Bool IsStop() const { return GetInfo().IsStop(); }
181 : :
182 : : // The counterpart: Continue formatting at all costs
183 : 52762 : inline sal_Bool IsNewLine() const { return GetInfo().IsNewLine(); }
184 : :
185 : : // FormatQuick(); Refresh formatting information
186 : 16911 : inline sal_Bool IsQuick() const { return GetInfo().IsQuick(); }
187 : :
188 : : // Create a SwLineLayout if needed, which avoids Ftn/Fly to oscillate
189 : : void MakeDummyLine();
190 : :
191 : : // SwTxtIter functionality
192 : : void Insert( SwLineLayout *pLine );
193 : :
194 : : // The remaining height to the page border
195 : : KSHORT GetFrmRstHeight() const;
196 : :
197 : : // How wide would you be without any bounds (Flys etc.)?
198 : : SwTwips _CalcFitToContent( );
199 : :
200 : : SwLinePortion* MakeRestPortion(const SwLineLayout* pLine, xub_StrLen nPos);
201 : :
202 : 25339 : inline const SwFmtDrop *GetDropFmt() const { return pDropFmt; }
203 : 0 : inline void ClearDropFmt() { pDropFmt = 0; }
204 : :
205 : 135863 : inline SwMultiPortion *GetMulti() const { return pMulti; }
206 : :
207 : 14115 : inline sal_Bool IsOnceMore() const { return bOnceMore; }
208 : 0 : inline void SetOnceMore( sal_Bool bNew ) { bOnceMore = bNew; }
209 : :
210 : : inline sal_Bool HasChanges() const { return bChanges; }
211 : 32091 : inline void SetChanges() { bChanges = sal_True; }
212 : :
213 : 0 : inline sal_Bool HasTruncLines() const { return bTruncLines; }
214 : 14227 : inline void SetTruncLines( sal_Bool bNew ) { bTruncLines = bNew; }
215 : :
216 : 51550 : inline sal_Bool IsUnclipped() const { return bUnclipped; }
217 : 65667 : inline void SetUnclipped( sal_Bool bNew ) { bUnclipped = bNew; }
218 : :
219 : 108021 : inline sal_Bool IsFlyInCntBase() const { return bFlyInCntBase; }
220 : 68633 : inline void SetFlyInCntBase( sal_Bool bNew = sal_True ){ bFlyInCntBase = bNew; }
221 : :
222 : 1748940 : inline SwTxtFormatInfo &GetInfo()
223 : 1748940 : { return (SwTxtFormatInfo&)SwTxtIter::GetInfo(); }
224 : 320048 : inline const SwTxtFormatInfo &GetInfo() const
225 : 320048 : { return (const SwTxtFormatInfo&)SwTxtIter::GetInfo(); }
226 : :
227 : 3 : inline void InitCntHyph() { CntHyphens( nCntEndHyph, nCntMidHyph ); }
228 : 53368 : inline const sal_uInt8 &CntEndHyph() const { return nCntEndHyph; }
229 : 53368 : inline const sal_uInt8 &CntMidHyph() const { return nCntMidHyph; }
230 : 53784 : inline sal_uInt8 &CntEndHyph() { return nCntEndHyph; }
231 : 53784 : inline sal_uInt8 &CntMidHyph() { return nCntMidHyph; }
232 : : };
233 : :
234 : :
235 : :
236 : : #endif
237 : :
238 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|