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

Generated by: LCOV version 1.10