LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/text - itrtxt.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 170 213 79.8 %
Date: 2013-07-09 Functions: 22 23 95.7 %
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             : 
      20             : #include "ndtxt.hxx"
      21             : #include "flyfrm.hxx"
      22             : #include "paratr.hxx"
      23             : #include <vcl/outdev.hxx>
      24             : #include <editeng/paravertalignitem.hxx>
      25             : 
      26             : #include "pormulti.hxx"
      27             : #include <pagefrm.hxx>
      28             : #include <pagedesc.hxx> // SwPageDesc
      29             : #include <tgrditem.hxx>
      30             : #include <porfld.hxx>
      31             : 
      32             : #include "itrtxt.hxx"
      33             : #include "txtfrm.hxx"
      34             : #include "porfly.hxx"
      35             : 
      36             : /*************************************************************************
      37             :  *                      SwTxtIter::CtorInitTxtIter()
      38             :  *************************************************************************/
      39             : 
      40       48573 : void SwTxtIter::CtorInitTxtIter( SwTxtFrm *pNewFrm, SwTxtInfo *pNewInf )
      41             : {
      42       48573 :     SwTxtNode *pNode = pNewFrm->GetTxtNode();
      43             : 
      44             :     OSL_ENSURE( pNewFrm->GetPara(), "No paragraph" );
      45             : 
      46       48573 :     CtorInitAttrIter( *pNode, pNewFrm->GetPara()->GetScriptInfo(), pNewFrm );
      47             : 
      48       48573 :     pFrm = pNewFrm;
      49       48573 :     pInf = pNewInf;
      50       48573 :     aLineInf.CtorInitLineInfo( pNode->GetSwAttrSet(), *pNode );
      51       48573 :     nFrameStart = pFrm->Frm().Pos().Y() + pFrm->Prt().Pos().Y();
      52       48573 :     SwTxtIter::Init();
      53       48573 :     if( pNode->GetSwAttrSet().GetRegister().GetValue() )
      54           0 :         bRegisterOn = pFrm->FillRegister( nRegStart, nRegDiff );
      55             :     else
      56       48573 :         bRegisterOn = sal_False;
      57       48573 : }
      58             : 
      59             : /*************************************************************************
      60             :  *                      SwTxtIter::Init()
      61             :  *************************************************************************/
      62             : 
      63       48642 : void SwTxtIter::Init()
      64             : {
      65       48642 :     pCurr = pInf->GetParaPortion();
      66       48642 :     nStart = pInf->GetTxtStart();
      67       48642 :     nY = nFrameStart;
      68       48642 :     bPrev = sal_True;
      69       48642 :     pPrev = 0;
      70       48642 :     nLineNr = 1;
      71       48642 : }
      72             : 
      73             : /*************************************************************************
      74             :  *                 SwTxtIter::_GetHeightAndAscent()
      75             :  *************************************************************************/
      76             : 
      77       42022 : void SwTxtIter::CalcAscentAndHeight( KSHORT &rAscent, KSHORT &rHeight ) const
      78             : {
      79       42022 :     rHeight = GetLineHeight();
      80       42022 :     rAscent = pCurr->GetAscent() + rHeight - pCurr->Height();
      81       42022 : }
      82             : 
      83             : /*************************************************************************
      84             :  *                    SwTxtIter::_GetPrev()
      85             :  *************************************************************************/
      86             : 
      87          54 : SwLineLayout *SwTxtIter::_GetPrev()
      88             : {
      89          54 :     pPrev = 0;
      90          54 :     bPrev = sal_True;
      91          54 :     SwLineLayout *pLay = pInf->GetParaPortion();
      92          54 :     if( pCurr == pLay )
      93           2 :         return 0;
      94        1344 :     while( pLay->GetNext() != pCurr )
      95        1240 :         pLay = pLay->GetNext();
      96          52 :     return pPrev = pLay;
      97             : }
      98             : 
      99             : /*************************************************************************
     100             :  *                    SwTxtIter::GetPrev()
     101             :  *************************************************************************/
     102             : 
     103        7477 : const SwLineLayout *SwTxtIter::GetPrev()
     104             : {
     105        7477 :     if(! bPrev)
     106           0 :         _GetPrev();
     107        7477 :     return pPrev;
     108             : }
     109             : 
     110             : /*************************************************************************
     111             :  *                    SwTxtIter::Prev()
     112             :  *************************************************************************/
     113             : 
     114        1409 : const SwLineLayout *SwTxtIter::Prev()
     115             : {
     116        1409 :     if( !bPrev )
     117          54 :         _GetPrev();
     118        1409 :     if( pPrev )
     119             :     {
     120         965 :         bPrev = sal_False;
     121         965 :         pCurr = pPrev;
     122         965 :         nStart = nStart - pCurr->GetLen();
     123         965 :         nY = nY - GetLineHeight();
     124         965 :         if( !pCurr->IsDummy() && !(--nLineNr) )
     125           0 :             ++nLineNr;
     126         965 :         return pCurr;
     127             :     }
     128             :     else
     129         444 :         return 0;
     130             : }
     131             : 
     132             : /*************************************************************************
     133             :  *                      SwTxtIter::Next()
     134             :  *************************************************************************/
     135             : 
     136      459161 : const SwLineLayout *SwTxtIter::Next()
     137             : {
     138      459161 :     if(pCurr->GetNext())
     139             :     {
     140      407300 :         pPrev = pCurr;
     141      407300 :         bPrev = sal_True;
     142      407300 :         nStart = nStart + pCurr->GetLen();
     143      407300 :         nY += GetLineHeight();
     144      407300 :         if( pCurr->GetLen() || ( nLineNr>1 && !pCurr->IsDummy() ) )
     145      407010 :             ++nLineNr;
     146      407300 :         return pCurr = pCurr->GetNext();
     147             :     }
     148             :     else
     149       51861 :         return 0;
     150             : }
     151             : 
     152             : /*************************************************************************
     153             :  *                      SwTxtIter::NextLine()
     154             :  *************************************************************************/
     155             : 
     156           0 : const SwLineLayout *SwTxtIter::NextLine()
     157             : {
     158           0 :     const SwLineLayout *pNext = Next();
     159           0 :     while( pNext && pNext->IsDummy() && pNext->GetNext() )
     160             :     {
     161           0 :         pNext = Next();
     162             :     }
     163           0 :     return pNext;
     164             : }
     165             : 
     166             : /*************************************************************************
     167             :  *                      SwTxtIter::GetNextLine()
     168             :  *************************************************************************/
     169             : 
     170       18483 : const SwLineLayout *SwTxtIter::GetNextLine() const
     171             : {
     172       18483 :     const SwLineLayout *pNext = pCurr->GetNext();
     173       36978 :     while( pNext && pNext->IsDummy() && pNext->GetNext() )
     174             :     {
     175          12 :         pNext = pNext->GetNext();
     176             :     }
     177       18483 :     return (SwLineLayout*)pNext;
     178             : }
     179             : 
     180             : /*************************************************************************
     181             :  *                      SwTxtIter::GetPrevLine()
     182             :  *************************************************************************/
     183             : 
     184           4 : const SwLineLayout *SwTxtIter::GetPrevLine()
     185             : {
     186           4 :     const SwLineLayout *pRoot = pInf->GetParaPortion();
     187           4 :     if( pRoot == pCurr )
     188           4 :         return 0;
     189           0 :     const SwLineLayout *pLay = pRoot;
     190             : 
     191           0 :     while( pLay->GetNext() != pCurr )
     192           0 :         pLay = pLay->GetNext();
     193             : 
     194           0 :     if( pLay->IsDummy() )
     195             :     {
     196           0 :         const SwLineLayout *pTmp = pRoot;
     197           0 :         pLay = pRoot->IsDummy() ? 0 : pRoot;
     198           0 :         while( pTmp->GetNext() != pCurr )
     199             :         {
     200           0 :             if( !pTmp->IsDummy() )
     201           0 :                 pLay = pTmp;
     202           0 :             pTmp = pTmp->GetNext();
     203             :         }
     204             :     }
     205             : 
     206             :     // Wenn sich nichts getan hat, dann gibt es nur noch Dummys
     207           0 :     return (SwLineLayout*)pLay;
     208             : }
     209             : 
     210             : /*************************************************************************
     211             :  *                      SwTxtIter::PrevLine()
     212             :  *************************************************************************/
     213             : 
     214         318 : const SwLineLayout *SwTxtIter::PrevLine()
     215             : {
     216         318 :     const SwLineLayout *pMyPrev = Prev();
     217         318 :     if( !pMyPrev )
     218          13 :         return 0;
     219             : 
     220         305 :     const SwLineLayout *pLast = pMyPrev;
     221         611 :     while( pMyPrev && pMyPrev->IsDummy() )
     222             :     {
     223           1 :         pLast = pMyPrev;
     224           1 :         pMyPrev = Prev();
     225             :     }
     226         305 :     return (SwLineLayout*)(pMyPrev ? pMyPrev : pLast);
     227             : }
     228             : 
     229             : /*************************************************************************
     230             :  *                      SwTxtIter::Bottom()
     231             :  *************************************************************************/
     232             : 
     233       14244 : void SwTxtIter::Bottom()
     234             : {
     235       14244 :     while( Next() )
     236             :     {
     237             :         // nothing
     238             :     }
     239       14244 : }
     240             : 
     241             : /*************************************************************************
     242             :  *                      SwTxtIter::CharToLine()
     243             :  *************************************************************************/
     244             : 
     245       36320 : void SwTxtIter::CharToLine(const xub_StrLen nChar)
     246             : {
     247       36320 :     while( nStart + pCurr->GetLen() <= nChar && Next() )
     248             :         ;
     249       36320 :     while( nStart > nChar && Prev() )
     250             :         ;
     251       36320 : }
     252             : 
     253             : /*************************************************************************
     254             :  *                      SwTxtIter::CharCrsrToLine()
     255             :  *************************************************************************/
     256             : 
     257             : // 1170: beruecksichtigt Mehrdeutigkeiten:
     258       28783 : const SwLineLayout *SwTxtCursor::CharCrsrToLine( const xub_StrLen nPosition )
     259             : {
     260       28783 :     CharToLine( nPosition );
     261       28783 :     if( nPosition != nStart )
     262       22869 :         bRightMargin = sal_False;
     263       28783 :     sal_Bool bPrevious = bRightMargin && pCurr->GetLen() && GetPrev() &&
     264       28783 :         GetPrev()->GetLen();
     265       28783 :     if( bPrevious && nPosition && CH_BREAK == GetInfo().GetChar( nPosition-1 ) )
     266           0 :         bPrevious = sal_False;
     267       28783 :     return bPrevious ? PrevLine() : pCurr;
     268             : }
     269             : 
     270             : /*************************************************************************
     271             :  *                      SwTxtCrsr::AdjustBaseLine()
     272             :  *************************************************************************/
     273             : 
     274       26182 : sal_uInt16 SwTxtCursor::AdjustBaseLine( const SwLineLayout& rLine,
     275             :                                     const SwLinePortion* pPor,
     276             :                                     sal_uInt16 nPorHeight, sal_uInt16 nPorAscent,
     277             :                                     const sal_Bool bAutoToCentered ) const
     278             : {
     279       26182 :     if ( pPor )
     280             :     {
     281         738 :         nPorHeight = pPor->Height();
     282         738 :         nPorAscent = pPor->GetAscent();
     283             :     }
     284             : 
     285       26182 :     sal_uInt16 nOfst = rLine.GetRealHeight() - rLine.Height();
     286             : 
     287       26182 :     GETGRID( pFrm->FindPageFrm() )
     288       26182 :     const sal_Bool bHasGrid = pGrid && GetInfo().SnapToGrid();
     289             : 
     290       26182 :     if ( bHasGrid )
     291             :     {
     292          18 :         const sal_uInt16 nRubyHeight = pGrid->GetRubyHeight();
     293          18 :         const sal_Bool bRubyTop = ! pGrid->GetRubyTextBelow();
     294             : 
     295          18 :         if ( GetInfo().IsMulti() )
     296             :             // we are inside the GetCharRect recursion for multi portions
     297             :             // we center the portion in its surrounding line
     298           0 :             nOfst = ( pCurr->Height() - nPorHeight ) / 2 + nPorAscent;
     299             :         else
     300             :         {
     301             :             // We have to take care for ruby portions.
     302             :             // The ruby portion is NOT centered
     303          18 :             nOfst = nOfst + nPorAscent;
     304             : 
     305          18 :             if ( ! pPor || ! pPor->IsMultiPortion() ||
     306           0 :                  ! ((SwMultiPortion*)pPor)->IsRuby() )
     307             :             {
     308             :                 // Portions which are bigger than on grid distance are
     309             :                 // centered inside the whole line.
     310             : 
     311             :                 //for text refactor
     312          18 :                 const sal_uInt16 nLineNetto =  rLine.Height() - nRubyHeight;
     313             :                 //const sal_uInt16 nLineNetto = ( nPorHeight > nGridWidth ) ?
     314             :                  //                           rLine.Height() - nRubyHeight :
     315             :                  //                           nGridWidth;
     316          18 :                 nOfst += ( nLineNetto - nPorHeight ) / 2;
     317          18 :                 if ( bRubyTop )
     318          18 :                     nOfst = nOfst + nRubyHeight;
     319             :             }
     320             :         }
     321             :     }
     322             :     else
     323             :     {
     324       26164 :         switch ( GetLineInfo().GetVertAlign() ) {
     325             :             case SvxParaVertAlignItem::TOP :
     326           0 :                 nOfst = nOfst + nPorAscent;
     327           0 :                 break;
     328             :             case SvxParaVertAlignItem::CENTER :
     329             :                 OSL_ENSURE( rLine.Height() >= nPorHeight, "Portion height > Line height");
     330           0 :                 nOfst += ( rLine.Height() - nPorHeight ) / 2 + nPorAscent;
     331           0 :                 break;
     332             :             case SvxParaVertAlignItem::BOTTOM :
     333           0 :                 nOfst += rLine.Height() - nPorHeight + nPorAscent;
     334           0 :                 break;
     335             :             case SvxParaVertAlignItem::AUTOMATIC :
     336       26150 :                 if ( bAutoToCentered || GetInfo().GetTxtFrm()->IsVertical() )
     337             :                 {
     338             :                     //Badaa: 2008-04-18 * Support for Classical Mongolian Script (SCMS) joint with Jiayanmin
     339           0 :                     if( GetInfo().GetTxtFrm()->IsVertLR() )
     340           0 :                             nOfst += rLine.Height() - ( rLine.Height() - nPorHeight ) / 2 - nPorAscent;
     341             :                     else
     342           0 :                             nOfst += ( rLine.Height() - nPorHeight ) / 2 + nPorAscent;
     343           0 :                     break;
     344             :                 }
     345             :             case SvxParaVertAlignItem::BASELINE :
     346             :                 // base line
     347       26164 :                 nOfst = nOfst + rLine.GetAscent();
     348       26164 :                 break;
     349             :         }
     350             :     }
     351             : 
     352       26182 :     return nOfst;
     353             : }
     354             : 
     355             : /*************************************************************************
     356             :  *                      SwTxtIter::TwipsToLine()
     357             :  *************************************************************************/
     358             : 
     359        6595 : const SwLineLayout *SwTxtIter::TwipsToLine( const SwTwips y)
     360             : {
     361        6595 :     while( nY + GetLineHeight() <= y && Next() )
     362             :         ;
     363        6595 :     while( nY > y && Prev() )
     364             :         ;
     365        6595 :     return pCurr;
     366             : }
     367             : 
     368             : //
     369             : // Local helper function to check, if pCurr needs a field rest portion:
     370             : //
     371           2 : static sal_Bool lcl_NeedsFieldRest( const SwLineLayout* pCurr )
     372             : {
     373           2 :     const SwLinePortion *pPor = pCurr->GetPortion();
     374           2 :     sal_Bool bRet = sal_False;
     375           4 :     while( pPor && !bRet )
     376             :     {
     377           2 :         bRet = pPor->InFldGrp() && ((SwFldPortion*)pPor)->HasFollow();
     378           2 :         if( !pPor->GetPortion() || !pPor->GetPortion()->InFldGrp() )
     379           2 :             break;
     380           0 :         pPor = pPor->GetPortion();
     381             :     }
     382           2 :     return bRet;
     383             : }
     384             : 
     385             : /*************************************************************************
     386             :  *                      SwTxtIter::TruncLines()
     387             :  *************************************************************************/
     388             : 
     389        7768 : void SwTxtIter::TruncLines( bool bNoteFollow )
     390             : {
     391        7768 :     SwLineLayout *pDel = pCurr->GetNext();
     392        7768 :     const xub_StrLen nEnd = nStart + pCurr->GetLen();
     393             : 
     394        7768 :     if( pDel )
     395             :     {
     396         357 :         pCurr->SetNext( 0 );
     397         357 :         if( GetHints() && bNoteFollow )
     398             :         {
     399           6 :             GetInfo().GetParaPortion()->SetFollowField( pDel->IsRest() ||
     400           6 :                                                         lcl_NeedsFieldRest( pCurr ) );
     401             : 
     402             :             // bug 88534: wrong positioning of flys
     403           2 :             SwTxtFrm* pFollow = GetTxtFrm()->GetFollow();
     404           4 :             if ( pFollow && ! pFollow->IsLocked() &&
     405           2 :                  nEnd == pFollow->GetOfst() )
     406             :             {
     407           2 :                 xub_StrLen nRangeEnd = nEnd;
     408           2 :                 SwLineLayout* pLine = pDel;
     409             : 
     410             :                 // determine range to be searched for flys anchored as characters
     411           6 :                 while ( pLine )
     412             :                 {
     413           2 :                     nRangeEnd = nRangeEnd + pLine->GetLen();
     414           2 :                     pLine = pLine->GetNext();
     415             :                 }
     416             : 
     417           2 :                 SwpHints* pTmpHints = GetTxtFrm()->GetTxtNode()->GetpSwpHints();
     418             : 
     419             :                 // examine hints in range nEnd - (nEnd + nRangeChar)
     420          10 :                 for( sal_uInt16 i = 0; i < pTmpHints->Count(); i++ )
     421             :                 {
     422           8 :                     const SwTxtAttr* pHt = pTmpHints->GetTextHint( i );
     423           8 :                     if( RES_TXTATR_FLYCNT == pHt->Which() )
     424             :                     {
     425             :                         // check, if hint is in our range
     426           8 :                         const sal_uInt16 nTmpPos = *pHt->GetStart();
     427           8 :                         if ( nEnd <= nTmpPos && nTmpPos < nRangeEnd )
     428             :                             pFollow->_InvalidateRange(
     429           3 :                                 SwCharRange( nTmpPos, nTmpPos ), 0 );
     430             :                     }
     431             :                 }
     432             :             }
     433             :         }
     434         357 :         delete pDel;
     435             :     }
     436       16802 :     if( pCurr->IsDummy() &&
     437        9025 :         !pCurr->GetLen() &&
     438        1257 :          nStart < GetTxtFrm()->GetTxt().Len() )
     439           0 :         pCurr->SetRealHeight( 1 );
     440        7768 :     if( GetHints() )
     441        1889 :         pFrm->RemoveFtn( nEnd );
     442        7768 : }
     443             : 
     444             : /*************************************************************************
     445             :  *                      SwTxtIter::CntHyphens()
     446             :  *************************************************************************/
     447             : 
     448           1 : void SwTxtIter::CntHyphens( sal_uInt8 &nEndCnt, sal_uInt8 &nMidCnt) const
     449             : {
     450           1 :     nEndCnt = 0;
     451           1 :     nMidCnt = 0;
     452           1 :     if ( bPrev && pPrev && !pPrev->IsEndHyph() && !pPrev->IsMidHyph() )
     453           0 :          return;
     454           1 :     SwLineLayout *pLay = pInf->GetParaPortion();
     455           1 :     if( pCurr == pLay )
     456           1 :         return;
     457           0 :     while( pLay != pCurr )
     458             :     {
     459           0 :         if ( pLay->IsEndHyph() )
     460           0 :             nEndCnt++;
     461             :         else
     462           0 :             nEndCnt = 0;
     463           0 :         if ( pLay->IsMidHyph() )
     464           0 :             nMidCnt++;
     465             :         else
     466           0 :             nMidCnt = 0;
     467           0 :         pLay = pLay->GetNext();
     468             :     }
     469             : }
     470             : 
     471             : /*************************************************************************
     472             :  *                          SwHookOut
     473             :  *
     474             :  * Change current output device to formatting device, this has to be done before
     475             :  * formatting.
     476             :  *************************************************************************/
     477             : 
     478       24068 : SwHookOut::SwHookOut( SwTxtSizeInfo& rInfo ) :
     479             :      pInf( &rInfo ),
     480       24068 :      pOut( rInfo.GetOut() ),
     481       48136 :      bOnWin( rInfo.OnWin() )
     482             : {
     483             :     OSL_ENSURE( rInfo.GetRefDev(), "No reference device for text formatting" );
     484             : 
     485             :     // set new values
     486       24068 :     rInfo.SetOut( rInfo.GetRefDev() );
     487       24068 :     rInfo.SetOnWin( false );
     488       24068 : }
     489             : 
     490       24068 : SwHookOut::~SwHookOut()
     491             : {
     492       24068 :     pInf->SetOut( pOut );
     493       24068 :     pInf->SetOnWin( bOnWin );
     494       24167 : }
     495             : 
     496             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10