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

Generated by: LCOV version 1.10