LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/text - porlay.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 108 115 93.9 %
Date: 2013-07-09 Functions: 85 92 92.4 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : #ifndef _PORLAY_HXX
      20             : #define _PORLAY_HXX
      21             : 
      22             : #include <tools/string.hxx>
      23             : #include <tools/fract.hxx>
      24             : #include <scriptinfo.hxx>
      25             : 
      26             : #include "swrect.hxx"   // SwRepaint
      27             : #include "portxt.hxx"
      28             : #include "swfont.hxx"
      29             : 
      30             : #include <vector>
      31             : #include <deque>
      32             : 
      33             : class SwMarginPortion;
      34             : class SwDropPortion;
      35             : class SvStream;
      36             : class SwTxtFormatter;
      37             : 
      38             : /*************************************************************************
      39             :  * class SwCharRange
      40             :  *************************************************************************/
      41             : 
      42             : class SwCharRange
      43             : {
      44             :     xub_StrLen nStart, nLen;
      45             : public:
      46       22463 :     inline SwCharRange( const xub_StrLen nInitStart = 0,
      47       22463 :         const xub_StrLen nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
      48       33554 :     inline xub_StrLen &Start() { return nStart; }
      49       53916 :     inline const xub_StrLen &Start() const { return nStart; }
      50       23991 :     inline void LeftMove( xub_StrLen nNew )
      51       23991 :             { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
      52             :     inline xub_StrLen End() const
      53             :                 { return nStart + nLen; }
      54       42942 :     inline xub_StrLen &Len() { return nLen; }
      55        1432 :     inline const xub_StrLen &Len() const { return nLen; }
      56        5032 :     inline bool operator<(const SwCharRange &rRange) const
      57        5032 :                 { return nStart < rRange.nStart; }
      58        5026 :     inline bool operator>(const SwCharRange &rRange) const
      59        5026 :                 { return nStart + nLen > rRange.nStart + rRange.nLen; }
      60        5032 :     inline bool operator!=(const SwCharRange &rRange) const
      61        5032 :                 { return *this < rRange || *this > rRange; }
      62             :     SwCharRange &operator+=(const SwCharRange &rRange);
      63             : };
      64             : 
      65             : /*************************************************************************
      66             :  * class SwRepaint
      67             :  *************************************************************************/
      68             : 
      69             : // SwRepaint is a document-global SwRect
      70             : // nOfst states from where in the first line should be painted
      71             : // nRightOfst gives the right margin
      72          67 : class SwRepaint : public SwRect
      73             : {
      74             :     SwTwips nOfst;
      75             :     SwTwips nRightOfst;
      76             : public:
      77        3532 :     SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
      78          67 :     SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
      79          67 :         nRightOfst( rRep.nRightOfst ) {}
      80             : 
      81       92920 :     SwTwips GetOfst() const { return nOfst; }
      82       89445 :     void   SetOfst( const SwTwips nNew ) { nOfst = nNew; }
      83       27101 :     SwTwips GetRightOfst() const { return nRightOfst; }
      84       15950 :     void   SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
      85             : };
      86             : 
      87             : 
      88             : /// Collection of SwLinePortion instances, representing one line of text.
      89             : class SwLineLayout : public SwTxtPortion
      90             : {
      91             : private:
      92             :     SwLineLayout *pNext;                // The next Line
      93             :     std::vector<long>* pLLSpaceAdd;     // Used for justified alignment.
      94             :     std::deque<sal_uInt16>* pKanaComp;  // Used for Kana compression.
      95             :     KSHORT nRealHeight;                 // The height resulting from line spacing and register
      96             :     sal_Bool bFormatAdj : 1;
      97             :     sal_Bool bDummy     : 1;
      98             :     sal_Bool bFntChg    : 1;
      99             :     sal_Bool bEndHyph   : 1;
     100             :     sal_Bool bMidHyph   : 1;
     101             :     sal_Bool bTab       : 1;
     102             :     sal_Bool bFly       : 1;
     103             :     sal_Bool bRest      : 1;
     104             :     sal_Bool bBlinking  : 1;
     105             :     sal_Bool bClipping  : 1; // Clipping needed for exact line height
     106             :     sal_Bool bContent   : 1; // Text for line numbering
     107             :     sal_Bool bRedline   : 1; // The Redlining
     108             :     sal_Bool bForcedLeftMargin : 1; // Left adjustment moved by the Fly
     109             :     sal_Bool bHanging : 1; // Contains a hanging portion in the margin
     110             :     sal_Bool bUnderscore : 1;
     111             : 
     112             :     SwTwips _GetHangingMargin() const;
     113             : 
     114             : public:
     115             :     // From SwLinePortion
     116             :     virtual SwLinePortion *Insert( SwLinePortion *pPortion );
     117             :     virtual SwLinePortion *Append( SwLinePortion *pPortion );
     118             :     inline SwLinePortion *GetFirstPortion() const;
     119             : 
     120             :     // Flags
     121             :     inline void ResetFlags();
     122        1215 :     inline void SetFormatAdj( const sal_Bool bNew ) { bFormatAdj = bNew; }
     123       41567 :     inline sal_Bool IsFormatAdj() const { return bFormatAdj; }
     124             :     inline void SetFntChg( const sal_Bool bNew ) { bFntChg = bNew; }
     125             :     inline sal_Bool IsFntChg() const { return bFntChg; }
     126       23991 :     inline void SetEndHyph( const sal_Bool bNew ) { bEndHyph = bNew; }
     127       58406 :     inline sal_Bool IsEndHyph() const { return bEndHyph; }
     128       23991 :     inline void SetMidHyph( const sal_Bool bNew ) { bMidHyph = bNew; }
     129       23992 :     inline sal_Bool IsMidHyph() const { return bMidHyph; }
     130             :     inline void SetTab( const sal_Bool bNew ) { bTab = bNew; }
     131             :     inline sal_Bool IsTab() const { return bTab; }
     132         100 :     inline void SetFly( const sal_Bool bNew ) { bFly = bNew; }
     133        3164 :     inline sal_Bool IsFly() const { return bFly; }
     134         305 :     inline void SetRest( const sal_Bool bNew ) { bRest = bNew; }
     135       33005 :     inline sal_Bool IsRest() const { return bRest; }
     136           6 :     inline void SetBlinking( const sal_Bool bNew = sal_True ) { bBlinking = bNew; }
     137        1967 :     inline sal_Bool IsBlinking() const { return bBlinking; }
     138       27085 :     inline void SetCntnt( const sal_Bool bNew = sal_True ) { bContent = bNew; }
     139        6715 :     inline sal_Bool HasCntnt() const { return bContent; }
     140       25303 :     inline void SetRedline( const sal_Bool bNew = sal_True ) { bRedline = bNew; }
     141          63 :     inline sal_Bool HasRedline() const { return bRedline; }
     142           0 :     inline void SetForcedLeftMargin( const sal_Bool bNew = sal_True ) { bForcedLeftMargin = bNew; }
     143        3129 :     inline sal_Bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
     144       72733 :     inline void SetHanging( const sal_Bool bNew = sal_True ) { bHanging = bNew; }
     145             :     inline sal_Bool IsHanging() const { return bHanging; }
     146       23439 :     inline void SetUnderscore( const sal_Bool bNew = sal_True ) { bUnderscore = bNew; }
     147       27715 :     inline sal_Bool HasUnderscore() const { return bUnderscore; }
     148             : 
     149             :     // Respecting empty dummy lines
     150       25318 :     inline void SetDummy( const sal_Bool bNew ) { bDummy = bNew; }
     151      129760 :     inline sal_Bool IsDummy() const { return bDummy; }
     152             : 
     153       25731 :     inline void SetClipping( const sal_Bool bNew ) { bClipping = bNew; }
     154       72880 :     inline sal_Bool IsClipping() const { return bClipping; }
     155             : 
     156             :     inline SwLineLayout();
     157             :     virtual ~SwLineLayout();
     158             : 
     159      905256 :     inline SwLineLayout *GetNext() { return pNext; }
     160      137671 :     inline const SwLineLayout *GetNext() const { return pNext; }
     161        8341 :     inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
     162             : 
     163             :     void Init( SwLinePortion *pNextPortion = NULL);
     164             : 
     165             :     // Collects the data for the line
     166             :     void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
     167             : 
     168       53620 :     inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
     169      605436 :     inline KSHORT GetRealHeight() const { return nRealHeight; }
     170             : 
     171             :     // Creates the glue chain for short lines
     172             :     SwMarginPortion *CalcLeftMargin();
     173             : 
     174       47430 :     inline SwTwips GetHangingMargin() const
     175       47430 :         { return _GetHangingMargin(); }
     176             : 
     177             :     // For special treatment for empty lines
     178             :     virtual sal_Bool Format( SwTxtFormatInfo &rInf );
     179             : 
     180             :     //
     181             :     // STUFF FOR JUSTIFIED ALIGNMENT
     182             :     //
     183       28397 :     inline bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
     184             :     void InitSpaceAdd();     // Creates pLLSpaceAdd if necessary
     185             :     void CreateSpaceAdd( const long nInit = 0 );
     186       25580 :     inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
     187          66 :     inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
     188          40 :     inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
     189             :     {
     190          40 :         if ( nIdx == GetLLSpaceAddCount() )
     191          26 :             pLLSpaceAdd->push_back( nNew );
     192             :         else
     193          14 :             (*pLLSpaceAdd)[ nIdx ] = nNew;
     194          40 :     }
     195          46 :     inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
     196           0 :     inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
     197       20456 :     inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
     198             : 
     199             :     //
     200             :     // STUFF FOR KANA COMPRESSION
     201             :     //
     202           0 :     inline void SetKanaComp( std::deque<sal_uInt16>* pNew ){ pKanaComp = pNew; }
     203       25569 :     inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
     204       48169 :     inline std::deque<sal_uInt16>* GetpKanaComp() const { return pKanaComp; }
     205           0 :     inline std::deque<sal_uInt16>& GetKanaComp() { return *pKanaComp; }
     206             : 
     207             :     /** determine ascent and descent for positioning of as-character anchored
     208             :         object
     209             : 
     210             :         OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
     211             :         Method calculates maximum ascents and descents of the line layout.
     212             :         One value considering as-character anchored objects, one without these
     213             :         objects.
     214             :         Portions for other anchored objects aren't considered.
     215             :         OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
     216             :         to control, if the fly content portions and line portion are considered.
     217             : 
     218             :         @param _orAscent
     219             :         output parameter - maximum ascent without as-character anchored objects
     220             : 
     221             :         @param _orDescent
     222             :         output parameter - maximum descent without as-character anchored objects
     223             : 
     224             :         @param _orObjAscent
     225             :         output parameter - maximum ascent with as-character anchored objects
     226             : 
     227             :         @param _orObjDescent
     228             :         output parameter - maximum descent with as-character anchored objects
     229             : 
     230             :         @param _pDontConsiderPortion
     231             :         input parameter - portion, which isn't considered for calculating
     232             :         <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
     233             :         as-character anchored object or it isn't as high as the line.
     234             : 
     235             :         @param _bNoFlyCntPorAndLinePor
     236             :         optional input parameter - boolean, indicating that fly content portions
     237             :         and the line portion are considered or not.
     238             : 
     239             :         @author OD
     240             :     */
     241             :     void MaxAscentDescent( SwTwips& _orAscent,
     242             :                            SwTwips& _orDescent,
     243             :                            SwTwips& _orObjAscent,
     244             :                            SwTwips& _orObjDescent,
     245             :                            const SwLinePortion* _pDontConsiderPortion = NULL,
     246             :                            const bool _bNoFlyCntPorAndLinePor = false ) const;
     247             : 
     248             :     OUTPUT_OPERATOR
     249        8220 :     DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
     250             : };
     251             : 
     252             : /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
     253             : class SwParaPortion : public SwLineLayout
     254             : {
     255             :     // Area that needs repainting
     256             :     SwRepaint aRepaint;
     257             :     // Area that needs reformatting
     258             :     SwCharRange aReformat;
     259             :     SwScriptInfo aScriptInfo;
     260             :     // Fraction aZoom;
     261             :     long nDelta;
     262             : 
     263             :     // If a SwTxtFrm is locked, no changes occur to the formatting data (under
     264             :     // pLine) (compare with Orphans)
     265             :     sal_Bool bFlys          : 1; // Overlapping Flys?
     266             :     sal_Bool bPrep          : 1; // PREP_*
     267             :     sal_Bool bPrepWidows    : 1; // PREP_WIDOWS
     268             :     sal_Bool bPrepAdjust    : 1; // PREP_ADJUST_FRM
     269             :     sal_Bool bPrepMustFit   : 1; // PREP_MUST_FIT
     270             :     sal_Bool bFollowField   : 1; // We have a bit of field left for the Follow
     271             : 
     272             :     sal_Bool bFixLineHeight : 1; // Fixed line height
     273             :     sal_Bool bFtnNum    : 1; // contains a footnotenumberportion
     274             :     sal_Bool bMargin    : 1; // contains a hanging punctuation in the margin
     275             : 
     276             :     sal_Bool bFlag00    : 1;
     277             :     sal_Bool bFlag11    : 1;
     278             :     sal_Bool bFlag12    : 1;
     279             :     sal_Bool bFlag13    : 1;
     280             :     sal_Bool bFlag14    : 1;
     281             :     sal_Bool bFlag15    : 1;
     282             :     sal_Bool bFlag16    : 1;
     283             : 
     284             : public:
     285             :     SwParaPortion();
     286             :     virtual ~SwParaPortion();
     287             : 
     288             :     // Resets all formatting information (except for bFlys)
     289             :     inline void FormatReset();
     290             : 
     291             :     // Resets the Flags
     292             :     inline void ResetPreps();
     293             : 
     294             :     // Get/Set methods
     295      122861 :     inline SwRepaint *GetRepaint() { return &aRepaint; }
     296       53178 :     inline const SwRepaint *GetRepaint() const { return &aRepaint; }
     297       77743 :     inline SwCharRange *GetReformat() { return &aReformat; }
     298       52484 :     inline const SwCharRange *GetReformat() const { return &aReformat; }
     299       50177 :     inline long *GetDelta() { return &nDelta; }
     300             :     inline const long *GetDelta() const { return &nDelta; }
     301      139871 :     inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
     302       52616 :     inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
     303             : 
     304             :     // For SwTxtFrm::Format: returns the paragraph's current length
     305             :     xub_StrLen GetParLen() const;
     306             : 
     307             :     // For Prepare()
     308             :     sal_Bool UpdateQuoVadis( const XubString &rQuo );
     309             : 
     310             :     // Flags
     311         696 :     inline void SetFly( const sal_Bool bNew = sal_True ) { bFlys = bNew; }
     312         937 :     inline sal_Bool HasFly() const { return bFlys; }
     313             : 
     314             :     // Preps
     315         816 :     inline void SetPrep( const sal_Bool bNew = sal_True ) { bPrep = bNew; }
     316        4459 :     inline sal_Bool IsPrep() const { return bPrep; }
     317           0 :     inline void SetPrepWidows( const sal_Bool bNew = sal_True ) { bPrepWidows = bNew; }
     318        4735 :     inline sal_Bool IsPrepWidows() const { return bPrepWidows; }
     319       21245 :     inline void SetPrepMustFit( const sal_Bool bNew = sal_True ) { bPrepMustFit = bNew; }
     320       20979 :     inline sal_Bool IsPrepMustFit() const { return bPrepMustFit; }
     321         697 :     inline void SetPrepAdjust( const sal_Bool bNew = sal_True ) { bPrepAdjust = bNew; }
     322        4459 :     inline sal_Bool IsPrepAdjust() const { return bPrepAdjust; }
     323           2 :     inline void SetFollowField( const sal_Bool bNew = sal_True ) { bFollowField = bNew; }
     324         302 :     inline sal_Bool IsFollowField() const { return bFollowField; }
     325          32 :     inline void SetFixLineHeight( const sal_Bool bNew = sal_True ) { bFixLineHeight = bNew; }
     326           0 :     inline sal_Bool  IsFixLineHeight() const { return bFixLineHeight; }
     327             : 
     328        5812 :     inline void SetFtnNum( const sal_Bool bNew = sal_True ) { bFtnNum = bNew; }
     329         354 :     inline sal_Bool  IsFtnNum() const { return bFtnNum; }
     330           0 :     inline void SetMargin( const sal_Bool bNew = sal_True ) { bMargin = bNew; }
     331       19847 :     inline sal_Bool  IsMargin() const { return bMargin; }
     332             :     inline void SetFlag00( const sal_Bool bNew = sal_True ) { bFlag00 = bNew; }
     333             :     inline sal_Bool  IsFlag00() const { return bFlag00; }
     334             :     inline void SetFlag11( const sal_Bool bNew = sal_True ) { bFlag11 = bNew; }
     335             :     inline sal_Bool  IsFlag11() const { return bFlag11; }
     336             :     inline void SetFlag12( const sal_Bool bNew = sal_True ) { bFlag12 = bNew; }
     337             :     inline sal_Bool  IsFlag12() const { return bFlag12; }
     338             :     inline void SetFlag13( const sal_Bool bNew = sal_True ) { bFlag13 = bNew; }
     339             :     inline sal_Bool  IsFlag13() const { return bFlag13; }
     340             :     inline void SetFlag14( const sal_Bool bNew = sal_True ) { bFlag14 = bNew; }
     341             :     inline sal_Bool  IsFlag14() const { return bFlag14; }
     342             :     inline void SetFlag15( const sal_Bool bNew = sal_True ) { bFlag15 = bNew; }
     343             :     inline sal_Bool  IsFlag15() const { return bFlag15; }
     344             :     inline void SetFlag16( const sal_Bool bNew = sal_True ) { bFlag16 = bNew; }
     345             :     inline sal_Bool  IsFlag16() const { return bFlag16; }
     346             : 
     347             :     // Read/Write methods for the SWG filter
     348             :     SvStream &ReadSwg ( SvStream& rStream ); //$ istream
     349             :     SvStream &WriteSwg( SvStream& rStream ); //$ ostream
     350             : 
     351             :     // Set nErgo in the QuoVadisPortion
     352             :     void SetErgoSumNum( const XubString &rErgo );
     353             : 
     354             :     const SwDropPortion *FindDropPortion() const;
     355             : 
     356             : #ifdef DBG_UTIL
     357             :     void dumpAsXml( xmlTextWriter* writer, SwTxtFrm* pTxtFrm );
     358             : #endif
     359             : 
     360             :     OUTPUT_OPERATOR
     361        7064 :     DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
     362             : };
     363             : 
     364             : /*************************************************************************
     365             :  * Inline implementations
     366             :  *************************************************************************/
     367             : 
     368       33410 : inline void SwLineLayout::ResetFlags()
     369             : {
     370             :     bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
     371             :     = bRest = bBlinking = bClipping = bContent = bRedline
     372       33410 :     = bForcedLeftMargin = bHanging = sal_False;
     373       33410 : }
     374             : 
     375        7841 : inline SwLineLayout::SwLineLayout()
     376             :     : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
     377        7841 :       bUnderscore( sal_False )
     378             : {
     379        7841 :     ResetFlags();
     380        7841 :     SetWhichPor( POR_LAY );
     381        7841 : }
     382             : 
     383        9256 : inline void SwParaPortion::ResetPreps()
     384             : {
     385        9256 :     bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = sal_False;
     386        9256 : }
     387             : 
     388        4754 : inline void SwParaPortion::FormatReset()
     389             : {
     390        4754 :     nDelta = 0;
     391        4754 :     aReformat = SwCharRange( 0, STRING_LEN );
     392             :     // bFlys needs to be retained in SwTxtFrm::_Format() so that empty
     393             :     // paragraphs that needed to avoid Frames with no flow, reformat
     394             :     // when the Frame disappears from the Area
     395             :     // bFlys = sal_False;
     396        4754 :     ResetPreps();
     397        4754 :     bFollowField = bFixLineHeight = bMargin = sal_False;
     398        4754 : }
     399             : 
     400       88918 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
     401       88918 : { return( pPortion ? pPortion : (SwLinePortion*)this ); }
     402             : 
     403             : CLASSIO( SwLineLayout )
     404             : CLASSIO( SwParaPortion )
     405             : 
     406             : #endif
     407             : 
     408             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10