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