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

Generated by: LCOV version 1.10