23#include <osl/diagnose.h>
24#include <rtl/ustring.hxx>
25#include <com/sun/star/i18n/Boundary.hpp>
26#include <com/sun/star/i18n/XBreakIterator.hpp>
44#define POR_TERMINATE PortionType::NONE
47#define PORATTR_SPECIAL 1
48#define PORATTR_READONLY 2
50#define PORATTR_TERM 128
55static size_t FindBreak(
const std::vector<T>& rPositions, T nValue);
59static size_t FindLastBreak(
const std::vector<T>& rPositions, T nValue);
65 m_pTextFrame(pTextFrame),
67 m_pViewOptions( pViewOpt ),
68 m_nBeforePortions( 0 ),
71 OSL_ENSURE(
m_pTextFrame !=
nullptr,
"Need SwTextFrame!" );
90 "portion exceeds model string!" );
116 "portion exceeds model string!" );
118 OSL_ENSURE( !
m_bFinished,
"We are already done!" );
147 sal_Int32 nEnd=nStart + rText.getLength();
200 OSL_ENSURE( !
m_bFinished,
"We are already done!" );
207 OSL_ENSURE( !
m_bFinished,
"We are already done!" );
210 "skip exceeds model string!" );
217 OSL_ENSURE( !
m_bFinished,
"We are already done!" );
232 size_t nPortionNo,
sal_uInt8 nAttr )
const
235 "Illegal portion number" );
275 OSL_ENSURE(
m_bFinished,
"Shouldn't call this before we are done!" );
282 sal_Int32 nPos )
const
296 sal_Int32 nLineCount = ( nBreaks > 3 )
298 : ( ( nBreaks == 3 ) ? 1 : 0 );
308 if ( nLineNo >= nLineCount )
310 nLineNo = nLineCount - 1;
317 i18n::Boundary& rLineBound )
323 Boundary& rBound )
const
325 OSL_ENSURE(
m_aLineBreaks.size() >= 2,
"need min + max value" );
335 OSL_ENSURE(
nPos >= 0,
"illegal position" );
352 "accessibility portion disagrees with text model" );
358 OSL_ENSURE(nStartPos >=
TextFrameIndex(0),
"There's something weird in number of characters of SwTextFrame");
367 rBound.startPos = rPositions[
nPos];
368 rBound.endPos = rPositions[
nPos+1];
372static size_t FindBreak(
const std::vector<T>& rPositions, T
const nValue)
374 OSL_ENSURE( rPositions.size() >= 2,
"need min + max value" );
375 OSL_ENSURE( rPositions[0] <=
nValue,
"need min value" );
376 OSL_ENSURE( rPositions[rPositions.size()-1] >=
nValue,
377 "need first terminator value" );
378 OSL_ENSURE( rPositions[rPositions.size()-2] >=
nValue,
379 "need second terminator value" );
382 size_t nMax = rPositions.size()-2;
385 while( nMin+1 < nMax )
388 OSL_ENSURE( ( (nMin == 0) && (rPositions[nMin] <=
nValue) ) ||
389 ( (nMin != 0) && (rPositions[nMin] <
nValue) ),
390 "minvalue not minimal" );
391 OSL_ENSURE(
nValue <= rPositions[nMax],
"max value not maximal" );
394 size_t nMiddle = (nMin + nMax)/2;
395 OSL_ENSURE( nMin < nMiddle,
"progress?" );
396 OSL_ENSURE( nMiddle < nMax,
"progress?" );
399 OSL_ENSURE( rPositions[nMin] <= rPositions[nMiddle],
400 "garbled positions array" );
401 OSL_ENSURE( rPositions[nMiddle] <= rPositions[nMax],
402 "garbled positions array" );
404 if(
nValue > rPositions[nMiddle] )
411 OSL_ENSURE( (nMax == nMin) || (nMax == nMin+1),
"only two left" );
412 if( (rPositions[nMin] <
nValue) && (rPositions[nMin+1] <=
nValue) )
416 OSL_ENSURE( rPositions[nMin] <=
nValue,
"not smaller or equal" );
417 OSL_ENSURE(
nValue <= rPositions[nMin+1],
"not equal or larger" );
418 OSL_ENSURE( (nMin == 0) || (rPositions[nMin-1] <=
nValue),
419 "earlier value should have been returned" );
421 OSL_ENSURE( nMin < rPositions.size()-1,
422 "shouldn't return last position (due to terminator values)" );
428static size_t FindLastBreak(
const std::vector<T>& rPositions, T
const nValue)
434 while ( nResult < rPositions.size() - 2 &&
435 rPositions[nResult+1] <=
nValue )
447 OSL_ENSURE(
nPos >= 0,
"illegal position; check before" );
459 sal_Int32 nCurrent = 0;
471 if( (nNew < 0) && (nNew >
nLength) )
473 else if (nNew <= nCurrent)
490 sal_Int32 nPos)
const
492 OSL_ENSURE(
m_pTextFrame !=
nullptr,
"Need SwTextNode!" );
516 OSL_ENSURE( sal_Int32(nEndPos - nStartPos) ==
519 "accessibility portion disagrees with text model" );
522 nRet += sal_Int32(nWithinPortion);
539 sal_Int32 nRefPos(0);
555 size_t nCorePortionNo = nPortionNo;
556 while (nCorePos == nCoreEndPos)
559 nCoreEndPos = nCorePos;
565 OSL_ENSURE( nCorePos != nCoreEndPos,
566 "portion with core-representation expected" );
578 else if(nPortionNo != nCorePortionNo)
591 OSL_ENSURE( sal_Int32(nCoreEndPos - nCorePos) ==
594 "text portion expected" );
600 if( rpPos !=
nullptr )
602 OSL_ENSURE( rpPos == &rPos,
"Yes!" );
603 OSL_ENSURE( nRefPos <=
nPos,
"wrong reference" );
609 sal_Int32 nLineOffset = o3tl::narrowing<sal_Int32>( nMyLine - nRefLine );
610 if( nLineOffset != 0 )
657 sal_Int32 nStart, sal_Int32 nEnd,
660 bool bIsEditable =
true;
663 size_t nStartPortion, nEndPortion;
669 size_t nLastPortion = nEndPortion;
674 if (nLastPortion > 0)
682 nStartPortion = nLastPortion + 1;
685 for(
size_t nPor = nStartPortion; nPor <= nLastPortion; nPor++ )
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...
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...
static size_t FindLastBreak(const std::vector< T > &rPositions, T nValue)
like FindBreak, but finds the last equal or larger position
static sal_uInt8 nFramePos
virtual void Text(TextFrameIndex nLength, PortionType nType) override
(empty) destructor
void GetBoundaryOfLine(const sal_Int32 nLineNo, css::i18n::Boundary &rLineBound)
bool FillBoundaryIFDateField(css::i18n::Boundary &rBound, const sal_Int32 nPos)
bool IsIndexInFootnode(sal_Int32 nIndex)
bool IsGrayPortionType(PortionType nType) const
AccessiblePositions m_aAccessiblePositions
position of portion breaks in the core view
sal_Int32 GetFieldIndex(sal_Int32 nPos) const
std::unique_ptr< AccessiblePositions > m_pSentences
additional portion attributes
void GetSentenceBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos)
AccessiblePositions m_aLineBreaks
static void FillBoundary(css::i18n::Boundary &rBound, const AccessiblePositions &rPositions, size_t nPos)
fill the boundary with the values from rPositions[nPos]
void GetAttributeBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos) const
bool IsInGrayPortion(sal_Int32 nPos)
bool GetEditableRange(sal_Int32 nStart, sal_Int32 nEnd, TextFrameIndex &rCoreStart, TextFrameIndex &rCoreEnd) const
Convert start and end positions into core positions.
TextFrameIndex GetCoreViewPosition(sal_Int32 nPos) const
get the position in the core view string for a given (accessibility) position
AccessiblePositions m_aFieldPosition
portion breaks in m_sAccessibleString
void GetLineBoundary(css::i18n::Boundary &rBound, sal_Int32 nPos) const
get the start & end positions of the sentence
bool IsSpecialPortion(size_t nPortionNo) const
std::vector< sal_Int32 > AccessiblePositions
void GetLastLineBoundary(css::i18n::Boundary &rBound) const
const OUString & GetAccessibleString() const
get the text string, as presented by the layout
std::vector< std::pair< sal_Int32, sal_Int32 > > m_vecPairPos
FramePositions m_ViewPositions
position of line breaks
virtual void Finish() override
end of paragraph.
bool IsZeroCorePositionData()
std::vector< sal_uInt8 > m_aPortionAttrs
sal_Int32 GetLineCount() const
virtual void Skip(TextFrameIndex nLength) override
skip characters.
sal_Int32 GetAccessiblePosition(TextFrameIndex nPos) const
get the position in the accessibility string for a given view position
TextFrameIndex m_nViewPosition
TextFrameIndex FillSpecialPos(sal_Int32 nPos, SwSpecialPos &rPos, SwSpecialPos *&rpPos) const
fill a SwSpecialPos structure, suitable for calling SwTextFrame->GetCharRect Returns the core positio...
TextFrameIndex GetLastValidCorePosition() const
virtual void LineBreak() override
line break.
OUString m_sAccessibleString
the accessible string note that the content is different both from the string in the text node(s) as ...
size_t m_nBeforePortions
positions of sentence breaks
const SwViewOption * m_pViewOptions
SwAccessiblePortionData(const SwTextFrame *pTextFrame, const SwViewOption *pViewOpt)
bool IsPortionAttrSet(size_t nPortionNo, sal_uInt8 nAttr) const
Access to portion attributes.
bool IsValidCorePosition(TextFrameIndex nPos) const
Determine whether this core position is valid for these portions.
TextFrameIndex GetFirstValidCorePosition() const
sal_Int32 GetLineNo(const sal_Int32 nPos) const
void AdjustAndCheck(sal_Int32 nPos, size_t &nPortionNo, TextFrameIndex &rCorePos, bool &bEdit) const
virtual ~SwAccessiblePortionData() override
SwTextFrame const * m_pTextFrame
virtual void Special(TextFrameIndex nLength, const OUString &rText, PortionType nType) override
special portion.
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
const css::lang::Locale & GetLocale(const LanguageType aLang)
Represents the visualization of a paragraph.
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
bool IsPagePreview() const
bool IsShowBookmarks(bool const bHard=false) const
bool IsTab(bool bHard=false) const
bool IsFieldShadings() const
SwSPExtendRange
SwSpecialPos.
SwSPExtendRange nExtendRange