LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/core/text - guess.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 133 212 62.7 %
Date: 2013-07-09 Functions: 3 4 75.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 <ctype.h>
      21             : #include <editeng/unolingu.hxx>
      22             : #include <tools/shl.hxx>    // needed for SW_MOD() macro
      23             : #include <dlelstnr.hxx>
      24             : #include <swmodule.hxx>
      25             : #include <IDocumentSettingAccess.hxx>
      26             : #include <guess.hxx>
      27             : #include <inftxt.hxx>
      28             : #include <pagefrm.hxx>
      29             : #include <pagedesc.hxx> // SwPageDesc
      30             : #include <tgrditem.hxx>
      31             : #include <com/sun/star/i18n/BreakType.hpp>
      32             : #include <com/sun/star/i18n/WordType.hpp>
      33             : #include <unotools/charclass.hxx>
      34             : #include <porfld.hxx>
      35             : #include <paratr.hxx>
      36             : 
      37             : using namespace ::com::sun::star;
      38             : using namespace ::com::sun::star::uno;
      39             : using namespace ::com::sun::star::i18n;
      40             : using namespace ::com::sun::star::beans;
      41             : using namespace ::com::sun::star::linguistic2;
      42             : 
      43             : #define CH_FULL_BLANK 0x3000
      44             : 
      45             : /*************************************************************************
      46             :  *                      SwTxtGuess::Guess
      47             :  *
      48             :  * provides information for line break calculation
      49             :  * returns true if no line break has to be performed
      50             :  * otherwise possible break or hyphenation position is determined
      51             :  *************************************************************************/
      52             : 
      53       23921 : sal_Bool SwTxtGuess::Guess( const SwTxtPortion& rPor, SwTxtFormatInfo &rInf,
      54             :                             const KSHORT nPorHeight )
      55             : {
      56       23921 :     nCutPos = rInf.GetIdx();
      57             : 
      58             :     // Empty strings are always 0
      59       23921 :     if( !rInf.GetLen() || rInf.GetTxt().isEmpty() )
      60           0 :         return sal_False;
      61             : 
      62             :     OSL_ENSURE( rInf.GetIdx() < rInf.GetTxt().getLength(),
      63             :             "+SwTxtGuess::Guess: invalid SwTxtFormatInfo" );
      64             : 
      65             :     OSL_ENSURE( nPorHeight, "+SwTxtGuess::Guess: no height" );
      66             : 
      67             :     sal_uInt16 nMinSize;
      68             :     sal_uInt16 nMaxSizeDiff;
      69             : 
      70             :     const SwScriptInfo& rSI =
      71       23921 :             ((SwParaPortion*)rInf.GetParaPortion())->GetScriptInfo();
      72             : 
      73       23923 :     sal_uInt16 nMaxComp = ( SW_CJK == rInf.GetFont()->GetActual() ) &&
      74           2 :                         rSI.CountCompChg() &&
      75           0 :                         ! rInf.IsMulti() &&
      76           0 :                         ! rPor.InFldGrp() &&
      77           0 :                         ! rPor.IsDropPortion() ?
      78             :                         10000 :
      79       23921 :                             0 ;
      80             : 
      81       23921 :     SwTwips nLineWidth = rInf.Width() - rInf.X();
      82       23921 :     sal_Int32 nMaxLen = rInf.GetTxt().getLength() - rInf.GetIdx();
      83             : 
      84       23921 :     if ( rInf.GetLen() < nMaxLen )
      85       13852 :         nMaxLen = rInf.GetLen();
      86             : 
      87       23921 :     if( !nMaxLen )
      88           0 :         return sal_False;
      89             : 
      90       23921 :     KSHORT nItalic = 0;
      91       23921 :     if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
      92             :     {
      93         265 :         bool bAddItalic = true;
      94             : 
      95             :         // do not add extra italic value if we have an active character grid
      96         265 :         if ( rInf.SnapToGrid() )
      97             :         {
      98         263 :             GETGRID( rInf.GetTxtFrm()->FindPageFrm() )
      99         263 :             bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
     100             :         }
     101             : 
     102             :         // do not add extra italic value for an isolated blank:
     103         271 :         if ( 1 == rInf.GetLen() &&
     104           6 :              CH_BLANK == rInf.GetTxt()[ rInf.GetIdx() ] )
     105           0 :             bAddItalic = false;
     106             : 
     107         265 :         nItalic = bAddItalic ? nPorHeight / 12 : 0;
     108             : 
     109         265 :         nLineWidth -= nItalic;
     110             : 
     111             :         // #i46524# LineBreak bug with italics
     112         265 :         if ( nLineWidth < 0 ) nLineWidth = 0;
     113             :     }
     114             : 
     115       23921 :     const bool bUnbreakableNumberings = rInf.GetTxtFrm()->GetTxtNode()->
     116       23921 :             getIDocumentSettingAccess()->get(IDocumentSettingAccess::UNBREAKABLE_NUMBERINGS);
     117             : 
     118             :     // first check if everything fits to line
     119       29568 :     if ( ( long ( nLineWidth ) * 2 > long ( nMaxLen ) * nPorHeight ) ||
     120         804 :          ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
     121             :     {
     122             :         // call GetTxtSize with maximum compression (for kanas)
     123        5647 :         rInf.GetTxtSize( &rSI, rInf.GetIdx(), nMaxLen,
     124       11294 :                          nMaxComp, nMinSize, nMaxSizeDiff );
     125             : 
     126        5647 :         nBreakWidth = nMinSize;
     127             : 
     128        5647 :         if ( ( nBreakWidth <= nLineWidth ) || ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
     129             :         {
     130             :             // portion fits to line
     131        5646 :             nCutPos = rInf.GetIdx() + nMaxLen;
     132        5898 :             if( nItalic &&
     133         138 :                 ( nCutPos >= rInf.GetTxt().getLength() ||
     134             :                   // #i48035# Needed for CalcFitToContent
     135             :                   // if first line ends with a manual line break
     136           8 :                   rInf.GetTxt()[ nCutPos ] == CH_BREAK ) )
     137         122 :                 nBreakWidth = nBreakWidth + nItalic;
     138             : 
     139             :             // save maximum width for later use
     140        5646 :             if ( nMaxSizeDiff )
     141           0 :                 rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
     142             : 
     143        5646 :             return sal_True;
     144             :         }
     145             :     }
     146             : 
     147       18275 :     bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
     148       18275 :     xub_StrLen nHyphPos = 0;
     149             : 
     150             :     // nCutPos is the first character not fitting to the current line
     151             :     // nHyphPos is the first character not fitting to the current line,
     152             :     // considering an additional "-" for hyphenation
     153       18275 :     if( bHyph )
     154             :     {
     155           0 :         nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp, nHyphPos );
     156             : 
     157           0 :         if ( !nHyphPos && rInf.GetIdx() )
     158           0 :             nHyphPos = rInf.GetIdx() - 1;
     159             :     }
     160             :     else
     161             :     {
     162       18275 :         nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp );
     163             : 
     164             : #if OSL_DEBUG_LEVEL > 1
     165             :         if ( STRING_LEN != nCutPos )
     166             :         {
     167             :             rInf.GetTxtSize( &rSI, rInf.GetIdx(), nCutPos - rInf.GetIdx(),
     168             :                              nMaxComp, nMinSize, nMaxSizeDiff );
     169             :             OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
     170             :         }
     171             : #endif
     172             :     }
     173             : 
     174       18275 :     if( nCutPos > rInf.GetIdx() + nMaxLen )
     175             :     {
     176             :         // second check if everything fits to line
     177         764 :         nCutPos = nBreakPos = rInf.GetIdx() + nMaxLen - 1;
     178         764 :         rInf.GetTxtSize( &rSI, rInf.GetIdx(), nMaxLen, nMaxComp,
     179        1528 :                          nMinSize, nMaxSizeDiff );
     180             : 
     181         764 :         nBreakWidth = nMinSize;
     182             : 
     183             :         // The following comparison should always give sal_True, otherwise
     184             :         // there likely has been a pixel rounding error in GetTxtBreak
     185         764 :         if ( nBreakWidth <= nLineWidth )
     186             :         {
     187         764 :             if( nItalic && ( nBreakPos + 1 ) >= rInf.GetTxt().getLength() )
     188          43 :                 nBreakWidth = nBreakWidth + nItalic;
     189             : 
     190             :             // save maximum width for later use
     191         764 :             if ( nMaxSizeDiff )
     192           0 :                 rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
     193             : 
     194         764 :             return sal_True;
     195             :         }
     196             :     }
     197             : 
     198             :     // we have to trigger an underflow for a footnote portion
     199             :     // which does not fit to the current line
     200       17511 :     if ( rPor.IsFtnPortion() )
     201             :     {
     202           0 :         nBreakPos = rInf.GetIdx();
     203           0 :         nCutPos = rInf.GetLen();
     204           0 :         return sal_False;
     205             :     }
     206             : 
     207       17511 :     xub_StrLen nPorLen = 0;
     208             :     // do not call the break iterator nCutPos is a blank
     209       17511 :     sal_Unicode cCutChar = rInf.GetTxt()[ nCutPos ];
     210       17511 :     if( CH_BLANK == cCutChar || CH_FULL_BLANK == cCutChar )
     211             :     {
     212         254 :         nBreakPos = nCutPos;
     213         254 :         xub_StrLen nX = nBreakPos;
     214             : 
     215         254 :         const SvxAdjust& rAdjust = rInf.GetTxtFrm()->GetTxtNode()->GetSwAttrSet().GetAdjust().GetAdjust();
     216         254 :         if ( rAdjust == SVX_ADJUST_LEFT )
     217             :         {
     218             :             // we step back until a non blank character has been found
     219             :             // or there is only one more character left
     220         494 :             while( nX && nBreakPos > rInf.GetTxt().getLength() &&
     221           0 :                    ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
     222             :                      CH_FULL_BLANK == cCutChar ) )
     223           0 :                 --nBreakPos;
     224             :         }
     225             :         else // #i20878#
     226             :         {
     227          21 :             while( nX && nBreakPos > rInf.GetLineStart() + 1 &&
     228          14 :                    ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
     229             :                      CH_FULL_BLANK == cCutChar ) )
     230           0 :                 --nBreakPos;
     231             :         }
     232             : 
     233         254 :         if( nBreakPos > rInf.GetIdx() )
     234         254 :             nPorLen = nBreakPos - rInf.GetIdx();
     235         506 :         while( ++nCutPos < rInf.GetTxt().getLength() &&
     236         504 :                ( CH_BLANK == ( cCutChar = rInf.GetChar( nCutPos ) ) ||
     237             :                  CH_FULL_BLANK == cCutChar ) )
     238             :             ; // nothing
     239             : 
     240         254 :         nBreakStart = nCutPos;
     241             :     }
     242       17257 :     else if( g_pBreakIt->GetBreakIter().is() )
     243             :     {
     244             :         // New: We should have a look into the last portion, if it was a
     245             :         // field portion. For this, we expand the text of the field portion
     246             :         // into our string. If the line break position is inside of before
     247             :         // the field portion, we trigger an underflow.
     248             : 
     249       17257 :         xub_StrLen nOldIdx = rInf.GetIdx();
     250       17257 :         sal_Unicode cFldChr = 0;
     251             : 
     252             : #if OSL_DEBUG_LEVEL > 0
     253             :         OUString aDebugString;
     254             : #endif
     255             : 
     256             :         // be careful: a field portion can be both: 0x01 (common field)
     257             :         // or 0x02 (the follow of a footnode)
     258       51793 :         if ( rInf.GetLast() && rInf.GetLast()->InFldGrp() &&
     259          44 :              ! rInf.GetLast()->IsFtnPortion() &&
     260       17279 :              rInf.GetIdx() > rInf.GetLineStart() &&
     261             :              CH_TXTATR_BREAKWORD ==
     262           0 :                 ( cFldChr = rInf.GetTxt()[ rInf.GetIdx() - 1 ] ) )
     263             :         {
     264           0 :             SwFldPortion* pFld = (SwFldPortion*)rInf.GetLast();
     265           0 :             OUString aTxt;
     266           0 :             pFld->GetExpTxt( rInf, aTxt );
     267             : 
     268           0 :             if ( !aTxt.isEmpty() )
     269             :             {
     270           0 :                 nFieldDiff = aTxt.getLength() - 1;
     271           0 :                 nCutPos = nCutPos + nFieldDiff;
     272           0 :                 nHyphPos = nHyphPos + nFieldDiff;
     273             : 
     274             : #if OSL_DEBUG_LEVEL > 0
     275             :                 aDebugString = rInf.GetTxt();
     276             : #endif
     277             : 
     278           0 :                 OUString& rOldTxt = const_cast<OUString&> (rInf.GetTxt());
     279           0 :                 rOldTxt = rOldTxt.replaceAt( rInf.GetIdx() - 1, 1, aTxt );
     280           0 :                 rInf.SetIdx( rInf.GetIdx() + nFieldDiff );
     281             :             }
     282             :             else
     283           0 :                 cFldChr = 0;
     284             :         }
     285             : 
     286       17257 :         LineBreakHyphenationOptions aHyphOpt;
     287       34514 :         Reference< XHyphenator >  xHyph;
     288       17257 :         if( bHyph )
     289             :         {
     290           0 :             xHyph = ::GetHyphenator();
     291           0 :             aHyphOpt = LineBreakHyphenationOptions( xHyph,
     292           0 :                                 rInf.GetHyphValues(), nHyphPos );
     293             :         }
     294             : 
     295             :         // Get Language for break iterator.
     296             :         // We have to switch the current language if we have a script
     297             :         // change at nCutPos. Otherwise LATIN punctuation would never
     298             :         // be allowed to be hanging punctuation.
     299             :         // NEVER call GetLang if the string has been modified!!!
     300       17257 :         LanguageType aLang = rInf.GetFont()->GetLanguage();
     301             : 
     302             :         // If we are inside a field portion, we use a temporary string which
     303             :         // differs from the string at the textnode. Therefore we are not allowed
     304             :         // to call the GetLang function.
     305       17257 :         if ( nCutPos && ! rPor.InFldGrp() )
     306             :         {
     307       17237 :             const CharClass& rCC = GetAppCharClass();
     308             : 
     309             :             // step back until a non-punctuation character is reached
     310       17237 :             xub_StrLen nLangIndex = nCutPos;
     311             : 
     312             :             // If a field has been expanded right in front of us we do not
     313             :             // step further than the beginning of the expanded field
     314             :             // (which is the position of the field placeholder in our
     315             :             // original string).
     316             :             const xub_StrLen nDoNotStepOver = CH_TXTATR_BREAKWORD == cFldChr ?
     317           0 :                                               rInf.GetIdx() - nFieldDiff - 1:
     318       17237 :                                               0;
     319             : 
     320       57829 :             while ( nLangIndex > nDoNotStepOver &&
     321       20287 :                     ! rCC.isLetterNumeric( rInf.GetTxt(), nLangIndex ) )
     322        3068 :                 --nLangIndex;
     323             : 
     324             :             // last "real" character is not inside our current portion
     325             :             // we have to check the script type of the last "real" character
     326       17237 :             if ( nLangIndex < rInf.GetIdx() )
     327             :             {
     328          85 :                 sal_uInt16 nScript = g_pBreakIt->GetRealScriptOfText( rInf.GetTxt(),
     329         170 :                                                                 nLangIndex );
     330             :                 OSL_ENSURE( nScript, "Script is not between 1 and 4" );
     331             : 
     332             :                 // compare current script with script from last "real" character
     333          85 :                 if ( nScript - 1 != rInf.GetFont()->GetActual() )
     334             :                     aLang = rInf.GetTxtFrm()->GetTxtNode()->GetLang(
     335             :                         CH_TXTATR_BREAKWORD == cFldChr ?
     336             :                         nDoNotStepOver :
     337           0 :                         nLangIndex, 0, nScript );
     338             :             }
     339             :         }
     340             : 
     341             :         const ForbiddenCharacters aForbidden(
     342       34514 :                 *rInf.GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->getForbiddenCharacters( aLang, true ) );
     343             : 
     344       34422 :         const sal_Bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
     345       34422 :                                       ! rPor.InFldGrp();
     346             : 
     347             :         LineBreakUserOptions aUserOpt(
     348             :                 aForbidden.beginLine, aForbidden.endLine,
     349       34514 :                 rInf.HasForbiddenChars(), bAllowHanging, sal_False );
     350             : 
     351             :         //! register listener to LinguServiceEvents now in order to get
     352             :         //! notified about relevant changes in the future
     353       17257 :         SwModule *pModule = SW_MOD();
     354       17257 :         if (!pModule->GetLngSvcEvtListener().is())
     355           9 :             pModule->CreateLngSvcEvtListener();
     356             : 
     357             :         // !!! We must have a local copy of the locale, because inside
     358             :         // getLineBreak the LinguEventListener can trigger a new formatting,
     359             :         // which can corrupt the locale pointer inside pBreakIt.
     360       34514 :         const lang::Locale aLocale = g_pBreakIt->GetLocale( aLang );
     361             : 
     362             :         // determines first possible line break from nRightPos to
     363             :         // start index of current line
     364       34514 :         LineBreakResults aResult = g_pBreakIt->GetBreakIter()->getLineBreak(
     365       17257 :             rInf.GetTxt(), nCutPos, aLocale,
     366       51771 :             rInf.GetLineStart(), aHyphOpt, aUserOpt );
     367             : 
     368       17257 :         nBreakPos = (xub_StrLen)aResult.breakIndex;
     369             : 
     370             :         // if we are formatting multi portions we want to allow line breaks
     371             :         // at the border between single line and multi line portion
     372             :         // we have to be carefull with footnote portions, they always come in
     373             :         // with an index 0
     374       17257 :         if ( nBreakPos < rInf.GetLineStart() && rInf.IsFirstMulti() &&
     375           0 :              ! rInf.IsFtnInside() )
     376           0 :             nBreakPos = rInf.GetLineStart();
     377             : 
     378       17257 :         nBreakStart = nBreakPos;
     379             : 
     380       17257 :         bHyph = BreakType::HYPHENATION == aResult.breakType;
     381             : 
     382       17257 :         if ( bHyph && nBreakPos != STRING_LEN)
     383             :         {
     384             :             // found hyphenation position within line
     385             :             // nBreakPos is set to the hyphenation position
     386           0 :             xHyphWord = aResult.rHyphenatedWord;
     387           0 :             nBreakPos += xHyphWord->getHyphenationPos() + 1;
     388             : 
     389             : #if OSL_DEBUG_LEVEL > 1
     390             :             // e.g., Schif-fahrt, referes to our string
     391             :             const String aWord = xHyphWord->getWord();
     392             :             // e.g., Schiff-fahrt, referes to the word after hyphenation
     393             :             const String aHyphenatedWord = xHyphWord->getHyphenatedWord();
     394             :             // e.g., Schif-fahrt: 5, referes to our string
     395             :             const sal_uInt16 nHyphenationPos = xHyphWord->getHyphenationPos();
     396             :             (void)nHyphenationPos;
     397             :             // e.g., Schiff-fahrt: 6, referes to the word after hyphenation
     398             :             const sal_uInt16 nHyphenPos = xHyphWord->getHyphenPos();
     399             :             (void)nHyphenPos;
     400             : #endif
     401             : 
     402             :             // if not in interactive mode, we have to break behind a soft hyphen
     403           0 :             if ( ! rInf.IsInterHyph() && rInf.GetIdx() )
     404             :             {
     405             :                 const long nSoftHyphPos =
     406           0 :                         xHyphWord->getWord().indexOf( CHAR_SOFTHYPHEN );
     407             : 
     408           0 :                 if ( nSoftHyphPos >= 0 &&
     409           0 :                      nBreakStart + nSoftHyphPos <= nBreakPos &&
     410           0 :                      nBreakPos > rInf.GetLineStart() )
     411           0 :                     nBreakPos = rInf.GetIdx() - 1;
     412             :             }
     413             : 
     414           0 :             if( nBreakPos >= rInf.GetIdx() )
     415             :             {
     416           0 :                 nPorLen = nBreakPos - rInf.GetIdx();
     417           0 :                 if( '-' == rInf.GetTxt()[ nBreakPos - 1 ] )
     418           0 :                     xHyphWord = NULL;
     419           0 :             }
     420             :         }
     421       17257 :         else if ( !bHyph && nBreakPos >= rInf.GetLineStart() )
     422             :         {
     423             :             OSL_ENSURE( nBreakPos != STRING_LEN, "we should have found a break pos" );
     424             : 
     425             :             // found break position within line
     426       15732 :             xHyphWord = NULL;
     427             : 
     428             :             // check, if break position is soft hyphen and an underflow
     429             :             // has to be triggered
     430       28746 :             if( nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
     431       13014 :                 CHAR_SOFTHYPHEN == rInf.GetTxt()[ nBreakPos - 1 ] )
     432           0 :                 nBreakPos = rInf.GetIdx() - 1;
     433             : 
     434       15732 :             const SvxAdjust& rAdjust = rInf.GetTxtFrm()->GetTxtNode()->GetSwAttrSet().GetAdjust().GetAdjust();
     435       15732 :             if( rAdjust != SVX_ADJUST_LEFT )
     436             :             {
     437             :                 // Delete any blanks at the end of a line, but be careful:
     438             :                 // If a field has been expanded, we do not want to delete any
     439             :                 // blanks inside the field portion. This would cause an unwanted
     440             :                 // underflow
     441          50 :                 xub_StrLen nX = nBreakPos;
     442         328 :                 while( nX > rInf.GetLineStart() &&
     443         228 :                        ( CH_TXTATR_BREAKWORD != cFldChr || nX > rInf.GetIdx() ) &&
     444         136 :                        ( CH_BLANK == rInf.GetChar( --nX ) ||
     445          46 :                          CH_FULL_BLANK == rInf.GetChar( nX ) ) )
     446          44 :                     nBreakPos = nX;
     447             :             }
     448       15732 :             if( nBreakPos > rInf.GetIdx() )
     449       14574 :                 nPorLen = nBreakPos - rInf.GetIdx();
     450             :         }
     451             :         else
     452             :         {
     453             :             // no line break found, setting nBreakPos to STRING_LEN
     454             :             // causes a break cut
     455        1525 :             nBreakPos = STRING_LEN;
     456             :             OSL_ENSURE( nCutPos >= rInf.GetIdx(), "Deep cut" );
     457        1525 :             nPorLen = nCutPos - rInf.GetIdx();
     458             :         }
     459             : 
     460       17257 :         if( nBreakPos > nCutPos && nBreakPos != STRING_LEN )
     461             :         {
     462           0 :             const xub_StrLen nHangingLen = nBreakPos - nCutPos;
     463             :             SwPosSize aTmpSize = rInf.GetTxtSize( &rSI, nCutPos,
     464           0 :                                                   nHangingLen, 0 );
     465             :             OSL_ENSURE( !pHanging, "A hanging portion is hanging around" );
     466           0 :             pHanging = new SwHangingPortion( aTmpSize );
     467           0 :             pHanging->SetLen( nHangingLen );
     468           0 :             nPorLen = nCutPos - rInf.GetIdx();
     469             :         }
     470             : 
     471             :         // If we expanded a field, we must repair the original string.
     472             :         // In case we do not trigger an underflow, we correct the nBreakPos
     473             :         // value, but we cannot correct the nBreakStart value:
     474             :         // If we have found a hyphenation position, nBreakStart can lie before
     475             :         // the field.
     476       17257 :         if ( CH_TXTATR_BREAKWORD == cFldChr )
     477             :         {
     478           0 :             if ( nBreakPos < rInf.GetIdx() )
     479           0 :                 nBreakPos = nOldIdx - 1;
     480           0 :             else if ( STRING_LEN != nBreakPos )
     481             :             {
     482             :                 OSL_ENSURE( nBreakPos >= nFieldDiff, "I've got field trouble!" );
     483           0 :                 nBreakPos = nBreakPos - nFieldDiff;
     484             :             }
     485             : 
     486             :             OSL_ENSURE( nCutPos >= rInf.GetIdx() && nCutPos >= nFieldDiff,
     487             :                     "I've got field trouble, part2!" );
     488           0 :             nCutPos = nCutPos - nFieldDiff;
     489             : 
     490           0 :             OUString& rOldTxt = const_cast<OUString&> (rInf.GetTxt());
     491           0 :             OUString aReplacement( cFldChr );
     492           0 :             rOldTxt = rOldTxt.replaceAt( nOldIdx - 1, nFieldDiff + 1, aReplacement);
     493           0 :             rInf.SetIdx( nOldIdx );
     494             : 
     495             : #if OSL_DEBUG_LEVEL > 0
     496             :             OSL_ENSURE( aDebugString == rInf.GetTxt(),
     497             :                     "Somebody, somebody, somebody put something in my string" );
     498             : #endif
     499       17257 :         }
     500             :     }
     501             : 
     502       17511 :     if( nPorLen )
     503             :     {
     504       15585 :         rInf.GetTxtSize( &rSI, rInf.GetIdx(), nPorLen,
     505       31170 :                          nMaxComp, nMinSize, nMaxSizeDiff );
     506             : 
     507             :         // save maximum width for later use
     508       15585 :         if ( nMaxSizeDiff )
     509           0 :             rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
     510             : 
     511       15585 :         nBreakWidth = nItalic + nMinSize;
     512             :     }
     513             :     else
     514        1926 :         nBreakWidth = 0;
     515             : 
     516       17511 :     if( pHanging )
     517           0 :         nBreakPos = nCutPos;
     518             : 
     519       17511 :     return sal_False;
     520             : }
     521             : 
     522             : /*************************************************************************
     523             :  *                      SwTxtGuess::AlternativeSpelling
     524             :  *************************************************************************/
     525             : 
     526             : // returns true if word at position nPos has a diffenrent spelling
     527             : // if hyphenated at this position (old german spelling)
     528             : 
     529           0 : bool SwTxtGuess::AlternativeSpelling( const SwTxtFormatInfo &rInf,
     530             :     const xub_StrLen nPos )
     531             : {
     532             :     // get word boundaries
     533             :     xub_StrLen nWordLen;
     534             : 
     535             :     Boundary aBound =
     536           0 :         g_pBreakIt->GetBreakIter()->getWordBoundary( rInf.GetTxt(), nPos,
     537           0 :         g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
     538           0 :         WordType::DICTIONARY_WORD, sal_True );
     539           0 :     nBreakStart = (xub_StrLen)aBound.startPos;
     540           0 :     nWordLen = static_cast<xub_StrLen>(aBound.endPos - nBreakStart);
     541             : 
     542             :     // if everything else fails, we want to cut at nPos
     543           0 :     nCutPos = nPos;
     544             : 
     545           0 :     XubString aTxt( rInf.GetTxt().copy( nBreakStart, nWordLen ) );
     546             : 
     547             :     // check, if word has alternative spelling
     548           0 :     Reference< XHyphenator >  xHyph( ::GetHyphenator() );
     549             :     OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
     550             :     //! subtract 1 since the UNO-interface is 0 based
     551           0 :     xHyphWord = xHyph->queryAlternativeSpelling( OUString(aTxt),
     552           0 :                         g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
     553           0 :                         nPos - nBreakStart, rInf.GetHyphValues() );
     554           0 :     return xHyphWord.is() && xHyphWord->isAlternativeSpelling();
     555          99 : }
     556             : 
     557             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10