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

Generated by: LCOV version 1.11