2010-10-14 08:30:41 +02:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
2011-03-31 10:05:04 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
2000-09-18 23:08:29 +00:00
|
|
|
*
|
2011-03-31 10:05:04 +02:00
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
2000-09-18 23:08:29 +00:00
|
|
|
*
|
2011-03-31 10:05:04 +02:00
|
|
|
* This file incorporates work covered by the following license notice:
|
2000-09-18 23:08:29 +00:00
|
|
|
*
|
2011-03-31 10:05:04 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed
|
|
|
|
* with this work for additional information regarding copyright
|
|
|
|
* ownership. The ASF licenses this file to you under the Apache
|
|
|
|
* License, Version 2.0 (the "License"); you may not use this file
|
|
|
|
* except in compliance with the License. You may obtain a copy of
|
|
|
|
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
|
|
|
|
*/
|
2006-09-16 20:34:42 +00:00
|
|
|
|
2000-09-18 23:08:29 +00:00
|
|
|
#include <ctype.h>
|
2010-01-08 18:32:51 +01:00
|
|
|
#include <editeng/unolingu.hxx>
|
2002-02-19 12:45:46 +00:00
|
|
|
#include <dlelstnr.hxx>
|
|
|
|
#include <swmodule.hxx>
|
2006-08-14 15:36:58 +00:00
|
|
|
#include <IDocumentSettingAccess.hxx>
|
2000-10-25 11:07:02 +00:00
|
|
|
#include <guess.hxx>
|
2006-08-14 15:36:58 +00:00
|
|
|
#include <inftxt.hxx>
|
2002-08-07 07:20:02 +00:00
|
|
|
#include <pagefrm.hxx>
|
2013-10-22 15:58:57 +03:00
|
|
|
#include <pagedesc.hxx>
|
2002-08-07 07:20:02 +00:00
|
|
|
#include <tgrditem.hxx>
|
2000-11-20 15:27:07 +00:00
|
|
|
#include <com/sun/star/i18n/BreakType.hpp>
|
2001-02-15 12:45:21 +00:00
|
|
|
#include <com/sun/star/i18n/WordType.hpp>
|
2002-02-20 11:44:15 +00:00
|
|
|
#include <unotools/charclass.hxx>
|
2001-10-26 13:42:27 +00:00
|
|
|
#include <porfld.hxx>
|
2011-05-02 14:59:26 +02:00
|
|
|
#include <paratr.hxx>
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
using namespace ::com::sun::star;
|
2000-09-18 23:08:29 +00:00
|
|
|
using namespace ::com::sun::star::uno;
|
2000-11-20 15:27:07 +00:00
|
|
|
using namespace ::com::sun::star::i18n;
|
2001-02-15 12:45:21 +00:00
|
|
|
using namespace ::com::sun::star::beans;
|
2000-10-27 11:17:04 +00:00
|
|
|
using namespace ::com::sun::star::linguistic2;
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2002-03-27 12:26:53 +00:00
|
|
|
#define CH_FULL_BLANK 0x3000
|
|
|
|
|
2014-04-18 00:59:07 -04:00
|
|
|
// provides information for line break calculation
|
|
|
|
// returns true if no line break has to be performed
|
|
|
|
// otherwise possible break or hyphenation position is determined
|
2014-02-02 19:54:50 +01:00
|
|
|
bool SwTxtGuess::Guess( const SwTxtPortion& rPor, SwTxtFormatInfo &rInf,
|
2014-07-22 17:14:17 +02:00
|
|
|
const sal_uInt16 nPorHeight )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-02-15 12:45:21 +00:00
|
|
|
nCutPos = rInf.GetIdx();
|
2001-04-09 09:44:17 +00:00
|
|
|
|
2011-05-02 14:59:26 +02:00
|
|
|
// Empty strings are always 0
|
2013-04-07 21:25:31 +02:00
|
|
|
if( !rInf.GetLen() || rInf.GetTxt().isEmpty() )
|
2014-02-02 19:54:50 +01:00
|
|
|
return false;
|
2001-05-07 10:37:09 +00:00
|
|
|
|
2013-04-07 21:25:31 +02:00
|
|
|
OSL_ENSURE( rInf.GetIdx() < rInf.GetTxt().getLength(),
|
2000-09-18 23:08:29 +00:00
|
|
|
"+SwTxtGuess::Guess: invalid SwTxtFormatInfo" );
|
|
|
|
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( nPorHeight, "+SwTxtGuess::Guess: no height" );
|
2001-05-07 10:37:09 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nMaxSizeDiff;
|
2001-04-09 09:44:17 +00:00
|
|
|
|
|
|
|
const SwScriptInfo& rSI =
|
2014-11-24 10:39:29 +02:00
|
|
|
static_cast<SwParaPortion*>(rInf.GetParaPortion())->GetScriptInfo();
|
2001-04-09 09:44:17 +00:00
|
|
|
|
2011-01-17 15:06:54 +01:00
|
|
|
sal_uInt16 nMaxComp = ( SW_CJK == rInf.GetFont()->GetActual() ) &&
|
2001-04-09 09:44:17 +00:00
|
|
|
rSI.CountCompChg() &&
|
|
|
|
! rInf.IsMulti() &&
|
2001-05-07 10:37:09 +00:00
|
|
|
! rPor.InFldGrp() &&
|
|
|
|
! rPor.IsDropPortion() ?
|
2001-04-09 09:44:17 +00:00
|
|
|
10000 :
|
|
|
|
0 ;
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2000-11-24 14:38:27 +00:00
|
|
|
SwTwips nLineWidth = rInf.Width() - rInf.X();
|
2013-04-07 21:25:31 +02:00
|
|
|
sal_Int32 nMaxLen = rInf.GetTxt().getLength() - rInf.GetIdx();
|
2007-09-27 08:12:57 +00:00
|
|
|
|
|
|
|
if ( rInf.GetLen() < nMaxLen )
|
|
|
|
nMaxLen = rInf.GetLen();
|
|
|
|
|
2003-10-30 09:19:05 +00:00
|
|
|
if( !nMaxLen )
|
2014-02-02 19:54:50 +01:00
|
|
|
return false;
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2014-07-22 17:14:17 +02:00
|
|
|
sal_uInt16 nItalic = 0;
|
2000-09-18 23:08:29 +00:00
|
|
|
if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
|
|
|
|
{
|
2012-12-05 08:33:07 +09:00
|
|
|
bool bAddItalic = true;
|
2002-08-07 07:20:02 +00:00
|
|
|
|
|
|
|
// do not add extra italic value if we have an active character grid
|
|
|
|
if ( rInf.SnapToGrid() )
|
|
|
|
{
|
2014-03-07 16:49:52 +01:00
|
|
|
SwTextGridItem const*const pGrid(
|
|
|
|
GetGridItem(rInf.GetTxtFrm()->FindPageFrm()));
|
2003-11-25 09:46:05 +00:00
|
|
|
bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
|
2002-08-07 07:20:02 +00:00
|
|
|
}
|
|
|
|
|
2003-11-25 09:46:05 +00:00
|
|
|
// do not add extra italic value for an isolated blank:
|
|
|
|
if ( 1 == rInf.GetLen() &&
|
2013-04-07 21:25:31 +02:00
|
|
|
CH_BLANK == rInf.GetTxt()[ rInf.GetIdx() ] )
|
2012-12-05 08:33:07 +09:00
|
|
|
bAddItalic = false;
|
2003-11-25 09:46:05 +00:00
|
|
|
|
2002-08-07 07:20:02 +00:00
|
|
|
nItalic = bAddItalic ? nPorHeight / 12 : 0;
|
2005-09-28 10:18:23 +00:00
|
|
|
|
|
|
|
nLineWidth -= nItalic;
|
|
|
|
|
2011-04-16 22:42:13 -03:00
|
|
|
// #i46524# LineBreak bug with italics
|
2005-09-28 10:18:23 +00:00
|
|
|
if ( nLineWidth < 0 ) nLineWidth = 0;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2013-08-21 13:17:07 +02:00
|
|
|
const sal_Int32 nLeftRightBorderSpace =
|
|
|
|
(!rPor.GetJoinBorderWithNext() ? rInf.GetFont()->GetRightBorderSpace() : 0) +
|
|
|
|
(!rPor.GetJoinBorderWithPrev() ? rInf.GetFont()->GetLeftBorderSpace() : 0);
|
|
|
|
|
|
|
|
nLineWidth -= nLeftRightBorderSpace;
|
2013-07-22 22:21:54 +02:00
|
|
|
|
2011-11-10 16:10:25 +01:00
|
|
|
const bool bUnbreakableNumberings = rInf.GetTxtFrm()->GetTxtNode()->
|
|
|
|
getIDocumentSettingAccess()->get(IDocumentSettingAccess::UNBREAKABLE_NUMBERINGS);
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
// first check if everything fits to line
|
2011-11-10 16:10:25 +01:00
|
|
|
if ( ( long ( nLineWidth ) * 2 > long ( nMaxLen ) * nPorHeight ) ||
|
|
|
|
( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-04-09 09:44:17 +00:00
|
|
|
// call GetTxtSize with maximum compression (for kanas)
|
|
|
|
rInf.GetTxtSize( &rSI, rInf.GetIdx(), nMaxLen,
|
2013-08-21 11:50:31 +02:00
|
|
|
nMaxComp, nBreakWidth, nMaxSizeDiff );
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2011-11-10 16:10:25 +01:00
|
|
|
if ( ( nBreakWidth <= nLineWidth ) || ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-02-15 12:45:21 +00:00
|
|
|
// portion fits to line
|
2005-09-28 10:18:23 +00:00
|
|
|
nCutPos = rInf.GetIdx() + nMaxLen;
|
|
|
|
if( nItalic &&
|
2013-04-07 21:25:31 +02:00
|
|
|
( nCutPos >= rInf.GetTxt().getLength() ||
|
2011-04-16 22:42:13 -03:00
|
|
|
// #i48035# Needed for CalcFitToContent
|
2005-09-28 10:18:23 +00:00
|
|
|
// if first line ends with a manual line break
|
2013-04-07 21:25:31 +02:00
|
|
|
rInf.GetTxt()[ nCutPos ] == CH_BREAK ) )
|
2007-09-27 08:12:57 +00:00
|
|
|
nBreakWidth = nBreakWidth + nItalic;
|
2001-04-09 09:44:17 +00:00
|
|
|
|
|
|
|
// save maximum width for later use
|
|
|
|
if ( nMaxSizeDiff )
|
2014-09-03 08:35:32 +02:00
|
|
|
rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
|
2001-04-09 09:44:17 +00:00
|
|
|
|
2013-08-21 13:17:07 +02:00
|
|
|
nBreakWidth += nLeftRightBorderSpace;
|
|
|
|
|
2014-02-02 19:54:50 +01:00
|
|
|
return true;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-12-05 08:33:07 +09:00
|
|
|
bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
|
2014-01-14 16:50:42 +00:00
|
|
|
sal_Int32 nHyphPos = 0;
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
// nCutPos is the first character not fitting to the current line
|
|
|
|
// nHyphPos is the first character not fitting to the current line,
|
|
|
|
// considering an additional "-" for hyphenation
|
2000-09-18 23:08:29 +00:00
|
|
|
if( bHyph )
|
2001-02-15 12:45:21 +00:00
|
|
|
{
|
2001-04-09 09:44:17 +00:00
|
|
|
nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp, nHyphPos );
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
if ( !nHyphPos && rInf.GetIdx() )
|
|
|
|
nHyphPos = rInf.GetIdx() - 1;
|
|
|
|
}
|
2000-09-18 23:08:29 +00:00
|
|
|
else
|
2001-03-15 14:58:37 +00:00
|
|
|
{
|
2001-04-09 09:44:17 +00:00
|
|
|
nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp );
|
|
|
|
|
2010-11-25 17:08:45 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2014-01-14 16:50:42 +00:00
|
|
|
if ( COMPLETE_STRING != nCutPos )
|
2001-04-09 09:44:17 +00:00
|
|
|
{
|
2013-08-21 11:50:31 +02:00
|
|
|
sal_uInt16 nMinSize;
|
2001-04-09 09:44:17 +00:00
|
|
|
rInf.GetTxtSize( &rSI, rInf.GetIdx(), nCutPos - rInf.GetIdx(),
|
|
|
|
nMaxComp, nMinSize, nMaxSizeDiff );
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
|
2001-04-09 09:44:17 +00:00
|
|
|
}
|
2001-03-15 14:58:37 +00:00
|
|
|
#endif
|
|
|
|
}
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
if( nCutPos > rInf.GetIdx() + nMaxLen )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-02-15 12:45:21 +00:00
|
|
|
// second check if everything fits to line
|
|
|
|
nCutPos = nBreakPos = rInf.GetIdx() + nMaxLen - 1;
|
2001-04-09 09:44:17 +00:00
|
|
|
rInf.GetTxtSize( &rSI, rInf.GetIdx(), nMaxLen, nMaxComp,
|
2013-08-21 11:50:31 +02:00
|
|
|
nBreakWidth, nMaxSizeDiff );
|
2001-04-09 09:44:17 +00:00
|
|
|
|
2014-02-02 19:54:50 +01:00
|
|
|
// The following comparison should always give true, otherwise
|
2012-09-06 11:54:01 +02:00
|
|
|
// there likely has been a pixel rounding error in GetTxtBreak
|
2001-02-15 12:45:21 +00:00
|
|
|
if ( nBreakWidth <= nLineWidth )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2013-04-07 21:25:31 +02:00
|
|
|
if( nItalic && ( nBreakPos + 1 ) >= rInf.GetTxt().getLength() )
|
2007-09-27 08:12:57 +00:00
|
|
|
nBreakWidth = nBreakWidth + nItalic;
|
2001-04-09 09:44:17 +00:00
|
|
|
|
|
|
|
// save maximum width for later use
|
|
|
|
if ( nMaxSizeDiff )
|
2014-09-03 08:35:32 +02:00
|
|
|
rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
|
2001-04-09 09:44:17 +00:00
|
|
|
|
2013-08-21 13:17:07 +02:00
|
|
|
nBreakWidth += nLeftRightBorderSpace;
|
|
|
|
|
2014-02-02 19:54:50 +01:00
|
|
|
return true;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-08-20 12:08:45 +00:00
|
|
|
// we have to trigger an underflow for a footnote portion
|
|
|
|
// which does not fit to the current line
|
|
|
|
if ( rPor.IsFtnPortion() )
|
|
|
|
{
|
|
|
|
nBreakPos = rInf.GetIdx();
|
|
|
|
nCutPos = rInf.GetLen();
|
2014-02-02 19:54:50 +01:00
|
|
|
return false;
|
2001-08-20 12:08:45 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 16:50:42 +00:00
|
|
|
sal_Int32 nPorLen = 0;
|
2002-03-27 12:26:53 +00:00
|
|
|
// do not call the break iterator nCutPos is a blank
|
2015-02-17 10:02:24 +00:00
|
|
|
sal_Unicode cCutChar = nCutPos < rInf.GetTxt().getLength() ? rInf.GetTxt()[nCutPos] : 0;
|
2002-03-27 12:26:53 +00:00
|
|
|
if( CH_BLANK == cCutChar || CH_FULL_BLANK == cCutChar )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-02-15 12:45:21 +00:00
|
|
|
nBreakPos = nCutPos;
|
2014-01-14 16:50:42 +00:00
|
|
|
sal_Int32 nX = nBreakPos;
|
2001-06-27 12:25:02 +00:00
|
|
|
|
2011-05-02 14:59:26 +02:00
|
|
|
const SvxAdjust& rAdjust = rInf.GetTxtFrm()->GetTxtNode()->GetSwAttrSet().GetAdjust().GetAdjust();
|
|
|
|
if ( rAdjust == SVX_ADJUST_LEFT )
|
|
|
|
{
|
|
|
|
// we step back until a non blank character has been found
|
|
|
|
// or there is only one more character left
|
2013-04-07 21:25:31 +02:00
|
|
|
while( nX && nBreakPos > rInf.GetTxt().getLength() &&
|
2011-05-02 14:59:26 +02:00
|
|
|
( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
|
|
|
|
CH_FULL_BLANK == cCutChar ) )
|
|
|
|
--nBreakPos;
|
|
|
|
}
|
2011-03-31 10:05:04 +02:00
|
|
|
else // #i20878#
|
2011-05-02 14:59:26 +02:00
|
|
|
{
|
|
|
|
while( nX && nBreakPos > rInf.GetLineStart() + 1 &&
|
|
|
|
( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
|
|
|
|
CH_FULL_BLANK == cCutChar ) )
|
|
|
|
--nBreakPos;
|
|
|
|
}
|
2001-06-27 12:25:02 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
if( nBreakPos > rInf.GetIdx() )
|
|
|
|
nPorLen = nBreakPos - rInf.GetIdx();
|
2013-04-07 21:25:31 +02:00
|
|
|
while( ++nCutPos < rInf.GetTxt().getLength() &&
|
2002-03-27 12:26:53 +00:00
|
|
|
( CH_BLANK == ( cCutChar = rInf.GetChar( nCutPos ) ) ||
|
|
|
|
CH_FULL_BLANK == cCutChar ) )
|
|
|
|
; // nothing
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
nBreakStart = nCutPos;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
2013-04-19 10:34:21 +02:00
|
|
|
else if( g_pBreakIt->GetBreakIter().is() )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-10-26 13:42:27 +00:00
|
|
|
// New: We should have a look into the last portion, if it was a
|
|
|
|
// field portion. For this, we expand the text of the field portion
|
|
|
|
// into our string. If the line break position is inside of before
|
|
|
|
// the field portion, we trigger an underflow.
|
|
|
|
|
2014-01-14 16:50:42 +00:00
|
|
|
sal_Int32 nOldIdx = rInf.GetIdx();
|
2012-10-19 05:34:48 -05:00
|
|
|
sal_Unicode cFldChr = 0;
|
2001-10-26 13:42:27 +00:00
|
|
|
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2013-01-25 23:01:35 +00:00
|
|
|
OUString aDebugString;
|
2001-10-26 13:42:27 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// be careful: a field portion can be both: 0x01 (common field)
|
|
|
|
// or 0x02 (the follow of a footnode)
|
|
|
|
if ( rInf.GetLast() && rInf.GetLast()->InFldGrp() &&
|
|
|
|
! rInf.GetLast()->IsFtnPortion() &&
|
|
|
|
rInf.GetIdx() > rInf.GetLineStart() &&
|
2001-12-20 10:54:36 +00:00
|
|
|
CH_TXTATR_BREAKWORD ==
|
2013-04-07 21:25:31 +02:00
|
|
|
( cFldChr = rInf.GetTxt()[ rInf.GetIdx() - 1 ] ) )
|
2001-10-26 13:42:27 +00:00
|
|
|
{
|
2014-11-21 14:36:31 +02:00
|
|
|
SwFldPortion* pFld = static_cast<SwFldPortion*>(rInf.GetLast());
|
2013-04-07 21:25:31 +02:00
|
|
|
OUString aTxt;
|
2001-10-26 13:42:27 +00:00
|
|
|
pFld->GetExpTxt( rInf, aTxt );
|
|
|
|
|
2013-04-07 21:25:31 +02:00
|
|
|
if ( !aTxt.isEmpty() )
|
2001-10-26 13:42:27 +00:00
|
|
|
{
|
2013-04-07 21:25:31 +02:00
|
|
|
nFieldDiff = aTxt.getLength() - 1;
|
2007-09-27 08:12:57 +00:00
|
|
|
nCutPos = nCutPos + nFieldDiff;
|
|
|
|
nHyphPos = nHyphPos + nFieldDiff;
|
2001-10-26 13:42:27 +00:00
|
|
|
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2001-10-26 13:42:27 +00:00
|
|
|
aDebugString = rInf.GetTxt();
|
|
|
|
#endif
|
|
|
|
|
2013-05-12 17:01:01 +02:00
|
|
|
OUString& rOldTxt = const_cast<OUString&> (rInf.GetTxt());
|
2013-04-07 21:25:31 +02:00
|
|
|
rOldTxt = rOldTxt.replaceAt( rInf.GetIdx() - 1, 1, aTxt );
|
2001-10-26 13:42:27 +00:00
|
|
|
rInf.SetIdx( rInf.GetIdx() + nFieldDiff );
|
|
|
|
}
|
|
|
|
else
|
|
|
|
cFldChr = 0;
|
|
|
|
}
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
LineBreakHyphenationOptions aHyphOpt;
|
|
|
|
Reference< XHyphenator > xHyph;
|
|
|
|
if( bHyph )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-02-15 12:45:21 +00:00
|
|
|
xHyph = ::GetHyphenator();
|
2001-03-28 09:44:46 +00:00
|
|
|
aHyphOpt = LineBreakHyphenationOptions( xHyph,
|
2001-03-29 07:05:13 +00:00
|
|
|
rInf.GetHyphValues(), nHyphPos );
|
2001-02-15 12:45:21 +00:00
|
|
|
}
|
2000-11-21 10:36:49 +00:00
|
|
|
|
2002-11-01 08:39:36 +00:00
|
|
|
// Get Language for break iterator.
|
2001-07-24 06:56:43 +00:00
|
|
|
// We have to switch the current language if we have a script
|
|
|
|
// change at nCutPos. Otherwise LATIN punctuation would never
|
|
|
|
// be allowed to be hanging punctuation.
|
2002-11-01 08:39:36 +00:00
|
|
|
// NEVER call GetLang if the string has been modified!!!
|
|
|
|
LanguageType aLang = rInf.GetFont()->GetLanguage();
|
|
|
|
|
2013-04-07 21:25:31 +02:00
|
|
|
// If we are inside a field portion, we use a temporary string which
|
2002-11-01 08:39:36 +00:00
|
|
|
// differs from the string at the textnode. Therefore we are not allowed
|
|
|
|
// to call the GetLang function.
|
|
|
|
if ( nCutPos && ! rPor.InFldGrp() )
|
|
|
|
{
|
|
|
|
const CharClass& rCC = GetAppCharClass();
|
|
|
|
|
|
|
|
// step back until a non-punctuation character is reached
|
2014-01-14 16:50:42 +00:00
|
|
|
sal_Int32 nLangIndex = nCutPos;
|
2002-11-01 08:39:36 +00:00
|
|
|
|
|
|
|
// If a field has been expanded right in front of us we do not
|
|
|
|
// step further than the beginning of the expanded field
|
|
|
|
// (which is the position of the field placeholder in our
|
|
|
|
// original string).
|
2014-01-14 16:50:42 +00:00
|
|
|
const sal_Int32 nDoNotStepOver = CH_TXTATR_BREAKWORD == cFldChr ?
|
2002-11-01 08:39:36 +00:00
|
|
|
rInf.GetIdx() - nFieldDiff - 1:
|
|
|
|
0;
|
|
|
|
|
|
|
|
while ( nLangIndex > nDoNotStepOver &&
|
|
|
|
! rCC.isLetterNumeric( rInf.GetTxt(), nLangIndex ) )
|
|
|
|
--nLangIndex;
|
|
|
|
|
|
|
|
// last "real" character is not inside our current portion
|
|
|
|
// we have to check the script type of the last "real" character
|
|
|
|
if ( nLangIndex < rInf.GetIdx() )
|
|
|
|
{
|
2013-04-19 10:34:21 +02:00
|
|
|
sal_uInt16 nScript = g_pBreakIt->GetRealScriptOfText( rInf.GetTxt(),
|
2002-11-01 08:39:36 +00:00
|
|
|
nLangIndex );
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( nScript, "Script is not between 1 and 4" );
|
2002-11-01 08:39:36 +00:00
|
|
|
|
|
|
|
// compare current script with script from last "real" character
|
|
|
|
if ( nScript - 1 != rInf.GetFont()->GetActual() )
|
|
|
|
aLang = rInf.GetTxtFrm()->GetTxtNode()->GetLang(
|
|
|
|
CH_TXTATR_BREAKWORD == cFldChr ?
|
|
|
|
nDoNotStepOver :
|
|
|
|
nLangIndex, 0, nScript );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
const ForbiddenCharacters aForbidden(
|
2006-08-14 15:36:58 +00:00
|
|
|
*rInf.GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->getForbiddenCharacters( aLang, true ) );
|
2002-02-20 11:44:15 +00:00
|
|
|
|
2014-02-02 19:54:50 +01:00
|
|
|
const bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
|
2002-02-20 11:44:15 +00:00
|
|
|
! rPor.InFldGrp();
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
LineBreakUserOptions aUserOpt(
|
|
|
|
aForbidden.beginLine, aForbidden.endLine,
|
2014-02-02 19:54:50 +01:00
|
|
|
rInf.HasForbiddenChars(), bAllowHanging, false );
|
2002-02-19 12:45:46 +00:00
|
|
|
|
|
|
|
//! register listener to LinguServiceEvents now in order to get
|
|
|
|
//! notified about relevant changes in the future
|
|
|
|
SwModule *pModule = SW_MOD();
|
|
|
|
if (!pModule->GetLngSvcEvtListener().is())
|
|
|
|
pModule->CreateLngSvcEvtListener();
|
|
|
|
|
2002-08-19 14:02:46 +00:00
|
|
|
// !!! We must have a local copy of the locale, because inside
|
|
|
|
// getLineBreak the LinguEventListener can trigger a new formatting,
|
|
|
|
// which can corrupt the locale pointer inside pBreakIt.
|
2013-04-19 10:34:21 +02:00
|
|
|
const lang::Locale aLocale = g_pBreakIt->GetLocale( aLang );
|
2002-08-19 14:02:46 +00:00
|
|
|
|
2014-01-21 18:57:30 +02:00
|
|
|
// determines first possible line break from nCutPos to
|
2001-02-15 12:45:21 +00:00
|
|
|
// start index of current line
|
2013-04-19 10:34:21 +02:00
|
|
|
LineBreakResults aResult = g_pBreakIt->GetBreakIter()->getLineBreak(
|
2002-08-19 14:02:46 +00:00
|
|
|
rInf.GetTxt(), nCutPos, aLocale,
|
|
|
|
rInf.GetLineStart(), aHyphOpt, aUserOpt );
|
|
|
|
|
2014-01-14 16:50:42 +00:00
|
|
|
nBreakPos = aResult.breakIndex;
|
2001-03-13 09:12:19 +00:00
|
|
|
|
|
|
|
// if we are formatting multi portions we want to allow line breaks
|
|
|
|
// at the border between single line and multi line portion
|
2014-04-29 19:25:03 +00:00
|
|
|
// we have to be careful with footnote portions, they always come in
|
2001-04-18 11:26:13 +00:00
|
|
|
// with an index 0
|
2001-10-26 13:42:27 +00:00
|
|
|
if ( nBreakPos < rInf.GetLineStart() && rInf.IsFirstMulti() &&
|
2001-04-18 11:26:13 +00:00
|
|
|
! rInf.IsFtnInside() )
|
2001-03-13 09:12:19 +00:00
|
|
|
nBreakPos = rInf.GetLineStart();
|
|
|
|
|
|
|
|
nBreakStart = nBreakPos;
|
2001-02-15 12:45:21 +00:00
|
|
|
|
2001-04-18 11:26:13 +00:00
|
|
|
bHyph = BreakType::HYPHENATION == aResult.breakType;
|
2001-02-15 12:45:21 +00:00
|
|
|
|
2014-01-14 16:50:42 +00:00
|
|
|
if ( bHyph && nBreakPos != COMPLETE_STRING )
|
2001-02-15 12:45:21 +00:00
|
|
|
{
|
|
|
|
// found hyphenation position within line
|
|
|
|
// nBreakPos is set to the hyphenation position
|
|
|
|
xHyphWord = aResult.rHyphenatedWord;
|
2001-08-17 10:08:09 +00:00
|
|
|
nBreakPos += xHyphWord->getHyphenationPos() + 1;
|
2001-08-14 08:15:03 +00:00
|
|
|
|
2003-04-15 15:53:18 +00:00
|
|
|
#if OSL_DEBUG_LEVEL > 1
|
2001-08-14 08:15:03 +00:00
|
|
|
// e.g., Schif-fahrt, referes to our string
|
2013-10-15 17:36:59 +02:00
|
|
|
const OUString aWord = xHyphWord->getWord();
|
2001-08-14 08:15:03 +00:00
|
|
|
// e.g., Schiff-fahrt, referes to the word after hyphenation
|
2013-10-15 17:36:59 +02:00
|
|
|
const OUString aHyphenatedWord = xHyphWord->getHyphenatedWord();
|
2001-08-14 08:15:03 +00:00
|
|
|
// e.g., Schif-fahrt: 5, referes to our string
|
2011-01-17 15:06:54 +01:00
|
|
|
const sal_uInt16 nHyphenationPos = xHyphWord->getHyphenationPos();
|
2007-09-27 08:12:57 +00:00
|
|
|
(void)nHyphenationPos;
|
2001-08-14 08:15:03 +00:00
|
|
|
// e.g., Schiff-fahrt: 6, referes to the word after hyphenation
|
2011-01-17 15:06:54 +01:00
|
|
|
const sal_uInt16 nHyphenPos = xHyphWord->getHyphenPos();
|
2007-09-27 08:12:57 +00:00
|
|
|
(void)nHyphenPos;
|
2001-08-14 08:15:03 +00:00
|
|
|
#endif
|
|
|
|
|
2001-08-17 10:08:09 +00:00
|
|
|
// if not in interactive mode, we have to break behind a soft hyphen
|
|
|
|
if ( ! rInf.IsInterHyph() && rInf.GetIdx() )
|
|
|
|
{
|
|
|
|
const long nSoftHyphPos =
|
|
|
|
xHyphWord->getWord().indexOf( CHAR_SOFTHYPHEN );
|
2001-08-14 08:15:03 +00:00
|
|
|
|
2001-08-17 10:08:09 +00:00
|
|
|
if ( nSoftHyphPos >= 0 &&
|
|
|
|
nBreakStart + nSoftHyphPos <= nBreakPos &&
|
|
|
|
nBreakPos > rInf.GetLineStart() )
|
|
|
|
nBreakPos = rInf.GetIdx() - 1;
|
|
|
|
}
|
2001-08-14 08:15:03 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
if( nBreakPos >= rInf.GetIdx() )
|
2000-09-18 23:08:29 +00:00
|
|
|
{
|
2001-02-15 12:45:21 +00:00
|
|
|
nPorLen = nBreakPos - rInf.GetIdx();
|
2013-04-07 21:25:31 +02:00
|
|
|
if( '-' == rInf.GetTxt()[ nBreakPos - 1 ] )
|
2001-02-15 12:45:21 +00:00
|
|
|
xHyphWord = NULL;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
2001-02-15 12:45:21 +00:00
|
|
|
}
|
|
|
|
else if ( !bHyph && nBreakPos >= rInf.GetLineStart() )
|
|
|
|
{
|
2014-01-14 16:50:42 +00:00
|
|
|
OSL_ENSURE( nBreakPos != COMPLETE_STRING, "we should have found a break pos" );
|
2001-08-17 10:08:09 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
// found break position within line
|
|
|
|
xHyphWord = NULL;
|
2001-08-14 08:15:03 +00:00
|
|
|
|
|
|
|
// check, if break position is soft hyphen and an underflow
|
|
|
|
// has to be triggered
|
2001-08-17 10:08:09 +00:00
|
|
|
if( nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
|
2013-04-07 21:25:31 +02:00
|
|
|
CHAR_SOFTHYPHEN == rInf.GetTxt()[ nBreakPos - 1 ] )
|
2001-02-15 12:45:21 +00:00
|
|
|
nBreakPos = rInf.GetIdx() - 1;
|
2001-08-14 08:15:03 +00:00
|
|
|
|
2011-05-02 14:59:26 +02:00
|
|
|
const SvxAdjust& rAdjust = rInf.GetTxtFrm()->GetTxtNode()->GetSwAttrSet().GetAdjust().GetAdjust();
|
|
|
|
if( rAdjust != SVX_ADJUST_LEFT )
|
|
|
|
{
|
|
|
|
// Delete any blanks at the end of a line, but be careful:
|
|
|
|
// If a field has been expanded, we do not want to delete any
|
|
|
|
// blanks inside the field portion. This would cause an unwanted
|
|
|
|
// underflow
|
2014-01-14 16:50:42 +00:00
|
|
|
sal_Int32 nX = nBreakPos;
|
2011-05-02 14:59:26 +02:00
|
|
|
while( nX > rInf.GetLineStart() &&
|
|
|
|
( CH_TXTATR_BREAKWORD != cFldChr || nX > rInf.GetIdx() ) &&
|
|
|
|
( CH_BLANK == rInf.GetChar( --nX ) ||
|
|
|
|
CH_FULL_BLANK == rInf.GetChar( nX ) ) )
|
|
|
|
nBreakPos = nX;
|
|
|
|
}
|
2001-02-15 12:45:21 +00:00
|
|
|
if( nBreakPos > rInf.GetIdx() )
|
|
|
|
nPorLen = nBreakPos - rInf.GetIdx();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2014-01-14 16:50:42 +00:00
|
|
|
// no line break found, setting nBreakPos to COMPLETE_STRING
|
2001-02-15 12:45:21 +00:00
|
|
|
// causes a break cut
|
2014-01-14 16:50:42 +00:00
|
|
|
nBreakPos = COMPLETE_STRING;
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( nCutPos >= rInf.GetIdx(), "Deep cut" );
|
2001-02-15 12:45:21 +00:00
|
|
|
nPorLen = nCutPos - rInf.GetIdx();
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2014-01-14 16:50:42 +00:00
|
|
|
if( nBreakPos > nCutPos && nBreakPos != COMPLETE_STRING )
|
2001-02-15 12:45:21 +00:00
|
|
|
{
|
2014-01-14 16:50:42 +00:00
|
|
|
const sal_Int32 nHangingLen = nBreakPos - nCutPos;
|
2001-04-09 09:44:17 +00:00
|
|
|
SwPosSize aTmpSize = rInf.GetTxtSize( &rSI, nCutPos,
|
2002-02-20 11:44:15 +00:00
|
|
|
nHangingLen, 0 );
|
2013-08-21 13:17:07 +02:00
|
|
|
aTmpSize.Width(aTmpSize.Width() + nLeftRightBorderSpace);
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( !pHanging, "A hanging portion is hanging around" );
|
2001-02-15 12:45:21 +00:00
|
|
|
pHanging = new SwHangingPortion( aTmpSize );
|
2002-02-20 11:44:15 +00:00
|
|
|
pHanging->SetLen( nHangingLen );
|
2001-02-28 07:41:57 +00:00
|
|
|
nPorLen = nCutPos - rInf.GetIdx();
|
2001-02-15 12:45:21 +00:00
|
|
|
}
|
2001-10-26 13:42:27 +00:00
|
|
|
|
|
|
|
// If we expanded a field, we must repair the original string.
|
|
|
|
// In case we do not trigger an underflow, we correct the nBreakPos
|
|
|
|
// value, but we cannot correct the nBreakStart value:
|
|
|
|
// If we have found a hyphenation position, nBreakStart can lie before
|
|
|
|
// the field.
|
2001-12-20 10:54:36 +00:00
|
|
|
if ( CH_TXTATR_BREAKWORD == cFldChr )
|
2001-10-26 13:42:27 +00:00
|
|
|
{
|
|
|
|
if ( nBreakPos < rInf.GetIdx() )
|
|
|
|
nBreakPos = nOldIdx - 1;
|
2014-01-14 16:50:42 +00:00
|
|
|
else if ( COMPLETE_STRING != nBreakPos )
|
2001-10-26 13:42:27 +00:00
|
|
|
{
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( nBreakPos >= nFieldDiff, "I've got field trouble!" );
|
2007-09-27 08:12:57 +00:00
|
|
|
nBreakPos = nBreakPos - nFieldDiff;
|
2001-10-26 13:42:27 +00:00
|
|
|
}
|
|
|
|
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( nCutPos >= rInf.GetIdx() && nCutPos >= nFieldDiff,
|
2001-10-26 13:42:27 +00:00
|
|
|
"I've got field trouble, part2!" );
|
2007-09-27 08:12:57 +00:00
|
|
|
nCutPos = nCutPos - nFieldDiff;
|
2001-10-26 13:42:27 +00:00
|
|
|
|
2013-05-12 17:01:01 +02:00
|
|
|
OUString& rOldTxt = const_cast<OUString&> (rInf.GetTxt());
|
|
|
|
OUString aReplacement( cFldChr );
|
|
|
|
rOldTxt = rOldTxt.replaceAt( nOldIdx - 1, nFieldDiff + 1, aReplacement);
|
2001-10-26 13:42:27 +00:00
|
|
|
rInf.SetIdx( nOldIdx );
|
|
|
|
|
2011-11-24 00:52:07 +01:00
|
|
|
#if OSL_DEBUG_LEVEL > 0
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( aDebugString == rInf.GetTxt(),
|
2001-10-26 13:42:27 +00:00
|
|
|
"Somebody, somebody, somebody put something in my string" );
|
2002-11-05 08:05:03 +00:00
|
|
|
#endif
|
2001-10-26 13:42:27 +00:00
|
|
|
}
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
2000-11-21 10:36:49 +00:00
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
if( nPorLen )
|
2001-04-09 09:44:17 +00:00
|
|
|
{
|
|
|
|
rInf.GetTxtSize( &rSI, rInf.GetIdx(), nPorLen,
|
2013-08-21 11:50:31 +02:00
|
|
|
nMaxComp, nBreakWidth, nMaxSizeDiff );
|
2001-04-09 09:44:17 +00:00
|
|
|
|
|
|
|
// save maximum width for later use
|
|
|
|
if ( nMaxSizeDiff )
|
2014-09-03 08:35:32 +02:00
|
|
|
rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
|
2001-04-09 09:44:17 +00:00
|
|
|
|
2013-08-21 13:17:07 +02:00
|
|
|
nBreakWidth += nItalic + nLeftRightBorderSpace;
|
2001-04-09 09:44:17 +00:00
|
|
|
}
|
2001-02-15 12:45:21 +00:00
|
|
|
else
|
|
|
|
nBreakWidth = 0;
|
|
|
|
|
2000-11-21 10:36:49 +00:00
|
|
|
if( pHanging )
|
2001-02-28 07:41:57 +00:00
|
|
|
nBreakPos = nCutPos;
|
|
|
|
|
2014-02-02 19:54:50 +01:00
|
|
|
return false;
|
2000-09-18 23:08:29 +00:00
|
|
|
}
|
|
|
|
|
2001-02-15 12:45:21 +00:00
|
|
|
// returns true if word at position nPos has a diffenrent spelling
|
|
|
|
// if hyphenated at this position (old german spelling)
|
2012-12-05 08:33:07 +09:00
|
|
|
bool SwTxtGuess::AlternativeSpelling( const SwTxtFormatInfo &rInf,
|
2014-01-14 16:50:42 +00:00
|
|
|
const sal_Int32 nPos )
|
2001-02-15 12:45:21 +00:00
|
|
|
{
|
|
|
|
// get word boundaries
|
|
|
|
Boundary aBound =
|
2013-04-19 10:34:21 +02:00
|
|
|
g_pBreakIt->GetBreakIter()->getWordBoundary( rInf.GetTxt(), nPos,
|
|
|
|
g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
|
2014-02-02 19:54:50 +01:00
|
|
|
WordType::DICTIONARY_WORD, true );
|
2014-01-14 16:50:42 +00:00
|
|
|
nBreakStart = aBound.startPos;
|
2013-09-04 12:17:22 +01:00
|
|
|
sal_Int32 nWordLen = aBound.endPos - nBreakStart;
|
2001-02-15 12:45:21 +00:00
|
|
|
|
2001-03-15 14:58:37 +00:00
|
|
|
// if everything else fails, we want to cut at nPos
|
|
|
|
nCutPos = nPos;
|
|
|
|
|
2013-09-04 12:17:22 +01:00
|
|
|
OUString aTxt( rInf.GetTxt().copy( nBreakStart, nWordLen ) );
|
2001-02-15 12:45:21 +00:00
|
|
|
|
|
|
|
// check, if word has alternative spelling
|
|
|
|
Reference< XHyphenator > xHyph( ::GetHyphenator() );
|
2010-11-25 17:08:45 +01:00
|
|
|
OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
|
2001-02-15 12:45:21 +00:00
|
|
|
//! subtract 1 since the UNO-interface is 0 based
|
2013-09-04 12:17:22 +01:00
|
|
|
xHyphWord = xHyph->queryAlternativeSpelling( aTxt,
|
2013-04-19 10:34:21 +02:00
|
|
|
g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
|
2001-03-29 07:05:13 +00:00
|
|
|
nPos - nBreakStart, rInf.GetHyphValues() );
|
2001-02-15 12:45:21 +00:00
|
|
|
return xHyphWord.is() && xHyphWord->isAlternativeSpelling();
|
|
|
|
}
|
2000-09-18 23:08:29 +00:00
|
|
|
|
2010-10-14 08:30:41 +02:00
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|