LCOV - code coverage report
Current view: top level - sw/source/core/text - porglue.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 37 126 29.4 %
Date: 2015-06-13 12:38:46 Functions: 9 13 69.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 "swrect.hxx"
      21             : #include "paratr.hxx"
      22             : #include "viewopt.hxx"
      23             : #include <SwPortionHandler.hxx>
      24             : #include "porglue.hxx"
      25             : #include "inftxt.hxx"
      26             : #include "porlay.hxx"
      27             : #include "porfly.hxx"
      28             : #include <comphelper/string.hxx>
      29             : 
      30       20583 : SwGluePortion::SwGluePortion( const sal_uInt16 nInitFixWidth )
      31       20583 :     : nFixWidth( nInitFixWidth )
      32             : {
      33       20583 :     PrtWidth( nFixWidth );
      34       20583 :     SetWhichPor( POR_GLUE );
      35       20583 : }
      36             : 
      37           0 : sal_Int32 SwGluePortion::GetCrsrOfst( const sal_uInt16 nOfst ) const
      38             : {
      39           0 :     if( !GetLen() || nOfst > GetLen() || !Width() )
      40           0 :         return SwLinePortion::GetCrsrOfst( nOfst );
      41             :     else
      42           0 :         return nOfst / (Width() / GetLen());
      43             : }
      44             : 
      45           0 : SwPosSize SwGluePortion::GetTextSize( const SwTextSizeInfo &rInf ) const
      46             : {
      47           0 :     if( 1 >= GetLen() || rInf.GetLen() > GetLen() || !Width() || !GetLen() )
      48           0 :         return SwPosSize(*this);
      49             :     else
      50           0 :         return SwPosSize( (Width() / GetLen()) * rInf.GetLen(), Height() );
      51             : }
      52             : 
      53           0 : bool SwGluePortion::GetExpText( const SwTextSizeInfo &rInf, OUString &rText ) const
      54             : {
      55           0 :     if( GetLen() && rInf.OnWin() &&
      56           0 :         rInf.GetOpt().IsBlank() && rInf.IsNoSymbol() )
      57             :     {
      58           0 :         OUStringBuffer aBuf;
      59           0 :         comphelper::string::padToLength(aBuf, GetLen(), CH_BULLET);
      60           0 :         rText = aBuf.makeStringAndClear();
      61           0 :         return true;
      62             :     }
      63           0 :     return false;
      64             : }
      65             : 
      66        2876 : void SwGluePortion::Paint( const SwTextPaintInfo &rInf ) const
      67             : {
      68        2876 :     if( !GetLen() )
      69        5752 :         return;
      70             : 
      71           0 :     if( rInf.GetFont()->IsPaintBlank() )
      72             :     {
      73           0 :         OUStringBuffer aBuf;
      74           0 :         comphelper::string::padToLength(aBuf, GetFixWidth() / GetLen(), ' ');
      75           0 :         OUString aText(aBuf.makeStringAndClear());
      76           0 :         SwTextPaintInfo aInf( rInf, &aText );
      77           0 :         aInf.DrawText( *this, aText.getLength(), true );
      78             :     }
      79             : 
      80           0 :     if( rInf.OnWin() && rInf.GetOpt().IsBlank() && rInf.IsNoSymbol() )
      81             :     {
      82             : #if OSL_DEBUG_LEVEL > 0
      83             :         const sal_Unicode cChar = rInf.GetChar( rInf.GetIdx() );
      84             :         OSL_ENSURE( CH_BLANK  == cChar || CH_BULLET == cChar,
      85             :                 "SwGluePortion::Paint: blank expected" );
      86             : #endif
      87           0 :         if( 1 == GetLen() )
      88             :         {
      89           0 :             OUString aBullet( CH_BULLET );
      90           0 :             SwPosSize aBulletSize( rInf.GetTextSize( aBullet ) );
      91           0 :             Point aPos( rInf.GetPos() );
      92           0 :             aPos.X() += (Width()/2) - (aBulletSize.Width()/2);
      93           0 :             SwTextPaintInfo aInf( rInf, &aBullet );
      94           0 :             aInf.SetPos( aPos );
      95           0 :             SwTextPortion aBulletPor;
      96           0 :             aBulletPor.Width( aBulletSize.Width() );
      97           0 :             aBulletPor.Height( aBulletSize.Height() );
      98           0 :             aBulletPor.SetAscent( GetAscent() );
      99           0 :             aInf.DrawText( aBulletPor, aBullet.getLength(), true );
     100             :         }
     101             :         else
     102             :         {
     103           0 :             SwTextSlot aSlot( &rInf, this, true, false );
     104           0 :             rInf.DrawText( *this, rInf.GetLen(), true );
     105             :         }
     106             :     }
     107             : }
     108             : 
     109        1121 : void SwGluePortion::MoveGlue( SwGluePortion *pTarget, const short nPrtGlue )
     110             : {
     111        1121 :     short nPrt = std::min( nPrtGlue, GetPrtGlue() );
     112        1121 :     if( 0 < nPrt )
     113             :     {
     114        1105 :         pTarget->AddPrtWidth( nPrt );
     115        1105 :         SubPrtWidth( nPrt );
     116             :     }
     117        1121 : }
     118             : 
     119           2 : void SwGluePortion::Join( SwGluePortion *pVictim )
     120             : {
     121             :     // The GluePortion is extracted and flushed away ...
     122           2 :     AddPrtWidth( pVictim->PrtWidth() );
     123           2 :     SetLen( pVictim->GetLen() + GetLen() );
     124           2 :     if( Height() < pVictim->Height() )
     125           2 :         Height( pVictim->Height() );
     126             : 
     127           2 :     AdjFixWidth();
     128           2 :     Cut( pVictim );
     129           2 :     delete pVictim;
     130           2 : }
     131             : 
     132             : /**
     133             :  * We're expecting a frame-local SwRect!
     134             :  */
     135        1123 : SwFixPortion::SwFixPortion( const SwRect &rRect )
     136        1123 :        :SwGluePortion( sal_uInt16(rRect.Width()) ), nFix( sal_uInt16(rRect.Left()) )
     137             : {
     138        1123 :     Height( sal_uInt16(rRect.Height()) );
     139        1123 :     SetWhichPor( POR_FIX );
     140        1123 : }
     141             : 
     142       16905 : SwFixPortion::SwFixPortion(const sal_uInt16 nFixedWidth, const sal_uInt16 nFixedPos)
     143       16905 :        : SwGluePortion(nFixedWidth), nFix(nFixedPos)
     144             : {
     145       16905 :     SetWhichPor( POR_FIX );
     146       16905 : }
     147             : 
     148        2555 : SwMarginPortion::SwMarginPortion( const sal_uInt16 nFixedWidth )
     149        2555 :     :SwGluePortion( nFixedWidth )
     150             : {
     151        2555 :     SetWhichPor( POR_MARGIN );
     152        2555 : }
     153             : 
     154             : /**
     155             :  * In the outer loop all portions are inspected - the GluePortions
     156             :  * at the end are processed first.
     157             :  * The end is shifted forwardly till no more GluePortions remain.
     158             :  * Always GluePortion-pairs (pLeft and pRight) are treated, where
     159             :  * textportions between pLeft and pRight are moved at the back of
     160             :  * pRight if pRight has enough Glue. With every move part of the
     161             :  * Glue is transferred from pRight to pLeft.
     162             :  * The next loop starts with the processed pLeft as pRight.
     163             :  */
     164           0 : void SwMarginPortion::AdjustRight( const SwLineLayout *pCurr )
     165             : {
     166           0 :     SwGluePortion *pRight = 0;
     167           0 :     bool bNoMove = 0 != pCurr->GetpKanaComp();
     168           0 :     while( pRight != this )
     169             :     {
     170             : 
     171             :         // 1) We search for the left Glue
     172           0 :         SwLinePortion *pPos = this;
     173           0 :         SwGluePortion *pLeft = 0;
     174           0 :         while( pPos )
     175             :         {
     176           0 :             if( pPos->InFixMargGrp() )
     177           0 :                 pLeft = static_cast<SwGluePortion*>(pPos);
     178           0 :             pPos = pPos->GetPortion();
     179           0 :             if( pPos == pRight)
     180           0 :                 pPos = 0;
     181             :         }
     182             : 
     183             :         // Two adjoining FlyPortions are merged
     184           0 :         if( pRight && pLeft && pLeft->GetPortion() == pRight )
     185             :         {
     186           0 :             pRight->MoveAllGlue( pLeft );
     187           0 :             pRight = 0;
     188             :         }
     189           0 :         sal_uInt16 nRightGlue = pRight && 0 < pRight->GetPrtGlue()
     190           0 :                           ? sal_uInt16(pRight->GetPrtGlue()) : 0;
     191             :         // 2) balance left and right Glue
     192             :         //    But not for tabs ...
     193           0 :         if( pLeft && nRightGlue && !pRight->InTabGrp() )
     194             :         {
     195             :             // pPrev is the portion immediately before pRight
     196           0 :             SwLinePortion *pPrev = pRight->FindPrevPortion( pLeft );
     197             : 
     198           0 :             if ( pRight->IsFlyPortion() && pRight->GetLen() )
     199             :             {
     200           0 :                 SwFlyPortion *pFly = static_cast<SwFlyPortion *>(pRight);
     201           0 :                 if ( pFly->GetBlankWidth() < nRightGlue )
     202             :                 {
     203             :                     // Creating new TextPortion, that takes over the
     204             :                     // Blank previously swallowed by the Fly.
     205           0 :                     nRightGlue = nRightGlue - pFly->GetBlankWidth();
     206           0 :                     pFly->SubPrtWidth( pFly->GetBlankWidth() );
     207           0 :                     pFly->SetLen( 0 );
     208           0 :                     SwTextPortion *pNewPor = new SwTextPortion;
     209           0 :                     pNewPor->SetLen( 1 );
     210           0 :                     pNewPor->Height( pFly->Height() );
     211           0 :                     pNewPor->Width( pFly->GetBlankWidth() );
     212           0 :                     pFly->Insert( pNewPor );
     213             :                 }
     214             :                 else
     215           0 :                     pPrev = pLeft;
     216             :             }
     217           0 :             while( pPrev != pLeft )
     218             :             {
     219           0 :                 if( bNoMove || pPrev->PrtWidth() >= nRightGlue ||
     220           0 :                     pPrev->InHyphGrp() || pPrev->IsKernPortion() )
     221             :                 {
     222             :                     // The portion before the pRight cannot be moved
     223             :                     // because no Glue is remaining.
     224             :                     // We set the break condition:
     225           0 :                     pPrev = pLeft;
     226             :                 }
     227             :                 else
     228             :                 {
     229           0 :                     nRightGlue = nRightGlue - pPrev->PrtWidth();
     230             :                     // pPrev is moved behind pRight. For this the
     231             :                     // Glue value between pRight and pLeft gets balanced.
     232           0 :                     pRight->MoveGlue( pLeft, short( pPrev->PrtWidth() ) );
     233             :                     // Now fix the linking of our portions.
     234           0 :                     SwLinePortion *pPrevPrev = pPrev->FindPrevPortion( pLeft );
     235           0 :                     pPrevPrev->SetPortion( pRight );
     236           0 :                     pPrev->SetPortion( pRight->GetPortion() );
     237           0 :                     pRight->SetPortion( pPrev );
     238           0 :                     if ( pPrev->GetPortion() && pPrev->InTextGrp()
     239           0 :                          && pPrev->GetPortion()->IsHolePortion() )
     240             :                     {
     241             :                         SwHolePortion *pHolePor =
     242           0 :                             static_cast<SwHolePortion*>(pPrev->GetPortion());
     243           0 :                         if ( !pHolePor->GetPortion() ||
     244           0 :                              !pHolePor->GetPortion()->InFixMargGrp() )
     245             :                         {
     246           0 :                             pPrev->AddPrtWidth( pHolePor->GetBlankWidth() );
     247           0 :                             pPrev->SetLen( pPrev->GetLen() + 1 );
     248           0 :                             pPrev->SetPortion( pHolePor->GetPortion() );
     249           0 :                             delete pHolePor;
     250             :                         }
     251             :                     }
     252           0 :                     pPrev = pPrevPrev;
     253             :                 }
     254             :             }
     255             :         }
     256             :         // If no left Glue remaines we set the break condition.
     257           0 :         pRight = pLeft ? pLeft : this;
     258             :     }
     259         177 : }
     260             : 
     261             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11