LCOV - code coverage report
Current view: top level - sw/source/core/text - txttab.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 221 251 88.0 %
Date: 2015-06-13 12:38:46 Functions: 11 13 84.6 %
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 "hintids.hxx"
      21             : #include <comphelper/string.hxx>
      22             : #include <editeng/lrspitem.hxx>
      23             : #include <editeng/tstpitem.hxx>
      24             : #include <rtl/ustrbuf.hxx>
      25             : #include <IDocumentSettingAccess.hxx>
      26             : #include <frmatr.hxx>
      27             : #include <SwPortionHandler.hxx>
      28             : 
      29             : #include "viewopt.hxx"
      30             : #include "portab.hxx"
      31             : #include "inftxt.hxx"
      32             : #include "itrform2.hxx"
      33             : #include "txtfrm.hxx"
      34             : #include <numrule.hxx>
      35             : #include <porfld.hxx>
      36             : #include <boost/scoped_ptr.hpp>
      37             : 
      38             : /**
      39             :  * #i24363# tab stops relative to indent
      40             :  *
      41             :  * Return the first tab stop that is > nSearchPos.
      42             :  * If the tab stop is outside the print area, we
      43             :  * return 0 if it is not the first tab stop.
      44             :  */
      45       35588 : const SvxTabStop *SwLineInfo::GetTabStop( const SwTwips nSearchPos, const SwTwips nRight ) const
      46             : {
      47       58151 :     for( sal_uInt16 i = 0; i < pRuler->Count(); ++i )
      48             :     {
      49       43971 :         const SvxTabStop &rTabStop = pRuler->operator[](i);
      50       43971 :         if( rTabStop.GetTabPos() > SwTwips(nRight) )
      51         578 :             return i ? 0 : &rTabStop;
      52             : 
      53       43393 :         if( rTabStop.GetTabPos() > nSearchPos )
      54       20830 :             return &rTabStop;
      55             :     }
      56       14180 :     return 0;
      57             : }
      58             : 
      59           0 : sal_uInt16 SwLineInfo::NumberOfTabStops() const
      60             : {
      61           0 :     return pRuler->Count();
      62             : }
      63             : 
      64       35588 : SwTabPortion *SwTextFormatter::NewTabPortion( SwTextFormatInfo &rInf, bool bAuto ) const
      65             : {
      66       35588 :     sal_Unicode cFill = 0;
      67       35588 :     sal_Unicode cDec = 0;
      68             :     SvxTabAdjust eAdj;
      69             : 
      70             :     sal_uInt16 nNewTabPos;
      71       35588 :     bool bAutoTabStop = true;
      72             :     {
      73       35588 :         const bool bRTL = pFrm->IsRightToLeft();
      74             :         // #i24363# tab stops relative to indent
      75             :         // nTabLeft: The absolute value, the tab stops are relative to: Tabs origin.
      76             : 
      77             :         // #i91133#
      78             :         const bool bTabsRelativeToIndent =
      79       35588 :             pFrm->GetTextNode()->getIDocumentSettingAccess()->get(DocumentSettingId::TABS_RELATIVE_TO_INDENT);
      80             :         const SwTwips nTabLeft = bRTL
      81          27 :                                  ? pFrm->Frm().Right() -
      82           0 :                                    ( bTabsRelativeToIndent ? GetTabLeft() : 0 )
      83       39692 :                                  : pFrm->Frm().Left() +
      84       75307 :                                    ( bTabsRelativeToIndent ? GetTabLeft() : 0 );
      85             : 
      86             :         // The absolute position, where we started the line formatting
      87       35588 :         SwTwips nLinePos = GetLeftMargin();
      88       35588 :         if ( bRTL )
      89             :         {
      90          27 :             Point aPoint( nLinePos, 0 );
      91          27 :             pFrm->SwitchLTRtoRTL( aPoint );
      92          27 :             nLinePos = aPoint.X();
      93             :         }
      94             : 
      95             :         // The current position, relative to the line start
      96       35588 :         SwTwips nTabPos = rInf.GetLastTab() ? rInf.GetLastTab()->GetTabPos() : 0;
      97       35588 :         if( nTabPos < rInf.X() )
      98             :         {
      99       23459 :             nTabPos = rInf.X();
     100             :         }
     101             : 
     102             :         // The current position in absolute coordinates
     103             :         const SwTwips nCurrentAbsPos = bRTL ?
     104             :                                        nLinePos - nTabPos :
     105       35588 :                                        nLinePos + nTabPos;
     106             : 
     107             :         SwTwips nMyRight;
     108       35588 :         if ( pFrm->IsVertLR() )
     109           0 :            nMyRight = Left();
     110             :         else
     111       35588 :            nMyRight = Right();
     112             : 
     113       35588 :         if ( pFrm->IsVertical() )
     114             :         {
     115          27 :             Point aRightTop( nMyRight, pFrm->Frm().Top() );
     116          27 :             pFrm->SwitchHorizontalToVertical( aRightTop );
     117          27 :             nMyRight = aRightTop.Y();
     118             :         }
     119             : 
     120       35588 :         SwTwips nNextPos = 0;
     121             : 
     122             :         // #i24363# tab stops relative to indent
     123             :         // nSearchPos: The current position relative to the tabs origin
     124             :         const SwTwips nSearchPos = bRTL ?
     125             :                                    nTabLeft - nCurrentAbsPos :
     126       35588 :                                    nCurrentAbsPos - nTabLeft;
     127             : 
     128             :         // First, we examine the tab stops set at the paragraph style or
     129             :         // any hard set tab stops:
     130             :         // Note: If there are no user defined tab stops, there is always a
     131             :         // default tab stop.
     132       35588 :         const SvxTabStop* pTabStop = aLineInf.GetTabStop( nSearchPos, nMyRight );
     133       35588 :         if ( pTabStop )
     134             :         {
     135       21399 :             cFill = ' ' != pTabStop->GetFill() ? pTabStop->GetFill() : 0;
     136       21399 :             cDec = pTabStop->GetDecimal();
     137       21399 :             eAdj = pTabStop->GetAdjustment();
     138       21399 :             nNextPos = pTabStop->GetTabPos();
     139       21399 :             if(!bTabsRelativeToIndent && eAdj == SVX_TAB_ADJUST_DEFAULT && nSearchPos < 0)
     140             :             {
     141             :                 //calculate default tab position of default tabs in negative indent
     142          23 :                 nNextPos = ( nSearchPos / nNextPos ) * nNextPos;
     143             :             }
     144       21399 :             bAutoTabStop = false;
     145             :         }
     146             :         else
     147             :         {
     148       14189 :             sal_uInt16 nDefTabDist = aLineInf.GetDefTabStop();
     149       14189 :             if( USHRT_MAX == nDefTabDist )
     150             :             {
     151             :                 const SvxTabStopItem& rTab =
     152             :                     static_cast<const SvxTabStopItem &>(pFrm->GetAttrSet()->
     153        6709 :                       GetPool()->GetDefaultItem( RES_PARATR_TABSTOP ));
     154        6709 :                 if( rTab.Count() )
     155        6709 :                     nDefTabDist = (sal_uInt16)rTab[0].GetTabPos();
     156             :                 else
     157           0 :                     nDefTabDist = SVX_TAB_DEFDIST;
     158        6709 :                 aLineInf.SetDefTabStop( nDefTabDist );
     159             :             }
     160       14189 :             SwTwips nCount = nSearchPos;
     161             : 
     162             :             // Minimum tab stop width is 1
     163       14189 :             if (nDefTabDist <= 0)
     164           0 :                 nDefTabDist = 1;
     165             : 
     166       14189 :             nCount /= nDefTabDist;
     167       14090 :             nNextPos = ( nCount < 0 || ( !nCount && nSearchPos <= 0 ) )
     168         240 :                        ? ( nCount * nDefTabDist )
     169       14429 :                        : ( ( nCount + 1 ) * nDefTabDist );
     170             : 
     171             :             // --> FME 2004-09-21 #117919 Minimum tab stop width is 1 or 51 twips:
     172       14189 :             const SwTwips nMinimumTabWidth = pFrm->GetTextNode()->getIDocumentSettingAccess()->get(DocumentSettingId::TAB_COMPAT) ? 0 : 50;
     173       28378 :             if( (  bRTL && nTabLeft - nNextPos >= nCurrentAbsPos - nMinimumTabWidth ) ||
     174       28378 :                  ( !bRTL && nNextPos + nTabLeft <= nCurrentAbsPos + nMinimumTabWidth  ) )
     175             :             {
     176         137 :                 nNextPos += nDefTabDist;
     177             :             }
     178       14189 :             cFill = 0;
     179       14189 :             eAdj = SVX_TAB_ADJUST_LEFT;
     180             :         }
     181             : 
     182             :         // #i115705# - correction and refactoring:
     183             :         // overrule determined next tab stop position in order to apply
     184             :         // a tab stop at the left margin under the following conditions:
     185             :         // - the new tab portion is inside the hanging indent
     186             :         // - a tab stop at the left margin is allowed
     187             :         // - the determined next tab stop is a default tab stop position OR
     188             :         //   the determined next tab stop is beyond the left margin
     189             :         {
     190       35588 :             long nLeftMarginTabPos = 0;
     191             :             {
     192       35588 :                 if ( !bTabsRelativeToIndent )
     193             :                 {
     194       31457 :                     if ( bRTL )
     195             :                     {
     196          27 :                         Point aPoint( Left(), 0 );
     197          27 :                         pFrm->SwitchLTRtoRTL( aPoint );
     198          27 :                         nLeftMarginTabPos = pFrm->Frm().Right() - aPoint.X();
     199             :                     }
     200             :                     else
     201             :                     {
     202       31430 :                         nLeftMarginTabPos = Left() - pFrm->Frm().Left();
     203             :                     }
     204             :                 }
     205       35588 :                 if( pCurr->HasForcedLeftMargin() )
     206             :                 {
     207           0 :                     SwLinePortion* pPor = pCurr->GetPortion();
     208           0 :                     while( pPor && !pPor->IsFlyPortion() )
     209             :                     {
     210           0 :                         pPor = pPor->GetPortion();
     211             :                     }
     212           0 :                     if ( pPor )
     213             :                     {
     214           0 :                         nLeftMarginTabPos += pPor->Width();
     215             :                     }
     216             :                 }
     217             :             }
     218             :             const bool bNewTabPortionInsideHangingIndent =
     219          27 :                         bRTL ? nCurrentAbsPos > nTabLeft - nLeftMarginTabPos
     220       35615 :                              : nCurrentAbsPos < nTabLeft + nLeftMarginTabPos;
     221       35588 :             if ( bNewTabPortionInsideHangingIndent )
     222             :             {
     223             :                 // If the paragraph is not inside a list having a list tab stop following
     224             :                 // the list label or no further tab stop found in such a paragraph or
     225             :                 // the next tab stop position does not equal the list tab stop,
     226             :                 // a tab stop at the left margin can be applied. If this condition is
     227             :                 // not hold, it is overruled by compatibility option TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST.
     228             :                 const bool bTabAtLeftMarginAllowed =
     229       11477 :                     ( !aLineInf.IsListTabStopIncluded() ||
     230        3964 :                       !pTabStop ||
     231       11354 :                       nNextPos != aLineInf.GetListTabStopPosition() ) ||
     232             :                     // compatibility option TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST:
     233        1438 :                     pFrm->GetTextNode()->getIDocumentSettingAccess()->
     234        7390 :                         get(DocumentSettingId::TAB_AT_LEFT_INDENT_FOR_PARA_IN_LIST);
     235        5952 :                 if ( bTabAtLeftMarginAllowed )
     236             :                 {
     237        4514 :                     if ( !pTabStop || eAdj == SVX_TAB_ADJUST_DEFAULT ||
     238             :                          ( nNextPos > nLeftMarginTabPos ) )
     239             :                     {
     240        4465 :                         eAdj = SVX_TAB_ADJUST_DEFAULT;
     241        4465 :                         cFill = 0;
     242        4465 :                         nNextPos = nLeftMarginTabPos;
     243             :                     }
     244             :                 }
     245             :             }
     246             :         }
     247             : 
     248       35588 :         nNextPos += bRTL ? nLinePos - nTabLeft : nTabLeft - nLinePos;
     249             :         OSL_ENSURE( nNextPos >= 0, "GetTabStop: Don't go back!" );
     250       35588 :         nNewTabPos = sal_uInt16(nNextPos);
     251             :     }
     252             : 
     253       35588 :     SwTabPortion *pTabPor = 0;
     254       35588 :     if ( bAuto )
     255             :     {
     256       18683 :         if ( SVX_TAB_ADJUST_DECIMAL == eAdj &&
     257             :              // #127428#
     258           0 :              1 == aLineInf.NumberOfTabStops() )
     259           0 :             pTabPor = new SwAutoTabDecimalPortion( nNewTabPos, cDec, cFill );
     260             :     }
     261             :     else
     262             :     {
     263       16905 :         switch( eAdj )
     264             :         {
     265             :         case SVX_TAB_ADJUST_RIGHT :
     266             :             {
     267        1445 :                 pTabPor = new SwTabRightPortion( nNewTabPos, cFill );
     268        1445 :                 break;
     269             :             }
     270             :         case SVX_TAB_ADJUST_CENTER :
     271             :             {
     272        1317 :                 pTabPor = new SwTabCenterPortion( nNewTabPos, cFill );
     273        1317 :                 break;
     274             :             }
     275             :         case SVX_TAB_ADJUST_DECIMAL :
     276             :             {
     277           9 :                 pTabPor = new SwTabDecimalPortion( nNewTabPos, cDec, cFill );
     278           9 :                 break;
     279             :             }
     280             :         default:
     281             :             {
     282             :                 OSL_ENSURE( SVX_TAB_ADJUST_LEFT == eAdj || SVX_TAB_ADJUST_DEFAULT == eAdj,
     283             :                     "+SwTextFormatter::NewTabPortion: unknown adjustment" );
     284       14134 :                 pTabPor = new SwTabLeftPortion( nNewTabPos, cFill, bAutoTabStop );
     285       14134 :                 break;
     286             :             }
     287             :         }
     288             :     }
     289             : 
     290       35588 :     return pTabPor;
     291             : }
     292             : 
     293             : /**
     294             :  * The base class is initialized without setting anything
     295             :  */
     296       16905 : SwTabPortion::SwTabPortion( const sal_uInt16 nTabPosition, const sal_Unicode cFillChar, const bool bAutoTab )
     297       16905 :     : SwFixPortion( 0, 0 ), nTabPos(nTabPosition), cFill(cFillChar), bAutoTabStop( bAutoTab )
     298             : {
     299       16905 :     nLineLength = 1;
     300             :     OSL_ENSURE(!IsFilled() || ' ' != cFill, "SwTabPortion::CTOR: blanks ?!");
     301       16905 :     SetWhichPor( POR_TAB );
     302       16905 : }
     303             : 
     304       16914 : bool SwTabPortion::Format( SwTextFormatInfo &rInf )
     305             : {
     306       16914 :     SwTabPortion *pLastTab = rInf.GetLastTab();
     307       16914 :     if( pLastTab == this )
     308           0 :         return PostFormat( rInf );
     309       16914 :     if( pLastTab )
     310         784 :         pLastTab->PostFormat( rInf );
     311       16914 :     return PreFormat( rInf );
     312             : }
     313             : 
     314        1987 : void SwTabPortion::FormatEOL( SwTextFormatInfo &rInf )
     315             : {
     316        1987 :     if( rInf.GetLastTab() == this && !IsTabLeftPortion() )
     317        1987 :         PostFormat( rInf );
     318        1987 : }
     319             : 
     320       16914 : bool SwTabPortion::PreFormat( SwTextFormatInfo &rInf )
     321             : {
     322             :     OSL_ENSURE( rInf.X() <= GetTabPos(), "SwTabPortion::PreFormat: rush hour" );
     323             : 
     324             :     // Here we settle down ...
     325       16914 :     Fix( static_cast<sal_uInt16>(rInf.X()) );
     326             : 
     327       16914 :     const bool bTabCompat = rInf.GetTextFrm()->GetTextNode()->getIDocumentSettingAccess()->get(DocumentSettingId::TAB_COMPAT);
     328       16914 :     const bool bTabOverflow = rInf.GetTextFrm()->GetTextNode()->getIDocumentSettingAccess()->get(DocumentSettingId::TAB_OVERFLOW);
     329             : 
     330             :     // The minimal width of a tab is one blank at least.
     331             :     // #i37686# In compatibility mode, the minimum width
     332             :     // should be 1, even for non-left tab stops.
     333       16914 :     sal_uInt16 nMinimumTabWidth = 1;
     334       16914 :     if ( !bTabCompat )
     335             :     {
     336             :         // #i89179#
     337             :         // tab portion representing the list tab of a list label gets the
     338             :         // same font as the corresponding number portion
     339          45 :         boost::scoped_ptr< SwFontSave > pSave( 0 );
     340          90 :         if ( GetLen() == 0 &&
     341          45 :              rInf.GetLast() && rInf.GetLast()->InNumberGrp() &&
     342           0 :              static_cast<SwNumberPortion*>(rInf.GetLast())->HasFont() )
     343             :         {
     344             :             const SwFont* pNumberPortionFont =
     345           0 :                     static_cast<SwNumberPortion*>(rInf.GetLast())->GetFont();
     346           0 :             pSave.reset( new SwFontSave( rInf, const_cast<SwFont*>(pNumberPortionFont) ) );
     347             :         }
     348          90 :         OUString aTmp( ' ' );
     349          90 :         SwTextSizeInfo aInf( rInf, &aTmp );
     350          90 :         nMinimumTabWidth = aInf.GetTextSize().Width();
     351             :     }
     352       16914 :     PrtWidth( nMinimumTabWidth );
     353             : 
     354             :     // Break tab stop to next line if:
     355             :     // 1. Minmal width does not fit to line anymore.
     356             :     // 2. An underflow event was called for the tab portion.
     357       33831 :     bool bFull = ( bTabCompat && rInf.IsUnderflow() ) ||
     358       33825 :                      ( rInf.Width() <= rInf.X() + PrtWidth() && rInf.X() <= rInf.Width() ) ;
     359             : 
     360             :     // #95477# Rotated tab stops get the width of one blank
     361       16914 :     const sal_uInt16 nDir = rInf.GetFont()->GetOrientation( rInf.GetTextFrm()->IsVertical() );
     362             : 
     363       16914 :     if( ! bFull && 0 == nDir )
     364             :     {
     365       16902 :         const sal_uInt16 nWhich = GetWhichPor();
     366       16902 :         switch( nWhich )
     367             :         {
     368             :             case POR_TABRIGHT:
     369             :             case POR_TABDECIMAL:
     370             :             case POR_TABCENTER:
     371             :             {
     372        2771 :                 if( POR_TABDECIMAL == nWhich )
     373             :                     rInf.SetTabDecimal(
     374           9 :                         static_cast<SwTabDecimalPortion*>(this)->GetTabDecimal());
     375        2771 :                 rInf.SetLastTab( this );
     376        2771 :                 break;
     377             :             }
     378             :             case POR_TABLEFT:
     379             :             {
     380       14131 :                 PrtWidth( static_cast<sal_uInt16>(GetTabPos() - rInf.X()) );
     381       14131 :                 bFull = rInf.Width() <= rInf.X() + PrtWidth();
     382             : 
     383             :                 // In tabulator compatibility mode, we reset the bFull flag
     384             :                 // if the tabulator is at the end of the paragraph and the
     385             :                 // tab stop position is outside the frame:
     386       14131 :                 bool bAtParaEnd = rInf.GetIdx() + GetLen() == rInf.GetText().getLength();
     387       14168 :                 if ( bFull && bTabCompat &&
     388       14199 :                      ( ( bTabOverflow && ( rInf.IsTabOverflow() || !IsAutoTabStop() ) ) || bAtParaEnd ) &&
     389          31 :                      GetTabPos() >= rInf.GetTextFrm()->Frm().Width() )
     390             :                 {
     391           9 :                     bFull = false;
     392           9 :                     if ( bTabOverflow && !IsAutoTabStop() )
     393           1 :                         rInf.SetTabOverflow( true );
     394             :                 }
     395             : 
     396       14131 :                 break;
     397             :             }
     398             :             default: OSL_ENSURE( false, "SwTabPortion::PreFormat: unknown adjustment" );
     399             :         }
     400             :     }
     401             : 
     402       16914 :     if( bFull )
     403             :     {
     404             :         // We have to look for endless loops, if the width is smaller than one blank
     405          51 :         if( rInf.GetIdx() == rInf.GetLineStart() &&
     406             :             // #119175# TabStop should be forced to current
     407             :             // line if there is a fly reducing the line width:
     408          11 :             !rInf.GetFly() )
     409             :         {
     410          11 :             PrtWidth( static_cast<sal_uInt16>(rInf.Width() - rInf.X()) );
     411          11 :             SetFixWidth( PrtWidth() );
     412             :         }
     413             :         else
     414             :         {
     415          29 :             Height( 0 );
     416          29 :             Width( 0 );
     417          29 :             SetLen( 0 );
     418          29 :             SetAscent( 0 );
     419          29 :             SetPortion( NULL ); //?????
     420             :         }
     421          40 :         return true;
     422             :     }
     423             :     else
     424             :     {
     425             :         // A trick with impact: The new Tabportions now behave like
     426             :         // FlyFrms, located in the line - including adjustment !
     427       16874 :         SetFixWidth( PrtWidth() );
     428       16874 :         return false;
     429             :     }
     430             : }
     431             : 
     432        2771 : bool SwTabPortion::PostFormat( SwTextFormatInfo &rInf )
     433             : {
     434        2771 :     const bool bTabOverMargin = rInf.GetTextFrm()->GetTextNode()->getIDocumentSettingAccess()->get(DocumentSettingId::TAB_OVER_MARGIN);
     435             :     // If the tab position is larger than the right margin, it gets scaled down by default.
     436             :     // However, if compat mode enabled, we allow tabs to go over the margin: the rest of the paragraph is not broken into lines.
     437        2771 :     const sal_uInt16 nRight = bTabOverMargin ? GetTabPos() : std::min(GetTabPos(), rInf.Width());
     438        2771 :     const SwLinePortion *pPor = GetPortion();
     439             : 
     440        2771 :     sal_uInt16 nPorWidth = 0;
     441        7180 :     while( pPor )
     442             :     {
     443        1638 :         nPorWidth = nPorWidth + pPor->Width();
     444        1638 :         pPor = pPor->GetPortion();
     445             :     }
     446             : 
     447        2771 :     const sal_uInt16 nWhich = GetWhichPor();
     448             :     OSL_ENSURE( POR_TABLEFT != nWhich, "SwTabPortion::PostFormat: already formatted" );
     449        2771 :     const bool bTabCompat = rInf.GetTextFrm()->GetTextNode()->getIDocumentSettingAccess()->get(DocumentSettingId::TAB_COMPAT);
     450             : 
     451             :     // #127428# Abandon dec. tab position if line is full
     452        2771 :     if ( bTabCompat && POR_TABDECIMAL == nWhich )
     453             :     {
     454           9 :         sal_uInt16 nPrePorWidth = static_cast<const SwTabDecimalPortion*>(this)->GetWidthOfPortionsUpToDecimalPosition();
     455             : 
     456             :         // no value was set => no decimal character was found
     457           9 :         if ( USHRT_MAX != nPrePorWidth )
     458             :         {
     459           4 :             if ( nPrePorWidth && nPorWidth - nPrePorWidth > rInf.Width() - nRight )
     460             :             {
     461           0 :                 nPrePorWidth += nPorWidth - nPrePorWidth - ( rInf.Width() - nRight );
     462             :             }
     463             : 
     464           4 :             nPorWidth = nPrePorWidth - 1;
     465             :         }
     466             :     }
     467             : 
     468        2771 :     if( POR_TABCENTER == nWhich )
     469             :     {
     470             :         // centered tabs are problematic:
     471             :         // We have to detect how much fits into the line.
     472        1317 :         sal_uInt16 nNewWidth = nPorWidth /2;
     473        1317 :         if( nNewWidth > rInf.Width() - nRight )
     474           0 :             nNewWidth = nPorWidth - (rInf.Width() - nRight);
     475        1317 :         nPorWidth = nNewWidth;
     476             :     }
     477             : 
     478        2771 :     const sal_uInt16 nDiffWidth = nRight - Fix();
     479             : 
     480        2771 :     if( nDiffWidth > nPorWidth )
     481             :     {
     482        2747 :         const sal_uInt16 nOldWidth = GetFixWidth();
     483        2747 :         const sal_uInt16 nAdjDiff = nDiffWidth - nPorWidth;
     484        2747 :         if( nAdjDiff > GetFixWidth() )
     485        2747 :             PrtWidth( nAdjDiff );
     486             :         // Dont be afraid: we have to move rInf further.
     487             :         // The right-tab till now only had the width of one blank.
     488             :         // Now that we stretched, the difference had to be added to rInf.X() !
     489        2747 :         rInf.X( rInf.X() + PrtWidth() - nOldWidth );
     490             :     }
     491        2771 :     SetFixWidth( PrtWidth() );
     492             :     // reset last values
     493        2771 :     rInf.SetLastTab(0);
     494        2771 :     if( POR_TABDECIMAL == nWhich )
     495           9 :         rInf.SetTabDecimal(0);
     496             : 
     497        2771 :     return rInf.Width() <= rInf.X();
     498             : }
     499             : 
     500             : /**
     501             :  * Ex: LineIter::DrawTab()
     502             :  */
     503         549 : void SwTabPortion::Paint( const SwTextPaintInfo &rInf ) const
     504             : {
     505             : #if OSL_DEBUG_LEVEL > 1
     506             :     // We want to view the fixed width
     507             :     if( rInf.OnWin() && OPTDBG( rInf ) &&
     508             :         !rInf.GetOpt().IsPagePreview() && \
     509             :         !rInf.GetOpt().IsReadonly() && \
     510             :         SwViewOption::IsFieldShadings()    )
     511             :     {
     512             :         const sal_uInt16 nTmpWidth = PrtWidth();
     513             :         const_cast<SwTabPortion*>(this)->PrtWidth( GetFixWidth() );
     514             :         rInf.DrawViewOpt( *this, POR_TAB );
     515             :         const_cast<SwTabPortion*>(this)->PrtWidth( nTmpWidth );
     516             :     }
     517             : #endif
     518             : 
     519             :     // #i89179#
     520             :     // tab portion representing the list tab of a list label gets the
     521             :     // same font as the corresponding number portion
     522         549 :     boost::scoped_ptr< SwFontSave > pSave( 0 );
     523         549 :     bool bAfterNumbering = false;
     524         549 :     if ( GetLen() == 0 )
     525             :     {
     526             :         const SwLinePortion* pPrevPortion =
     527         143 :             const_cast<SwTabPortion*>(this)->FindPrevPortion( rInf.GetParaPortion() );
     528         286 :         if ( pPrevPortion &&
     529         286 :              pPrevPortion->InNumberGrp() &&
     530         143 :              static_cast<const SwNumberPortion*>(pPrevPortion)->HasFont() )
     531             :         {
     532             :             const SwFont* pNumberPortionFont =
     533         143 :                     static_cast<const SwNumberPortion*>(pPrevPortion)->GetFont();
     534         143 :             pSave.reset( new SwFontSave( rInf, const_cast<SwFont*>(pNumberPortionFont) ) );
     535         143 :             bAfterNumbering = true;
     536             :         }
     537             :     }
     538         549 :     rInf.DrawBackBrush( *this );
     539         549 :     if( !bAfterNumbering )
     540         406 :         rInf.DrawBorder( *this );
     541             : 
     542             :     // do we have to repaint a post it portion?
     543         549 :     if( rInf.OnWin() && pPortion && !pPortion->Width() )
     544           1 :         pPortion->PrePaint( rInf, this );
     545             : 
     546             :     // display special characters
     547         549 :     if( rInf.OnWin() && rInf.GetOpt().IsTab() )
     548             :     {
     549             :         // filled tabs are shaded in gray
     550           0 :         if( IsFilled() )
     551           0 :             rInf.DrawViewOpt( *this, POR_TAB );
     552             :         else
     553           0 :             rInf.DrawTab( *this );
     554             :     }
     555             : 
     556             :     // Tabs should be underlined at once
     557         549 :     if( rInf.GetFont()->IsPaintBlank() )
     558             :     {
     559             :         // Tabs with filling/filled tabs
     560           0 :         const sal_uInt16 nCharWidth = rInf.GetTextSize(OUString(' ')).Width();
     561             : 
     562             :         // Robust:
     563           0 :         if( nCharWidth )
     564             :         {
     565             :             // Always with kerning, also on printer!
     566           0 :             sal_uInt16 nChar = Width() / nCharWidth;
     567           0 :             OUStringBuffer aBuf;
     568           0 :             comphelper::string::padToLength(aBuf, nChar, ' ');
     569           0 :             rInf.DrawText(aBuf.makeStringAndClear(), *this, 0, nChar, true);
     570             :         }
     571             :     }
     572             : 
     573             :     // Display fill characters
     574         549 :     if( IsFilled() )
     575             :     {
     576             :         // Tabs with filling/filled tabs
     577          78 :         const sal_uInt16 nCharWidth = rInf.GetTextSize(OUString(cFill)).Width();
     578             :         OSL_ENSURE( nCharWidth, "!SwTabPortion::Paint: sophisticated tabchar" );
     579             : 
     580             :         // Robust:
     581          78 :         if( nCharWidth )
     582             :         {
     583             :             // Always with kerning, also on printer!
     584          78 :             sal_uInt16 nChar = Width() / nCharWidth;
     585          78 :             if ( cFill == '_' )
     586           1 :                 ++nChar; // to avoid gaps
     587          78 :             OUStringBuffer aBuf;
     588          78 :             comphelper::string::padToLength(aBuf, nChar, cFill);
     589          78 :             rInf.DrawText(aBuf.makeStringAndClear(), *this, 0, nChar, true);
     590             :         }
     591         549 :     }
     592         549 : }
     593             : 
     594           0 : void SwAutoTabDecimalPortion::Paint( const SwTextPaintInfo & ) const
     595             : {
     596           0 : }
     597             : 
     598          68 : void SwTabPortion::HandlePortion( SwPortionHandler& rPH ) const
     599             : {
     600          68 :     rPH.Text( GetLen(), GetWhichPor(), Height(), Width() );
     601         245 : }
     602             : 
     603             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11