LibreOffice Module sw (master) 1
txtedt.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 <config_wasm_strip.h>
21
22#include <hintids.hxx>
23#include <utility>
24#include <vcl/svapp.hxx>
25#include <svl/itemiter.hxx>
27#include <editeng/splwrap.hxx>
28#include <editeng/langitem.hxx>
29#include <editeng/fontitem.hxx>
32#include <SwSmartTagMgr.hxx>
33#include <o3tl/safeint.hxx>
34#include <osl/diagnose.h>
35#include <officecfg/Office/Writer.hxx>
38#include <sal/log.hxx>
39#include <swmodule.hxx>
40#include <splargs.hxx>
41#include <viewopt.hxx>
42#include <acmplwrd.hxx>
43#include <doc.hxx>
46#include <docsh.hxx>
47#include <txtfld.hxx>
48#include <txatbase.hxx>
49#include <charatr.hxx>
50#include <pam.hxx>
51#include <hints.hxx>
52#include <ndtxt.hxx>
53#include <txtfrm.hxx>
54#include <SwGrammarMarkUp.hxx>
55#include <rootfrm.hxx>
56#include <swscanner.hxx>
57
58#include <breakit.hxx>
59#include <UndoOverwrite.hxx>
60#include <txatritr.hxx>
61#include <redline.hxx>
62#include <docary.hxx>
63#include <scriptinfo.hxx>
64#include <docstat.hxx>
65#include <editsh.hxx>
66#include <unotextmarkup.hxx>
67#include <txtatr.hxx>
68#include <fmtautofmt.hxx>
69#include <istyleaccess.hxx>
70#include <unicode/uchar.h>
72
73#include <com/sun/star/i18n/WordType.hpp>
74#include <com/sun/star/i18n/ScriptType.hpp>
75#include <com/sun/star/i18n/XBreakIterator.hpp>
76
77#include <vector>
78
79#include <unotextrange.hxx>
80
81using namespace ::com::sun::star;
82using namespace ::com::sun::star::frame;
83using namespace ::com::sun::star::i18n;
84using namespace ::com::sun::star::beans;
85using namespace ::com::sun::star::uno;
86using namespace ::com::sun::star::linguistic2;
87using namespace ::com::sun::star::smarttags;
88
89namespace
90{
91 void DetectAndMarkMissingDictionaries( SwDoc& rDoc,
92 const uno::Reference< XSpellChecker1 >& xSpell,
93 const LanguageType eActLang )
94 {
95 if( xSpell.is() && !xSpell->hasLanguage( eActLang.get() ) )
96 rDoc.SetMissingDictionaries( true );
97 else
98 rDoc.SetMissingDictionaries( false );
99 }
100}
101
102static bool lcl_HasComments(const SwTextNode& rNode)
103{
104 sal_Int32 nPosition = rNode.GetText().indexOf(CH_TXTATR_INWORD);
105 while (nPosition != -1)
106 {
107 const SwTextAttr* pAttr = rNode.GetTextAttrForCharAt(nPosition);
108 if (pAttr && pAttr->Which() == RES_TXTATR_ANNOTATION)
109 return true;
110 nPosition = rNode.GetText().indexOf(CH_TXTATR_INWORD, nPosition + 1);
111 }
112 return false;
113}
114
115// possible delimiter characters within URLs for word breaking
116static bool lcl_IsDelim( const sal_Unicode c )
117{
118 return '#' == c || '$' == c || '%' == c || '&' == c || '+' == c ||
119 ',' == c || '-' == c || '.' == c || '/' == c || ':' == c ||
120 ';' == c || '=' == c || '?' == c || '@' == c || '_' == c;
121}
122
123// allow to check normal text with hyperlink by recognizing (parts of) URLs
124static bool lcl_IsURL(std::u16string_view rWord,
125 SwTextNode &rNode, sal_Int32 nBegin, sal_Int32 nLen)
126{
127 // not a text with hyperlink
128 if ( !rNode.GetTextAttrAt(nBegin, RES_TXTATR_INETFMT) )
129 return false;
130
131 // there is a dot in the word, which is not a period ("example.org")
132 const size_t nPosAt = rWord.find('.');
133 if (nPosAt != std::u16string_view::npos && nPosAt < rWord.length() - 1)
134 return true;
135
136 // an e-mail address ("user@example")
137 if ( rWord.find('@') != std::u16string_view::npos )
138 return true;
139
140 const OUString& rText = rNode.GetText();
141
142 // scheme (e.g. "http" in "http://" or "mailto" in "mailto:address"):
143 // word is followed by 1) ':' + an alphanumeric character; 2) or ':' + a delimiter
144 if ( nBegin + nLen + 2 <= rText.getLength() && ':' == rText[nBegin + nLen] )
145 {
146 sal_Unicode c = rText[nBegin + nLen + 1];
147 if ( u_isalnum(c) || lcl_IsDelim(c) )
148 return true;
149 }
150
151 // path, query, fragment (e.g. "path" in "example.org/path"):
152 // word is preceded by 1) an alphanumeric character + a delimiter; 2) or two delimiters
153 if ( 2 <= nBegin && lcl_IsDelim(rText[nBegin - 1]) )
154 {
155 sal_Unicode c = rText[nBegin - 2];
156 if ( u_isalnum(c) || lcl_IsDelim(c) )
157 return true;
158 }
159
160 return false;
161}
162
163/*
164 * This has basically the same function as SwScriptInfo::MaskHiddenRanges,
165 * only for deleted redlines
166 */
167
168static sal_Int32
169lcl_MaskRedlines( const SwTextNode& rNode, OUStringBuffer& rText,
170 sal_Int32 nStt, sal_Int32 nEnd,
171 const sal_Unicode cChar )
172{
173 sal_Int32 nNumOfMaskedRedlines = 0;
174
175 const SwDoc& rDoc = rNode.GetDoc();
176
177 for ( SwRedlineTable::size_type nAct = rDoc.getIDocumentRedlineAccess().GetRedlinePos( rNode, RedlineType::Any ); nAct < rDoc.getIDocumentRedlineAccess().GetRedlineTable().size(); ++nAct )
178 {
179 const SwRangeRedline* pRed = rDoc.getIDocumentRedlineAccess().GetRedlineTable()[ nAct ];
180
181 if ( pRed->Start()->GetNode() > rNode )
182 break;
183
184 if( RedlineType::Delete == pRed->GetType() )
185 {
186 sal_Int32 nRedlineEnd;
187 sal_Int32 nRedlineStart;
188
189 pRed->CalcStartEnd( rNode.GetIndex(), nRedlineStart, nRedlineEnd );
190
191 if ( nRedlineEnd < nStt || nRedlineStart > nEnd )
192 continue;
193
194 while ( nRedlineStart < nRedlineEnd && nRedlineStart < nEnd )
195 {
196 if (nRedlineStart >= nStt)
197 {
198 rText[nRedlineStart] = cChar;
199 ++nNumOfMaskedRedlines;
200 }
201 ++nRedlineStart;
202 }
203 }
204 }
205
206 return nNumOfMaskedRedlines;
207}
208
212static bool
213lcl_MaskRedlinesAndHiddenText( const SwTextNode& rNode, OUStringBuffer& rText,
214 sal_Int32 nStt, sal_Int32 nEnd,
215 const sal_Unicode cChar = CH_TXTATR_INWORD )
216{
217 sal_Int32 nRedlinesMasked = 0;
218 sal_Int32 nHiddenCharsMasked = 0;
219
220 const SwDoc& rDoc = rNode.GetDoc();
222
223 // If called from word count or from spell checking, deleted redlines
224 // should be masked:
225 if ( bShowChg )
226 {
227 nRedlinesMasked = lcl_MaskRedlines( rNode, rText, nStt, nEnd, cChar );
228 }
229
230 const bool bHideHidden = !SW_MOD()->GetViewOption(rDoc.GetDocumentSettingManager().get(DocumentSettingId::HTML_MODE))->IsShowHiddenChar();
231
232 // If called from word count, we want to mask the hidden ranges even
233 // if they are visible:
234 if ( bHideHidden )
235 {
236 nHiddenCharsMasked =
237 SwScriptInfo::MaskHiddenRanges( rNode, rText, nStt, nEnd, cChar );
238 }
239
240 return (nRedlinesMasked > 0) || (nHiddenCharsMasked > 0);
241}
242
247 const SwTextFrame & rTextFrame, const SwTextNode & rNode,
248 sal_Int32 const nChgStart, sal_Int32 const nChgEnd)
249{
250 TextFrameIndex const iChgStart(rTextFrame.MapModelToView(&rNode, nChgStart));
251 TextFrameIndex const iChgEnd(rTextFrame.MapModelToView(&rNode, nChgEnd));
252
253 SwRect aRect = rTextFrame.GetPaintArea();
254 SwRect aTmp = rTextFrame.GetPaintArea();
255
256 const SwTextFrame* pStartFrame = &rTextFrame;
257 while( pStartFrame->HasFollow() &&
258 iChgStart >= pStartFrame->GetFollow()->GetOffset())
259 pStartFrame = pStartFrame->GetFollow();
260 const SwTextFrame* pEndFrame = pStartFrame;
261 while( pEndFrame->HasFollow() &&
262 iChgEnd >= pEndFrame->GetFollow()->GetOffset())
263 pEndFrame = pEndFrame->GetFollow();
264
265 bool bSameFrame = true;
266
267 if( rTextFrame.HasFollow() )
268 {
269 if( pEndFrame != pStartFrame )
270 {
271 bSameFrame = false;
272 SwRect aStFrame( pStartFrame->GetPaintArea() );
273 {
274 SwRectFnSet aRectFnSet(pStartFrame);
275 aRectFnSet.SetLeft( aTmp, aRectFnSet.GetLeft(aStFrame) );
276 aRectFnSet.SetRight( aTmp, aRectFnSet.GetRight(aStFrame) );
277 aRectFnSet.SetBottom( aTmp, aRectFnSet.GetBottom(aStFrame) );
278 }
279 aStFrame = pEndFrame->GetPaintArea();
280 {
281 SwRectFnSet aRectFnSet(pEndFrame);
282 aRectFnSet.SetTop( aRect, aRectFnSet.GetTop(aStFrame) );
283 aRectFnSet.SetLeft( aRect, aRectFnSet.GetLeft(aStFrame) );
284 aRectFnSet.SetRight( aRect, aRectFnSet.GetRight(aStFrame) );
285 }
286 aRect.Union( aTmp );
287 while( true )
288 {
289 pStartFrame = pStartFrame->GetFollow();
290 if( pStartFrame == pEndFrame )
291 break;
292 aRect.Union( pStartFrame->GetPaintArea() );
293 }
294 }
295 }
296 if( bSameFrame )
297 {
298 SwRectFnSet aRectFnSet(pStartFrame);
299 if( aRectFnSet.GetTop(aTmp) == aRectFnSet.GetTop(aRect) )
300 aRectFnSet.SetLeft( aRect, aRectFnSet.GetLeft(aTmp) );
301 else
302 {
303 SwRect aStFrame( pStartFrame->GetPaintArea() );
304 aRectFnSet.SetLeft( aRect, aRectFnSet.GetLeft(aStFrame) );
305 aRectFnSet.SetRight( aRect, aRectFnSet.GetRight(aStFrame) );
306 aRectFnSet.SetTop( aRect, aRectFnSet.GetTop(aTmp) );
307 }
308
309 if( aTmp.Height() > aRect.Height() )
310 aRect.Height( aTmp.Height() );
311 }
312
313 return aRect;
314}
315
319static bool lcl_HaveCommonAttributes( IStyleAccess& rStyleAccess,
320 const SfxItemSet* pSet1,
321 sal_uInt16 nWhichId,
322 const SfxItemSet& rSet2,
323 std::shared_ptr<SfxItemSet>& pStyleHandle )
324{
325 bool bRet = false;
326
327 std::unique_ptr<SfxItemSet> pNewSet;
328
329 if ( !pSet1 )
330 {
331 OSL_ENSURE( nWhichId, "lcl_HaveCommonAttributes not used correctly" );
332 if ( SfxItemState::SET == rSet2.GetItemState( nWhichId, false ) )
333 {
334 pNewSet = rSet2.Clone();
335 pNewSet->ClearItem( nWhichId );
336 }
337 }
338 else if ( pSet1->Count() )
339 {
340 SfxItemIter aIter( *pSet1 );
341 const SfxPoolItem* pItem = aIter.GetCurItem();
342 do
343 {
344 if ( SfxItemState::SET == rSet2.GetItemState( pItem->Which(), false ) )
345 {
346 if ( !pNewSet )
347 pNewSet = rSet2.Clone();
348 pNewSet->ClearItem( pItem->Which() );
349 }
350
351 pItem = aIter.NextItem();
352 } while (pItem);
353 }
354
355 if ( pNewSet )
356 {
357 if ( pNewSet->Count() )
358 pStyleHandle = rStyleAccess.getAutomaticStyle( *pNewSet, IStyleAccess::AUTO_STYLE_CHAR );
359 bRet = true;
360 }
361
362 return bRet;
363}
364
389 sal_Int32 nStt,
390 const sal_Int32 nLen,
391 const sal_uInt16 nWhich,
392 const SfxItemSet* pSet,
393 const bool bInclRefToxMark,
394 const bool bExactRange )
395{
396 if ( !GetpSwpHints() )
397 return;
398
399 sal_Int32 nEnd = nStt + nLen;
400 {
401 // enlarge range for the reset of text attributes in case of an overlapping input field
402 const SwTextInputField* pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextAttrAt(nStt, RES_TXTATR_INPUTFIELD, ::sw::GetTextAttrMode::Parent));
403 if ( pTextInputField == nullptr )
404 {
405 pTextInputField = dynamic_cast<const SwTextInputField*>(GetTextAttrAt(nEnd, RES_TXTATR_INPUTFIELD, ::sw::GetTextAttrMode::Parent));
406 }
407 if ( pTextInputField != nullptr )
408 {
409 if ( nStt > pTextInputField->GetStart() )
410 {
411 nStt = pTextInputField->GetStart();
412 }
413 if ( nEnd < *(pTextInputField->End()) )
414 {
415 nEnd = *(pTextInputField->End());
416 }
417 }
418 }
419
420 bool bChanged = false;
421
422 // nMin and nMax initialized to maximum / minimum (inverse)
423 sal_Int32 nMin = m_Text.getLength();
424 sal_Int32 nMax = nStt;
425 const bool bNoLen = nMin == 0;
426
427 // We have to remember the "new" attributes that have
428 // been introduced by splitting surrounding attributes (case 2,3,4).
429 std::vector<SwTextAttr *> newAttributes;
430 std::vector<SwTextAttr *> delAttributes;
431
432 // iterate over attribute array until start of attribute is behind deletion range
433 m_pSwpHints->SortIfNeedBe(); // trigger sorting now, we don't want it during iteration
434 size_t i = 0;
435 sal_Int32 nAttrStart = sal_Int32();
436 SwTextAttr *pHt = nullptr;
437 while ( (i < m_pSwpHints->Count())
438 && ( ( ( nAttrStart = m_pSwpHints->GetWithoutResorting(i)->GetStart()) < nEnd )
439 || nLen==0 ) && !bExactRange)
440 {
441 pHt = m_pSwpHints->GetWithoutResorting(i);
442
443 // attributes without end stay in!
444 // but consider <bInclRefToxMark> used by Undo
445 const sal_Int32* const pAttrEnd = pHt->GetEnd();
446 const bool bKeepAttrWithoutEnd =
447 pAttrEnd == nullptr
448 && ( !bInclRefToxMark
449 || ( RES_TXTATR_REFMARK != pHt->Which()
450 && RES_TXTATR_TOXMARK != pHt->Which()
451 && RES_TXTATR_META != pHt->Which()
452 && RES_TXTATR_METAFIELD != pHt->Which() ) );
453 if ( bKeepAttrWithoutEnd )
454 {
455
456 i++;
457 continue;
458 }
459 // attributes with content stay in
460 if ( pHt->HasContent() )
461 {
462 ++i;
463 continue;
464 }
465
466 // Default behavior is to process all attributes:
467 bool bSkipAttr = false;
468 std::shared_ptr<SfxItemSet> pStyleHandle;
469
470 // 1. case: We want to reset only the attributes listed in pSet:
471 if ( pSet )
472 {
473 bSkipAttr = SfxItemState::SET != pSet->GetItemState( pHt->Which(), false );
474 if ( bSkipAttr && RES_TXTATR_AUTOFMT == pHt->Which() )
475 {
476 // if the current attribute is an autostyle, we have to check if the autostyle
477 // and pSet have any attributes in common. If so, pStyleHandle will contain
478 // a handle to AutoStyle / pSet:
479 bSkipAttr = !lcl_HaveCommonAttributes( getIDocumentStyleAccess(), pSet, 0, *static_cast<const SwFormatAutoFormat&>(pHt->GetAttr()).GetStyleHandle(), pStyleHandle );
480 }
481 }
482 else if ( nWhich )
483 {
484 // 2. case: We want to reset only the attributes with WhichId nWhich:
485 bSkipAttr = nWhich != pHt->Which();
486 if ( bSkipAttr && RES_TXTATR_AUTOFMT == pHt->Which() )
487 {
488 bSkipAttr = !lcl_HaveCommonAttributes( getIDocumentStyleAccess(), nullptr, nWhich, *static_cast<const SwFormatAutoFormat&>(pHt->GetAttr()).GetStyleHandle(), pStyleHandle );
489 }
490 }
491 else if ( !bInclRefToxMark )
492 {
493 // 3. case: Reset all attributes except from ref/toxmarks:
494 // skip hints with CH_TXTATR here
495 // (deleting those is ONLY allowed for UNDO!)
496 bSkipAttr = RES_TXTATR_REFMARK == pHt->Which()
497 || RES_TXTATR_TOXMARK == pHt->Which()
498 || RES_TXTATR_META == pHt->Which()
499 || RES_TXTATR_METAFIELD == pHt->Which();
500 }
501
502 if ( bSkipAttr )
503 {
504 i++;
505 continue;
506 }
507
508 if (nStt <= nAttrStart) // Case: 1,3,5
509 {
510 const sal_Int32 nAttrEnd = pAttrEnd != nullptr
511 ? *pAttrEnd
512 : nAttrStart;
513 if (nEnd > nAttrStart
514 || (nEnd == nAttrEnd && nEnd == nAttrStart)) // Case: 1,3
515 {
516 if ( nMin > nAttrStart )
517 nMin = nAttrStart;
518 if ( nMax < nAttrEnd )
519 nMax = nAttrEnd;
520 // If only a no-extent hint is deleted, no resorting is needed
521 bChanged = bChanged || nEnd > nAttrStart || bNoLen;
522 if (nAttrEnd <= nEnd) // Case: 1
523 {
524 delAttributes.push_back(pHt);
525
526 if ( pStyleHandle )
527 {
528 SwTextAttr* pNew = MakeTextAttr( GetDoc(),
529 *pStyleHandle, nAttrStart, nAttrEnd );
530 newAttributes.push_back(pNew);
531 }
532 }
533 else // Case: 3
534 {
535 bChanged = true;
536 m_pSwpHints->NoteInHistory( pHt );
537 // UGLY: this may temporarily destroy the sorting!
538 pHt->SetStart(nEnd);
539 m_pSwpHints->NoteInHistory( pHt, true );
540
541 if ( pStyleHandle && nAttrStart < nEnd )
542 {
543 SwTextAttr* pNew = MakeTextAttr( GetDoc(),
544 *pStyleHandle, nAttrStart, nEnd );
545 newAttributes.push_back(pNew);
546 }
547 }
548 }
549 }
550 else if (pAttrEnd != nullptr) // Case: 2,4,5
551 {
552 if (*pAttrEnd > nStt) // Case: 2,4
553 {
554 if (*pAttrEnd < nEnd) // Case: 2
555 {
556 if ( nMin > nAttrStart )
557 nMin = nAttrStart;
558 if ( nMax < *pAttrEnd )
559 nMax = *pAttrEnd;
560 bChanged = true;
561
562 const sal_Int32 nAttrEnd = *pAttrEnd;
563
564 m_pSwpHints->NoteInHistory( pHt );
565 // UGLY: this may temporarily destroy the sorting!
566 pHt->SetEnd(nStt);
567 m_pSwpHints->NoteInHistory( pHt, true );
568
569 if ( pStyleHandle )
570 {
571 SwTextAttr* pNew = MakeTextAttr( GetDoc(),
572 *pStyleHandle, nStt, nAttrEnd );
573 newAttributes.push_back(pNew);
574 }
575 }
576 else if (nLen) // Case: 4
577 {
578 // for Length 0 both hints would be merged again by
579 // InsertHint, so leave them alone!
580 if ( nMin > nAttrStart )
581 nMin = nAttrStart;
582 if ( nMax < *pAttrEnd )
583 nMax = *pAttrEnd;
584 bChanged = true;
585 const sal_Int32 nTmpEnd = *pAttrEnd;
586 m_pSwpHints->NoteInHistory( pHt );
587 // UGLY: this may temporarily destroy the sorting!
588 pHt->SetEnd(nStt);
589 m_pSwpHints->NoteInHistory( pHt, true );
590
591 if ( pStyleHandle && nStt < nEnd )
592 {
593 SwTextAttr* pNew = MakeTextAttr( GetDoc(),
594 *pStyleHandle, nStt, nEnd );
595 newAttributes.push_back(pNew);
596 }
597
598 if( nEnd < nTmpEnd )
599 {
600 SwTextAttr* pNew = MakeTextAttr( GetDoc(),
601 pHt->GetAttr(), nEnd, nTmpEnd );
602 if ( pNew )
603 {
604 SwTextCharFormat* pCharFormat = dynamic_cast<SwTextCharFormat*>(pHt);
605 if ( pCharFormat )
606 static_txtattr_cast<SwTextCharFormat*>(pNew)->SetSortNumber(pCharFormat->GetSortNumber());
607
608 newAttributes.push_back(pNew);
609 }
610 }
611 }
612 }
613 }
614 ++i;
615 }
616
617 if (bExactRange)
618 {
619 // Only delete the hints which start at nStt and end at nEnd.
620 for (i = 0; i < m_pSwpHints->Count(); ++i)
621 {
622 SwTextAttr* pHint = m_pSwpHints->Get(i);
623 if ( (isTXTATR_WITHEND(pHint->Which()) && RES_TXTATR_AUTOFMT != pHint->Which())
624 || pHint->GetStart() != nStt)
625 continue;
626
627 const sal_Int32* pHintEnd = pHint->GetEnd();
628 if (!pHintEnd || *pHintEnd != nEnd)
629 continue;
630
631 delAttributes.push_back(pHint);
632 }
633 }
634
635 if (bChanged && !delAttributes.empty())
636 { // Delete() calls GetStartOf() - requires sorted hints!
637 m_pSwpHints->Resort();
638 }
639
640 // delay deleting the hints because it re-sorts the hints array
641 for (SwTextAttr *const pDel : delAttributes)
642 {
643 m_pSwpHints->Delete(pDel);
644 DestroyAttr(pDel);
645 }
646
647 // delay inserting the hints because it re-sorts the hints array
648 for (SwTextAttr *const pNew : newAttributes)
649 {
651 }
652
654
655 if (!bChanged)
656 return;
657
658 if ( HasHints() )
659 { // possibly sometimes Resort would be sufficient, but...
660 m_pSwpHints->MergePortions(*this);
661 }
662
663 // TextFrame's respond to aHint, others to aNew
664 SwUpdateAttr aHint(
665 nMin,
666 nMax,
667 0);
668
669 CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aHint));
670 SwFormatChg aNew( GetFormatColl() );
671 CallSwClientNotify(sw::LegacyModifyHint(nullptr, &aNew));
672}
673
674static sal_Int32 clipIndexBounds(std::u16string_view aStr, sal_Int32 nPos)
675{
676 if (nPos < 0)
677 return 0;
678 if (nPos > sal_Int32(aStr.size()))
679 return aStr.size();
680 return nPos;
681}
682
683// Return current word:
684// Search from left to right, so find the word before nPos.
685// Except if at the start of the paragraph, then return the first word.
686// If the first word consists only of whitespace, return an empty string.
687OUString SwTextFrame::GetCurWord(SwPosition const& rPos) const
688{
690 SwTextNode *const pTextNode(rPos.GetNode().GetTextNode());
691 assert(pTextNode);
692 OUString const& rText(GetText());
693 assert(sal_Int32(nPos) <= rText.getLength()); // invalid index
694
695 if (rText.isEmpty() || IsHiddenNow())
696 return OUString();
697
698 assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
699 const uno::Reference< XBreakIterator > &rxBreak = g_pBreakIt->GetBreakIter();
700 sal_Int16 nWordType = WordType::DICTIONARY_WORD;
701 lang::Locale aLocale( g_pBreakIt->GetLocale(pTextNode->GetLang(rPos.GetContentIndex())) );
702 Boundary aBndry =
703 rxBreak->getWordBoundary(rText, sal_Int32(nPos), aLocale, nWordType, true);
704
705 // if no word was found use previous word (if any)
706 if (aBndry.startPos == aBndry.endPos)
707 {
708 aBndry = rxBreak->previousWord(rText, sal_Int32(nPos), aLocale, nWordType);
709 }
710
711 // check if word was found and if it uses a symbol font, if so
712 // enforce returning an empty string
713 if (aBndry.endPos != aBndry.startPos
714 && IsSymbolAt(TextFrameIndex(aBndry.startPos)))
715 {
716 aBndry.endPos = aBndry.startPos;
717 }
718
719 // can have -1 as start/end of bounds not found
720 aBndry.startPos = clipIndexBounds(rText, aBndry.startPos);
721 aBndry.endPos = clipIndexBounds(rText, aBndry.endPos);
722
723 return rText.copy(aBndry.startPos,
724 aBndry.endPos - aBndry.startPos);
725}
726
727SwScanner::SwScanner( const SwTextNode& rNd, const OUString& rText,
728 const LanguageType* pLang, const ModelToViewHelper& rConvMap,
729 sal_uInt16 nType, sal_Int32 nStart, sal_Int32 nEnd, bool bClp )
730 : SwScanner(
731 [&rNd](sal_Int32 const nBegin, sal_uInt16 const nScript, bool const bNoChar)
732 { return rNd.GetLang(nBegin, bNoChar ? 0 : 1, nScript); }
733 , rText, pLang, rConvMap, nType, nStart, nEnd, bClp)
734{
735}
736
737SwScanner::SwScanner(std::function<LanguageType(sal_Int32, sal_Int32, bool)> aGetLangOfChar,
738 OUString aText, const LanguageType* pLang,
739 ModelToViewHelper aConvMap, sal_uInt16 nType, sal_Int32 nStart,
740 sal_Int32 nEnd, bool bClp)
741 : m_pGetLangOfChar(std::move(aGetLangOfChar))
742 , m_aPreDashReplacementText(std::move(aText))
743 , m_pLanguage(pLang)
744 , m_ModelToView(std::move(aConvMap))
745 , m_nLength(0)
746 , m_nOverriddenDashCount(0)
747 , m_nWordType(nType)
748 , m_bClip(bClp)
749{
750 m_nStartPos = m_nBegin = nStart;
751 m_nEndPos = nEnd;
752
753 //MSWord f.e has special emdash and endash behaviour in that they break
754 //words for the purposes of word counting, while a hyphen etc. doesn't.
755
756 //The default configuration treats emdash/endash as a word break, but
757 //additional ones can be added in under tools->options
758 if (m_nWordType == i18n::WordType::WORD_COUNT)
759 {
761 OUStringBuffer aBuf(m_aPreDashReplacementText);
762 for (sal_Int32 i = m_nStartPos; i < m_nEndPos; ++i)
763 {
764 if (i < 0)
765 continue;
766 sal_Unicode cChar = aBuf[i];
767 if (sDashes.indexOf(cChar) != -1)
768 {
769 aBuf[i] = ' ';
771 }
772 }
773 m_aText = aBuf.makeStringAndClear();
774 }
775 else
777
778 assert(m_aPreDashReplacementText.getLength() == m_aText.getLength());
779
780 if ( m_pLanguage )
781 {
783 }
784 else
785 {
786 ModelToViewHelper::ModelPosition aModelBeginPos =
788 m_aCurrentLang = m_pGetLangOfChar(aModelBeginPos.mnPos, 0, true);
789 }
790}
791
792namespace
793{
794 //fdo#45271 for Asian words count characters instead of words
795 sal_Int32 forceEachAsianCodePointToWord(const OUString &rText, sal_Int32 nBegin, sal_Int32 nLen)
796 {
797 if (nLen > 1)
798 {
799 const uno::Reference< XBreakIterator > &rxBreak = g_pBreakIt->GetBreakIter();
800
801 sal_uInt16 nCurrScript = rxBreak->getScriptType( rText, nBegin );
802
803 sal_Int32 indexUtf16 = nBegin;
804 rText.iterateCodePoints(&indexUtf16);
805
806 //First character is Asian, consider it a word :-(
807 if (nCurrScript == i18n::ScriptType::ASIAN)
808 {
809 nLen = indexUtf16 - nBegin;
810 return nLen;
811 }
812
813 //First character was not Asian, consider appearance of any Asian character
814 //to be the end of the word
815 while (indexUtf16 < nBegin + nLen)
816 {
817 nCurrScript = rxBreak->getScriptType( rText, indexUtf16 );
818 if (nCurrScript == i18n::ScriptType::ASIAN)
819 {
820 nLen = indexUtf16 - nBegin;
821 return nLen;
822 }
823 rText.iterateCodePoints(&indexUtf16);
824 }
825 }
826 return nLen;
827 }
828}
829
831{
833 Boundary aBound;
834
835 const CharClass* pCC = &GetAppCharClass();
836 std::optional<CharClass> xLocalCharClass;
837
838 while ( true )
839 {
840 // skip non-letter characters:
841 while (m_nBegin < m_aText.getLength())
842 {
843 if (m_nBegin >= 0 && !u_isspace(m_aText[m_nBegin]))
844 {
845 if ( !m_pLanguage )
846 {
847 const sal_uInt16 nNextScriptType = g_pBreakIt->GetBreakIter()->getScriptType( m_aText, m_nBegin );
848 ModelToViewHelper::ModelPosition aModelBeginPos =
850 m_aCurrentLang = m_pGetLangOfChar(aModelBeginPos.mnPos, nNextScriptType, false);
851 }
852
853 if ( m_nWordType != i18n::WordType::WORD_COUNT )
854 {
855 xLocalCharClass.emplace(LanguageTag( g_pBreakIt->GetLocale( m_aCurrentLang ) ));
856 pCC = &*xLocalCharClass;
857 if ( pCC->isLetterNumeric(OUString(m_aText[m_nBegin])) )
858 break;
859 }
860 else
861 break;
862 }
863 ++m_nBegin;
864 }
865
866 if ( m_nBegin >= m_aText.getLength() || m_nBegin >= m_nEndPos )
867 return false;
868
869 // get the word boundaries
870 aBound = g_pBreakIt->GetBreakIter()->getWordBoundary( m_aText, m_nBegin,
872 OSL_ENSURE( aBound.endPos >= aBound.startPos, "broken aBound result" );
873
874 // we don't want to include preceding text
875 // to count words in text with mixed script punctuation correctly,
876 // but we want to include preceding symbols (eg. percent sign, section sign,
877 // degree sign defined by dict_word_hu to spell check their affixed forms).
878 if (m_nWordType == i18n::WordType::WORD_COUNT && aBound.startPos < m_nBegin)
879 aBound.startPos = m_nBegin;
880
881 //no word boundaries could be found
882 if(aBound.endPos == aBound.startPos)
883 return false;
884
885 //if a word before is found it has to be searched for the next
886 if(aBound.endPos == m_nBegin)
887 ++m_nBegin;
888 else
889 break;
890 } // end while( true )
891
892 // #i89042, as discussed with HDU: don't evaluate script changes for word count. Use whole word.
893 if ( m_nWordType == i18n::WordType::WORD_COUNT )
894 {
895 m_nBegin = std::max(aBound.startPos, m_nBegin);
896 m_nLength = 0;
897 if (aBound.endPos > m_nBegin)
898 m_nLength = aBound.endPos - m_nBegin;
899 }
900 else
901 {
902 // we have to differentiate between these cases:
903 if ( aBound.startPos <= m_nBegin )
904 {
905 OSL_ENSURE( aBound.endPos >= m_nBegin, "Unexpected aBound result" );
906
907 // restrict boundaries to script boundaries and nEndPos
908 const sal_uInt16 nCurrScript = g_pBreakIt->GetBreakIter()->getScriptType( m_aText, m_nBegin );
909 OUString aTmpWord = m_aText.copy( m_nBegin, aBound.endPos - m_nBegin );
910 const sal_Int32 nScriptEnd = m_nBegin +
911 g_pBreakIt->GetBreakIter()->endOfScript( aTmpWord, 0, nCurrScript );
912 const sal_Int32 nEnd = std::min( aBound.endPos, nScriptEnd );
913
914 // restrict word start to last script change position
915 sal_Int32 nScriptBegin = 0;
916 if ( aBound.startPos < m_nBegin )
917 {
918 // search from nBegin backwards until the next script change
919 aTmpWord = m_aText.copy( aBound.startPos,
920 m_nBegin - aBound.startPos + 1 );
921 nScriptBegin = aBound.startPos +
922 g_pBreakIt->GetBreakIter()->beginOfScript( aTmpWord, m_nBegin - aBound.startPos,
923 nCurrScript );
924 }
925
926 m_nBegin = std::max( aBound.startPos, nScriptBegin );
927 m_nLength = nEnd - m_nBegin;
928 }
929 else
930 {
931 const sal_uInt16 nCurrScript = g_pBreakIt->GetBreakIter()->getScriptType( m_aText, aBound.startPos );
932 OUString aTmpWord = m_aText.copy( aBound.startPos,
933 aBound.endPos - aBound.startPos );
934 const sal_Int32 nScriptEnd = aBound.startPos +
935 g_pBreakIt->GetBreakIter()->endOfScript( aTmpWord, 0, nCurrScript );
936 const sal_Int32 nEnd = std::min( aBound.endPos, nScriptEnd );
937 m_nBegin = aBound.startPos;
938 m_nLength = nEnd - m_nBegin;
939 }
940 }
941
942 // optionally clip the result of getWordBoundaries:
943 if ( m_bClip )
944 {
945 aBound.startPos = std::max( aBound.startPos, m_nStartPos );
946 aBound.endPos = std::min( aBound.endPos, m_nEndPos );
947 if (aBound.endPos < aBound.startPos)
948 {
950 m_nLength = 0; // found word is outside of search interval
951 }
952 else
953 {
954 m_nBegin = aBound.startPos;
955 m_nLength = aBound.endPos - m_nBegin;
956 }
957 }
958
959 if( ! m_nLength )
960 return false;
961
962 if ( m_nWordType == i18n::WordType::WORD_COUNT )
963 m_nLength = forceEachAsianCodePointToWord(m_aText, m_nBegin, m_nLength);
964
966
967 return true;
968}
969
970// Note: this is a clone of SwTextFrame::AutoSpell_, so keep them in sync when fixing things!
972{
973 // modify string according to redline information and hidden text
974 const OUString aOldText( m_Text );
975 OUStringBuffer buf(m_Text);
976 const bool bContainsComments = lcl_HasComments(*this);
977 const bool bRestoreString =
978 lcl_MaskRedlinesAndHiddenText(*this, buf, 0, m_Text.getLength());
979 if (bRestoreString)
980 { // ??? UGLY: is it really necessary to modify m_Text here?
981 m_Text = buf.makeStringAndClear();
982 }
983
984 sal_Int32 nBegin = ( &pArgs->pStartPos->GetNode() != this )
985 ? 0
986 : pArgs->pStartPos->GetContentIndex();
987
988 sal_Int32 nEnd = ( &pArgs->pEndPos->GetNode() != this )
989 ? m_Text.getLength()
990 : pArgs->pEndPos->GetContentIndex();
991
992 pArgs->xSpellAlt = nullptr;
993
994 // 4 cases:
995
996 // 1. IsWrongDirty = 0 and GetWrong = 0
997 // Everything is checked and correct
998 // 2. IsWrongDirty = 0 and GetWrong = 1
999 // Everything is checked and errors are identified in the wrong list
1000 // 3. IsWrongDirty = 1 and GetWrong = 0
1001 // Nothing has been checked
1002 // 4. IsWrongDirty = 1 and GetWrong = 1
1003 // Text has been checked but there is an invalid range in the wrong list
1004
1005 // Nothing has to be done for case 1.
1006 if ( ( IsWrongDirty() || GetWrong() ) && m_Text.getLength() )
1007 {
1008 if (nBegin > m_Text.getLength())
1009 {
1010 nBegin = m_Text.getLength();
1011 }
1012 if (nEnd > m_Text.getLength())
1013 {
1014 nEnd = m_Text.getLength();
1015 }
1016
1017 if(!IsWrongDirty())
1018 {
1019 const sal_Int32 nTemp = GetWrong()->NextWrong( nBegin );
1020 if(nTemp > nEnd)
1021 {
1022 // reset original text
1023 if ( bRestoreString )
1024 {
1025 m_Text = aOldText;
1026 }
1027 return false;
1028 }
1029 if(nTemp > nBegin)
1030 nBegin = nTemp;
1031
1032 }
1033
1034 // In case 2. we pass the wrong list to the scanned, because only
1035 // the words in the wrong list have to be checked
1036 SwScanner aScanner( *this, m_Text, nullptr, ModelToViewHelper(),
1037 WordType::DICTIONARY_WORD,
1038 nBegin, nEnd );
1039 while( !pArgs->xSpellAlt.is() && aScanner.NextWord() )
1040 {
1041 const OUString& rWord = aScanner.GetWord();
1042
1043 // get next language for next word, consider language attributes
1044 // within the word
1045 LanguageType eActLang = aScanner.GetCurrentLanguage();
1046 DetectAndMarkMissingDictionaries( GetTextNode()->GetDoc(), pArgs->xSpeller, eActLang );
1047
1048 if( rWord.getLength() > 0 && LANGUAGE_NONE != eActLang &&
1049 !lcl_IsURL(rWord, *this, aScanner.GetBegin(), aScanner.GetLen() ) )
1050 {
1051 if (pArgs->xSpeller.is())
1052 {
1053 SvxSpellWrapper::CheckSpellLang( pArgs->xSpeller, eActLang );
1054 pArgs->xSpellAlt = pArgs->xSpeller->spell( rWord, static_cast<sal_uInt16>(eActLang),
1055 Sequence< PropertyValue >() );
1056 }
1057 if( pArgs->xSpellAlt.is() )
1058 {
1059 if ( IsSymbolAt(aScanner.GetBegin()) ||
1060 // redlines can leave "in word" character within word,
1061 // we must remove them before spell checking
1062 // to avoid false alarm
1063 ( (bRestoreString || bContainsComments) && pArgs->xSpeller->isValid( rWord.replaceAll(OUStringChar(CH_TXTATR_INWORD), ""),
1064 static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) ) )
1065 {
1066 pArgs->xSpellAlt = nullptr;
1067 }
1068 else
1069 {
1070 // make sure the selection build later from the data
1071 // below does not include "in word" character to the
1072 // left and right in order to preserve those. Therefore
1073 // count those "in words" in order to modify the
1074 // selection accordingly.
1075 const sal_Unicode* pChar = rWord.getStr();
1076 sal_Int32 nLeft = 0;
1077 while (*pChar++ == CH_TXTATR_INWORD)
1078 ++nLeft;
1079 pChar = rWord.getLength() ? rWord.getStr() + rWord.getLength() - 1 : nullptr;
1080 sal_Int32 nRight = 0;
1081 while (pChar && *pChar-- == CH_TXTATR_INWORD)
1082 ++nRight;
1083
1084 pArgs->pStartPos->Assign(*this, aScanner.GetEnd() - nRight );
1085 pArgs->pEndPos->Assign(*this, aScanner.GetBegin() + nLeft );
1086 }
1087 }
1088 }
1089 }
1090 }
1091
1092 // reset original text
1093 if ( bRestoreString )
1094 {
1095 m_Text = aOldText;
1096 }
1097
1098 return pArgs->xSpellAlt.is();
1099}
1100
1102 LanguageType nLang, sal_uInt16 nLangWhichId,
1103 const vcl::Font *pFont, sal_uInt16 nFontWhichId )
1104{
1105 SwEditShell *pEditShell = GetDoc().GetEditShell();
1106 if (!pEditShell)
1107 return;
1108 SfxItemSet aSet(pEditShell->GetAttrPool(), nLangWhichId, nLangWhichId );
1109 if (pFont)
1110 aSet.MergeRange(nFontWhichId, nFontWhichId); // Keep it sorted
1111 aSet.Put( SvxLanguageItem( nLang, nLangWhichId ) );
1112
1113 OSL_ENSURE( pFont, "target font missing?" );
1114 if (pFont)
1115 {
1116 SvxFontItem aFontItem = static_cast<const SvxFontItem&>( aSet.Get( nFontWhichId ) );
1117 aFontItem.SetFamilyName( pFont->GetFamilyName());
1118 aFontItem.SetFamily( pFont->GetFamilyType());
1119 aFontItem.SetStyleName( pFont->GetStyleName());
1120 aFontItem.SetPitch( pFont->GetPitch());
1121 aFontItem.SetCharSet( pFont->GetCharSet() );
1122 aSet.Put( aFontItem );
1123 }
1124
1126 // SetAttr( aSet ); <- Does not set language attribute of empty paragraphs correctly,
1127 // <- because since there is no selection the flag to garbage
1128 // <- collect all attributes is set, and therefore attributes spanned
1129 // <- over empty selection are removed.
1130
1131}
1132
1134{
1135 // get range of text within node to be converted
1136 // (either all the text or the text within the selection
1137 // when the conversion was started)
1138 const sal_Int32 nTextBegin = ( &rArgs.pStartPos->GetNode() == this )
1139 ? std::min(rArgs.pStartPos->GetContentIndex(), m_Text.getLength())
1140 : 0;
1141
1142 const sal_Int32 nTextEnd = ( &rArgs.pEndPos->GetNode() == this )
1143 ? std::min(rArgs.pEndPos->GetContentIndex(), m_Text.getLength())
1144 : m_Text.getLength();
1145
1146 rArgs.aConvText.clear();
1147
1148 // modify string according to redline information and hidden text
1149 const OUString aOldText( m_Text );
1150 OUStringBuffer buf(m_Text);
1151 const bool bRestoreString =
1152 lcl_MaskRedlinesAndHiddenText(*this, buf, 0, m_Text.getLength());
1153 if (bRestoreString)
1154 { // ??? UGLY: is it really necessary to modify m_Text here?
1155 m_Text = buf.makeStringAndClear();
1156 }
1157
1158 bool bFound = false;
1159 sal_Int32 nBegin = nTextBegin;
1160 sal_Int32 nLen = 0;
1161 LanguageType nLangFound = LANGUAGE_NONE;
1162 if (m_Text.isEmpty())
1163 {
1165 {
1166 // create SwPaM with mark & point spanning empty paragraph
1167 //SwPaM aCurPaM( *this, *this, nBegin, nBegin + nLen ); <-- wrong c-tor, does sth different
1168 SwPaM aCurPaM( *this, 0 );
1169
1170 SetLanguageAndFont( aCurPaM,
1173 }
1174 }
1175 else
1176 {
1177 SwLanguageIterator aIter( *this, nBegin );
1178
1179 // Implicit changes require setting new attributes, which in turn destroys
1180 // the attribute sequence on that aIter iterates. We store the necessary
1181 // coordinates and apply those changes after iterating through the text.
1182 typedef std::pair<sal_Int32, sal_Int32> ImplicitChangesRange;
1183 std::vector<ImplicitChangesRange> aImplicitChanges;
1184
1185 // find non zero length text portion of appropriate language
1186 do {
1187 nLangFound = aIter.GetLanguage();
1188 bool bLangOk = (nLangFound == rArgs.nConvSrcLang) ||
1191
1192 sal_Int32 nChPos = aIter.GetChgPos();
1193 // the position at the end of the paragraph is COMPLETE_STRING and
1194 // thus must be cut to the end of the actual string.
1195 assert(nChPos != -1);
1196 if (nChPos == -1 || nChPos == COMPLETE_STRING)
1197 {
1198 nChPos = m_Text.getLength();
1199 }
1200
1201 nLen = nChPos - nBegin;
1202 bFound = bLangOk && nLen > 0;
1203 if (!bFound)
1204 {
1205 // create SwPaM with mark & point spanning the attributed text
1206 //SwPaM aCurPaM( *this, *this, nBegin, nBegin + nLen ); <-- wrong c-tor, does sth different
1207 SwPaM aCurPaM( *this, nBegin );
1208 aCurPaM.SetMark();
1209 aCurPaM.GetPoint()->SetContent(nBegin + nLen);
1210
1211 // check script type of selected text
1212 if (SwEditShell *pEditShell = GetDoc().GetEditShell())
1213 {
1214 pEditShell->Push(); // save current cursor on stack
1215 pEditShell->SetSelection( aCurPaM );
1216 bool bIsAsianScript = (SvtScriptType::ASIAN == pEditShell->GetScriptType());
1217 pEditShell->Pop(SwCursorShell::PopMode::DeleteCurrent); // restore cursor from stack
1218
1219 if (!bIsAsianScript && rArgs.bAllowImplicitChangesForNotConvertibleText)
1220 {
1221 // Store for later use
1222 aImplicitChanges.emplace_back(nBegin, nBegin+nLen);
1223 }
1224 }
1225 nBegin = nChPos; // start of next language portion
1226 }
1227 } while (!bFound && aIter.Next()); /* loop while nothing was found and still sth is left to be searched */
1228
1229 // Apply implicit changes, if any, now that aIter is no longer used
1230 for (const auto& rImplicitChange : aImplicitChanges)
1231 {
1232 SwPaM aPaM( *this, rImplicitChange.first );
1233 aPaM.SetMark();
1234 aPaM.GetPoint()->SetContent( rImplicitChange.second );
1236 }
1237
1238 }
1239
1240 // keep resulting text within selection / range of text to be converted
1241 if (nBegin < nTextBegin)
1242 nBegin = nTextBegin;
1243 if (nBegin + nLen > nTextEnd)
1244 nLen = nTextEnd - nBegin;
1245 bool bInSelection = nBegin < nTextEnd;
1246
1247 if (bFound && bInSelection) // convertible text found within selection/range?
1248 {
1249 OSL_ENSURE( !m_Text.isEmpty(), "convertible text portion missing!" );
1250 rArgs.aConvText = m_Text.copy(nBegin, nLen);
1251 rArgs.nConvTextLang = nLangFound;
1252
1253 // position where to start looking in next iteration (after current ends)
1254 rArgs.pStartPos->Assign(*this, nBegin + nLen );
1255 // end position (when we have travelled over the whole document)
1256 rArgs.pEndPos->Assign(*this, nBegin );
1257 }
1258
1259 // restore original text
1260 if ( bRestoreString )
1261 {
1262 m_Text = aOldText;
1263 }
1264
1265 return !rArgs.aConvText.isEmpty();
1266}
1267
1268// Note: this is a clone of SwTextNode::Spell, so keep them in sync when fixing things!
1269SwRect SwTextFrame::AutoSpell_(SwTextNode & rNode, sal_Int32 nActPos)
1270{
1271 SwRect aRect;
1272 assert(sw::FrameContainsNode(*this, rNode.GetIndex()));
1273 SwTextNode *const pNode(&rNode);
1274 if (!nActPos)
1275 nActPos = COMPLETE_STRING;
1276
1278
1279 // modify string according to redline information and hidden text
1280 const OUString aOldText( pNode->GetText() );
1281 OUStringBuffer buf(pNode->m_Text);
1282 const bool bContainsComments = lcl_HasComments(rNode);
1283 const bool bRestoreString =
1284 lcl_MaskRedlinesAndHiddenText(*pNode, buf, 0, pNode->GetText().getLength());
1285 if (bRestoreString)
1286 { // ??? UGLY: is it really necessary to modify m_Text here? just for GetLang()?
1287 pNode->m_Text = buf.makeStringAndClear();
1288 }
1289
1290 // a change of data indicates that at least one word has been modified
1291
1292 sal_Int32 nBegin = 0;
1293 sal_Int32 nEnd = pNode->GetText().getLength();
1294 sal_Int32 nInsertPos = 0;
1295 sal_Int32 nChgStart = COMPLETE_STRING;
1296 sal_Int32 nChgEnd = 0;
1297 sal_Int32 nInvStart = COMPLETE_STRING;
1298 sal_Int32 nInvEnd = 0;
1299
1300 const bool bAddAutoCmpl = pNode->IsAutoCompleteWordDirty() &&
1302
1303 if( pNode->GetWrong() )
1304 {
1305 nBegin = pNode->GetWrong()->GetBeginInv();
1306 if( COMPLETE_STRING != nBegin )
1307 {
1308 nEnd = std::max(pNode->GetWrong()->GetEndInv(), pNode->GetText().getLength());
1309 }
1310
1311 // get word around nBegin, we start at nBegin - 1
1312 if ( COMPLETE_STRING != nBegin )
1313 {
1314 if ( nBegin )
1315 --nBegin;
1316
1317 LanguageType eActLang = pNode->GetLang( nBegin );
1318 Boundary aBound =
1319 g_pBreakIt->GetBreakIter()->getWordBoundary( pNode->GetText(), nBegin,
1320 g_pBreakIt->GetLocale( eActLang ),
1321 WordType::DICTIONARY_WORD, true );
1322 nBegin = aBound.startPos;
1323 }
1324
1325 // get the position in the wrong list
1326 nInsertPos = pNode->GetWrong()->GetWrongPos( nBegin );
1327
1328 // sometimes we have to skip one entry
1329 if( nInsertPos < pNode->GetWrong()->Count() &&
1330 nBegin == pNode->GetWrong()->Pos( nInsertPos ) +
1331 pNode->GetWrong()->Len( nInsertPos ) )
1332 nInsertPos++;
1333 }
1334
1335 bool bFresh = nBegin < nEnd;
1336 bool bPending(false);
1337
1338 if( bFresh )
1339 {
1340 uno::Reference< XSpellChecker1 > xSpell( ::GetSpellChecker() );
1341 SwDoc& rDoc = pNode->GetDoc();
1342
1343 SwScanner aScanner( *pNode, pNode->GetText(), nullptr, ModelToViewHelper(),
1344 WordType::DICTIONARY_WORD, nBegin, nEnd);
1345
1346 while( aScanner.NextWord() )
1347 {
1348 const OUString& rWord = aScanner.GetWord();
1349 nBegin = aScanner.GetBegin();
1350 sal_Int32 nLen = aScanner.GetLen();
1351
1352 // get next language for next word, consider language attributes
1353 // within the word
1354 LanguageType eActLang = aScanner.GetCurrentLanguage();
1355 DetectAndMarkMissingDictionaries( rDoc, xSpell, eActLang );
1356
1357 bool bSpell = xSpell.is() && xSpell->hasLanguage( static_cast<sal_uInt16>(eActLang) );
1358 if( bSpell && !rWord.isEmpty() && !lcl_IsURL(rWord, *pNode, nBegin, nLen) )
1359 {
1360 // check for: bAlter => xHyphWord.is()
1361 OSL_ENSURE(!bSpell || xSpell.is(), "NULL pointer");
1362 if( !xSpell->isValid( rWord, static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) &&
1363 // redlines can leave "in word" character within word,
1364 // we must remove them before spell checking
1365 // to avoid false alarm
1366 ((!bRestoreString && !bContainsComments) || !xSpell->isValid( rWord.replaceAll(OUStringChar(CH_TXTATR_INWORD), ""),
1367 static_cast<sal_uInt16>(eActLang), Sequence< PropertyValue >() ) ) )
1368 {
1369 sal_Int32 nSmartTagStt = nBegin;
1370 sal_Int32 nDummy = 1;
1371 if ( !pNode->GetSmartTags() || !pNode->GetSmartTags()->InWrongWord( nSmartTagStt, nDummy ) )
1372 {
1373 if( !pNode->GetWrong() )
1374 {
1375 pNode->SetWrong( std::make_unique<SwWrongList>( WRONGLIST_SPELL ) );
1376 pNode->GetWrong()->SetInvalid( 0, nEnd );
1377 }
1378 SwWrongList::FreshState const eState(pNode->GetWrong()->Fresh(
1379 nChgStart, nChgEnd, nBegin, nLen, nInsertPos, nActPos));
1380 switch (eState)
1381 {
1383 pNode->GetWrong()->Insert(OUString(), nullptr, nBegin, nLen, nInsertPos++);
1384 break;
1386 bPending = true;
1387 [[fallthrough]]; // to mark as invalid
1389 nInvStart = nBegin;
1390 nInvEnd = nBegin + nLen;
1391 break;
1392 }
1393 }
1394 }
1395 else if( bAddAutoCmpl && rACW.GetMinWordLen() <= rWord.getLength() )
1396 {
1397 // tdf#119695 only add the word if the cursor position is outside the word
1398 // so that the incomplete words are not added as autocomplete candidates
1399 bool bCursorOutsideWord = nActPos > nBegin + nLen || nActPos < nBegin;
1400 if (bCursorOutsideWord)
1401 rACW.InsertWord(rWord, rDoc);
1402 }
1403 }
1404 }
1405 }
1406
1407 // reset original text
1408 // i63141 before calling GetCharRect(..) with formatting!
1409 if ( bRestoreString )
1410 {
1411 pNode->m_Text = aOldText;
1412 }
1413 if( pNode->GetWrong() )
1414 {
1415 if( bFresh )
1416 pNode->GetWrong()->Fresh( nChgStart, nChgEnd,
1417 nEnd, 0, nInsertPos, nActPos );
1418
1419 // Calculate repaint area:
1420
1421 if( nChgStart < nChgEnd )
1422 {
1423 aRect = lcl_CalculateRepaintRect(*this, rNode, nChgStart, nChgEnd);
1424
1425 // fdo#71558 notify misspelled word to accessibility
1426#if !ENABLE_WASM_STRIP_ACCESSIBILITY
1427 SwViewShell* pViewSh = getRootFrame() ? getRootFrame()->GetCurrShell() : nullptr;
1428 if( pViewSh )
1429 pViewSh->InvalidateAccessibleParaAttrs( *this );
1430#endif
1431 }
1432
1433 pNode->GetWrong()->SetInvalid( nInvStart, nInvEnd );
1434 pNode->SetWrongDirty(
1435 (COMPLETE_STRING != pNode->GetWrong()->GetBeginInv())
1436 ? (bPending
1440 if( !pNode->GetWrong()->Count() && ! pNode->IsWrongDirty() )
1441 pNode->ClearWrong();
1442 }
1443 else
1445
1446 if( bAddAutoCmpl )
1447 pNode->SetAutoCompleteWordDirty( false );
1448
1449 return aRect;
1450}
1451
1462{
1463 SwRect aRet;
1464
1465 assert(sw::FrameContainsNode(*this, rNode.GetIndex()));
1466 SwTextNode *const pNode = &rNode;
1467 const OUString& rText = pNode->GetText();
1468
1469 // Iterate over language portions
1470 SmartTagMgr& rSmartTagMgr = SwSmartTagMgr::Get();
1471
1472 SwWrongList* pSmartTagList = pNode->GetSmartTags();
1473
1474 sal_Int32 nBegin = 0;
1475 sal_Int32 nEnd = rText.getLength();
1476
1477 if ( pSmartTagList )
1478 {
1479 if ( pSmartTagList->GetBeginInv() != COMPLETE_STRING )
1480 {
1481 nBegin = pSmartTagList->GetBeginInv();
1482 nEnd = std::min( pSmartTagList->GetEndInv(), rText.getLength() );
1483
1484 if ( nBegin < nEnd )
1485 {
1486 const LanguageType aCurrLang = pNode->GetLang( nBegin );
1487 const css::lang::Locale aCurrLocale = g_pBreakIt->GetLocale( aCurrLang );
1488 nBegin = g_pBreakIt->GetBreakIter()->beginOfSentence( rText, nBegin, aCurrLocale );
1489 nEnd = g_pBreakIt->GetBreakIter()->endOfSentence(rText, nEnd, aCurrLocale);
1490 if (nEnd > rText.getLength() || nEnd < 0)
1491 nEnd = rText.getLength();
1492 }
1493 }
1494 }
1495
1496 const sal_uInt16 nNumberOfEntries = pSmartTagList ? pSmartTagList->Count() : 0;
1497 sal_uInt16 nNumberOfRemovedEntries = 0;
1498 sal_uInt16 nNumberOfInsertedEntries = 0;
1499
1500 // clear smart tag list between nBegin and nEnd:
1501 if ( 0 != nNumberOfEntries )
1502 {
1503 sal_Int32 nChgStart = COMPLETE_STRING;
1504 sal_Int32 nChgEnd = 0;
1505 const sal_uInt16 nCurrentIndex = pSmartTagList->GetWrongPos( nBegin );
1506 pSmartTagList->Fresh( nChgStart, nChgEnd, nBegin, nEnd - nBegin, nCurrentIndex, COMPLETE_STRING );
1507 nNumberOfRemovedEntries = nNumberOfEntries - pSmartTagList->Count();
1508 }
1509
1510 if ( nBegin < nEnd )
1511 {
1512 // Expand the string:
1513 const ModelToViewHelper aConversionMap(*pNode, getRootFrame() /*TODO - replace or expand fields for smart tags?*/);
1514 const OUString& aExpandText = aConversionMap.getViewText();
1515
1516 // Ownership ov ConversionMap is passed to SwXTextMarkup object!
1517 uno::Reference<text::XTextMarkup> const xTextMarkup =
1518 new SwXTextMarkup(pNode, aConversionMap);
1519
1520 css::uno::Reference< css::frame::XController > xController = pNode->GetDoc().GetDocShell()->GetController();
1521
1522 SwPosition start(*pNode, nBegin);
1523 SwPosition end (*pNode, nEnd);
1525
1526 rSmartTagMgr.RecognizeTextRange(xRange, xTextMarkup, xController);
1527
1528 sal_Int32 nLangBegin = nBegin;
1529 sal_Int32 nLangEnd;
1530
1531 // smart tag recognition has to be done for each language portion:
1532 SwLanguageIterator aIter( *pNode, nLangBegin );
1533
1534 do
1535 {
1536 const LanguageType nLang = aIter.GetLanguage();
1537 const css::lang::Locale aLocale = g_pBreakIt->GetLocale( nLang );
1538 nLangEnd = std::min<sal_Int32>( nEnd, aIter.GetChgPos() );
1539
1540 const sal_Int32 nExpandBegin = aConversionMap.ConvertToViewPosition( nLangBegin );
1541 const sal_Int32 nExpandEnd = aConversionMap.ConvertToViewPosition( nLangEnd );
1542
1543 rSmartTagMgr.RecognizeString(aExpandText, xTextMarkup, xController, aLocale, nExpandBegin, nExpandEnd - nExpandBegin );
1544
1545 nLangBegin = nLangEnd;
1546 }
1547 while ( aIter.Next() && nLangEnd < nEnd );
1548
1549 pSmartTagList = pNode->GetSmartTags();
1550
1551 const sal_uInt16 nNumberOfEntriesAfterRecognize = pSmartTagList ? pSmartTagList->Count() : 0;
1552 nNumberOfInsertedEntries = nNumberOfEntriesAfterRecognize - ( nNumberOfEntries - nNumberOfRemovedEntries );
1553 }
1554
1555 if( pSmartTagList )
1556 {
1557 // Update WrongList stuff
1558 pSmartTagList->SetInvalid( COMPLETE_STRING, 0 );
1559 pNode->SetSmartTagDirty( COMPLETE_STRING != pSmartTagList->GetBeginInv() );
1560
1561 if( !pSmartTagList->Count() && !pNode->IsSmartTagDirty() )
1562 pNode->ClearSmartTags();
1563
1564 // Calculate repaint area:
1565 if ( nBegin < nEnd && ( 0 != nNumberOfRemovedEntries ||
1566 0 != nNumberOfInsertedEntries ) )
1567 {
1568 aRet = lcl_CalculateRepaintRect(*this, rNode, nBegin, nEnd);
1569 }
1570 }
1571 else
1572 pNode->SetSmartTagDirty( false );
1573
1574 return aRet;
1575}
1576
1577void SwTextFrame::CollectAutoCmplWrds(SwTextNode & rNode, sal_Int32 nActPos)
1578{
1579 assert(sw::FrameContainsNode(*this, rNode.GetIndex())); (void) this;
1580 SwTextNode *const pNode(&rNode);
1581 if (!nActPos)
1582 nActPos = COMPLETE_STRING;
1583
1584 SwDoc& rDoc = pNode->GetDoc();
1586
1587 sal_Int32 nBegin = 0;
1588 sal_Int32 nEnd = pNode->GetText().getLength();
1589 sal_Int32 nLen;
1590 bool bACWDirty = false;
1591
1592 if( nBegin < nEnd )
1593 {
1594 int nCnt = 200;
1595 SwScanner aScanner( *pNode, pNode->GetText(), nullptr, ModelToViewHelper(),
1596 WordType::DICTIONARY_WORD, nBegin, nEnd );
1597 while( aScanner.NextWord() )
1598 {
1599 nBegin = aScanner.GetBegin();
1600 nLen = aScanner.GetLen();
1601 if( rACW.GetMinWordLen() <= nLen )
1602 {
1603 const OUString& rWord = aScanner.GetWord();
1604
1605 if( nActPos < nBegin || ( nBegin + nLen ) < nActPos )
1606 {
1607 if( rACW.GetMinWordLen() <= rWord.getLength() )
1608 rACW.InsertWord( rWord, rDoc );
1609 }
1610 else
1611 bACWDirty = true;
1612 }
1613 if( !--nCnt )
1614 {
1615 // don't wait for TIMER here, so we can finish big paragraphs
1616 if (Application::AnyInput(VCL_INPUT_ANY & VclInputFlags(~VclInputFlags::TIMER)))
1617 return;
1618 nCnt = 100;
1619 }
1620 }
1621 }
1622
1623 if (!bACWDirty)
1624 pNode->SetAutoCompleteWordDirty( false );
1625}
1626
1628 SwTextFrame const& rFrame, SwTextNode const& rNode,
1629 SwInterHyphInfo const& rHyphInfo)
1630 : m_nStart(rFrame.MapModelToView(&rNode, rHyphInfo.m_nStart))
1631 , m_nEnd(rFrame.MapModelToView(&rNode, rHyphInfo.m_nEnd))
1632 , m_nWordStart(0)
1633 , m_nWordLen(0)
1634{
1635}
1636
1638 SwTextNode const& rNode, SwInterHyphInfo & o_rHyphInfo)
1639{
1640 std::pair<SwTextNode const*, sal_Int32> const wordStart(rFrame.MapViewToModel(m_nWordStart));
1641 std::pair<SwTextNode const*, sal_Int32> const wordEnd(rFrame.MapViewToModel(m_nWordStart+m_nWordLen));
1642 if (wordStart.first != &rNode || wordEnd.first != &rNode)
1643 { // not sure if this can happen since nStart/nEnd are in rNode
1644 SAL_WARN("sw.core", "UpdateTextNodeHyphInfo: outside of node");
1645 return;
1646 }
1647 o_rHyphInfo.m_nWordStart = wordStart.second;
1648 o_rHyphInfo.m_nWordLen = wordEnd.second - wordStart.second;
1649 o_rHyphInfo.SetHyphWord(m_xHyphWord);
1650}
1651
1654{
1655 // shortcut: paragraph doesn't have a language set:
1657 && LanguageType(USHRT_MAX) == GetLang(0, m_Text.getLength()))
1658 {
1659 return false;
1660 }
1661
1663 [&rHyphInf, this]() {
1664 std::pair<Point, bool> tmp;
1665 Point const*const pPoint = rHyphInf.GetCursorPos();
1666 if (pPoint)
1667 {
1668 tmp.first = *pPoint;
1669 tmp.second = true;
1670 }
1671 return static_cast<SwTextFrame*>(this->getLayoutFrame(
1672 this->GetDoc().getIDocumentLayoutAccess().GetCurrentLayout(),
1673 nullptr, pPoint ? &tmp : nullptr));
1674 });
1675 if (!pFrame)
1676 {
1677 // There was a comment here that claimed that the following assertion
1678 // shouldn't exist as it's triggered by "Trennung ueber Sonderbereiche",
1679 // (hyphenation across special sections?), whatever that means.
1680 OSL_ENSURE( pFrame, "!SwTextNode::Hyphenate: can't find any frame" );
1681 return false;
1682 }
1683 SwInterHyphInfoTextFrame aHyphInfo(*pFrame, *this, rHyphInf);
1684
1685 pFrame = &(pFrame->GetFrameAtOfst( aHyphInfo.m_nStart ));
1686
1687 while( pFrame )
1688 {
1689 if (pFrame->Hyphenate(aHyphInfo))
1690 {
1691 // The layout is not robust wrt. "direct formatting"
1692 // cf. layact.cxx, SwLayAction::TurboAction_(), if( !pCnt->IsValid() ...
1693 pFrame->SetCompletePaint();
1694 aHyphInfo.UpdateTextNodeHyphInfo(*pFrame, *this, rHyphInf);
1695 return true;
1696 }
1697 pFrame = pFrame->GetFollow();
1698 if( pFrame )
1699 {
1700 aHyphInfo.m_nEnd = aHyphInfo.m_nEnd - (pFrame->GetOffset() - aHyphInfo.m_nStart);
1701 aHyphInfo.m_nStart = pFrame->GetOffset();
1702 }
1703 }
1704 return false;
1705}
1706
1707namespace
1708{
1709 struct swTransliterationChgData
1710 {
1711 sal_Int32 nStart;
1712 sal_Int32 nLen;
1713 OUString sChanged;
1714 Sequence< sal_Int32 > aOffsets;
1715 };
1716}
1717
1718// change text to Upper/Lower/Hiragana/Katakana/...
1721 sal_Int32 nStt, sal_Int32 nEnd,
1722 SwUndoTransliterate* pUndo, bool bUseRedlining )
1723{
1724 if (nStt >= nEnd)
1725 return;
1726
1727 const sal_Int32 selStart = nStt;
1728 const sal_Int32 selEnd = nEnd;
1729
1730 // since we don't use Hiragana/Katakana or half-width/full-width transliterations here
1731 // it is fine to use ANYWORD_IGNOREWHITESPACES. (ANY_WORD btw is broken and will
1732 // occasionally miss words in consecutive sentences). Also with ANYWORD_IGNOREWHITESPACES
1733 // text like 'just-in-time' will be converted to 'Just-In-Time' which seems to be the
1734 // proper thing to do.
1735 const sal_Int16 nWordType = WordType::ANYWORD_IGNOREWHITESPACES;
1736
1737 // In order to have less trouble with changing text size, e.g. because
1738 // of ligatures or German small sz being resolved, we need to process
1739 // the text replacements from end to start.
1740 // This way the offsets for the yet to be changed words will be
1741 // left unchanged by the already replaced text.
1742 // For this we temporarily save the changes to be done in this vector
1743 std::vector< swTransliterationChgData > aChanges;
1744 swTransliterationChgData aChgData;
1745
1746 if (rTrans.getType() == TransliterationFlags::TITLE_CASE)
1747 {
1748 // for 'capitalize every word' we need to iterate over each word
1749
1750 Boundary aSttBndry;
1751 Boundary aEndBndry;
1752 aSttBndry = g_pBreakIt->GetBreakIter()->getWordBoundary(
1753 GetText(), nStt,
1754 g_pBreakIt->GetLocale( GetLang( nStt ) ),
1755 nWordType,
1756 true /*prefer forward direction*/);
1757 aEndBndry = g_pBreakIt->GetBreakIter()->getWordBoundary(
1758 GetText(), nEnd,
1759 g_pBreakIt->GetLocale( GetLang( nEnd ) ),
1760 nWordType,
1761 false /*prefer backward direction*/);
1762
1763 // prevent backtracking to the previous word if selection is at word boundary
1764 if (aSttBndry.endPos <= nStt)
1765 {
1766 aSttBndry = g_pBreakIt->GetBreakIter()->nextWord(
1767 GetText(), aSttBndry.endPos,
1768 g_pBreakIt->GetLocale( GetLang( aSttBndry.endPos ) ),
1769 nWordType);
1770 }
1771 // prevent advancing to the next word if selection is at word boundary
1772 if (aEndBndry.startPos >= nEnd)
1773 {
1774 aEndBndry = g_pBreakIt->GetBreakIter()->previousWord(
1775 GetText(), aEndBndry.startPos,
1776 g_pBreakIt->GetLocale( GetLang( aEndBndry.startPos ) ),
1777 nWordType);
1778 }
1779
1780 /* Nothing to do if user selection lies entirely outside of word start and end boundary computed above.
1781 * Skip this node, because otherwise the below logic for constraining to the selection will fail */
1782 if (aSttBndry.startPos >= selEnd || aEndBndry.endPos <= selStart) {
1783 return;
1784 }
1785
1786 // prevent going outside of the user's selection, which may
1787 // start in the middle of a word
1788 aSttBndry.startPos = std::max(aSttBndry.startPos, selStart);
1789 aEndBndry.startPos = std::max(aSttBndry.startPos, aEndBndry.startPos);
1790
1791 Boundary aCurWordBndry( aSttBndry );
1792 while (aCurWordBndry.startPos <= aEndBndry.startPos)
1793 {
1794 nStt = aCurWordBndry.startPos;
1795 nEnd = aCurWordBndry.endPos;
1796 const sal_Int32 nLen = nEnd - nStt;
1797 OSL_ENSURE( nLen > 0, "invalid word length of 0" );
1798
1799 Sequence <sal_Int32> aOffsets;
1800 OUString const sChgd( rTrans.transliterate(
1801 GetText(), GetLang(nStt), nStt, nLen, &aOffsets) );
1802
1803 assert(nStt < m_Text.getLength());
1804 if (0 != rtl_ustr_shortenedCompare_WithLength(
1805 m_Text.getStr() + nStt, m_Text.getLength() - nStt,
1806 sChgd.getStr(), sChgd.getLength(), nLen))
1807 {
1808 aChgData.nStart = nStt;
1809 aChgData.nLen = nLen;
1810 aChgData.sChanged = sChgd;
1811 aChgData.aOffsets = aOffsets;
1812 aChanges.push_back( aChgData );
1813 }
1814
1815 aCurWordBndry = g_pBreakIt->GetBreakIter()->nextWord(
1816 GetText(), nStt,
1817 g_pBreakIt->GetLocale(GetLang(nStt, 1)),
1818 nWordType);
1819 }
1820 }
1821 else if (rTrans.getType() == TransliterationFlags::SENTENCE_CASE)
1822 {
1823 // For 'sentence case' we need to iterate sentence by sentence.
1824 // nLastStart and nLastEnd are the boundaries of the last sentence in
1825 // the user's selection.
1826 sal_Int32 nLastStart = g_pBreakIt->GetBreakIter()->beginOfSentence(
1827 GetText(), nEnd,
1828 g_pBreakIt->GetLocale( GetLang( nEnd ) ) );
1829 sal_Int32 nLastEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1830 GetText(), nLastStart,
1831 g_pBreakIt->GetLocale( GetLang( nLastStart ) ) );
1832
1833 // Begin with the starting point of the user's selection (it may not be
1834 // the beginning of a sentence)...
1835 sal_Int32 nCurrentStart = nStt;
1836 // ...And extend to the end of the first sentence
1837 sal_Int32 nCurrentEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1838 GetText(), nCurrentStart,
1839 g_pBreakIt->GetLocale( GetLang( nCurrentStart ) ) );
1840
1841 // prevent backtracking to the previous sentence if selection starts at end of a sentence
1842 if (nCurrentEnd <= nStt)
1843 {
1844 // now nCurrentStart is probably located on a non-letter word. (unless we
1845 // are in Asian text with no spaces...)
1846 // Thus to get the real sentence start we should locate the next real word,
1847 // that is one found by DICTIONARY_WORD
1848 i18n::Boundary aBndry = g_pBreakIt->GetBreakIter()->nextWord(
1849 GetText(), nCurrentEnd,
1850 g_pBreakIt->GetLocale( GetLang( nCurrentEnd ) ),
1851 i18n::WordType::DICTIONARY_WORD);
1852
1853 // now get new current sentence boundaries
1854 nCurrentStart = g_pBreakIt->GetBreakIter()->beginOfSentence(
1855 GetText(), aBndry.startPos,
1856 g_pBreakIt->GetLocale( GetLang( aBndry.startPos) ) );
1857 nCurrentEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1858 GetText(), nCurrentStart,
1859 g_pBreakIt->GetLocale( GetLang( nCurrentStart) ) );
1860 }
1861 // prevent advancing to the next sentence if selection ends at start of a sentence
1862 if (nLastStart >= nEnd)
1863 {
1864 // now nCurrentStart is probably located on a non-letter word. (unless we
1865 // are in Asian text with no spaces...)
1866 // Thus to get the real sentence start we should locate the previous real word,
1867 // that is one found by DICTIONARY_WORD
1868 i18n::Boundary aBndry = g_pBreakIt->GetBreakIter()->previousWord(
1869 GetText(), nLastStart,
1870 g_pBreakIt->GetLocale( GetLang( nLastStart) ),
1871 i18n::WordType::DICTIONARY_WORD);
1872 nLastEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1873 GetText(), aBndry.startPos,
1874 g_pBreakIt->GetLocale( GetLang( aBndry.startPos) ) );
1875 if (nCurrentEnd > nLastEnd)
1876 nCurrentEnd = nLastEnd;
1877 }
1878
1879 // Prevent going outside of the user's selection
1880 nCurrentStart = std::max(selStart, nCurrentStart);
1881 nCurrentEnd = std::min(selEnd, nCurrentEnd);
1882 nLastEnd = std::min(selEnd, nLastEnd);
1883
1884 while (nCurrentStart < nLastEnd)
1885 {
1886 sal_Int32 nLen = nCurrentEnd - nCurrentStart;
1887 OSL_ENSURE( nLen > 0, "invalid word length of 0" );
1888
1889 Sequence <sal_Int32> aOffsets;
1890 OUString const sChgd( rTrans.transliterate(GetText(),
1891 GetLang(nCurrentStart), nCurrentStart, nLen, &aOffsets) );
1892
1893 assert(nStt < m_Text.getLength());
1894 if (0 != rtl_ustr_shortenedCompare_WithLength(
1895 m_Text.getStr() + nStt, m_Text.getLength() - nStt,
1896 sChgd.getStr(), sChgd.getLength(), nLen))
1897 {
1898 aChgData.nStart = nCurrentStart;
1899 aChgData.nLen = nLen;
1900 aChgData.sChanged = sChgd;
1901 aChgData.aOffsets = aOffsets;
1902 aChanges.push_back( aChgData );
1903 }
1904
1905 Boundary aFirstWordBndry = g_pBreakIt->GetBreakIter()->nextWord(
1906 GetText(), nCurrentEnd,
1907 g_pBreakIt->GetLocale( GetLang( nCurrentEnd ) ),
1908 nWordType);
1909 nCurrentStart = aFirstWordBndry.startPos;
1910 nCurrentEnd = g_pBreakIt->GetBreakIter()->endOfSentence(
1911 GetText(), nCurrentStart,
1912 g_pBreakIt->GetLocale( GetLang( nCurrentStart ) ) );
1913 }
1914 }
1915 else
1916 {
1917 // here we may transliterate over complete language portions...
1918
1919 std::unique_ptr<SwLanguageIterator> pIter;
1920 if( rTrans.needLanguageForTheMode() )
1921 pIter.reset(new SwLanguageIterator( *this, nStt ));
1922
1923 sal_Int32 nEndPos = 0;
1925 do {
1926 if( pIter )
1927 {
1928 nLang = pIter->GetLanguage();
1929 nEndPos = pIter->GetChgPos();
1930 if( nEndPos > nEnd )
1931 nEndPos = nEnd;
1932 }
1933 else
1934 {
1936 nEndPos = nEnd;
1937 }
1938 const sal_Int32 nLen = nEndPos - nStt;
1939
1940 Sequence <sal_Int32> aOffsets;
1941 OUString const sChgd( rTrans.transliterate(
1942 m_Text, nLang, nStt, nLen, &aOffsets) );
1943
1944 assert(nStt < m_Text.getLength());
1945 if (0 != rtl_ustr_shortenedCompare_WithLength(
1946 m_Text.getStr() + nStt, m_Text.getLength() - nStt,
1947 sChgd.getStr(), sChgd.getLength(), nLen))
1948 {
1949 aChgData.nStart = nStt;
1950 aChgData.nLen = nLen;
1951 aChgData.sChanged = sChgd;
1952 aChgData.aOffsets = aOffsets;
1953 aChanges.push_back( aChgData );
1954 }
1955
1956 nStt = nEndPos;
1957 } while( nEndPos < nEnd && pIter && pIter->Next() );
1958 }
1959
1960 if (aChanges.empty())
1961 return;
1962
1963 // now apply the changes from end to start to leave the offsets of the
1964 // yet unchanged text parts remain the same.
1965 size_t nSum(0);
1966
1967 for (size_t i = 0; i < aChanges.size(); ++i)
1968 { // check this here since AddChanges cannot be moved below
1969 // call to ReplaceTextOnly
1970 swTransliterationChgData & rData =
1971 aChanges[ aChanges.size() - 1 - i ];
1972
1973 nSum += rData.sChanged.getLength() - rData.nLen;
1974 if (nSum > o3tl::make_unsigned(GetSpaceLeft()))
1975 {
1976 SAL_WARN("sw.core", "SwTextNode::ReplaceTextOnly: "
1977 "node text with insertion > node capacity.");
1978 return;
1979 }
1980
1981 if ( bUseRedlining )
1982 {
1983 // create SwPaM with mark & point spanning the attributed text
1984 //SwPaM aCurPaM( *this, *this, nBegin, nBegin + nLen ); <-- wrong c-tor, does sth different
1985 SwPaM aCurPaM( *this, rData.nStart );
1986 aCurPaM.SetMark();
1987 aCurPaM.GetPoint()->SetContent( rData.nStart + rData.nLen );
1988 // replace the changed words
1989 if ( aCurPaM.GetText() != rData.sChanged )
1990 GetDoc().getIDocumentContentOperations().ReplaceRange( aCurPaM, rData.sChanged, false );
1991 }
1992 else
1993 {
1994 if (pUndo)
1995 pUndo->AddChanges( *this, rData.nStart, rData.nLen, rData.aOffsets );
1996 ReplaceTextOnly( rData.nStart, rData.nLen, rData.sChanged, rData.aOffsets );
1997 }
1998 }
1999}
2000
2001void SwTextNode::ReplaceTextOnly( sal_Int32 nPos, sal_Int32 nLen,
2002 std::u16string_view aText,
2003 const Sequence<sal_Int32>& rOffsets )
2004{
2005 assert(sal_Int32(aText.size()) - nLen <= GetSpaceLeft());
2006
2007 m_Text = m_Text.replaceAt(nPos, nLen, aText);
2008
2009 sal_Int32 nTLen = aText.size();
2010 const sal_Int32* pOffsets = rOffsets.getConstArray();
2011 // now look for no 1-1 mapping -> move the indices!
2012 sal_Int32 nMyOff = nPos;
2013 for( sal_Int32 nI = 0; nI < nTLen; ++nI )
2014 {
2015 const sal_Int32 nOff = pOffsets[ nI ];
2016 if( nOff < nMyOff )
2017 {
2018 // something is inserted
2019 sal_Int32 nCnt = 1;
2020 while( nI + nCnt < nTLen && nOff == pOffsets[ nI + nCnt ] )
2021 ++nCnt;
2022
2023 Update(SwContentIndex(this, nMyOff), nCnt, UpdateMode::Default);
2024 nMyOff = nOff;
2025 //nMyOff -= nCnt;
2026 nI += nCnt - 1;
2027 }
2028 else if( nOff > nMyOff )
2029 {
2030 // something is deleted
2031 Update(SwContentIndex(this, nMyOff + 1), nOff - nMyOff, UpdateMode::Negative);
2032 nMyOff = nOff;
2033 }
2034 ++nMyOff;
2035 }
2036 if( nMyOff < nLen )
2037 // something is deleted at the end
2038 Update(SwContentIndex(this, nMyOff), nLen - nMyOff, UpdateMode::Negative);
2039
2040 // notify the layout!
2041 const auto aDelHint = sw::DeleteText(nPos, nTLen);
2042 CallSwClientNotify(aDelHint);
2043
2044 const auto aInsHint = sw::MakeInsertText(*this, nPos, nTLen);
2045 CallSwClientNotify(aInsHint);
2046}
2047
2048// the return values allows us to see if we did the heavy-
2049// lifting required to actually break and count the words.
2051 sal_Int32 nStt, sal_Int32 nEnd ) const
2052{
2053 if( nStt > nEnd )
2054 { // bad call
2055 return false;
2056 }
2057 if (IsInRedlines())
2058 { //not counting txtnodes used to hold deleted redline content
2059 return false;
2060 }
2061 bool bCountAll = ( (0 == nStt) && (GetText().getLength() == nEnd) );
2062 ++rStat.nAllPara; // #i93174#: count _all_ paragraphs
2063 if ( IsHidden() )
2064 { // not counting hidden paras
2065 return false;
2066 }
2067 // count words in numbering string if started at beginning of para:
2068 bool bCountNumbering = nStt == 0;
2069 bool bHasBullet = false, bHasNumbering = false;
2070 OUString sNumString;
2071 if (bCountNumbering)
2072 {
2073 sNumString = GetNumString();
2074 bHasNumbering = !sNumString.isEmpty();
2075 if (!bHasNumbering)
2076 bHasBullet = HasBullet();
2077 bCountNumbering = bHasNumbering || bHasBullet;
2078 }
2079
2080 if( nStt == nEnd && !bCountNumbering)
2081 { // unnumbered empty node or empty selection
2082 if (bCountAll)
2083 {
2084 SetWordCountDirty( false ); // reset flag to speed up DoIdleJob
2085 }
2086 return false;
2087 }
2088
2089 // count of non-empty paras
2090 ++rStat.nPara;
2091
2092 // Shortcut when counting whole paragraph and current count is clean
2093 if ( bCountAll && !IsWordCountDirty() )
2094 {
2095 // accumulate into DocStat record to return the values
2096
2101 return false;
2102 }
2103
2104 // ConversionMap to expand fields, remove invisible and redline deleted text for scanner
2105 const ModelToViewHelper aConversionMap(*this,
2106 getIDocumentLayoutAccess().GetCurrentLayout(),
2108 const OUString& aExpandText = aConversionMap.getViewText();
2109
2110 if (aExpandText.isEmpty() && !bCountNumbering)
2111 {
2112 if (bCountAll)
2113 {
2114 SetWordCountDirty( false ); // reset flag to speed up DoIdleJob
2115 }
2116 return false;
2117 }
2118
2119 // map start and end points onto the ConversionMap
2120 const sal_Int32 nExpandBegin = aConversionMap.ConvertToViewPosition( nStt );
2121 const sal_Int32 nExpandEnd = aConversionMap.ConvertToViewPosition( nEnd );
2122
2123 //do the count
2124 // all counts exclude hidden paras and hidden+redlined within para
2125 // definition of space/white chars in SwScanner (and BreakIter!)
2126 // uses both u_isspace and BreakIter getWordBoundary in SwScanner
2127 sal_uInt32 nTmpWords = 0; // count of all words
2128 sal_uInt32 nTmpAsianWords = 0; //count of all Asian codepoints
2129 sal_uInt32 nTmpChars = 0; // count of all chars
2130 sal_uInt32 nTmpCharsExcludingSpaces = 0; // all non-white chars
2131
2132 // count words in masked and expanded text:
2133 if (!aExpandText.isEmpty())
2134 {
2135 assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
2136
2137 // zero is NULL for pLanguage -----------v last param = true for clipping
2138 SwScanner aScanner( *this, aExpandText, nullptr, aConversionMap, i18n::WordType::WORD_COUNT,
2139 nExpandBegin, nExpandEnd, true );
2140
2141 // used to filter out scanner returning almost empty strings (len=1; unichar=0x0001)
2142 const OUString aBreakWord( CH_TXTATR_BREAKWORD );
2143
2144 while ( aScanner.NextWord() )
2145 {
2146 if( !aExpandText.match(aBreakWord, aScanner.GetBegin() ))
2147 {
2148 ++nTmpWords;
2149 const OUString &rWord = aScanner.GetWord();
2150 if (g_pBreakIt->GetBreakIter()->getScriptType(rWord, 0) == i18n::ScriptType::ASIAN)
2151 ++nTmpAsianWords;
2152 nTmpCharsExcludingSpaces += g_pBreakIt->getGraphemeCount(rWord);
2153 }
2154 }
2155
2156 nTmpCharsExcludingSpaces += aScanner.getOverriddenDashCount();
2157
2158 nTmpChars = g_pBreakIt->getGraphemeCount(aExpandText, nExpandBegin, nExpandEnd);
2159 }
2160
2161 // no nTmpCharsExcludingSpaces adjust needed neither for blanked out MaskedChars
2162 // nor for mid-word selection - set scanner bClip = true at creation
2163
2164 // count outline number label - ? no expansion into map
2165 // always counts all of number-ish label
2166 if (bHasNumbering) // count words in numbering string
2167 {
2168 LanguageType aLanguage = GetLang( 0 );
2169
2170 SwScanner aScanner( *this, sNumString, &aLanguage, ModelToViewHelper(),
2171 i18n::WordType::WORD_COUNT, 0, sNumString.getLength(), true );
2172
2173 while ( aScanner.NextWord() )
2174 {
2175 ++nTmpWords;
2176 const OUString &rWord = aScanner.GetWord();
2177 if (g_pBreakIt->GetBreakIter()->getScriptType(rWord, 0) == i18n::ScriptType::ASIAN)
2178 ++nTmpAsianWords;
2179 nTmpCharsExcludingSpaces += g_pBreakIt->getGraphemeCount(rWord);
2180 }
2181
2182 nTmpCharsExcludingSpaces += aScanner.getOverriddenDashCount();
2183 nTmpChars += g_pBreakIt->getGraphemeCount(sNumString);
2184 }
2185 else if ( bHasBullet )
2186 {
2187 ++nTmpWords;
2188 ++nTmpChars;
2189 ++nTmpCharsExcludingSpaces;
2190 }
2191
2192 // If counting the whole para then update cached values and mark clean
2193 if ( bCountAll )
2194 {
2198 m_aParagraphIdleData.nNumberOfCharsExcludingSpaces = nTmpCharsExcludingSpaces;
2199 SetWordCountDirty( false );
2200 }
2201 // accumulate into DocStat record to return the values
2202 rStat.nWord += nTmpWords;
2203 rStat.nAsianWord += nTmpAsianWords;
2204 rStat.nChar += nTmpChars;
2205 rStat.nCharExcludingSpaces += nTmpCharsExcludingSpaces;
2206
2207 return true;
2208}
2209
2210void SwTextNode::SetWrong( std::unique_ptr<SwWrongList> pNew )
2211{
2212 m_aParagraphIdleData.pWrong = std::move(pNew);
2213}
2214
2216{
2218}
2219
2220std::unique_ptr<SwWrongList> SwTextNode::ReleaseWrong()
2221{
2222 return std::move(m_aParagraphIdleData.pWrong);
2223}
2224
2226{
2227 return m_aParagraphIdleData.pWrong.get();
2228}
2229
2230// #i71360#
2232{
2233 return m_aParagraphIdleData.pWrong.get();
2234}
2235
2236void SwTextNode::SetGrammarCheck( std::unique_ptr<SwGrammarMarkUp> pNew )
2237{
2238 m_aParagraphIdleData.pGrammarCheck = std::move(pNew);
2239}
2240
2242{
2244}
2245
2246std::unique_ptr<SwGrammarMarkUp> SwTextNode::ReleaseGrammarCheck()
2247{
2248 return std::move(m_aParagraphIdleData.pGrammarCheck);
2249}
2250
2252{
2254}
2255
2257{
2258 return static_cast<SwWrongList const*>(const_cast<SwTextNode*>(this)->GetGrammarCheck());
2259}
2260
2261void SwTextNode::SetSmartTags( std::unique_ptr<SwWrongList> pNew )
2262{
2263 OSL_ENSURE( !pNew || SwSmartTagMgr::Get().IsSmartTagsEnabled(),
2264 "Weird - we have a smart tag list without any recognizers?" );
2265
2266 m_aParagraphIdleData.pSmartTags = std::move(pNew);
2267}
2268
2270{
2272}
2273
2274std::unique_ptr<SwWrongList> SwTextNode::ReleaseSmartTags()
2275{
2276 return std::move(m_aParagraphIdleData.pSmartTags);
2277}
2278
2280{
2281 return m_aParagraphIdleData.pSmartTags.get();
2282}
2283
2285{
2286 return const_cast<SwWrongList const*>(const_cast<SwTextNode*>(this)->GetSmartTags());
2287}
2288
2289void SwTextNode::SetWordCountDirty( bool bNew ) const
2290{
2292}
2293
2295{
2297}
2298
2300{
2302}
2303
2305{
2307}
2308
2310{
2312}
2313
2315{
2317}
2318
2320{
2322}
2323
2324void SwTextNode::SetSmartTagDirty( bool bNew ) const
2325{
2327}
2328
2330{
2332}
2333
2335{
2337}
2338
2340{
2342}
2343
2344// <-- Paragraph statistics end
2345
2346/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const sal_Int32 m_nLength
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:34
static bool AnyInput(VclInputFlags nType=VCL_INPUT_ANY)
bool isLetterNumeric(const OUString &rStr, sal_Int32 nPos) const
virtual bool ReplaceRange(SwPaM &rPam, const OUString &rNewStr, const bool bRegExReplace)=0
Replace selected range in a TextNode with string.
virtual void InsertItemSet(const SwPaM &rRg, const SfxItemSet &, const SetAttrMode nFlags=SetAttrMode::DEFAULT, SwRootFrame const *pLayout=nullptr)=0
static bool IsShowChanges(const RedlineFlags eM)
virtual SwRedlineTable::size_type GetRedlinePos(const SwNode &rNode, RedlineType nType) const =0
virtual const SwRedlineTable & GetRedlineTable() const =0
virtual RedlineFlags GetRedlineFlags() const =0
Query the currently set redline mode.
virtual std::shared_ptr< SfxItemSet > getAutomaticStyle(const SfxItemSet &rSet, SwAutoStyleFamily eFamily, const OUString *pParentName=nullptr)=0
ModelPosition ConvertToModelPosition(sal_Int32 nViewPos) const
Converts a view position into a model position.
const OUString & getViewText() const
sal_Int32 ConvertToViewPosition(sal_Int32 nModelPos) const
Converts a model position into a view position.
const SfxPoolItem * GetCurItem() const
const SfxPoolItem * NextItem()
sal_uInt16 Count() const
virtual std::unique_ptr< SfxItemSet > Clone(bool bItems=true, SfxItemPool *pToPool=nullptr) const
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
const SfxPoolItem & Get(sal_uInt16 nWhich, bool bSrchInParent=true) const
void MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo)
sal_uInt16 Which() const
void RecognizeTextRange(const css::uno::Reference< css::text::XTextRange > &rRange, const css::uno::Reference< css::text::XTextMarkup > &rMarkup, const css::uno::Reference< css::frame::XController > &rController) const
void RecognizeString(const OUString &rText, const css::uno::Reference< css::text::XTextMarkup > &rMarkup, const css::uno::Reference< css::frame::XController > &rController, const css::lang::Locale &rLocale, sal_uInt32 nStart, sal_uInt32 nLen) const
void SetStyleName(const OUString &rStyleName)
void SetFamily(FontFamily _eFamily)
void SetPitch(FontPitch _ePitch)
void SetFamilyName(const OUString &rFamilyName)
void SetCharSet(rtl_TextEncoding _eEncoding)
static sal_Int16 CheckSpellLang(css::uno::Reference< css::linguistic2::XSpellChecker1 > const &xSpell, LanguageType nLang)
bool InsertWord(const OUString &rWord, SwDoc &rDoc)
Definition: acmplwrd.cxx:219
sal_uInt16 GetMinWordLen() const
Definition: acmplwrd.hxx:64
sal_Int32 getGraphemeCount(const OUString &rStr, sal_Int32 nStart, sal_Int32 nEnd) const
Definition: breakit.cxx:158
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
Marks a character position inside a document model content node (SwContentNode)
SwFormatColl * GetFormatColl() const
Definition: node.hxx:497
SwContentFrame * getLayoutFrame(const SwRootFrame *, const SwPosition *pPos=nullptr, std::pair< Point, bool > const *pViewPosAndCalcFrame=nullptr) const
Definition: node.cxx:1230
const SwAttrSet & GetSwAttrSet() const
Does node has already its own auto-attributes? Access to SwAttrSet.
Definition: node.hxx:765
css::uno::Reference< css::frame::XController > GetController()
Definition: docsh.cxx:1293
Definition: doc.hxx:195
static SwAutoCompleteWord & GetAutoCompleteWords()
Definition: doc.hxx:1550
void SetMissingDictionaries(bool bIsMissing)
Use to notify if the dictionary can be found for a single content portion (has to be called for all p...
Definition: doc.cxx:1849
IDocumentContentOperations const & getIDocumentContentOperations() const
Definition: doc.cxx:323
IDocumentRedlineAccess const & getIDocumentRedlineAccess() const
Definition: doc.cxx:343
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:330
::sw::DocumentSettingManager & GetDocumentSettingManager()
Definition: doc.cxx:194
SwDocShell * GetDocShell()
Definition: doc.hxx:1362
const std::shared_ptr< SfxItemSet > & GetStyleHandle() const
Definition: fmtautofmt.hxx:49
SwRect GetPaintArea() const
|* The paintarea is the area, in which the content of a frame is allowed |* to be displayed.
Definition: ssfrm.cxx:593
SwRootFrame * getRootFrame()
Definition: frame.hxx:680
void SetCompletePaint() const
Definition: frame.hxx:995
a clone of SwInterHyphInfo, but with TextFrameIndex instead of node index
Definition: txtfrm.hxx:58
TextFrameIndex m_nWordLen
Definition: txtfrm.hxx:68
SwInterHyphInfoTextFrame(SwTextFrame const &rFrame, SwTextNode const &rNode, SwInterHyphInfo const &rHyphInfo)
Definition: txtedt.cxx:1627
TextFrameIndex m_nEnd
Definition: txtfrm.hxx:65
TextFrameIndex m_nStart
input: requested range to hyphenate
Definition: txtfrm.hxx:64
css::uno::Reference< css::linguistic2::XHyphenatedWord > m_xHyphWord
output: hyphenated word
Definition: txtfrm.hxx:61
void UpdateTextNodeHyphInfo(SwTextFrame const &rFrame, SwTextNode const &rNode, SwInterHyphInfo &o_rHyphInfo)
Definition: txtedt.cxx:1637
TextFrameIndex m_nWordStart
output: found word
Definition: txtfrm.hxx:67
void SetHyphWord(const css::uno::Reference< css::linguistic2::XHyphenatedWord > &rxHW)
Definition: splargs.hxx:131
sal_Int32 m_nWordStart
output: found word
Definition: splargs.hxx:117
const Point * GetCursorPos() const
Definition: splargs.hxx:127
sal_Int32 m_nWordLen
Definition: splargs.hxx:118
LanguageType GetLanguage() const
Definition: txatritr.hxx:68
sal_Int32 GetChgPos() const
Definition: txatritr.hxx:67
SwTextNode * GetTextNode()
Inline methods from Node.hxx.
Definition: ndtxt.hxx:897
SwNodeOffset GetIndex() const
Definition: node.hxx:312
SwDoc & GetDoc()
Definition: node.hxx:233
bool IsInRedlines() const
Checks if this node is in redlines.
Definition: node.cxx:2170
IStyleAccess & getIDocumentStyleAccess()
Provides access to the document automatic styles interface.
Definition: node.cxx:2168
const IDocumentLayoutAccess & getIDocumentLayoutAccess() const
Provides access to the document layout interface.
Definition: node.cxx:2158
PaM is Point and Mark: a selection of the document model.
Definition: pam.hxx:187
virtual void SetMark()
Unless this is called, the getter method of Mark will return Point.
Definition: pam.cxx:642
OUString GetText() const
Definition: pam.cxx:1282
const SwPosition * GetPoint() const
Definition: pam.hxx:261
const SwPosition * Start() const
Definition: pam.hxx:266
void CalcStartEnd(SwNodeOffset nNdIdx, sal_Int32 &rStart, sal_Int32 &rEnd) const
Calculates the intersection with text node number nNdIdx.
Definition: docredln.cxx:1435
RedlineType GetType(sal_uInt16 nPos=0) const
Definition: docredln.cxx:1940
void SetBottom(SwRect &rRect, tools::Long nNew) const
Definition: frame.hxx:1387
void SetRight(SwRect &rRect, tools::Long nNew) const
Definition: frame.hxx:1389
tools::Long GetTop(const SwRect &rRect) const
Definition: frame.hxx:1377
tools::Long GetLeft(const SwRect &rRect) const
Definition: frame.hxx:1379
tools::Long GetBottom(const SwRect &rRect) const
Definition: frame.hxx:1378
void SetTop(SwRect &rRect, tools::Long nNew) const
Definition: frame.hxx:1386
tools::Long GetRight(const SwRect &rRect) const
Definition: frame.hxx:1380
void SetLeft(SwRect &rRect, tools::Long nNew) const
Definition: frame.hxx:1388
Of course Writer needs its own rectangles.
Definition: swrect.hxx:35
void Height(tools::Long nNew)
Definition: swrect.hxx:193
SwRect & Union(const SwRect &rRect)
Definition: swrect.cxx:35
size_type size() const
Definition: docary.hxx:267
vector_type::size_type size_type
Definition: docary.hxx:222
SwViewShell * GetCurrShell() const
Definition: rootfrm.hxx:208
const LanguageType * m_pLanguage
Definition: swscanner.hxx:38
sal_uInt16 m_nWordType
Definition: swscanner.hxx:46
sal_Int32 m_nLength
Definition: swscanner.hxx:43
const ModelToViewHelper m_ModelToView
Definition: swscanner.hxx:39
bool m_bClip
Definition: swscanner.hxx:47
const OUString m_aPreDashReplacementText
Definition: swscanner.hxx:36
LanguageType m_aCurrentLang
Definition: swscanner.hxx:45
sal_Int32 m_nEndPos
Definition: swscanner.hxx:41
sal_Int32 GetBegin() const
Definition: swscanner.hxx:66
OUString m_aText
Definition: swscanner.hxx:37
sal_Int32 GetLen() const
Definition: swscanner.hxx:68
const OUString & GetWord() const
Definition: swscanner.hxx:64
sal_Int32 getOverriddenDashCount() const
Definition: swscanner.hxx:72
sal_Int32 m_nStartPos
Definition: swscanner.hxx:40
sal_Int32 GetEnd() const
Definition: swscanner.hxx:67
std::function< LanguageType(sal_Int32, sal_Int32, bool)> m_pGetLangOfChar
Definition: swscanner.hxx:34
sal_Int32 m_nBegin
Definition: swscanner.hxx:42
OUString m_aWord
Definition: swscanner.hxx:35
bool NextWord()
Definition: txtedt.cxx:830
SwScanner(std::function< LanguageType(sal_Int32, sal_Int32, bool)> pGetLangOfChar, OUString aText, const LanguageType *pLang, ModelToViewHelper aConvMap, sal_uInt16 nWordType, sal_Int32 nStart, sal_Int32 nEnd, bool bClip=false)
Definition: txtedt.cxx:737
sal_Int32 m_nOverriddenDashCount
Definition: swscanner.hxx:44
LanguageType GetCurrentLanguage() const
Definition: swscanner.hxx:70
static sal_Int32 MaskHiddenRanges(const SwTextNode &rNode, OUStringBuffer &rText, const sal_Int32 nStt, const sal_Int32 nEnd, const sal_Unicode cChar)
Hidden text attribute handling.
Definition: porlay.cxx:1998
static SwSmartTagMgr & Get()
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
const SfxPoolItem & GetAttr() const
Definition: txatbase.hxx:167
virtual const sal_Int32 * GetEnd() const
end position
Definition: txatbase.cxx:48
const sal_Int32 * End() const
Definition: txatbase.hxx:156
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
virtual void SetEnd(sal_Int32)
Definition: txatbase.cxx:53
void SetStart(sal_Int32 n)
start position
Definition: txatbase.hxx:87
bool HasContent() const
Definition: txatbase.hxx:112
sal_uInt16 Which() const
Definition: txatbase.hxx:116
void SetSortNumber(sal_uInt16 nSortNumber)
Definition: txtatr.hxx:48
sal_uInt16 GetSortNumber() const
Definition: txtatr.hxx:49
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:165
SwTextFrame * GetFollow()
Definition: txtfrm.hxx:861
TextFrameIndex GetOffset() const
Definition: txtfrm.hxx:444
std::pair< SwTextNode *, sal_Int32 > MapViewToModel(TextFrameIndex nIndex) const
map position in potentially merged text frame to SwPosition
Definition: txtfrm.cxx:1231
void CollectAutoCmplWrds(SwTextNode &, sal_Int32)
Is called by DoIdleJob_()
Definition: txtedt.cxx:1577
SwRect SmartTagScan(SwTextNode &)
Is called by DoIdleJob_()
Definition: txtedt.cxx:1461
bool Hyphenate(SwInterHyphInfoTextFrame &rInf)
We format a Line for interactive hyphenation.
Definition: txthyph.cxx:58
TextFrameIndex MapModelToView(SwTextNode const *pNode, sal_Int32 nIndex) const
Definition: txtfrm.cxx:1252
bool IsSymbolAt(TextFrameIndex) const
Definition: itratr.cxx:186
SwRect AutoSpell_(SwTextNode &, sal_Int32)
Is called by DoIdleJob_(), ExecSpellPopup() and UpDown()
Definition: txtedt.cxx:1269
TextFrameIndex MapModelToViewPos(SwPosition const &rPos) const
Definition: txtfrm.cxx:1267
bool IsHiddenNow() const
Hidden.
Definition: txtfrm.cxx:1360
SwTextFrame & GetFrameAtOfst(TextFrameIndex nOfst)
Definition: frmcrsr.cxx:143
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1293
OUString GetCurWord(SwPosition const &) const
Definition: txtedt.cxx:687
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:111
bool HasBullet() const
Returns if this text node has a bullet.
Definition: ndtxt.cxx:3227
OUString m_Text
Definition: ndtxt.hxx:128
sw::ParagraphIdleData m_aParagraphIdleData
Definition: ndtxt.hxx:130
void SetWrongDirty(sw::WrongState eNew) const
Definition: txtedt.cxx:2299
SAL_DLLPRIVATE void SetLanguageAndFont(const SwPaM &rPaM, LanguageType nLang, sal_uInt16 nLangWhichId, const vcl::Font *pFont, sal_uInt16 nFontWhichId)
Definition: txtedt.cxx:1101
sal_Int32 GetSpaceLeft() const
Definition: ndtxt.hxx:914
bool IsSmartTagDirty() const
Definition: txtedt.cxx:2329
SwWrongList * GetSmartTags()
Definition: txtedt.cxx:2279
void RstTextAttr(const sal_Int32 nContentStart, const sal_Int32 nLen, const sal_uInt16 nWhich=0, const SfxItemSet *pSet=nullptr, const bool bInclRefToxMark=false, const bool bExactRange=false)
delete all attributes.
Definition: txtedt.cxx:388
bool IsGrammarCheckDirty() const
Definition: txtedt.cxx:2319
void ClearSmartTags()
Definition: txtedt.cxx:2269
void DestroyAttr(SwTextAttr *pAttr)
Definition: thints.cxx:1186
void TryDeleteSwpHints()
Definition: ndtxt.hxx:883
SwWrongList * GetWrong()
Definition: txtedt.cxx:2225
bool IsAutoCompleteWordDirty() const
Definition: txtedt.cxx:2339
void SetWordCountDirty(bool bNew) const
Definition: txtedt.cxx:2289
void SetGrammarCheckDirty(bool bNew) const
Definition: txtedt.cxx:2314
void SetSmartTags(std::unique_ptr< SwWrongList > pNew)
Definition: txtedt.cxx:2261
void SetSmartTagDirty(bool bNew) const
Definition: txtedt.cxx:2324
void ReplaceTextOnly(sal_Int32 nPos, sal_Int32 nLen, std::u16string_view aText, const css::uno::Sequence< sal_Int32 > &rOffsets)
Definition: txtedt.cxx:2001
std::unique_ptr< SwpHints > m_pSwpHints
May be 0.
Definition: ndtxt.hxx:122
void ClearGrammarCheck()
Definition: txtedt.cxx:2241
bool HasHints() const
Definition: ndtxt.hxx:252
void SetAutoCompleteWordDirty(bool bNew) const
Definition: txtedt.cxx:2334
void ClearWrong()
Definition: txtedt.cxx:2215
std::unique_ptr< SwWrongList > ReleaseSmartTags()
Definition: txtedt.cxx:2274
bool CountWords(SwDocStat &rStat, sal_Int32 nStart, sal_Int32 nEnd) const
count words in given range - returns true if we refreshed out count
Definition: txtedt.cxx:2050
bool Convert(SwConversionArgs &)
Definition: txtedt.cxx:1133
bool IsSymbolAt(sal_Int32 nBegin) const
in ndcopy.cxx
Definition: itratr.cxx:855
bool IsWordCountDirty() const
Definition: txtedt.cxx:2294
std::unique_ptr< SwGrammarMarkUp > ReleaseGrammarCheck()
Definition: txtedt.cxx:2246
SwGrammarMarkUp * GetGrammarCheck()
Definition: txtedt.cxx:2251
virtual void Update(SwContentIndex const &rPos, const sal_Int32 nChangeLen, UpdateMode eMode) override
override SwContentIndexReg
Definition: ndtxt.cxx:1251
bool IsHidden() const
Definition: ndtxt.cxx:4727
sw::WrongState GetWrongDirty() const
Definition: txtedt.cxx:2304
OUString GetNumString(const bool _bInclPrefixAndSuffixStrings=true, const unsigned int _nRestrictToThisLevel=MAXLEVEL, SwRootFrame const *pLayout=nullptr, SwListRedlineType eRedline=SwListRedlineType::SHOW) const
Returns outline of numbering string.
Definition: ndtxt.cxx:3245
bool Spell(SwSpellArgs *)
Definition: txtedt.cxx:971
SwTextAttr * GetTextAttrAt(sal_Int32 const nIndex, sal_uInt16 const nWhich, ::sw::GetTextAttrMode const eMode=::sw::GetTextAttrMode::Default) const
get the innermost text attribute covering position nIndex.
Definition: ndtxt.cxx:1802
bool IsWrongDirty() const
Definition: txtedt.cxx:2309
SwpHints * GetpSwpHints()
Definition: ndtxt.hxx:250
void SetWrong(std::unique_ptr< SwWrongList > pNew)
Definition: txtedt.cxx:2210
const OUString & GetText() const
Definition: ndtxt.hxx:242
void TransliterateText(utl::TransliterationWrapper &rTrans, sal_Int32 nStart, sal_Int32 nEnd, SwUndoTransliterate *pUndo, bool bUseRedlining=false)
change text to Upper/Lower/Hiragana/Katakana/...
Definition: txtedt.cxx:1719
bool InsertHint(SwTextAttr *const pAttr, const SetAttrMode nMode=SetAttrMode::DEFAULT)
Insert pAttr into hints array.
Definition: thints.cxx:1340
LanguageType GetLang(const sal_Int32 nBegin, const sal_Int32 nLen=0, sal_uInt16 nScript=0) const
Definition: thints.cxx:3462
void SetGrammarCheck(std::unique_ptr< SwGrammarMarkUp > pNew)
Definition: txtedt.cxx:2236
SwTextAttr * GetTextAttrForCharAt(const sal_Int32 nIndex, const sal_uInt16 nWhich=RES_TXTATR_END) const
get the text attribute at position nIndex which owns the dummy character CH_TXTATR_* at that position...
Definition: ndtxt.cxx:3153
bool Hyphenate(SwInterHyphInfo &rHyphInf)
Interactive hyphenation: we find TextFrame and call its CalcHyph.
Definition: txtedt.cxx:1653
std::unique_ptr< SwWrongList > ReleaseWrong()
Definition: txtedt.cxx:2220
void AddChanges(SwTextNode &rTNd, sal_Int32 nStart, sal_Int32 nLen, css::uno::Sequence< sal_Int32 > const &rOffsets)
Definition: unovwr.cxx:383
static bool IsAutoCompleteWords()
Definition: viewopt.cxx:319
void InvalidateAccessibleParaAttrs(const SwTextFrame &rTextFrame)
invalidate attributes for paragraphs and paragraph's characters
Definition: viewsh.cxx:2615
const SfxItemPool & GetAttrPool() const
Definition: viewsh.hxx:625
sal_uInt16 Count() const
Definition: wrong.hxx:323
sal_Int32 GetEndInv() const
Definition: wrong.hxx:289
sal_Int32 Pos(sal_uInt16 nIdx) const
Definition: wrong.hxx:318
FreshState Fresh(sal_Int32 &rStart, sal_Int32 &rEnd, sal_Int32 nPos, sal_Int32 nLen, sal_uInt16 nIndex, sal_Int32 nCursorPos)
Remove given range of entries.
Definition: wrong.cxx:356
sal_uInt16 GetWrongPos(sal_Int32 nValue) const
Find the first position that is greater or equal to the given value.
Definition: wrong.cxx:191
bool InWrongWord(sal_Int32 &rChk, sal_Int32 &rLn) const
If a word is incorrectly selected, this method returns begin and length of it.
Definition: wrong.cxx:103
void SetInvalid(sal_Int32 nBegin, sal_Int32 nEnd)
Definition: wrong.cxx:254
void Insert(sal_uInt16 nWhere, std::vector< SwWrongArea >::iterator startPos, std::vector< SwWrongArea >::iterator const &endPos)
Definition: wrong.cxx:538
sal_Int32 GetBeginInv() const
Definition: wrong.hxx:288
sal_Int32 Len(sal_uInt16 nIdx) const
Definition: wrong.hxx:313
sal_Int32 NextWrong(sal_Int32 nChk) const
Find next incorrectly selected position.
Definition: wrong.cxx:164
Implementation of the css::text::XTextMarkup interface.
static rtl::Reference< SwXTextRange > CreateXTextRange(SwDoc &rDoc, const SwPosition &rPos, const SwPosition *const pMark)
Definition: unoobj2.cxx:1199
static bool IsChinese(LanguageType nLang)
virtual bool get(DocumentSettingId id) const override
Return the specified document setting.
OUString transliterate(const OUString &rStr, sal_Int32 nStart, sal_Int32 nLen) const
bool needLanguageForTheMode() const
TransliterationFlags getType() const
FontFamily GetFamilyType()
const OUString & GetStyleName() const
const OUString & GetFamilyName() const
FontPitch GetPitch()
rtl_TextEncoding GetCharSet() const
constexpr TypedWhichId< SvxFontItem > RES_CHRATR_CJK_FONT(22)
bool isTXTATR_WITHEND(const sal_uInt16 nWhich)
Definition: hintids.hxx:474
constexpr TypedWhichId< SwFormatAutoFormat > RES_TXTATR_AUTOFMT(50)
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
constexpr TypedWhichId< SvxLanguageItem > RES_CHRATR_CJK_LANGUAGE(24)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_ANNOTATION(60)
#define CH_TXTATR_INWORD
Definition: hintids.hxx:172
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_METAFIELD(49)
constexpr TypedWhichId< SwFormatRefMark > RES_TXTATR_REFMARK(RES_TXTATR_WITHEND_BEGIN)
constexpr TypedWhichId< SwFormatMeta > RES_TXTATR_META(48)
constexpr TypedWhichId< SwTOXMark > RES_TXTATR_TOXMARK(47)
constexpr TypedWhichId< SwFormatField > RES_TXTATR_INPUTFIELD(55)
#define CH_TXTATR_BREAKWORD
Definition: hintids.hxx:171
CharClass & GetAppCharClass()
Definition: init.cxx:706
VclInputFlags
#define VCL_INPUT_ANY
#define LANGUAGE_SYSTEM
#define LANGUAGE_NONE
sal_uInt16 nPos
#define SAL_WARN(area, stream)
aStr
aBuf
@ HideFieldmarkCommands
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:390
int i
constexpr std::enable_if_t< std::is_signed_v< T >, std::make_unsigned_t< T > > make_unsigned(T value)
Count
end
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SwTextFrame * SwHyphIterCacheLastTextFrame(SwTextNode const *pNode, const sw::Creator &create)
Definition: edlingu.cxx:584
WrongState
Definition: ndtxt.hxx:86
bool FrameContainsNode(SwContentFrame const &rFrame, SwNodeOffset nNodeIndex)
Definition: txtfrm.cxx:290
TextFrameIndex MapModelToView(MergedPara const &, SwTextNode const *pNode, sal_Int32 nIndex)
Definition: txtfrm.cxx:1183
InsertText MakeInsertText(SwTextNode &rNode, const sal_Int32 nPos, const sal_Int32 nLen)
Definition: docbm.cxx:2078
@ Parent
EXPAND : (Start < nIndex <= End)
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
QPRO_FUNC_TYPE nType
static LanguageType nLang
Definition: srtdlg.cxx:51
This struct defines a position in the model string.
SwPosition * pStartPos
Definition: splargs.hxx:40
SwPosition * pEndPos
Definition: splargs.hxx:41
OUString aConvText
Definition: splargs.hxx:61
bool bAllowImplicitChangesForNotConvertibleText
Definition: splargs.hxx:69
LanguageType nConvSrcLang
Definition: splargs.hxx:62
LanguageType nConvTargetLang
Definition: splargs.hxx:66
const vcl::Font * pTargetFont
Definition: splargs.hxx:67
LanguageType nConvTextLang
Definition: splargs.hxx:63
sal_uLong nWord
Definition: docstat.hxx:35
sal_uLong nCharExcludingSpaces
Definition: docstat.hxx:38
sal_uLong nPara
paragraphs for document statistic: non-empty and non-hidden ones
Definition: docstat.hxx:32
sal_uLong nAsianWord
Definition: docstat.hxx:36
sal_uLong nAllPara
all paragraphs, including empty/hidden ones
Definition: docstat.hxx:34
sal_uLong nChar
Definition: docstat.hxx:37
Marks a position in the document model.
Definition: pam.hxx:37
SwNode & GetNode() const
Definition: pam.hxx:80
void Assign(const SwNode &rNd, SwNodeOffset nDelta, sal_Int32 nContentOffset=0)
These all set both nNode and nContent.
Definition: pam.cxx:230
void SetContent(sal_Int32 nContentIndex)
Set content index, only valid to call this if the position points to a SwContentNode subclass.
Definition: pam.cxx:266
sal_Int32 GetContentIndex() const
Definition: pam.hxx:84
css::uno::Reference< css::linguistic2::XSpellAlternatives > xSpellAlt
Definition: splargs.hxx:87
css::uno::Reference< css::linguistic2::XSpellChecker1 > xSpeller
Definition: splargs.hxx:85
UNDERLYING_TYPE get() const
sal_uLong nNumberOfAsianWords
Definition: ndtxt.hxx:94
WrongState eWrongDirty
online spell checking needed/done?
Definition: ndtxt.hxx:98
sal_uLong nNumberOfCharsExcludingSpaces
Definition: ndtxt.hxx:96
std::unique_ptr< SwWrongList > pWrong
Definition: ndtxt.hxx:90
std::unique_ptr< SwWrongList > pSmartTags
Definition: ndtxt.hxx:92
sal_uLong nNumberOfWords
Definition: ndtxt.hxx:93
std::unique_ptr< SwGrammarMarkUp > pGrammarCheck
Definition: ndtxt.hxx:91
bool bAutoComplDirty
auto complete list dirty
Definition: ndtxt.hxx:101
sal_uLong nNumberOfChars
Definition: ndtxt.hxx:95
Reference< XController > xController
#define SW_MOD()
Definition: swmodule.hxx:256
uno::Reference< linguistic2::XSpellChecker1 > GetSpellChecker()
Definition: swtypes.cxx:52
@ NOHINTADJUST
attention: NOHINTADJUST prevents MergePortions! when using this need to pay attention to ignore start...
constexpr sal_Int32 COMPLETE_STRING
Definition: swtypes.hxx:57
SwTextAttr * MakeTextAttr(SwDoc &rDoc, SfxPoolItem &rAttr, sal_Int32 const nStt, sal_Int32 const nEnd, CopyOrNewType const bIsCopy, SwTextNode *const pTextNode)
if COPY then pTextNode must be given!
Definition: thints.cxx:1030
const formula::FormulaGrammar::AddressConvention aConvMap[]
static bool lcl_IsDelim(const sal_Unicode c)
Definition: txtedt.cxx:116
static bool lcl_MaskRedlinesAndHiddenText(const SwTextNode &rNode, OUStringBuffer &rText, sal_Int32 nStt, sal_Int32 nEnd, const sal_Unicode cChar=CH_TXTATR_INWORD)
Used for spell checking.
Definition: txtedt.cxx:213
static SwRect lcl_CalculateRepaintRect(const SwTextFrame &rTextFrame, const SwTextNode &rNode, sal_Int32 const nChgStart, sal_Int32 const nChgEnd)
Used for spell checking.
Definition: txtedt.cxx:246
static bool lcl_IsURL(std::u16string_view rWord, SwTextNode &rNode, sal_Int32 nBegin, sal_Int32 nLen)
Definition: txtedt.cxx:124
static sal_Int32 clipIndexBounds(std::u16string_view aStr, sal_Int32 nPos)
Definition: txtedt.cxx:674
static sal_Int32 lcl_MaskRedlines(const SwTextNode &rNode, OUStringBuffer &rText, sal_Int32 nStt, sal_Int32 nEnd, const sal_Unicode cChar)
Definition: txtedt.cxx:169
static bool lcl_HasComments(const SwTextNode &rNode)
Definition: txtedt.cxx:102
static bool lcl_HaveCommonAttributes(IStyleAccess &rStyleAccess, const SfxItemSet *pSet1, sal_uInt16 nWhichId, const SfxItemSet &rSet2, std::shared_ptr< SfxItemSet > &pStyleHandle)
Used for automatic styles.
Definition: txtedt.cxx:319
sal_uInt16 sal_Unicode
@ WRONGLIST_SPELL
Definition: wrong.hxx:58
const char * pChar