LCOV - code coverage report
Current view: top level - sw/source/core/text - itrtxt.hxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 88 91 96.7 %
Date: 2014-11-03 Functions: 58 65 89.2 %
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_ITRTXT_HXX
      20             : #define INCLUDED_SW_SOURCE_CORE_TEXT_ITRTXT_HXX
      21             : #include "swtypes.hxx"
      22             : #include "itratr.hxx"
      23             : #include "inftxt.hxx"
      24             : 
      25             : class SwTxtFrm;
      26             : struct SwPosition;
      27             : struct SwCrsrMoveState;
      28             : class SwMarginPortion;
      29             : class SwFlyPortion;
      30             : 
      31      318182 : class SwTxtIter : public SwAttrIter
      32             : {
      33             : protected:
      34             :     SwLineInfo aLineInf;
      35             :     SwTxtFrm  *pFrm;
      36             :     SwTxtInfo *pInf;
      37             :     SwLineLayout *pCurr;
      38             :     SwLineLayout *pPrev;
      39             :     SwTwips nFrameStart;
      40             :     SwTwips nY;
      41             :     SwTwips nRegStart;          // The register's start position (Y)
      42             :     sal_Int32 nStart;          // Start in the text string, end = pCurr->GetLen()
      43             :     sal_uInt16 nRegDiff;            // Register's line distance
      44             :     sal_uInt16 nLineNr;             // Line number
      45             :     bool bPrev          : 1;
      46             :     bool bRegisterOn    : 1;    // Keep in register
      47             :     bool bOneBlock      : 1;    // Justified text: Dispose single words
      48             :     bool bLastBlock     : 1;    // Justified text: Also the last line
      49             :     bool bLastCenter    : 1;    // Justified text: Center last line
      50             : 
      51             :     SwLineLayout *_GetPrev();
      52             : 
      53             :     // Reset in the first line
      54             :     void Init();
      55             :     void CtorInitTxtIter( SwTxtFrm *pFrm, SwTxtInfo *pInf );
      56      317328 :     inline SwTxtIter(SwTxtNode* pTxtNode)
      57             :         : SwAttrIter(pTxtNode)
      58             :         , pFrm(NULL)
      59             :         , pInf(NULL)
      60             :         , pCurr(NULL)
      61             :         , pPrev(NULL)
      62             :         , nFrameStart(0)
      63             :         , nY(0)
      64             :         , nRegStart(0)
      65             :         , nStart(0)
      66             :         , nRegDiff(0)
      67             :         , nLineNr(0)
      68             :         , bPrev(false)
      69             :         , bRegisterOn(false)
      70             :         , bOneBlock(false)
      71             :         , bLastBlock(false)
      72      317328 :         , bLastCenter(false)
      73      317328 :         {}
      74             : public:
      75         854 :     inline SwTxtIter( SwTxtFrm *pTxtFrm, SwTxtInfo *pTxtInf )
      76             :         : SwAttrIter( pTxtFrm != NULL ? pTxtFrm->GetTxtNode() : NULL)
      77             :         , bOneBlock(false)
      78             :         , bLastBlock(false)
      79         854 :         , bLastCenter(false)
      80             :         {
      81         854 :             CtorInitTxtIter( pTxtFrm, pTxtInf );
      82         854 :         }
      83     1276584 :     inline const SwLineLayout *GetCurr() const { return pCurr; } // NEVER 0!
      84       13741 :     inline const SwLineLayout *GetNext() const { return pCurr->GetNext(); }
      85             :            const SwLineLayout *GetPrev();
      86      292470 :     inline sal_Int32 GetLength() const { return pCurr->GetLen(); }
      87      566369 :     inline sal_uInt16 GetLineNr() const { return nLineNr; }
      88      694507 :     inline sal_Int32 GetStart() const { return nStart; }
      89      208404 :     inline sal_Int32 GetEnd() const { return GetStart() + GetLength(); }
      90     1032524 :     inline SwTwips Y() const { return nY; }
      91             : 
      92           0 :     inline SwTwips RegStart() const { return nRegStart; }
      93           0 :     inline sal_uInt16 RegDiff() const { return nRegDiff; }
      94      180277 :     inline bool IsRegisterOn() const { return bRegisterOn; }
      95             : 
      96     7795520 :     inline SwTxtInfo &GetInfo() { return *pInf; }
      97     2074512 :     inline const SwTxtInfo &GetInfo() const { return *pInf; }
      98             : 
      99        2742 :     inline void Top() { Init(); }
     100             :     void Bottom();
     101             :     const SwLineLayout *Next();
     102             :     const SwLineLayout *Prev();
     103             : 
     104             :     // Skips the FlyFrms dummy line
     105             :     const SwLineLayout *NextLine();
     106             :     const SwLineLayout *PrevLine();
     107             :     const SwLineLayout *GetNextLine() const;
     108             :     const SwLineLayout *GetPrevLine();
     109             : 
     110             :     void CharToLine( const sal_Int32 );
     111             :     const SwLineLayout *TwipsToLine(const SwTwips);
     112             : 
     113             :     // Truncates all after pCurr
     114             :     void TruncLines( bool bNoteFollow = false );
     115             : 
     116     1548643 :     inline sal_uInt16 GetLineHeight() const { return pCurr->GetRealHeight(); }
     117             :     void CalcAscentAndHeight( sal_uInt16 &rAscent, sal_uInt16 &rHeight ) const;
     118             : 
     119             :     // Lots of trouble for querying pCurr == pPara
     120      740173 :     inline bool IsFirstTxtLine() const
     121     1754814 :     { return nStart == GetInfo().GetTxtStart() &&
     122     1316353 :         !( pCurr->IsDummy() && GetNextLine() ); }
     123             : 
     124             :     // Replacement for the old IsFirstLine()
     125      347852 :     inline bool IsParaLine() const
     126      347852 :         { return pCurr == pInf->GetParaPortion(); }
     127             : 
     128      143102 :     const SwLineInfo &GetLineInfo() const { return aLineInf; }
     129             :     inline SwTwips GetFirstPos() const { return nFrameStart; }
     130             :     inline bool SeekAndChg( SwTxtSizeInfo &rInf );
     131             :     inline bool SeekAndChgBefore( SwTxtSizeInfo &rInf );
     132             :     inline bool SeekStartAndChg( SwTxtSizeInfo &rInf, const bool bPara=false );
     133             : 
     134     1046580 :     inline SwTxtFrm *GetTxtFrm() { return pFrm; }
     135        8752 :     inline const SwTxtFrm *GetTxtFrm() const { return pFrm; }
     136             : 
     137             :     // Counts consecutive hyphens in order to be within the boundary given by MaxHyphens
     138             :     void CntHyphens( sal_uInt8 &nEndCnt, sal_uInt8 &nMidCnt) const;
     139             : };
     140             : 
     141      317328 : class SwTxtMargin : public SwTxtIter
     142             : {
     143             : private:
     144             :           SwTwips nLeft;
     145             :           SwTwips nRight;
     146             :           SwTwips nFirst;
     147             :           sal_uInt16  nDropLeft;
     148             :           sal_uInt16  nDropHeight;
     149             :           sal_uInt16  nDropDescent;
     150             :           sal_uInt16  nDropLines;
     151             :           sal_uInt16  nAdjust;
     152             :           // #i91133#
     153             :           SwTwips mnTabLeft;
     154             : 
     155             : protected:
     156             :     // For FormatQuoVadis
     157           0 :     inline void Right( const SwTwips nNew ) { nRight = nNew; }
     158             :     // For CalcFlyAdjust
     159             :     inline void SetDropLeft( const sal_uInt16 nNew ) { nDropLeft = nNew; }
     160             : 
     161             :     void CtorInitTxtMargin( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
     162      237348 :     inline SwTxtMargin(SwTxtNode* pTxtNode)
     163             :         : SwTxtIter(pTxtNode)
     164             :         , nLeft(0)
     165             :         , nRight(0)
     166             :         , nFirst(0)
     167             :         , nDropLeft(0)
     168             :         , nDropHeight(0)
     169             :         , nDropDescent(0)
     170             :         , nDropLines(0)
     171             :         , nAdjust(0)
     172      237348 :         , mnTabLeft(0)
     173      237348 :         { }
     174             : public:
     175       79980 :     inline SwTxtMargin( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf )
     176       79980 :         : SwTxtIter( pTxtFrm != NULL ? pTxtFrm->GetTxtNode() : NULL)
     177             :         {
     178       79980 :             CtorInitTxtMargin( pTxtFrm, pTxtSizeInf );
     179       79980 :         }
     180             :     inline SwTwips GetLeftMargin() const;
     181             :     inline SwTwips Left() const;
     182      388651 :     inline SwTwips Right() const { return nRight; }
     183      143092 :     inline SwTwips FirstLeft() const { return nFirst; }
     184       13396 :     inline SwTwips CurrWidth() const { return pCurr->PrtWidth(); }
     185             :            SwTwips GetLineStart() const;
     186         234 :     inline SwTwips GetLineEnd() const { return GetLineStart() + CurrWidth(); }
     187      263525 :     inline Point GetTopLeft() const { return Point( GetLineStart(), Y() ); }
     188          28 :     inline bool IsOneBlock() const { return bOneBlock; }
     189        1208 :     inline bool IsLastBlock() const { return bLastBlock; }
     190         618 :     inline bool IsLastCenter() const { return bLastCenter; }
     191      477606 :     inline sal_uInt16 GetAdjust() const { return nAdjust; }
     192       13510 :     inline sal_uInt16 GetLineWidth() const
     193       13510 :            { return sal_uInt16( Right() - GetLeftMargin() + 1 ); }
     194       53819 :     inline SwTwips GetLeftMin() const { return nFirst < nLeft ? nFirst : nLeft; }
     195         370 :     inline bool HasNegFirst() const { return nFirst < nLeft; }
     196             : 
     197             :     // #i91133#
     198        5022 :     inline SwTwips GetTabLeft() const
     199             :     {
     200        5022 :         return mnTabLeft;
     201             :     }
     202             :     // DropCaps
     203      135614 :     inline sal_uInt16 GetDropLines() const { return nDropLines; }
     204          36 :     inline void SetDropLines( const sal_uInt16 nNew ) { nDropLines = nNew; }
     205       53819 :     inline sal_uInt16 GetDropLeft() const { return nDropLeft; }
     206         120 :     inline sal_uInt16 GetDropHeight() const { return nDropHeight; }
     207          36 :     inline void SetDropHeight( const sal_uInt16 nNew ) { nDropHeight = nNew; }
     208          24 :     inline sal_uInt16 GetDropDescent() const { return nDropDescent; }
     209          36 :     inline void SetDropDescent( const sal_uInt16 nNew ) { nDropDescent = nNew; }
     210             :     void DropInit();
     211             : 
     212             :     // Returns the TxtPos for start and end of the current line without whitespace
     213             :     // Implemented in frminf.cxx
     214             :     sal_Int32 GetTxtStart() const;
     215             :     sal_Int32 GetTxtEnd() const;
     216             : 
     217      921763 :     inline SwTxtSizeInfo &GetInfo()
     218      921763 :         { return (SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
     219      101884 :     inline const SwTxtSizeInfo &GetInfo() const
     220      101884 :         { return (const SwTxtSizeInfo&)SwTxtIter::GetInfo(); }
     221             : 
     222             : };
     223             : 
     224      237348 : class SwTxtAdjuster : public SwTxtMargin
     225             : {
     226             :     // Adjusts the portion, if we have adjustment and FlyFrms
     227             :     void CalcFlyAdjust( SwLineLayout *pCurr );
     228             : 
     229             :     // Calls SplitGlues and CalcBlockAdjust
     230             :     void FormatBlock( );
     231             : 
     232             :     // Creates the glue chain for short lines
     233             :     SwMarginPortion* CalcRightMargin( SwLineLayout *pCurr, SwTwips nReal = 0 );
     234             : 
     235             :     // Calculate the adjustment (FlyPortions)
     236             :     SwFlyPortion *CalcFlyPortion( const long nRealWidth,
     237             :                                   const SwRect &rCurrRect );
     238             : 
     239             : protected:
     240      237348 :     inline SwTxtAdjuster(SwTxtNode* pTxtNode) : SwTxtMargin(pTxtNode) { }
     241             :     // Creates the Glues for adjusted paragraphs
     242             :     void CalcNewBlock( SwLineLayout *pCurr, const SwLinePortion *pStopAt,
     243             :         SwTwips nReal = 0, bool bSkipKashida = false );
     244             :     SwTwips CalcKanaAdj( SwLineLayout *pCurr );
     245             : public:
     246             :     inline SwTxtAdjuster( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf ) : SwTxtMargin(pTxtFrm!=NULL?pTxtFrm->GetTxtNode():NULL)
     247             :            { CtorInitTxtMargin( pTxtFrm, pTxtSizeInf ); }
     248             : 
     249             :     // Is overloaded by SwTxtFormatter due to UpdatePos
     250             :     void CalcAdjLine( SwLineLayout *pCurr );
     251             : 
     252             :     // For adjusting afterwards
     253      163797 :     inline void GetAdjusted() const
     254             :     {
     255      163797 :         if( pCurr->IsFormatAdj() )
     256        2748 :             ((SwTxtAdjuster*)this)->CalcAdjLine( pCurr );
     257      163797 :     }
     258             : 
     259             :     // Special treatment for DropCaps
     260             :     void CalcDropAdjust();
     261             :     void CalcDropRepaint();
     262             : };
     263             : 
     264      237348 : class SwTxtCursor : public SwTxtAdjuster
     265             : {
     266             :     // A small helper-class to save SwTxtCursor member, manipulate them
     267             :     // and to restore them
     268             :     friend class SwTxtCursorSave;
     269             : 
     270             :     // Ambiguities
     271             :     static bool bRightMargin;
     272             :     void _GetCharRect(SwRect *, const sal_Int32, SwCrsrMoveState* );
     273             : protected:
     274             :     void CtorInitTxtCursor( SwTxtFrm *pFrm, SwTxtSizeInfo *pInf );
     275      119602 :     SwTxtCursor(SwTxtNode* pTxtNode) : SwTxtAdjuster(pTxtNode) { }
     276             : public:
     277      117746 :     SwTxtCursor( SwTxtFrm *pTxtFrm, SwTxtSizeInfo *pTxtSizeInf )
     278      117746 :         : SwTxtAdjuster(pTxtFrm->GetTxtNode())
     279             :     {
     280      117746 :         CtorInitTxtCursor(pTxtFrm, pTxtSizeInf);
     281      117746 :     }
     282             :     bool GetCharRect(SwRect *, const sal_Int32, SwCrsrMoveState* = 0,
     283             :         const long nMax = 0 );
     284             :     bool GetEndCharRect(SwRect *, const sal_Int32, SwCrsrMoveState* = 0,
     285             :         const long nMax = 0 );
     286             :     sal_Int32 GetCrsrOfst( SwPosition *pPos, const Point &rPoint,
     287             :                 bool nChgNode, SwCrsrMoveState* = 0 ) const;
     288             :     // Respects ambiguities: For the implementation see below
     289             :     const SwLineLayout *CharCrsrToLine( const sal_Int32 nPos );
     290             : 
     291             :     // calculates baseline for portion rPor
     292             :     // bAutoToCentered indicates, if AUTOMATIC mode means CENTERED or BASELINE
     293             :     sal_uInt16 AdjustBaseLine( const SwLineLayout& rLine, const SwLinePortion* pPor,
     294             :                            sal_uInt16 nPorHeight = 0, sal_uInt16 nAscent = 0,
     295             :                            const bool bAutoToCentered = false ) const;
     296             : 
     297           6 :     static inline void SetRightMargin( const bool bNew ){ bRightMargin = bNew; }
     298         216 :     static inline bool IsRightMargin() { return bRightMargin; }
     299             : };
     300             : 
     301             : // Change current output device to printer, this has to be done before
     302             : // formatting.
     303             : class SwHookOut
     304             : {
     305             :     SwTxtSizeInfo* pInf;
     306             :     OutputDevice* pOut;
     307             :     bool bOnWin;
     308             : public:
     309             :     SwHookOut( SwTxtSizeInfo& rInfo );
     310             :     ~SwHookOut();
     311             : };
     312             : 
     313      500532 : inline bool SwTxtIter::SeekAndChg( SwTxtSizeInfo &rInf )
     314             : {
     315      500532 :     return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
     316             : }
     317             : 
     318         146 : inline bool SwTxtIter::SeekAndChgBefore( SwTxtSizeInfo &rInf )
     319             : {
     320         146 :     if ( rInf.GetIdx() )
     321           2 :         return SeekAndChgAttrIter( rInf.GetIdx()-1, rInf.GetOut() );
     322             :     else
     323         144 :         return SeekAndChgAttrIter( rInf.GetIdx(), rInf.GetOut() );
     324             : }
     325             : 
     326       24749 : inline bool SwTxtIter::SeekStartAndChg( SwTxtSizeInfo &rInf, const bool bPara )
     327             : {
     328       24749 :     return SeekStartAndChgAttrIter( rInf.GetOut(), bPara );
     329             : }
     330             : 
     331      739613 : inline SwTwips SwTxtMargin::GetLeftMargin() const
     332             : {
     333      739613 :     return IsFirstTxtLine() ? nFirst : Left();
     334             : }
     335             : 
     336      437054 : inline SwTwips SwTxtMargin::Left() const
     337             : {
     338      437054 :     return (nDropLines >= nLineNr && 1 != nLineNr) ? nFirst + nDropLeft : nLeft;
     339             : }
     340             : 
     341             : #endif
     342             : 
     343             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10