LCOV - code coverage report
Current view: top level - sw/source/core/text - frminf.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 156 0.0 %
Date: 2014-04-14 Functions: 0 12 0.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 <pam.hxx>
      21             : #include <frminf.hxx>
      22             : #include <itrtxt.hxx>
      23             : 
      24             : /*************************************************************************
      25             :  *                   SwTxtMargin::GetTxtStart()
      26             :  *************************************************************************/
      27             : 
      28           0 : sal_Int32 SwTxtMargin::GetTxtStart() const
      29             : {
      30           0 :     const OUString &rTxt = GetInfo().GetTxt();
      31           0 :     const sal_Int32 nEnd = nStart + pCurr->GetLen();
      32             : 
      33           0 :     for( sal_Int32 i = nStart; i < nEnd; ++i )
      34             :     {
      35           0 :         const sal_Unicode aChar = rTxt[i];
      36           0 :         if( CH_TAB != aChar && ' ' != aChar )
      37           0 :             return i;
      38             :     }
      39           0 :     return nEnd;
      40             : }
      41             : 
      42             : /*************************************************************************
      43             :  *                   SwTxtMargin::GetTxtEnd()
      44             :  *************************************************************************/
      45             : 
      46           0 : sal_Int32 SwTxtMargin::GetTxtEnd() const
      47             : {
      48           0 :     const OUString &rTxt = GetInfo().GetTxt();
      49           0 :     const sal_Int32 nEnd = nStart + pCurr->GetLen();
      50           0 :     for( sal_Int32 i = nEnd - 1; i >= nStart; --i )
      51             :     {
      52           0 :         const sal_Unicode aChar = rTxt[i];
      53           0 :         if( CH_TAB != aChar && CH_BREAK != aChar && ' ' != aChar )
      54           0 :             return i + 1;
      55             :     }
      56           0 :     return nStart;
      57             : }
      58             : 
      59             : /*************************************************************************
      60             :  *                   SwTxtFrmInfo::IsOneLine()
      61             :  *************************************************************************/
      62             : 
      63             : // Does the paragraph fit into one line?
      64           0 : bool SwTxtFrmInfo::IsOneLine() const
      65             : {
      66           0 :     const SwLineLayout *pLay = pFrm->GetPara();
      67           0 :     if( !pLay )
      68           0 :         return false;
      69             : 
      70             :     // For follows false of course
      71           0 :     if( pFrm->GetFollow() )
      72           0 :         return false;
      73             : 
      74           0 :     pLay = pLay->GetNext();
      75           0 :     while( pLay )
      76             :     {
      77           0 :         if( pLay->GetLen() )
      78           0 :             return false;
      79           0 :         pLay = pLay->GetNext();
      80             :     }
      81           0 :     return true;
      82             : }
      83             : 
      84             : /*************************************************************************
      85             :  *                   SwTxtFrmInfo::IsFilled()
      86             :  *************************************************************************/
      87             : 
      88             : // Is the line filled for X percent?
      89           0 : bool SwTxtFrmInfo::IsFilled( const sal_uInt8 nPercent ) const
      90             : {
      91           0 :     const SwLineLayout *pLay = pFrm->GetPara();
      92           0 :     if( !pLay )
      93           0 :         return false;
      94             : 
      95           0 :     long nWidth = pFrm->Prt().Width();
      96           0 :     nWidth *= nPercent;
      97           0 :     nWidth /= 100;
      98           0 :     return KSHORT(nWidth) <= pLay->Width();
      99             : }
     100             : 
     101             : /*************************************************************************
     102             :  *                   SwTxtFrmInfo::GetLineStart()
     103             :  *************************************************************************/
     104             : 
     105             : // Where does the text start (without whitespace)? (document global)
     106           0 : SwTwips SwTxtFrmInfo::GetLineStart( const SwTxtCursor &rLine ) const
     107             : {
     108           0 :     const sal_Int32 nTxtStart = rLine.GetTxtStart();
     109           0 :     if( rLine.GetStart() == nTxtStart )
     110           0 :         return rLine.GetLineStart();
     111             : 
     112           0 :     SwRect aRect;
     113           0 :     if( ((SwTxtCursor&)rLine).GetCharRect( &aRect, nTxtStart ) )
     114           0 :         return aRect.Left();
     115             : 
     116           0 :     return rLine.GetLineStart();
     117             : }
     118             : 
     119             : /*************************************************************************
     120             :  *                   SwTxtFrmInfo::GetLineStart()
     121             :  *************************************************************************/
     122             : 
     123             : // Where does the text start (without whitespace)? (relative in the Frame)
     124           0 : SwTwips SwTxtFrmInfo::GetLineStart() const
     125             : {
     126           0 :     SwTxtSizeInfo aInf( (SwTxtFrm*)pFrm );
     127           0 :     SwTxtCursor aLine( (SwTxtFrm*)pFrm, &aInf );
     128           0 :     return GetLineStart( aLine ) - pFrm->Frm().Left() - pFrm->Prt().Left();
     129             : }
     130             : 
     131             : // Calculates the character's position and returns the middle position
     132           0 : SwTwips SwTxtFrmInfo::GetCharPos( sal_Int32 nChar, bool bCenter ) const
     133             : {
     134           0 :     SWRECTFN( pFrm )
     135           0 :     SwFrmSwapper aSwapper( pFrm, true );
     136             : 
     137           0 :     SwTxtSizeInfo aInf( (SwTxtFrm*)pFrm );
     138           0 :     SwTxtCursor aLine( (SwTxtFrm*)pFrm, &aInf );
     139             : 
     140             :     SwTwips nStt, nNext;
     141           0 :     SwRect aRect;
     142           0 :     if( ((SwTxtCursor&)aLine).GetCharRect( &aRect, nChar ) )
     143             :     {
     144           0 :         if ( bVert )
     145           0 :             pFrm->SwitchHorizontalToVertical( aRect );
     146             : 
     147           0 :         nStt = (aRect.*fnRect->fnGetLeft)();
     148             :     }
     149             :     else
     150           0 :         nStt = aLine.GetLineStart();
     151             : 
     152           0 :     if( !bCenter )
     153           0 :         return nStt - (pFrm->Frm().*fnRect->fnGetLeft)();
     154             : 
     155           0 :     if( ((SwTxtCursor&)aLine).GetCharRect( &aRect, nChar+1 ) )
     156             :     {
     157           0 :         if ( bVert )
     158           0 :             pFrm->SwitchHorizontalToVertical( aRect );
     159             : 
     160           0 :         nNext = (aRect.*fnRect->fnGetLeft)();
     161             :     }
     162             :     else
     163           0 :         nNext = aLine.GetLineStart();
     164             : 
     165           0 :     return (( nNext + nStt ) / 2 ) - (pFrm->Frm().*fnRect->fnGetLeft)();
     166             : }
     167             : 
     168             : /*************************************************************************
     169             :  *                   SwTxtFrmInfo::GetSpaces()
     170             :  *************************************************************************/
     171             : 
     172           0 : SwPaM *AddPam( SwPaM *pPam, const SwTxtFrm* pTxtFrm,
     173             :                 const sal_Int32 nPos, const sal_Int32 nLen )
     174             : {
     175           0 :     if( nLen )
     176             :     {
     177             :         // It could be the first
     178           0 :         if( pPam->HasMark() )
     179             :         {
     180             :             // If the new position is right after the current one, then
     181             :             // simply extend the Pam
     182           0 :             if( nPos == pPam->GetPoint()->nContent.GetIndex() )
     183             :             {
     184           0 :                 pPam->GetPoint()->nContent += nLen;
     185           0 :                 return pPam;
     186             :             }
     187           0 :             pPam = new SwPaM( *pPam );
     188             :         }
     189             : 
     190           0 :         SwIndex &rContent = pPam->GetPoint()->nContent;
     191           0 :         rContent.Assign( (SwTxtNode*)pTxtFrm->GetTxtNode(), nPos );
     192           0 :         pPam->SetMark();
     193           0 :         rContent += nLen;
     194             :     }
     195           0 :     return pPam;
     196             : }
     197             : 
     198             : // Accumulates the whitespace at line start and end in the Pam
     199           0 : void SwTxtFrmInfo::GetSpaces( SwPaM &rPam, bool bWithLineBreak ) const
     200             : {
     201           0 :     SwTxtSizeInfo aInf( (SwTxtFrm*)pFrm );
     202           0 :     SwTxtMargin aLine( (SwTxtFrm*)pFrm, &aInf );
     203           0 :     SwPaM *pPam = &rPam;
     204           0 :     bool bFirstLine = true;
     205           0 :     do {
     206             : 
     207           0 :         if( aLine.GetCurr()->GetLen() )
     208             :         {
     209           0 :             sal_Int32 nPos = aLine.GetTxtStart();
     210             :             // Do NOT include the blanks/tabs from the first line
     211             :             // in the selection
     212           0 :             if( !bFirstLine && nPos > aLine.GetStart() )
     213             :                 pPam = AddPam( pPam, pFrm, aLine.GetStart(),
     214           0 :                                 nPos - aLine.GetStart() );
     215             : 
     216             :             // Do NOT include the blanks/tabs from the last line
     217             :             // in the selection
     218           0 :             if( aLine.GetNext() )
     219             :             {
     220           0 :                 nPos = aLine.GetTxtEnd();
     221             : 
     222           0 :                 if( nPos < aLine.GetEnd() )
     223             :                 {
     224           0 :                     MSHORT nOff = !bWithLineBreak && CH_BREAK ==
     225           0 :                                 aLine.GetInfo().GetChar( aLine.GetEnd() - 1 )
     226           0 :                                 ? 1 : 0;
     227           0 :                     pPam = AddPam( pPam, pFrm, nPos, aLine.GetEnd() - nPos - nOff );
     228             :                 }
     229             :             }
     230             :         }
     231           0 :         bFirstLine = false;
     232             :     }
     233           0 :     while( aLine.Next() );
     234           0 : }
     235             : 
     236             : /*************************************************************************
     237             :  *                   SwTxtFrmInfo::IsBullet()
     238             :  *************************************************************************/
     239             : 
     240             : // Is there a bullet/symbol etc. at the text position?
     241             : // Fonts: CharSet, SYMBOL und DONTKNOW
     242           0 : bool SwTxtFrmInfo::IsBullet( sal_Int32 nTxtStart ) const
     243             : {
     244           0 :     SwTxtSizeInfo aInf( (SwTxtFrm*)pFrm );
     245           0 :     SwTxtMargin aLine( (SwTxtFrm*)pFrm, &aInf );
     246           0 :     aInf.SetIdx( nTxtStart );
     247           0 :     return aLine.IsSymbol( nTxtStart );
     248             : }
     249             : 
     250             : /*************************************************************************
     251             :  *                   SwTxtFrmInfo::GetFirstIndent()
     252             :  *************************************************************************/
     253             : 
     254             : // Get first line indent
     255             : // The precondition for a positive or negative first line indent:
     256             : // All lines (except for the first one) have the same left margin.
     257             : // We do not want to be so picky and work with a tolerance of TOLERANCE twips.
     258             : 
     259           0 : SwTwips SwTxtFrmInfo::GetFirstIndent() const
     260             : {
     261           0 :     SwTxtSizeInfo aInf( (SwTxtFrm*)pFrm );
     262           0 :     SwTxtCursor aLine( (SwTxtFrm*)pFrm, &aInf );
     263           0 :     const SwTwips nFirst = GetLineStart( aLine );
     264           0 :     const SwTwips TOLERANCE = 20;
     265             : 
     266           0 :     if( !aLine.Next() )
     267           0 :         return 0;
     268             : 
     269           0 :     SwTwips nLeft = GetLineStart( aLine );
     270           0 :     while( aLine.Next() )
     271             :     {
     272           0 :         if( aLine.GetCurr()->GetLen() )
     273             :         {
     274           0 :             const SwTwips nCurrLeft = GetLineStart( aLine );
     275           0 :             if( nLeft + TOLERANCE < nCurrLeft ||
     276           0 :                 nLeft - TOLERANCE > nCurrLeft )
     277           0 :                 return 0;
     278             :         }
     279             :     }
     280             : 
     281             :     // At first we only return +1, -1 and 0
     282           0 :     if( nLeft == nFirst )
     283           0 :         return 0;
     284             : 
     285           0 :     if( nLeft > nFirst )
     286           0 :         return -1;
     287             : 
     288           0 :     return 1;
     289             : }
     290             : 
     291             : /*************************************************************************
     292             :  *                   SwTxtFrmInfo::GetBigIndent()
     293             :  *************************************************************************/
     294             : 
     295           0 : sal_Int32 SwTxtFrmInfo::GetBigIndent( sal_Int32& rFndPos,
     296             :                                     const SwTxtFrm *pNextFrm ) const
     297             : {
     298           0 :     SwTxtSizeInfo aInf( (SwTxtFrm*)pFrm );
     299           0 :     SwTxtCursor aLine( (SwTxtFrm*)pFrm, &aInf );
     300           0 :     SwTwips nNextIndent = 0;
     301             : 
     302           0 :     if( pNextFrm )
     303             :     {
     304             :         // I'm a single line
     305           0 :         SwTxtSizeInfo aNxtInf( (SwTxtFrm*)pNextFrm );
     306           0 :         SwTxtCursor aNxtLine( (SwTxtFrm*)pNextFrm, &aNxtInf );
     307           0 :         nNextIndent = GetLineStart( aNxtLine );
     308             :     }
     309             :     else
     310             :     {
     311             :         // I'm multi-line
     312           0 :         if( aLine.Next() )
     313             :         {
     314           0 :             nNextIndent = GetLineStart( aLine );
     315           0 :             aLine.Prev();
     316             :         }
     317             :     }
     318             : 
     319           0 :     if( nNextIndent <= GetLineStart( aLine ) )
     320           0 :         return 0;
     321             : 
     322           0 :     const Point aPoint( nNextIndent, aLine.Y() );
     323           0 :     rFndPos = aLine.GetCrsrOfst( 0, aPoint, false );
     324           0 :     if( 1 >= rFndPos )
     325           0 :         return 0;
     326             : 
     327             :     // Is on front of a non-space
     328           0 :     const OUString& rTxt = aInf.GetTxt();
     329           0 :     sal_Unicode aChar = rTxt[rFndPos];
     330           0 :     if( CH_TAB == aChar || CH_BREAK == aChar || ' ' == aChar ||
     331           0 :         (( CH_TXTATR_BREAKWORD == aChar || CH_TXTATR_INWORD == aChar ) &&
     332           0 :             aInf.HasHint( rFndPos ) ) )
     333           0 :         return 0;
     334             : 
     335             :     // and after a space
     336           0 :     aChar = rTxt[rFndPos - 1];
     337           0 :     if( CH_TAB != aChar && CH_BREAK != aChar &&
     338           0 :         ( ( CH_TXTATR_BREAKWORD != aChar && CH_TXTATR_INWORD != aChar ) ||
     339           0 :             !aInf.HasHint( rFndPos - 1 ) ) &&
     340             :         // More than two Blanks!
     341           0 :         ( ' ' != aChar || ' ' != rTxt[rFndPos - 2] ) )
     342           0 :         return 0;
     343             : 
     344           0 :     SwRect aRect;
     345           0 :     return aLine.GetCharRect( &aRect, rFndPos )
     346           0 :             ? static_cast<sal_Int32>(aRect.Left() - pFrm->Frm().Left() - pFrm->Prt().Left())
     347           0 :             : 0;
     348             : }
     349             : 
     350             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10