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

Generated by: LCOV version 1.10