LibreOffice Module sw (master)  1
accportions.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 <sal/config.h>
21 
22 #include <string_view>
23 
24 #include "accportions.hxx"
25 #include <rtl/ustring.hxx>
26 #include <com/sun/star/i18n/Boundary.hpp>
27 #include <com/sun/star/i18n/XBreakIterator.hpp>
28 #include <txttypes.hxx>
29 
30 // for portion replacement in Special()
31 #include <viewopt.hxx>
32 
33 // for GetWordBoundary(...), GetSentenceBoundary(...):
34 #include <breakit.hxx>
35 #include <txtfrm.hxx>
36 
37 // for FillSpecialPos(...)
38 #include <crstate.hxx>
39 
40 using namespace ::com::sun::star;
41 
42 using i18n::Boundary;
43 
44 // 'portion type' for terminating portions
45 #define POR_TERMINATE PortionType::NONE
46 
47 // portion attributes
48 #define PORATTR_SPECIAL 1
49 #define PORATTR_READONLY 2
50 #define PORATTR_GRAY 4
51 #define PORATTR_TERM 128
52 
55 template<typename T>
56 static size_t FindBreak(const std::vector<T>& rPositions, T nValue);
57 
59 template<typename T>
60 static size_t FindLastBreak(const std::vector<T>& rPositions, T nValue);
61 
62 
64  const SwTextFrame *const pTextFrame,
65  const SwViewOption* pViewOpt ) :
67  m_pTextFrame(pTextFrame),
68  m_aBuffer(),
69  m_nViewPosition( 0 ),
70  m_pViewOptions( pViewOpt ),
71  m_sAccessibleString(),
72  m_aLineBreaks(),
73  m_aAccessiblePositions(),
74  m_aFieldPosition(),
75  m_aPortionAttrs(),
76  m_nBeforePortions( 0 ),
77  m_bFinished( false )
78 {
79  OSL_ENSURE( m_pTextFrame != nullptr, "Need SwTextFrame!" );
80 
81  // reserve some space to reduce memory allocations
82  m_aLineBreaks.reserve( 5 );
83  m_ViewPositions.reserve( 10 );
84  m_aAccessiblePositions.reserve( 10 );
85 
86  // always include 'first' line-break position
87  m_aLineBreaks.push_back( 0 );
88 }
89 
91 {
92 }
93 
95  PortionType nType, sal_Int32 /*nHeight*/, sal_Int32 /*nWidth*/)
96 {
97  OSL_ENSURE((m_nViewPosition + nLength) <= TextFrameIndex(m_pTextFrame->GetText().getLength()),
98  "portion exceeds model string!" );
99 
100  OSL_ENSURE( !m_bFinished, "We are already done!" );
101 
102  // ignore zero-length portions
103  if (nLength == TextFrameIndex(0))
104  return;
105 
106  // store 'old' positions
107  m_ViewPositions.push_back( m_nViewPosition );
108  m_aAccessiblePositions.push_back( m_aBuffer.getLength() );
109 
110  // store portion attributes
111  sal_uInt8 nAttr = IsGrayPortionType(nType) ? PORATTR_GRAY : 0;
112  m_aPortionAttrs.push_back( nAttr );
113 
114  // update buffer + nViewPosition
115  m_aBuffer.append(std::u16string_view(m_pTextFrame->GetText()).substr(sal_Int32(m_nViewPosition), sal_Int32(nLength)));
116  m_nViewPosition += nLength;
117 }
118 
120  TextFrameIndex const nLength, const OUString& rText, PortionType nType,
121  sal_Int32 /*nHeight*/, sal_Int32 /*nWidth*/, const SwFont* /*pFont*/)
122 {
123  OSL_ENSURE(m_nViewPosition >= TextFrameIndex(0), "illegal position");
124  OSL_ENSURE((m_nViewPosition + nLength) <= TextFrameIndex(m_pTextFrame->GetText().getLength()),
125  "portion exceeds model string!" );
126 
127  OSL_ENSURE( !m_bFinished, "We are already done!" );
128 
129  // construct string with representation; either directly from
130  // rText, or use resources for special case portions
131  OUString sDisplay;
132  switch( nType )
133  {
135  case PortionType::FlyCnt:
136  sDisplay = OUString(u'\xfffc');
137  break;
138  case PortionType::Field:
139  case PortionType::Hidden:
141  case PortionType::IsoRef:
142  // When the field content is empty, input a special character.
143  if (rText.isEmpty())
144  sDisplay = OUString(u'\xfffc');
145  else
146  sDisplay = rText;
147  m_aFieldPosition.push_back(m_aBuffer.getLength());
148  m_aFieldPosition.push_back(m_aBuffer.getLength() + rText.getLength());
149  break;
151  break;
153  {
154  sDisplay = rText;
155  sal_Int32 nStart=m_aBuffer.getLength();
156  sal_Int32 nEnd=nStart + rText.getLength();
157  m_vecPairPos.emplace_back(nStart,nEnd);
158  break;
159  }
160  break;
161  case PortionType::Number:
162  case PortionType::Bullet:
163  sDisplay = rText + " ";
164  break;
165  // There should probably be some special treatment to graphical bullets
166  case PortionType::GrfNum:
167  break;
168  // #i111768# - apply patch from kstribley:
169  // Include the control characters.
171  sDisplay = rText + OUStringChar(m_pTextFrame->GetText()[sal_Int32(m_nViewPosition)]);
172  break;
174  // TODO
175  break;
176  default:
177  sDisplay = rText;
178  break;
179  }
180 
181  // ignore zero/zero portions (except for terminators)
182  if ((nLength == TextFrameIndex(0)) && (sDisplay.getLength() == 0) && (nType != POR_TERMINATE))
183  return;
184 
185  // special treatment for zero length portion at the beginning:
186  // count as 'before' portion
187  if ((nLength == TextFrameIndex(0)) && (m_nViewPosition == TextFrameIndex(0)))
189 
190  // store the 'old' positions
191  m_ViewPositions.push_back( m_nViewPosition );
192  m_aAccessiblePositions.push_back( m_aBuffer.getLength() );
193 
194  // store portion attributes
195  sal_uInt8 nAttr = PORATTR_SPECIAL;
196  if( IsGrayPortionType(nType) ) nAttr |= PORATTR_GRAY;
197  if (nLength == TextFrameIndex(0)) nAttr |= PORATTR_READONLY;
198  if( nType == POR_TERMINATE ) nAttr |= PORATTR_TERM;
199  m_aPortionAttrs.push_back( nAttr );
200 
201  // update buffer + nViewPosition
202  m_aBuffer.append( sDisplay );
203  m_nViewPosition += nLength;
204 }
205 
206 void SwAccessiblePortionData::LineBreak(sal_Int32 /*nWidth*/)
207 {
208  OSL_ENSURE( !m_bFinished, "We are already done!" );
209 
210  m_aLineBreaks.push_back( m_aBuffer.getLength() );
211 }
212 
214 {
215  OSL_ENSURE( !m_bFinished, "We are already done!" );
216  OSL_ENSURE( m_ViewPositions.empty(), "Never Skip() after portions" );
217  OSL_ENSURE(nLength <= TextFrameIndex(m_pTextFrame->GetText().getLength()),
218  "skip exceeds model string!" );
219 
220  m_nViewPosition += nLength;
221 }
222 
224 {
225  OSL_ENSURE( !m_bFinished, "We are already done!" );
226 
227  // include terminator values: always include two 'last character'
228  // markers in the position arrays to make sure we always find one
229  // position before the end
230  Special( TextFrameIndex(0), OUString(), POR_TERMINATE );
231  Special( TextFrameIndex(0), OUString(), POR_TERMINATE );
232  LineBreak(0);
233  LineBreak(0);
234 
235  m_sAccessibleString = m_aBuffer.makeStringAndClear();
236  m_bFinished = true;
237 }
238 
240  size_t nPortionNo, sal_uInt8 nAttr ) const
241 {
242  OSL_ENSURE( nPortionNo < m_aPortionAttrs.size(),
243  "Illegal portion number" );
244  return (m_aPortionAttrs[nPortionNo] & nAttr) != 0;
245 }
246 
247 bool SwAccessiblePortionData::IsSpecialPortion( size_t nPortionNo ) const
248 {
249  return IsPortionAttrSet(nPortionNo, PORATTR_SPECIAL);
250 }
251 
253 {
254  // gray portions?
255  // Compare with: inftxt.cxx, SwTextPaintInfo::DrawViewOpt(...)
256  bool bGray = false;
257  switch( nType )
258  {
260  case PortionType::IsoRef:
261  case PortionType::Ref:
263  case PortionType::Number:
264  case PortionType::Field:
266  case PortionType::IsoTox:
267  case PortionType::Tox:
268  case PortionType::Hidden:
269  bGray = !m_pViewOptions->IsPagePreview() &&
271  break;
272  case PortionType::Table: bGray = m_pViewOptions->IsTab(); break;
273  case PortionType::SoftHyphen: bGray = m_pViewOptions->IsSoftHyph(); break;
274  case PortionType::Blank: bGray = m_pViewOptions->IsHardBlank(); break;
275  default:
276  break; // bGray is false
277  }
278  return bGray;
279 }
280 
282 {
283  OSL_ENSURE( m_bFinished, "Shouldn't call this before we are done!" );
284 
285  return m_sAccessibleString;
286 }
287 
289  Boundary& rBound,
290  sal_Int32 nPos ) const
291 {
292  FillBoundary( rBound, m_aLineBreaks,
293  FindBreak( m_aLineBreaks, nPos ) );
294 }
295 
296 // #i89175#
298 {
299  size_t nBreaks = m_aLineBreaks.size();
300  // A non-empty paragraph has at least 4 breaks: one for each line3 and
301  // 3 additional ones.
302  // An empty paragraph has 3 breaks.
303  // Less than 3 breaks is an error case.
304  sal_Int32 nLineCount = ( nBreaks > 3 )
305  ? nBreaks - 3
306  : ( ( nBreaks == 3 ) ? 1 : 0 );
307  return nLineCount;
308 }
309 
310 sal_Int32 SwAccessiblePortionData::GetLineNo( const sal_Int32 nPos ) const
311 {
312  sal_Int32 nLineNo = FindBreak( m_aLineBreaks, nPos );
313 
314  // handling of position after last character
315  const sal_Int32 nLineCount( GetLineCount() );
316  if ( nLineNo >= nLineCount )
317  {
318  nLineNo = nLineCount - 1;
319  }
320 
321  return nLineNo;
322 }
323 
324 void SwAccessiblePortionData::GetBoundaryOfLine( const sal_Int32 nLineNo,
325  i18n::Boundary& rLineBound )
326 {
327  FillBoundary( rLineBound, m_aLineBreaks, nLineNo );
328 }
329 
331  Boundary& rBound ) const
332 {
333  OSL_ENSURE( m_aLineBreaks.size() >= 2, "need min + max value" );
334 
335  // The last two positions except the two delimiters are the ones
336  // we are looking for, except for empty paragraphs (nBreaks==3)
337  size_t nBreaks = m_aLineBreaks.size();
338  FillBoundary( rBound, m_aLineBreaks, nBreaks <= 3 ? 0 : nBreaks-4 );
339 }
340 
342 {
343  OSL_ENSURE( nPos >= 0, "illegal position" );
344  OSL_ENSURE( nPos <= m_sAccessibleString.getLength(), "illegal position" );
345 
346  // find the portion number
347  size_t nPortionNo = FindBreak( m_aAccessiblePositions, nPos );
348 
349  // get core view portion size
350  TextFrameIndex nStartPos = m_ViewPositions[nPortionNo];
351 
352  // if it's a non-special portion, move into the portion, else
353  // return the portion start
354  if( ! IsSpecialPortion( nPortionNo ) )
355  {
356  // text portions have to be of the same width
357  OSL_ENSURE( sal_Int32(m_ViewPositions[nPortionNo+1] - nStartPos) ==
358  ( m_aAccessiblePositions[nPortionNo+1] -
359  m_aAccessiblePositions[nPortionNo] ),
360  "accessibility portion disagrees with text model" );
361 
362  nStartPos += TextFrameIndex(nPos - m_aAccessiblePositions[nPortionNo]);
363  }
364  // else: return nStartPos unmodified
365 
366  OSL_ENSURE(nStartPos >= TextFrameIndex(0), "There's something weird in number of characters of SwTextFrame");
367  return nStartPos;
368 }
369 
371  Boundary& rBound,
372  const AccessiblePositions& rPositions,
373  size_t nPos )
374 {
375  rBound.startPos = rPositions[nPos];
376  rBound.endPos = rPositions[nPos+1];
377 }
378 
379 template<typename T>
380 static size_t FindBreak(const std::vector<T>& rPositions, T const nValue)
381 {
382  OSL_ENSURE( rPositions.size() >= 2, "need min + max value" );
383  OSL_ENSURE( rPositions[0] <= nValue, "need min value" );
384  OSL_ENSURE( rPositions[rPositions.size()-1] >= nValue,
385  "need first terminator value" );
386  OSL_ENSURE( rPositions[rPositions.size()-2] >= nValue,
387  "need second terminator value" );
388 
389  size_t nMin = 0;
390  size_t nMax = rPositions.size()-2;
391 
392  // loop until no more than two candidates are left
393  while( nMin+1 < nMax )
394  {
395  // check loop invariants
396  OSL_ENSURE( ( (nMin == 0) && (rPositions[nMin] <= nValue) ) ||
397  ( (nMin != 0) && (rPositions[nMin] < nValue) ),
398  "minvalue not minimal" );
399  OSL_ENSURE( nValue <= rPositions[nMax], "max value not maximal" );
400 
401  // get middle (and ensure progress)
402  size_t nMiddle = (nMin + nMax)/2;
403  OSL_ENSURE( nMin < nMiddle, "progress?" );
404  OSL_ENSURE( nMiddle < nMax, "progress?" );
405 
406  // check array
407  OSL_ENSURE( rPositions[nMin] <= rPositions[nMiddle],
408  "garbled positions array" );
409  OSL_ENSURE( rPositions[nMiddle] <= rPositions[nMax],
410  "garbled positions array" );
411 
412  if( nValue > rPositions[nMiddle] )
413  nMin = nMiddle;
414  else
415  nMax = nMiddle;
416  }
417 
418  // only two are left; we only need to check which one is the winner
419  OSL_ENSURE( (nMax == nMin) || (nMax == nMin+1), "only two left" );
420  if( (rPositions[nMin] < nValue) && (rPositions[nMin+1] <= nValue) )
421  nMin = nMin+1;
422 
423  // finally, check to see whether the returned value is the 'right' position
424  OSL_ENSURE( rPositions[nMin] <= nValue, "not smaller or equal" );
425  OSL_ENSURE( nValue <= rPositions[nMin+1], "not equal or larger" );
426  OSL_ENSURE( (nMin == 0) || (rPositions[nMin-1] <= nValue),
427  "earlier value should have been returned" );
428 
429  OSL_ENSURE( nMin < rPositions.size()-1,
430  "shouldn't return last position (due to terminator values)" );
431 
432  return nMin;
433 }
434 
435 template<typename T>
436 static size_t FindLastBreak(const std::vector<T>& rPositions, T const nValue)
437 {
438  size_t nResult = FindBreak( rPositions, nValue );
439 
440  // skip 'zero-length' portions
441  // #i70538# consider size of <rPosition> and ignore last entry
442  while ( nResult < rPositions.size() - 2 &&
443  rPositions[nResult+1] <= nValue )
444  {
445  nResult++;
446  }
447 
448  return nResult;
449 }
450 
452  Boundary& rBound,
453  sal_Int32 nPos )
454 {
455  OSL_ENSURE( nPos >= 0, "illegal position; check before" );
456  OSL_ENSURE( nPos < m_sAccessibleString.getLength(), "illegal position" );
457 
458  if( m_pSentences == nullptr )
459  {
461 
463  m_pSentences->reserve(10);
464 
465  // use xBreak->endOfSentence to iterate over all words; store
466  // positions in pSentences
467  sal_Int32 nCurrent = 0;
468  sal_Int32 nLength = m_sAccessibleString.getLength();
469  do
470  {
471  m_pSentences->push_back( nCurrent );
472 
473  const TextFrameIndex nFramePos = GetCoreViewPosition(nCurrent);
474 
475  sal_Int32 nNew = g_pBreakIt->GetBreakIter()->endOfSentence(
476  m_sAccessibleString, nCurrent,
477  g_pBreakIt->GetLocale(m_pTextFrame->GetLangOfChar(nFramePos, 0, true))) + 1;
478 
479  if( (nNew < 0) && (nNew > nLength) )
480  nNew = nLength;
481  else if (nNew <= nCurrent)
482  nNew = nCurrent + 1; // ensure forward progress
483 
484  nCurrent = nNew;
485  }
486  while (nCurrent < nLength);
487 
488  // finish with two terminators
489  m_pSentences->push_back( nLength );
490  m_pSentences->push_back( nLength );
491  }
492 
493  FillBoundary( rBound, *m_pSentences, FindBreak( *m_pSentences, nPos ) );
494 }
495 
497  Boundary& rBound,
498  sal_Int32 nPos) const
499 {
500  OSL_ENSURE( m_pTextFrame != nullptr, "Need SwTextNode!" );
501 
502  // attribute boundaries can only occur on portion boundaries
505 }
506 
508 {
509  OSL_ENSURE(nPos <= TextFrameIndex(m_pTextFrame->GetText().getLength()), "illegal position");
510 
511  // find the portion number
512  // #i70538# - consider "empty" model portions - e.g. number portion
513  size_t nPortionNo = FindLastBreak( m_ViewPositions, nPos );
514 
515  sal_Int32 nRet = m_aAccessiblePositions[nPortionNo];
516 
517  // if the view portion has more than one position, go into it;
518  // else return that position
519  TextFrameIndex nStartPos = m_ViewPositions[nPortionNo];
520  TextFrameIndex nEndPos = m_ViewPositions[nPortionNo+1];
521  if (!IsSpecialPortion(nPortionNo))
522  {
523  // text portions have to be of the same width
524  OSL_ENSURE( sal_Int32(nEndPos - nStartPos) ==
525  ( m_aAccessiblePositions[nPortionNo+1] -
526  m_aAccessiblePositions[nPortionNo] ),
527  "accessibility portion disagrees with text model" );
528 
529  TextFrameIndex nWithinPortion = nPos - m_ViewPositions[nPortionNo];
530  nRet += sal_Int32(nWithinPortion);
531  }
532  // else: return nRet unmodified
533 
534  OSL_ENSURE( (nRet >= 0) && (nRet <= m_sAccessibleString.getLength()),
535  "too long!" );
536  return nRet;
537 }
538 
540  sal_Int32 nPos,
541  SwSpecialPos& rPos,
542  SwSpecialPos*& rpPos ) const
543 {
544  size_t nPortionNo = FindLastBreak( m_aAccessiblePositions, nPos );
545 
547  sal_Int32 nRefPos(0);
548  TextFrameIndex nCorePos(0);
549 
550  if( nPortionNo < m_nBeforePortions )
551  {
552  nExtend = SwSPExtendRange::BEFORE;
553  rpPos = &rPos;
554  }
555  else
556  {
557  TextFrameIndex nCoreEndPos = m_ViewPositions[nPortionNo+1];
558  nCorePos = m_ViewPositions[nPortionNo];
559 
560  // skip backwards over zero-length portions, since GetCharRect()
561  // counts all model-zero-length portions as belonging to the
562  // previous portion
563  size_t nCorePortionNo = nPortionNo;
564  while (nCorePos == nCoreEndPos)
565  {
566  nCorePortionNo--;
567  nCoreEndPos = nCorePos;
568  nCorePos = m_ViewPositions[nCorePortionNo];
569 
570  OSL_ENSURE( nCorePos >= TextFrameIndex(0), "Can't happen." );
571  OSL_ENSURE( nCorePortionNo >= m_nBeforePortions, "Can't happen." );
572  }
573  OSL_ENSURE( nCorePos != nCoreEndPos,
574  "portion with core-representation expected" );
575 
576  // if we have anything except plain text, compute nExtend + nRefPos
577  if (IsSpecialPortion(nCorePortionNo))
578  {
579  // case 1: a non-text portion
580  // reference position is the first accessibility for our
581  // core portion
582  nRefPos = m_aAccessiblePositions[ nCorePortionNo ];
583  nExtend = SwSPExtendRange::NONE;
584  rpPos = &rPos;
585  }
586  else if(nPortionNo != nCorePortionNo)
587  {
588  // case 2: a multi-character (text!) portion, followed by
589  // zero-length portions
590  // reference position is the first character of the next
591  // portion, and we are 'behind'
592  nRefPos = m_aAccessiblePositions[ nCorePortionNo+1 ];
593  nExtend = SwSPExtendRange::BEHIND;
594  rpPos = &rPos;
595  }
596  else
597  {
598  // case 3: regular text portion
599  OSL_ENSURE( sal_Int32(nCoreEndPos - nCorePos) ==
600  ( m_aAccessiblePositions[nPortionNo+1] -
601  m_aAccessiblePositions[nPortionNo] ),
602  "text portion expected" );
603 
604  nCorePos += TextFrameIndex(nPos - m_aAccessiblePositions[nPortionNo]);
605  rpPos = nullptr;
606  }
607  }
608  if( rpPos != nullptr )
609  {
610  OSL_ENSURE( rpPos == &rPos, "Yes!" );
611  OSL_ENSURE( nRefPos <= nPos, "wrong reference" );
612 
613  // get the line number, and adjust nRefPos for the line
614  // (if necessary)
615  size_t nRefLine = FindBreak( m_aLineBreaks, nRefPos );
616  size_t nMyLine = FindBreak( m_aLineBreaks, nPos );
617  sal_uInt16 nLineOffset = static_cast<sal_uInt16>( nMyLine - nRefLine );
618  if( nLineOffset != 0 )
619  nRefPos = m_aLineBreaks[ nMyLine ];
620 
621  // fill char offset and 'special position'
622  rPos.nCharOfst = nPos - nRefPos;
623  rPos.nExtendRange = nExtend;
624  rPos.nLineOfst = nLineOffset;
625  }
626 
627  return nCorePos;
628 }
629 
630 bool SwAccessiblePortionData::FillBoundaryIFDateField( css::i18n::Boundary& rBound, const sal_Int32 nPos )
631 {
632  if( m_aFieldPosition.size() < 2 )
633  return false;
634  for( size_t i = 0; i < m_aFieldPosition.size() - 1; i += 2 )
635  {
636  if( nPos < m_aFieldPosition[ i + 1 ] && nPos >= m_aFieldPosition[ i ] )
637  {
638  rBound.startPos = m_aFieldPosition[i];
639  rBound.endPos = m_aFieldPosition[i + 1];
640  return true;
641  }
642  }
643  return false;
644 }
645 
647  sal_Int32 nPos,
648  size_t& nPortionNo,
649  TextFrameIndex& rCorePos,
650  bool& bEdit) const
651 {
652  // find portion and get mode position
653  nPortionNo = FindBreak( m_aAccessiblePositions, nPos );
654  rCorePos = m_ViewPositions[ nPortionNo ];
655 
656  // for special portions, make sure we're on a portion boundary
657  // for text portions, add the in-portion offset
658  if( IsSpecialPortion( nPortionNo ) )
659  bEdit &= nPos == m_aAccessiblePositions[nPortionNo];
660  else
661  rCorePos += TextFrameIndex(nPos - m_aAccessiblePositions[nPortionNo]);
662 }
663 
665  sal_Int32 nStart, sal_Int32 nEnd,
666  TextFrameIndex& rCoreStart, TextFrameIndex& rCoreEnd) const
667 {
668  bool bIsEditable = true;
669 
670  // get start and end portions
671  size_t nStartPortion, nEndPortion;
672  AdjustAndCheck( nStart, nStartPortion, rCoreStart, bIsEditable );
673  AdjustAndCheck( nEnd, nEndPortion, rCoreEnd, bIsEditable );
674 
675  // iterate over portions, and make sure there is no read-only portion
676  // in-between
677  size_t nLastPortion = nEndPortion;
678 
679  // don't count last portion if we're in front of a special portion
680  if( IsSpecialPortion(nLastPortion) )
681  {
682  if (nLastPortion > 0)
683  nLastPortion--;
684  else
685  // special case: because size_t is usually unsigned, we can't just
686  // decrease nLastPortion to -1 (which would normally do the job, so
687  // this whole if wouldn't be needed). Instead, we'll do this
688  // special case and just increase the start portion beyond the last
689  // portion to make sure the loop below will have zero iteration.
690  nStartPortion = nLastPortion + 1;
691  }
692 
693  for( size_t nPor = nStartPortion; nPor <= nLastPortion; nPor++ )
694  {
695  bIsEditable &= ! IsPortionAttrSet(nPor, PORATTR_READONLY);
696  }
697 
698  return bIsEditable;
699 }
700 
702 {
703  // a position is valid if it's within the core view positions that we know
704  return (m_ViewPositions[0] <= nPos) && (nPos <= m_ViewPositions.back());
705 }
706 
708 {
709  if (m_ViewPositions.empty()) return true;
710  return m_ViewPositions[0] == TextFrameIndex(0)
711  && m_ViewPositions.back() == TextFrameIndex(0);
712 }
713 
715 {
716  for (const auto & pairPos : m_vecPairPos)
717  {
718  if(nIndex >= pairPos.first && nIndex < pairPos.second )
719  {
720  return true;
721  }
722  }
723  return false;
724 }
725 
727 {
728 // return IsGrayPortion( FindBreak( aAccessiblePositions, nPos ) );
730  PORATTR_GRAY );
731 }
732 
733 sal_Int32 SwAccessiblePortionData::GetFieldIndex(sal_Int32 nPos) const
734 {
735  sal_Int32 nIndex = -1;
736  if( m_aFieldPosition.size() >= 2 )
737  {
738  for( size_t i = 0; i < m_aFieldPosition.size() - 1; i += 2 )
739  {
740  if( nPos <= m_aFieldPosition[ i + 1 ] && nPos >= m_aFieldPosition[ i ] )
741  {
742  nIndex = i/2;
743  break;
744  }
745  }
746  }
747  return nIndex;
748 }
749 
751 {
752  return m_ViewPositions[0];
753 }
754 
756 {
757  return m_ViewPositions.back();
758 }
759 
760 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const OUString & GetAccessibleString() const
get the text string, as presented by the layout
const SwViewOption * m_pViewOptions
Definition: accportions.hxx:47
Represents the visualization of a paragraph.
Definition: txtfrm.hxx:151
#define PORATTR_SPECIAL
Definition: accportions.cxx:48
SwAccessiblePortionData(const SwTextFrame *pTextFrame, const SwViewOption *pViewOpt)
Definition: accportions.cxx:63
AccessiblePositions m_aLineBreaks
Definition: accportions.hxx:62
sal_Int32 nIndex
bool IsPagePreview() const
Definition: viewopt.hxx:624
sal_Int32 nCharOfst
Definition: crstate.hxx:110
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
Definition: txtfrm.cxx:1333
#define PORATTR_GRAY
Definition: accportions.cxx:50
virtual ~SwAccessiblePortionData() override
Definition: accportions.cxx:90
virtual void LineBreak(sal_Int32 nWidth) override
line break.
TextFrameIndex FillSpecialPos(sal_Int32 nPos, SwSpecialPos &rPos, SwSpecialPos *&rpPos) const
fill a SwSpecialPos structure, suitable for calling SwTextFrame->GetCharRect Returns the core positio...
The SwPortionHandler interface implements a visitor for the layout engine's text portions.
TextFrameIndex GetFirstValidCorePosition() const
bool IsGrayPortionType(PortionType nType) const
OUString m_sAccessibleString
the accessible string note that the content is different both from the string in the text node(s) as ...
Definition: accportions.hxx:53
FramePositions m_ViewPositions
position of line breaks
Definition: accportions.hxx:63
bool IsHardBlank() const
Definition: viewopt.hxx:230
void AdjustAndCheck(sal_Int32 nPos, size_t &nPortionNo, TextFrameIndex &rCorePos, bool &bEdit) const
#define PORATTR_READONLY
Definition: accportions.cxx:49
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
Definition: txtfrm.cxx:1283
#define POR_TERMINATE
Definition: accportions.cxx:45
std::vector< sal_uInt8 > m_aPortionAttrs
Definition: accportions.hxx:67
bool IsReadonly() const
Definition: viewopt.hxx:452
OUStringBuffer m_aBuffer
Definition: accportions.hxx:45
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
SwBreakIt * g_pBreakIt
Definition: breakit.cxx:33
size_t m_nBeforePortions
positions of sentence breaks
Definition: accportions.hxx:71
std::vector< std::pair< sal_Int32, sal_Int32 > > m_vecPairPos
sal_Int32 GetLineCount() const
virtual void Text(TextFrameIndex nLength, PortionType nType, sal_Int32 nHeight=0, sal_Int32 nWidth=0) override
(empty) destructor
Definition: accportions.cxx:94
virtual void Skip(TextFrameIndex nLength) override
skip characters.
static sal_uInt8 nFramePos
Definition: basesh.cxx:108
void GetAttributeBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos) const
void GetLineBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos) const
get the start & end positions of the sentence
std::unique_ptr< AccessiblePositions > m_pSentences
additional portion attributes
Definition: accportions.hxx:69
bool IsInGrayPortion(sal_Int32 nPos)
#define PORATTR_TERM
Definition: accportions.cxx:51
TextFrameIndex GetLastValidCorePosition() const
int i
bool GetEditableRange(sal_Int32 nStart, sal_Int32 nEnd, TextFrameIndex &rCoreStart, TextFrameIndex &rCoreEnd) const
Convert start and end positions into core positions.
void GetBoundaryOfLine(const sal_Int32 nLineNo, css::i18n::Boundary &rLineBound)
static void FillBoundary(css::i18n::Boundary &rBound, const AccessiblePositions &rPositions, size_t nPos)
fill the boundary with the values from rPositions[nPos]
bool FillBoundaryIFDateField(css::i18n::Boundary &rBound, const sal_Int32 nPos)
float u
void GetSentenceBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos)
TextFrameIndex GetCoreViewPosition(sal_Int32 nPos) const
get the position in the core view string for a given (accessibility) position
bool IsTab(bool bHard=false) const
Definition: viewopt.hxx:218
PortionType
Definition: txttypes.hxx:23
TextFrameIndex m_nViewPosition
Definition: accportions.hxx:46
static bool IsFieldShadings()
Definition: viewopt.hxx:660
sal_uInt16 nLineOfst
Definition: crstate.hxx:111
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
virtual void Finish() override
end of paragraph.
bool IsValidCorePosition(TextFrameIndex nPos) const
Determine whether this core position is valid for these portions.
std::vector< sal_Int32 > AccessiblePositions
Definition: accportions.hxx:59
unsigned char sal_uInt8
sal_Int32 GetLineNo(const sal_Int32 nPos) const
bool IsPortionAttrSet(size_t nPortionNo, sal_uInt8 nAttr) const
Access to portion attributes.
bool m_bFinished
of portions before first core character
Definition: accportions.hxx:72
const char sDisplay[]
AccessiblePositions m_aAccessiblePositions
position of portion breaks in the core view
Definition: accportions.hxx:64
SwSPExtendRange
SwSpecialPos.
Definition: crstate.hxx:103
void GetLastLineBoundary(css::i18n::Boundary &rBound) const
bool IsSoftHyph() const
Definition: viewopt.hxx:263
SwSPExtendRange nExtendRange
Definition: crstate.hxx:112
AccessiblePositions m_aFieldPosition
portion breaks in m_sAccessibleString
Definition: accportions.hxx:65
sal_Int32 nLength
static size_t FindBreak(const std::vector< T > &rPositions, T nValue)
returns the index of the first position whose value is smaller or equal, and whose following value is...
SwTextFrame const * m_pTextFrame
Definition: accportions.hxx:42
sal_Int32 GetAccessiblePosition(TextFrameIndex nPos) const
get the position in the accessibility string for a given view position
bool IsSpecialPortion(size_t nPortionNo) const
const int nLineCount
sal_Int32 GetFieldIndex(sal_Int32 nPos) const
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...
bool IsIndexInFootnode(sal_Int32 nIndex)
static size_t FindLastBreak(const std::vector< T > &rPositions, T nValue)
like FindBreak, but finds the last equal or larger position
virtual void Special(TextFrameIndex nLength, const OUString &rText, PortionType nType, sal_Int32 nHeight=0, sal_Int32 nWidth=0, const SwFont *pFont=nullptr) override
special portion.