1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
* This file is part of the LibreOffice project.
*
* 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/.
*
* This file incorporates work covered by the following license notice:
*
* 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 .
*/
#include <editeng/unolingu.hxx>
#include <breakit.hxx>
#include <IDocumentSettingAccess.hxx>
#include "guess.hxx"
#include "inftxt.hxx"
#include <pagefrm.hxx>
#include <tgrditem.hxx>
#include <com/sun/star/i18n/BreakType.hpp>
#include <com/sun/star/i18n/WordType.hpp>
#include <com/sun/star/i18n/XBreakIterator.hpp>
#include <unotools/charclass.hxx>
#include "porfld.hxx"
#include <paratr.hxx>
#include <doc.hxx>
using namespace ::com::sun::star;
using namespace ::com::sun::star::uno;
using namespace ::com::sun::star::i18n;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::linguistic2;
namespace{
bool IsBlank(sal_Unicode ch) { return ch == CH_BLANK || ch == CH_FULL_BLANK || ch == CH_NB_SPACE || ch == CH_SIX_PER_EM; }
}
// provides information for line break calculation
// returns true if no line break has to be performed
// otherwise possible break or hyphenation position is determined
bool SwTextGuess::Guess( const SwTextPortion& rPor, SwTextFormatInfo &rInf,
const sal_uInt16 nPorHeight )
{
nCutPos = rInf.GetIdx();
// Empty strings are always 0
if( !rInf.GetLen() || rInf.GetText().isEmpty() )
return false;
OSL_ENSURE( rInf.GetIdx() < TextFrameIndex(rInf.GetText().getLength()),
"+SwTextGuess::Guess: invalid SwTextFormatInfo" );
OSL_ENSURE( nPorHeight, "+SwTextGuess::Guess: no height" );
sal_uInt16 nMaxSizeDiff;
const SwScriptInfo& rSI = rInf.GetParaPortion()->GetScriptInfo();
sal_uInt16 nMaxComp = ( SwFontScript::CJK == rInf.GetFont()->GetActual() ) &&
rSI.CountCompChg() &&
! rInf.IsMulti() &&
! rPor.InFieldGrp() &&
! rPor.IsDropPortion() ?
10000 :
0 ;
SwTwips nLineWidth = rInf.GetLineWidth();
TextFrameIndex nMaxLen = TextFrameIndex(rInf.GetText().getLength()) - rInf.GetIdx();
const SvxAdjust& rAdjust = rInf.GetTextFrame()->GetTextNodeForParaProps()->GetSwAttrSet().GetAdjust().GetAdjust();
// tdf#104668 space chars at the end should be cut if the compatibility option is enabled
// for LTR mode only
if ( !rInf.GetTextFrame()->IsRightToLeft() )
{
if (rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(
DocumentSettingId::MS_WORD_COMP_TRAILING_BLANKS))
{
if ( rAdjust == SvxAdjust::Right || rAdjust == SvxAdjust::Center )
{
TextFrameIndex nSpaceCnt(0);
for (sal_Int32 i = rInf.GetText().getLength() - 1;
sal_Int32(rInf.GetIdx()) <= i; --i)
{
sal_Unicode cChar = rInf.GetText()[i];
if ( cChar != CH_BLANK && cChar != CH_FULL_BLANK && cChar != CH_SIX_PER_EM )
break;
++nSpaceCnt;
}
TextFrameIndex nCharsCnt = nMaxLen - nSpaceCnt;
if ( nSpaceCnt && nCharsCnt < rPor.GetLen() )
{
nMaxLen = nCharsCnt;
if ( !nMaxLen )
return true;
}
}
}
}
if ( rInf.GetLen() < nMaxLen )
nMaxLen = rInf.GetLen();
if( !nMaxLen )
return false;
sal_uInt16 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() )
{
SwTextGridItem const*const pGrid(
GetGridItem(rInf.GetTextFrame()->FindPageFrame()));
bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
}
// do not add extra italic value for an isolated blank:
if (TextFrameIndex(1) == rInf.GetLen() &&
CH_BLANK == rInf.GetText()[sal_Int32(rInf.GetIdx())])
{
bAddItalic = false;
}
if (rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess().get(
DocumentSettingId::TAB_OVER_MARGIN))
{
// Content is allowed over the margin: in this case over-margin content caused by italic
// formatting is OK.
bAddItalic = false;
}
nItalic = bAddItalic ? nPorHeight / 12 : 0;
nLineWidth -= nItalic;
// #i46524# LineBreak bug with italics
if ( nLineWidth < 0 ) nLineWidth = 0;
}
const sal_Int32 nLeftRightBorderSpace =
(!rPor.GetJoinBorderWithNext() ? rInf.GetFont()->GetRightBorderSpace() : 0) +
(!rPor.GetJoinBorderWithPrev() ? rInf.GetFont()->GetLeftBorderSpace() : 0);
nLineWidth -= nLeftRightBorderSpace;
const bool bUnbreakableNumberings = rInf.GetTextFrame()->GetDoc()
.getIDocumentSettingAccess().get(DocumentSettingId::UNBREAKABLE_NUMBERINGS);
// first check if everything fits to line
if ( ( nLineWidth * 2 > SwTwips(sal_Int32(nMaxLen)) * nPorHeight ) ||
( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
{
// call GetTextSize with maximum compression (for kanas)
rInf.GetTextSize( &rSI, rInf.GetIdx(), nMaxLen,
nMaxComp, nBreakWidth, nMaxSizeDiff );
if ( ( nBreakWidth <= nLineWidth ) || ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
{
// portion fits to line
nCutPos = rInf.GetIdx() + nMaxLen;
if( nItalic &&
(nCutPos >= TextFrameIndex(rInf.GetText().getLength()) ||
// #i48035# Needed for CalcFitToContent
// if first line ends with a manual line break
rInf.GetText()[sal_Int32(nCutPos)] == CH_BREAK))
nBreakWidth = nBreakWidth + nItalic;
// save maximum width for later use
if ( nMaxSizeDiff )
rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
nBreakWidth += nLeftRightBorderSpace;
return true;
}
}
bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
TextFrameIndex nHyphPos(0);
// 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
if( bHyph )
{
nCutPos = rInf.GetTextBreak( nLineWidth, nMaxLen, nMaxComp, nHyphPos, rInf.GetCachedVclData().get() );
if ( !nHyphPos && rInf.GetIdx() )
nHyphPos = rInf.GetIdx() - TextFrameIndex(1);
}
else
{
nCutPos = rInf.GetTextBreak( nLineWidth, nMaxLen, nMaxComp, rInf.GetCachedVclData().get() );
#if OSL_DEBUG_LEVEL > 1
if ( TextFrameIndex(COMPLETE_STRING) != nCutPos )
{
sal_uInt16 nMinSize;
rInf.GetTextSize( &rSI, rInf.GetIdx(), nCutPos - rInf.GetIdx(),
nMaxComp, nMinSize, nMaxSizeDiff );
OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
}
#endif
}
if( nCutPos > rInf.GetIdx() + nMaxLen )
{
// second check if everything fits to line
nCutPos = nBreakPos = rInf.GetIdx() + nMaxLen - TextFrameIndex(1);
rInf.GetTextSize( &rSI, rInf.GetIdx(), nMaxLen, nMaxComp,
nBreakWidth, nMaxSizeDiff );
// The following comparison should always give true, otherwise
// there likely has been a pixel rounding error in GetTextBreak
if ( nBreakWidth <= nLineWidth )
{
if (nItalic && (nBreakPos + TextFrameIndex(1)) >= TextFrameIndex(rInf.GetText().getLength()))
nBreakWidth = nBreakWidth + nItalic;
// save maximum width for later use
if ( nMaxSizeDiff )
rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
nBreakWidth += nLeftRightBorderSpace;
return true;
}
}
// we have to trigger an underflow for a footnote portion
// which does not fit to the current line
if ( rPor.IsFootnotePortion() )
{
nBreakPos = rInf.GetIdx();
nCutPos = TextFrameIndex(-1);
return false;
}
TextFrameIndex nPorLen(0);
// do not call the break iterator nCutPos is a blank
sal_Unicode cCutChar = nCutPos < TextFrameIndex(rInf.GetText().getLength())
? rInf.GetText()[sal_Int32(nCutPos)]
: 0;
if (IsBlank(cCutChar))
{
nBreakPos = nCutPos;
TextFrameIndex nX = nBreakPos;
if ( rAdjust == SvxAdjust::Left )
{
// we step back until a non blank character has been found
// or there is only one more character left
while (nX && TextFrameIndex(rInf.GetText().getLength()) < nBreakPos &&
IsBlank(rInf.GetChar(--nX)))
--nBreakPos;
}
else // #i20878#
{
while (nX && nBreakPos > rInf.GetLineStart() + TextFrameIndex(1) &&
IsBlank(rInf.GetChar(--nX)))
--nBreakPos;
}
if( nBreakPos > rInf.GetIdx() )
nPorLen = nBreakPos - rInf.GetIdx();
while (++nCutPos < TextFrameIndex(rInf.GetText().getLength()) &&
IsBlank(rInf.GetChar(nCutPos)))
; // nothing
nBreakStart = nCutPos;
}
else
{
// 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.
TextFrameIndex nOldIdx = rInf.GetIdx();
sal_Unicode cFieldChr = 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()->InFieldGrp() &&
! rInf.GetLast()->IsFootnotePortion() &&
rInf.GetIdx() > rInf.GetLineStart() &&
CH_TXTATR_BREAKWORD ==
(cFieldChr = rInf.GetText()[sal_Int32(rInf.GetIdx()) - 1]))
{
SwFieldPortion* pField = static_cast<SwFieldPortion*>(rInf.GetLast());
OUString aText;
pField->GetExpText( rInf, aText );
if ( !aText.isEmpty() )
{
nFieldDiff = TextFrameIndex(aText.getLength() - 1);
nCutPos = nCutPos + nFieldDiff;
nHyphPos = nHyphPos + nFieldDiff;
#if OSL_DEBUG_LEVEL > 0
aDebugString = rInf.GetText();
#endif
// this is pretty nutso... reverted at the end...
OUString& rOldText = const_cast<OUString&> (rInf.GetText());
rOldText = rOldText.replaceAt(sal_Int32(rInf.GetIdx()) - 1, 1, aText);
rInf.SetIdx( rInf.GetIdx() + nFieldDiff );
}
else
cFieldChr = 0;
}
LineBreakHyphenationOptions aHyphOpt;
Reference< XHyphenator > xHyph;
if( bHyph )
{
xHyph = ::GetHyphenator();
aHyphOpt = LineBreakHyphenationOptions( xHyph,
rInf.GetHyphValues(), sal_Int32(nHyphPos));
}
// 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.InFieldGrp() )
{
const CharClass& rCC = GetAppCharClass();
// step back until a non-punctuation character is reached
TextFrameIndex 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 TextFrameIndex nDoNotStepOver = CH_TXTATR_BREAKWORD == cFieldChr
? rInf.GetIdx() - nFieldDiff - TextFrameIndex(1)
: TextFrameIndex(0);
if ( nLangIndex > nDoNotStepOver &&
TextFrameIndex(rInf.GetText().getLength()) == nLangIndex)
--nLangIndex;
while ( nLangIndex > nDoNotStepOver &&
!rCC.isLetterNumeric(rInf.GetText(), sal_Int32(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 = g_pBreakIt->GetRealScriptOfText( rInf.GetText(),
sal_Int32(nLangIndex));
OSL_ENSURE( nScript, "Script is not between 1 and 4" );
// compare current script with script from last "real" character
if ( SwFontScript(nScript - 1) != rInf.GetFont()->GetActual() )
{
aLang = rInf.GetTextFrame()->GetLangOfChar(
CH_TXTATR_BREAKWORD == cFieldChr
? nDoNotStepOver
: nLangIndex,
nScript, true);
}
}
}
const ForbiddenCharacters aForbidden(
*rInf.GetTextFrame()->GetDoc().getIDocumentSettingAccess().getForbiddenCharacters(aLang, true));
const bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
! rInf.GetTextFrame()->IsInTab() &&
! rPor.InFieldGrp();
LineBreakUserOptions aUserOpt(
aForbidden.beginLine, aForbidden.endLine,
rInf.HasForbiddenChars(), bAllowHanging, false );
// !!! 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 = g_pBreakIt->GetLocale( aLang );
// determines first possible line break from nCutPos to
// start index of current line
LineBreakResults aResult = g_pBreakIt->GetBreakIter()->getLineBreak(
rInf.GetText(), sal_Int32(nCutPos), aLocale,
sal_Int32(rInf.GetLineStart()), aHyphOpt, aUserOpt );
nBreakPos = TextFrameIndex(aResult.breakIndex);
// if we are formatting multi portions we want to allow line breaks
// at the border between single line and multi line portion
// we have to be careful with footnote portions, they always come in
// with an index 0
if ( nBreakPos < rInf.GetLineStart() && rInf.IsFirstMulti() &&
! rInf.IsFootnoteInside() )
nBreakPos = rInf.GetLineStart();
nBreakStart = nBreakPos;
bHyph = BreakType::HYPHENATION == aResult.breakType;
if (bHyph && nBreakPos != TextFrameIndex(COMPLETE_STRING))
{
// found hyphenation position within line
// nBreakPos is set to the hyphenation position
xHyphWord = aResult.rHyphenatedWord;
nBreakPos += TextFrameIndex(xHyphWord->getHyphenationPos() + 1);
// if not in interactive mode, we have to break behind a soft hyphen
if ( ! rInf.IsInterHyph() && rInf.GetIdx() )
{
sal_Int32 const nSoftHyphPos =
xHyphWord->getWord().indexOf( CHAR_SOFTHYPHEN );
if ( nSoftHyphPos >= 0 &&
nBreakStart + TextFrameIndex(nSoftHyphPos) <= nBreakPos &&
nBreakPos > rInf.GetLineStart() )
nBreakPos = rInf.GetIdx() - TextFrameIndex(1);
}
if( nBreakPos >= rInf.GetIdx() )
{
nPorLen = nBreakPos - rInf.GetIdx();
if ('-' == rInf.GetText()[ sal_Int32(nBreakPos) - 1 ])
xHyphWord = nullptr;
}
}
else if ( !bHyph && nBreakPos >= rInf.GetLineStart() )
{
OSL_ENSURE(sal_Int32(nBreakPos) != COMPLETE_STRING, "we should have found a break pos");
// found break position within line
xHyphWord = nullptr;
// check, if break position is soft hyphen and an underflow
// has to be triggered
if( nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
CHAR_SOFTHYPHEN == rInf.GetText()[ sal_Int32(nBreakPos) - 1 ])
{
nBreakPos = rInf.GetIdx() - TextFrameIndex(1);
}
if( rAdjust != SvxAdjust::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
TextFrameIndex nX = nBreakPos;
while( nX > rInf.GetLineStart() &&
( CH_TXTATR_BREAKWORD != cFieldChr || nX > rInf.GetIdx() ) &&
( CH_BLANK == rInf.GetChar( --nX ) ||
CH_SIX_PER_EM == rInf.GetChar( nX ) ||
CH_FULL_BLANK == rInf.GetChar( nX ) ) )
nBreakPos = nX;
}
if( nBreakPos > rInf.GetIdx() )
nPorLen = nBreakPos - rInf.GetIdx();
}
else
{
// no line break found, setting nBreakPos to COMPLETE_STRING
// causes a break cut
nBreakPos = TextFrameIndex(COMPLETE_STRING);
OSL_ENSURE( nCutPos >= rInf.GetIdx(), "Deep cut" );
nPorLen = nCutPos - rInf.GetIdx();
}
if (nBreakPos > nCutPos && nBreakPos != TextFrameIndex(COMPLETE_STRING))
{
const TextFrameIndex nHangingLen = nBreakPos - nCutPos;
SwPosSize aTmpSize = rInf.GetTextSize( &rSI, nCutPos, nHangingLen );
aTmpSize.Width(aTmpSize.Width() + nLeftRightBorderSpace);
OSL_ENSURE( !pHanging, "A hanging portion is hanging around" );
pHanging.reset( new SwHangingPortion( aTmpSize ) );
pHanging->SetLen( nHangingLen );
nPorLen = nCutPos - rInf.GetIdx();
}
// 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 == cFieldChr )
{
if ( nBreakPos < rInf.GetIdx() )
nBreakPos = nOldIdx - TextFrameIndex(1);
else if (TextFrameIndex(COMPLETE_STRING) != 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;
OUString& rOldText = const_cast<OUString&> (rInf.GetText());
OUString aReplacement( cFieldChr );
rOldText = rOldText.replaceAt(sal_Int32(nOldIdx) - 1, sal_Int32(nFieldDiff) + 1, aReplacement);
rInf.SetIdx( nOldIdx );
#if OSL_DEBUG_LEVEL > 0
OSL_ENSURE( aDebugString == rInf.GetText(),
"Somebody, somebody, somebody put something in my string" );
#endif
}
}
if( nPorLen )
{
rInf.GetTextSize( &rSI, rInf.GetIdx(), nPorLen,
nMaxComp, nBreakWidth, nMaxSizeDiff,
rInf.GetCachedVclData().get() );
// save maximum width for later use
if ( nMaxSizeDiff )
rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
nBreakWidth += nItalic + nLeftRightBorderSpace;
}
else
nBreakWidth = 0;
if( pHanging )
{
nBreakPos = nCutPos;
// Keep following SwBreakPortion in the same line.
if ( CH_BREAK == rInf.GetChar( nBreakPos + pHanging->GetLen() ) )
return true;
}
return false;
}
// returns true if word at position nPos has a different spelling
// if hyphenated at this position (old german spelling)
bool SwTextGuess::AlternativeSpelling( const SwTextFormatInfo &rInf,
const TextFrameIndex nPos)
{
// get word boundaries
Boundary aBound = g_pBreakIt->GetBreakIter()->getWordBoundary(
rInf.GetText(), sal_Int32(nPos),
g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
WordType::DICTIONARY_WORD, true );
nBreakStart = TextFrameIndex(aBound.startPos);
sal_Int32 nWordLen = aBound.endPos - sal_Int32(nBreakStart);
// if everything else fails, we want to cut at nPos
nCutPos = nPos;
OUString const aText( rInf.GetText().copy(sal_Int32(nBreakStart), nWordLen) );
// check, if word has alternative spelling
Reference< XHyphenator > xHyph( ::GetHyphenator() );
OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
//! subtract 1 since the UNO-interface is 0 based
xHyphWord = xHyph->queryAlternativeSpelling( aText,
g_pBreakIt->GetLocale( rInf.GetFont()->GetLanguage() ),
sal::static_int_cast<sal_Int16>(sal_Int32(nPos - nBreakStart)),
rInf.GetHyphValues() );
return xHyphWord.is() && xHyphWord->isAlternativeSpelling();
}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|