LibreOffice Module sw (master) 1
guess.cxx
Go to the documentation of this file.
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 <editeng/unolingu.hxx>
21#include <breakit.hxx>
23#include "guess.hxx"
24#include "inftxt.hxx"
25#include <pagefrm.hxx>
26#include <tgrditem.hxx>
27#include <com/sun/star/i18n/BreakType.hpp>
28#include <com/sun/star/i18n/WordType.hpp>
29#include <com/sun/star/i18n/XBreakIterator.hpp>
31#include "porfld.hxx"
32#include <paratr.hxx>
33#include <doc.hxx>
35
36using namespace ::com::sun::star;
37using namespace ::com::sun::star::uno;
38using namespace ::com::sun::star::i18n;
39using namespace ::com::sun::star::beans;
40using namespace ::com::sun::star::linguistic2;
41
42namespace{
43
44bool IsBlank(sal_Unicode ch) { return ch == CH_BLANK || ch == CH_FULL_BLANK || ch == CH_NB_SPACE || ch == CH_SIX_PER_EM; }
45
46}
47
48// provides information for line break calculation
49// returns true if no line break has to be performed
50// otherwise possible break or hyphenation position is determined
52 const sal_uInt16 nPorHeight )
53{
54 m_nCutPos = rInf.GetIdx();
55
56 // Empty strings are always 0
57 if( !rInf.GetLen() || rInf.GetText().isEmpty() )
58 return false;
59
60 OSL_ENSURE( rInf.GetIdx() < TextFrameIndex(rInf.GetText().getLength()),
61 "+SwTextGuess::Guess: invalid SwTextFormatInfo" );
62
63 OSL_ENSURE( nPorHeight, "+SwTextGuess::Guess: no height" );
64
65 sal_uInt16 nMaxSizeDiff;
66
67 const SwScriptInfo& rSI = rInf.GetParaPortion()->GetScriptInfo();
68
69 sal_uInt16 nMaxComp = ( SwFontScript::CJK == rInf.GetFont()->GetActual() ) &&
70 rSI.CountCompChg() &&
71 ! rInf.IsMulti() &&
72 ! rPor.InFieldGrp() &&
73 ! rPor.IsDropPortion() ?
74 10000 :
75 0 ;
76
78 TextFrameIndex nMaxLen = TextFrameIndex(rInf.GetText().getLength()) - rInf.GetIdx();
79
81
82 // tdf#104668 space chars at the end should be cut if the compatibility option is enabled
83 // for LTR mode only
84 if ( !rInf.GetTextFrame()->IsRightToLeft() )
85 {
88 {
89 if ( rAdjust == SvxAdjust::Right || rAdjust == SvxAdjust::Center )
90 {
91 TextFrameIndex nSpaceCnt(0);
92 for (sal_Int32 i = rInf.GetText().getLength() - 1;
93 sal_Int32(rInf.GetIdx()) <= i; --i)
94 {
95 sal_Unicode cChar = rInf.GetText()[i];
96 if ( cChar != CH_BLANK && cChar != CH_FULL_BLANK && cChar != CH_SIX_PER_EM )
97 break;
98 ++nSpaceCnt;
99 }
100 TextFrameIndex nCharsCnt = nMaxLen - nSpaceCnt;
101 if ( nSpaceCnt && nCharsCnt < rPor.GetLen() )
102 {
103 if (nSpaceCnt)
104 rInf.GetTextSize( &rSI, rInf.GetIdx() + nCharsCnt, nSpaceCnt,
105 nMaxComp, m_nExtraBlankWidth, nMaxSizeDiff );
106 nMaxLen = nCharsCnt;
107 if ( !nMaxLen )
108 return true;
109 }
110 }
111 }
112 }
113
114 if ( rInf.GetLen() < nMaxLen )
115 nMaxLen = rInf.GetLen();
116
117 if( !nMaxLen )
118 return false;
119
120 sal_uInt16 nItalic = 0;
121 if( ITALIC_NONE != rInf.GetFont()->GetItalic() && !rInf.NotEOL() )
122 {
123 bool bAddItalic = true;
124
125 // do not add extra italic value if we have an active character grid
126 if ( rInf.SnapToGrid() )
127 {
128 SwTextGridItem const*const pGrid(
130 bAddItalic = !pGrid || GRID_LINES_CHARS != pGrid->GetGridType();
131 }
132
133 // do not add extra italic value for an isolated blank:
134 if (TextFrameIndex(1) == rInf.GetLen() &&
135 CH_BLANK == rInf.GetText()[sal_Int32(rInf.GetIdx())])
136 {
137 bAddItalic = false;
138 }
139
142 {
143 // Content is allowed over the margin: in this case over-margin content caused by italic
144 // formatting is OK.
145 bAddItalic = false;
146 }
147
148 nItalic = bAddItalic ? nPorHeight / 12 : 0;
149
150 nLineWidth -= nItalic;
151
152 // #i46524# LineBreak bug with italics
153 if ( nLineWidth < 0 ) nLineWidth = 0;
154 }
155
156 const sal_Int32 nLeftRightBorderSpace =
157 (!rPor.GetJoinBorderWithNext() ? rInf.GetFont()->GetRightBorderSpace() : 0) +
158 (!rPor.GetJoinBorderWithPrev() ? rInf.GetFont()->GetLeftBorderSpace() : 0);
159
160 nLineWidth -= nLeftRightBorderSpace;
161
162 const bool bUnbreakableNumberings = rInf.GetTextFrame()->GetDoc()
164
165 // first check if everything fits to line
166 if ( ( nLineWidth * 2 > SwTwips(sal_Int32(nMaxLen)) * nPorHeight ) ||
167 ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
168 {
169 // call GetTextSize with maximum compression (for kanas)
170 rInf.GetTextSize( &rSI, rInf.GetIdx(), nMaxLen,
171 nMaxComp, m_nBreakWidth, nMaxSizeDiff );
172
173 if ( ( m_nBreakWidth <= nLineWidth ) || ( bUnbreakableNumberings && rPor.IsNumberPortion() ) )
174 {
175 // portion fits to line
176 m_nCutPos = rInf.GetIdx() + nMaxLen;
177 if( nItalic &&
178 (m_nCutPos >= TextFrameIndex(rInf.GetText().getLength()) ||
179 // #i48035# Needed for CalcFitToContent
180 // if first line ends with a manual line break
181 rInf.GetText()[sal_Int32(m_nCutPos)] == CH_BREAK))
182 m_nBreakWidth = m_nBreakWidth + nItalic;
183
184 // save maximum width for later use
185 if ( nMaxSizeDiff )
186 rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
187
188 m_nBreakWidth += nLeftRightBorderSpace;
189
190 return true;
191 }
192 }
193
194 bool bHyph = rInf.IsHyphenate() && !rInf.IsHyphForbud();
195 TextFrameIndex nHyphPos(0);
196
197 // nCutPos is the first character not fitting to the current line
198 // nHyphPos is the first character not fitting to the current line,
199 // considering an additional "-" for hyphenation
200 if( bHyph )
201 {
202 // nHyphZone is the first character not fitting in the hyphenation zone,
203 // or 0, if the whole line in the hyphenation zone,
204 // or -1, if no hyphenation zone defined (i.e. it is 0)
205 sal_Int32 nHyphZone = -1;
206 const css::beans::PropertyValues & rHyphValues = rInf.GetHyphValues();
207 assert( rHyphValues.getLength() > 5 && rHyphValues[5].Name == UPN_HYPH_ZONE );
208 // hyphenation zone (distance from the line end in twips)
209 sal_uInt16 nTextHyphenZone;
210 if ( rHyphValues[5].Value >>= nTextHyphenZone )
211 nHyphZone = nTextHyphenZone >= nLineWidth
212 ? 0
213 : sal_Int32(rInf.GetTextBreak( nLineWidth - nTextHyphenZone,
214 nMaxLen, nMaxComp, rInf.GetCachedVclData().get() ));
215
216 m_nCutPos = rInf.GetTextBreak( nLineWidth, nMaxLen, nMaxComp, nHyphPos, rInf.GetCachedVclData().get() );
217
218 // don't try to hyphenate in the hyphenation zone
219 if ( nHyphZone != -1 && TextFrameIndex(COMPLETE_STRING) != m_nCutPos )
220 {
221 sal_Int32 nZonePos = sal_Int32(m_nCutPos);
222 // disable hyphenation, if there is a space within the hyphenation zone
223 // Note: for better interoperability, not fitting space character at
224 // rInf.GetIdx()[nHyphZone] always disables the hyphenation, don't need to calculate
225 // with its fitting part. Moreover, do not check double or more spaces there, they
226 // are accepted outside of the hyphenation zone, too.
227 for (; sal_Int32(rInf.GetIdx()) <= nZonePos && nHyphZone <= nZonePos; --nZonePos )
228 {
229 sal_Unicode cChar = rInf.GetText()[nZonePos];
230 if ( cChar == CH_BLANK || cChar == CH_FULL_BLANK || cChar == CH_SIX_PER_EM )
231 {
232 bHyph = false;
233 }
234 }
235 }
236
237 // search start of the last word, if needed
238 if ( bHyph )
239 {
240 // nLastWord is the space character before the last word
241 sal_Int32 nLastWord = rInf.GetText().getLength() - 1;
242 bool bHyphenationNoLastWord = false;
243 assert( rHyphValues.getLength() > 3 && rHyphValues[3].Name == UPN_HYPH_NO_LAST_WORD );
244 if ( rHyphValues[3].Value >>= bHyphenationNoLastWord )
245 {
246 // skip spaces after the last word
247 bool bCutBlank = false;
248 for (; sal_Int32(rInf.GetIdx()) <= nLastWord; --nLastWord )
249 {
250 sal_Unicode cChar = rInf.GetText()[nLastWord];
251 if ( cChar != CH_BLANK && cChar != CH_FULL_BLANK && cChar != CH_SIX_PER_EM )
252 bCutBlank = true;
253 else if ( bCutBlank )
254 break;
255 }
256 }
257
258 // don't hyphenate the last word of the paragraph
259 if ( bHyphenationNoLastWord && sal_Int32(m_nCutPos) > nLastWord &&
261 {
262 m_nCutPos = TextFrameIndex(nLastWord);
263 }
264 }
265
266 if ( !nHyphPos && rInf.GetIdx() )
267 nHyphPos = rInf.GetIdx() - TextFrameIndex(1);
268 }
269 else
270 {
271 m_nCutPos = rInf.GetTextBreak( nLineWidth, nMaxLen, nMaxComp, rInf.GetCachedVclData().get() );
272
273#if OSL_DEBUG_LEVEL > 1
275 {
276 sal_uInt16 nMinSize;
277 rInf.GetTextSize( &rSI, rInf.GetIdx(), m_nCutPos - rInf.GetIdx(),
278 nMaxComp, nMinSize, nMaxSizeDiff );
279 OSL_ENSURE( nMinSize <= nLineWidth, "What a Guess!!!" );
280 }
281#endif
282 }
283
284 if( m_nCutPos > rInf.GetIdx() + nMaxLen )
285 {
286 // second check if everything fits to line
287 m_nCutPos = m_nBreakPos = rInf.GetIdx() + nMaxLen - TextFrameIndex(1);
288 rInf.GetTextSize( &rSI, rInf.GetIdx(), nMaxLen, nMaxComp,
289 m_nBreakWidth, nMaxSizeDiff );
290
291 // The following comparison should always give true, otherwise
292 // there likely has been a pixel rounding error in GetTextBreak
293 if ( m_nBreakWidth <= nLineWidth )
294 {
295 if (nItalic && (m_nBreakPos + TextFrameIndex(1)) >= TextFrameIndex(rInf.GetText().getLength()))
296 m_nBreakWidth = m_nBreakWidth + nItalic;
297
298 // save maximum width for later use
299 if ( nMaxSizeDiff )
300 rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
301
302 m_nBreakWidth += nLeftRightBorderSpace;
303
304 return true;
305 }
306 }
307
308 // we have to trigger an underflow for a footnote portion
309 // which does not fit to the current line
310 if ( rPor.IsFootnotePortion() )
311 {
312 m_nBreakPos = rInf.GetIdx();
314 return false;
315 }
316
317 TextFrameIndex nPorLen(0);
318 // do not call the break iterator nCutPos is a blank
319 sal_Unicode cCutChar = m_nCutPos < TextFrameIndex(rInf.GetText().getLength())
320 ? rInf.GetText()[sal_Int32(m_nCutPos)]
321 : 0;
322 if (IsBlank(cCutChar))
323 {
326
327 if ( rAdjust == SvxAdjust::Left )
328 {
329 // we step back until a non blank character has been found
330 // or there is only one more character left
331 while (nX && TextFrameIndex(rInf.GetText().getLength()) < m_nBreakPos &&
332 IsBlank(rInf.GetChar(--nX)))
333 --m_nBreakPos;
334 }
335 else // #i20878#
336 {
337 while (nX && m_nBreakPos > rInf.GetLineStart() + TextFrameIndex(1) &&
338 IsBlank(rInf.GetChar(--nX)))
339 --m_nBreakPos;
340 }
341
342 if( m_nBreakPos > rInf.GetIdx() )
343 nPorLen = m_nBreakPos - rInf.GetIdx();
344 while (++m_nCutPos < TextFrameIndex(rInf.GetText().getLength()) &&
345 IsBlank(rInf.GetChar(m_nCutPos)))
346 ; // nothing
347
349 }
350 else
351 {
352 // New: We should have a look into the last portion, if it was a
353 // field portion. For this, we expand the text of the field portion
354 // into our string. If the line break position is inside of before
355 // the field portion, we trigger an underflow.
356
357 TextFrameIndex nOldIdx = rInf.GetIdx();
358 sal_Unicode cFieldChr = 0;
359
360#if OSL_DEBUG_LEVEL > 0
361 OUString aDebugString;
362#endif
363
364 // be careful: a field portion can be both: 0x01 (common field)
365 // or 0x02 (the follow of a footnode)
366 if ( rInf.GetLast() && rInf.GetLast()->InFieldGrp() &&
367 ! rInf.GetLast()->IsFootnotePortion() &&
368 rInf.GetIdx() > rInf.GetLineStart() &&
370 (cFieldChr = rInf.GetText()[sal_Int32(rInf.GetIdx()) - 1]))
371 {
372 SwFieldPortion* pField = static_cast<SwFieldPortion*>(rInf.GetLast());
373 OUString aText;
374 pField->GetExpText( rInf, aText );
375
376 if ( !aText.isEmpty() )
377 {
378 m_nFieldDiff = TextFrameIndex(aText.getLength() - 1);
380 nHyphPos = nHyphPos + m_nFieldDiff;
381
382#if OSL_DEBUG_LEVEL > 0
383 aDebugString = rInf.GetText();
384#endif
385
386 // this is pretty nutso... reverted at the end...
387 OUString& rOldText = const_cast<OUString&> (rInf.GetText());
388 rOldText = rOldText.replaceAt(sal_Int32(rInf.GetIdx()) - 1, 1, aText);
389 rInf.SetIdx( rInf.GetIdx() + m_nFieldDiff );
390 }
391 else
392 cFieldChr = 0;
393 }
394
395 LineBreakHyphenationOptions aHyphOpt;
396 Reference< XHyphenator > xHyph;
397 if( bHyph )
398 {
399 xHyph = ::GetHyphenator();
400 aHyphOpt = LineBreakHyphenationOptions( xHyph,
401 rInf.GetHyphValues(), sal_Int32(nHyphPos));
402 }
403
404 // Get Language for break iterator.
405 // We have to switch the current language if we have a script
406 // change at nCutPos. Otherwise LATIN punctuation would never
407 // be allowed to be hanging punctuation.
408 // NEVER call GetLang if the string has been modified!!!
409 LanguageType aLang = rInf.GetFont()->GetLanguage();
410
411 // If we are inside a field portion, we use a temporary string which
412 // differs from the string at the textnode. Therefore we are not allowed
413 // to call the GetLang function.
414 if ( m_nCutPos && ! rPor.InFieldGrp() )
415 {
416 const CharClass& rCC = GetAppCharClass();
417
418 // step back until a non-punctuation character is reached
419 TextFrameIndex nLangIndex = m_nCutPos;
420
421 // If a field has been expanded right in front of us we do not
422 // step further than the beginning of the expanded field
423 // (which is the position of the field placeholder in our
424 // original string).
425 const TextFrameIndex nDoNotStepOver = CH_TXTATR_BREAKWORD == cFieldChr
426 ? rInf.GetIdx() - m_nFieldDiff - TextFrameIndex(1)
427 : TextFrameIndex(0);
428
429 if ( nLangIndex > nDoNotStepOver &&
430 TextFrameIndex(rInf.GetText().getLength()) == nLangIndex)
431 --nLangIndex;
432
433 while ( nLangIndex > nDoNotStepOver &&
434 !rCC.isLetterNumeric(rInf.GetText(), sal_Int32(nLangIndex)))
435 --nLangIndex;
436
437 // last "real" character is not inside our current portion
438 // we have to check the script type of the last "real" character
439 if ( nLangIndex < rInf.GetIdx() )
440 {
441 sal_uInt16 nScript = g_pBreakIt->GetRealScriptOfText( rInf.GetText(),
442 sal_Int32(nLangIndex));
443 OSL_ENSURE( nScript, "Script is not between 1 and 4" );
444
445 // compare current script with script from last "real" character
446 if ( SwFontScript(nScript - 1) != rInf.GetFont()->GetActual() )
447 {
448 aLang = rInf.GetTextFrame()->GetLangOfChar(
449 CH_TXTATR_BREAKWORD == cFieldChr
450 ? nDoNotStepOver
451 : nLangIndex,
452 nScript, true);
453 }
454 }
455 }
456
457 const ForbiddenCharacters aForbidden(
459
460 const bool bAllowHanging = rInf.IsHanging() && ! rInf.IsMulti() &&
461 ! rInf.GetTextFrame()->IsInTab() &&
462 ! rPor.InFieldGrp();
463
464 LineBreakUserOptions aUserOpt(
465 aForbidden.beginLine, aForbidden.endLine,
466 rInf.HasForbiddenChars(), bAllowHanging, false );
467
468 // !!! We must have a local copy of the locale, because inside
469 // getLineBreak the LinguEventListener can trigger a new formatting,
470 // which can corrupt the locale pointer inside pBreakIt.
471 const lang::Locale aLocale = g_pBreakIt->GetLocale( aLang );
472
473 // determines first possible line break from nCutPos to
474 // start index of current line
475 LineBreakResults aResult = g_pBreakIt->GetBreakIter()->getLineBreak(
476 rInf.GetText(), sal_Int32(m_nCutPos), aLocale,
477 sal_Int32(rInf.GetLineStart()), aHyphOpt, aUserOpt );
478
479 m_nBreakPos = TextFrameIndex(aResult.breakIndex);
480
481 // if we are formatting multi portions we want to allow line breaks
482 // at the border between single line and multi line portion
483 // we have to be careful with footnote portions, they always come in
484 // with an index 0
485 if ( m_nBreakPos < rInf.GetLineStart() && rInf.IsFirstMulti() &&
486 ! rInf.IsFootnoteInside() )
487 m_nBreakPos = rInf.GetLineStart();
488
490
491 bHyph = BreakType::HYPHENATION == aResult.breakType;
492
494 {
495 // found hyphenation position within line
496 // nBreakPos is set to the hyphenation position
497 m_xHyphWord = aResult.rHyphenatedWord;
498 m_nBreakPos += TextFrameIndex(m_xHyphWord->getHyphenationPos() + 1);
499
500 // if not in interactive mode, we have to break behind a soft hyphen
501 if ( ! rInf.IsInterHyph() && rInf.GetIdx() )
502 {
503 sal_Int32 const nSoftHyphPos =
504 m_xHyphWord->getWord().indexOf( CHAR_SOFTHYPHEN );
505
506 if ( nSoftHyphPos >= 0 &&
507 m_nBreakStart + TextFrameIndex(nSoftHyphPos) <= m_nBreakPos &&
508 m_nBreakPos > rInf.GetLineStart() )
509 m_nBreakPos = rInf.GetIdx() - TextFrameIndex(1);
510 }
511
512 if( m_nBreakPos >= rInf.GetIdx() )
513 {
514 nPorLen = m_nBreakPos - rInf.GetIdx();
515 if ('-' == rInf.GetText()[ sal_Int32(m_nBreakPos) - 1 ])
516 m_xHyphWord = nullptr;
517 }
518 }
519 else if ( !bHyph && m_nBreakPos >= rInf.GetLineStart() )
520 {
521 OSL_ENSURE(sal_Int32(m_nBreakPos) != COMPLETE_STRING, "we should have found a break pos");
522
523 // found break position within line
524 m_xHyphWord = nullptr;
525
526 // check, if break position is soft hyphen and an underflow
527 // has to be triggered
528 if( m_nBreakPos > rInf.GetLineStart() && rInf.GetIdx() &&
529 CHAR_SOFTHYPHEN == rInf.GetText()[ sal_Int32(m_nBreakPos) - 1 ])
530 {
531 m_nBreakPos = rInf.GetIdx() - TextFrameIndex(1);
532 }
533
534 if( rAdjust != SvxAdjust::Left )
535 {
536 // Delete any blanks at the end of a line, but be careful:
537 // If a field has been expanded, we do not want to delete any
538 // blanks inside the field portion. This would cause an unwanted
539 // underflow
541 while( nX > rInf.GetLineStart() &&
542 ( CH_TXTATR_BREAKWORD != cFieldChr || nX > rInf.GetIdx() ) &&
543 ( CH_BLANK == rInf.GetChar( --nX ) ||
544 CH_SIX_PER_EM == rInf.GetChar( nX ) ||
545 CH_FULL_BLANK == rInf.GetChar( nX ) ) )
546 m_nBreakPos = nX;
547 }
548 if( m_nBreakPos > rInf.GetIdx() )
549 nPorLen = m_nBreakPos - rInf.GetIdx();
550 }
551 else
552 {
553 // no line break found, setting nBreakPos to COMPLETE_STRING
554 // causes a break cut
556 OSL_ENSURE( m_nCutPos >= rInf.GetIdx(), "Deep cut" );
557 nPorLen = m_nCutPos - rInf.GetIdx();
558 }
559
561 {
562 const TextFrameIndex nHangingLen = m_nBreakPos - m_nCutPos;
563 SwPosSize aTmpSize = rInf.GetTextSize( &rSI, m_nCutPos, nHangingLen );
564 aTmpSize.Width(aTmpSize.Width() + nLeftRightBorderSpace);
565 OSL_ENSURE( !m_pHanging, "A hanging portion is hanging around" );
566 m_pHanging.reset( new SwHangingPortion( std::move(aTmpSize) ) );
567 m_pHanging->SetLen( nHangingLen );
568 nPorLen = m_nCutPos - rInf.GetIdx();
569 }
570
571 // If we expanded a field, we must repair the original string.
572 // In case we do not trigger an underflow, we correct the nBreakPos
573 // value, but we cannot correct the nBreakStart value:
574 // If we have found a hyphenation position, nBreakStart can lie before
575 // the field.
576 if ( CH_TXTATR_BREAKWORD == cFieldChr )
577 {
578 if ( m_nBreakPos < rInf.GetIdx() )
579 m_nBreakPos = nOldIdx - TextFrameIndex(1);
581 {
582 OSL_ENSURE( m_nBreakPos >= m_nFieldDiff, "I've got field trouble!" );
584 }
585
586 OSL_ENSURE( m_nCutPos >= rInf.GetIdx() && m_nCutPos >= m_nFieldDiff,
587 "I've got field trouble, part2!" );
589
590 OUString& rOldText = const_cast<OUString&> (rInf.GetText());
591 OUString aReplacement( cFieldChr );
592 rOldText = rOldText.replaceAt(sal_Int32(nOldIdx) - 1, sal_Int32(m_nFieldDiff) + 1, aReplacement);
593 rInf.SetIdx( nOldIdx );
594
595#if OSL_DEBUG_LEVEL > 0
596 OSL_ENSURE( aDebugString == rInf.GetText(),
597 "Somebody, somebody, somebody put something in my string" );
598#endif
599 }
600 }
601
602 if( nPorLen )
603 {
604 rInf.GetTextSize( &rSI, rInf.GetIdx(), nPorLen,
605 nMaxComp, m_nBreakWidth, nMaxSizeDiff,
606 rInf.GetCachedVclData().get() );
607
608 // save maximum width for later use
609 if ( nMaxSizeDiff )
610 rInf.SetMaxWidthDiff( &rPor, nMaxSizeDiff );
611
612 m_nBreakWidth += nItalic + nLeftRightBorderSpace;
613 }
614 else
615 m_nBreakWidth = 0;
616
617 if (m_nBreakStart > rInf.GetIdx() + nPorLen + m_nFieldDiff)
618 {
619 rInf.GetTextSize(&rSI, rInf.GetIdx() + nPorLen,
620 m_nBreakStart - rInf.GetIdx() - nPorLen - m_nFieldDiff, nMaxComp,
621 m_nExtraBlankWidth, nMaxSizeDiff, rInf.GetCachedVclData().get());
622 }
623
624 if( m_pHanging )
625 {
627 // Keep following SwBreakPortion in the same line.
628 if ( CH_BREAK == rInf.GetChar( m_nBreakPos + m_pHanging->GetLen() ) )
629 return true;
630 }
631
632 return false;
633}
634
635// returns true if word at position nPos has a different spelling
636// if hyphenated at this position (old german spelling)
638 const TextFrameIndex nPos)
639{
640 // get word boundaries
641 Boundary aBound = g_pBreakIt->GetBreakIter()->getWordBoundary(
642 rInf.GetText(), sal_Int32(nPos),
644 WordType::DICTIONARY_WORD, true );
645 m_nBreakStart = TextFrameIndex(aBound.startPos);
646 sal_Int32 nWordLen = aBound.endPos - sal_Int32(m_nBreakStart);
647
648 // if everything else fails, we want to cut at nPos
649 m_nCutPos = nPos;
650
651 OUString const aText( rInf.GetText().copy(sal_Int32(m_nBreakStart), nWordLen) );
652
653 // check, if word has alternative spelling
654 Reference< XHyphenator > xHyph( ::GetHyphenator() );
655 OSL_ENSURE( xHyph.is(), "Hyphenator is missing");
657 m_xHyphWord = xHyph->queryAlternativeSpelling( aText,
659 sal::static_int_cast<sal_Int16>(sal_Int32(nPos - m_nBreakStart)),
660 rInf.GetHyphValues() );
661 return m_xHyphWord.is() && m_xHyphWord->isAlternativeSpelling();
662}
663
664/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
sal_Int32 nLineWidth
o3tl::strong_int< sal_Int32, struct Tag_TextFrameIndex > TextFrameIndex
Denotes a character index in a text frame at a layout level, after extent mapping from a text node at...
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
bool isLetterNumeric(const OUString &rStr, sal_Int32 nPos) const
virtual bool get(DocumentSettingId id) const =0
Return the specified document setting.
virtual const css::i18n::ForbiddenCharacters * getForbiddenCharacters(LanguageType nLang, bool bLocaleData) const =0
Return the forbidden characters.
SvxAdjust GetAdjust() const
const SvxAdjustItem & GetAdjust(bool=true) const
Definition: paratr.hxx:194
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
Definition: breakit.hxx:62
const css::lang::Locale & GetLocale(const LanguageType aLang)
Definition: breakit.hxx:67
sal_uInt16 GetRealScriptOfText(const OUString &rText, sal_Int32 nPos) const
Definition: breakit.cxx:83
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:726
IDocumentSettingAccess const & getIDocumentSettingAccess() const
Definition: doc.cxx:176
virtual bool GetExpText(const SwTextSizeInfo &rInf, OUString &rText) const override
Definition: porfld.cxx:452
FontItalic GetItalic() const
Definition: swfont.hxx:282
sal_uInt16 GetRightBorderSpace() const
Definition: swfont.hxx:892
SwFontScript GetActual() const
Definition: swfont.hxx:184
LanguageType GetLanguage() const
Definition: swfont.hxx:283
sal_uInt16 GetLeftBorderSpace() const
Definition: swfont.hxx:907
bool IsInTab() const
Definition: frame.hxx:955
bool IsRightToLeft() const
Definition: frame.hxx:987
SwPageFrame * FindPageFrame()
Definition: frame.hxx:680
bool GetJoinBorderWithPrev() const
Definition: porlin.hxx:177
TextFrameIndex GetLen() const
Definition: porlin.hxx:77
bool GetJoinBorderWithNext() const
Definition: porlin.hxx:178
bool IsFootnotePortion() const
Definition: porlin.hxx:129
bool IsDropPortion() const
Definition: porlin.hxx:130
bool InFieldGrp() const
Definition: porlin.hxx:111
bool IsNumberPortion() const
Definition: porlin.hxx:144
SwScriptInfo & GetScriptInfo()
Definition: porlay.hxx:291
SwTwips Width() const
Definition: possiz.hxx:51
size_t CountCompChg() const
Definition: scriptinfo.hxx:162
SwLinePortion * GetLast()
Definition: inftxt.hxx:561
bool IsInterHyph() const
Definition: inftxt.hxx:582
TextFrameIndex GetLineStart() const
Definition: inftxt.hxx:590
bool IsHyphenate() const
If the Hyphenator returns ERROR or the language is set to NOLANGUAGE we do not hyphenate.
Definition: inftxt.cxx:1492
SwTwips GetLineWidth()
Returns the distance between the current horizontal position and the end of the line.
Definition: inftxt.cxx:1769
const css::beans::PropertyValues & GetHyphValues() const
Definition: inftxt.cxx:1413
bool IsHyphForbud() const
Definition: inftxt.hxx:565
SwDoc & GetDoc()
Definition: txtfrm.hxx:464
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
Definition: txtfrm.cxx:1346
SwTextNode const * GetTextNodeForParaProps() const
Definition: txtfrm.cxx:1306
SwTextGrid GetGridType() const
Definition: tgrditem.hxx:81
bool AlternativeSpelling(const SwTextFormatInfo &rInf, const TextFrameIndex nPos)
Definition: guess.cxx:637
sal_uInt16 m_nExtraBlankWidth
Definition: guess.hxx:41
sal_uInt16 m_nBreakWidth
Definition: guess.hxx:40
TextFrameIndex m_nBreakPos
Definition: guess.hxx:37
std::unique_ptr< SwHangingPortion > m_pHanging
Definition: guess.hxx:34
TextFrameIndex m_nBreakStart
Definition: guess.hxx:36
css::uno::Reference< css::linguistic2::XHyphenatedWord > m_xHyphWord
Definition: guess.hxx:33
bool Guess(const SwTextPortion &rPor, SwTextFormatInfo &rInf, const sal_uInt16 nHeight)
Definition: guess.cxx:51
TextFrameIndex m_nCutPos
Definition: guess.hxx:35
TextFrameIndex m_nFieldDiff
Definition: guess.hxx:38
SwParaPortion * GetParaPortion()
Definition: inftxt.hxx:121
This portion represents a part of the paragraph string.
Definition: portxt.hxx:27
SwTextFrame * GetTextFrame()
Definition: inftxt.hxx:285
void SetMaxWidthDiff(const SwLinePortion *nKey, sal_uInt16 nVal)
Definition: inftxt.hxx:295
TextFrameIndex GetTextBreak(const tools::Long nLineWidth, const TextFrameIndex nMaxLen, const sal_uInt16 nComp, vcl::text::TextLayoutCache const *) const
Definition: inftxt.cxx:433
const std::shared_ptr< const vcl::text::TextLayoutCache > & GetCachedVclData() const
Definition: inftxt.hxx:329
SwFont * GetFont()
Definition: inftxt.hxx:231
void SetIdx(const TextFrameIndex nNew)
Definition: inftxt.hxx:273
bool IsHanging() const
Definition: inftxt.hxx:209
SwPosSize GetTextSize(OutputDevice *pOut, const SwScriptInfo *pSI, const OUString &rText, TextFrameIndex nIdx, TextFrameIndex nLen) const
Definition: inftxt.cxx:382
sal_Unicode GetChar(TextFrameIndex const nPos) const
Definition: inftxt.hxx:240
TextFrameIndex GetLen() const
Definition: inftxt.hxx:274
bool NotEOL() const
Definition: inftxt.hxx:194
bool IsFootnoteInside() const
Definition: inftxt.hxx:199
bool IsFirstMulti() const
Definition: inftxt.hxx:205
const OUString & GetText() const
Definition: inftxt.hxx:239
TextFrameIndex GetIdx() const
Definition: inftxt.hxx:272
bool SnapToGrid() const
Definition: inftxt.hxx:215
bool HasForbiddenChars() const
Definition: inftxt.hxx:213
bool IsMulti() const
Definition: inftxt.hxx:203
ITALIC_NONE
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:173
CharClass & GetAppCharClass()
Definition: init.cxx:705
constexpr OUStringLiteral UPN_HYPH_ZONE
constexpr OUStringLiteral UPN_HYPH_NO_LAST_WORD
sal_uInt16 nPos
Value
int i
SwTextGridItem const * GetGridItem(SwPageFrame const *const)
Definition: pagechg.cxx:2595
SvxAdjust
const sal_Unicode CH_BREAK
Definition: swfont.hxx:43
const sal_Unicode CH_NB_SPACE
Definition: swfont.hxx:48
const sal_Unicode CH_SIX_PER_EM
Definition: swfont.hxx:49
const sal_Unicode CH_BLANK
Definition: swfont.hxx:42
SwFontScript
Definition: swfont.hxx:124
const sal_Unicode CH_FULL_BLANK
Definition: swfont.hxx:47
uno::Reference< linguistic2::XHyphenator > GetHyphenator()
Definition: swtypes.cxx:57
tools::Long SwTwips
Definition: swtypes.hxx:51
#define CHAR_SOFTHYPHEN
Definition: swtypes.hxx:163
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57
@ GRID_LINES_CHARS
Definition: tgrditem.hxx:30
sal_uInt16 sal_Unicode