LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/text - porexp.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 42 118 35.6 %
Date: 2013-07-09 Functions: 11 20 55.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>  // SwViewOptions
      21             : #include <SwPortionHandler.hxx>
      22             : #include <inftxt.hxx>
      23             : #include <porexp.hxx>
      24             : 
      25             : /*************************************************************************
      26             :  *                      class SwExpandPortion
      27             :  *************************************************************************/
      28             : 
      29           0 : xub_StrLen SwExpandPortion::GetCrsrOfst( const MSHORT nOfst ) const
      30           0 : { return SwLinePortion::GetCrsrOfst( nOfst ); }
      31             : 
      32             : /*************************************************************************
      33             :  *              virtual SwExpandPortion::GetExpTxt()
      34             :  *************************************************************************/
      35             : 
      36           0 : sal_Bool SwExpandPortion::GetExpTxt( const SwTxtSizeInfo&, OUString &rTxt ) const
      37             : {
      38           0 :     rTxt = OUString();
      39             :     // Nicht etwa: return 0 != rTxt.Len();
      40             :     // Weil: leere Felder ersetzen CH_TXTATR gegen einen Leerstring
      41           0 :     return sal_True;
      42             : }
      43             : 
      44             : /*************************************************************************
      45             :  *              virtual SwExpandPortion::HandlePortion()
      46             :  *************************************************************************/
      47             : 
      48           0 : void SwExpandPortion::HandlePortion( SwPortionHandler& rPH ) const
      49             : {
      50           0 :     String aString;
      51           0 :     rPH.Special( GetLen(), aString, GetWhichPor() );
      52           0 : }
      53             : 
      54             : /*************************************************************************
      55             :  *              virtual SwExpandPortion::GetTxtSize()
      56             :  *************************************************************************/
      57             : 
      58           0 : SwPosSize SwExpandPortion::GetTxtSize( const SwTxtSizeInfo &rInf ) const
      59             : {
      60           0 :     SwTxtSlot aDiffTxt( &rInf, this, false, false );
      61           0 :     return rInf.GetTxtSize();
      62             : }
      63             : 
      64             : /*************************************************************************
      65             :  *                 virtual SwExpandPortion::Format()
      66             :  *************************************************************************/
      67             : 
      68             : // 5010: Exp und Tabs
      69             : 
      70          23 : sal_Bool SwExpandPortion::Format( SwTxtFormatInfo &rInf )
      71             : {
      72          23 :     SwTxtSlot aDiffTxt( &rInf, this, true, false );
      73          23 :     const xub_StrLen nFullLen = rInf.GetLen();
      74             : 
      75             :     // So komisch es aussieht, die Abfrage auf GetLen() muss wegen der
      76             :     // ExpandPortions _hinter_ aDiffTxt (vgl. SoftHyphs)
      77             :     // sal_False returnen wegen SetFull ...
      78          23 :     if( !nFullLen )
      79             :     {
      80             :         // nicht Init(), weil wir Hoehe und Ascent brauchen
      81           0 :         Width(0);
      82           0 :         return sal_False;
      83             :     }
      84          23 :     return SwTxtPortion::Format( rInf );
      85             : }
      86             : 
      87             : /*************************************************************************
      88             :  *              virtual SwExpandPortion::Paint()
      89             :  *************************************************************************/
      90             : 
      91         872 : void SwExpandPortion::Paint( const SwTxtPaintInfo &rInf ) const
      92             : {
      93         872 :     SwTxtSlot aDiffTxt( &rInf, this, true, true );
      94             : 
      95         872 :     rInf.DrawBackBrush( *this );
      96             : 
      97             :     // do we have to repaint a post it portion?
      98         872 :     if( rInf.OnWin() && pPortion && !pPortion->Width() )
      99          81 :         pPortion->PrePaint( rInf, this );
     100             : 
     101             :     // The contents of field portions is not considered during the
     102             :     // calculation of the directions. Therefore we let vcl handle
     103             :     // the calculation by removing the BIDI_STRONG_FLAG temporarily.
     104        1744 :     SwLayoutModeModifier aLayoutModeModifier( *rInf.GetOut() );
     105         872 :     aLayoutModeModifier.SetAuto();
     106             : 
     107             :     // ST2
     108         872 :     if ( rInf.GetSmartTags() || rInf.GetGrammarCheckList() )
     109           0 :         rInf.DrawMarkedText( *this, rInf.GetLen(), sal_False, sal_False,
     110           0 :             0 != rInf.GetSmartTags(), 0 != rInf.GetGrammarCheckList() );
     111             :     else
     112        1744 :         rInf.DrawText( *this, rInf.GetLen(), sal_False );
     113         872 : }
     114             : 
     115             : /*************************************************************************
     116             :  *                      class SwBlankPortion
     117             :  *************************************************************************/
     118             : 
     119          23 : SwLinePortion *SwBlankPortion::Compress() { return this; }
     120             : 
     121             : /*************************************************************************
     122             :  *                 SwBlankPortion::MayUnderFlow()
     123             :  *************************************************************************/
     124             : 
     125             : // 5497: Es gibt schon Gemeinheiten auf der Welt...
     126             : // Wenn eine Zeile voll mit HardBlanks ist und diese ueberlaeuft,
     127             : // dann duerfen keine Underflows generiert werden!
     128             : // Komplikationen bei Flys...
     129             : 
     130           0 : MSHORT SwBlankPortion::MayUnderFlow( const SwTxtFormatInfo &rInf,
     131             :     xub_StrLen nIdx, sal_Bool bUnderFlow ) const
     132             : {
     133           0 :     if( rInf.StopUnderFlow() )
     134           0 :         return 0;
     135           0 :     const SwLinePortion *pPos = rInf.GetRoot();
     136           0 :     if( pPos->GetPortion() )
     137           0 :         pPos = pPos->GetPortion();
     138           0 :     while( pPos && pPos->IsBlankPortion() )
     139           0 :         pPos = pPos->GetPortion();
     140           0 :     if( !pPos || !rInf.GetIdx() || ( !pPos->GetLen() && pPos == rInf.GetRoot() ) )
     141           0 :         return 0; // Nur noch BlankPortions unterwegs
     142             :     // Wenn vor uns ein Blank ist, brauchen wir kein Underflow ausloesen,
     143             :     // wenn hinter uns ein Blank ist, brauchen wir kein Underflow weiterreichen
     144           0 :     if( bUnderFlow && CH_BLANK == rInf.GetTxt()[ nIdx + 1] )
     145           0 :         return 0;
     146           0 :     if( nIdx && !((SwTxtFormatInfo&)rInf).GetFly() )
     147             :     {
     148           0 :         while( pPos && !pPos->IsFlyPortion() )
     149           0 :             pPos = pPos->GetPortion();
     150           0 :         if( !pPos )
     151             :         {
     152             :         //Hier wird ueberprueft, ob es in dieser Zeile noch sinnvolle Umbrueche
     153             :         //gibt, Blanks oder Felder etc., wenn nicht, kein Underflow.
     154             :         //Wenn Flys im Spiel sind, lassen wir das Underflow trotzdem zu.
     155           0 :             xub_StrLen nBlank = nIdx;
     156           0 :             while( --nBlank > rInf.GetLineStart() )
     157             :             {
     158           0 :                 const sal_Unicode cCh = rInf.GetChar( nBlank );
     159           0 :                 if( CH_BLANK == cCh ||
     160           0 :                     (( CH_TXTATR_BREAKWORD == cCh || CH_TXTATR_INWORD == cCh )
     161           0 :                         && rInf.HasHint( nBlank ) ) )
     162           0 :                     break;
     163             :             }
     164           0 :             if( nBlank <= rInf.GetLineStart() )
     165           0 :                 return 0;
     166             :         }
     167             :     }
     168             :     sal_Unicode cCh;
     169           0 :     if( nIdx < 2 || CH_BLANK == (cCh = rInf.GetChar( nIdx - 1 )) )
     170           0 :         return 1;
     171           0 :     if( CH_BREAK == cCh )
     172           0 :         return 0;
     173           0 :     return 2;
     174             : }
     175             : 
     176             : /*************************************************************************
     177             :  *                 virtual SwBlankPortion::FormatEOL()
     178             :  *************************************************************************/
     179             : // Format end of Line
     180             : 
     181           0 : void SwBlankPortion::FormatEOL( SwTxtFormatInfo &rInf )
     182             : {
     183           0 :     MSHORT nMay = MayUnderFlow( rInf, rInf.GetIdx() - nLineLength, sal_True );
     184           0 :     if( nMay )
     185             :     {
     186           0 :         if( nMay > 1 )
     187             :         {
     188           0 :             if( rInf.GetLast() == this )
     189           0 :                rInf.SetLast( FindPrevPortion( rInf.GetRoot() ) );
     190           0 :             rInf.X( rInf.X() - PrtWidth() );
     191           0 :             rInf.SetIdx( rInf.GetIdx() - GetLen() );
     192             :         }
     193           0 :         Truncate();
     194           0 :         rInf.SetUnderFlow( this );
     195           0 :         if( rInf.GetLast()->IsKernPortion() )
     196           0 :             rInf.SetUnderFlow( rInf.GetLast() );
     197             :     }
     198           0 : }
     199             : 
     200             : /*************************************************************************
     201             :  *                 virtual SwBlankPortion::Format()
     202             :  *************************************************************************/
     203             : 
     204             : // 7771: UnderFlows weiterreichen und selbst ausloesen!
     205          23 : sal_Bool SwBlankPortion::Format( SwTxtFormatInfo &rInf )
     206             : {
     207          23 :     const sal_Bool bFull = rInf.IsUnderFlow() || SwExpandPortion::Format( rInf );
     208          23 :     if( bFull && MayUnderFlow( rInf, rInf.GetIdx(), rInf.IsUnderFlow() ) )
     209             :     {
     210           0 :         Truncate();
     211           0 :         rInf.SetUnderFlow( this );
     212           0 :         if( rInf.GetLast()->IsKernPortion() )
     213           0 :             rInf.SetUnderFlow( rInf.GetLast() );
     214             :     }
     215          23 :     return bFull;
     216             : }
     217             : 
     218             : /*************************************************************************
     219             :  *                 virtual SwBlankPortion::Paint()
     220             :  *************************************************************************/
     221             : 
     222          25 : void SwBlankPortion::Paint( const SwTxtPaintInfo &rInf ) const
     223             : {
     224          25 :     if( !bMulti ) // No gray background for multiportion brackets
     225           7 :         rInf.DrawViewOpt( *this, POR_BLANK );
     226          25 :     SwExpandPortion::Paint( rInf );
     227          25 : }
     228             : 
     229             : /*************************************************************************
     230             :  *              virtual SwBlankPortion::GetExpTxt()
     231             :  *************************************************************************/
     232             : 
     233          58 : sal_Bool SwBlankPortion::GetExpTxt( const SwTxtSizeInfo&, OUString &rTxt ) const
     234             : {
     235          58 :     rTxt = OUString(cChar);
     236          58 :     return sal_True;
     237             : }
     238             : 
     239             : /*************************************************************************
     240             :  *              virtual SwBlankPortion::HandlePortion()
     241             :  *************************************************************************/
     242             : 
     243           0 : void SwBlankPortion::HandlePortion( SwPortionHandler& rPH ) const
     244             : {
     245           0 :     OUString aString( cChar );
     246           0 :     rPH.Special( GetLen(), aString, GetWhichPor() );
     247           0 : }
     248             : 
     249             : /*************************************************************************
     250             :  *                      class SwPostItsPortion
     251             :  *************************************************************************/
     252             : 
     253           9 : SwPostItsPortion::SwPostItsPortion( sal_Bool bScrpt )
     254           9 :     : bScript( bScrpt )
     255             : {
     256           9 :     nLineLength = 1;
     257           9 :     SetWhichPor( POR_POSTITS );
     258           9 : }
     259             : 
     260           2 : void SwPostItsPortion::Paint( const SwTxtPaintInfo &rInf ) const
     261             : {
     262           2 :     if( rInf.OnWin() && Width() )
     263           0 :         rInf.DrawPostIts( *this, IsScript() );
     264           2 : }
     265             : 
     266           0 : KSHORT SwPostItsPortion::GetViewWidth( const SwTxtSizeInfo &rInf ) const
     267             : {
     268             :     // Nicht zu fassen: PostIts sind immer zu sehen.
     269           0 :     return rInf.OnWin() ?
     270           0 :                 (KSHORT)rInf.GetOpt().GetPostItsWidth( rInf.GetOut() ) : 0;
     271             : }
     272             : 
     273             : /*************************************************************************
     274             :  *                 virtual SwPostItsPortion::Format()
     275             :  *************************************************************************/
     276             : 
     277           9 : sal_Bool SwPostItsPortion::Format( SwTxtFormatInfo &rInf )
     278             : {
     279           9 :     sal_Bool bRet = SwLinePortion::Format( rInf );
     280             :     // 32749: PostIts sollen keine Auswirkung auf Zeilenhoehe etc. haben
     281           9 :     SetAscent( 1 );
     282           9 :     Height( 1 );
     283           9 :     return bRet;
     284             : }
     285             : 
     286             : /*************************************************************************
     287             :  *              virtual SwPostItsPortion::GetExpTxt()
     288             :  *************************************************************************/
     289             : 
     290           0 : sal_Bool SwPostItsPortion::GetExpTxt( const SwTxtSizeInfo &rInf, OUString &rTxt ) const
     291             : {
     292           0 :     if( rInf.OnWin() && rInf.GetOpt().IsPostIts() )
     293           0 :         rTxt = OUString(' ');
     294             :     else
     295           0 :         rTxt = OUString();
     296           0 :     return sal_True;
     297          99 : }
     298             : 
     299             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10