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;
173  default:
174  sDisplay = rText;
175  break;
176  }
177 
178  // ignore zero/zero portions (except for terminators)
179  if ((nLength == TextFrameIndex(0)) && (sDisplay.getLength() == 0) && (nType != POR_TERMINATE))
180  return;
181 
182  // special treatment for zero length portion at the beginning:
183  // count as 'before' portion
184  if ((nLength == TextFrameIndex(0)) && (m_nViewPosition == TextFrameIndex(0)))
186 
187  // store the 'old' positions
188  m_ViewPositions.push_back( m_nViewPosition );
189  m_aAccessiblePositions.push_back( m_aBuffer.getLength() );
190 
191  // store portion attributes
192  sal_uInt8 nAttr = PORATTR_SPECIAL;
193  if( IsGrayPortionType(nType) ) nAttr |= PORATTR_GRAY;
194  if (nLength == TextFrameIndex(0)) nAttr |= PORATTR_READONLY;
195  if( nType == POR_TERMINATE ) nAttr |= PORATTR_TERM;
196  m_aPortionAttrs.push_back( nAttr );
197 
198  // update buffer + nViewPosition
199  m_aBuffer.append( sDisplay );
200  m_nViewPosition += nLength;
201 }
202 
203 void SwAccessiblePortionData::LineBreak(sal_Int32 /*nWidth*/)
204 {
205  OSL_ENSURE( !m_bFinished, "We are already done!" );
206 
207  m_aLineBreaks.push_back( m_aBuffer.getLength() );
208 }
209 
211 {
212  OSL_ENSURE( !m_bFinished, "We are already done!" );
213  OSL_ENSURE( m_ViewPositions.empty(), "Never Skip() after portions" );
214  OSL_ENSURE(nLength <= TextFrameIndex(m_pTextFrame->GetText().getLength()),
215  "skip exceeds model string!" );
216 
217  m_nViewPosition += nLength;
218 }
219 
221 {
222  OSL_ENSURE( !m_bFinished, "We are already done!" );
223 
224  // include terminator values: always include two 'last character'
225  // markers in the position arrays to make sure we always find one
226  // position before the end
227  Special( TextFrameIndex(0), OUString(), POR_TERMINATE );
228  Special( TextFrameIndex(0), OUString(), POR_TERMINATE );
229  LineBreak(0);
230  LineBreak(0);
231 
232  m_sAccessibleString = m_aBuffer.makeStringAndClear();
233  m_bFinished = true;
234 }
235 
237  size_t nPortionNo, sal_uInt8 nAttr ) const
238 {
239  OSL_ENSURE( nPortionNo < m_aPortionAttrs.size(),
240  "Illegal portion number" );
241  return (m_aPortionAttrs[nPortionNo] & nAttr) != 0;
242 }
243 
244 bool SwAccessiblePortionData::IsSpecialPortion( size_t nPortionNo ) const
245 {
246  return IsPortionAttrSet(nPortionNo, PORATTR_SPECIAL);
247 }
248 
250 {
251  // gray portions?
252  // Compare with: inftxt.cxx, SwTextPaintInfo::DrawViewOpt(...)
253  bool bGray = false;
254  switch( nType )
255  {
257  case PortionType::IsoRef:
258  case PortionType::Ref:
260  case PortionType::Number:
261  case PortionType::Field:
263  case PortionType::IsoTox:
264  case PortionType::Tox:
265  case PortionType::Hidden:
266  bGray = !m_pViewOptions->IsPagePreview() &&
268  break;
269  case PortionType::Table: bGray = m_pViewOptions->IsTab(); break;
270  case PortionType::SoftHyphen: bGray = m_pViewOptions->IsSoftHyph(); break;
271  case PortionType::Blank: bGray = m_pViewOptions->IsHardBlank(); break;
272  default:
273  break; // bGray is false
274  }
275  return bGray;
276 }
277 
279 {
280  OSL_ENSURE( m_bFinished, "Shouldn't call this before we are done!" );
281 
282  return m_sAccessibleString;
283 }
284 
286  Boundary& rBound,
287  sal_Int32 nPos ) const
288 {
289  FillBoundary( rBound, m_aLineBreaks,
290  FindBreak( m_aLineBreaks, nPos ) );
291 }
292 
293 // #i89175#
295 {
296  size_t nBreaks = m_aLineBreaks.size();
297  // A non-empty paragraph has at least 4 breaks: one for each line3 and
298  // 3 additional ones.
299  // An empty paragraph has 3 breaks.
300  // Less than 3 breaks is an error case.
301  sal_Int32 nLineCount = ( nBreaks > 3 )
302  ? nBreaks - 3
303  : ( ( nBreaks == 3 ) ? 1 : 0 );
304  return nLineCount;
305 }
306 
307 sal_Int32 SwAccessiblePortionData::GetLineNo( const sal_Int32 nPos ) const
308 {
309  sal_Int32 nLineNo = FindBreak( m_aLineBreaks, nPos );
310 
311  // handling of position after last character
312  const sal_Int32 nLineCount( GetLineCount() );
313  if ( nLineNo >= nLineCount )
314  {
315  nLineNo = nLineCount - 1;
316  }
317 
318  return nLineNo;
319 }
320 
321 void SwAccessiblePortionData::GetBoundaryOfLine( const sal_Int32 nLineNo,
322  i18n::Boundary& rLineBound )
323 {
324  FillBoundary( rLineBound, m_aLineBreaks, nLineNo );
325 }
326 
328  Boundary& rBound ) const
329 {
330  OSL_ENSURE( m_aLineBreaks.size() >= 2, "need min + max value" );
331 
332  // The last two positions except the two delimiters are the ones
333  // we are looking for, except for empty paragraphs (nBreaks==3)
334  size_t nBreaks = m_aLineBreaks.size();
335  FillBoundary( rBound, m_aLineBreaks, nBreaks <= 3 ? 0 : nBreaks-4 );
336 }
337 
339 {
340  OSL_ENSURE( nPos >= 0, "illegal position" );
341  OSL_ENSURE( nPos <= m_sAccessibleString.getLength(), "illegal position" );
342 
343  // find the portion number
344  size_t nPortionNo = FindBreak( m_aAccessiblePositions, nPos );
345 
346  // get core view portion size
347  TextFrameIndex nStartPos = m_ViewPositions[nPortionNo];
348 
349  // if it's a non-special portion, move into the portion, else
350  // return the portion start
351  if( ! IsSpecialPortion( nPortionNo ) )
352  {
353  // 'wide' portions have to be of the same width
354  OSL_ENSURE( sal_Int32(m_ViewPositions[nPortionNo+1] - nStartPos) ==
355  ( m_aAccessiblePositions[nPortionNo+1] -
356  m_aAccessiblePositions[nPortionNo] ),
357  "accessibility portion disagrees with text model" );
358 
359  nStartPos += TextFrameIndex(nPos - m_aAccessiblePositions[nPortionNo]);
360  }
361  // else: return nStartPos unmodified
362 
363  OSL_ENSURE(nStartPos >= TextFrameIndex(0), "There's something weird in number of characters of SwTextFrame");
364  return nStartPos;
365 }
366 
368  Boundary& rBound,
369  const AccessiblePositions& rPositions,
370  size_t nPos )
371 {
372  rBound.startPos = rPositions[nPos];
373  rBound.endPos = rPositions[nPos+1];
374 }
375 
376 template<typename T>
377 static size_t FindBreak(const std::vector<T>& rPositions, T const nValue)
378 {
379  OSL_ENSURE( rPositions.size() >= 2, "need min + max value" );
380  OSL_ENSURE( rPositions[0] <= nValue, "need min value" );
381  OSL_ENSURE( rPositions[rPositions.size()-1] >= nValue,
382  "need first terminator value" );
383  OSL_ENSURE( rPositions[rPositions.size()-2] >= nValue,
384  "need second terminator value" );
385 
386  size_t nMin = 0;
387  size_t nMax = rPositions.size()-2;
388 
389  // loop until no more than two candidates are left
390  while( nMin+1 < nMax )
391  {
392  // check loop invariants
393  OSL_ENSURE( ( (nMin == 0) && (rPositions[nMin] <= nValue) ) ||
394  ( (nMin != 0) && (rPositions[nMin] < nValue) ),
395  "minvalue not minimal" );
396  OSL_ENSURE( nValue <= rPositions[nMax], "max value not maximal" );
397 
398  // get middle (and ensure progress)
399  size_t nMiddle = (nMin + nMax)/2;
400  OSL_ENSURE( nMin < nMiddle, "progress?" );
401  OSL_ENSURE( nMiddle < nMax, "progress?" );
402 
403  // check array
404  OSL_ENSURE( rPositions[nMin] <= rPositions[nMiddle],
405  "garbled positions array" );
406  OSL_ENSURE( rPositions[nMiddle] <= rPositions[nMax],
407  "garbled positions array" );
408 
409  if( nValue > rPositions[nMiddle] )
410  nMin = nMiddle;
411  else
412  nMax = nMiddle;
413  }
414 
415  // only two are left; we only need to check which one is the winner
416  OSL_ENSURE( (nMax == nMin) || (nMax == nMin+1), "only two left" );
417  if( (rPositions[nMin] < nValue) && (rPositions[nMin+1] <= nValue) )
418  nMin = nMin+1;
419 
420  // finally, check to see whether the returned value is the 'right' position
421  OSL_ENSURE( rPositions[nMin] <= nValue, "not smaller or equal" );
422  OSL_ENSURE( nValue <= rPositions[nMin+1], "not equal or larger" );
423  OSL_ENSURE( (nMin == 0) || (rPositions[nMin-1] <= nValue),
424  "earlier value should have been returned" );
425 
426  OSL_ENSURE( nMin < rPositions.size()-1,
427  "shouldn't return last position (due to terminator values)" );
428 
429  return nMin;
430 }
431 
432 template<typename T>
433 static size_t FindLastBreak(const std::vector<T>& rPositions, T const nValue)
434 {
435  size_t nResult = FindBreak( rPositions, nValue );
436 
437  // skip 'zero-length' portions
438  // #i70538# consider size of <rPosition> and ignore last entry
439  while ( nResult < rPositions.size() - 2 &&
440  rPositions[nResult+1] <= nValue )
441  {
442  nResult++;
443  }
444 
445  return nResult;
446 }
447 
449  Boundary& rBound,
450  sal_Int32 nPos )
451 {
452  OSL_ENSURE( nPos >= 0, "illegal position; check before" );
453  OSL_ENSURE( nPos < m_sAccessibleString.getLength(), "illegal position" );
454 
455  if( m_pSentences == nullptr )
456  {
457  assert(g_pBreakIt && g_pBreakIt->GetBreakIter().is());
458 
460  m_pSentences->reserve(10);
461 
462  // use xBreak->endOfSentence to iterate over all words; store
463  // positions in pSentences
464  sal_Int32 nCurrent = 0;
465  sal_Int32 nLength = m_sAccessibleString.getLength();
466  do
467  {
468  m_pSentences->push_back( nCurrent );
469 
470  const TextFrameIndex nFramePos = GetCoreViewPosition(nCurrent);
471 
472  sal_Int32 nNew = g_pBreakIt->GetBreakIter()->endOfSentence(
473  m_sAccessibleString, nCurrent,
474  g_pBreakIt->GetLocale(m_pTextFrame->GetLangOfChar(nFramePos, 0, true))) + 1;
475 
476  if( (nNew < 0) && (nNew > nLength) )
477  nNew = nLength;
478  else if (nNew <= nCurrent)
479  nNew = nCurrent + 1; // ensure forward progress
480 
481  nCurrent = nNew;
482  }
483  while (nCurrent < nLength);
484 
485  // finish with two terminators
486  m_pSentences->push_back( nLength );
487  m_pSentences->push_back( nLength );
488  }
489 
490  FillBoundary( rBound, *m_pSentences, FindBreak( *m_pSentences, nPos ) );
491 }
492 
494  Boundary& rBound,
495  sal_Int32 nPos) const
496 {
497  OSL_ENSURE( m_pTextFrame != nullptr, "Need SwTextNode!" );
498 
499  // attribute boundaries can only occur on portion boundaries
502 }
503 
505 {
506  OSL_ENSURE(nPos <= TextFrameIndex(m_pTextFrame->GetText().getLength()), "illegal position");
507 
508  // find the portion number
509  // #i70538# - consider "empty" model portions - e.g. number portion
510  size_t nPortionNo = FindLastBreak( m_ViewPositions, nPos );
511 
512  sal_Int32 nRet = m_aAccessiblePositions[nPortionNo];
513 
514  // if the view portion has more than one position, go into it;
515  // else return that position
516  TextFrameIndex nStartPos = m_ViewPositions[nPortionNo];
517  TextFrameIndex nEndPos = m_ViewPositions[nPortionNo+1];
518  if ((nEndPos - nStartPos) > TextFrameIndex(1))
519  {
520  // 'wide' portions have to be of the same width
521  OSL_ENSURE( sal_Int32(nEndPos - nStartPos) ==
522  ( m_aAccessiblePositions[nPortionNo+1] -
523  m_aAccessiblePositions[nPortionNo] ),
524  "accessibility portion disagrees with text model" );
525 
526  TextFrameIndex nWithinPortion = nPos - m_ViewPositions[nPortionNo];
527  nRet += sal_Int32(nWithinPortion);
528  }
529  // else: return nRet unmodified
530 
531  OSL_ENSURE( (nRet >= 0) && (nRet <= m_sAccessibleString.getLength()),
532  "too long!" );
533  return nRet;
534 }
535 
537  sal_Int32 nPos,
538  SwSpecialPos& rPos,
539  SwSpecialPos*& rpPos ) const
540 {
541  size_t nPortionNo = FindLastBreak( m_aAccessiblePositions, nPos );
542 
544  sal_Int32 nRefPos(0);
545  TextFrameIndex nCorePos(0);
546 
547  if( nPortionNo < m_nBeforePortions )
548  {
549  nExtend = SwSPExtendRange::BEFORE;
550  rpPos = &rPos;
551  }
552  else
553  {
554  TextFrameIndex nCoreEndPos = m_ViewPositions[nPortionNo+1];
555  nCorePos = m_ViewPositions[nPortionNo];
556 
557  // skip backwards over zero-length portions, since GetCharRect()
558  // counts all model-zero-length portions as belonging to the
559  // previous portion
560  size_t nCorePortionNo = nPortionNo;
561  while (nCorePos == nCoreEndPos)
562  {
563  nCorePortionNo--;
564  nCoreEndPos = nCorePos;
565  nCorePos = m_ViewPositions[nCorePortionNo];
566 
567  OSL_ENSURE( nCorePos >= TextFrameIndex(0), "Can't happen." );
568  OSL_ENSURE( nCorePortionNo >= m_nBeforePortions, "Can't happen." );
569  }
570  OSL_ENSURE( nCorePos != nCoreEndPos,
571  "portion with core-representation expected" );
572 
573  // if we have anything except plain text, compute nExtend + nRefPos
574  if ((nCoreEndPos - nCorePos == TextFrameIndex(1)) &&
575  (m_pTextFrame->GetText()[sal_Int32(nCorePos)] != m_sAccessibleString[nPos]))
576  {
577  // case 1: a one-character, non-text portion
578  // reference position is the first accessibility for our
579  // core portion
580  nRefPos = m_aAccessiblePositions[ nCorePortionNo ];
581  nExtend = SwSPExtendRange::NONE;
582  rpPos = &rPos;
583  }
584  else if(nPortionNo != nCorePortionNo)
585  {
586  // case 2: a multi-character (text!) portion, followed by
587  // zero-length portions
588  // reference position is the first character of the next
589  // portion, and we are 'behind'
590  nRefPos = m_aAccessiblePositions[ nCorePortionNo+1 ];
591  nExtend = SwSPExtendRange::BEHIND;
592  rpPos = &rPos;
593  }
594  else
595  {
596  // case 3: regular text portion
597  OSL_ENSURE( sal_Int32(nCoreEndPos - nCorePos) ==
598  ( m_aAccessiblePositions[nPortionNo+1] -
599  m_aAccessiblePositions[nPortionNo] ),
600  "text portion expected" );
601 
602  nCorePos += TextFrameIndex(nPos - m_aAccessiblePositions[nPortionNo]);
603  rpPos = nullptr;
604  }
605  }
606  if( rpPos != nullptr )
607  {
608  OSL_ENSURE( rpPos == &rPos, "Yes!" );
609  OSL_ENSURE( nRefPos <= nPos, "wrong reference" );
610 
611  // get the line number, and adjust nRefPos for the line
612  // (if necessary)
613  size_t nRefLine = FindBreak( m_aLineBreaks, nRefPos );
614  size_t nMyLine = FindBreak( m_aLineBreaks, nPos );
615  sal_uInt16 nLineOffset = static_cast<sal_uInt16>( nMyLine - nRefLine );
616  if( nLineOffset != 0 )
617  nRefPos = m_aLineBreaks[ nMyLine ];
618 
619  // fill char offset and 'special position'
620  rPos.nCharOfst = nPos - nRefPos;
621  rPos.nExtendRange = nExtend;
622  rPos.nLineOfst = nLineOffset;
623  }
624 
625  return nCorePos;
626 }
627 
628 bool SwAccessiblePortionData::FillBoundaryIFDateField( css::i18n::Boundary& rBound, const sal_Int32 nPos )
629 {
630  if( m_aFieldPosition.size() < 2 )
631  return false;
632  for( size_t i = 0; i < m_aFieldPosition.size() - 1; i += 2 )
633  {
634  if( nPos < m_aFieldPosition[ i + 1 ] && nPos >= m_aFieldPosition[ i ] )
635  {
636  rBound.startPos = m_aFieldPosition[i];
637  rBound.endPos = m_aFieldPosition[i + 1];
638  return true;
639  }
640  }
641  return false;
642 }
643 
645  sal_Int32 nPos,
646  size_t& nPortionNo,
647  TextFrameIndex& rCorePos,
648  bool& bEdit) const
649 {
650  // find portion and get mode position
651  nPortionNo = FindBreak( m_aAccessiblePositions, nPos );
652  rCorePos = m_ViewPositions[ nPortionNo ];
653 
654  // for special portions, make sure we're on a portion boundary
655  // for text portions, add the in-portion offset
656  if( IsSpecialPortion( nPortionNo ) )
657  bEdit &= nPos == m_aAccessiblePositions[nPortionNo];
658  else
659  rCorePos += TextFrameIndex(nPos - m_aAccessiblePositions[nPortionNo]);
660 }
661 
663  sal_Int32 nStart, sal_Int32 nEnd,
664  TextFrameIndex& rCoreStart, TextFrameIndex& rCoreEnd) const
665 {
666  bool bIsEditable = true;
667 
668  // get start and end portions
669  size_t nStartPortion, nEndPortion;
670  AdjustAndCheck( nStart, nStartPortion, rCoreStart, bIsEditable );
671  AdjustAndCheck( nEnd, nEndPortion, rCoreEnd, bIsEditable );
672 
673  // iterate over portions, and make sure there is no read-only portion
674  // in-between
675  size_t nLastPortion = nEndPortion;
676 
677  // don't count last portion if we're in front of a special portion
678  if( IsSpecialPortion(nLastPortion) )
679  {
680  if (nLastPortion > 0)
681  nLastPortion--;
682  else
683  // special case: because size_t is usually unsigned, we can't just
684  // decrease nLastPortion to -1 (which would normally do the job, so
685  // this whole if wouldn't be needed). Instead, we'll do this
686  // special case and just increase the start portion beyond the last
687  // portion to make sure the loop below will have zero iteration.
688  nStartPortion = nLastPortion + 1;
689  }
690 
691  for( size_t nPor = nStartPortion; nPor <= nLastPortion; nPor++ )
692  {
693  bIsEditable &= ! IsPortionAttrSet(nPor, PORATTR_READONLY);
694  }
695 
696  return bIsEditable;
697 }
698 
700 {
701  // a position is valid if it's within the core view positions that we know
702  return (m_ViewPositions[0] <= nPos) && (nPos <= m_ViewPositions.back());
703 }
704 
706 {
707  if (m_ViewPositions.empty()) return true;
708  return m_ViewPositions[0] == TextFrameIndex(0)
709  && m_ViewPositions.back() == TextFrameIndex(0);
710 }
711 
713 {
714  for (const auto & pairPos : m_vecPairPos)
715  {
716  if(nIndex >= pairPos.first && nIndex < pairPos.second )
717  {
718  return true;
719  }
720  }
721  return false;
722 }
723 
725 {
726 // return IsGrayPortion( FindBreak( aAccessiblePositions, nPos ) );
728  PORATTR_GRAY );
729 }
730 
731 sal_Int32 SwAccessiblePortionData::GetFieldIndex(sal_Int32 nPos)
732 {
733  sal_Int32 nIndex = -1;
734  if( m_aFieldPosition.size() >= 2 )
735  {
736  for( size_t i = 0; i < m_aFieldPosition.size() - 1; i += 2 )
737  {
738  if( nPos <= m_aFieldPosition[ i + 1 ] && nPos >= m_aFieldPosition[ i ] )
739  {
740  nIndex = i/2;
741  break;
742  }
743  }
744  }
745  return nIndex;
746 }
747 
749 {
750  return m_ViewPositions[0];
751 }
752 
754 {
755  return m_ViewPositions.back();
756 }
757 
758 /* 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:149
#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
bool IsPagePreview() const
Definition: viewopt.hxx:596
sal_Int32 nCharOfst
Definition: crstate.hxx:110
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
Definition: txtfrm.cxx:1340
#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:224
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:1290
#define POR_TERMINATE
Definition: accportions.cxx:45
std::vector< sal_uInt8 > m_aPortionAttrs
Definition: accportions.hxx:67
bool IsReadonly() const
Definition: viewopt.hxx:424
OUStringBuffer m_aBuffer
Definition: accportions.hxx:45
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:131
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
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]
int i
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:212
PortionType
Definition: txttypes.hxx:23
TextFrameIndex m_nViewPosition
Definition: accportions.hxx:46
static bool IsFieldShadings()
Definition: viewopt.hxx:632
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 GetFieldIndex(sal_Int32 nPos)
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
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:247
SwSPExtendRange nExtendRange
Definition: crstate.hxx:112
AccessiblePositions m_aFieldPosition
portion breaks in m_sAccessibleString
Definition: accportions.hxx:65
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 const nLength
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
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.