LCOV - code coverage report
Current view: top level - sw/source/core/text - porlay.hxx (source / functions) Hit Total Coverage
Test: commit 0e63ca4fde4e446f346e35849c756a30ca294aab Lines: 110 115 95.7 %
Date: 2014-04-11 Functions: 87 92 94.6 %
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 INCLUDED_SW_SOURCE_CORE_TEXT_PORLAY_HXX
      20             : #define INCLUDED_SW_SOURCE_CORE_TEXT_PORLAY_HXX
      21             : 
      22             : #include <tools/fract.hxx>
      23             : #include <scriptinfo.hxx>
      24             : 
      25             : #include "swrect.hxx"
      26             : #include "portxt.hxx"
      27             : #include "swfont.hxx"
      28             : 
      29             : #include <vector>
      30             : #include <deque>
      31             : 
      32             : class SwMarginPortion;
      33             : class SwDropPortion;
      34             : class SvStream;
      35             : class SwTxtFormatter;
      36             : 
      37             : class SwCharRange
      38             : {
      39             :     sal_Int32 nStart, nLen;
      40             : public:
      41      102280 :     inline SwCharRange( const sal_Int32 nInitStart = 0,
      42      102280 :         const sal_Int32 nInitLen = 0): nStart( nInitStart ), nLen(nInitLen) {}
      43       75345 :     inline sal_Int32 &Start() { return nStart; }
      44      122317 :     inline const sal_Int32 &Start() const { return nStart; }
      45       52440 :     inline void LeftMove( sal_Int32 nNew )
      46       52440 :             { if ( nNew < nStart ) { nLen += nStart-nNew; nStart = nNew; } }
      47             :     inline sal_Int32 End() const
      48             :                 { return nStart + nLen; }
      49      112833 :     inline sal_Int32 &Len() { return nLen; }
      50        3971 :     inline const sal_Int32 &Len() const { return nLen; }
      51        7479 :     inline bool operator<(const SwCharRange &rRange) const
      52        7479 :                 { return nStart < rRange.nStart; }
      53        7468 :     inline bool operator>(const SwCharRange &rRange) const
      54        7468 :                 { return nStart + nLen > rRange.nStart + rRange.nLen; }
      55        7479 :     inline bool operator!=(const SwCharRange &rRange) const
      56        7479 :                 { return *this < rRange || *this > rRange; }
      57             :     SwCharRange &operator+=(const SwCharRange &rRange);
      58             : };
      59             : 
      60             : // SwRepaint is a document-global SwRect
      61             : // nOfst states from where in the first line should be painted
      62             : // nRightOfst gives the right margin
      63          67 : class SwRepaint : public SwRect
      64             : {
      65             :     SwTwips nOfst;
      66             :     SwTwips nRightOfst;
      67             : public:
      68       25505 :     SwRepaint() : SwRect(), nOfst( 0 ), nRightOfst( 0 ) {}
      69          67 :     SwRepaint( const SwRepaint& rRep ) : SwRect( rRep ), nOfst( rRep.nOfst ),
      70          67 :         nRightOfst( rRep.nRightOfst ) {}
      71             : 
      72      238201 :     SwTwips GetOfst() const { return nOfst; }
      73      227651 :     void   SetOfst( const SwTwips nNew ) { nOfst = nNew; }
      74       55873 :     SwTwips GetRightOfst() const { return nRightOfst; }
      75       58612 :     void   SetRightOfst( const SwTwips nNew ) { nRightOfst = nNew; }
      76             : };
      77             : 
      78             : /// Collection of SwLinePortion instances, representing one line of text
      79             : class SwLineLayout : public SwTxtPortion
      80             : {
      81             : private:
      82             :     SwLineLayout *pNext;                // The next Line
      83             :     std::vector<long>* pLLSpaceAdd;     // Used for justified alignment
      84             :     std::deque<sal_uInt16>* pKanaComp;  // Used for Kana compression
      85             :     KSHORT nRealHeight;                 // The height resulting from line spacing and register
      86             :     bool bFormatAdj : 1;
      87             :     bool bDummy     : 1;
      88             :     bool bFntChg    : 1;
      89             :     bool bEndHyph   : 1;
      90             :     bool bMidHyph   : 1;
      91             :     bool bTab       : 1;
      92             :     bool bFly       : 1;
      93             :     bool bRest      : 1;
      94             :     bool bBlinking  : 1;
      95             :     bool bClipping  : 1; // Clipping needed for exact line height
      96             :     bool bContent   : 1; // Text for line numbering
      97             :     bool bRedline   : 1; // The Redlining
      98             :     bool bForcedLeftMargin : 1; // Left adjustment moved by the Fly
      99             :     bool bHanging : 1; // Contains a hanging portion in the margin
     100             :     bool bUnderscore : 1;
     101             : 
     102             :     SwTwips _GetHangingMargin() const;
     103             : 
     104             : public:
     105             :     // From SwLinePortion
     106             :     virtual SwLinePortion *Insert( SwLinePortion *pPortion ) SAL_OVERRIDE;
     107             :     virtual SwLinePortion *Append( SwLinePortion *pPortion ) SAL_OVERRIDE;
     108             :     inline SwLinePortion *GetFirstPortion() const;
     109             : 
     110             :     // Flags
     111             :     inline void ResetFlags();
     112       10026 :     inline void SetFormatAdj( const bool bNew ) { bFormatAdj = bNew; }
     113       57356 :     inline bool IsFormatAdj() const { return bFormatAdj; }
     114             :     inline void SetFntChg( const bool bNew ) { bFntChg = bNew; }
     115             :     inline bool IsFntChg() const { return bFntChg; }
     116       52440 :     inline void SetEndHyph( const bool bNew ) { bEndHyph = bNew; }
     117      119931 :     inline bool IsEndHyph() const { return bEndHyph; }
     118       52440 :     inline void SetMidHyph( const bool bNew ) { bMidHyph = bNew; }
     119       52433 :     inline bool IsMidHyph() const { return bMidHyph; }
     120             :     inline void SetTab( const bool bNew ) { bTab = bNew; }
     121             :     inline bool IsTab() const { return bTab; }
     122         285 :     inline void SetFly( const bool bNew ) { bFly = bNew; }
     123        3362 :     inline bool IsFly() const { return bFly; }
     124        3300 :     inline void SetRest( const bool bNew ) { bRest = bNew; }
     125       44726 :     inline bool IsRest() const { return bRest; }
     126           6 :     inline void SetBlinking( const bool bNew = true ) { bBlinking = bNew; }
     127        8788 :     inline bool IsBlinking() const { return bBlinking; }
     128       67813 :     inline void SetCntnt( const bool bNew = true ) { bContent = bNew; }
     129       66640 :     inline bool HasCntnt() const { return bContent; }
     130       56833 :     inline void SetRedline( const bool bNew = true ) { bRedline = bNew; }
     131         506 :     inline bool HasRedline() const { return bRedline; }
     132           0 :     inline void SetForcedLeftMargin( const bool bNew = true ) { bForcedLeftMargin = bNew; }
     133       26552 :     inline bool HasForcedLeftMargin() const { return bForcedLeftMargin; }
     134      161142 :     inline void SetHanging( const bool bNew = true ) { bHanging = bNew; }
     135             :     inline bool IsHanging() const { return bHanging; }
     136       51877 :     inline void SetUnderscore( const bool bNew = true ) { bUnderscore = bNew; }
     137       57089 :     inline bool HasUnderscore() const { return bUnderscore; }
     138             : 
     139             :     // Respecting empty dummy lines
     140       56859 :     inline void SetDummy( const bool bNew ) { bDummy = bNew; }
     141      417954 :     inline bool IsDummy() const { return bDummy; }
     142             : 
     143       63575 :     inline void SetClipping( const bool bNew ) { bClipping = bNew; }
     144      134731 :     inline bool IsClipping() const { return bClipping; }
     145             : 
     146             :     inline SwLineLayout();
     147             :     virtual ~SwLineLayout();
     148             : 
     149     1074615 :     inline SwLineLayout *GetNext() { return pNext; }
     150      230651 :     inline const SwLineLayout *GetNext() const { return pNext; }
     151       24031 :     inline void SetNext( SwLineLayout *pNew ) { pNext = pNew; }
     152             : 
     153             :     void Init( SwLinePortion *pNextPortion = NULL);
     154             : 
     155             :     // Collects the data for the line
     156             :     void CalcLine( SwTxtFormatter &rLine, SwTxtFormatInfo &rInf );
     157             : 
     158      134983 :     inline void SetRealHeight( KSHORT nNew ) { nRealHeight = nNew; }
     159      869282 :     inline KSHORT GetRealHeight() const { return nRealHeight; }
     160             : 
     161             :     // Creates the glue chain for short lines
     162             :     SwMarginPortion *CalcLeftMargin();
     163             : 
     164      104309 :     inline SwTwips GetHangingMargin() const
     165      104309 :         { return _GetHangingMargin(); }
     166             : 
     167             :     // For special treatment for empty lines
     168             :     virtual bool Format( SwTxtFormatInfo &rInf ) SAL_OVERRIDE;
     169             : 
     170             :     // Stuff for justified alignment
     171       40184 :     inline bool IsSpaceAdd() { return pLLSpaceAdd != NULL; }
     172             :     void InitSpaceAdd();     // Creates pLLSpaceAdd if necessary
     173             :     void CreateSpaceAdd( const long nInit = 0 );
     174       60138 :     inline void FinishSpaceAdd() { delete pLLSpaceAdd; pLLSpaceAdd = NULL; }
     175         344 :     inline sal_uInt16 GetLLSpaceAddCount() const { return sal::static_int_cast< sal_uInt16 >(pLLSpaceAdd->size()); }
     176         230 :     inline void SetLLSpaceAdd( long nNew, sal_uInt16 nIdx )
     177             :     {
     178         230 :         if ( nIdx == GetLLSpaceAddCount() )
     179         123 :             pLLSpaceAdd->push_back( nNew );
     180             :         else
     181         107 :             (*pLLSpaceAdd)[ nIdx ] = nNew;
     182         230 :     }
     183         142 :     inline long GetLLSpaceAdd( sal_uInt16 nIdx ) { return (*pLLSpaceAdd)[ nIdx ]; }
     184           0 :     inline void RemoveFirstLLSpaceAdd() { pLLSpaceAdd->erase( pLLSpaceAdd->begin() ); }
     185       50581 :     inline std::vector<long>* GetpLLSpaceAdd() const { return pLLSpaceAdd; }
     186             : 
     187             :     // Stuff for Kana compression
     188           0 :     inline void SetKanaComp( std::deque<sal_uInt16>* pNew ){ pKanaComp = pNew; }
     189       59970 :     inline void FinishKanaComp() { delete pKanaComp; pKanaComp = NULL; }
     190       89550 :     inline std::deque<sal_uInt16>* GetpKanaComp() const { return pKanaComp; }
     191           0 :     inline std::deque<sal_uInt16>& GetKanaComp() { return *pKanaComp; }
     192             : 
     193             :     /** determine ascent and descent for positioning of as-character anchored
     194             :         object
     195             : 
     196             :         OD 07.01.2004 #i11859# - previously local method <lcl_MaxAscDescent>
     197             :         Method calculates maximum ascents and descents of the line layout.
     198             :         One value considering as-character anchored objects, one without these
     199             :         objects.
     200             :         Portions for other anchored objects aren't considered.
     201             :         OD 2005-05-20 #i47162# - add optional parameter <_bNoFlyCntPorAndLinePor>
     202             :         to control, if the fly content portions and line portion are considered.
     203             : 
     204             :         @param _orAscent
     205             :         output parameter - maximum ascent without as-character anchored objects
     206             : 
     207             :         @param _orDescent
     208             :         output parameter - maximum descent without as-character anchored objects
     209             : 
     210             :         @param _orObjAscent
     211             :         output parameter - maximum ascent with as-character anchored objects
     212             : 
     213             :         @param _orObjDescent
     214             :         output parameter - maximum descent with as-character anchored objects
     215             : 
     216             :         @param _pDontConsiderPortion
     217             :         input parameter - portion, which isn't considered for calculating
     218             :         <_orObjAscent> and <_orObjDescent>, if it isn't a portion for a
     219             :         as-character anchored object or it isn't as high as the line.
     220             : 
     221             :         @param _bNoFlyCntPorAndLinePor
     222             :         optional input parameter - boolean, indicating that fly content portions
     223             :         and the line portion are considered or not.
     224             :     */
     225             :     void MaxAscentDescent( SwTwips& _orAscent,
     226             :                            SwTwips& _orDescent,
     227             :                            SwTwips& _orObjAscent,
     228             :                            SwTwips& _orObjDescent,
     229             :                            const SwLinePortion* _pDontConsiderPortion = NULL,
     230             :                            const bool _bNoFlyCntPorAndLinePor = false ) const;
     231             : 
     232             :     OUTPUT_OPERATOR_OVERRIDE
     233       23620 :     DECL_FIXEDMEMPOOL_NEWDEL(SwLineLayout)
     234             : };
     235             : 
     236             : /// Collection of SwLineLayout instances, represents the paragraph text in Writer layout.
     237             : class SwParaPortion : public SwLineLayout
     238             : {
     239             :     // Area that needs repainting
     240             :     SwRepaint aRepaint;
     241             :     // Area that needs reformatting
     242             :     SwCharRange aReformat;
     243             :     SwScriptInfo aScriptInfo;
     244             :     // Fraction aZoom;
     245             :     long nDelta;
     246             : 
     247             :     // If a SwTxtFrm is locked, no changes occur to the formatting data (under
     248             :     // pLine) (compare with Orphans)
     249             :     bool bFlys          : 1; // Overlapping Flys?
     250             :     bool bPrep          : 1; // PREP_*
     251             :     bool bPrepWidows    : 1; // PREP_WIDOWS
     252             :     bool bPrepAdjust    : 1; // PREP_ADJUST_FRM
     253             :     bool bPrepMustFit   : 1; // PREP_MUST_FIT
     254             :     bool bFollowField   : 1; // We have a bit of field left for the Follow
     255             : 
     256             :     bool bFixLineHeight : 1; // Fixed line height
     257             :     bool bFtnNum    : 1; // contains a footnotenumberportion
     258             :     bool bMargin    : 1; // contains a hanging punctuation in the margin
     259             : 
     260             :     bool bFlag00    : 1;
     261             :     bool bFlag11    : 1;
     262             :     bool bFlag12    : 1;
     263             :     bool bFlag13    : 1;
     264             :     bool bFlag14    : 1;
     265             :     bool bFlag15    : 1;
     266             :     bool bFlag16    : 1;
     267             : 
     268             : public:
     269             :     SwParaPortion();
     270             :     virtual ~SwParaPortion();
     271             : 
     272             :     // Resets all formatting information (except for bFlys)
     273             :     inline void FormatReset();
     274             : 
     275             :     // Resets the Flags
     276             :     inline void ResetPreps();
     277             : 
     278             :     // Get/Set methods
     279      306263 :     inline SwRepaint *GetRepaint() { return &aRepaint; }
     280      167013 :     inline const SwRepaint *GetRepaint() const { return &aRepaint; }
     281      159392 :     inline SwCharRange *GetReformat() { return &aReformat; }
     282      118346 :     inline const SwCharRange *GetReformat() const { return &aReformat; }
     283      125995 :     inline long *GetDelta() { return &nDelta; }
     284             :     inline const long *GetDelta() const { return &nDelta; }
     285      329837 :     inline SwScriptInfo& GetScriptInfo() { return aScriptInfo; }
     286      137823 :     inline const SwScriptInfo& GetScriptInfo() const { return aScriptInfo; }
     287             : 
     288             :     // For SwTxtFrm::Format: returns the paragraph's current length
     289             :     sal_Int32 GetParLen() const;
     290             : 
     291             :     // For Prepare()
     292             :     bool UpdateQuoVadis( const OUString &rQuo );
     293             : 
     294             :     // Flags
     295        1665 :     inline void SetFly( const bool bNew = true ) { bFlys = bNew; }
     296        8623 :     inline bool HasFly() const { return bFlys; }
     297             : 
     298             :     // Preps
     299        7850 :     inline void SetPrep( const bool bNew = true ) { bPrep = bNew; }
     300        9377 :     inline bool IsPrep() const { return bPrep; }
     301          74 :     inline void SetPrepWidows( const bool bNew = true ) { bPrepWidows = bNew; }
     302       10105 :     inline bool IsPrepWidows() const { return bPrepWidows; }
     303       77696 :     inline void SetPrepMustFit( const bool bNew = true ) { bPrepMustFit = bNew; }
     304       73764 :     inline bool IsPrepMustFit() const { return bPrepMustFit; }
     305        5458 :     inline void SetPrepAdjust( const bool bNew = true ) { bPrepAdjust = bNew; }
     306        9377 :     inline bool IsPrepAdjust() const { return bPrepAdjust; }
     307         252 :     inline void SetFollowField( const bool bNew = true ) { bFollowField = bNew; }
     308         792 :     inline bool IsFollowField() const { return bFollowField; }
     309        1729 :     inline void SetFixLineHeight( const bool bNew = true ) { bFixLineHeight = bNew; }
     310           1 :     inline bool IsFixLineHeight() const { return bFixLineHeight; }
     311             : 
     312       27973 :     inline void SetFtnNum( const bool bNew = true ) { bFtnNum = bNew; }
     313        4450 :     inline bool IsFtnNum() const { return bFtnNum; }
     314           0 :     inline void SetMargin( const bool bNew = true ) { bMargin = bNew; }
     315       46039 :     inline bool IsMargin() const { return bMargin; }
     316             :     inline void SetFlag00( const bool bNew = true ) { bFlag00 = bNew; }
     317             :     inline bool IsFlag00() const { return bFlag00; }
     318             :     inline void SetFlag11( const bool bNew = true ) { bFlag11 = bNew; }
     319             :     inline bool IsFlag11() const { return bFlag11; }
     320             :     inline void SetFlag12( const bool bNew = true ) { bFlag12 = bNew; }
     321             :     inline bool IsFlag12() const { return bFlag12; }
     322             :     inline void SetFlag13( const bool bNew = true ) { bFlag13 = bNew; }
     323             :     inline bool IsFlag13() const { return bFlag13; }
     324             :     inline void SetFlag14( const bool bNew = true ) { bFlag14 = bNew; }
     325             :     inline bool IsFlag14() const { return bFlag14; }
     326             :     inline void SetFlag15( const bool bNew = true ) { bFlag15 = bNew; }
     327             :     inline bool IsFlag15() const { return bFlag15; }
     328             :     inline void SetFlag16( const bool bNew = true ) { bFlag16 = bNew; }
     329             :     inline bool IsFlag16() const { return bFlag16; }
     330             : 
     331             :     // Read/Write methods for the SWG filter
     332             :     SvStream &ReadSwg ( SvStream& rStream ); //$ istream
     333             :     SvStream &WriteSwg( SvStream& rStream ); //$ ostream
     334             : 
     335             :     // Set nErgo in the QuoVadisPortion
     336             :     void SetErgoSumNum( const OUString &rErgo );
     337             : 
     338             :     const SwDropPortion *FindDropPortion() const;
     339             : 
     340             : #ifdef DBG_UTIL
     341             :     void dumpAsXml( xmlTextWriter* writer, SwTxtFrm* pTxtFrm );
     342             : #endif
     343             : 
     344             :     OUTPUT_OPERATOR_OVERRIDE
     345       51010 :     DECL_FIXEDMEMPOOL_NEWDEL(SwParaPortion)
     346             : };
     347             : 
     348             : /*************************************************************************
     349             :  * Inline implementations
     350             :  *************************************************************************/
     351             : 
     352       97824 : inline void SwLineLayout::ResetFlags()
     353             : {
     354             :     bFormatAdj = bDummy = bFntChg = bTab = bEndHyph = bMidHyph = bFly
     355             :     = bRest = bBlinking = bClipping = bContent = bRedline
     356       97824 :     = bForcedLeftMargin = bHanging = false;
     357       97824 : }
     358             : 
     359       37854 : inline SwLineLayout::SwLineLayout()
     360             :     : pNext( 0 ), pLLSpaceAdd( 0 ), pKanaComp( 0 ), nRealHeight( 0 ),
     361       37854 :       bUnderscore( false )
     362             : {
     363       37854 :     ResetFlags();
     364       37854 :     SetWhichPor( POR_LAY );
     365       37854 : }
     366             : 
     367       39764 : inline void SwParaPortion::ResetPreps()
     368             : {
     369       39764 :     bPrep = bPrepWidows = bPrepAdjust = bPrepMustFit = false;
     370       39764 : }
     371             : 
     372       30316 : inline void SwParaPortion::FormatReset()
     373             : {
     374       30316 :     nDelta = 0;
     375       30316 :     aReformat = SwCharRange(0, COMPLETE_STRING);
     376             :     // bFlys needs to be retained in SwTxtFrm::_Format() so that empty
     377             :     // paragraphs that needed to avoid Frames with no flow, reformat
     378             :     // when the Frame disappears from the Area
     379             :     // bFlys = false;
     380       30316 :     ResetPreps();
     381       30316 :     bFollowField = bFixLineHeight = bMargin = false;
     382       30316 : }
     383             : 
     384      175539 : inline SwLinePortion *SwLineLayout::GetFirstPortion() const
     385      175539 : { return( pPortion ? pPortion : (SwLinePortion*)this ); }
     386             : 
     387             : #endif
     388             : 
     389             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10