xref: /trunk/main/sw/source/core/text/porlay.hxx (revision cea84f56765a2ac06f0f5a2718f45f6430edc781) !
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     SwRepaint& operator=(const SwRepaint&) = default;
84 
GetOfst() const85     SwTwips GetOfst() const { return nOfst; }
SetOfst(const SwTwips nNew)86     void   SetOfst( const SwTwips nNew ) { nOfst = nNew; }
GetRightOfst() const87     SwTwips GetRightOfst() const { return nRightOfst; }
SetRightOfst(const SwTwips nNew)88     void   SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
89 };
90 
91 /*************************************************************************
92  *                      class SwLineLayout
93  *************************************************************************/
94 
95 class SwLineLayout : public SwTxtPortion
96 {
97 private:
98     SwLineLayout *pNext;                // Die naechste Zeile.
99     std::vector<long>* pLLSpaceAdd;     // Used for justified alignment.
100     SvUShorts* pKanaComp;               // Used for Kana compression.
101     KSHORT nRealHeight;                 // Die aus Zeilenabstand/Register resultierende Hoehe.
102     sal_Bool bFormatAdj : 1;
103     sal_Bool bDummy     : 1;
104     sal_Bool bFntChg    : 1;
105     sal_Bool bEndHyph   : 1;
106     sal_Bool bMidHyph   : 1;
107     sal_Bool bTab       : 1;
108     sal_Bool bFly       : 1;
109     sal_Bool bRest      : 1;
110     sal_Bool bBlinking  : 1;
111     sal_Bool bClipping  : 1; // Clipping erforderlich wg. exakter Zeilenhoehe
112     sal_Bool bContent   : 1; // enthaelt Text, fuer Zeilennumerierung
113     sal_Bool bRedline   : 1; // enthaelt Redlining
114     sal_Bool bForcedLeftMargin : 1; // vom Fly verschobener linker Einzug
115     sal_Bool bHanging : 1; // contents a hanging portion in the margin
116     sal_Bool bUnderscore : 1;
117 
118     SwTwips _GetHangingMargin() const;
119 
120 public:
121     // von SwLinePortion
122     virtual SwLinePortion *Insert( SwLinePortion *pPortion );
123     virtual SwLinePortion *Append( SwLinePortion *pPortion );
124     inline SwLinePortion *GetFirstPortion() const;
125 
126     // Flags
127     inline void ResetFlags();
SetFormatAdj(const sal_Bool bNew)128     inline void SetFormatAdj( const sal_Bool bNew ) { bFormatAdj = bNew; }
IsFormatAdj() const129     inline sal_Bool IsFormatAdj() const { return bFormatAdj; }
SetFntChg(const sal_Bool bNew)130     inline void SetFntChg( const sal_Bool bNew ) { bFntChg = bNew; }
IsFntChg() const131     inline sal_Bool IsFntChg() const { return bFntChg; }
SetEndHyph(const sal_Bool bNew)132     inline void SetEndHyph( const sal_Bool bNew ) { bEndHyph = bNew; }
IsEndHyph() const133     inline sal_Bool IsEndHyph() const { return bEndHyph; }
SetMidHyph(const sal_Bool bNew)134     inline void SetMidHyph( const sal_Bool bNew ) { bMidHyph = bNew; }
IsMidHyph() const135     inline sal_Bool IsMidHyph() const { return bMidHyph; }
SetTab(const sal_Bool bNew)136     inline void SetTab( const sal_Bool bNew ) { bTab = bNew; }
IsTab() const137     inline sal_Bool IsTab() const { return bTab; }
SetFly(const sal_Bool bNew)138     inline void SetFly( const sal_Bool bNew ) { bFly = bNew; }
IsFly() const139     inline sal_Bool IsFly() const { return bFly; }
SetRest(const sal_Bool bNew)140     inline void SetRest( const sal_Bool bNew ) { bRest = bNew; }
IsRest() const141     inline sal_Bool IsRest() const { return bRest; }
SetBlinking(const sal_Bool bNew=sal_True)142     inline void SetBlinking( const sal_Bool bNew = sal_True ) { bBlinking = bNew; }
IsBlinking() const143     inline sal_Bool IsBlinking() const { return bBlinking; }
SetCntnt(const sal_Bool bNew=sal_True)144     inline void SetCntnt( const sal_Bool bNew = sal_True ) { bContent = bNew; }
HasCntnt() const145     inline sal_Bool HasCntnt() const { return bContent; }
SetRedline(const sal_Bool bNew=sal_True)146     inline void SetRedline( const sal_Bool bNew = sal_True ) { bRedline = bNew; }
HasRedline() const147     inline sal_Bool HasRedline() const { return bRedline; }
SetForcedLeftMargin(const sal_Bool bNew=sal_True)148     inline void SetForcedLeftMargin( const sal_Bool bNew = sal_True ) { bForcedLeftMargin = bNew; }
HasForcedLeftMargin() const149     inline sal_Bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
SetHanging(const sal_Bool bNew=sal_True)150     inline void SetHanging( const sal_Bool bNew = sal_True ) { bHanging = bNew; }
IsHanging() const151     inline sal_Bool IsHanging() const { return bHanging; }
SetUnderscore(const sal_Bool bNew=sal_True)152     inline void SetUnderscore( const sal_Bool bNew = sal_True ) { bUnderscore = bNew; }
HasUnderscore() const153     inline sal_Bool HasUnderscore() const { return bUnderscore; }
154 
155     // Beruecksichtigung von Dummyleerzeilen
156     // 4147, 8221:
SetDummy(const sal_Bool bNew)157     inline void SetDummy( const sal_Bool bNew ) { bDummy = bNew; }
IsDummy() const158     inline sal_Bool IsDummy() const { return bDummy; }
159 
SetClipping(const sal_Bool bNew)160     inline void SetClipping( const sal_Bool bNew ) { bClipping = bNew; }
IsClipping() const161     inline sal_Bool IsClipping() const { return bClipping; }
162 
163     inline SwLineLayout();
164     virtual ~SwLineLayout();
165 
GetNext()166     inline SwLineLayout *GetNext() { return pNext; }
GetNext() const167     inline const SwLineLayout *GetNext() const { return pNext; }
SetNext(SwLineLayout * pNew)168     inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
169 
170     void Init( SwLinePortion *pNextPortion = NULL);
171 
172     // Sammelt die Daten fuer die Zeile.
173     void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
174 
SetRealHeight(KSHORT nNew)175     inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
GetRealHeight() const176     inline KSHORT GetRealHeight() const { return nRealHeight; }
177 
178     // Erstellt bei kurzen Zeilen die Glue-Kette.
179     SwMarginPortion *CalcLeftMargin();
180 
GetHangingMargin() const181     inline SwTwips GetHangingMargin() const
182         { return _GetHangingMargin(); }
183 
184     // fuer die Sonderbehandlung bei leeren Zeilen
185     virtual sal_Bool Format( SwTxtFormatInfo &rInf );
186 
187     //
188     // STUFF FOR JUSTIFIED ALIGNMENT
189     //
IsSpaceAdd()190     inline sal_Bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
191     void InitSpaceAdd();     // Creates pLLSpaceAdd if necessary
192     void CreateSpaceAdd( const long nInit = 0 );
FinishSpaceAdd()193     inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
GetLLSpaceAddCount() const194     inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
SetLLSpaceAdd(long nNew,sal_uInt16 nIdx)195     inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
196     {
197         if ( nIdx == GetLLSpaceAddCount() )
198             pLLSpaceAdd->push_back( nNew );
199         else
200             (*pLLSpaceAdd)[ nIdx ] = nNew;
201     }
GetLLSpaceAdd(sal_uInt16 nIdx)202     inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
RemoveFirstLLSpaceAdd()203     inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
GetpLLSpaceAdd() const204     inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
205 
206     //
207     // STUFF FOR KANA COMPRESSION
208     //
SetKanaComp(SvUShorts * pNew)209     inline void SetKanaComp( SvUShorts* pNew ){ pKanaComp = pNew; }
FinishKanaComp()210     inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
GetpKanaComp() const211     inline SvUShorts* GetpKanaComp() const { return pKanaComp; }
GetKanaComp()212     inline SvUShorts& GetKanaComp() { return *pKanaComp; }
213 
214     /** determine ascent and descent for positioning of as-character anchored
215         object
216 
217         OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
218         Method calculates maximum ascents and descents of the line layout.
219         One value considering as-character anchored objects, one without these
220         objects.
221         Portions for other anchored objects aren't considered.
222         OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
223         to control, if the fly content portions and line portion are considered.
224 
225         @param _orAscent
226         output parameter - maximum ascent without as-character anchored objects
227 
228         @param _orDescent
229         output parameter - maximum descent without as-character anchored objects
230 
231         @param _orObjAscent
232         output parameter - maximum ascent with as-character anchored objects
233 
234         @param _orObjDescent
235         output parameter - maximum descent with as-character anchored objects
236 
237         @param _pDontConsiderPortion
238         input parameter - portion, which isn't considered for calculating
239         <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
240         as-character anchored object or it isn't as high as the line.
241 
242         @param _bNoFlyCntPorAndLinePor
243         optional input parameter - boolean, indicating that fly content portions
244         and the line portion are considered or not.
245 
246         @author OD
247     */
248     void MaxAscentDescent( SwTwips& _orAscent,
249                            SwTwips& _orDescent,
250                            SwTwips& _orObjAscent,
251                            SwTwips& _orObjDescent,
252                            const SwLinePortion* _pDontConsiderPortion = NULL,
253                            const bool _bNoFlyCntPorAndLinePor = false ) const;
254 
255 #ifdef DBG_UTIL
256     void DebugPortions( SvStream &rOs, const XubString &rTxt,
257                         const xub_StrLen nStart ); //$ ostream
258 #endif
259 
260     OUTPUT_OPERATOR
261     DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
262 };
263 
264 class SwParaPortion : public SwLineLayout
265 {
266     // neu zu paintender Bereich
267     SwRepaint aRepaint;
268     // neu zu formatierender Bereich
269     SwCharRange aReformat;
270     SwScriptInfo aScriptInfo;
271 //   Fraction aZoom;
272     long nDelta;
273 
274     // Wenn ein SwTxtFrm gelocked ist, werden keine Veraenderungen an den
275     // Formatierungsdaten (unter pLine) vorgenommen (vgl. ORPHANS)
276     sal_Bool bFlys          : 1; // Ueberlappen Flys ?
277     sal_Bool bPrep          : 1; // PREP_*
278     sal_Bool bPrepWidows    : 1; // PREP_WIDOWS
279     sal_Bool bPrepAdjust    : 1; // PREP_ADJUST_FRM
280     sal_Bool bPrepMustFit   : 1; // PREP_MUST_FIT
281     sal_Bool bFollowField   : 1; // Es steht noch ein Feldrest fuer den Follow an.
282 
283     sal_Bool bFixLineHeight : 1; // Feste Zeilenhoehe
284     sal_Bool bFtnNum    : 1; // contents a footnotenumberportion
285     sal_Bool bMargin    : 1; // contents a hanging punctuation in the margin
286 
287     sal_Bool bFlag00    : 1; //
288     sal_Bool bFlag11    : 1; //
289     sal_Bool bFlag12    : 1; //
290     sal_Bool bFlag13    : 1; //
291     sal_Bool bFlag14    : 1; //
292     sal_Bool bFlag15    : 1; //
293     sal_Bool bFlag16    : 1; //
294 
295 public:
296     SwParaPortion();
297     virtual ~SwParaPortion();
298 
299     // setzt alle Formatinformationen zurueck (ausser bFlys wg. 9916)
300     inline void FormatReset();
301 
302     // Setzt die Flags zurueck
303     inline void ResetPreps();
304 
305     // Get/Set-Methoden
GetRepaint()306     inline SwRepaint *GetRepaint() { return &aRepaint; }
GetRepaint() const307     inline const SwRepaint *GetRepaint() const { return &aRepaint; }
GetReformat()308     inline SwCharRange *GetReformat() { return &aReformat; }
GetReformat() const309     inline const SwCharRange *GetReformat() const { return &aReformat; }
GetDelta()310     inline long *GetDelta() { return &nDelta; }
GetDelta() const311     inline const long *GetDelta() const { return &nDelta; }
GetScriptInfo()312     inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
GetScriptInfo() const313     inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
314 
315     // fuer SwTxtFrm::Format: liefert die aktuelle Laenge des Absatzes
316     xub_StrLen GetParLen() const;
317 
318     // fuer Prepare()
319     sal_Bool UpdateQuoVadis( const XubString &rQuo );
320 
321     // Flags
SetFly(const sal_Bool bNew=sal_True)322     inline void SetFly( const sal_Bool bNew = sal_True ) { bFlys = bNew; }
HasFly() const323     inline sal_Bool HasFly() const { return bFlys; }
324 
325     // Preps
SetPrep(const sal_Bool bNew=sal_True)326     inline void SetPrep( const sal_Bool bNew = sal_True ) { bPrep = bNew; }
IsPrep() const327     inline sal_Bool IsPrep() const { return bPrep; }
SetPrepWidows(const sal_Bool bNew=sal_True)328     inline void SetPrepWidows( const sal_Bool bNew = sal_True ) { bPrepWidows = bNew; }
IsPrepWidows() const329     inline sal_Bool IsPrepWidows() const { return bPrepWidows; }
SetPrepMustFit(const sal_Bool bNew=sal_True)330     inline void SetPrepMustFit( const sal_Bool bNew = sal_True ) { bPrepMustFit = bNew; }
IsPrepMustFit() const331     inline sal_Bool IsPrepMustFit() const { return bPrepMustFit; }
SetPrepAdjust(const sal_Bool bNew=sal_True)332     inline void SetPrepAdjust( const sal_Bool bNew = sal_True ) { bPrepAdjust = bNew; }
IsPrepAdjust() const333     inline sal_Bool IsPrepAdjust() const { return bPrepAdjust; }
SetFollowField(const sal_Bool bNew=sal_True)334     inline void SetFollowField( const sal_Bool bNew = sal_True ) { bFollowField = bNew; }
IsFollowField() const335     inline sal_Bool IsFollowField() const { return bFollowField; }
SetFixLineHeight(const sal_Bool bNew=sal_True)336     inline void SetFixLineHeight( const sal_Bool bNew = sal_True ) { bFixLineHeight = bNew; }
IsFixLineHeight() const337     inline sal_Bool  IsFixLineHeight() const { return bFixLineHeight; }
338 
SetFtnNum(const sal_Bool bNew=sal_True)339     inline void SetFtnNum( const sal_Bool bNew = sal_True ) { bFtnNum = bNew; }
IsFtnNum() const340     inline sal_Bool  IsFtnNum() const { return bFtnNum; }
SetMargin(const sal_Bool bNew=sal_True)341     inline void SetMargin( const sal_Bool bNew = sal_True ) { bMargin = bNew; }
IsMargin() const342     inline sal_Bool  IsMargin() const { return bMargin; }
SetFlag00(const sal_Bool bNew=sal_True)343     inline void SetFlag00( const sal_Bool bNew = sal_True ) { bFlag00 = bNew; }
IsFlag00() const344     inline sal_Bool  IsFlag00() const { return bFlag00; }
SetFlag11(const sal_Bool bNew=sal_True)345     inline void SetFlag11( const sal_Bool bNew = sal_True ) { bFlag11 = bNew; }
IsFlag11() const346     inline sal_Bool  IsFlag11() const { return bFlag11; }
SetFlag12(const sal_Bool bNew=sal_True)347     inline void SetFlag12( const sal_Bool bNew = sal_True ) { bFlag12 = bNew; }
IsFlag12() const348     inline sal_Bool  IsFlag12() const { return bFlag12; }
SetFlag13(const sal_Bool bNew=sal_True)349     inline void SetFlag13( const sal_Bool bNew = sal_True ) { bFlag13 = bNew; }
IsFlag13() const350     inline sal_Bool  IsFlag13() const { return bFlag13; }
SetFlag14(const sal_Bool bNew=sal_True)351     inline void SetFlag14( const sal_Bool bNew = sal_True ) { bFlag14 = bNew; }
IsFlag14() const352     inline sal_Bool  IsFlag14() const { return bFlag14; }
SetFlag15(const sal_Bool bNew=sal_True)353     inline void SetFlag15( const sal_Bool bNew = sal_True ) { bFlag15 = bNew; }
IsFlag15() const354     inline sal_Bool  IsFlag15() const { return bFlag15; }
SetFlag16(const sal_Bool bNew=sal_True)355     inline void SetFlag16( const sal_Bool bNew = sal_True ) { bFlag16 = bNew; }
IsFlag16() const356     inline sal_Bool  IsFlag16() const { return bFlag16; }
357 
358     // schneller, hoeher, weiter: Read/Write-Methoden fuer den SWG-Filter
359     SvStream &ReadSwg ( SvStream& rStream ); //$ istream
360     SvStream &WriteSwg( SvStream& rStream ); //$ ostream
361 
362     // nErgo in der QuoVadisPortion setzen
363     void SetErgoSumNum( const XubString &rErgo );
364 
365     const SwDropPortion *FindDropPortion() const;
366 
367     OUTPUT_OPERATOR
368     DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
369 };
370 
371 /*************************************************************************
372  *                      Inline-Implementierungen
373  *************************************************************************/
374 
ResetFlags()375 inline void SwLineLayout::ResetFlags()
376 {
377     bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
378     = bRest = bBlinking = bClipping = bContent = bRedline
379     = bForcedLeftMargin = bHanging = sal_False;
380 }
381 
SwLineLayout()382 inline SwLineLayout::SwLineLayout()
383     : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
384       bUnderscore( sal_False )
385 {
386     ResetFlags();
387     SetWhichPor( POR_LAY );
388 }
389 
ResetPreps()390 inline void SwParaPortion::ResetPreps()
391 {
392     bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = sal_False;
393 }
394 
FormatReset()395 inline void SwParaPortion::FormatReset()
396 {
397     nDelta = 0;
398     aReformat = SwCharRange( 0, STRING_LEN );
399 //  AMA 9916: bFlys muss in SwTxtFrm::_Format() erhalten bleiben, damit
400 //  leere Absaetze, die Rahmen ohne Umfluss ausweichen mussten, sich
401 //  neu formatieren, wenn der Rahmen aus dem Bereich verschwindet.
402 //  bFlys = sal_False;
403     ResetPreps();
404     bFollowField = bFixLineHeight = bMargin = sal_False;
405 }
406 
407 #ifdef UNX
408 // C30 ist mit dem ternaeren Ausdruck ueberfordert.
GetFirstPortion() const409 inline SwLinePortion *SwLineLayout::GetFirstPortion() const
410 {
411     SwLinePortion *pTmp = pPortion;
412     if ( !pPortion )
413         pTmp = (SwLinePortion*)this;
414     return( pTmp );
415 }
416 #else
GetFirstPortion() const417 inline SwLinePortion *SwLineLayout::GetFirstPortion() const
418 { return( pPortion ? pPortion : (SwLinePortion*)this ); }
419 #endif
420 
421 CLASSIO( SwLineLayout )
422 CLASSIO( SwParaPortion )
423 
424 #endif
425