LCOV - code coverage report
Current view: top level - sw/source/core/text - guess.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 159 216 73.6 %
Date: 2015-06-13 12:38:46 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      102021 : bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf,
      48             :                             const sal_uInt16 nPorHeight )
      49             : {
      50      102021 :     nCutPos = rInf.GetIdx();
      51             : 
      52             :     // Empty strings are always 0
      53      102021 :     if( !rInf.GetLen() || rInf.GetText().isEmpty() )
      54           0 :         return false;
      55             : 
      56             :     OSL_ENSURE( rInf.GetIdx() < rInf.GetText().getLength(),
      57             :             "+SwTextGuess::Guess: invalid SwTextFormatInfo" );
      58             : 
      59             :     OSL_ENSURE( nPorHeight, "+SwTextGuess::Guess: no height" );
      60             : 
      61             :     sal_uInt16 nMaxSizeDiff;
      62             : 
      63             :     const SwScriptInfo& rSI =
      64      102021 :             static_cast<SwParaPortion*>(rInf.GetParaPortion())->GetScriptInfo();
      65             : 
      66      104300 :     sal_uInt16 nMaxComp = ( SW_CJK == rInf.GetFont()->GetActual() ) &&
      67        2279 :                         rSI.CountCompChg() &&
      68           0 :                         ! rInf.IsMulti() &&
      69           0 :                         ! rPor.InFieldGrp() &&
      70           0 :                         ! rPor.IsDropPortion() ?
      71             :                         10000 :
      72      102021 :                             0 ;
      73             : 
      74      102021 :     SwTwips nLineWidth = rInf.Width() - rInf.X();
      75      102021 :     sal_Int32 nMaxLen = rInf.GetText().getLength() - rInf.GetIdx();
      76             : 
      77      102021 :     if ( rInf.GetLen() < nMaxLen )
      78       56223 :         nMaxLen = rInf.GetLen();
      79             : 
      80      102021 :     if( !nMaxLen )
      81           0 :         return false;
      82             : 
      83      102021 :     sal_uInt16 nItalic = 0;
      84      102021 :     if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
      85             :     {
      86        5959 :         bool bAddItalic = true;
      87             : 
      88             :         // do not add extra italic value if we have an active character grid
      89        5959 :         if ( rInf.SnapToGrid() )
      90             :         {
      91             :             SwTextGridItem const*const pGrid(
      92         809 :                     GetGridItem(rInf.GetTextFrm()->FindPageFrm()));
      93         809 :             bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
      94             :         }
      95             : 
      96             :         // do not add extra italic value for an isolated blank:
      97        6570 :         if ( 1 == rInf.GetLen() &&
      98         611 :              CH_BLANK == rInf.GetText()[ rInf.GetIdx() ] )
      99         459 :             bAddItalic = false;
     100             : 
     101        5959 :         nItalic = bAddItalic ? nPorHeight / 12 : 0;
     102             : 
     103        5959 :         nLineWidth -= nItalic;
     104             : 
     105             :         // #i46524# LineBreak bug with italics
     106        5959 :         if ( nLineWidth < 0 ) nLineWidth = 0;
     107             :     }
     108             : 
     109             :     const sal_Int32 nLeftRightBorderSpace =
     110      306063 :         (!rPor.GetJoinBorderWithNext() ? rInf.GetFont()->GetRightBorderSpace() : 0) +
     111      306063 :         (!rPor.GetJoinBorderWithPrev() ? rInf.GetFont()->GetLeftBorderSpace() : 0);
     112             : 
     113      102021 :     nLineWidth -= nLeftRightBorderSpace;
     114             : 
     115      102021 :     const bool bUnbreakableNumberings = rInf.GetTextFrm()->GetTextNode()->
     116      102021 :             getIDocumentSettingAccess()->get(DocumentSettingId::UNBREAKABLE_NUMBERINGS);
     117             : 
     118             :     // first check if everything fits to line
     119      163755 :     if ( ( long ( nLineWidth ) * 2 > long ( nMaxLen ) * nPorHeight ) ||
     120       16036 :          ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
     121             :     {
     122             :         // call GetTextSize with maximum compression (for kanas)
     123             :         rInf.GetTextSize( &rSI, rInf.GetIdx(), nMaxLen,
     124       61734 :                          nMaxComp, nBreakWidth, nMaxSizeDiff );
     125             : 
     126       61734 :         if ( ( nBreakWidth <= nLineWidth ) || ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
     127             :         {
     128             :             // portion fits to line
     129       61708 :             nCutPos = rInf.GetIdx() + nMaxLen;
     130       66061 :             if( nItalic &&
     131        4401 :                 ( nCutPos >= rInf.GetText().getLength() ||
     132             :                   // #i48035# Needed for CalcFitToContent
     133             :                   // if first line ends with a manual line break
     134        1484 :                   rInf.GetText()[ nCutPos ] == CH_BREAK ) )
     135        1436 :                 nBreakWidth = nBreakWidth + nItalic;
     136             : 
     137             :             // save maximum width for later use
     138       61708 :             if ( nMaxSizeDiff )
     139           0 :                 rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
     140             : 
     141       61708 :             nBreakWidth += nLeftRightBorderSpace;
     142             : 
     143       61708 :             return true;
     144             :         }
     145             :     }
     146             : 
     147       40313 :     bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
     148       40313 :     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       40313 :     if( bHyph )
     154             :     {
     155           0 :         nCutPos = rInf.GetTextBreak( nLineWidth, nMaxLen, nMaxComp, nHyphPos, rInf.GetCachedVclData().get() );
     156             : 
     157           0 :         if ( !nHyphPos && rInf.GetIdx() )
     158           0 :             nHyphPos = rInf.GetIdx() - 1;
     159             :     }
     160             :     else
     161             :     {
     162       40313 :         nCutPos = rInf.GetTextBreak( nLineWidth, nMaxLen, nMaxComp, rInf.GetCachedVclData().get() );
     163             : 
     164             : #if OSL_DEBUG_LEVEL > 1
     165             :         if ( COMPLETE_STRING != nCutPos )
     166             :         {
     167             :             sal_uInt16 nMinSize;
     168             :             rInf.GetTextSize( &rSI, rInf.GetIdx(), nCutPos - rInf.GetIdx(),
     169             :                              nMaxComp, nMinSize, nMaxSizeDiff );
     170             :             OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
     171             :         }
     172             : #endif
     173             :     }
     174             : 
     175       40313 :     if( nCutPos > rInf.GetIdx() + nMaxLen )
     176             :     {
     177             :         // second check if everything fits to line
     178        5109 :         nCutPos = nBreakPos = rInf.GetIdx() + nMaxLen - 1;
     179             :         rInf.GetTextSize( &rSI, rInf.GetIdx(), nMaxLen, nMaxComp,
     180        5109 :                          nBreakWidth, nMaxSizeDiff );
     181             : 
     182             :         // The following comparison should always give true, otherwise
     183             :         // there likely has been a pixel rounding error in GetTextBreak
     184        5109 :         if ( nBreakWidth <= nLineWidth )
     185             :         {
     186        5109 :             if( nItalic && ( nBreakPos + 1 ) >= rInf.GetText().getLength() )
     187          65 :                 nBreakWidth = nBreakWidth + nItalic;
     188             : 
     189             :             // save maximum width for later use
     190        5109 :             if ( nMaxSizeDiff )
     191           0 :                 rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
     192             : 
     193        5109 :             nBreakWidth += nLeftRightBorderSpace;
     194             : 
     195        5109 :             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       35204 :     if ( rPor.IsFootnotePortion() )
     202             :     {
     203           0 :         nBreakPos = rInf.GetIdx();
     204           0 :         nCutPos = -1;
     205           0 :         return false;
     206             :     }
     207             : 
     208       35204 :     sal_Int32 nPorLen = 0;
     209             :     // do not call the break iterator nCutPos is a blank
     210       35204 :     sal_Unicode cCutChar = nCutPos < rInf.GetText().getLength() ? rInf.GetText()[nCutPos] : 0;
     211       35204 :     if( CH_BLANK == cCutChar || CH_FULL_BLANK == cCutChar )
     212             :     {
     213        1424 :         nBreakPos = nCutPos;
     214        1424 :         sal_Int32 nX = nBreakPos;
     215             : 
     216        1424 :         const SvxAdjust& rAdjust = rInf.GetTextFrm()->GetTextNode()->GetSwAttrSet().GetAdjust().GetAdjust();
     217        1424 :         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        2064 :             while( nX && nBreakPos > rInf.GetText().getLength() &&
     222           0 :                    ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
     223             :                      CH_FULL_BLANK == cCutChar ) )
     224           0 :                 --nBreakPos;
     225             :         }
     226             :         else // #i20878#
     227             :         {
     228        1614 :             while( nX && nBreakPos > rInf.GetLineStart() + 1 &&
     229         875 :                    ( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
     230             :                      CH_FULL_BLANK == cCutChar ) )
     231         157 :                 --nBreakPos;
     232             :         }
     233             : 
     234        1424 :         if( nBreakPos > rInf.GetIdx() )
     235        1317 :             nPorLen = nBreakPos - rInf.GetIdx();
     236        4086 :         while( ++nCutPos < rInf.GetText().getLength() &&
     237        3392 :                ( CH_BLANK == ( cCutChar = rInf.GetChar( nCutPos ) ) ||
     238             :                  CH_FULL_BLANK == cCutChar ) )
     239             :             ; // nothing
     240             : 
     241        1424 :         nBreakStart = nCutPos;
     242             :     }
     243       33780 :     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       33780 :         sal_Int32 nOldIdx = rInf.GetIdx();
     251       33780 :         sal_Unicode cFieldChr = 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      101595 :         if ( rInf.GetLast() && rInf.GetLast()->InFieldGrp() &&
     260         509 :              ! rInf.GetLast()->IsFootnotePortion() &&
     261       34061 :              rInf.GetIdx() > rInf.GetLineStart() &&
     262             :              CH_TXTATR_BREAKWORD ==
     263          27 :                 ( cFieldChr = rInf.GetText()[ rInf.GetIdx() - 1 ] ) )
     264             :         {
     265          27 :             SwFieldPortion* pField = static_cast<SwFieldPortion*>(rInf.GetLast());
     266          27 :             OUString aText;
     267          27 :             pField->GetExpText( rInf, aText );
     268             : 
     269          27 :             if ( !aText.isEmpty() )
     270             :             {
     271          27 :                 nFieldDiff = aText.getLength() - 1;
     272          27 :                 nCutPos = nCutPos + nFieldDiff;
     273          27 :                 nHyphPos = nHyphPos + nFieldDiff;
     274             : 
     275             : #if OSL_DEBUG_LEVEL > 0
     276             :                 aDebugString = rInf.GetText();
     277             : #endif
     278             : 
     279          27 :                 OUString& rOldText = const_cast<OUString&> (rInf.GetText());
     280          27 :                 rOldText = rOldText.replaceAt( rInf.GetIdx() - 1, 1, aText );
     281          27 :                 rInf.SetIdx( rInf.GetIdx() + nFieldDiff );
     282             :             }
     283             :             else
     284           0 :                 cFieldChr = 0;
     285             :         }
     286             : 
     287       33780 :         LineBreakHyphenationOptions aHyphOpt;
     288       67560 :         Reference< XHyphenator >  xHyph;
     289       33780 :         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       33780 :         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       33780 :         if ( nCutPos && ! rPor.InFieldGrp() )
     307             :         {
     308       33629 :             const CharClass& rCC = GetAppCharClass();
     309             : 
     310             :             // step back until a non-punctuation character is reached
     311       33629 :             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 == cFieldChr ?
     318          27 :                                               rInf.GetIdx() - nFieldDiff - 1:
     319       33656 :                                               0;
     320             : 
     321       67258 :             if ( nLangIndex > nDoNotStepOver &&
     322       33629 :                     rInf.GetText().getLength() == nLangIndex )
     323           0 :                 --nLangIndex;
     324             : 
     325      157655 :             while ( nLangIndex > nDoNotStepOver &&
     326       61998 :                     ! rCC.isLetterNumeric( rInf.GetText(), nLangIndex ) )
     327       28399 :                 --nLangIndex;
     328             : 
     329             :             // last "real" character is not inside our current portion
     330             :             // we have to check the script type of the last "real" character
     331       33629 :             if ( nLangIndex < rInf.GetIdx() )
     332             :             {
     333         127 :                 sal_uInt16 nScript = g_pBreakIt->GetRealScriptOfText( rInf.GetText(),
     334         127 :                                                                 nLangIndex );
     335             :                 OSL_ENSURE( nScript, "Script is not between 1 and 4" );
     336             : 
     337             :                 // compare current script with script from last "real" character
     338         127 :                 if ( nScript - 1 != rInf.GetFont()->GetActual() )
     339             :                     aLang = rInf.GetTextFrm()->GetTextNode()->GetLang(
     340             :                         CH_TXTATR_BREAKWORD == cFieldChr ?
     341             :                         nDoNotStepOver :
     342           1 :                         nLangIndex, 0, nScript );
     343             :             }
     344             :         }
     345             : 
     346             :         const ForbiddenCharacters aForbidden(
     347       67560 :                 *rInf.GetTextFrm()->GetNode()->getIDocumentSettingAccess()->getForbiddenCharacters( aLang, true ) );
     348             : 
     349       67302 :         const bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
     350       67302 :                                       ! rPor.InFieldGrp();
     351             : 
     352             :         LineBreakUserOptions aUserOpt(
     353             :                 aForbidden.beginLine, aForbidden.endLine,
     354       67560 :                 rInf.HasForbiddenChars(), bAllowHanging, false );
     355             : 
     356             :         //! register listener to LinguServiceEvents now in order to get
     357             :         //! notified about relevant changes in the future
     358       33780 :         SwModule *pModule = SW_MOD();
     359       33780 :         if (!pModule->GetLngSvcEvtListener().is())
     360          23 :             pModule->CreateLngSvcEvtListener();
     361             : 
     362             :         // !!! We must have a local copy of the locale, because inside
     363             :         // getLineBreak the LinguEventListener can trigger a new formatting,
     364             :         // which can corrupt the locale pointer inside pBreakIt.
     365       67560 :         const lang::Locale aLocale = g_pBreakIt->GetLocale( aLang );
     366             : 
     367             :         // determines first possible line break from nCutPos to
     368             :         // start index of current line
     369       67560 :         LineBreakResults aResult = g_pBreakIt->GetBreakIter()->getLineBreak(
     370       33780 :             rInf.GetText(), nCutPos, aLocale,
     371      101340 :             rInf.GetLineStart(), aHyphOpt, aUserOpt );
     372             : 
     373       33780 :         nBreakPos = aResult.breakIndex;
     374             : 
     375             :         // if we are formatting multi portions we want to allow line breaks
     376             :         // at the border between single line and multi line portion
     377             :         // we have to be careful with footnote portions, they always come in
     378             :         // with an index 0
     379       33780 :         if ( nBreakPos < rInf.GetLineStart() && rInf.IsFirstMulti() &&
     380           0 :              ! rInf.IsFootnoteInside() )
     381           0 :             nBreakPos = rInf.GetLineStart();
     382             : 
     383       33780 :         nBreakStart = nBreakPos;
     384             : 
     385       33780 :         bHyph = BreakType::HYPHENATION == aResult.breakType;
     386             : 
     387       33780 :         if ( bHyph && nBreakPos != COMPLETE_STRING )
     388             :         {
     389             :             // found hyphenation position within line
     390             :             // nBreakPos is set to the hyphenation position
     391           0 :             xHyphWord = aResult.rHyphenatedWord;
     392           0 :             nBreakPos += xHyphWord->getHyphenationPos() + 1;
     393             : 
     394             :             // if not in interactive mode, we have to break behind a soft hyphen
     395           0 :             if ( ! rInf.IsInterHyph() && rInf.GetIdx() )
     396             :             {
     397             :                 const long nSoftHyphPos =
     398           0 :                         xHyphWord->getWord().indexOf( CHAR_SOFTHYPHEN );
     399             : 
     400           0 :                 if ( nSoftHyphPos >= 0 &&
     401           0 :                      nBreakStart + nSoftHyphPos <= nBreakPos &&
     402           0 :                      nBreakPos > rInf.GetLineStart() )
     403           0 :                     nBreakPos = rInf.GetIdx() - 1;
     404             :             }
     405             : 
     406           0 :             if( nBreakPos >= rInf.GetIdx() )
     407             :             {
     408           0 :                 nPorLen = nBreakPos - rInf.GetIdx();
     409           0 :                 if( '-' == rInf.GetText()[ nBreakPos - 1 ] )
     410           0 :                     xHyphWord = NULL;
     411           0 :             }
     412             :         }
     413       33780 :         else if ( !bHyph && nBreakPos >= rInf.GetLineStart() )
     414             :         {
     415             :             OSL_ENSURE( nBreakPos != COMPLETE_STRING, "we should have found a break pos" );
     416             : 
     417             :             // found break position within line
     418       32922 :             xHyphWord = NULL;
     419             : 
     420             :             // check, if break position is soft hyphen and an underflow
     421             :             // has to be triggered
     422       59595 :             if( nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
     423       26673 :                 CHAR_SOFTHYPHEN == rInf.GetText()[ nBreakPos - 1 ] )
     424           0 :                 nBreakPos = rInf.GetIdx() - 1;
     425             : 
     426       32922 :             const SvxAdjust& rAdjust = rInf.GetTextFrm()->GetTextNode()->GetSwAttrSet().GetAdjust().GetAdjust();
     427       32922 :             if( rAdjust != SVX_ADJUST_LEFT )
     428             :             {
     429             :                 // Delete any blanks at the end of a line, but be careful:
     430             :                 // If a field has been expanded, we do not want to delete any
     431             :                 // blanks inside the field portion. This would cause an unwanted
     432             :                 // underflow
     433        2586 :                 sal_Int32 nX = nBreakPos;
     434       17507 :                 while( nX > rInf.GetLineStart() &&
     435       12335 :                        ( CH_TXTATR_BREAKWORD != cFieldChr || nX > rInf.GetIdx() ) &&
     436        7373 :                        ( CH_BLANK == rInf.GetChar( --nX ) ||
     437        2474 :                          CH_FULL_BLANK == rInf.GetChar( nX ) ) )
     438        2425 :                     nBreakPos = nX;
     439             :             }
     440       32922 :             if( nBreakPos > rInf.GetIdx() )
     441       30295 :                 nPorLen = nBreakPos - rInf.GetIdx();
     442             :         }
     443             :         else
     444             :         {
     445             :             // no line break found, setting nBreakPos to COMPLETE_STRING
     446             :             // causes a break cut
     447         858 :             nBreakPos = COMPLETE_STRING;
     448             :             OSL_ENSURE( nCutPos >= rInf.GetIdx(), "Deep cut" );
     449         858 :             nPorLen = nCutPos - rInf.GetIdx();
     450             :         }
     451             : 
     452       33780 :         if( nBreakPos > nCutPos && nBreakPos != COMPLETE_STRING )
     453             :         {
     454           0 :             const sal_Int32 nHangingLen = nBreakPos - nCutPos;
     455             :             SwPosSize aTmpSize = rInf.GetTextSize( &rSI, nCutPos,
     456           0 :                                                   nHangingLen, 0 );
     457           0 :             aTmpSize.Width(aTmpSize.Width() + nLeftRightBorderSpace);
     458             :             OSL_ENSURE( !pHanging, "A hanging portion is hanging around" );
     459           0 :             pHanging = new SwHangingPortion( aTmpSize );
     460           0 :             pHanging->SetLen( nHangingLen );
     461           0 :             nPorLen = nCutPos - rInf.GetIdx();
     462             :         }
     463             : 
     464             :         // If we expanded a field, we must repair the original string.
     465             :         // In case we do not trigger an underflow, we correct the nBreakPos
     466             :         // value, but we cannot correct the nBreakStart value:
     467             :         // If we have found a hyphenation position, nBreakStart can lie before
     468             :         // the field.
     469       33780 :         if ( CH_TXTATR_BREAKWORD == cFieldChr )
     470             :         {
     471          27 :             if ( nBreakPos < rInf.GetIdx() )
     472           6 :                 nBreakPos = nOldIdx - 1;
     473          21 :             else if ( COMPLETE_STRING != nBreakPos )
     474             :             {
     475             :                 OSL_ENSURE( nBreakPos >= nFieldDiff, "I've got field trouble!" );
     476          21 :                 nBreakPos = nBreakPos - nFieldDiff;
     477             :             }
     478             : 
     479             :             OSL_ENSURE( nCutPos >= rInf.GetIdx() && nCutPos >= nFieldDiff,
     480             :                     "I've got field trouble, part2!" );
     481          27 :             nCutPos = nCutPos - nFieldDiff;
     482             : 
     483          27 :             OUString& rOldText = const_cast<OUString&> (rInf.GetText());
     484          27 :             OUString aReplacement( cFieldChr );
     485          27 :             rOldText = rOldText.replaceAt( nOldIdx - 1, nFieldDiff + 1, aReplacement);
     486          27 :             rInf.SetIdx( nOldIdx );
     487             : 
     488             : #if OSL_DEBUG_LEVEL > 0
     489             :             OSL_ENSURE( aDebugString == rInf.GetText(),
     490             :                     "Somebody, somebody, somebody put something in my string" );
     491             : #endif
     492       33780 :         }
     493             :     }
     494             : 
     495       35204 :     if( nPorLen )
     496             :     {
     497             :         rInf.GetTextSize( &rSI, rInf.GetIdx(), nPorLen,
     498             :                          nMaxComp, nBreakWidth, nMaxSizeDiff,
     499       31956 :                          rInf.GetCachedVclData().get() );
     500             : 
     501             :         // save maximum width for later use
     502       31956 :         if ( nMaxSizeDiff )
     503           0 :             rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
     504             : 
     505       31956 :         nBreakWidth += nItalic + nLeftRightBorderSpace;
     506             :     }
     507             :     else
     508        3248 :         nBreakWidth = 0;
     509             : 
     510       35204 :     if( pHanging )
     511           0 :         nBreakPos = nCutPos;
     512             : 
     513       35204 :     return false;
     514             : }
     515             : 
     516             : // returns true if word at position nPos has a diffenrent spelling
     517             : // if hyphenated at this position (old german spelling)
     518           0 : bool SwTextGuess::AlternativeSpelling( const SwTextFormatInfo &rInf,
     519             :     const sal_Int32 nPos )
     520             : {
     521             :     // get word boundaries
     522             :     Boundary aBound =
     523           0 :         g_pBreakIt->GetBreakIter()->getWordBoundary( rInf.GetText(), nPos,
     524           0 :         g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
     525           0 :         WordType::DICTIONARY_WORD, true );
     526           0 :     nBreakStart = aBound.startPos;
     527           0 :     sal_Int32 nWordLen = aBound.endPos - nBreakStart;
     528             : 
     529             :     // if everything else fails, we want to cut at nPos
     530           0 :     nCutPos = nPos;
     531             : 
     532           0 :     OUString aText( rInf.GetText().copy( nBreakStart, nWordLen ) );
     533             : 
     534             :     // check, if word has alternative spelling
     535           0 :     Reference< XHyphenator >  xHyph( ::GetHyphenator() );
     536             :     OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
     537             :     //! subtract 1 since the UNO-interface is 0 based
     538           0 :     xHyphWord = xHyph->queryAlternativeSpelling( aText,
     539           0 :                         g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
     540           0 :                         nPos - nBreakStart, rInf.GetHyphValues() );
     541           0 :     return xHyphWord.is() && xHyphWord->isAlternativeSpelling();
     542         177 : }
     543             : 
     544             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11