LCOV - code coverage report
Current view: top level - sw/source/core/text - porexp.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 81 122 66.4 %
Date: 2015-06-13 12:38:46 Functions: 14 20 70.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 <viewopt.hxx>
      21             : #include <SwPortionHandler.hxx>
      22             : #include <inftxt.hxx>
      23             : #include <porexp.hxx>
      24             : 
      25           0 : sal_Int32 SwExpandPortion::GetCrsrOfst( const sal_uInt16 nOfst ) const
      26           0 : { return SwLinePortion::GetCrsrOfst( nOfst ); }
      27             : 
      28           0 : bool SwExpandPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
      29             : {
      30           0 :     rText.clear();
      31             :     // Do not do: return 0 != rText.Len();
      32             :     // Reason being: empty fields replace CH_TXTATR with an empty string
      33           0 :     return true;
      34             : }
      35             : 
      36           0 : void SwExpandPortion::HandlePortion( SwPortionHandler& rPH ) const
      37             : {
      38           0 :     rPH.Special( GetLen(), OUString(), GetWhichPor() );
      39           0 : }
      40             : 
      41           0 : SwPosSize SwExpandPortion::GetTextSize( const SwTextSizeInfo &rInf ) const
      42             : {
      43           0 :     SwTextSlot aDiffText( &rInf, this, false, false );
      44           0 :     return rInf.GetTextSize();
      45             : }
      46             : 
      47         750 : bool SwExpandPortion::Format( SwTextFormatInfo &rInf )
      48             : {
      49         750 :     SwTextSlot aDiffText( &rInf, this, true, false );
      50         750 :     const sal_Int32 nFullLen = rInf.GetLen();
      51             : 
      52             :     // As odd as it may seem: the query for GetLen() must return
      53             :     // false due to the ExpandPortions _after_ the aDiffText (see SoftHyphs)
      54             :     // caused by the SetFull ...
      55         750 :     if( !nFullLen )
      56             :     {
      57             :         // Do not Init(), because we need height and ascent
      58           0 :         Width(0);
      59           0 :         return false;
      60             :     }
      61         750 :     return SwTextPortion::Format( rInf );
      62             : }
      63             : 
      64        2225 : void SwExpandPortion::Paint( const SwTextPaintInfo &rInf ) const
      65             : {
      66        2225 :     SwTextSlot aDiffText( &rInf, this, true, true );
      67        4450 :     const SwFont aOldFont = *rInf.GetFont();
      68        2225 :     if( GetJoinBorderWithPrev() )
      69           0 :         const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetLeftBorder(0);
      70        2225 :     if( GetJoinBorderWithNext() )
      71           0 :         const_cast<SwTextPaintInfo&>(rInf).GetFont()->SetRightBorder(0);
      72             : 
      73        2225 :     rInf.DrawBackBrush( *this );
      74        2225 :     rInf.DrawBorder( *this );
      75             : 
      76             :     // Do we have to repaint a post it portion?
      77        2225 :     if( rInf.OnWin() && pPortion && !pPortion->Width() )
      78          85 :         pPortion->PrePaint( rInf, this );
      79             : 
      80             :     // The contents of field portions is not considered during the
      81             :     // calculation of the directions. Therefore we let vcl handle
      82             :     // the calculation by removing the BIDI_STRONG_FLAG temporarily.
      83        4450 :     SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
      84        2225 :     aLayoutModeModifier.SetAuto();
      85             : 
      86             :     // ST2
      87        2225 :     if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
      88             :         rInf.DrawMarkedText( *this, rInf.GetLen(), false, false,
      89           0 :             0 != rInf.GetSmartTags(), 0 != rInf.GetGrammarCheckList() );
      90             :     else
      91        2225 :         rInf.DrawText( *this, rInf.GetLen(), false );
      92             : 
      93        2225 :     if( GetJoinBorderWithPrev() || GetJoinBorderWithNext() )
      94        2225 :         *const_cast<SwTextPaintInfo&>(rInf).GetFont() = aOldFont;
      95        2225 : }
      96             : 
      97         849 : SwLinePortion *SwBlankPortion::Compress() { return this; }
      98             : 
      99             : /**
     100             :  * If a Line is full of HardBlanks and overflows, we must not generate
     101             :  * underflows!
     102             :  * Causes problems with Fly
     103             :  */
     104          30 : sal_uInt16 SwBlankPortion::MayUnderflow( const SwTextFormatInfo &rInf,
     105             :     sal_Int32 nIdx, bool bUnderflow )
     106             : {
     107          30 :     if( rInf.StopUnderflow() )
     108           0 :         return 0;
     109          30 :     const SwLinePortion *pPos = rInf.GetRoot();
     110          30 :     if( pPos->GetPortion() )
     111          30 :         pPos = pPos->GetPortion();
     112          60 :     while( pPos && pPos->IsBlankPortion() )
     113           0 :         pPos = pPos->GetPortion();
     114          30 :     if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
     115           0 :         return 0; // There are just BlankPortions left
     116             : 
     117             :     // If a Blank is preceding us, we do not need to trigger underflow
     118             :     // If a Blank is succeeding us, we do not need to pass on the underflow
     119          30 :     if (bUnderflow && nIdx + 1 < rInf.GetText().getLength() && CH_BLANK == rInf.GetText()[nIdx + 1])
     120           0 :         return 0;
     121          30 :     if( nIdx && !const_cast<SwTextFormatInfo&>(rInf).GetFly() )
     122             :     {
     123         165 :         while( pPos && !pPos->IsFlyPortion() )
     124         105 :             pPos = pPos->GetPortion();
     125          30 :         if( !pPos )
     126             :         {
     127             :         // We check to see if there are useful line breaks, blanks or fields etc. left
     128             :         // In case there still are some, no underflow
     129             :         // If there are Flys, we still allow the underflow
     130          30 :             sal_Int32 nBlank = nIdx;
     131         156 :             while( --nBlank > rInf.GetLineStart() )
     132             :             {
     133         126 :                 const sal_Unicode cCh = rInf.GetChar( nBlank );
     134         156 :                 if( CH_BLANK == cCh ||
     135          96 :                     (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
     136           0 :                         && rInf.HasHint( nBlank ) ) )
     137          30 :                     break;
     138             :             }
     139          30 :             if( nBlank <= rInf.GetLineStart() )
     140           0 :                 return 0;
     141             :         }
     142             :     }
     143             :     sal_Unicode cCh;
     144          30 :     if( nIdx < 2 || CH_BLANK == (cCh = rInf.GetChar( nIdx - 1 )) )
     145           6 :         return 1;
     146          24 :     if( CH_BREAK == cCh )
     147           0 :         return 0;
     148          24 :     return 2;
     149             : }
     150             : 
     151             : /**
     152             :  * Format End of Line
     153             :  */
     154           0 : void SwBlankPortion::FormatEOL( SwTextFormatInfo &rInf )
     155             : {
     156           0 :     sal_uInt16 nMay = MayUnderflow( rInf, rInf.GetIdx() - nLineLength, true );
     157           0 :     if( nMay )
     158             :     {
     159           0 :         if( nMay > 1 )
     160             :         {
     161           0 :             if( rInf.GetLast() == this )
     162           0 :                rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
     163           0 :             rInf.X( rInf.X() - PrtWidth() );
     164           0 :             rInf.SetIdx( rInf.GetIdx() - GetLen() );
     165             :         }
     166           0 :         Truncate();
     167           0 :         rInf.SetUnderflow( this );
     168           0 :         if( rInf.GetLast()->IsKernPortion() )
     169           0 :             rInf.SetUnderflow( rInf.GetLast() );
     170             :     }
     171           0 : }
     172             : 
     173             : /**
     174             :  * Pass on the underflows and trigger them ourselves!
     175             :  */
     176         765 : bool SwBlankPortion::Format( SwTextFormatInfo &rInf )
     177             : {
     178         765 :     const bool bFull = rInf.IsUnderflow() || SwExpandPortion::Format( rInf );
     179         765 :     if( bFull && MayUnderflow( rInf, rInf.GetIdx(), rInf.IsUnderflow() ) )
     180             :     {
     181          15 :         Truncate();
     182          15 :         rInf.SetUnderflow( this );
     183          15 :         if( rInf.GetLast()->IsKernPortion() )
     184           0 :             rInf.SetUnderflow( rInf.GetLast() );
     185             :     }
     186         765 :     return bFull;
     187             : }
     188             : 
     189         202 : void SwBlankPortion::Paint( const SwTextPaintInfo &rInf ) const
     190             : {
     191         202 :     if( !bMulti ) // No gray background for multiportion brackets
     192         195 :         rInf.DrawViewOpt( *this, POR_BLANK );
     193         202 :     SwExpandPortion::Paint( rInf );
     194         202 : }
     195             : 
     196        1047 : bool SwBlankPortion::GetExpText( const SwTextSizeInfo&, OUString &rText ) const
     197             : {
     198        1047 :     rText = OUString(cChar);
     199        1047 :     return true;
     200             : }
     201             : 
     202           0 : void SwBlankPortion::HandlePortion( SwPortionHandler& rPH ) const
     203             : {
     204           0 :     rPH.Special( GetLen(), OUString( cChar ), GetWhichPor() );
     205           0 : }
     206             : 
     207         121 : SwPostItsPortion::SwPostItsPortion( bool bScrpt )
     208         121 :     : bScript( bScrpt )
     209             : {
     210         121 :     nLineLength = 1;
     211         121 :     SetWhichPor( POR_POSTITS );
     212         121 : }
     213             : 
     214          38 : void SwPostItsPortion::Paint( const SwTextPaintInfo &rInf ) const
     215             : {
     216          38 :     if( rInf.OnWin() && Width() )
     217          24 :         rInf.DrawPostIts( *this, IsScript() );
     218          38 : }
     219             : 
     220          24 : sal_uInt16 SwPostItsPortion::GetViewWidth( const SwTextSizeInfo &rInf ) const
     221             : {
     222             :     // Unbelievable: PostIts are always visible
     223          24 :     return rInf.OnWin() ? SwViewOption::GetPostItsWidth( rInf.GetOut() ) : 0;
     224             : }
     225             : 
     226         121 : bool SwPostItsPortion::Format( SwTextFormatInfo &rInf )
     227             : {
     228         121 :     const bool bRet = SwLinePortion::Format( rInf );
     229             :     // PostIts should not have an effect on line height etc.
     230         121 :     SetAscent( 1 );
     231         121 :     Height( 1 );
     232         121 :     return bRet;
     233             : }
     234             : 
     235          28 : bool SwPostItsPortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
     236             : {
     237          28 :     if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
     238           0 :         rText = " ";
     239             :     else
     240          28 :         rText.clear();
     241          28 :     return true;
     242         177 : }
     243             : 
     244             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11