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

Generated by: LCOV version 1.10