Files
libreoffice/sw/source/core/text/guess.cxx

558 lines
21 KiB
C++
Raw Normal View History

/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
/*
* This file is part of the LibreOffice project.
2000-09-18 23:08:29 +00:00
*
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
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
*
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
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
*
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
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 .
*/
2000-09-18 23:08:29 +00:00
#include <ctype.h>
#include <editeng/unolingu.hxx>
#include <tools/shl.hxx> // needed for SW_MOD() macro
#include <dlelstnr.hxx>
#include <swmodule.hxx>
#include <IDocumentSettingAccess.hxx>
#include <guess.hxx>
#include <inftxt.hxx>
#include <pagefrm.hxx>
#include <pagedesc.hxx> // SwPageDesc
#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>
#include <unotools/charclass.hxx>
#include <porfld.hxx>
#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
#define CH_FULL_BLANK 0x3000
2000-09-18 23:08:29 +00:00
/*************************************************************************
* SwTxtGuess::Guess
*
2001-02-15 12:45:21 +00: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
2000-09-18 23:08:29 +00:00
*************************************************************************/
2001-04-09 09:44:17 +00:00
sal_Bool SwTxtGuess::Guess( const SwTxtPortion& rPor, SwTxtFormatInfo &rInf,
const KSHORT 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
// Empty strings are always 0
if( !rInf.GetLen() || rInf.GetTxt().isEmpty() )
2000-09-18 23:08:29 +00:00
return sal_False;
OSL_ENSURE( rInf.GetIdx() < rInf.GetTxt().getLength(),
2000-09-18 23:08:29 +00:00
"+SwTxtGuess::Guess: invalid SwTxtFormatInfo" );
OSL_ENSURE( nPorHeight, "+SwTxtGuess::Guess: no height" );
sal_uInt16 nMinSize;
sal_uInt16 nMaxSizeDiff;
2001-04-09 09:44:17 +00:00
const SwScriptInfo& rSI =
((SwParaPortion*)rInf.GetParaPortion())->GetScriptInfo();
sal_uInt16 nMaxComp = ( SW_CJK == rInf.GetFont()->GetActual() ) &&
2001-04-09 09:44:17 +00:00
rSI.CountCompChg() &&
! rInf.IsMulti() &&
! rPor.InFldGrp() &&
! rPor.IsDropPortion() ?
2001-04-09 09:44:17 +00:00
10000 :
0 ;
2000-09-18 23:08:29 +00:00
SwTwips nLineWidth = rInf.Width() - rInf.X();
sal_Int32 nMaxLen = rInf.GetTxt().getLength() - rInf.GetIdx();
if ( rInf.GetLen() < nMaxLen )
nMaxLen = rInf.GetLen();
if( !nMaxLen )
2000-09-18 23:08:29 +00:00
return sal_False;
KSHORT nItalic = 0;
if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
{
bool bAddItalic = true;
// do not add extra italic value if we have an active character grid
if ( rInf.SnapToGrid() )
{
GETGRID( rInf.GetTxtFrm()->FindPageFrm() )
bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
}
// do not add extra italic value for an isolated blank:
if ( 1 == rInf.GetLen() &&
CH_BLANK == rInf.GetTxt()[ rInf.GetIdx() ] )
bAddItalic = false;
nItalic = bAddItalic ? nPorHeight / 12 : 0;
nLineWidth -= nItalic;
// #i46524# LineBreak bug with italics
if ( nLineWidth < 0 ) nLineWidth = 0;
2000-09-18 23:08:29 +00: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
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,
nMaxComp, nMinSize, nMaxSizeDiff );
nBreakWidth = nMinSize;
2000-09-18 23:08:29 +00: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
nCutPos = rInf.GetIdx() + nMaxLen;
if( nItalic &&
( nCutPos >= rInf.GetTxt().getLength() ||
// #i48035# Needed for CalcFitToContent
// if first line ends with a manual line break
rInf.GetTxt()[ nCutPos ] == CH_BREAK ) )
nBreakWidth = nBreakWidth + nItalic;
2001-04-09 09:44:17 +00:00
// save maximum width for later use
if ( nMaxSizeDiff )
rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
2001-04-09 09:44:17 +00:00
2000-09-18 23:08:29 +00:00
return sal_True;
}
}
bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
2000-09-18 23:08:29 +00:00
xub_StrLen nHyphPos = 0;
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-04-09 09:44:17 +00:00
nCutPos = rInf.GetTxtBreak( nLineWidth, nMaxLen, nMaxComp );
#if OSL_DEBUG_LEVEL > 1
2001-04-09 09:44:17 +00:00
if ( STRING_LEN != nCutPos )
{
rInf.GetTxtSize( &rSI, rInf.GetIdx(), nCutPos - rInf.GetIdx(),
nMaxComp, nMinSize, nMaxSizeDiff );
OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
2001-04-09 09:44:17 +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,
nMinSize, nMaxSizeDiff );
nBreakWidth = nMinSize;
// The following comparison should always give sal_True, otherwise
// 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
{
if( nItalic && ( nBreakPos + 1 ) >= rInf.GetTxt().getLength() )
nBreakWidth = nBreakWidth + nItalic;
2001-04-09 09:44:17 +00:00
// save maximum width for later use
if ( nMaxSizeDiff )
rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
2001-04-09 09:44:17 +00:00
2000-09-18 23:08:29 +00:00
return sal_True;
}
}
// 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();
return sal_False;
}
2001-02-15 12:45:21 +00:00
xub_StrLen nPorLen = 0;
// do not call the break iterator nCutPos is a blank
sal_Unicode cCutChar = rInf.GetTxt()[ nCutPos ];
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;
xub_StrLen nX = nBreakPos;
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
while( nX && nBreakPos > rInf.GetTxt().getLength() &&
( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
CH_FULL_BLANK == cCutChar ) )
--nBreakPos;
}
re-base on ALv2 code. Includes: Patches contributed by Oliver-Rainer Wittmann sw34bf06: #i117783# - Writer's implementation of XPagePrintable - apply print settings to new printing routines http://svn.apache.org/viewvc?view=revision&revision=1172115 sw34bf06: #o12311627# use <rtl_random> methods to create unique ids for list styles and list ids http://svn.apache.org/viewvc?view=revision&revision=1172112 sw34bf06 #i114725#,#i115828# - method <SwDoc::ClearDoc()> - clear list structures completely http://svn.apache.org/viewvc?view=revision&revision=1172122 i#118572 - remove ui string and help content regarding usage of Java Mail in Writer's Mail Merge as Java Mail is not used. http://svn.apache.org/viewvc?view=revision&revision=1197035 Patches contributed by Mathias Bauer cws mba34issues01: #i117718#: provide filter name in case storage of medium does not allow to detect one http://svn.apache.org/viewvc?view=revision&revision=1172350 cws mba34issues01: #i117721#: directly provide parameters retrieved from SfxMedium http://svn.apache.org/viewvc?view=revision&revision=1172353 gnumake4 work variously http://svn.apache.org/viewvc?view=revision&revision=1394707 http://svn.apache.org/viewvc?view=revision&revision=1394326 http://svn.apache.org/viewvc?view=revision&revision=1396797 http://svn.apache.org/viewvc?view=revision&revision=1397315 cws mba34issues01: #i117723#: convert assertion into trace http://svn.apache.org/viewvc?view=revision&revision=1172355 cws mba34issues01: #i117699#: keep layout alive until swdoc dies http://svn.apache.org/viewvc?view=revision&revision=1172362 cws mba34issues01: #i117943#: missing color attributes in RTF clipboard http://svn.apache.org/viewvc?view=revision&revision=1172363 Patch contributed by Henning Brinkmann imported patch i#103878 http://svn.apache.org/viewvc?view=revision&revision=1172109 Patches contributed by Michael Stahl sw34bf06: #i117955#: WW8 export: disable storing of section breaks in endnotes http://svn.apache.org/viewvc?view=revision&revision=1172119 Patch contributed by imacat Fixed the Asian language work count. http://svn.apache.org/viewvc?view=revision&revision=1241345 Patch contributed by Pedro Giffuni i#20878 - Add comment with BZ issue for reference. http://svn.apache.org/viewvc?view=revision&revision=1244517 Patch contributed by Andre Fischer Do not add targets for junit tests when junit is disabled. http://svn.apache.org/viewvc?view=revision&revision=1241508 add writerperfect dependency.
2011-03-31 10:05:04 +02:00
else // #i20878#
{
while( nX && nBreakPos > rInf.GetLineStart() + 1 &&
( CH_BLANK == ( cCutChar = rInf.GetChar( --nX ) ) ||
CH_FULL_BLANK == cCutChar ) )
--nBreakPos;
}
2001-02-15 12:45:21 +00:00
if( nBreakPos > rInf.GetIdx() )
nPorLen = nBreakPos - rInf.GetIdx();
while( ++nCutPos < rInf.GetTxt().getLength() &&
( 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
}
CWS-TOOLING: integrate CWS oj18 2009-08-21 15:08:49 +0200 oj r275263 : wrong check 2009-08-21 08:56:01 +0200 oj r275215 : missing not 2009-08-20 07:27:13 +0200 oj r275164 : use new method from global 2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale 2009-08-18 10:39:32 +0200 oj r275082 : missing header include 2009-08-18 10:09:44 +0200 oj r275081 : new methods at global 2009-08-18 10:09:00 +0200 oj r275080 : unused var 2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml 2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55) 2009-08-17 13:29:44 +0200 oj r275047 : compile error 2009-08-17 13:27:47 +0200 oj r275045 : compile error 2009-08-17 11:44:54 +0200 oj r275040 : add dep 2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl 2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl 2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code 2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand 2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char 2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator 2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc 2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled 2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger 2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand 2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand 2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl 2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
2009-09-08 04:57:32 +00:00
else if( pBreakIt->GetBreakIter().is() )
2000-09-18 23:08:29 +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.
xub_StrLen nOldIdx = rInf.GetIdx();
sal_Unicode cFldChr = 0;
#if OSL_DEBUG_LEVEL > 0
OUString aDebugString;
#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() &&
CH_TXTATR_BREAKWORD ==
( cFldChr = rInf.GetTxt()[ rInf.GetIdx() - 1 ] ) )
{
SwFldPortion* pFld = (SwFldPortion*)rInf.GetLast();
OUString aTxt;
pFld->GetExpTxt( rInf, aTxt );
if ( !aTxt.isEmpty() )
{
nFieldDiff = aTxt.getLength() - 1;
nCutPos = nCutPos + nFieldDiff;
nHyphPos = nHyphPos + nFieldDiff;
#if OSL_DEBUG_LEVEL > 0
aDebugString = rInf.GetTxt();
#endif
OUString rOldTxt = rInf.GetTxt();
rOldTxt = rOldTxt.replaceAt( rInf.GetIdx() - 1, 1, aTxt );
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();
aHyphOpt = LineBreakHyphenationOptions( xHyph,
rInf.GetHyphValues(), nHyphPos );
2001-02-15 12:45:21 +00:00
}
2000-11-21 10:36:49 +00:00
// Get Language for break iterator.
// 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.
// NEVER call GetLang if the string has been modified!!!
LanguageType aLang = rInf.GetFont()->GetLanguage();
// If we are inside a field portion, we use a temporary string which
// 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
xub_StrLen nLangIndex = nCutPos;
// 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).
const xub_StrLen nDoNotStepOver = CH_TXTATR_BREAKWORD == cFldChr ?
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() )
{
sal_uInt16 nScript = pBreakIt->GetRealScriptOfText( rInf.GetTxt(),
nLangIndex );
OSL_ENSURE( nScript, "Script is not between 1 and 4" );
// 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(
*rInf.GetTxtFrm()->GetNode()->getIDocumentSettingAccess()->getForbiddenCharacters( aLang, true ) );
const sal_Bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
! rPor.InFldGrp();
2001-02-15 12:45:21 +00:00
LineBreakUserOptions aUserOpt(
aForbidden.beginLine, aForbidden.endLine,
rInf.HasForbiddenChars(), bAllowHanging, sal_False );
//! 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();
// !!! 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.
const lang::Locale aLocale = pBreakIt->GetLocale( aLang );
2001-02-15 12:45:21 +00:00
// determines first possible line break from nRightPos to
// start index of current line
CWS-TOOLING: integrate CWS oj18 2009-08-21 15:08:49 +0200 oj r275263 : wrong check 2009-08-21 08:56:01 +0200 oj r275215 : missing not 2009-08-20 07:27:13 +0200 oj r275164 : use new method from global 2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale 2009-08-18 10:39:32 +0200 oj r275082 : missing header include 2009-08-18 10:09:44 +0200 oj r275081 : new methods at global 2009-08-18 10:09:00 +0200 oj r275080 : unused var 2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml 2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55) 2009-08-17 13:29:44 +0200 oj r275047 : compile error 2009-08-17 13:27:47 +0200 oj r275045 : compile error 2009-08-17 11:44:54 +0200 oj r275040 : add dep 2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl 2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl 2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code 2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand 2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char 2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator 2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc 2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled 2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger 2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand 2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand 2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl 2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
2009-09-08 04:57:32 +00:00
LineBreakResults aResult = pBreakIt->GetBreakIter()->getLineBreak(
rInf.GetTxt(), nCutPos, aLocale,
rInf.GetLineStart(), aHyphOpt, aUserOpt );
2001-03-13 09:12:19 +00:00
nBreakPos = (xub_StrLen)aResult.breakIndex;
// if we are formatting multi portions we want to allow line breaks
// at the border between single line and multi line portion
2001-04-18 11:26:13 +00:00
// we have to be carefull with footnote portions, they always come in
// with an index 0
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
if ( bHyph && nBreakPos != STRING_LEN)
{
// found hyphenation position within line
// nBreakPos is set to the hyphenation position
xHyphWord = aResult.rHyphenatedWord;
nBreakPos += xHyphWord->getHyphenationPos() + 1;
#if OSL_DEBUG_LEVEL > 1
// e.g., Schif-fahrt, referes to our string
const String aWord = xHyphWord->getWord();
// e.g., Schiff-fahrt, referes to the word after hyphenation
const String aHyphenatedWord = xHyphWord->getHyphenatedWord();
// e.g., Schif-fahrt: 5, referes to our string
const sal_uInt16 nHyphenationPos = xHyphWord->getHyphenationPos();
(void)nHyphenationPos;
// e.g., Schiff-fahrt: 6, referes to the word after hyphenation
const sal_uInt16 nHyphenPos = xHyphWord->getHyphenPos();
(void)nHyphenPos;
#endif
// 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 );
if ( nSoftHyphPos >= 0 &&
nBreakStart + nSoftHyphPos <= nBreakPos &&
nBreakPos > rInf.GetLineStart() )
nBreakPos = rInf.GetIdx() - 1;
}
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();
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() )
{
OSL_ENSURE( nBreakPos != STRING_LEN, "we should have found a break pos" );
2001-02-15 12:45:21 +00:00
// found break position within line
xHyphWord = NULL;
// check, if break position is soft hyphen and an underflow
// has to be triggered
if( nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
CHAR_SOFTHYPHEN == rInf.GetTxt()[ nBreakPos - 1 ] )
2001-02-15 12:45:21 +00:00
nBreakPos = rInf.GetIdx() - 1;
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
xub_StrLen nX = nBreakPos;
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
{
// no line break found, setting nBreakPos to STRING_LEN
// causes a break cut
nBreakPos = STRING_LEN;
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
}
2001-02-15 12:45:21 +00:00
if( nBreakPos > nCutPos && nBreakPos != STRING_LEN )
{
const xub_StrLen nHangingLen = nBreakPos - nCutPos;
2001-04-09 09:44:17 +00:00
SwPosSize aTmpSize = rInf.GetTxtSize( &rSI, nCutPos,
nHangingLen, 0 );
OSL_ENSURE( !pHanging, "A hanging portion is hanging around" );
2001-02-15 12:45:21 +00:00
pHanging = new SwHangingPortion( aTmpSize );
pHanging->SetLen( nHangingLen );
2001-02-28 07:41:57 +00:00
nPorLen = nCutPos - rInf.GetIdx();
2001-02-15 12:45:21 +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.
if ( CH_TXTATR_BREAKWORD == cFldChr )
{
if ( nBreakPos < rInf.GetIdx() )
nBreakPos = nOldIdx - 1;
else if ( STRING_LEN != nBreakPos )
{
OSL_ENSURE( nBreakPos >= nFieldDiff, "I've got field trouble!" );
nBreakPos = nBreakPos - nFieldDiff;
}
OSL_ENSURE( nCutPos >= rInf.GetIdx() && nCutPos >= nFieldDiff,
"I've got field trouble, part2!" );
nCutPos = nCutPos - nFieldDiff;
XubString& rOldTxt = (XubString&)rInf.GetTxt();
rOldTxt.Erase( nOldIdx - 1, nFieldDiff + 1 );
rOldTxt.Insert( cFldChr, nOldIdx - 1 );
rInf.SetIdx( nOldIdx );
#if OSL_DEBUG_LEVEL > 0
OSL_ENSURE( aDebugString == rInf.GetTxt(),
"Somebody, somebody, somebody put something in my string" );
#endif
}
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,
nMaxComp, nMinSize, nMaxSizeDiff );
// save maximum width for later use
if ( nMaxSizeDiff )
rInf.SetMaxWidthDiff( (sal_uLong)&rPor, nMaxSizeDiff );
2001-04-09 09:44:17 +00:00
nBreakWidth = nItalic + nMinSize;
}
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;
2000-09-18 23:08:29 +00:00
return sal_False;
}
2001-02-15 12:45:21 +00:00
/*************************************************************************
* SwTxtGuess::AlternativeSpelling
*************************************************************************/
// returns true if word at position nPos has a diffenrent spelling
// if hyphenated at this position (old german spelling)
bool SwTxtGuess::AlternativeSpelling( const SwTxtFormatInfo &rInf,
2001-02-15 12:45:21 +00:00
const xub_StrLen nPos )
{
// get word boundaries
xub_StrLen nWordLen;
Boundary aBound =
CWS-TOOLING: integrate CWS oj18 2009-08-21 15:08:49 +0200 oj r275263 : wrong check 2009-08-21 08:56:01 +0200 oj r275215 : missing not 2009-08-20 07:27:13 +0200 oj r275164 : use new method from global 2009-08-19 10:22:35 +0200 oj r275138 : call GetLocale instead of pLocale 2009-08-18 10:39:32 +0200 oj r275082 : missing header include 2009-08-18 10:09:44 +0200 oj r275081 : new methods at global 2009-08-18 10:09:00 +0200 oj r275080 : unused var 2009-08-18 08:59:04 +0200 oj r275078 : move files from classes to xml 2009-08-17 14:58:16 +0200 oj r275056 : CWS-TOOLING: rebase CWS oj18 to trunk@275001 (milestone: DEV300:m55) 2009-08-17 13:29:44 +0200 oj r275047 : compile error 2009-08-17 13:27:47 +0200 oj r275045 : compile error 2009-08-17 11:44:54 +0200 oj r275040 : add dep 2009-07-22 14:26:05 +0200 oj r274240 : move unused services into fwl 2009-07-22 14:25:35 +0200 oj r274239 : move unused services into fwl 2009-07-22 13:47:45 +0200 oj r274233 : remove some unused code 2009-07-22 09:06:20 +0200 oj r274219 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 08:48:58 +0200 oj r274218 : create NumberFormatter on demand 2009-07-22 08:39:23 +0200 oj r274217 : change char to sal_Char 2009-07-22 07:33:34 +0200 oj r274214 : export dbtoolsclient dbcharsethelper for sc 2009-07-22 07:30:04 +0200 oj r274213 : late init of numberformatter and breakiterator 2009-07-22 07:28:55 +0200 oj r274212 : export dbtoolsclient dbcharsethelper for sc 2009-07-21 13:43:28 +0200 oj r274196 : check if quick start is enbaled 2009-07-21 13:40:09 +0200 oj r274195 : check config entry for UiEventsLogger 2009-07-21 13:37:40 +0200 oj r274194 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:35:38 +0200 oj r274193 : code refactoring, remove of duplicate code and some late inits and removale of not needed files 2009-07-21 13:33:41 +0200 oj r274192 : doc meta data will now be created on demand 2009-07-21 13:13:40 +0200 oj r274187 : load ldap functions on demand 2009-07-21 13:03:17 +0200 oj r274183 : late init of TransliterationImpl 2009-07-21 12:36:10 +0200 oj r274180 : late init of charClass
2009-09-08 04:57:32 +00:00
pBreakIt->GetBreakIter()->getWordBoundary( rInf.GetTxt(), nPos,
2001-02-15 12:45:21 +00:00
pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
WordType::DICTIONARY_WORD, sal_True );
nBreakStart = (xub_StrLen)aBound.startPos;
nWordLen = static_cast<xub_StrLen>(aBound.endPos - nBreakStart);
2001-02-15 12:45:21 +00:00
// if everything else fails, we want to cut at nPos
nCutPos = nPos;
XubString aTxt( rInf.GetTxt().copy( nBreakStart, nWordLen ) );
2001-02-15 12:45:21 +00:00
// check, if word has alternative spelling
Reference< XHyphenator > xHyph( ::GetHyphenator() );
OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
2001-02-15 12:45:21 +00:00
//! subtract 1 since the UNO-interface is 0 based
xHyphWord = xHyph->queryAlternativeSpelling( OUString(aTxt),
pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
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
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */