xref: /AOO41X/main/sw/source/core/text/itrform2.hxx (revision 1d2dbeb0b7301723c6d13094e87a8714ef81a328)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 #ifndef _ITRFORM2_HXX
24 #define _ITRFORM2_HXX
25 #include "itrpaint.hxx"
26 
27 class SwFlyCntPortion;
28 class SwInterHyphInfo;
29 class SwDropPortion;
30 class SwFmtDrop;
31 class SwTxtAttr;
32 class SwNumberPortion;
33 class SwErgoSumPortion;
34 class SwExpandPortion;
35 class SwMultiPortion;
36 class SwFtnPortion;
37 class SvLongs;
38 
39 /*************************************************************************
40  *                      class SwTxtFormatter
41  *************************************************************************/
42 
43 class SwTxtFormatter : public SwTxtPainter
44 {
45     const SwFmtDrop *pDropFmt;
46     SwMultiPortion* pMulti; // during formatting a multi-portion
47     sal_uInt8 nCntEndHyph;  // zaehlt aufeinanderfolgende Hyphens am Zeilenende
48     sal_uInt8 nCntMidHyph;  // zaehlt aufeinanderfolgende Hyphens vor Flies
49     xub_StrLen nLeftScanIdx; // for increasing performance during
50     xub_StrLen nRightScanIdx;     // scanning for portion ends
51     sal_Bool bOnceMore : 1; // noch 'ne Runde?
52     sal_Bool bFlyInCntBase : 1; // Base-Referenz der zeichengeb. Rahmen setzen
53     sal_Bool bChanges : 1; // Flag, fuer die Berechnung des Repaint-Rechtecks
54     sal_Bool bTruncLines : 1; // Flag, Repaint-Rechtecks ggf. erweitern
55     sal_Bool bUnclipped : 1; // Flag, ob Repaint groesser als feste Zeilenhoehe
56     sal_uInt16 m_nHintEndIndex; // HACK for TryNewNoLengthPortion
57     SwLinePortion *NewPortion( SwTxtFormatInfo &rInf );
58     SwTxtPortion  *NewTxtPortion( SwTxtFormatInfo &rInf );
59     SwLinePortion *NewExtraPortion( SwTxtFormatInfo &rInf );
60     SwTabPortion *NewTabPortion( SwTxtFormatInfo &rInf, bool bAuto ) const;
61     SwNumberPortion *NewNumberPortion( SwTxtFormatInfo &rInf ) const;
62     SwDropPortion *NewDropPortion( SwTxtFormatInfo &rInf );
63     SwNumberPortion *NewFtnNumPortion( SwTxtFormatInfo &rInf ) const;
64     SwErgoSumPortion *NewErgoSumPortion( SwTxtFormatInfo &rInf ) const;
65     SwExpandPortion *NewFldPortion( SwTxtFormatInfo &rInf,
66                                     const SwTxtAttr *pHt ) const;
67     SwFtnPortion *NewFtnPortion( SwTxtFormatInfo &rInf, SwTxtAttr *pHt );
68     SwFlyCntPortion *NewFlyCntPortion( SwTxtFormatInfo &rInf,
69                                        SwTxtAttr *pHt ) const;
70     SwLinePortion *WhichFirstPortion( SwTxtFormatInfo &rInf );
71     SwTxtPortion *WhichTxtPor( SwTxtFormatInfo &rInf ) const;
72     SwExpandPortion * TryNewNoLengthPortion( SwTxtFormatInfo & rInfo );
73 
74     // Das Herzstueck der Formatierung
75     void BuildPortions( SwTxtFormatInfo &rInf );
76     sal_Bool BuildMultiPortion( SwTxtFormatInfo &rInf, SwMultiPortion& rMulti );
77 
78     // Berechnung des emulierten rechten Rands
79     void CalcFlyWidth( SwTxtFormatInfo &rInf );
80 
81     // wird von SwTxtFormatter wegen UpdatePos ueberladen
82     void CalcAdjustLine( SwLineLayout *pCurr );
83 
84     // consideres line spacing attributes
85     void CalcRealHeight( sal_Bool bNewLine = sal_False );
86 
87     // uebertraegt die Daten nach rInf
88     void FeedInf( SwTxtFormatInfo &rInf ) const;
89 
90     // behandelt die Unterlaufsituationen
91     SwLinePortion *UnderFlow( SwTxtFormatInfo &rInf );
92 
93     // errechnet den Ascent und die Hoehe aus der Fontmetric
94     void CalcAscent( SwTxtFormatInfo &rInf, SwLinePortion *pPor );
95 
96     // determines, if a optimized repaint rectange is allowed
97     sal_Bool AllowRepaintOpt() const;
98 
99     // calculates and sets the optimized repaint offset
100     long CalcOptRepaint( xub_StrLen nOldLineEnd, const SvLongs* pFlyStart );
101 
102     // wird von FormatLine gerufen.
103     void FormatReset( SwTxtFormatInfo &rInf );
104 
105     // durch das Adjustment aendert sich die Position der Portions
106     void UpdatePos( SwLineLayout *pCurr, Point aStart, xub_StrLen nStartIdx,
107             sal_Bool bAllWays = sal_False ) const;
108 
109     // Setze alle FlyInCntFrms auf die uebergebene BaseLine
110     void AlignFlyInCntBase( long nBaseLine ) const;
111 
112     // Unterlaufbedingungen bei Flys
113     sal_Bool ChkFlyUnderflow( SwTxtFormatInfo &rInf ) const;
114 
115     // Portion einfuegen.
116     void InsertPortion( SwTxtFormatInfo &rInf, SwLinePortion *pPor ) const;
117 
118     // schaetzt die Hoehe fuer die DropPortion
119     void GuessDropHeight( const MSHORT nLines );
120 
121 public:
122     // errechnet die Hoehe fuer die DropPortion
123     void CalcDropHeight( const MSHORT nLines );
124 
125     // errechnet den Bottom des Absatzes, beruecksichtigt an diesem verankerte
126     // Objekte mit Umlauf 1. Absatz.
127     SwTwips CalcBottomLine() const;
128 
129     // Beruecksichtigt zeichengebundene Objekte bei der Repaintrechteck-
130     // berechnung in Zeilen mit fester Zeilenhoehe
131     void CalcUnclipped( SwTwips& rTop, SwTwips& rBottom );
132 
133     // u.a. fuer DropCaps
134     sal_Bool CalcOnceMore();
135 
136     void CtorInitTxtFormatter( SwTxtFrm *pFrm, SwTxtFormatInfo *pInf );
SwTxtFormatter(SwTxtFrm * pTxtFrm,SwTxtFormatInfo * pTxtFmtInf)137     inline SwTxtFormatter( SwTxtFrm *pTxtFrm, SwTxtFormatInfo *pTxtFmtInf ) : SwTxtPainter(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
138            { CtorInitTxtFormatter( pTxtFrm, pTxtFmtInf ); }
139     ~SwTxtFormatter();
140 
141     xub_StrLen FormatLine( const xub_StrLen nStart );
142 
143     void RecalcRealHeight();
144 
145     // Wir formatieren eine Zeile fuer die interaktive Trennung
146     sal_Bool Hyphenate( SwInterHyphInfo &rInf );
147 
148     // Spezialmethode fuer QuoVadis-Texte
149     // nErgo ist die Seitennummer der ErgoSum-Ftn
150     // Bei 0 ist es noch unklar.
151     xub_StrLen FormatQuoVadis( const xub_StrLen nStart );
152 
153     // Die Notbremse: Formatierung abbrechen, Zeile verwerfen.
IsStop() const154     inline sal_Bool IsStop() const { return GetInfo().IsStop(); }
155 
156     // Das Gegenstueck: Formatierung unbedingt fortsetzen.
IsNewLine() const157     inline sal_Bool IsNewLine() const { return GetInfo().IsNewLine(); }
158 
159     // FormatQuick(); auffrischen von Formatinformationen
IsQuick() const160     inline sal_Bool IsQuick() const { return GetInfo().IsQuick(); }
161 
162     // erzeugt ggfs. ein SwLineLayout, dass Ftn/Fly--Oszillation unterbindet.
163     void MakeDummyLine();
164 
165     // SwTxtIter-Funktionalitaet
166     void Insert( SwLineLayout *pLine );
167 
168     // die noch verbleibende Hoehe bis zum Seitenrand
169     KSHORT GetFrmRstHeight() const;
170 
171     // Wie breit waerest Du ohne rechte Begrenzungen (Flys etc.)?
172     SwTwips _CalcFitToContent( );
173 
174     SwLinePortion* MakeRestPortion(const SwLineLayout* pLine, xub_StrLen nPos);
175 
GetDropFmt() const176     inline const SwFmtDrop *GetDropFmt() const { return pDropFmt; }
ClearDropFmt()177     inline void ClearDropFmt() { pDropFmt = 0; }
178 
GetMulti() const179     inline SwMultiPortion *GetMulti() const { return pMulti; }
180 
IsOnceMore() const181     inline sal_Bool IsOnceMore() const { return bOnceMore; }
SetOnceMore(sal_Bool bNew)182     inline void       SetOnceMore( sal_Bool bNew ) { bOnceMore = bNew; }
183 
HasChanges() const184     inline sal_Bool HasChanges() const { return bChanges; }
SetChanges()185     inline void       SetChanges()       { bChanges = sal_True; }
186 
HasTruncLines() const187     inline sal_Bool HasTruncLines() const { return bTruncLines; }
SetTruncLines(sal_Bool bNew)188     inline void       SetTruncLines( sal_Bool bNew ) { bTruncLines = bNew; }
189 
IsUnclipped() const190     inline sal_Bool IsUnclipped() const { return bUnclipped; }
SetUnclipped(sal_Bool bNew)191     inline void       SetUnclipped( sal_Bool bNew ) { bUnclipped = bNew; }
192 
IsFlyInCntBase() const193     inline sal_Bool IsFlyInCntBase() const { return bFlyInCntBase; }
SetFlyInCntBase(sal_Bool bNew=sal_True)194     inline void  SetFlyInCntBase( sal_Bool bNew = sal_True ){ bFlyInCntBase = bNew; }
195 
GetInfo()196     inline SwTxtFormatInfo &GetInfo()
197         { return (SwTxtFormatInfo&)SwTxtIter::GetInfo(); }
GetInfo() const198     inline const SwTxtFormatInfo &GetInfo() const
199         { return (const SwTxtFormatInfo&)SwTxtIter::GetInfo(); }
200 
InitCntHyph()201     inline void InitCntHyph() { CntHyphens( nCntEndHyph, nCntMidHyph ); }
CntEndHyph() const202     inline const sal_uInt8 &CntEndHyph() const { return nCntEndHyph; }
CntMidHyph() const203     inline const sal_uInt8 &CntMidHyph() const { return nCntMidHyph; }
CntEndHyph()204     inline sal_uInt8 &CntEndHyph() { return nCntEndHyph; }
CntMidHyph()205     inline sal_uInt8 &CntMidHyph() { return nCntMidHyph; }
206 };
207 
208 
209 
210 #endif
211