summaryrefslogtreecommitdiffstats
path: root/editeng/source/rtf
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-27 16:51:28 +0000
commit940b4d1848e8c70ab7642901a68594e8016caffc (patch)
treeeb72f344ee6c3d9b80a7ecc079ea79e9fba8676d /editeng/source/rtf
parentInitial commit. (diff)
downloadlibreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.tar.xz
libreoffice-940b4d1848e8c70ab7642901a68594e8016caffc.zip
Adding upstream version 1:7.0.4.upstream/1%7.0.4upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'editeng/source/rtf')
-rw-r--r--editeng/source/rtf/rtfitem.cxx1895
-rw-r--r--editeng/source/rtf/svxrtf.cxx1180
2 files changed, 3075 insertions, 0 deletions
diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx
new file mode 100644
index 000000000..dab691d39
--- /dev/null
+++ b/editeng/source/rtf/rtfitem.cxx
@@ -0,0 +1,1895 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include <editeng/fontitem.hxx>
+#include <editeng/postitem.hxx>
+#include <editeng/wghtitem.hxx>
+#include <editeng/fhgtitem.hxx>
+#include <editeng/udlnitem.hxx>
+#include <editeng/crossedoutitem.hxx>
+#include <editeng/shdditem.hxx>
+#include <editeng/autokernitem.hxx>
+#include <editeng/wrlmitem.hxx>
+#include <editeng/contouritem.hxx>
+#include <editeng/colritem.hxx>
+#include <editeng/kernitem.hxx>
+#include <editeng/cmapitem.hxx>
+#include <editeng/escapementitem.hxx>
+#include <editeng/langitem.hxx>
+#include <editeng/emphasismarkitem.hxx>
+#include <editeng/twolinesitem.hxx>
+#include <editeng/lrspitem.hxx>
+#include <editeng/ulspitem.hxx>
+#include <editeng/shaditem.hxx>
+#include <editeng/borderline.hxx>
+#include <editeng/boxitem.hxx>
+#include <editeng/keepitem.hxx>
+#include <editeng/brushitem.hxx>
+#include <editeng/lspcitem.hxx>
+#include <editeng/adjustitem.hxx>
+#include <editeng/tstpitem.hxx>
+#include <editeng/spltitem.hxx>
+#include <editeng/hyphenzoneitem.hxx>
+#include <editeng/charscaleitem.hxx>
+#include <editeng/charrotateitem.hxx>
+#include <editeng/charreliefitem.hxx>
+#include <editeng/paravertalignitem.hxx>
+#include <editeng/forbiddenruleitem.hxx>
+#include <editeng/hngpnctitem.hxx>
+#include <editeng/scriptspaceitem.hxx>
+#include <editeng/frmdiritem.hxx>
+#include <editeng/charhiddenitem.hxx>
+
+#include <svtools/rtftoken.h>
+#include <svl/itempool.hxx>
+#include <svl/itemiter.hxx>
+#include <sal/log.hxx>
+#include <vcl/font.hxx>
+
+#include <editeng/svxrtf.hxx>
+#include <editeng/editids.hrc>
+
+#include <limits.h>
+
+#define BRACELEFT '{'
+#define BRACERIGHT '}'
+
+using namespace ::com::sun::star;
+using namespace editeng;
+
+void SvxRTFParser::SetScriptAttr( RTF_CharTypeDef eType, SfxItemSet& rSet,
+ SfxPoolItem& rItem )
+{
+ const sal_uInt16 *pNormal = nullptr, *pCJK = nullptr, *pCTL = nullptr;
+ switch( rItem.Which() )
+ {
+ case SID_ATTR_CHAR_FONT:
+ pNormal = &aPlainMap.nFont;
+ pCJK = &aPlainMap.nCJKFont;
+ pCTL = &aPlainMap.nCTLFont;
+ break;
+
+ case SID_ATTR_CHAR_FONTHEIGHT:
+ pNormal = &aPlainMap.nFontHeight;
+ pCJK = &aPlainMap.nCJKFontHeight;
+ pCTL = &aPlainMap.nCTLFontHeight;
+ break;
+
+ case SID_ATTR_CHAR_POSTURE:
+ pNormal = &aPlainMap.nPosture;
+ pCJK = &aPlainMap.nCJKPosture;
+ pCTL = &aPlainMap.nCTLPosture;
+ break;
+
+ case SID_ATTR_CHAR_WEIGHT:
+ pNormal = &aPlainMap.nWeight;
+ pCJK = &aPlainMap.nCJKWeight;
+ pCTL = &aPlainMap.nCTLWeight;
+ break;
+
+ case SID_ATTR_CHAR_LANGUAGE:
+ pNormal = &aPlainMap.nLanguage;
+ pCJK = &aPlainMap.nCJKLanguage;
+ pCTL = &aPlainMap.nCTLLanguage;
+ break;
+
+ case 0:
+ // it exist no WhichId - don't set this item
+ break;
+
+ default:
+ rSet.Put( rItem );
+ break;
+ }
+
+ if( DOUBLEBYTE_CHARTYPE == eType )
+ {
+ if( bIsLeftToRightDef && pCJK )
+ {
+ rItem.SetWhich( *pCJK );
+ rSet.Put( rItem );
+ }
+ }
+ else if( !bIsLeftToRightDef )
+ {
+ if( pCTL )
+ {
+ rItem.SetWhich( *pCTL );
+ rSet.Put( rItem );
+ }
+ }
+ else
+ {
+ if( LOW_CHARTYPE == eType )
+ {
+ if( pNormal )
+ {
+ rItem.SetWhich( *pNormal );
+ rSet.Put( rItem );
+ }
+ }
+ else if( HIGH_CHARTYPE == eType )
+ {
+ if( pCTL )
+ {
+ rItem.SetWhich( *pCTL );
+ rSet.Put( rItem );
+ }
+ }
+ else
+ {
+ if( pCJK )
+ {
+ rItem.SetWhich( *pCJK );
+ rSet.Put( rItem );
+ }
+ if( pCTL )
+ {
+ rItem.SetWhich( *pCTL );
+ rSet.Put( rItem );
+ }
+ if( pNormal )
+ {
+ rItem.SetWhich( *pNormal );
+ rSet.Put( rItem );
+ }
+ }
+ }
+}
+
+
+void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
+{
+ DBG_ASSERT( pSet, "A SfxItemSet has to be provided as argument!" );
+ bool bFirstToken = true;
+ bool bContinue = true;
+ FontLineStyle eUnderline;
+ FontLineStyle eOverline;
+ FontEmphasisMark eEmphasis;
+ RTF_CharTypeDef eCharType = NOTDEF_CHARTYPE;
+ SvxParaVertAlignItem::Align nFontAlign;
+
+ bool bChkStkPos = !bNewGroup && !aAttrStack.empty();
+
+ while( bContinue && IsParserWorking() ) // as long as known Attribute are recognized
+ {
+ switch( nToken )
+ {
+ case RTF_PARD:
+ RTFPardPlain( true, &pSet );
+ break;
+
+ case RTF_PLAIN:
+ RTFPardPlain( false, &pSet );
+ break;
+
+ default:
+ do { // middle checked loop
+ if( !bChkStkPos )
+ break;
+
+ SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
+ if( !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
+ pCurrent->nSttCnt == pInsPos->GetCntIdx() ))
+ break;
+
+ int nLastToken = GetStackPtr(-1)->nTokenId;
+ if( RTF_PARD == nLastToken || RTF_PLAIN == nLastToken )
+ break;
+
+ if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList ||
+ pCurrent->nStyleNo )
+ {
+ // Open a new Group
+ std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType(
+ *pCurrent, *pInsPos, true ));
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // "Set" all valid attributes up until this point
+ AttrGroupEnd();
+ pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
+ pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
+
+ aAttrStack.push_back( std::move(pNew) );
+ pCurrent = aAttrStack.back().get();
+ }
+ else
+ // continue to use this entry as a new one
+ pCurrent->SetStartPos( *pInsPos );
+
+ pSet = &pCurrent->aAttrSet;
+ } while( false );
+
+ switch( nToken )
+ {
+ case RTF_INTBL:
+ case RTF_PAGEBB:
+ case RTF_SBYS:
+ case RTF_CS:
+ case RTF_LS:
+ case RTF_ILVL:
+ UnknownAttrToken( nToken );
+ break;
+
+ case RTF_S:
+ if( bIsInReadStyleTab )
+ {
+ if( !bFirstToken )
+ SkipToken();
+ bContinue = false;
+ }
+ else
+ {
+ sal_uInt16 nStyleNo = -1 == nTokenValue ? 0 : sal_uInt16(nTokenValue);
+ // set StyleNo to the current style on the AttrStack
+ SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
+ if( !pCurrent )
+ break;
+
+ pCurrent->nStyleNo = nStyleNo;
+ }
+ break;
+
+ case RTF_KEEP:
+ if( aPardMap.nSplit )
+ {
+ pSet->Put( SvxFormatSplitItem( false, aPardMap.nSplit ));
+ }
+ break;
+
+ case RTF_KEEPN:
+ if( aPardMap.nKeep )
+ {
+ pSet->Put( SvxFormatKeepItem( true, aPardMap.nKeep ));
+ }
+ break;
+
+ case RTF_LEVEL:
+ if( aPardMap.nOutlineLvl )
+ {
+ pSet->Put( SfxInt16Item( aPardMap.nOutlineLvl,
+ static_cast<sal_uInt16>(nTokenValue) ));
+ }
+ break;
+
+ case RTF_QL:
+ if( aPardMap.nAdjust )
+ {
+ pSet->Put( SvxAdjustItem( SvxAdjust::Left, aPardMap.nAdjust ));
+ }
+ break;
+ case RTF_QR:
+ if( aPardMap.nAdjust )
+ {
+ pSet->Put( SvxAdjustItem( SvxAdjust::Right, aPardMap.nAdjust ));
+ }
+ break;
+ case RTF_QJ:
+ if( aPardMap.nAdjust )
+ {
+ pSet->Put( SvxAdjustItem( SvxAdjust::Block, aPardMap.nAdjust ));
+ }
+ break;
+ case RTF_QC:
+ if( aPardMap.nAdjust )
+ {
+ pSet->Put( SvxAdjustItem( SvxAdjust::Center, aPardMap.nAdjust ));
+ }
+ break;
+
+ case RTF_FI:
+ if( aPardMap.nLRSpace )
+ {
+ SvxLRSpaceItem aLR(
+ static_cast<const SvxLRSpaceItem&>(pSet->Get(aPardMap.nLRSpace)));
+ sal_uInt16 nSz = 0;
+ if( -1 != nTokenValue )
+ {
+ if( IsCalcValue() )
+ CalcValue();
+ nSz = sal_uInt16(nTokenValue);
+ }
+ aLR.SetTextFirstLineOffset( nSz );
+ pSet->Put( aLR );
+ }
+ break;
+
+ case RTF_LI:
+ case RTF_LIN:
+ if( aPardMap.nLRSpace )
+ {
+ SvxLRSpaceItem aLR(
+ static_cast<const SvxLRSpaceItem&>(pSet->Get(aPardMap.nLRSpace)));
+ sal_uInt16 nSz = 0;
+ if( 0 < nTokenValue )
+ {
+ if( IsCalcValue() )
+ CalcValue();
+ nSz = sal_uInt16(nTokenValue);
+ }
+ aLR.SetTextLeft( nSz );
+ pSet->Put( aLR );
+ }
+ break;
+
+ case RTF_RI:
+ case RTF_RIN:
+ if( aPardMap.nLRSpace )
+ {
+ SvxLRSpaceItem aLR(
+ static_cast<const SvxLRSpaceItem&>(pSet->Get(aPardMap.nLRSpace)));
+ sal_uInt16 nSz = 0;
+ if( 0 < nTokenValue )
+ {
+ if( IsCalcValue() )
+ CalcValue();
+ nSz = sal_uInt16(nTokenValue);
+ }
+ aLR.SetRight( nSz );
+ pSet->Put( aLR );
+ }
+ break;
+
+ case RTF_SB:
+ if( aPardMap.nULSpace )
+ {
+ SvxULSpaceItem aUL(
+ static_cast<const SvxULSpaceItem&>(pSet->Get(aPardMap.nULSpace)));
+ sal_uInt16 nSz = 0;
+ if( 0 < nTokenValue )
+ {
+ if( IsCalcValue() )
+ CalcValue();
+ nSz = sal_uInt16(nTokenValue);
+ }
+ aUL.SetUpper( nSz );
+ pSet->Put( aUL );
+ }
+ break;
+
+ case RTF_SA:
+ if( aPardMap.nULSpace )
+ {
+ SvxULSpaceItem aUL(
+ static_cast<const SvxULSpaceItem&>(pSet->Get(aPardMap.nULSpace)));
+ sal_uInt16 nSz = 0;
+ if( 0 < nTokenValue )
+ {
+ if( IsCalcValue() )
+ CalcValue();
+ nSz = sal_uInt16(nTokenValue);
+ }
+ aUL.SetLower( nSz );
+ pSet->Put( aUL );
+ }
+ break;
+
+ case RTF_SLMULT:
+ if( aPardMap.nLinespacing && 1 == nTokenValue )
+ {
+ // then switches to multi-line!
+ SvxLineSpacingItem aLSpace(
+ static_cast<const SvxLineSpacingItem&>(pSet->Get( aPardMap.nLinespacing,false)));
+
+ // how much do you get from the line height value?
+
+ // Proportional-Size:
+ // Ie, the ratio is (n / 240) twips
+
+ nTokenValue = 240;
+ if( IsCalcValue() )
+ CalcValue();
+
+ nTokenValue = short( 100 * aLSpace.GetLineHeight() / nTokenValue );
+
+ aLSpace.SetPropLineSpace( static_cast<sal_uInt16>(nTokenValue) );
+ aLSpace.SetLineSpaceRule( SvxLineSpaceRule::Auto );
+
+ pSet->Put( aLSpace );
+ }
+ break;
+
+ case RTF_SL:
+ if( aPardMap.nLinespacing )
+ {
+ // Calculate the ratio between the default font and the
+ // specified size. The distance consists of the line height
+ // (100%) and the space above the line (20%).
+ SvxLineSpacingItem aLSpace(0, aPardMap.nLinespacing);
+
+ nTokenValue = !bTokenHasValue ? 0 : nTokenValue;
+ if (1000 == nTokenValue )
+ nTokenValue = 240;
+
+ SvxLineSpaceRule eLnSpc;
+ if (nTokenValue < 0)
+ {
+ eLnSpc = SvxLineSpaceRule::Fix;
+ nTokenValue = -nTokenValue;
+ }
+ else if (nTokenValue == 0)
+ {
+ //if \sl0 is used, the line spacing is automatically
+ //determined
+ eLnSpc = SvxLineSpaceRule::Auto;
+ }
+ else
+ eLnSpc = SvxLineSpaceRule::Min;
+
+ if (IsCalcValue())
+ CalcValue();
+
+ if (eLnSpc != SvxLineSpaceRule::Auto)
+ aLSpace.SetLineHeight( static_cast<sal_uInt16>(nTokenValue) );
+
+ aLSpace.SetLineSpaceRule(eLnSpc);
+ pSet->Put(aLSpace);
+ }
+ break;
+
+ case RTF_NOCWRAP:
+ if( aPardMap.nForbRule )
+ {
+ pSet->Put( SvxForbiddenRuleItem( false,
+ aPardMap.nForbRule ));
+ }
+ break;
+ case RTF_NOOVERFLOW:
+ if( aPardMap.nHangPunct )
+ {
+ pSet->Put( SvxHangingPunctuationItem( false,
+ aPardMap.nHangPunct ));
+ }
+ break;
+
+ case RTF_ASPALPHA:
+ if( aPardMap.nScriptSpace )
+ {
+ pSet->Put( SvxScriptSpaceItem( true,
+ aPardMap.nScriptSpace ));
+ }
+ break;
+
+ case RTF_FAFIXED:
+ case RTF_FAAUTO: nFontAlign = SvxParaVertAlignItem::Align::Automatic;
+ goto SET_FONTALIGNMENT;
+ case RTF_FAHANG: nFontAlign = SvxParaVertAlignItem::Align::Top;
+ goto SET_FONTALIGNMENT;
+ case RTF_FAVAR: nFontAlign = SvxParaVertAlignItem::Align::Bottom;
+ goto SET_FONTALIGNMENT;
+ case RTF_FACENTER: nFontAlign = SvxParaVertAlignItem::Align::Center;
+ goto SET_FONTALIGNMENT;
+ case RTF_FAROMAN: nFontAlign = SvxParaVertAlignItem::Align::Baseline;
+ goto SET_FONTALIGNMENT;
+SET_FONTALIGNMENT:
+ if( aPardMap.nFontAlign )
+ {
+ pSet->Put( SvxParaVertAlignItem( nFontAlign,
+ aPardMap.nFontAlign ));
+ }
+ break;
+
+ case RTF_B:
+ case RTF_AB:
+ if( IsAttrSttPos() ) // not in the text flow?
+ {
+
+ SvxWeightItem aTmpItem(
+ nTokenValue ? WEIGHT_BOLD : WEIGHT_NORMAL,
+ SID_ATTR_CHAR_WEIGHT );
+ SetScriptAttr( eCharType, *pSet, aTmpItem);
+ }
+ break;
+
+ case RTF_CAPS:
+ case RTF_SCAPS:
+ if( aPlainMap.nCaseMap &&
+ IsAttrSttPos() ) // not in the text flow?
+ {
+ SvxCaseMap eCaseMap;
+ if( !nTokenValue )
+ eCaseMap = SvxCaseMap::NotMapped;
+ else if( RTF_CAPS == nToken )
+ eCaseMap = SvxCaseMap::Uppercase;
+ else
+ eCaseMap = SvxCaseMap::SmallCaps;
+
+ pSet->Put( SvxCaseMapItem( eCaseMap, aPlainMap.nCaseMap ));
+ }
+ break;
+
+ case RTF_DN:
+ case RTF_SUB:
+ if( aPlainMap.nEscapement )
+ {
+ const sal_uInt16 nEsc = aPlainMap.nEscapement;
+ if( -1 == nTokenValue )
+ nTokenValue = 6; //RTF default \dn value in half-points
+ if( IsCalcValue() )
+ CalcValue();
+ const SvxEscapementItem& rOld =
+ static_cast<const SvxEscapementItem&>(pSet->Get( nEsc,false));
+ sal_Int16 nEs;
+ sal_uInt8 nProp;
+ if( DFLT_ESC_AUTO_SUPER == rOld.GetEsc() )
+ {
+ nEs = DFLT_ESC_AUTO_SUB;
+ nProp = rOld.GetProportionalHeight();
+ }
+ else
+ {
+ nEs = (nToken == RTF_SUB) ? DFLT_ESC_AUTO_SUB : -nTokenValue;
+ nProp = (nToken == RTF_SUB) ? DFLT_ESC_PROP : 100;
+ }
+ pSet->Put( SvxEscapementItem( nEs, nProp, nEsc ));
+ }
+ break;
+
+ case RTF_NOSUPERSUB:
+ if( aPlainMap.nEscapement )
+ {
+ const sal_uInt16 nEsc = aPlainMap.nEscapement;
+ pSet->Put( SvxEscapementItem( nEsc ));
+ }
+ break;
+
+ case RTF_EXPND:
+ if( aPlainMap.nKering )
+ {
+ if( -1 == nTokenValue )
+ nTokenValue = 0;
+ else
+ nTokenValue *= 5;
+ if( IsCalcValue() )
+ CalcValue();
+ pSet->Put( SvxKerningItem( static_cast<short>(nTokenValue), aPlainMap.nKering ));
+ }
+ break;
+
+ case RTF_KERNING:
+ if( aPlainMap.nAutoKerning )
+ {
+ if( -1 == nTokenValue )
+ nTokenValue = 0;
+ else
+ nTokenValue *= 10;
+ if( IsCalcValue() )
+ CalcValue();
+ pSet->Put( SvxAutoKernItem( 0 != nTokenValue,
+ aPlainMap.nAutoKerning ));
+ }
+ break;
+
+ case RTF_EXPNDTW:
+ if( aPlainMap.nKering )
+ {
+ if( -1 == nTokenValue )
+ nTokenValue = 0;
+ if( IsCalcValue() )
+ CalcValue();
+ pSet->Put( SvxKerningItem( static_cast<short>(nTokenValue), aPlainMap.nKering ));
+ }
+ break;
+
+ case RTF_F:
+ case RTF_AF:
+ {
+ const vcl::Font& rSVFont = GetFont( sal_uInt16(nTokenValue) );
+ SvxFontItem aTmpItem( rSVFont.GetFamilyType(),
+ rSVFont.GetFamilyName(), rSVFont.GetStyleName(),
+ rSVFont.GetPitch(), rSVFont.GetCharSet(),
+ SID_ATTR_CHAR_FONT );
+ SetScriptAttr( eCharType, *pSet, aTmpItem );
+ if( RTF_F == nToken )
+ {
+ SetEncoding( rSVFont.GetCharSet() );
+ RereadLookahead();
+ }
+ }
+ break;
+
+ case RTF_FS:
+ case RTF_AFS:
+ {
+ if( -1 == nTokenValue )
+ nTokenValue = 240;
+ else
+ nTokenValue *= 10;
+// #i66167#
+// for the SwRTFParser 'IsCalcValue' will be false and for the EditRTFParser
+// the conversion takes now place in EditRTFParser since for other reasons
+// the wrong MapUnit might still be use there
+// if( IsCalcValue() )
+// CalcValue();
+ SvxFontHeightItem aTmpItem(
+ static_cast<sal_uInt16>(nTokenValue), 100,
+ SID_ATTR_CHAR_FONTHEIGHT );
+ SetScriptAttr( eCharType, *pSet, aTmpItem );
+ }
+ break;
+
+ case RTF_I:
+ case RTF_AI:
+ if( IsAttrSttPos() ) // not in the text flow?
+ {
+ SvxPostureItem aTmpItem(
+ nTokenValue ? ITALIC_NORMAL : ITALIC_NONE,
+ SID_ATTR_CHAR_POSTURE );
+ SetScriptAttr( eCharType, *pSet, aTmpItem );
+ }
+ break;
+
+ case RTF_OUTL:
+ if( aPlainMap.nContour &&
+ IsAttrSttPos() ) // not in the text flow?
+ {
+ pSet->Put( SvxContourItem(nTokenValue != 0,
+ aPlainMap.nContour ));
+ }
+ break;
+
+ case RTF_SHAD:
+ if( aPlainMap.nShadowed &&
+ IsAttrSttPos() ) // not in the text flow?
+ {
+ pSet->Put( SvxShadowedItem(nTokenValue != 0,
+ aPlainMap.nShadowed ));
+ }
+ break;
+
+ case RTF_STRIKE:
+ if( aPlainMap.nCrossedOut &&
+ IsAttrSttPos() ) // not in the text flow?
+ {
+ pSet->Put( SvxCrossedOutItem(
+ nTokenValue ? STRIKEOUT_SINGLE : STRIKEOUT_NONE,
+ aPlainMap.nCrossedOut ));
+ }
+ break;
+
+ case RTF_STRIKED:
+ if( aPlainMap.nCrossedOut ) // not in the text flow?
+ {
+ pSet->Put( SvxCrossedOutItem(
+ nTokenValue ? STRIKEOUT_DOUBLE : STRIKEOUT_NONE,
+ aPlainMap.nCrossedOut ));
+ }
+ break;
+
+ case RTF_UL:
+ if( !IsAttrSttPos() )
+ break;
+ eUnderline = nTokenValue ? LINESTYLE_SINGLE : LINESTYLE_NONE;
+ goto ATTR_SETUNDERLINE;
+
+ case RTF_ULD:
+ eUnderline = LINESTYLE_DOTTED;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULDASH:
+ eUnderline = LINESTYLE_DASH;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULDASHD:
+ eUnderline = LINESTYLE_DASHDOT;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULDASHDD:
+ eUnderline = LINESTYLE_DASHDOTDOT;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULDB:
+ eUnderline = LINESTYLE_DOUBLE;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULNONE:
+ eUnderline = LINESTYLE_NONE;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULTH:
+ eUnderline = LINESTYLE_BOLD;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULWAVE:
+ eUnderline = LINESTYLE_WAVE;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULTHD:
+ eUnderline = LINESTYLE_BOLDDOTTED;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULTHDASH:
+ eUnderline = LINESTYLE_BOLDDASH;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULLDASH:
+ eUnderline = LINESTYLE_LONGDASH;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULTHLDASH:
+ eUnderline = LINESTYLE_BOLDLONGDASH;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULTHDASHD:
+ eUnderline = LINESTYLE_BOLDDASHDOT;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULTHDASHDD:
+ eUnderline = LINESTYLE_BOLDDASHDOTDOT;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULHWAVE:
+ eUnderline = LINESTYLE_BOLDWAVE;
+ goto ATTR_SETUNDERLINE;
+ case RTF_ULULDBWAVE:
+ eUnderline = LINESTYLE_DOUBLEWAVE;
+ goto ATTR_SETUNDERLINE;
+
+ case RTF_ULW:
+ eUnderline = LINESTYLE_SINGLE;
+
+ if( aPlainMap.nWordlineMode )
+ {
+ pSet->Put( SvxWordLineModeItem( true, aPlainMap.nWordlineMode ));
+ }
+ goto ATTR_SETUNDERLINE;
+
+ATTR_SETUNDERLINE:
+ if( aPlainMap.nUnderline )
+ {
+ pSet->Put( SvxUnderlineItem( eUnderline, aPlainMap.nUnderline ));
+ }
+ break;
+
+ case RTF_ULC:
+ if( aPlainMap.nUnderline )
+ {
+ std::unique_ptr<SvxUnderlineItem> aUL(std::make_unique<SvxUnderlineItem>(LINESTYLE_SINGLE, aPlainMap.nUnderline));
+ const SfxPoolItem* pItem(nullptr);
+
+ if( SfxItemState::SET == pSet->GetItemState(aPlainMap.nUnderline, false, &pItem ) )
+ {
+ // is switched off ?
+ if( LINESTYLE_NONE == static_cast<const SvxUnderlineItem*>(pItem)->GetLineStyle() )
+ break;
+
+ aUL.reset(static_cast<SvxUnderlineItem*>(pItem->Clone()));
+ }
+ else
+ {
+ aUL.reset(static_cast<SvxUnderlineItem*>(pSet->Get( aPlainMap.nUnderline, false).Clone()));
+ }
+
+ if(LINESTYLE_NONE == aUL->GetLineStyle())
+ {
+ aUL->SetLineStyle(LINESTYLE_SINGLE);
+ }
+
+ aUL->SetColor(GetColor(sal_uInt16(nTokenValue)));
+
+ pSet->Put(*aUL);
+ }
+ break;
+
+ case RTF_OL:
+ if( !IsAttrSttPos() )
+ break;
+ eOverline = nTokenValue ? LINESTYLE_SINGLE : LINESTYLE_NONE;
+ goto ATTR_SETOVERLINE;
+
+ case RTF_OLD:
+ eOverline = LINESTYLE_DOTTED;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLDASH:
+ eOverline = LINESTYLE_DASH;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLDASHD:
+ eOverline = LINESTYLE_DASHDOT;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLDASHDD:
+ eOverline = LINESTYLE_DASHDOTDOT;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLDB:
+ eOverline = LINESTYLE_DOUBLE;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLNONE:
+ eOverline = LINESTYLE_NONE;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLTH:
+ eOverline = LINESTYLE_BOLD;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLWAVE:
+ eOverline = LINESTYLE_WAVE;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLTHD:
+ eOverline = LINESTYLE_BOLDDOTTED;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLTHDASH:
+ eOverline = LINESTYLE_BOLDDASH;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLLDASH:
+ eOverline = LINESTYLE_LONGDASH;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLTHLDASH:
+ eOverline = LINESTYLE_BOLDLONGDASH;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLTHDASHD:
+ eOverline = LINESTYLE_BOLDDASHDOT;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLTHDASHDD:
+ eOverline = LINESTYLE_BOLDDASHDOTDOT;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLHWAVE:
+ eOverline = LINESTYLE_BOLDWAVE;
+ goto ATTR_SETOVERLINE;
+ case RTF_OLOLDBWAVE:
+ eOverline = LINESTYLE_DOUBLEWAVE;
+ goto ATTR_SETOVERLINE;
+
+ case RTF_OLW:
+ eOverline = LINESTYLE_SINGLE;
+
+ if( aPlainMap.nWordlineMode )
+ {
+ pSet->Put( SvxWordLineModeItem( true, aPlainMap.nWordlineMode ));
+ }
+ goto ATTR_SETOVERLINE;
+
+ATTR_SETOVERLINE:
+ if( aPlainMap.nUnderline )
+ {
+ pSet->Put( SvxOverlineItem( eOverline, aPlainMap.nOverline ));
+ }
+ break;
+
+ case RTF_OLC:
+ if( aPlainMap.nOverline )
+ {
+ std::unique_ptr<SvxOverlineItem> aOL(std::make_unique<SvxOverlineItem>(LINESTYLE_SINGLE, aPlainMap.nOverline));
+ const SfxPoolItem* pItem(nullptr);
+
+ if( SfxItemState::SET == pSet->GetItemState(aPlainMap.nOverline, false, &pItem ) )
+ {
+ // is switched off ?
+ if( LINESTYLE_NONE == static_cast<const SvxOverlineItem*>(pItem)->GetLineStyle() )
+ break;
+
+ aOL.reset(static_cast<SvxOverlineItem*>(pItem->Clone()));
+ }
+ else
+ {
+ aOL.reset(static_cast<SvxOverlineItem*>(pSet->Get( aPlainMap.nOverline, false).Clone()));
+ }
+
+ if(LINESTYLE_NONE == aOL->GetLineStyle())
+ {
+ aOL->SetLineStyle(LINESTYLE_SINGLE);
+ }
+
+ aOL->SetColor(GetColor(sal_uInt16(nTokenValue)));
+
+ pSet->Put(*aOL);
+ }
+ break;
+
+ case RTF_UP:
+ case RTF_SUPER:
+ if( aPlainMap.nEscapement )
+ {
+ const sal_uInt16 nEsc = aPlainMap.nEscapement;
+ if( -1 == nTokenValue )
+ nTokenValue = 6; //RTF default \up value in half-points
+ if( IsCalcValue() )
+ CalcValue();
+ const SvxEscapementItem& rOld =
+ static_cast<const SvxEscapementItem&>(pSet->Get( nEsc,false));
+ sal_Int16 nEs;
+ sal_uInt8 nProp;
+ if( DFLT_ESC_AUTO_SUB == rOld.GetEsc() )
+ {
+ nEs = DFLT_ESC_AUTO_SUPER;
+ nProp = rOld.GetProportionalHeight();
+ }
+ else
+ {
+ nEs = (nToken == RTF_SUPER) ? DFLT_ESC_AUTO_SUPER : nTokenValue;
+ nProp = (nToken == RTF_SUPER) ? DFLT_ESC_PROP : 100;
+ }
+ pSet->Put( SvxEscapementItem( nEs, nProp, nEsc ));
+ }
+ break;
+
+ case RTF_CF:
+ if( aPlainMap.nColor )
+ {
+ pSet->Put( SvxColorItem( GetColor( sal_uInt16(nTokenValue) ),
+ aPlainMap.nColor ));
+ }
+ break;
+ //#i12501# While cb is clearly documented in the rtf spec, word
+ //doesn't accept it at all
+#if 0
+ case RTF_CB:
+ if( aPlainMap.nBgColor )
+ {
+ pSet->Put( SvxBrushItem( GetColor( sal_uInt16(nTokenValue) ),
+ aPlainMap.nBgColor ));
+ }
+ break;
+#endif
+
+ case RTF_LANG:
+ if( aPlainMap.nLanguage )
+ {
+ pSet->Put( SvxLanguageItem( LanguageType(nTokenValue),
+ aPlainMap.nLanguage ));
+ }
+ break;
+
+ case RTF_LANGFE:
+ if( aPlainMap.nCJKLanguage )
+ {
+ pSet->Put( SvxLanguageItem( LanguageType(nTokenValue),
+ aPlainMap.nCJKLanguage ));
+ }
+ break;
+ case RTF_ALANG:
+ {
+ SvxLanguageItem aTmpItem( LanguageType(nTokenValue),
+ SID_ATTR_CHAR_LANGUAGE );
+ SetScriptAttr( eCharType, *pSet, aTmpItem );
+ }
+ break;
+
+ case RTF_RTLCH:
+ bIsLeftToRightDef = false;
+ break;
+ case RTF_LTRCH:
+ bIsLeftToRightDef = true;
+ break;
+ case RTF_RTLPAR:
+ if (aPardMap.nDirection)
+ {
+ pSet->Put(SvxFrameDirectionItem(SvxFrameDirection::Horizontal_RL_TB,
+ aPardMap.nDirection));
+ }
+ break;
+ case RTF_LTRPAR:
+ if (aPardMap.nDirection)
+ {
+ pSet->Put(SvxFrameDirectionItem(SvxFrameDirection::Horizontal_LR_TB,
+ aPardMap.nDirection));
+ }
+ break;
+ case RTF_LOCH: eCharType = LOW_CHARTYPE; break;
+ case RTF_HICH: eCharType = HIGH_CHARTYPE; break;
+ case RTF_DBCH: eCharType = DOUBLEBYTE_CHARTYPE; break;
+
+
+ case RTF_ACCNONE:
+ eEmphasis = FontEmphasisMark::NONE;
+ goto ATTR_SETEMPHASIS;
+ case RTF_ACCDOT:
+ eEmphasis = (FontEmphasisMark::Dot | FontEmphasisMark::PosAbove);
+ goto ATTR_SETEMPHASIS;
+
+ case RTF_ACCCOMMA:
+ eEmphasis = (FontEmphasisMark::Accent | FontEmphasisMark::PosAbove);
+ATTR_SETEMPHASIS:
+ if( aPlainMap.nEmphasis )
+ {
+ pSet->Put( SvxEmphasisMarkItem( eEmphasis,
+ aPlainMap.nEmphasis ));
+ }
+ break;
+
+ case RTF_TWOINONE:
+ if( aPlainMap.nTwoLines )
+ {
+ sal_Unicode cStt, cEnd;
+ switch ( nTokenValue )
+ {
+ case 1: cStt = '('; cEnd = ')'; break;
+ case 2: cStt = '['; cEnd = ']'; break;
+ case 3: cStt = '<'; cEnd = '>'; break;
+ case 4: cStt = '{'; cEnd = '}'; break;
+ default: cStt = 0; cEnd = 0; break;
+ }
+
+ pSet->Put( SvxTwoLinesItem( true, cStt, cEnd,
+ aPlainMap.nTwoLines ));
+ }
+ break;
+
+ case RTF_CHARSCALEX :
+ if (aPlainMap.nCharScaleX)
+ {
+ //i21372
+ if (nTokenValue < 1 || nTokenValue > 600)
+ nTokenValue = 100;
+ pSet->Put( SvxCharScaleWidthItem( sal_uInt16(nTokenValue),
+ aPlainMap.nCharScaleX ));
+ }
+ break;
+
+ case RTF_HORZVERT:
+ if( aPlainMap.nHorzVert )
+ {
+ // RTF knows only 90deg
+ pSet->Put( SvxCharRotateItem( 900, 1 == nTokenValue,
+ aPlainMap.nHorzVert ));
+ }
+ break;
+
+ case RTF_EMBO:
+ if (aPlainMap.nRelief)
+ {
+ pSet->Put(SvxCharReliefItem(FontRelief::Embossed,
+ aPlainMap.nRelief));
+ }
+ break;
+ case RTF_IMPR:
+ if (aPlainMap.nRelief)
+ {
+ pSet->Put(SvxCharReliefItem(FontRelief::Engraved,
+ aPlainMap.nRelief));
+ }
+ break;
+ case RTF_V:
+ if (aPlainMap.nHidden)
+ {
+ pSet->Put(SvxCharHiddenItem(nTokenValue != 0,
+ aPlainMap.nHidden));
+ }
+ break;
+ case RTF_CHBGFDIAG:
+ case RTF_CHBGDKVERT:
+ case RTF_CHBGDKHORIZ:
+ case RTF_CHBGVERT:
+ case RTF_CHBGHORIZ:
+ case RTF_CHBGDKFDIAG:
+ case RTF_CHBGDCROSS:
+ case RTF_CHBGCROSS:
+ case RTF_CHBGBDIAG:
+ case RTF_CHBGDKDCROSS:
+ case RTF_CHBGDKCROSS:
+ case RTF_CHBGDKBDIAG:
+ case RTF_CHCBPAT:
+ case RTF_CHCFPAT:
+ case RTF_CHSHDNG:
+ if( aPlainMap.nBgColor )
+ ReadBackgroundAttr( nToken, *pSet );
+ break;
+
+ case BRACELEFT:
+ {
+ // tests on Swg internal tokens
+ bool bHandled = false;
+ short nSkip = 0;
+ if( RTF_IGNOREFLAG != GetNextToken())
+ nSkip = -1;
+ else if( (nToken = GetNextToken() ) & RTF_SWGDEFS )
+ {
+ bHandled = true;
+ switch( nToken )
+ {
+ case RTF_PGDSCNO:
+ case RTF_PGBRK:
+ case RTF_SOUTLVL:
+ UnknownAttrToken( nToken );
+ // overwrite the closing parenthesis
+ break;
+
+ case RTF_SWG_ESCPROP:
+ {
+ // Store percentage change!
+ sal_uInt8 nProp = sal_uInt8( nTokenValue / 100 );
+ short nEsc = 0;
+ if( 1 == ( nTokenValue % 100 ))
+ // Recognize own auto-flags!
+ nEsc = DFLT_ESC_AUTO_SUPER;
+
+ if( aPlainMap.nEscapement )
+ pSet->Put( SvxEscapementItem( nEsc, nProp,
+ aPlainMap.nEscapement ));
+ }
+ break;
+
+ case RTF_HYPHEN:
+ {
+ SvxHyphenZoneItem aHypenZone(
+ (nTokenValue & 1) != 0,
+ aPardMap.nHyphenzone );
+ aHypenZone.SetPageEnd((nTokenValue & 2) != 0);
+
+ if( aPardMap.nHyphenzone &&
+ RTF_HYPHLEAD == GetNextToken() &&
+ RTF_HYPHTRAIL == GetNextToken() &&
+ RTF_HYPHMAX == GetNextToken() )
+ {
+ aHypenZone.GetMinLead() =
+ sal_uInt8(GetStackPtr( -2 )->nTokenValue);
+ aHypenZone.GetMinTrail() =
+ sal_uInt8(GetStackPtr( -1 )->nTokenValue);
+ aHypenZone.GetMaxHyphens() =
+ sal_uInt8(nTokenValue);
+
+ pSet->Put( aHypenZone );
+ }
+ else
+ SkipGroup(); // at the end of the group
+ }
+ break;
+
+ case RTF_SHADOW:
+ {
+ bool bSkip = true;
+ do { // middle check loop
+ SvxShadowLocation eSL = SvxShadowLocation( nTokenValue );
+ if( RTF_SHDW_DIST != GetNextToken() )
+ break;
+ sal_uInt16 nDist = sal_uInt16( nTokenValue );
+
+ if( RTF_SHDW_STYLE != GetNextToken() )
+ break;
+
+ if( RTF_SHDW_COL != GetNextToken() )
+ break;
+ sal_uInt16 nCol = sal_uInt16( nTokenValue );
+
+ if( RTF_SHDW_FCOL != GetNextToken() )
+ break;
+
+ Color aColor = GetColor( nCol );
+
+ if( aPardMap.nShadow )
+ pSet->Put( SvxShadowItem( aPardMap.nShadow,
+ &aColor, nDist, eSL ) );
+
+ bSkip = false;
+ } while( false );
+
+ if( bSkip )
+ SkipGroup(); // at the end of the group
+ }
+ break;
+
+ default:
+ bHandled = false;
+ if( (nToken & ~(0xff | RTF_SWGDEFS)) == RTF_TABSTOPDEF )
+ {
+ nToken = SkipToken( -2 );
+ ReadTabAttr( nToken, *pSet );
+
+ /*
+ cmc: #i76140, he who consumed the { must consume the }
+ We rewound to a state of { being the current
+ token so it is our responsibility to consume the }
+ token if we consumed the {. We will not have consumed
+ the { if it belonged to our caller, i.e. if the { we
+ are handling is the "firsttoken" passed to us then
+ the *caller* must consume it, not us. Otherwise *we*
+ should consume it.
+ */
+ if (nToken == BRACELEFT && !bFirstToken)
+ {
+ nToken = GetNextToken();
+ SAL_WARN_IF( nToken != BRACERIGHT,
+ "editeng",
+ "} did not follow { as expected");
+ }
+ }
+ else if( (nToken & ~(0xff| RTF_SWGDEFS)) == RTF_BRDRDEF)
+ {
+ nToken = SkipToken( -2 );
+ ReadBorderAttr( nToken, *pSet );
+ }
+ else // so no more attribute
+ nSkip = -2;
+ break;
+ }
+
+#if 1
+ /*
+ cmc: #i4727# / #i12713# Who owns this closing bracket?
+ If we read the opening one, we must read this one, if
+ other is counting the brackets so as to push/pop off
+ the correct environment then we will have pushed a new
+ environment for the start { of this, but will not see
+ the } and so is out of sync for the rest of the
+ document.
+ */
+ if (bHandled && !bFirstToken)
+ GetNextToken();
+#endif
+ }
+ else
+ nSkip = -2;
+
+ if( nSkip ) // all completely unknown
+ {
+ if (!bFirstToken)
+ --nSkip; // BRACELEFT: is the next token
+ SkipToken( nSkip );
+ bContinue = false;
+ }
+ }
+ break;
+ default:
+ if( (nToken & ~0xff ) == RTF_TABSTOPDEF )
+ ReadTabAttr( nToken, *pSet );
+ else if( (nToken & ~0xff ) == RTF_BRDRDEF )
+ ReadBorderAttr( nToken, *pSet );
+ else if( (nToken & ~0xff ) == RTF_SHADINGDEF )
+ ReadBackgroundAttr( nToken, *pSet );
+ else
+ {
+ // unknown token, so token "returned in Parser"
+ if( !bFirstToken )
+ SkipToken();
+ bContinue = false;
+ }
+ }
+ }
+ if( bContinue )
+ {
+ nToken = GetNextToken();
+ }
+ bFirstToken = false;
+ }
+}
+
+void SvxRTFParser::ReadTabAttr( int nToken, SfxItemSet& rSet )
+{
+ bool bMethodOwnsToken = false; // #i52542# patch from cmc.
+// then read all the TabStops
+ SvxTabStop aTabStop;
+ SvxTabStopItem aAttr( 0, 0, SvxTabAdjust::Default, aPardMap.nTabStop );
+ bool bContinue = true;
+ do {
+ switch( nToken )
+ {
+ case RTF_TB: // BarTab ???
+ case RTF_TX:
+ {
+ if( IsCalcValue() )
+ CalcValue();
+ aTabStop.GetTabPos() = nTokenValue;
+ aAttr.Insert( aTabStop );
+ aTabStop = SvxTabStop(); // all values default
+ }
+ break;
+
+ case RTF_TQL:
+ aTabStop.GetAdjustment() = SvxTabAdjust::Left;
+ break;
+ case RTF_TQR:
+ aTabStop.GetAdjustment() = SvxTabAdjust::Right;
+ break;
+ case RTF_TQC:
+ aTabStop.GetAdjustment() = SvxTabAdjust::Center;
+ break;
+ case RTF_TQDEC:
+ aTabStop.GetAdjustment() = SvxTabAdjust::Decimal;
+ break;
+
+ case RTF_TLDOT: aTabStop.GetFill() = '.'; break;
+ case RTF_TLHYPH: aTabStop.GetFill() = ' '; break;
+ case RTF_TLUL: aTabStop.GetFill() = '_'; break;
+ case RTF_TLTH: aTabStop.GetFill() = '-'; break;
+ case RTF_TLEQ: aTabStop.GetFill() = '='; break;
+
+ case BRACELEFT:
+ {
+ // Swg - control BRACELEFT RTF_IGNOREFLAG RTF_TLSWG BRACERIGHT
+ short nSkip = 0;
+ if( RTF_IGNOREFLAG != GetNextToken() )
+ nSkip = -1;
+ else if( RTF_TLSWG != ( nToken = GetNextToken() ))
+ nSkip = -2;
+ else
+ {
+ aTabStop.GetDecimal() = sal_uInt8(nTokenValue & 0xff);
+ aTabStop.GetFill() = sal_uInt8((nTokenValue >> 8) & 0xff);
+ // overwrite the closing parenthesis
+ if (bMethodOwnsToken)
+ GetNextToken();
+ }
+ if( nSkip )
+ {
+ SkipToken( nSkip ); // Ignore back again
+ bContinue = false;
+ }
+ }
+ break;
+
+ default:
+ bContinue = false;
+ }
+ if( bContinue )
+ {
+ nToken = GetNextToken();
+ bMethodOwnsToken = true;
+ }
+ } while( bContinue );
+
+ // Fill with defaults is still missing!
+ rSet.Put( aAttr );
+ SkipToken();
+}
+
+static void SetBorderLine( int nBorderTyp, SvxBoxItem& rItem,
+ const SvxBorderLine& rBorder )
+{
+ switch( nBorderTyp )
+ {
+ case RTF_BOX: // run through all levels
+ case RTF_BRDRT:
+ rItem.SetLine( &rBorder, SvxBoxItemLine::TOP );
+ if( RTF_BOX != nBorderTyp )
+ return;
+ [[fallthrough]];
+ case RTF_BRDRB:
+ rItem.SetLine( &rBorder, SvxBoxItemLine::BOTTOM );
+ if( RTF_BOX != nBorderTyp )
+ return;
+ [[fallthrough]];
+ case RTF_BRDRL:
+ rItem.SetLine( &rBorder, SvxBoxItemLine::LEFT );
+ if( RTF_BOX != nBorderTyp )
+ return;
+ [[fallthrough]];
+ case RTF_BRDRR:
+ rItem.SetLine( &rBorder, SvxBoxItemLine::RIGHT );
+ if( RTF_BOX != nBorderTyp )
+ return;
+ }
+}
+
+void SvxRTFParser::ReadBorderAttr( int nToken, SfxItemSet& rSet,
+ bool bTableDef )
+{
+ // then read the border attribute
+ std::unique_ptr<SvxBoxItem> aAttr(std::make_unique<SvxBoxItem>(aPardMap.nBox));
+ const SfxPoolItem* pItem(nullptr);
+
+ if( SfxItemState::SET == rSet.GetItemState( aPardMap.nBox, false, &pItem ) )
+ {
+ aAttr.reset(static_cast<SvxBoxItem*>(pItem->Clone()));
+ }
+
+ SvxBorderLine aBrd( nullptr, DEF_LINE_WIDTH_0 ); // Simple plain line
+ bool bContinue = true;
+ int nBorderTyp = 0;
+
+ long nWidth = 1;
+ bool bDoubleWidth = false;
+
+ do {
+ switch( nToken )
+ {
+ case RTF_BOX:
+ case RTF_BRDRT:
+ case RTF_BRDRB:
+ case RTF_BRDRL:
+ case RTF_BRDRR:
+ nBorderTyp = nToken;
+ break;
+
+ case RTF_CLBRDRT: // Cell top border
+ {
+ if( bTableDef )
+ {
+ if (nBorderTyp != 0)
+ SetBorderLine( nBorderTyp, *aAttr, aBrd );
+ nBorderTyp = RTF_BRDRT;
+ }
+ break;
+ }
+ case RTF_CLBRDRB: // Cell bottom border
+ {
+ if( bTableDef )
+ {
+ if (nBorderTyp != 0)
+ SetBorderLine( nBorderTyp, *aAttr, aBrd );
+ nBorderTyp = RTF_BRDRB;
+ }
+ break;
+ }
+ case RTF_CLBRDRL: // Cell left border
+ {
+ if( bTableDef )
+ {
+ if (nBorderTyp != 0)
+ SetBorderLine( nBorderTyp, *aAttr, aBrd );
+ nBorderTyp = RTF_BRDRL;
+ }
+ break;
+ }
+ case RTF_CLBRDRR: // Cell right border
+ {
+ if( bTableDef )
+ {
+ if (nBorderTyp != 0)
+ SetBorderLine( nBorderTyp, *aAttr, aBrd );
+ nBorderTyp = RTF_BRDRR;
+ }
+ break;
+ }
+
+ case RTF_BRDRDOT: // dotted border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::DOTTED);
+ break;
+ case RTF_BRDRDASH: // dashed border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::DASHED);
+ break;
+ case RTF_BRDRHAIR: // hairline border
+ {
+ aBrd.SetBorderLineStyle( SvxBorderLineStyle::SOLID);
+ aBrd.SetWidth( DEF_LINE_WIDTH_0 );
+ }
+ break;
+ case RTF_BRDRDB: // Double border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::DOUBLE);
+ break;
+ case RTF_BRDRINSET: // inset border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::INSET);
+ break;
+ case RTF_BRDROUTSET: // outset border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::OUTSET);
+ break;
+ case RTF_BRDRTNTHSG: // ThinThick Small gap
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::THINTHICK_SMALLGAP);
+ break;
+ case RTF_BRDRTNTHMG: // ThinThick Medium gap
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::THINTHICK_MEDIUMGAP);
+ break;
+ case RTF_BRDRTNTHLG: // ThinThick Large gap
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::THINTHICK_LARGEGAP);
+ break;
+ case RTF_BRDRTHTNSG: // ThickThin Small gap
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::THICKTHIN_SMALLGAP);
+ break;
+ case RTF_BRDRTHTNMG: // ThickThin Medium gap
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::THICKTHIN_MEDIUMGAP);
+ break;
+ case RTF_BRDRTHTNLG: // ThickThin Large gap
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::THICKTHIN_LARGEGAP);
+ break;
+ case RTF_BRDREMBOSS: // Embossed border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::EMBOSSED);
+ break;
+ case RTF_BRDRENGRAVE: // Engraved border
+ aBrd.SetBorderLineStyle(SvxBorderLineStyle::ENGRAVED);
+ break;
+
+ case RTF_BRDRS: // single thickness border
+ bDoubleWidth = false;
+ break;
+ case RTF_BRDRTH: // double thickness border width*2
+ bDoubleWidth = true;
+ break;
+ case RTF_BRDRW: // border width <255
+ nWidth = nTokenValue;
+ break;
+
+ case RTF_BRDRCF: // Border color
+ aBrd.SetColor( GetColor( sal_uInt16(nTokenValue) ) );
+ break;
+
+ case RTF_BRDRSH: // Shadowed border
+ rSet.Put( SvxShadowItem( aPardMap.nShadow, nullptr, 60 /*3pt*/,
+ SvxShadowLocation::BottomRight ) );
+ break;
+
+ case RTF_BRSP: // Spacing to content in twip
+ {
+ switch( nBorderTyp )
+ {
+ case RTF_BRDRB:
+ aAttr->SetDistance( static_cast<sal_uInt16>(nTokenValue), SvxBoxItemLine::BOTTOM );
+ break;
+
+ case RTF_BRDRT:
+ aAttr->SetDistance( static_cast<sal_uInt16>(nTokenValue), SvxBoxItemLine::TOP );
+ break;
+
+ case RTF_BRDRL:
+ aAttr->SetDistance( static_cast<sal_uInt16>(nTokenValue), SvxBoxItemLine::LEFT );
+ break;
+
+ case RTF_BRDRR:
+ aAttr->SetDistance( static_cast<sal_uInt16>(nTokenValue), SvxBoxItemLine::RIGHT );
+ break;
+
+ case RTF_BOX:
+ aAttr->SetAllDistances( static_cast<sal_uInt16>(nTokenValue) );
+ break;
+ }
+ }
+ break;
+
+ case RTF_BRDRBTW: // Border formatting group
+ case RTF_BRDRBAR: // Border outside
+ // TODO unhandled ATM
+ break;
+
+ default:
+ bContinue = (nToken & ~(0xff| RTF_SWGDEFS)) == RTF_BRDRDEF;
+ }
+ if( bContinue )
+ nToken = GetNextToken();
+ } while( bContinue );
+
+ // Finally compute the border width
+ if ( bDoubleWidth ) nWidth *= 2;
+ aBrd.SetWidth( nWidth );
+
+ SetBorderLine( nBorderTyp, *aAttr, aBrd );
+
+ rSet.Put( *aAttr );
+ SkipToken();
+}
+
+static sal_uInt32 CalcShading( sal_uInt32 nColor, sal_uInt32 nFillColor, sal_uInt8 nShading )
+{
+ nColor = (nColor * nShading) / 100;
+ nFillColor = (nFillColor * ( 100 - nShading )) / 100;
+ return nColor + nFillColor;
+}
+
+void SvxRTFParser::ReadBackgroundAttr( int nToken, SfxItemSet& rSet,
+ bool bTableDef )
+{
+ // then read the border attribute
+ bool bContinue = true;
+ sal_uInt16 nColor = USHRT_MAX, nFillColor = USHRT_MAX;
+ sal_uInt8 nFillValue = 0;
+
+ sal_uInt16 nWh = ( nToken & ~0xff ) == RTF_CHRFMT
+ ? aPlainMap.nBgColor
+ : aPardMap.nBrush;
+
+ do {
+ switch( nToken )
+ {
+ case RTF_CLCBPAT:
+ case RTF_CHCBPAT:
+ case RTF_CBPAT:
+ nFillColor = sal_uInt16( nTokenValue );
+ break;
+
+ case RTF_CLCFPAT:
+ case RTF_CHCFPAT:
+ case RTF_CFPAT:
+ nColor = sal_uInt16( nTokenValue );
+ break;
+
+ case RTF_CLSHDNG:
+ case RTF_CHSHDNG:
+ case RTF_SHADING:
+ nFillValue = static_cast<sal_uInt8>( nTokenValue / 100 );
+ break;
+
+ case RTF_CLBGDKHOR:
+ case RTF_CHBGDKHORIZ:
+ case RTF_BGDKHORIZ:
+ case RTF_CLBGDKVERT:
+ case RTF_CHBGDKVERT:
+ case RTF_BGDKVERT:
+ case RTF_CLBGDKBDIAG:
+ case RTF_CHBGDKBDIAG:
+ case RTF_BGDKBDIAG:
+ case RTF_CLBGDKFDIAG:
+ case RTF_CHBGDKFDIAG:
+ case RTF_BGDKFDIAG:
+ case RTF_CLBGDKCROSS:
+ case RTF_CHBGDKCROSS:
+ case RTF_BGDKCROSS:
+ case RTF_CLBGDKDCROSS:
+ case RTF_CHBGDKDCROSS:
+ case RTF_BGDKDCROSS:
+ // dark -> 60%
+ nFillValue = 60;
+ break;
+
+ case RTF_CLBGHORIZ:
+ case RTF_CHBGHORIZ:
+ case RTF_BGHORIZ:
+ case RTF_CLBGVERT:
+ case RTF_CHBGVERT:
+ case RTF_BGVERT:
+ case RTF_CLBGBDIAG:
+ case RTF_CHBGBDIAG:
+ case RTF_BGBDIAG:
+ case RTF_CLBGFDIAG:
+ case RTF_CHBGFDIAG:
+ case RTF_BGFDIAG:
+ case RTF_CLBGCROSS:
+ case RTF_CHBGCROSS:
+ case RTF_BGCROSS:
+ case RTF_CLBGDCROSS:
+ case RTF_CHBGDCROSS:
+ case RTF_BGDCROSS:
+ // light -> 20%
+ nFillValue = 20;
+ break;
+
+ default:
+ if( bTableDef )
+ bContinue = (nToken & ~(0xff | RTF_TABLEDEF) ) == RTF_SHADINGDEF;
+ else
+ bContinue = (nToken & ~0xff) == RTF_SHADINGDEF;
+ }
+ if( bContinue )
+ nToken = GetNextToken();
+ } while( bContinue );
+
+ Color aCol( COL_WHITE ), aFCol;
+ if( !nFillValue )
+ {
+ // there was only one of two colors specified or no BrushType
+ if( USHRT_MAX != nFillColor )
+ {
+ nFillValue = 100;
+ aCol = GetColor( nFillColor );
+ }
+ else if( USHRT_MAX != nColor )
+ aFCol = GetColor( nColor );
+ }
+ else
+ {
+ if( USHRT_MAX != nColor )
+ aCol = GetColor( nColor );
+ else
+ aCol = COL_BLACK;
+
+ if( USHRT_MAX != nFillColor )
+ aFCol = GetColor( nFillColor );
+ else
+ aFCol = COL_WHITE;
+ }
+
+ Color aColor;
+ if( 0 == nFillValue || 100 == nFillValue )
+ aColor = aCol;
+ else
+ aColor = Color(
+ static_cast<sal_uInt8>(CalcShading( aCol.GetRed(), aFCol.GetRed(), nFillValue )),
+ static_cast<sal_uInt8>(CalcShading( aCol.GetGreen(), aFCol.GetGreen(), nFillValue )),
+ static_cast<sal_uInt8>(CalcShading( aCol.GetBlue(), aFCol.GetBlue(), nFillValue )) );
+
+ rSet.Put( SvxBrushItem( aColor, nWh ) );
+ SkipToken();
+}
+
+
+// pard / plain handling
+void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet )
+{
+ if( bNewGroup || aAttrStack.empty() ) // not at the beginning of a new group
+ return;
+
+ SvxRTFItemStackType* pCurrent = aAttrStack.back().get();
+
+ int nLastToken = GetStackPtr(-1)->nTokenId;
+ bool bNewStkEntry = true;
+ if( RTF_PARD != nLastToken &&
+ RTF_PLAIN != nLastToken &&
+ BRACELEFT != nLastToken )
+ {
+ if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo)
+ {
+ // open a new group
+ std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *pInsPos, true ));
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // Set all until here valid attributes
+ AttrGroupEnd();
+ pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
+ pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
+ aAttrStack.push_back( std::move(pNew) );
+ pCurrent = aAttrStack.back().get();
+ }
+ else
+ {
+ // continue to use this entry as new
+ pCurrent->SetStartPos( *pInsPos );
+ bNewStkEntry = false;
+ }
+ }
+
+ // now reset all to default
+ if( bNewStkEntry &&
+ ( pCurrent->aAttrSet.GetParent() || pCurrent->aAttrSet.Count() ))
+ {
+ const SfxPoolItem *pItem, *pDef;
+ const sal_uInt16* pPtr;
+ sal_uInt16 nCnt;
+ const SfxItemSet* pDfltSet = &GetRTFDefaults();
+ if( bPard )
+ {
+ pCurrent->nStyleNo = 0;
+ pPtr = reinterpret_cast<sal_uInt16*>(&aPardMap);
+ nCnt = sizeof(aPardMap) / sizeof(sal_uInt16);
+ }
+ else
+ {
+ pPtr = reinterpret_cast<sal_uInt16*>(&aPlainMap);
+ nCnt = sizeof(aPlainMap) / sizeof(sal_uInt16);
+ }
+
+ for( sal_uInt16 n = 0; n < nCnt; ++n, ++pPtr )
+ {
+ // Item set and different -> Set the Default Pool
+ if( !*pPtr )
+ ;
+ else if (SfxItemPool::IsSlot(*pPtr))
+ pCurrent->aAttrSet.ClearItem( *pPtr );
+ else if( IsChkStyleAttr() )
+ pCurrent->aAttrSet.Put( pDfltSet->Get( *pPtr ) );
+ else if( !pCurrent->aAttrSet.GetParent() )
+ {
+ if( SfxItemState::SET ==
+ pDfltSet->GetItemState( *pPtr, false, &pDef ))
+ pCurrent->aAttrSet.Put( *pDef );
+ else
+ pCurrent->aAttrSet.ClearItem( *pPtr );
+ }
+ else if( SfxItemState::SET == pCurrent->aAttrSet.GetParent()->
+ GetItemState( *pPtr, true, &pItem ) &&
+ *( pDef = &pDfltSet->Get( *pPtr )) != *pItem )
+ pCurrent->aAttrSet.Put( *pDef );
+ else
+ {
+ if( SfxItemState::SET ==
+ pDfltSet->GetItemState( *pPtr, false, &pDef ))
+ pCurrent->aAttrSet.Put( *pDef );
+ else
+ pCurrent->aAttrSet.ClearItem( *pPtr );
+ }
+ }
+ }
+ else if( bPard )
+ pCurrent->nStyleNo = 0; // reset Style number
+
+ *ppSet = &pCurrent->aAttrSet;
+
+ if (bPard)
+ return;
+
+ //Once we have a default font, then any text without a font specifier is
+ //in the default font, and thus has the default font charset, otherwise
+ //we can fall back to the ansicpg set codeset
+ if (nDfltFont != -1)
+ {
+ const vcl::Font& rSVFont = GetFont(sal_uInt16(nDfltFont));
+ SetEncoding(rSVFont.GetCharSet());
+ }
+ else
+ SetEncoding(GetCodeSet());
+}
+
+void SvxRTFParser::SetDefault( int nToken, int nValue )
+{
+ if( !bNewDoc )
+ return;
+
+ SfxItemSet aTmp( *pAttrPool, aWhichMap.data() );
+ bool bOldFlag = bIsLeftToRightDef;
+ bIsLeftToRightDef = true;
+ switch( nToken )
+ {
+ case RTF_ADEFF:
+ bIsLeftToRightDef = false;
+ [[fallthrough]];
+ case RTF_DEFF:
+ {
+ if( -1 == nValue )
+ nValue = 0;
+ const vcl::Font& rSVFont = GetFont( sal_uInt16(nValue) );
+ SvxFontItem aTmpItem(
+ rSVFont.GetFamilyType(), rSVFont.GetFamilyName(),
+ rSVFont.GetStyleName(), rSVFont.GetPitch(),
+ rSVFont.GetCharSet(), SID_ATTR_CHAR_FONT );
+ SetScriptAttr( NOTDEF_CHARTYPE, aTmp, aTmpItem );
+ }
+ break;
+
+ case RTF_ADEFLANG:
+ bIsLeftToRightDef = false;
+ [[fallthrough]];
+ case RTF_DEFLANG:
+ // store default Language
+ if( -1 != nValue )
+ {
+ SvxLanguageItem aTmpItem( LanguageType(nValue), SID_ATTR_CHAR_LANGUAGE );
+ SetScriptAttr( NOTDEF_CHARTYPE, aTmp, aTmpItem );
+ }
+ break;
+
+ case RTF_DEFTAB:
+ if( aPardMap.nTabStop )
+ {
+ // RTF defines 720 twips as default
+ bIsSetDfltTab = true;
+ if( -1 == nValue || !nValue )
+ nValue = 720;
+
+ // who would like to have no twips ...
+ if( IsCalcValue() )
+ {
+ nTokenValue = nValue;
+ CalcValue();
+ nValue = nTokenValue;
+ }
+
+ // Calculate the ratio of default TabWidth / Tabs and
+ // calculate the corresponding new number.
+ // ?? how did one come up with 13 ??
+ sal_uInt16 nTabCount = (SVX_TAB_DEFDIST * 13 ) / sal_uInt16(nValue);
+ /*
+ cmc, make sure we have at least one, or all hell breaks loose in
+ everybody exporters, #i8247#
+ */
+ if (nTabCount < 1)
+ nTabCount = 1;
+
+ // we want Defaulttabs
+ SvxTabStopItem aNewTab( nTabCount, sal_uInt16(nValue),
+ SvxTabAdjust::Default, aPardMap.nTabStop );
+ while( nTabCount )
+ const_cast<SvxTabStop&>(aNewTab[ --nTabCount ]).GetAdjustment() = SvxTabAdjust::Default;
+
+ pAttrPool->SetPoolDefaultItem( aNewTab );
+ }
+ break;
+ }
+ bIsLeftToRightDef = bOldFlag;
+
+ if( aTmp.Count() )
+ {
+ SfxItemIter aIter( aTmp );
+ const SfxPoolItem* pItem = aIter.GetCurItem();
+ do
+ {
+ pAttrPool->SetPoolDefaultItem( *pItem );
+ pItem = aIter.NextItem();
+ } while (pItem);
+ }
+}
+
+// default: no conversion, leaving everything in twips.
+void SvxRTFParser::CalcValue()
+{
+}
+
+// for tokens that are not evaluated in ReadAttr
+void SvxRTFParser::UnknownAttrToken( int )
+{
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx
new file mode 100644
index 000000000..a5c1217ff
--- /dev/null
+++ b/editeng/source/rtf/svxrtf.cxx
@@ -0,0 +1,1180 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed
+ * with this work for additional information regarding copyright
+ * ownership. The ASF licenses this file to you under the Apache
+ * License, Version 2.0 (the "License"); you may not use this file
+ * except in compliance with the License. You may obtain a copy of
+ * the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#include <memory>
+#include <queue>
+#include <tools/diagnose_ex.h>
+#include <rtl/tencinfo.h>
+#include <svl/itemiter.hxx>
+#include <svl/whiter.hxx>
+#include <svtools/rtftoken.h>
+#include <svl/itempool.hxx>
+#include <i18nlangtag/languagetag.hxx>
+#include <tools/debug.hxx>
+
+#include <comphelper/string.hxx>
+
+#include <editeng/scriptspaceitem.hxx>
+#include <editeng/fontitem.hxx>
+#include <editeng/svxrtf.hxx>
+#include <editeng/editids.hrc>
+#include <vcl/font.hxx>
+#include <vcl/svapp.hxx>
+#include <vcl/settings.hxx>
+
+
+using namespace ::com::sun::star;
+
+
+static rtl_TextEncoding lcl_GetDefaultTextEncodingForRTF()
+{
+
+ OUString aLangString( Application::GetSettings().GetLanguageTag().getLanguage());
+
+ if ( aLangString == "ru" || aLangString == "uk" )
+ return RTL_TEXTENCODING_MS_1251;
+ if ( aLangString == "tr" )
+ return RTL_TEXTENCODING_MS_1254;
+ else
+ return RTL_TEXTENCODING_MS_1252;
+}
+
+// -------------- Methods --------------------
+
+SvxRTFParser::SvxRTFParser( SfxItemPool& rPool, SvStream& rIn )
+ : SvRTFParser( rIn, 5 )
+ , aPlainMap(rPool)
+ , aPardMap(rPool)
+ , pAttrPool( &rPool )
+ , nDfltFont( 0)
+ , bNewDoc( true )
+ , bNewGroup( false)
+ , bIsSetDfltTab( false)
+ , bChkStyleAttr( false )
+ , bCalcValue( false )
+ , bIsLeftToRightDef( true)
+ , bIsInReadStyleTab( false)
+{
+ pDfltFont.reset( new vcl::Font );
+ pDfltColor.reset( new Color );
+}
+
+SvxRTFParser::~SvxRTFParser()
+{
+ if( !aColorTbl.empty() )
+ ClearColorTbl();
+ if( !aAttrStack.empty() )
+ ClearAttrStack();
+}
+
+void SvxRTFParser::SetInsPos( const EditPosition& rNew )
+{
+ pInsPos = rNew.Clone();
+}
+
+SvParserState SvxRTFParser::CallParser()
+{
+ DBG_ASSERT( pInsPos, "no insertion position");
+
+ if( !pInsPos )
+ return SvParserState::Error;
+
+ if( !aColorTbl.empty() )
+ ClearColorTbl();
+ m_FontTable.clear();
+ m_StyleTable.clear();
+ if( !aAttrStack.empty() )
+ ClearAttrStack();
+
+ bIsSetDfltTab = false;
+ bNewGroup = false;
+ nDfltFont = 0;
+
+ // generate the correct WhichId table from the set WhichIds.
+ BuildWhichTable();
+
+ return SvRTFParser::CallParser();
+}
+
+void SvxRTFParser::Continue( int nToken )
+{
+ SvRTFParser::Continue( nToken );
+
+ SvParserState eStatus = GetStatus();
+ if (eStatus != SvParserState::Pending && eStatus != SvParserState::Error)
+ {
+ SetAllAttrOfStk();
+ //Regardless of what "color 0" is, word defaults to auto as the default colour.
+ //e.g. see #i7713#
+ }
+}
+
+
+// is called for each token that is recognized in CallParser
+void SvxRTFParser::NextToken( int nToken )
+{
+ sal_Unicode cCh;
+ switch( nToken )
+ {
+ case RTF_COLORTBL: ReadColorTable(); break;
+ case RTF_FONTTBL: ReadFontTable(); break;
+ case RTF_STYLESHEET: ReadStyleTable(); break;
+
+ case RTF_DEFF:
+ if( bNewDoc )
+ {
+ if (!m_FontTable.empty())
+ // Can immediately be set
+ SetDefault( nToken, nTokenValue );
+ else
+ // is set after reading the font table
+ nDfltFont = int(nTokenValue);
+ }
+ break;
+
+ case RTF_DEFTAB:
+ case RTF_DEFLANG:
+ if( bNewDoc )
+ SetDefault( nToken, nTokenValue );
+ break;
+
+
+ case RTF_PICT: ReadBitmapData(); break;
+
+ case RTF_LINE: cCh = '\n'; goto INSINGLECHAR;
+ case RTF_TAB: cCh = '\t'; goto INSINGLECHAR;
+ case RTF_SUBENTRYINDEX: cCh = ':'; goto INSINGLECHAR;
+
+ case RTF_EMDASH: cCh = 0x2014; goto INSINGLECHAR;
+ case RTF_ENDASH: cCh = 0x2013; goto INSINGLECHAR;
+ case RTF_BULLET: cCh = 0x2022; goto INSINGLECHAR;
+ case RTF_LQUOTE: cCh = 0x2018; goto INSINGLECHAR;
+ case RTF_RQUOTE: cCh = 0x2019; goto INSINGLECHAR;
+ case RTF_LDBLQUOTE: cCh = 0x201C; goto INSINGLECHAR;
+ case RTF_RDBLQUOTE: cCh = 0x201D; goto INSINGLECHAR;
+INSINGLECHAR:
+ aToken = OUString(cCh);
+ [[fallthrough]]; // aToken is set as Text
+ case RTF_TEXTTOKEN:
+ {
+ InsertText();
+ // all collected Attributes are set
+ for (size_t n = m_AttrSetList.size(); n; )
+ {
+ auto const& pStkSet = m_AttrSetList[--n];
+ SetAttrSet( *pStkSet );
+ m_AttrSetList.pop_back();
+ }
+ }
+ break;
+
+
+ case RTF_PAR:
+ InsertPara();
+ break;
+ case '{':
+ if (bNewGroup) // Nesting!
+ GetAttrSet_();
+ bNewGroup = true;
+ break;
+ case '}':
+ if( !bNewGroup ) // Empty Group ??
+ AttrGroupEnd();
+ bNewGroup = false;
+ break;
+ case RTF_INFO:
+ SkipGroup();
+ break;
+
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+ // First overwrite all (all have to be in one group!!)
+ // Could also appear in the RTF-file without the IGNORE-Flag; all Groups
+ // with the IGNORE-Flag are overwritten in the default branch.
+
+ case RTF_SWG_PRTDATA:
+ case RTF_FIELD:
+ case RTF_ATNID:
+ case RTF_ANNOTATION:
+
+ case RTF_BKMKSTART:
+ case RTF_BKMKEND:
+ case RTF_BKMK_KEY:
+ case RTF_XE:
+ case RTF_TC:
+ case RTF_NEXTFILE:
+ case RTF_TEMPLATE:
+ // RTF_SHPRSLT disabled for #i19718#
+ SkipGroup();
+ break;
+ // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
+
+ case RTF_PGDSCNO:
+ case RTF_PGBRK:
+ case RTF_SHADOW:
+ if( RTF_IGNOREFLAG != GetStackPtr( -1 )->nTokenId )
+ break;
+ nToken = SkipToken();
+ if( '{' == GetStackPtr( -1 )->nTokenId )
+ nToken = SkipToken();
+
+ ReadAttr( nToken, &GetAttrSet() );
+ break;
+
+ default:
+ switch( nToken & ~(0xff | RTF_SWGDEFS) )
+ {
+ case RTF_PARFMT: // here are no SWGDEFS
+ ReadAttr( nToken, &GetAttrSet() );
+ break;
+
+ case RTF_CHRFMT:
+ case RTF_BRDRDEF:
+ case RTF_TABSTOPDEF:
+
+ if( RTF_SWGDEFS & nToken)
+ {
+ if( RTF_IGNOREFLAG != GetStackPtr( -1 )->nTokenId )
+ break;
+ nToken = SkipToken();
+ if( '{' == GetStackPtr( -1 )->nTokenId )
+ {
+ nToken = SkipToken();
+ }
+ }
+ ReadAttr( nToken, &GetAttrSet() );
+ break;
+ default:
+ {
+ if( RTF_IGNOREFLAG == GetStackPtr( -1 )->nTokenId &&
+ '{' == GetStackPtr( -2 )->nTokenId )
+ SkipGroup();
+ }
+ break;
+ }
+ break;
+ }
+}
+
+void SvxRTFParser::ReadStyleTable()
+{
+ int bSaveChkStyleAttr = bChkStyleAttr ? 1 : 0;
+ sal_uInt16 nStyleNo = 0;
+ bool bHasStyleNo = false;
+ int _nOpenBrakets = 1; // the first was already detected earlier!!
+ std::unique_ptr<SvxRTFStyleType> pStyle(
+ new SvxRTFStyleType( *pAttrPool, aWhichMap.data() ));
+ pStyle->aAttrSet.Put( GetRTFDefaults() );
+
+ bIsInReadStyleTab = true;
+ bChkStyleAttr = false; // Do not check Attribute against the Styles
+
+ while( _nOpenBrakets && IsParserWorking() )
+ {
+ int nToken = GetNextToken();
+ switch( nToken )
+ {
+ case '}': if( --_nOpenBrakets && IsParserWorking() )
+ // Style has been completely read,
+ // so this is still a stable status
+ SaveState( RTF_STYLESHEET );
+ break;
+ case '{':
+ {
+ if( RTF_IGNOREFLAG != GetNextToken() )
+ SkipToken();
+ else if( RTF_UNKNOWNCONTROL != ( nToken = GetNextToken() ) &&
+ RTF_PN != nToken )
+ SkipToken( -2 );
+ else
+ {
+ // filter out at once
+ ReadUnknownData();
+ nToken = GetNextToken();
+ if( '}' != nToken )
+ eState = SvParserState::Error;
+ break;
+ }
+ ++_nOpenBrakets;
+ }
+ break;
+
+ case RTF_SBASEDON: pStyle->nBasedOn = sal_uInt16(nTokenValue); break;
+ case RTF_SNEXT: break;
+ case RTF_OUTLINELEVEL:
+ case RTF_SOUTLVL: pStyle->nOutlineNo = sal_uInt8(nTokenValue); break;
+ case RTF_S: nStyleNo = static_cast<short>(nTokenValue);
+ bHasStyleNo = true;
+ break;
+ case RTF_CS: nStyleNo = static_cast<short>(nTokenValue);
+ bHasStyleNo = true;
+ break;
+
+ case RTF_TEXTTOKEN:
+ if (bHasStyleNo)
+ {
+ pStyle->sName = DelCharAtEnd( aToken, ';' );
+
+ if (!m_StyleTable.empty())
+ {
+ m_StyleTable.erase(nStyleNo);
+ }
+ // All data from the font is available, so off to the table
+ m_StyleTable.insert(std::make_pair(nStyleNo, std::move(pStyle)));
+ pStyle.reset(new SvxRTFStyleType( *pAttrPool, aWhichMap.data() ));
+ pStyle->aAttrSet.Put( GetRTFDefaults() );
+ nStyleNo = 0;
+ bHasStyleNo = false;
+ }
+ break;
+ default:
+ switch( nToken & ~(0xff | RTF_SWGDEFS) )
+ {
+ case RTF_PARFMT: // here are no SWGDEFS
+ ReadAttr( nToken, &pStyle->aAttrSet );
+ break;
+
+ case RTF_CHRFMT:
+ case RTF_BRDRDEF:
+ case RTF_TABSTOPDEF:
+#ifndef NDEBUG
+ auto nEnteringToken = nToken;
+#endif
+ auto nEnteringIndex = m_nTokenIndex;
+ int nSkippedTokens = 0;
+ if( RTF_SWGDEFS & nToken)
+ {
+ if( RTF_IGNOREFLAG != GetStackPtr( -1 )->nTokenId )
+ break;
+ nToken = SkipToken();
+ ++nSkippedTokens;
+ if( '{' == GetStackPtr( -1 )->nTokenId )
+ {
+ nToken = SkipToken();
+ ++nSkippedTokens;
+ }
+ }
+ ReadAttr( nToken, &pStyle->aAttrSet );
+ if (nSkippedTokens && m_nTokenIndex == nEnteringIndex - nSkippedTokens)
+ {
+ // we called SkipToken to go back one or two, but ReadAttrs
+ // read nothing, so on next loop of the outer while we
+ // would end up in the same state again (assert that)
+ assert(nEnteringToken == GetNextToken());
+ // and loop endlessly, skip format a token
+ // instead to avoid that
+ SkipToken(nSkippedTokens);
+ }
+ break;
+ }
+ break;
+ }
+ }
+ pStyle.reset(); // Delete the Last Style
+ SkipToken(); // the closing brace is evaluated "above"
+
+ // Flag back to old state
+ bChkStyleAttr = bSaveChkStyleAttr;
+ bIsInReadStyleTab = false;
+}
+
+void SvxRTFParser::ReadColorTable()
+{
+ int nToken;
+ sal_uInt8 nRed = 0xff, nGreen = 0xff, nBlue = 0xff;
+
+ for (;;)
+ {
+ nToken = GetNextToken();
+ if ( '}' == nToken || !IsParserWorking() )
+ break;
+ switch( nToken )
+ {
+ case RTF_RED: nRed = sal_uInt8(nTokenValue); break;
+ case RTF_GREEN: nGreen = sal_uInt8(nTokenValue); break;
+ case RTF_BLUE: nBlue = sal_uInt8(nTokenValue); break;
+
+ case RTF_TEXTTOKEN:
+ if( 1 == aToken.getLength()
+ ? aToken[ 0 ] != ';'
+ : -1 == aToken.indexOf( ";" ) )
+ break; // At least the ';' must be found
+
+ [[fallthrough]];
+
+ case ';':
+ if( IsParserWorking() )
+ {
+ // one color is finished, fill in the table
+ // try to map the values to SV internal names
+ Color* pColor = new Color( nRed, nGreen, nBlue );
+ if( aColorTbl.empty() &&
+ sal_uInt8(-1) == nRed && sal_uInt8(-1) == nGreen && sal_uInt8(-1) == nBlue )
+ *pColor = COL_AUTO;
+ aColorTbl.push_back( pColor );
+ nRed = 0;
+ nGreen = 0;
+ nBlue = 0;
+
+ // Color has been completely read,
+ // so this is still a stable status
+ SaveState( RTF_COLORTBL );
+ }
+ break;
+ }
+ }
+ SkipToken(); // the closing brace is evaluated "above"
+}
+
+void SvxRTFParser::ReadFontTable()
+{
+ int _nOpenBrakets = 1; // the first was already detected earlier!!
+ std::unique_ptr<vcl::Font> pFont(new vcl::Font);
+ short nFontNo(0), nInsFontNo (0);
+ OUString sAltNm, sFntNm;
+ bool bIsAltFntNm = false;
+
+ rtl_TextEncoding nSystemChar = lcl_GetDefaultTextEncodingForRTF();
+ pFont->SetCharSet( nSystemChar );
+ SetEncoding( nSystemChar );
+
+ while( _nOpenBrakets && IsParserWorking() )
+ {
+ bool bCheckNewFont = false;
+ int nToken = GetNextToken();
+ switch( nToken )
+ {
+ case '}':
+ bIsAltFntNm = false;
+ // Style has been completely read,
+ // so this is still a stable status
+ if( --_nOpenBrakets <= 1 && IsParserWorking() )
+ SaveState( RTF_FONTTBL );
+ bCheckNewFont = true;
+ nInsFontNo = nFontNo;
+ break;
+ case '{':
+ if( RTF_IGNOREFLAG != GetNextToken() )
+ SkipToken();
+ // immediately skip unknown and all known but non-evaluated
+ // groups
+ else if( RTF_UNKNOWNCONTROL != ( nToken = GetNextToken() ) &&
+ RTF_PANOSE != nToken && RTF_FNAME != nToken &&
+ RTF_FONTEMB != nToken && RTF_FONTFILE != nToken )
+ SkipToken( -2 );
+ else
+ {
+ // filter out at once
+ ReadUnknownData();
+ nToken = GetNextToken();
+ if( '}' != nToken )
+ eState = SvParserState::Error;
+ break;
+ }
+ ++_nOpenBrakets;
+ break;
+ case RTF_FROMAN:
+ pFont->SetFamily( FAMILY_ROMAN );
+ break;
+ case RTF_FSWISS:
+ pFont->SetFamily( FAMILY_SWISS );
+ break;
+ case RTF_FMODERN:
+ pFont->SetFamily( FAMILY_MODERN );
+ break;
+ case RTF_FSCRIPT:
+ pFont->SetFamily( FAMILY_SCRIPT );
+ break;
+ case RTF_FDECOR:
+ pFont->SetFamily( FAMILY_DECORATIVE );
+ break;
+ // for technical/symbolic font of the rtl_TextEncoding is changed!
+ case RTF_FTECH:
+ pFont->SetCharSet( RTL_TEXTENCODING_SYMBOL );
+ [[fallthrough]];
+ case RTF_FNIL:
+ pFont->SetFamily( FAMILY_DONTKNOW );
+ break;
+ case RTF_FCHARSET:
+ if (-1 != nTokenValue)
+ {
+ rtl_TextEncoding nrtl_TextEncoding = rtl_getTextEncodingFromWindowsCharset(
+ static_cast<sal_uInt8>(nTokenValue));
+ pFont->SetCharSet(nrtl_TextEncoding);
+ //When we're in a font, the fontname is in the font
+ //charset, except for symbol fonts I believe
+ if (nrtl_TextEncoding == RTL_TEXTENCODING_SYMBOL)
+ nrtl_TextEncoding = RTL_TEXTENCODING_DONTKNOW;
+ SetEncoding(nrtl_TextEncoding);
+ }
+ break;
+ case RTF_FPRQ:
+ switch( nTokenValue )
+ {
+ case 1:
+ pFont->SetPitch( PITCH_FIXED );
+ break;
+ case 2:
+ pFont->SetPitch( PITCH_VARIABLE );
+ break;
+ }
+ break;
+ case RTF_F:
+ bCheckNewFont = true;
+ nInsFontNo = nFontNo;
+ nFontNo = static_cast<short>(nTokenValue);
+ break;
+ case RTF_FALT:
+ bIsAltFntNm = true;
+ break;
+ case RTF_TEXTTOKEN:
+ DelCharAtEnd( aToken, ';' );
+ if ( !aToken.isEmpty() )
+ {
+ if( bIsAltFntNm )
+ sAltNm = aToken;
+ else
+ sFntNm = aToken;
+ }
+ break;
+ }
+
+ if( bCheckNewFont && 1 >= _nOpenBrakets && !sFntNm.isEmpty() ) // one font is ready
+ {
+ // All data from the font is available, so off to the table
+ if (!sAltNm.isEmpty())
+ sFntNm += ";" + sAltNm;
+
+ pFont->SetFamilyName( sFntNm );
+ m_FontTable.insert(std::make_pair(nInsFontNo, std::move(pFont)));
+ pFont.reset(new vcl::Font);
+ pFont->SetCharSet( nSystemChar );
+ sAltNm.clear();
+ sFntNm.clear();
+ }
+ }
+ // the last one we have to delete manually
+ pFont.reset();
+ SkipToken(); // the closing brace is evaluated "above"
+
+ // set the default font in the Document
+ if( bNewDoc && IsParserWorking() )
+ SetDefault( RTF_DEFF, nDfltFont );
+}
+
+void SvxRTFParser::ClearColorTbl()
+{
+ while ( !aColorTbl.empty() )
+ {
+ delete aColorTbl.back();
+ aColorTbl.pop_back();
+ }
+}
+
+void SvxRTFParser::ClearAttrStack()
+{
+ aAttrStack.clear();
+}
+
+OUString& SvxRTFParser::DelCharAtEnd( OUString& rStr, const sal_Unicode cDel )
+{
+ if( !rStr.isEmpty() && ' ' == rStr[ 0 ])
+ rStr = comphelper::string::stripStart(rStr, ' ');
+ if( !rStr.isEmpty() && ' ' == rStr[ rStr.getLength()-1 ])
+ rStr = comphelper::string::stripEnd(rStr, ' ');
+ if( !rStr.isEmpty() && cDel == rStr[ rStr.getLength()-1 ])
+ rStr = rStr.copy( 0, rStr.getLength()-1 );
+ return rStr;
+}
+
+
+const vcl::Font& SvxRTFParser::GetFont( sal_uInt16 nId )
+{
+ SvxRTFFontTbl::const_iterator it = m_FontTable.find( nId );
+ if (it != m_FontTable.end())
+ {
+ return *it->second;
+ }
+ const SvxFontItem& rDfltFont = static_cast<const SvxFontItem&>(
+ pAttrPool->GetDefaultItem( aPlainMap.nFont ));
+ pDfltFont->SetFamilyName( rDfltFont.GetStyleName() );
+ pDfltFont->SetFamily( rDfltFont.GetFamily() );
+ return *pDfltFont;
+}
+
+SvxRTFItemStackType* SvxRTFParser::GetAttrSet_()
+{
+ SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
+ std::unique_ptr<SvxRTFItemStackType> pNew;
+ if( pCurrent )
+ pNew.reset(new SvxRTFItemStackType( *pCurrent, *pInsPos, false/*bCopyAttr*/ ));
+ else
+ pNew.reset(new SvxRTFItemStackType( *pAttrPool, aWhichMap.data(),
+ *pInsPos ));
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ aAttrStack.push_back( std::move(pNew) );
+ bNewGroup = false;
+ return aAttrStack.back().get();
+}
+
+
+void SvxRTFParser::ClearStyleAttr_( SvxRTFItemStackType& rStkType )
+{
+ // check attributes to the attributes of the stylesheet or to
+ // the default attrs of the document
+ SfxItemSet &rSet = rStkType.GetAttrSet();
+ const SfxItemPool& rPool = *rSet.GetPool();
+ const SfxPoolItem* pItem;
+ SfxWhichIter aIter( rSet );
+
+ if( !IsChkStyleAttr() ||
+ !rStkType.GetAttrSet().Count() ||
+ m_StyleTable.count( rStkType.nStyleNo ) == 0 )
+ {
+ for( sal_uInt16 nWhich = aIter.GetCurWhich(); nWhich; nWhich = aIter.NextWhich() )
+ {
+ if (SfxItemPool::IsWhich(nWhich) &&
+ SfxItemState::SET == rSet.GetItemState( nWhich, false, &pItem ) &&
+ rPool.GetDefaultItem( nWhich ) == *pItem )
+ rSet.ClearItem( nWhich ); // delete
+ }
+ }
+ else
+ {
+ // Delete all Attributes, which are already defined in the Style,
+ // from the current AttrSet.
+ auto const& pStyle = m_StyleTable.find(rStkType.nStyleNo)->second;
+ SfxItemSet &rStyleSet = pStyle->aAttrSet;
+ const SfxPoolItem* pSItem;
+ for( sal_uInt16 nWhich = aIter.GetCurWhich(); nWhich; nWhich = aIter.NextWhich() )
+ {
+ if( SfxItemState::SET == rStyleSet.GetItemState( nWhich, true, &pSItem ))
+ {
+ if( SfxItemState::SET == rSet.GetItemState( nWhich, false, &pItem )
+ && *pItem == *pSItem )
+ rSet.ClearItem( nWhich ); // delete
+ }
+ else if (SfxItemPool::IsWhich(nWhich) &&
+ SfxItemState::SET == rSet.GetItemState( nWhich, false, &pItem ) &&
+ rPool.GetDefaultItem( nWhich ) == *pItem )
+ rSet.ClearItem( nWhich ); // delete
+ }
+ }
+}
+
+void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack
+{
+ if( aAttrStack.empty() )
+ return;
+
+ std::unique_ptr<SvxRTFItemStackType> pOld = std::move(aAttrStack.back());
+ aAttrStack.pop_back();
+ SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
+
+ do { // middle check loop
+ sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx();
+ if (!pOld->m_pChildList &&
+ ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) ||
+ (nOldSttNdIdx == pInsPos->GetNodeIdx() &&
+ pOld->nSttCnt == pInsPos->GetCntIdx() )))
+ break; // no attributes or Area
+
+ // set only the attributes that are different from the parent
+ if( pCurrent && pOld->aAttrSet.Count() )
+ {
+ SfxItemIter aIter( pOld->aAttrSet );
+ const SfxPoolItem* pItem = aIter.GetCurItem(), *pGet;
+ do
+ {
+ if( SfxItemState::SET == pCurrent->aAttrSet.GetItemState(
+ pItem->Which(), false, &pGet ) &&
+ *pItem == *pGet )
+ pOld->aAttrSet.ClearItem( pItem->Which() );
+
+ pItem = aIter.NextItem();
+ } while (pItem);
+
+ if (!pOld->aAttrSet.Count() && !pOld->m_pChildList &&
+ !pOld->nStyleNo )
+ break;
+ }
+
+ // Set all attributes which have been defined from start until here
+ bool bCrsrBack = !pInsPos->GetCntIdx();
+ if( bCrsrBack )
+ {
+ // at the beginning of a paragraph? Move back one position
+ sal_Int32 nNd = pInsPos->GetNodeIdx();
+ MovePos(false);
+ // if can not move backward then later don't move forward !
+ bCrsrBack = nNd != pInsPos->GetNodeIdx();
+ }
+
+ if( pOld->pSttNd->GetIdx() < pInsPos->GetNodeIdx() ||
+ ( pOld->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
+ pOld->nSttCnt <= pInsPos->GetCntIdx() ) )
+ {
+ if( !bCrsrBack )
+ {
+ // all pard attributes are only valid until the previous
+ // paragraph !!
+ if( nOldSttNdIdx == pInsPos->GetNodeIdx() )
+ {
+ }
+ else
+ {
+ // Now it gets complicated:
+ // - all character attributes sre keep the area
+ // - all paragraph attributes to get the area
+ // up to the previous paragraph
+ std::unique_ptr<SvxRTFItemStackType> pNew(
+ new SvxRTFItemStackType(*pOld, *pInsPos, true));
+ pNew->aAttrSet.SetParent( pOld->aAttrSet.GetParent() );
+
+ // Delete all paragraph attributes from pNew
+ for( sal_uInt16 n = 0; n < (sizeof(aPardMap) / sizeof(sal_uInt16)) &&
+ pNew->aAttrSet.Count(); ++n )
+ if( reinterpret_cast<sal_uInt16*>(&aPardMap)[n] )
+ pNew->aAttrSet.ClearItem( reinterpret_cast<sal_uInt16*>(&aPardMap)[n] );
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // Were there any?
+ if( pNew->aAttrSet.Count() == pOld->aAttrSet.Count() )
+ {
+ pNew.reset();
+ }
+ else
+ {
+ pNew->nStyleNo = 0;
+
+ // Now span the real area of pNew from old
+ SetEndPrevPara( pOld->pEndNd, pOld->nEndCnt );
+ pNew->nSttCnt = 0;
+
+ if( IsChkStyleAttr() )
+ {
+ ClearStyleAttr_( *pOld );
+ ClearStyleAttr_( *pNew ); //#i10381#, methinks.
+ }
+
+ if( pCurrent )
+ {
+ pCurrent->Add(std::move(pOld));
+ pCurrent->Add(std::move(pNew));
+ }
+ else
+ {
+ // Last off the stack, thus cache it until the next text was
+ // read. (Span no attributes!)
+
+ m_AttrSetList.push_back(std::move(pOld));
+ m_AttrSetList.push_back(std::move(pNew));
+ }
+ break;
+ }
+ }
+ }
+
+ pOld->pEndNd = pInsPos->MakeNodeIdx().release();
+ pOld->nEndCnt = pInsPos->GetCntIdx();
+
+ /*
+ #i21422#
+ If the parent (pCurrent) sets something e.g. , and the child (pOld)
+ unsets it and the style both are based on has it unset then
+ clearing the pOld by looking at the style is clearly a disaster
+ as the text ends up with pCurrents bold and not pOlds no bold, this
+ should be rethought out. For the moment its safest to just do
+ the clean if we have no parent, all we suffer is too many
+ redundant properties.
+ */
+ if (IsChkStyleAttr() && !pCurrent)
+ ClearStyleAttr_( *pOld );
+
+ if( pCurrent )
+ {
+ pCurrent->Add(std::move(pOld));
+ // split up and create new entry, because it makes no sense
+ // to create a "so long" depend list. Bug 95010
+ if (bCrsrBack && 50 < pCurrent->m_pChildList->size())
+ {
+ // at the beginning of a paragraph? Move back one position
+ MovePos();
+ bCrsrBack = false;
+
+ // Open a new Group.
+ std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType(
+ *pCurrent, *pInsPos, true ));
+ pNew->SetRTFDefaults( GetRTFDefaults() );
+
+ // Set all until here valid Attributes
+ AttrGroupEnd();
+ pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); // can be changed after AttrGroupEnd!
+ pNew->aAttrSet.SetParent( pCurrent ? &pCurrent->aAttrSet : nullptr );
+ aAttrStack.push_back( std::move(pNew) );
+ }
+ }
+ else
+ // Last off the stack, thus cache it until the next text was
+ // read. (Span no attributes!)
+ m_AttrSetList.push_back(std::move(pOld));
+ }
+
+ if( bCrsrBack )
+ // at the beginning of a paragraph? Move back one position
+ MovePos();
+
+ } while( false );
+
+ bNewGroup = false;
+}
+
+void SvxRTFParser::SetAllAttrOfStk() // end all Attr. and set it into doc
+{
+ // repeat until all attributes will be taken from stack
+ while( !aAttrStack.empty() )
+ AttrGroupEnd();
+
+ for (size_t n = m_AttrSetList.size(); n; )
+ {
+ auto const& pStkSet = m_AttrSetList[--n];
+ SetAttrSet( *pStkSet );
+ pStkSet->DropChildList();
+ m_AttrSetList.pop_back();
+ }
+}
+
+// sets all the attributes that are different from the current
+void SvxRTFParser::SetAttrSet( SvxRTFItemStackType &rSet )
+{
+ // Was DefTab never read? then set to default
+ if( !bIsSetDfltTab )
+ SetDefault( RTF_DEFTAB, 720 );
+
+ if (rSet.m_pChildList)
+ rSet.Compress( *this );
+ if( rSet.aAttrSet.Count() || rSet.nStyleNo )
+ SetAttrInDoc( rSet );
+
+ // then process all the children
+ if (rSet.m_pChildList)
+ for (size_t n = 0; n < rSet.m_pChildList->size(); ++n)
+ SetAttrSet( *(*rSet.m_pChildList)[ n ] );
+}
+
+// Has no text been inserted yet? (SttPos from the top Stack entry!)
+bool SvxRTFParser::IsAttrSttPos()
+{
+ SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
+ return !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
+ pCurrent->nSttCnt == pInsPos->GetCntIdx());
+}
+
+
+void SvxRTFParser::SetAttrInDoc( SvxRTFItemStackType & )
+{
+}
+
+void SvxRTFParser::BuildWhichTable()
+{
+ aWhichMap.clear();
+ aWhichMap.push_back( 0 );
+
+ // Building a Which-Map 'rWhichMap' from an array of
+ // 'pWhichIds' from Which-Ids. It has the long 'nWhichIds'.
+ // The Which-Map is not going to be deleted.
+ ::BuildWhichTable( aWhichMap, reinterpret_cast<sal_uInt16*>(&aPardMap), sizeof(aPardMap) / sizeof(sal_uInt16) );
+ ::BuildWhichTable( aWhichMap, reinterpret_cast<sal_uInt16*>(&aPlainMap), sizeof(aPlainMap) / sizeof(sal_uInt16) );
+}
+
+const SfxItemSet& SvxRTFParser::GetRTFDefaults()
+{
+ if( !pRTFDefaults )
+ {
+ pRTFDefaults.reset( new SfxItemSet( *pAttrPool, aWhichMap.data() ) );
+ sal_uInt16 nId;
+ if( 0 != ( nId = aPardMap.nScriptSpace ))
+ {
+ SvxScriptSpaceItem aItem( false, nId );
+ if( bNewDoc )
+ pAttrPool->SetPoolDefaultItem( aItem );
+ else
+ pRTFDefaults->Put( aItem );
+ }
+ }
+ return *pRTFDefaults;
+}
+
+
+SvxRTFStyleType::SvxRTFStyleType( SfxItemPool& rPool, const sal_uInt16* pWhichRange )
+ : aAttrSet( rPool, pWhichRange )
+{
+ nOutlineNo = sal_uInt8(-1); // not set
+ nBasedOn = 0;
+}
+
+
+SvxRTFItemStackType::SvxRTFItemStackType(
+ SfxItemPool& rPool, const sal_uInt16* pWhichRange,
+ const EditPosition& rPos )
+ : aAttrSet( rPool, pWhichRange )
+ , nStyleNo( 0 )
+{
+ pSttNd = rPos.MakeNodeIdx();
+ nSttCnt = rPos.GetCntIdx();
+ pEndNd = pSttNd.get();
+ nEndCnt = nSttCnt;
+}
+
+SvxRTFItemStackType::SvxRTFItemStackType(
+ const SvxRTFItemStackType& rCpy,
+ const EditPosition& rPos,
+ bool const bCopyAttr )
+ : aAttrSet( *rCpy.aAttrSet.GetPool(), rCpy.aAttrSet.GetRanges() )
+ , nStyleNo( rCpy.nStyleNo )
+{
+ pSttNd = rPos.MakeNodeIdx();
+ nSttCnt = rPos.GetCntIdx();
+ pEndNd = pSttNd.get();
+ nEndCnt = nSttCnt;
+
+ aAttrSet.SetParent( &rCpy.aAttrSet );
+ if( bCopyAttr )
+ aAttrSet.Put( rCpy.aAttrSet );
+}
+
+/* ofz#13491 SvxRTFItemStackType dtor recursively
+ calls the dtor of its m_pChildList. The recurse
+ depth can grow sufficiently to trigger asan.
+
+ So breadth-first iterate through the nodes
+ and make a flat vector of them which can
+ be iterated through in order of most
+ distant from root first and release
+ their children linearly
+*/
+void SvxRTFItemStackType::DropChildList()
+{
+ if (!m_pChildList || m_pChildList->empty())
+ return;
+
+ std::vector<SvxRTFItemStackType*> bfs;
+ std::queue<SvxRTFItemStackType*> aQueue;
+ aQueue.push(this);
+
+ while (!aQueue.empty())
+ {
+ auto* front = aQueue.front();
+ aQueue.pop();
+ if (front->m_pChildList)
+ {
+ for (const auto& a : *front->m_pChildList)
+ aQueue.push(a.get());
+ bfs.push_back(front);
+ }
+ }
+
+ for (auto it = bfs.rbegin(); it != bfs.rend(); ++it)
+ {
+ SvxRTFItemStackType* pNode = *it;
+ pNode->m_pChildList.reset();
+ }
+}
+
+SvxRTFItemStackType::~SvxRTFItemStackType()
+{
+ if( pSttNd.get() != pEndNd )
+ delete pEndNd;
+}
+
+void SvxRTFItemStackType::Add(std::unique_ptr<SvxRTFItemStackType> pIns)
+{
+ if (!m_pChildList)
+ m_pChildList.reset( new SvxRTFItemStackList );
+ m_pChildList->push_back(std::move(pIns));
+}
+
+void SvxRTFItemStackType::SetStartPos( const EditPosition& rPos )
+{
+ if (pSttNd.get() != pEndNd)
+ delete pEndNd;
+ pSttNd = rPos.MakeNodeIdx();
+ pEndNd = pSttNd.get();
+ nSttCnt = rPos.GetCntIdx();
+}
+
+void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser )
+{
+ ENSURE_OR_RETURN_VOID(m_pChildList, "Compress: no ChildList" );
+ ENSURE_OR_RETURN_VOID(!m_pChildList->empty(), "Compress: ChildList empty");
+
+ SvxRTFItemStackType* pTmp = (*m_pChildList)[0].get();
+
+ if( !pTmp->aAttrSet.Count() ||
+ pSttNd->GetIdx() != pTmp->pSttNd->GetIdx() ||
+ nSttCnt != pTmp->nSttCnt )
+ return;
+
+ EditNodeIdx* pLastNd = pTmp->pEndNd;
+ sal_Int32 nLastCnt = pTmp->nEndCnt;
+
+ SfxItemSet aMrgSet( pTmp->aAttrSet );
+ for (size_t n = 1; n < m_pChildList->size(); ++n)
+ {
+ pTmp = (*m_pChildList)[n].get();
+ if (pTmp->m_pChildList)
+ pTmp->Compress( rParser );
+
+ if( !pTmp->nSttCnt
+ ? (pLastNd->GetIdx()+1 != pTmp->pSttNd->GetIdx() ||
+ !rParser.IsEndPara( pLastNd, nLastCnt ) )
+ : ( pTmp->nSttCnt != nLastCnt ||
+ pLastNd->GetIdx() != pTmp->pSttNd->GetIdx() ))
+ {
+ while (++n < m_pChildList->size())
+ {
+ pTmp = (*m_pChildList)[n].get();
+ if (pTmp->m_pChildList)
+ pTmp->Compress( rParser );
+ }
+ return;
+ }
+
+ if( n )
+ {
+ // Search for all which are set over the whole area
+ SfxItemIter aIter( aMrgSet );
+ const SfxPoolItem* pItem;
+ const SfxPoolItem* pIterItem = aIter.GetCurItem();
+ do {
+ sal_uInt16 nWhich = pIterItem->Which();
+ if( SfxItemState::SET != pTmp->aAttrSet.GetItemState( nWhich,
+ false, &pItem ) || *pItem != *pIterItem)
+ aMrgSet.ClearItem( nWhich );
+
+ pIterItem = aIter.NextItem();
+ } while(pIterItem);
+
+ if( !aMrgSet.Count() )
+ return;
+ }
+
+ pLastNd = pTmp->pEndNd;
+ nLastCnt = pTmp->nEndCnt;
+ }
+
+ if( pEndNd->GetIdx() != pLastNd->GetIdx() || nEndCnt != nLastCnt )
+ return;
+
+ // It can be merged
+ aAttrSet.Put( aMrgSet );
+
+ for (size_t n = 0; n < m_pChildList->size(); ++n)
+ {
+ pTmp = (*m_pChildList)[n].get();
+ pTmp->aAttrSet.Differentiate( aMrgSet );
+
+ if (!pTmp->m_pChildList && !pTmp->aAttrSet.Count() && !pTmp->nStyleNo)
+ {
+ m_pChildList->erase( m_pChildList->begin() + n );
+ --n;
+ }
+ }
+ if (m_pChildList->empty())
+ {
+ m_pChildList.reset();
+ }
+}
+void SvxRTFItemStackType::SetRTFDefaults( const SfxItemSet& rDefaults )
+{
+ if( rDefaults.Count() )
+ {
+ SfxItemIter aIter( rDefaults );
+ const SfxPoolItem* pItem = aIter.GetCurItem();
+ do {
+ sal_uInt16 nWhich = pItem->Which();
+ if( SfxItemState::SET != aAttrSet.GetItemState( nWhich, false ))
+ aAttrSet.Put(*pItem);
+
+ pItem = aIter.NextItem();
+ } while(pItem);
+ }
+}
+
+
+RTFPlainAttrMapIds::RTFPlainAttrMapIds( const SfxItemPool& rPool )
+{
+ nCaseMap = rPool.GetTrueWhich( SID_ATTR_CHAR_CASEMAP, false );
+ nBgColor = rPool.GetTrueWhich( SID_ATTR_BRUSH_CHAR, false );
+ nColor = rPool.GetTrueWhich( SID_ATTR_CHAR_COLOR, false );
+ nContour = rPool.GetTrueWhich( SID_ATTR_CHAR_CONTOUR, false );
+ nCrossedOut = rPool.GetTrueWhich( SID_ATTR_CHAR_STRIKEOUT, false );
+ nEscapement = rPool.GetTrueWhich( SID_ATTR_CHAR_ESCAPEMENT, false );
+ nFont = rPool.GetTrueWhich( SID_ATTR_CHAR_FONT, false );
+ nFontHeight = rPool.GetTrueWhich( SID_ATTR_CHAR_FONTHEIGHT, false );
+ nKering = rPool.GetTrueWhich( SID_ATTR_CHAR_KERNING, false );
+ nLanguage = rPool.GetTrueWhich( SID_ATTR_CHAR_LANGUAGE, false );
+ nPosture = rPool.GetTrueWhich( SID_ATTR_CHAR_POSTURE, false );
+ nShadowed = rPool.GetTrueWhich( SID_ATTR_CHAR_SHADOWED, false );
+ nUnderline = rPool.GetTrueWhich( SID_ATTR_CHAR_UNDERLINE, false );
+ nOverline = rPool.GetTrueWhich( SID_ATTR_CHAR_OVERLINE, false );
+ nWeight = rPool.GetTrueWhich( SID_ATTR_CHAR_WEIGHT, false );
+ nWordlineMode = rPool.GetTrueWhich( SID_ATTR_CHAR_WORDLINEMODE, false );
+ nAutoKerning = rPool.GetTrueWhich( SID_ATTR_CHAR_AUTOKERN, false );
+
+ nCJKFont = rPool.GetTrueWhich( SID_ATTR_CHAR_CJK_FONT, false );
+ nCJKFontHeight = rPool.GetTrueWhich( SID_ATTR_CHAR_CJK_FONTHEIGHT, false );
+ nCJKLanguage = rPool.GetTrueWhich( SID_ATTR_CHAR_CJK_LANGUAGE, false );
+ nCJKPosture = rPool.GetTrueWhich( SID_ATTR_CHAR_CJK_POSTURE, false );
+ nCJKWeight = rPool.GetTrueWhich( SID_ATTR_CHAR_CJK_WEIGHT, false );
+ nCTLFont = rPool.GetTrueWhich( SID_ATTR_CHAR_CTL_FONT, false );
+ nCTLFontHeight = rPool.GetTrueWhich( SID_ATTR_CHAR_CTL_FONTHEIGHT, false );
+ nCTLLanguage = rPool.GetTrueWhich( SID_ATTR_CHAR_CTL_LANGUAGE, false );
+ nCTLPosture = rPool.GetTrueWhich( SID_ATTR_CHAR_CTL_POSTURE, false );
+ nCTLWeight = rPool.GetTrueWhich( SID_ATTR_CHAR_CTL_WEIGHT, false );
+ nEmphasis = rPool.GetTrueWhich( SID_ATTR_CHAR_EMPHASISMARK, false );
+ nTwoLines = rPool.GetTrueWhich( SID_ATTR_CHAR_TWO_LINES, false );
+ nCharScaleX = rPool.GetTrueWhich( SID_ATTR_CHAR_SCALEWIDTH, false );
+ nHorzVert = rPool.GetTrueWhich( SID_ATTR_CHAR_ROTATED, false );
+ nRelief = rPool.GetTrueWhich( SID_ATTR_CHAR_RELIEF, false );
+ nHidden = rPool.GetTrueWhich( SID_ATTR_CHAR_HIDDEN, false );
+}
+
+RTFPardAttrMapIds ::RTFPardAttrMapIds ( const SfxItemPool& rPool )
+{
+ nLinespacing = rPool.GetTrueWhich( SID_ATTR_PARA_LINESPACE, false );
+ nAdjust = rPool.GetTrueWhich( SID_ATTR_PARA_ADJUST, false );
+ nTabStop = rPool.GetTrueWhich( SID_ATTR_TABSTOP, false );
+ nHyphenzone = rPool.GetTrueWhich( SID_ATTR_PARA_HYPHENZONE, false );
+ nLRSpace = rPool.GetTrueWhich( SID_ATTR_LRSPACE, false );
+ nULSpace = rPool.GetTrueWhich( SID_ATTR_ULSPACE, false );
+ nBrush = rPool.GetTrueWhich( SID_ATTR_BRUSH, false );
+ nBox = rPool.GetTrueWhich( SID_ATTR_BORDER_OUTER, false );
+ nShadow = rPool.GetTrueWhich( SID_ATTR_BORDER_SHADOW, false );
+ nOutlineLvl = rPool.GetTrueWhich( SID_ATTR_PARA_OUTLLEVEL, false );
+ nSplit = rPool.GetTrueWhich( SID_ATTR_PARA_SPLIT, false );
+ nKeep = rPool.GetTrueWhich( SID_ATTR_PARA_KEEP, false );
+ nFontAlign = rPool.GetTrueWhich( SID_PARA_VERTALIGN, false );
+ nScriptSpace = rPool.GetTrueWhich( SID_ATTR_PARA_SCRIPTSPACE, false );
+ nHangPunct = rPool.GetTrueWhich( SID_ATTR_PARA_HANGPUNCTUATION, false );
+ nForbRule = rPool.GetTrueWhich( SID_ATTR_PARA_FORBIDDEN_RULES, false );
+ nDirection = rPool.GetTrueWhich( SID_ATTR_FRAMEDIRECTION, false );
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */