xref: /AOO41X/main/sw/source/core/text/porlay.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 _PORLAY_HXX
24 #define _PORLAY_HXX
25 
26 #include <tools/string.hxx>
27 #include <tools/fract.hxx>
28 #include <scriptinfo.hxx>
29 
30 #include "swrect.hxx"   // SwRepaint
31 #include "portxt.hxx"
32 #include "swfont.hxx"
33 
34 #include <vector>
35 
36 class SwMarginPortion;
37 class SwDropPortion;
38 class SvStream;
39 class SwTxtFormatter;
40 
41 /*************************************************************************
42  *                      class SwCharRange
43  *************************************************************************/
44 
45 class SwCharRange
46 {
47     xub_StrLen nStart, nLen;
48 public:
SwCharRange(const xub_StrLen nInitStart=0,const xub_StrLen nInitLen=0)49     inline SwCharRange( const xub_StrLen nInitStart = 0,
50         const xub_StrLen nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
Start()51     inline xub_StrLen &Start() { return nStart; }
Start() const52     inline const xub_StrLen &Start() const { return nStart; }
LeftMove(xub_StrLen nNew)53     inline void LeftMove( xub_StrLen nNew )
54             { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
End() const55     inline xub_StrLen End() const
56                 { return nStart + nLen; }
Len()57     inline xub_StrLen &Len() { return nLen; }
Len() const58     inline const xub_StrLen &Len() const { return nLen; }
operator <(const SwCharRange & rRange) const59     inline sal_Bool operator<(const SwCharRange &rRange) const
60                 { return nStart < rRange.nStart; }
operator >(const SwCharRange & rRange) const61     inline sal_Bool operator>(const SwCharRange &rRange) const
62                 { return nStart + nLen > rRange.nStart + rRange.nLen; }
operator !=(const SwCharRange & rRange) const63     inline sal_Bool operator!=(const SwCharRange &rRange) const
64                 { return *this < rRange || *this > rRange; }
65     SwCharRange &operator+=(const SwCharRange &rRange);
66 };
67 
68 /*************************************************************************
69  *                      class SwRepaint
70  *************************************************************************/
71 
72 // SwRepaint ist ein dokumentglobales SwRect mit einem nOfst der angibt,
73 // ab wo in der ersten Zeile gepaintet werden soll
74 // und einem nRightOfst, der den rechten Rand bestimmt
75 class SwRepaint : public SwRect
76 {
77     SwTwips nOfst;
78     SwTwips nRightOfst;
79 public:
SwRepaint()80     SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
SwRepaint(const SwRepaint & rRep)81     SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
82         nRightOfst( rRep.nRightOfst ) {}
83 
GetOfst() const84     SwTwips GetOfst() const { return nOfst; }
SetOfst(const SwTwips nNew)85     void   SetOfst( const SwTwips nNew ) { nOfst = nNew; }
GetRightOfst() const86     SwTwips GetRightOfst() const { return nRightOfst; }
SetRightOfst(const SwTwips nNew)87     void   SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
88 };
89 
90 /*************************************************************************
91  *                      class SwLineLayout
92  *************************************************************************/
93 
94 class SwLineLayout : public SwTxtPortion
95 {
96 private:
97     SwLineLayout *pNext;                // Die naechste Zeile.
98     std::vector<long>* pLLSpaceAdd;     // Used for justified alignment.
99     SvUShorts* pKanaComp;               // Used for Kana compression.
100     KSHORT nRealHeight;                 // Die aus Zeilenabstand/Register resultierende Hoehe.
101     sal_Bool bFormatAdj : 1;
102     sal_Bool bDummy     : 1;
103     sal_Bool bFntChg    : 1;
104     sal_Bool bEndHyph   : 1;
105     sal_Bool bMidHyph   : 1;
106     sal_Bool bTab       : 1;
107     sal_Bool bFly       : 1;
108     sal_Bool bRest      : 1;
109     sal_Bool bBlinking  : 1;
110     sal_Bool bClipping  : 1; // Clipping erforderlich wg. exakter Zeilenhoehe
111     sal_Bool bContent   : 1; // enthaelt Text, fuer Zeilennumerierung
112     sal_Bool bRedline   : 1; // enthaelt Redlining
113     sal_Bool bForcedLeftMargin : 1; // vom Fly verschobener linker Einzug
114     sal_Bool bHanging : 1; // contents a hanging portion in the margin
115     sal_Bool bUnderscore : 1;
116 
117     SwTwips _GetHangingMargin() const;
118 
119 public:
120     // von SwLinePortion
121     virtual SwLinePortion *Insert( SwLinePortion *pPortion );
122     virtual SwLinePortion *Append( SwLinePortion *pPortion );
123     inline SwLinePortion *GetFirstPortion() const;
124 
125     // Flags
126     inline void ResetFlags();
SetFormatAdj(const sal_Bool bNew)127     inline void SetFormatAdj( const sal_Bool bNew ) { bFormatAdj = bNew; }
IsFormatAdj() const128     inline sal_Bool IsFormatAdj() const { return bFormatAdj; }
SetFntChg(const sal_Bool bNew)129     inline void SetFntChg( const sal_Bool bNew ) { bFntChg = bNew; }
IsFntChg() const130     inline sal_Bool IsFntChg() const { return bFntChg; }
SetEndHyph(const sal_Bool bNew)131     inline void SetEndHyph( const sal_Bool bNew ) { bEndHyph = bNew; }
IsEndHyph() const132     inline sal_Bool IsEndHyph() const { return bEndHyph; }
SetMidHyph(const sal_Bool bNew)133     inline void SetMidHyph( const sal_Bool bNew ) { bMidHyph = bNew; }
IsMidHyph() const134     inline sal_Bool IsMidHyph() const { return bMidHyph; }
SetTab(const sal_Bool bNew)135     inline void SetTab( const sal_Bool bNew ) { bTab = bNew; }
IsTab() const136     inline sal_Bool IsTab() const { return bTab; }
SetFly(const sal_Bool bNew)137     inline void SetFly( const sal_Bool bNew ) { bFly = bNew; }
IsFly() const138     inline sal_Bool IsFly() const { return bFly; }
SetRest(const sal_Bool bNew)139     inline void SetRest( const sal_Bool bNew ) { bRest = bNew; }
IsRest() const140     inline sal_Bool IsRest() const { return bRest; }
SetBlinking(const sal_Bool bNew=sal_True)141     inline void SetBlinking( const sal_Bool bNew = sal_True ) { bBlinking = bNew; }
IsBlinking() const142     inline sal_Bool IsBlinking() const { return bBlinking; }
SetCntnt(const sal_Bool bNew=sal_True)143     inline void SetCntnt( const sal_Bool bNew = sal_True ) { bContent = bNew; }
HasCntnt() const144     inline sal_Bool HasCntnt() const { return bContent; }
SetRedline(const sal_Bool bNew=sal_True)145     inline void SetRedline( const sal_Bool bNew = sal_True ) { bRedline = bNew; }
HasRedline() const146     inline sal_Bool HasRedline() const { return bRedline; }
SetForcedLeftMargin(const sal_Bool bNew=sal_True)147     inline void SetForcedLeftMargin( const sal_Bool bNew = sal_True ) { bForcedLeftMargin = bNew; }
HasForcedLeftMargin() const148     inline sal_Bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
SetHanging(const sal_Bool bNew=sal_True)149     inline void SetHanging( const sal_Bool bNew = sal_True ) { bHanging = bNew; }
IsHanging() const150     inline sal_Bool IsHanging() const { return bHanging; }
SetUnderscore(const sal_Bool bNew=sal_True)151     inline void SetUnderscore( const sal_Bool bNew = sal_True ) { bUnderscore = bNew; }
HasUnderscore() const152     inline sal_Bool HasUnderscore() const { return bUnderscore; }
153 
154     // Beruecksichtigung von Dummyleerzeilen
155     // 4147, 8221:
SetDummy(const sal_Bool bNew)156     inline void SetDummy( const sal_Bool bNew ) { bDummy = bNew; }
IsDummy() const157     inline sal_Bool IsDummy() const { return bDummy; }
158 
SetClipping(const sal_Bool bNew)159     inline void SetClipping( const sal_Bool bNew ) { bClipping = bNew; }
IsClipping() const160     inline sal_Bool IsClipping() const { return bClipping; }
161 
162     inline SwLineLayout();
163     virtual ~SwLineLayout();
164 
GetNext()165     inline SwLineLayout *GetNext() { return pNext; }
GetNext() const166     inline const SwLineLayout *GetNext() const { return pNext; }
SetNext(SwLineLayout * pNew)167     inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
168 
169     void Init( SwLinePortion *pNextPortion = NULL);
170 
171     // Sammelt die Daten fuer die Zeile.
172     void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
173 
SetRealHeight(KSHORT nNew)174     inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
GetRealHeight() const175     inline KSHORT GetRealHeight() const { return nRealHeight; }
176 
177     // Erstellt bei kurzen Zeilen die Glue-Kette.
178     SwMarginPortion *CalcLeftMargin();
179 
GetHangingMargin() const180     inline SwTwips GetHangingMargin() const
181         { return _GetHangingMargin(); }
182 
183     // fuer die Sonderbehandlung bei leeren Zeilen
184     virtual sal_Bool Format( SwTxtFormatInfo &rInf );
185 
186     //
187     // STUFF FOR JUSTIFIED ALIGNMENT
188     //
IsSpaceAdd()189     inline sal_Bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
190     void InitSpaceAdd();     // Creates pLLSpaceAdd if necessary
191     void CreateSpaceAdd( const long nInit = 0 );
FinishSpaceAdd()192     inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
GetLLSpaceAddCount() const193     inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
SetLLSpaceAdd(long nNew,sal_uInt16 nIdx)194     inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
195     {
196         if ( nIdx == GetLLSpaceAddCount() )
197             pLLSpaceAdd->push_back( nNew );
198         else
199             (*pLLSpaceAdd)[ nIdx ] = nNew;
200     }
GetLLSpaceAdd(sal_uInt16 nIdx)201     inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
RemoveFirstLLSpaceAdd()202     inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
GetpLLSpaceAdd() const203     inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
204 
205     //
206     // STUFF FOR KANA COMPRESSION
207     //
SetKanaComp(SvUShorts * pNew)208     inline void SetKanaComp( SvUShorts* pNew ){ pKanaComp = pNew; }
FinishKanaComp()209     inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
GetpKanaComp() const210     inline SvUShorts* GetpKanaComp() const { return pKanaComp; }
GetKanaComp()211     inline SvUShorts& GetKanaComp() { return *pKanaComp; }
212 
213     /** determine ascent and descent for positioning of as-character anchored
214         object
215 
216         OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
217         Method calculates maximum ascents and descents of the line layout.
218         One value considering as-character anchored objects, one without these
219         objects.
220         Portions for other anchored objects aren't considered.
221         OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
222         to control, if the fly content portions and line portion are considered.
223 
224         @param _orAscent
225         output parameter - maximum ascent without as-character anchored objects
226 
227         @param _orDescent
228         output parameter - maximum descent without as-character anchored objects
229 
230         @param _orObjAscent
231         output parameter - maximum ascent with as-character anchored objects
232 
233         @param _orObjDescent
234         output parameter - maximum descent with as-character anchored objects
235 
236         @param _pDontConsiderPortion
237         input parameter - portion, which isn't considered for calculating
238         <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
239         as-character anchored object or it isn't as high as the line.
240 
241         @param _bNoFlyCntPorAndLinePor
242         optional input parameter - boolean, indicating that fly content portions
243         and the line portion are considered or not.
244 
245         @author OD
246     */
247     void MaxAscentDescent( SwTwips& _orAscent,
248                            SwTwips& _orDescent,
249                            SwTwips& _orObjAscent,
250                            SwTwips& _orObjDescent,
251                            const SwLinePortion* _pDontConsiderPortion = NULL,
252                            const bool _bNoFlyCntPorAndLinePor = false ) const;
253 
254 #ifdef DBG_UTIL
255     void DebugPortions( SvStream &rOs, const XubString &rTxt,
256                         const xub_StrLen nStart ); //$ ostream
257 #endif
258 
259     OUTPUT_OPERATOR
260     DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
261 };
262 
263 class SwParaPortion : public SwLineLayout
264 {
265     // neu zu paintender Bereich
266     SwRepaint aRepaint;
267     // neu zu formatierender Bereich
268     SwCharRange aReformat;
269     SwScriptInfo aScriptInfo;
270 //   Fraction aZoom;
271     long nDelta;
272 
273     // Wenn ein SwTxtFrm gelocked ist, werden keine Veraenderungen an den
274     // Formatierungsdaten (unter pLine) vorgenommen (vgl. ORPHANS)
275     sal_Bool bFlys          : 1; // Ueberlappen Flys ?
276     sal_Bool bPrep          : 1; // PREP_*
277     sal_Bool bPrepWidows    : 1; // PREP_WIDOWS
278     sal_Bool bPrepAdjust    : 1; // PREP_ADJUST_FRM
279     sal_Bool bPrepMustFit   : 1; // PREP_MUST_FIT
280     sal_Bool bFollowField   : 1; // Es steht noch ein Feldrest fuer den Follow an.
281 
282     sal_Bool bFixLineHeight : 1; // Feste Zeilenhoehe
283     sal_Bool bFtnNum    : 1; // contents a footnotenumberportion
284     sal_Bool bMargin    : 1; // contents a hanging punctuation in the margin
285 
286     sal_Bool bFlag00    : 1; //
287     sal_Bool bFlag11    : 1; //
288     sal_Bool bFlag12    : 1; //
289     sal_Bool bFlag13    : 1; //
290     sal_Bool bFlag14    : 1; //
291     sal_Bool bFlag15    : 1; //
292     sal_Bool bFlag16    : 1; //
293 
294 public:
295     SwParaPortion();
296     virtual ~SwParaPortion();
297 
298     // setzt alle Formatinformationen zurueck (ausser bFlys wg. 9916)
299     inline void FormatReset();
300 
301     // Setzt die Flags zurueck
302     inline void ResetPreps();
303 
304     // Get/Set-Methoden
GetRepaint()305     inline SwRepaint *GetRepaint() { return &aRepaint; }
GetRepaint() const306     inline const SwRepaint *GetRepaint() const { return &aRepaint; }
GetReformat()307     inline SwCharRange *GetReformat() { return &aReformat; }
GetReformat() const308     inline const SwCharRange *GetReformat() const { return &aReformat; }
GetDelta()309     inline long *GetDelta() { return &nDelta; }
GetDelta() const310     inline const long *GetDelta() const { return &nDelta; }
GetScriptInfo()311     inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
GetScriptInfo() const312     inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
313 
314     // fuer SwTxtFrm::Format: liefert die aktuelle Laenge des Absatzes
315     xub_StrLen GetParLen() const;
316 
317     // fuer Prepare()
318     sal_Bool UpdateQuoVadis( const XubString &rQuo );
319 
320     // Flags
SetFly(const sal_Bool bNew=sal_True)321     inline void SetFly( const sal_Bool bNew = sal_True ) { bFlys = bNew; }
HasFly() const322     inline sal_Bool HasFly() const { return bFlys; }
323 
324     // Preps
SetPrep(const sal_Bool bNew=sal_True)325     inline void SetPrep( const sal_Bool bNew = sal_True ) { bPrep = bNew; }
IsPrep() const326     inline sal_Bool IsPrep() const { return bPrep; }
SetPrepWidows(const sal_Bool bNew=sal_True)327     inline void SetPrepWidows( const sal_Bool bNew = sal_True ) { bPrepWidows = bNew; }
IsPrepWidows() const328     inline sal_Bool IsPrepWidows() const { return bPrepWidows; }
SetPrepMustFit(const sal_Bool bNew=sal_True)329     inline void SetPrepMustFit( const sal_Bool bNew = sal_True ) { bPrepMustFit = bNew; }
IsPrepMustFit() const330     inline sal_Bool IsPrepMustFit() const { return bPrepMustFit; }
SetPrepAdjust(const sal_Bool bNew=sal_True)331     inline void SetPrepAdjust( const sal_Bool bNew = sal_True ) { bPrepAdjust = bNew; }
IsPrepAdjust() const332     inline sal_Bool IsPrepAdjust() const { return bPrepAdjust; }
SetFollowField(const sal_Bool bNew=sal_True)333     inline void SetFollowField( const sal_Bool bNew = sal_True ) { bFollowField = bNew; }
IsFollowField() const334     inline sal_Bool IsFollowField() const { return bFollowField; }
SetFixLineHeight(const sal_Bool bNew=sal_True)335     inline void SetFixLineHeight( const sal_Bool bNew = sal_True ) { bFixLineHeight = bNew; }
IsFixLineHeight() const336     inline sal_Bool  IsFixLineHeight() const { return bFixLineHeight; }
337 
SetFtnNum(const sal_Bool bNew=sal_True)338     inline void SetFtnNum( const sal_Bool bNew = sal_True ) { bFtnNum = bNew; }
IsFtnNum() const339     inline sal_Bool  IsFtnNum() const { return bFtnNum; }
SetMargin(const sal_Bool bNew=sal_True)340     inline void SetMargin( const sal_Bool bNew = sal_True ) { bMargin = bNew; }
IsMargin() const341     inline sal_Bool  IsMargin() const { return bMargin; }
SetFlag00(const sal_Bool bNew=sal_True)342     inline void SetFlag00( const sal_Bool bNew = sal_True ) { bFlag00 = bNew; }
IsFlag00() const343     inline sal_Bool  IsFlag00() const { return bFlag00; }
SetFlag11(const sal_Bool bNew=sal_True)344     inline void SetFlag11( const sal_Bool bNew = sal_True ) { bFlag11 = bNew; }
IsFlag11() const345     inline sal_Bool  IsFlag11() const { return bFlag11; }
SetFlag12(const sal_Bool bNew=sal_True)346     inline void SetFlag12( const sal_Bool bNew = sal_True ) { bFlag12 = bNew; }
IsFlag12() const347     inline sal_Bool  IsFlag12() const { return bFlag12; }
SetFlag13(const sal_Bool bNew=sal_True)348     inline void SetFlag13( const sal_Bool bNew = sal_True ) { bFlag13 = bNew; }
IsFlag13() const349     inline sal_Bool  IsFlag13() const { return bFlag13; }
SetFlag14(const sal_Bool bNew=sal_True)350     inline void SetFlag14( const sal_Bool bNew = sal_True ) { bFlag14 = bNew; }
IsFlag14() const351     inline sal_Bool  IsFlag14() const { return bFlag14; }
SetFlag15(const sal_Bool bNew=sal_True)352     inline void SetFlag15( const sal_Bool bNew = sal_True ) { bFlag15 = bNew; }
IsFlag15() const353     inline sal_Bool  IsFlag15() const { return bFlag15; }
SetFlag16(const sal_Bool bNew=sal_True)354     inline void SetFlag16( const sal_Bool bNew = sal_True ) { bFlag16 = bNew; }
IsFlag16() const355     inline sal_Bool  IsFlag16() const { return bFlag16; }
356 
357     // schneller, hoeher, weiter: Read/Write-Methoden fuer den SWG-Filter
358     SvStream &ReadSwg ( SvStream& rStream ); //$ istream
359     SvStream &WriteSwg( SvStream& rStream ); //$ ostream
360 
361     // nErgo in der QuoVadisPortion setzen
362     void SetErgoSumNum( const XubString &rErgo );
363 
364     const SwDropPortion *FindDropPortion() const;
365 
366     OUTPUT_OPERATOR
367     DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
368 };
369 
370 /*************************************************************************
371  *                      Inline-Implementierungen
372  *************************************************************************/
373 
ResetFlags()374 inline void SwLineLayout::ResetFlags()
375 {
376     bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
377     = bRest = bBlinking = bClipping = bContent = bRedline
378     = bForcedLeftMargin = bHanging = sal_False;
379 }
380 
SwLineLayout()381 inline SwLineLayout::SwLineLayout()
382     : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
383       bUnderscore( sal_False )
384 {
385     ResetFlags();
386     SetWhichPor( POR_LAY );
387 }
388 
ResetPreps()389 inline void SwParaPortion::ResetPreps()
390 {
391     bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = sal_False;
392 }
393 
FormatReset()394 inline void SwParaPortion::FormatReset()
395 {
396     nDelta = 0;
397     aReformat = SwCharRange( 0, STRING_LEN );
398 //  AMA 9916: bFlys muss in SwTxtFrm::_Format() erhalten bleiben, damit
399 //  leere Absaetze, die Rahmen ohne Umfluss ausweichen mussten, sich
400 //  neu formatieren, wenn der Rahmen aus dem Bereich verschwindet.
401 //  bFlys = sal_False;
402     ResetPreps();
403     bFollowField = bFixLineHeight = bMargin = sal_False;
404 }
405 
406 #ifdef UNX
407 // C30 ist mit dem ternaeren Ausdruck ueberfordert.
GetFirstPortion() const408 inline SwLinePortion *SwLineLayout::GetFirstPortion() const
409 {
410     SwLinePortion *pTmp = pPortion;
411     if ( !pPortion )
412         pTmp = (SwLinePortion*)this;
413     return( pTmp );
414 }
415 #else
GetFirstPortion() const416 inline SwLinePortion *SwLineLayout::GetFirstPortion() const
417 { return( pPortion ? pPortion : (SwLinePortion*)this ); }
418 #endif
419 
420 CLASSIO( SwLineLayout )
421 CLASSIO( SwParaPortion )
422 
423 #endif
424