23#include <rtl/tencinfo.h>
37#include <editeng/editids.hrc>
38#include <vcl/font.hxx>
51 if ( aLangString ==
"ru" || aLangString ==
"uk" )
52 return RTL_TEXTENCODING_MS_1251;
53 if ( aLangString ==
"tr" )
54 return RTL_TEXTENCODING_MS_1254;
56 return RTL_TEXTENCODING_MS_1252;
67 , bIsSetDfltTab( false)
68 , bChkStyleAttr( false )
70 , bIsLeftToRightDef( true)
71 , bIsInReadStyleTab( false)
96 return SvParserState::Error;
117 if (eStatus != SvParserState::Pending && eStatus != SvParserState::Error)
157 case RTF_LINE: cCh =
'\n';
goto INSINGLECHAR;
158 case RTF_TAB: cCh =
'\t';
goto INSINGLECHAR;
161 case RTF_EMDASH: cCh = 0x2014;
goto INSINGLECHAR;
162 case RTF_ENDASH: cCh = 0x2013;
goto INSINGLECHAR;
163 case RTF_BULLET: cCh = 0x2022;
goto INSINGLECHAR;
164 case RTF_LQUOTE: cCh = 0x2018;
goto INSINGLECHAR;
165 case RTF_RQUOTE: cCh = 0x2019;
goto INSINGLECHAR;
169 aToken = OUStringChar(cCh);
274 sal_uInt16 nStyleNo = 0;
275 bool bHasStyleNo =
false;
276 int _nOpenBrackets = 1;
306 eState = SvParserState::Error;
328 xStyle->sName =
aToken.toString();
353 auto nEnteringToken =
nToken;
356 int nSkippedTokens = 0;
370 if (nSkippedTokens &&
m_nTokenIndex == nEnteringIndex - nSkippedTokens)
396 sal_uInt8 nRed = 0xff, nGreen = 0xff, nBlue = 0xff;
410 if( 1 ==
aToken.getLength()
412 : -1 ==
aToken.indexOf(
";" ) )
422 Color aColor( nRed, nGreen, nBlue );
443 int _nOpenBrackets = 1;
445 short nFontNo(0), nInsFontNo (0);
446 OUString sAltNm, sFntNm;
447 bool bIsAltFntNm =
false;
455 bool bCheckNewFont =
false;
465 bCheckNewFont =
true;
466 nInsFontNo = nFontNo;
483 eState = SvParserState::Error;
513 rtl_TextEncoding nrtl_TextEncoding = rtl_getTextEncodingFromWindowsCharset(
518 if (nrtl_TextEncoding == RTL_TEXTENCODING_SYMBOL)
519 nrtl_TextEncoding = RTL_TEXTENCODING_DONTKNOW;
535 bCheckNewFont =
true;
536 nInsFontNo = nFontNo;
554 if( bCheckNewFont && 1 >= _nOpenBrackets && !sFntNm.isEmpty() )
557 if (!sAltNm.isEmpty())
558 sFntNm +=
";" + sAltNm;
561 m_FontTable.insert(std::make_pair(nInsFontNo, aFont));
588 if( !rStr.isEmpty() && cDel == rStr[ rStr.getLength()-1 ])
589 rStr.setLength( rStr.getLength()-1 );
617 return std::make_unique<MakeUniqueEnabler>(rPool, pWhichRange, rEditPosition);
623 std::unique_ptr<SvxRTFItemStackType> xNew;
625 xNew = std::make_unique<SvxRTFItemStackType>(*pCurrent, *
mxInsertPosition,
false);
633 throw std::range_error(
"ecStackOverflow");
655 SfxItemState::SET == aIter.
GetItemState(
false, &pItem ) &&
669 if( SfxItemState::SET == rStyleSet.
GetItemState( nWhich,
true, &pSItem ))
671 if( SfxItemState::SET == aIter.
GetItemState(
false, &pItem )
672 && *pItem == *pSItem )
676 SfxItemState::SET == aIter.
GetItemState(
false, &pItem ) &&
688 std::unique_ptr<SvxRTFItemStackType> pOld = std::move(
aAttrStack.back());
693 sal_Int32 nOldSttNdIdx = pOld->mxStartNodeIdx->GetIdx();
694 if (pOld->maChildList.empty() &&
695 ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) ||
708 pItem->
Which(),
false, &pGet ) &&
715 if (!pOld->aAttrSet.Count() && pOld->maChildList.empty() &&
748 auto xNew = std::make_unique<SvxRTFItemStackType>(*pOld, *
mxInsertPosition,
true);
749 xNew->aAttrSet.SetParent( pOld->aAttrSet.GetParent() );
753 if (sal_uInt16 wid = pair.second)
754 xNew->aAttrSet.ClearItem(wid);
758 if( xNew->aAttrSet.Count() == pOld->aAttrSet.Count() )
778 pCurrent->
Add(std::move(pOld));
779 pCurrent->
Add(std::move(xNew));
812 pCurrent->
Add(std::move(pOld));
815 if (bCrsrBack && 50 < pCurrent->
maChildList.size())
822 auto xNew(std::make_unique<SvxRTFItemStackType>(*pCurrent, *
mxInsertPosition,
true));
828 xNew->aAttrSet.SetParent( pCurrent ? &pCurrent->
aAttrSet :
nullptr );
857 pStkSet->DropChildList();
869 if (!
rSet.maChildList.empty())
870 rSet.Compress( *
this );
875 for (
size_t n = 0;
n <
rSet.maChildList.size(); ++
n)
899 static constexpr sal_uInt16 WIDS1[] {
900 SID_ATTR_PARA_LINESPACE,
901 SID_ATTR_PARA_ADJUST,
903 SID_ATTR_PARA_HYPHENZONE,
907 SID_ATTR_BORDER_OUTER,
908 SID_ATTR_BORDER_SHADOW,
909 SID_ATTR_PARA_OUTLLEVEL,
913 SID_ATTR_PARA_SCRIPTSPACE,
914 SID_ATTR_PARA_HANGPUNCTUATION,
915 SID_ATTR_PARA_FORBIDDEN_RULES,
916 SID_ATTR_FRAMEDIRECTION,
918 for (sal_uInt16 nWid : WIDS1)
930 static constexpr sal_uInt16 WIDS[] {
931 SID_ATTR_CHAR_CASEMAP, SID_ATTR_BRUSH_CHAR, SID_ATTR_CHAR_COLOR,
932 SID_ATTR_CHAR_CONTOUR, SID_ATTR_CHAR_STRIKEOUT, SID_ATTR_CHAR_ESCAPEMENT,
933 SID_ATTR_CHAR_FONT, SID_ATTR_CHAR_FONTHEIGHT, SID_ATTR_CHAR_KERNING,
934 SID_ATTR_CHAR_LANGUAGE, SID_ATTR_CHAR_POSTURE, SID_ATTR_CHAR_SHADOWED,
935 SID_ATTR_CHAR_UNDERLINE, SID_ATTR_CHAR_OVERLINE, SID_ATTR_CHAR_WEIGHT,
936 SID_ATTR_CHAR_WORDLINEMODE, SID_ATTR_CHAR_AUTOKERN, SID_ATTR_CHAR_CJK_FONT,
937 SID_ATTR_CHAR_CJK_FONTHEIGHT, sal_uInt16(SID_ATTR_CHAR_CJK_LANGUAGE), SID_ATTR_CHAR_CJK_POSTURE,
938 SID_ATTR_CHAR_CJK_WEIGHT, SID_ATTR_CHAR_CTL_FONT, SID_ATTR_CHAR_CTL_FONTHEIGHT,
939 SID_ATTR_CHAR_CTL_LANGUAGE, SID_ATTR_CHAR_CTL_POSTURE, SID_ATTR_CHAR_CTL_WEIGHT,
940 SID_ATTR_CHAR_EMPHASISMARK, SID_ATTR_CHAR_TWO_LINES, SID_ATTR_CHAR_SCALEWIDTH,
941 SID_ATTR_CHAR_ROTATED, SID_ATTR_CHAR_RELIEF, SID_ATTR_CHAR_HIDDEN,
943 for (sal_uInt16 nWid : WIDS)
958 if (
const sal_uInt16
nId =
aPardMap[SID_ATTR_PARA_SCRIPTSPACE])
972 : aAttrSet(rPool, pWhichRange)
981 : aAttrSet( rPool, pWhichRange )
982 , mxStartNodeIdx(rPos.MakeNodeIdx())
983#
if !defined(__COVERITY__)
985 , mxEndNodeIdx(mxStartNodeIdx)
987 , nSttCnt(rPos.GetCntIdx())
996 bool const bCopyAttr )
997 : aAttrSet( *rCpy.aAttrSet.GetPool(), rCpy.aAttrSet.
GetRanges() )
998 , mxStartNodeIdx(rPos.MakeNodeIdx())
999#
if !defined(__COVERITY__)
1001 , mxEndNodeIdx(mxStartNodeIdx)
1003 , nSttCnt(rPos.GetCntIdx())
1005 , nStyleNo(rCpy.nStyleNo)
1027 std::vector<SvxRTFItemStackType*> bfs;
1028 std::queue<SvxRTFItemStackType*> aQueue;
1031 while (!aQueue.empty())
1033 auto* front = aQueue.front();
1035 if (!front->maChildList.empty())
1037 for (
const auto&
a : front->maChildList)
1038 aQueue.push(
a.get());
1039 bfs.push_back(front);
1043 for (
auto it = bfs.rbegin(); it != bfs.rend(); ++it)
1078 sal_Int32 nLastCnt = pTmp->
nEndCnt;
1089 !rParser.
IsEndPara( &aLastNd, nLastCnt ) )
1090 : ( pTmp->
nSttCnt != nLastCnt ||
1109 sal_uInt16 nWhich = pIterItem->
Which();
1111 false, &pItem ) || *pItem != *pIterItem)
1117 if( !aMrgSet.
Count() )
1132 while (
n < nChildLen)
1148 if( rDefaults.
Count() )
1153 sal_uInt16 nWhich = pItem->
Which();
static const AllSettings & GetSettings()
sal_Int32 GetCntIdx() const
EditNodeIdx MakeNodeIdx() const
const SfxPoolItem * GetCurItem() const
const SfxPoolItem * NextItem()
const SfxPoolItem & GetDefaultItem(sal_uInt16 nWhich) const
sal_uInt16 GetTrueWhich(sal_uInt16 nSlot, bool bDeep=true) const
static bool IsWhich(sal_uInt16 nId)
void SetPoolDefaultItem(const SfxPoolItem &)
SfxItemPool * GetPool() const
void SetParent(const SfxItemSet *pNew)
sal_uInt16 ClearItem(sal_uInt16 nWhich=0)
SfxItemState GetItemState(sal_uInt16 nWhich, bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
const SfxPoolItem * Put(const SfxPoolItem &rItem, sal_uInt16 nWhich)
void Differentiate(const SfxItemSet &rSet)
sal_uInt16 GetCurWhich() const
SfxItemState GetItemState(bool bSrchInParent=true, const SfxPoolItem **ppItem=nullptr) const
SvParserState GetStatus() const
TokenStackType * GetStackPtr(short nCnt)
bool IsParserWorking() const
tools::Long m_nTokenIndex
T SkipToken(short nCnt=-1)
virtual void Continue(int nToken) override
virtual SvParserState CallParser() override
void SetEncoding(rtl_TextEncoding eEnc)
This item describes a Font.
FontFamily GetFamily() const
const OUString & GetStyleName() const
SvxRTFItemStackList maChildList
SvxRTFItemStackType(SvxRTFItemStackType const &)=delete
void SetRTFDefaults(const SfxItemSet &rDefaults)
std::optional< EditNodeIdx > mxStartNodeIdx
std::optional< EditNodeIdx > mxEndNodeIdx
void SetStartPos(const EditPosition &rPos)
static std::unique_ptr< SvxRTFItemStackType > createSvxRTFItemStackType(SfxItemPool &, const WhichRangesContainer &pWhichRange, const EditPosition &)
void Compress(const SvxRTFParser &)
SfxItemSet & GetAttrSet()
void Add(std::unique_ptr< SvxRTFItemStackType >)
SvxRTFParser(SvxRTFParser const &)=delete
WhichRangesContainer aWhichMap
virtual void InsertText()=0
void SetAttrSet(SvxRTFItemStackType &rSet)
static void DelCharAtEnd(OUStringBuffer &rStr, const sal_Unicode cDel)
bool IsChkStyleAttr() const
virtual void InsertPara()=0
std::optional< Color > mxDefaultColor
virtual void SetEndPrevPara(std::optional< EditNodeIdx > &rpNodePos, sal_Int32 &rCntPos)=0
SvxRTFStyleTbl m_StyleTable
virtual void Continue(int nToken) override
virtual bool IsEndPara(EditNodeIdx *pNd, sal_Int32 nCnt) const =0
std::vector< Color > maColorTable
std::optional< vcl::Font > pDfltFont
std::optional< EditPosition > mxInsertPosition
SvxRTFFontTbl m_FontTable
std::unique_ptr< SfxItemSet > pRTFDefaults
void ReadAttr(int nToken, SfxItemSet *pSet)
virtual void NextToken(int nToken) override
virtual SvParserState CallParser() override
const vcl::Font & GetFont(sal_uInt16 nId)
void ClearStyleAttr_(SvxRTFItemStackType &rStkType)
const SfxItemSet & GetRTFDefaults()
SvxRTFItemStackList m_AttrSetList
virtual ~SvxRTFParser() override
virtual void SetAttrInDoc(SvxRTFItemStackType &rSet)
void SetInsPos(const EditPosition &rNew)
SfxItemSet & GetAttrSet()
void SetDefault(int nToken, int nValue)
SvxRTFItemStackType * GetAttrSet_()
std::deque< std::unique_ptr< SvxRTFItemStackType > > aAttrStack
virtual void MovePos(bool bForward=true)=0
void SetPitch(FontPitch ePitch)
void SetFamily(FontFamily)
void SetCharSet(rtl_TextEncoding)
void SetFamilyName(const OUString &rFamilyName)
constexpr ::Color COL_AUTO(ColorTransparency, 0xFF, 0xFF, 0xFF, 0xFF)
#define DBG_ASSERT(sCon, aError)
#define ENSURE_OR_RETURN_VOID(c, m)
if(aStr !=aBuf) UpdateName_Impl(m_xFollowLb.get()
bool GetRanges(std::vector< std::shared_ptr< SwUnoCursor > > &rRanges, SwDoc &rDoc, SwPaM const &rDelPam)
const wchar_t *typedef int(__stdcall *DllNativeUnregProc)(int
std::map< sal_uInt16, sal_uInt16 > data
SvxRTFStyleType(SfxItemPool &rPool, const WhichRangesContainer &pWhichRange)
SAL_WARN_UNUSED_RESULT WhichRangesContainer MergeRange(sal_uInt16 nFrom, sal_uInt16 nTo) const
static rtl_TextEncoding lcl_GetDefaultTextEncodingForRTF()