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
49 #define PORATTR_GRAY 4
50 #define PORATTR_TERM 128
55 static size_t FindBreak(
const std::vector<T>& rPositions, T nValue);
59 static 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!" );
113 sal_Int32 , sal_Int32 ,
const SwFont* )
117 "portion exceeds model string!" );
119 OSL_ENSURE( !
m_bFinished,
"We are already done!" );
128 sDisplay = OUString(
u'\xfffc');
136 sDisplay = OUString(
u'\xfffc');
148 sal_Int32 nEnd=nStart + rText.getLength();
155 sDisplay = rText +
" ";
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];
372 static 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)" );
428 static size_t FindLastBreak(
const std::vector<T>& rPositions, T
const nValue)
430 size_t nResult =
FindBreak( rPositions, 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)
478 while (nCurrent < nLength);
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_uInt16 nLineOffset = o3tl::narrowing<sal_uInt16>( 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++ )
710 if(nIndex >= pairPos.first && nIndex < pairPos.second )
const OUString & GetAccessibleString() const
get the text string, as presented by the layout
const SwViewOption * m_pViewOptions
Represents the visualization of a paragraph.
SwAccessiblePortionData(const SwTextFrame *pTextFrame, const SwViewOption *pViewOpt)
AccessiblePositions m_aLineBreaks
bool IsPagePreview() const
LanguageType GetLangOfChar(TextFrameIndex nIndex, sal_uInt16 nScript, bool bNoChar=false) const
virtual ~SwAccessiblePortionData() override
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...
bool IsZeroCorePositionData()
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 ...
FramePositions m_ViewPositions
position of line breaks
void AdjustAndCheck(sal_Int32 nPos, size_t &nPortionNo, TextFrameIndex &rCorePos, bool &bEdit) const
const OUString & GetText() const
Returns the text portion we want to edit (for inline see underneath)
std::vector< sal_uInt8 > m_aPortionAttrs
size_t m_nBeforePortions
positions of sentence breaks
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
virtual void Skip(TextFrameIndex nLength) override
skip characters.
static sal_uInt8 nFramePos
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
bool IsInGrayPortion(sal_Int32 nPos)
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]
bool FillBoundaryIFDateField(css::i18n::Boundary &rBound, const sal_Int32 nPos)
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
TextFrameIndex m_nViewPosition
static bool IsFieldShadings()
css::uno::Reference< css::i18n::XBreakIterator > const & GetBreakIter() const
const css::lang::Locale & GetLocale(const LanguageType aLang)
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
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
AccessiblePositions m_aAccessiblePositions
position of portion breaks in the core view
SwSPExtendRange
SwSpecialPos.
void GetLastLineBoundary(css::i18n::Boundary &rBound) const
SwSPExtendRange nExtendRange
AccessiblePositions m_aFieldPosition
portion breaks in m_sAccessibleString
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
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.
bool m_bDetectedRangeSegmentation false