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

Generated by: LCOV version 1.10