xref: /trunk/main/sw/source/core/text/itrform2.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _ITRFORM2_HXX
28 #define _ITRFORM2_HXX
29 #include "itrpaint.hxx"
30 
31 class SwFlyCntPortion;
32 class SwInterHyphInfo;
33 class SwDropPortion;
34 class SwFmtDrop;
35 class SwTxtAttr;
36 class SwNumberPortion;
37 class SwErgoSumPortion;
38 class SwExpandPortion;
39 class SwMultiPortion;
40 class SwFtnPortion;
41 class SvLongs;
42 
43 /*************************************************************************
44  *                      class SwTxtFormatter
45  *************************************************************************/
46 
47 class SwTxtFormatter : public SwTxtPainter
48 {
49     const SwFmtDrop *pDropFmt;
50     SwMultiPortion* pMulti; // during formatting a multi-portion
51     sal_uInt8 nCntEndHyph;  // zaehlt aufeinanderfolgende Hyphens am Zeilenende
52     sal_uInt8 nCntMidHyph;  // zaehlt aufeinanderfolgende Hyphens vor Flies
53     xub_StrLen nLeftScanIdx; // for increasing performance during
54     xub_StrLen nRightScanIdx;     // scanning for portion ends
55     sal_Bool bOnceMore : 1; // noch 'ne Runde?
56     sal_Bool bFlyInCntBase : 1; // Base-Referenz der zeichengeb. Rahmen setzen
57     sal_Bool bChanges : 1; // Flag, fuer die Berechnung des Repaint-Rechtecks
58     sal_Bool bTruncLines : 1; // Flag, Repaint-Rechtecks ggf. erweitern
59     sal_Bool bUnclipped : 1; // Flag, ob Repaint groesser als feste Zeilenhoehe
60     sal_uInt16 m_nHintEndIndex; // HACK for TryNewNoLengthPortion
61     SwLinePortion *NewPortion( SwTxtFormatInfo &rInf );
62     SwTxtPortion  *NewTxtPortion( SwTxtFormatInfo &rInf );
63     SwLinePortion *NewExtraPortion( SwTxtFormatInfo &rInf );
64     SwTabPortion *NewTabPortion( SwTxtFormatInfo &rInf, bool bAuto ) const;
65     SwNumberPortion *NewNumberPortion( SwTxtFormatInfo &rInf ) const;
66     SwDropPortion *NewDropPortion( SwTxtFormatInfo &rInf );
67     SwNumberPortion *NewFtnNumPortion( SwTxtFormatInfo &rInf ) const;
68     SwErgoSumPortion *NewErgoSumPortion( SwTxtFormatInfo &rInf ) const;
69     SwExpandPortion *NewFldPortion( SwTxtFormatInfo &rInf,
70                                     const SwTxtAttr *pHt ) const;
71     SwFtnPortion *NewFtnPortion( SwTxtFormatInfo &rInf, SwTxtAttr *pHt );
72     SwFlyCntPortion *NewFlyCntPortion( SwTxtFormatInfo &rInf,
73                                        SwTxtAttr *pHt ) const;
74     SwLinePortion *WhichFirstPortion( SwTxtFormatInfo &rInf );
75     SwTxtPortion *WhichTxtPor( SwTxtFormatInfo &rInf ) const;
76     SwExpandPortion * TryNewNoLengthPortion( SwTxtFormatInfo & rInfo );
77 
78     // Das Herzstueck der Formatierung
79     void BuildPortions( SwTxtFormatInfo &rInf );
80     sal_Bool BuildMultiPortion( SwTxtFormatInfo &rInf, SwMultiPortion& rMulti );
81 
82     // Berechnung des emulierten rechten Rands
83     void CalcFlyWidth( SwTxtFormatInfo &rInf );
84 
85     // wird von SwTxtFormatter wegen UpdatePos ueberladen
86     void CalcAdjustLine( SwLineLayout *pCurr );
87 
88     // consideres line spacing attributes
89     void CalcRealHeight( sal_Bool bNewLine = sal_False );
90 
91     // uebertraegt die Daten nach rInf
92     void FeedInf( SwTxtFormatInfo &rInf ) const;
93 
94     // behandelt die Unterlaufsituationen
95     SwLinePortion *UnderFlow( SwTxtFormatInfo &rInf );
96 
97     // errechnet den Ascent und die Hoehe aus der Fontmetric
98     void CalcAscent( SwTxtFormatInfo &rInf, SwLinePortion *pPor );
99 
100     // determines, if a optimized repaint rectange is allowed
101     sal_Bool AllowRepaintOpt() const;
102 
103     // calculates and sets the optimized repaint offset
104     long CalcOptRepaint( xub_StrLen nOldLineEnd, const SvLongs* pFlyStart );
105 
106     // wird von FormatLine gerufen.
107     void FormatReset( SwTxtFormatInfo &rInf );
108 
109     // durch das Adjustment aendert sich die Position der Portions
110     void UpdatePos( SwLineLayout *pCurr, Point aStart, xub_StrLen nStartIdx,
111             sal_Bool bAllWays = sal_False ) const;
112 
113     // Setze alle FlyInCntFrms auf die uebergebene BaseLine
114     void AlignFlyInCntBase( long nBaseLine ) const;
115 
116     // Unterlaufbedingungen bei Flys
117     sal_Bool ChkFlyUnderflow( SwTxtFormatInfo &rInf ) const;
118 
119     // Portion einfuegen.
120     void InsertPortion( SwTxtFormatInfo &rInf, SwLinePortion *pPor ) const;
121 
122     // schaetzt die Hoehe fuer die DropPortion
123     void GuessDropHeight( const MSHORT nLines );
124 
125 public:
126     // errechnet die Hoehe fuer die DropPortion
127     void CalcDropHeight( const MSHORT nLines );
128 
129     // errechnet den Bottom des Absatzes, beruecksichtigt an diesem verankerte
130     // Objekte mit Umlauf 1. Absatz.
131     SwTwips CalcBottomLine() const;
132 
133     // Beruecksichtigt zeichengebundene Objekte bei der Repaintrechteck-
134     // berechnung in Zeilen mit fester Zeilenhoehe
135     void CalcUnclipped( SwTwips& rTop, SwTwips& rBottom );
136 
137     // u.a. fuer DropCaps
138     sal_Bool CalcOnceMore();
139 
140     void CtorInitTxtFormatter( SwTxtFrm *pFrm, SwTxtFormatInfo *pInf );
141     inline SwTxtFormatter( SwTxtFrm *pTxtFrm, SwTxtFormatInfo *pTxtFmtInf ) : SwTxtPainter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
142            { CtorInitTxtFormatter( pTxtFrm, pTxtFmtInf ); }
143     ~SwTxtFormatter();
144 
145     xub_StrLen FormatLine( const xub_StrLen nStart );
146 
147     void RecalcRealHeight();
148 
149     // Wir formatieren eine Zeile fuer die interaktive Trennung
150     sal_Bool Hyphenate( SwInterHyphInfo &rInf );
151 
152     // Spezialmethode fuer QuoVadis-Texte
153     // nErgo ist die Seitennummer der ErgoSum-Ftn
154     // Bei 0 ist es noch unklar.
155     xub_StrLen FormatQuoVadis( const xub_StrLen nStart );
156 
157     // Die Notbremse: Formatierung abbrechen, Zeile verwerfen.
158     inline sal_Bool IsStop() const { return GetInfo().IsStop(); }
159 
160     // Das Gegenstueck: Formatierung unbedingt fortsetzen.
161     inline sal_Bool IsNewLine() const { return GetInfo().IsNewLine(); }
162 
163     // FormatQuick(); auffrischen von Formatinformationen
164     inline sal_Bool IsQuick() const { return GetInfo().IsQuick(); }
165 
166     // erzeugt ggfs. ein SwLineLayout, dass Ftn/Fly--Oszillation unterbindet.
167     void MakeDummyLine();
168 
169     // SwTxtIter-Funktionalitaet
170     void Insert( SwLineLayout *pLine );
171 
172     // die noch verbleibende Hoehe bis zum Seitenrand
173     KSHORT GetFrmRstHeight() const;
174 
175     // Wie breit waerest Du ohne rechte Begrenzungen (Flys etc.)?
176     SwTwips _CalcFitToContent( );
177 
178     SwLinePortion* MakeRestPortion(const SwLineLayout* pLine, xub_StrLen nPos);
179 
180     inline const SwFmtDrop *GetDropFmt() const { return pDropFmt; }
181     inline void ClearDropFmt() { pDropFmt = 0; }
182 
183     inline SwMultiPortion *GetMulti() const { return pMulti; }
184 
185     inline sal_Bool IsOnceMore() const { return bOnceMore; }
186     inline void       SetOnceMore( sal_Bool bNew ) { bOnceMore = bNew; }
187 
188     inline sal_Bool HasChanges() const { return bChanges; }
189     inline void       SetChanges()       { bChanges = sal_True; }
190 
191     inline sal_Bool HasTruncLines() const { return bTruncLines; }
192     inline void       SetTruncLines( sal_Bool bNew ) { bTruncLines = bNew; }
193 
194     inline sal_Bool IsUnclipped() const { return bUnclipped; }
195     inline void       SetUnclipped( sal_Bool bNew ) { bUnclipped = bNew; }
196 
197     inline sal_Bool IsFlyInCntBase() const { return bFlyInCntBase; }
198     inline void  SetFlyInCntBase( sal_Bool bNew = sal_True ){ bFlyInCntBase = bNew; }
199 
200     inline SwTxtFormatInfo &GetInfo()
201         { return (SwTxtFormatInfo&)SwTxtIter::GetInfo(); }
202     inline const SwTxtFormatInfo &GetInfo() const
203         { return (const SwTxtFormatInfo&)SwTxtIter::GetInfo(); }
204 
205     inline void InitCntHyph() { CntHyphens( nCntEndHyph, nCntMidHyph ); }
206     inline const sal_uInt8 &CntEndHyph() const { return nCntEndHyph; }
207     inline const sal_uInt8 &CntMidHyph() const { return nCntMidHyph; }
208     inline sal_uInt8 &CntEndHyph() { return nCntEndHyph; }
209     inline sal_uInt8 &CntMidHyph() { return nCntMidHyph; }
210 };
211 
212 
213 
214 #endif
215