LCOV - code coverage report
Current view: top level - sw/source/core/text - porglue.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 37 126 29.4 %
Date: 2014-11-03 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       35638 : SwGluePortion::SwGluePortion( const sal_uInt16 nInitFixWidth )
      31       35638 :     : nFixWidth( nInitFixWidth )
      32             : {
      33       35638 :     PrtWidth( nFixWidth );
      34       35638 :     SetWhichPor( POR_GLUE );
      35       35638 : }
      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::GetTxtSize( const SwTxtSizeInfo &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::GetExpTxt( const SwTxtSizeInfo &rInf, OUString &rTxt ) 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 :         rTxt = aBuf.makeStringAndClear();
      61           0 :         return true;
      62             :     }
      63           0 :     return false;
      64             : }
      65             : 
      66        4700 : void SwGluePortion::Paint( const SwTxtPaintInfo &rInf ) const
      67             : {
      68        4700 :     if( !GetLen() )
      69        9400 :         return;
      70             : 
      71           0 :     if( rInf.GetFont()->IsPaintBlank() )
      72             :     {
      73           0 :         OUStringBuffer aBuf;
      74           0 :         comphelper::string::padToLength(aBuf, GetFixWidth() / GetLen(), ' ');
      75           0 :         OUString aTxt(aBuf.makeStringAndClear());
      76           0 :         SwTxtPaintInfo aInf( rInf, &aTxt );
      77           0 :         aInf.DrawText( *this, aTxt.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.GetTxtSize( aBullet ) );
      91           0 :             Point aPos( rInf.GetPos() );
      92           0 :             aPos.X() += (Width()/2) - (aBulletSize.Width()/2);
      93           0 :             SwTxtPaintInfo aInf( rInf, &aBullet );
      94           0 :             aInf.SetPos( aPos );
      95           0 :             SwTxtPortion 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 :             SwTxtSlot aSlot( &rInf, this, true, false );
     104           0 :             rInf.DrawText( *this, rInf.GetLen(), true );
     105             :         }
     106             :     }
     107             : }
     108             : 
     109        1962 : void SwGluePortion::MoveGlue( SwGluePortion *pTarget, const short nPrtGlue )
     110             : {
     111        1962 :     short nPrt = std::min( nPrtGlue, GetPrtGlue() );
     112        1962 :     if( 0 < nPrt )
     113             :     {
     114        1930 :         pTarget->AddPrtWidth( nPrt );
     115        1930 :         SubPrtWidth( nPrt );
     116             :     }
     117        1962 : }
     118             : 
     119           4 : void SwGluePortion::Join( SwGluePortion *pVictim )
     120             : {
     121             :     // Die GluePortion wird ausgesogen und weggespuelt ...
     122           4 :     AddPrtWidth( pVictim->PrtWidth() );
     123           4 :     SetLen( pVictim->GetLen() + GetLen() );
     124           4 :     if( Height() < pVictim->Height() )
     125           4 :         Height( pVictim->Height() );
     126             : 
     127           4 :     AdjFixWidth();
     128           4 :     Cut( pVictim );
     129           4 :     delete pVictim;
     130           4 : }
     131             : 
     132             : // Wir erwarten ein framelokales SwRect !
     133        2366 : SwFixPortion::SwFixPortion( const SwRect &rRect )
     134        2366 :        :SwGluePortion( sal_uInt16(rRect.Width()) ), nFix( sal_uInt16(rRect.Left()) )
     135             : {
     136        2366 :     Height( sal_uInt16(rRect.Height()) );
     137        2366 :     SetWhichPor( POR_FIX );
     138        2366 : }
     139             : 
     140       28646 : SwFixPortion::SwFixPortion(const sal_uInt16 nFixedWidth, const sal_uInt16 nFixedPos)
     141       28646 :        : SwGluePortion(nFixedWidth), nFix(nFixedPos)
     142             : {
     143       28646 :     SetWhichPor( POR_FIX );
     144       28646 : }
     145             : 
     146        4626 : SwMarginPortion::SwMarginPortion( const sal_uInt16 nFixedWidth )
     147        4626 :     :SwGluePortion( nFixedWidth )
     148             : {
     149        4626 :     SetWhichPor( POR_MARGIN );
     150        4626 : }
     151             : 
     152             : // In the outer loop all portions are inspected - the GluePortions
     153             : // at the end are processed first.
     154             : // The end is shifted forwardly till no more GluePortions remain.
     155             : // Always GluePortion-pairs (pLeft and pRight) are treated, where
     156             : // textportions between pLeft and pRight are moved at the back of
     157             : // pRight if pRight has enough Glue. With every move part of the
     158             : // Glue is transferred from pRight to pLeft.
     159             : // The next loop starts with the processed pLeft as pRight.
     160           0 : void SwMarginPortion::AdjustRight( const SwLineLayout *pCurr )
     161             : {
     162           0 :     SwGluePortion *pRight = 0;
     163           0 :     bool bNoMove = 0 != pCurr->GetpKanaComp();
     164           0 :     while( pRight != this )
     165             :     {
     166             : 
     167             :         // 1) We search for the left Glue
     168           0 :         SwLinePortion *pPos = (SwLinePortion*)this;
     169           0 :         SwGluePortion *pLeft = 0;
     170           0 :         while( pPos )
     171             :         {
     172           0 :             if( pPos->InFixMargGrp() )
     173           0 :                 pLeft = (SwGluePortion*)pPos;
     174           0 :             pPos = pPos->GetPortion();
     175           0 :             if( pPos == pRight)
     176           0 :                 pPos = 0;
     177             :         }
     178             : 
     179             :         // Two adjoining FlyPortions are merged
     180           0 :         if( pRight && pLeft && pLeft->GetPortion() == pRight )
     181             :         {
     182           0 :             pRight->MoveAllGlue( pLeft );
     183           0 :             pRight = 0;
     184             :         }
     185           0 :         sal_uInt16 nRightGlue = pRight && 0 < pRight->GetPrtGlue()
     186           0 :                           ? sal_uInt16(pRight->GetPrtGlue()) : 0;
     187             :         // 2) balance left and right Glue
     188             :         //    But not for tabs ...
     189           0 :         if( pLeft && nRightGlue && !pRight->InTabGrp() )
     190             :         {
     191             :             // pPrev is the portion immediately before pRight
     192           0 :             SwLinePortion *pPrev = pRight->FindPrevPortion( pLeft );
     193             : 
     194           0 :             if ( pRight->IsFlyPortion() && pRight->GetLen() )
     195             :             {
     196           0 :                 SwFlyPortion *pFly = (SwFlyPortion *)pRight;
     197           0 :                 if ( pFly->GetBlankWidth() < nRightGlue )
     198             :                 {
     199             :                     // Creating new TxtPortion, that takes over the
     200             :                     // Blank previously swallowed by the Fly.
     201           0 :                     nRightGlue = nRightGlue - pFly->GetBlankWidth();
     202           0 :                     pFly->SubPrtWidth( pFly->GetBlankWidth() );
     203           0 :                     pFly->SetLen( 0 );
     204           0 :                     SwTxtPortion *pNewPor = new SwTxtPortion;
     205           0 :                     pNewPor->SetLen( 1 );
     206           0 :                     pNewPor->Height( pFly->Height() );
     207           0 :                     pNewPor->Width( pFly->GetBlankWidth() );
     208           0 :                     pFly->Insert( pNewPor );
     209             :                 }
     210             :                 else
     211           0 :                     pPrev = pLeft;
     212             :             }
     213           0 :             while( pPrev != pLeft )
     214             :             {
     215           0 :                 if( bNoMove || pPrev->PrtWidth() >= nRightGlue ||
     216           0 :                     pPrev->InHyphGrp() || pPrev->IsKernPortion() )
     217             :                 {
     218             :                     // The portion before the pRight cannot be moved
     219             :                     // because no Glue is remaining.
     220             :                     // We set the break condition:
     221           0 :                     pPrev = pLeft;
     222             :                 }
     223             :                 else
     224             :                 {
     225           0 :                     nRightGlue = nRightGlue - pPrev->PrtWidth();
     226             :                     // pPrev is moved behind pRight. For this the
     227             :                     // Glue value between pRight and pLeft gets balanced.
     228           0 :                     pRight->MoveGlue( pLeft, short( pPrev->PrtWidth() ) );
     229             :                     // Now fix the linking of our portions.
     230           0 :                     SwLinePortion *pPrevPrev = pPrev->FindPrevPortion( pLeft );
     231           0 :                     pPrevPrev->SetPortion( pRight );
     232           0 :                     pPrev->SetPortion( pRight->GetPortion() );
     233           0 :                     pRight->SetPortion( pPrev );
     234           0 :                     if ( pPrev->GetPortion() && pPrev->InTxtGrp()
     235           0 :                          && pPrev->GetPortion()->IsHolePortion() )
     236             :                     {
     237             :                         SwHolePortion *pHolePor =
     238           0 :                             (SwHolePortion*)pPrev->GetPortion();
     239           0 :                         if ( !pHolePor->GetPortion() ||
     240           0 :                              !pHolePor->GetPortion()->InFixMargGrp() )
     241             :                         {
     242           0 :                             pPrev->AddPrtWidth( pHolePor->GetBlankWidth() );
     243           0 :                             pPrev->SetLen( pPrev->GetLen() + 1 );
     244           0 :                             pPrev->SetPortion( pHolePor->GetPortion() );
     245           0 :                             delete pHolePor;
     246             :                         }
     247             :                     }
     248           0 :                     pPrev = pPrevPrev;
     249             :                 }
     250             :             }
     251             :         }
     252             :         // If no left Glue remaines we set the break condition.
     253           0 :         pRight = pLeft ? pLeft : (SwGluePortion*)this;
     254             :     }
     255         270 : }
     256             : 
     257             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10