nss: upgrade to release 3.73
[LibreOffice.git] / include / editeng / svxrtf.hxx
blobfaff107c14966a2bf55f122d67559c36d98e631f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #ifndef INCLUDED_EDITENG_SVXRTF_HXX
21 #define INCLUDED_EDITENG_SVXRTF_HXX
23 #include <svl/itemset.hxx>
24 #include <svtools/parrtf.hxx>
25 #include <rtl/ustring.hxx>
26 #include <tools/color.hxx>
28 #include <editeng/editengdllapi.h>
30 #include <optional>
31 #include <vector>
32 #include <map>
33 #include <memory>
35 namespace vcl { class Font; }
36 struct SvxRTFStyleType;
37 class SvxRTFItemStackType;
38 class SvxRTFItemStackList : public std::vector<std::unique_ptr<SvxRTFItemStackType>> {};
40 // Mapper-Classes for the various requirements on Document positions
41 // Swg - NodePosition is a SwIndex, which is used internally
42 // EditEngine - ULONG to list of paragraphs
44 class EditEngine;
45 class ContentNode;
46 class EditNodeIdx
48 public:
49 EditNodeIdx(EditEngine* pEE, ContentNode* pNd);
50 sal_Int32 GetIdx() const;
51 ContentNode* GetNode() { return mpNode; }
52 private:
53 EditEngine* mpEditEngine;
54 ContentNode* mpNode;
57 class EditSelection;
58 class EditPosition
60 private:
61 EditEngine* mpEditEngine;
62 EditSelection* mpCurSel;
64 public:
65 EditPosition(EditEngine* pIEE, EditSelection* pSel);
67 sal_Int32 GetNodeIdx() const;
68 sal_Int32 GetCntIdx() const;
70 // clone
71 std::unique_ptr<EditPosition> Clone() const;
73 // clone NodeIndex
74 std::unique_ptr<EditNodeIdx> MakeNodeIdx() const;
77 typedef std::map<short, std::unique_ptr<vcl::Font>> SvxRTFFontTbl;
78 typedef std::map<sal_uInt16, std::unique_ptr<SvxRTFStyleType>> SvxRTFStyleTbl;
80 // own helper classes for the RTF Parser
81 struct SvxRTFStyleType
83 SfxItemSet aAttrSet; // the attributes of Style (+ derivated!)
84 OUString sName;
85 sal_uInt16 nBasedOn;
86 sal_uInt8 nOutlineNo;
88 SvxRTFStyleType( SfxItemPool& rPool, const sal_uInt16* pWhichRange );
92 // Here are the IDs for all character attributes, which can be detected by
93 // SvxParser and can be set in a SfxItemSet. The IDs are set correctly through
94 // the SlotIds from POOL.
95 struct RTFPlainAttrMapIds
97 sal_uInt16 nCaseMap,
98 nBgColor,
99 nColor,
100 nContour,
101 nCrossedOut,
102 nEscapement,
103 nFont,
104 nFontHeight,
105 nKering,
106 nLanguage,
107 nPosture,
108 nShadowed,
109 nUnderline,
110 nOverline,
111 nWeight,
112 nWordlineMode,
113 nAutoKerning,
114 nCJKFont,
115 nCJKFontHeight,
116 nCJKLanguage,
117 nCJKPosture,
118 nCJKWeight,
119 nCTLFont,
120 nCTLFontHeight,
121 nCTLLanguage,
122 nCTLPosture,
123 nCTLWeight,
124 nEmphasis,
125 nTwoLines,
126 nCharScaleX,
127 nHorzVert,
128 nRelief,
129 nHidden
131 RTFPlainAttrMapIds( const SfxItemPool& rPool );
134 // Here are the IDs for all paragraph attributes, which can be detected by
135 // SvxParser and can be set in a SfxItemSet. The IDs are set correctly through
136 // the SlotIds from POOL.
137 struct RTFPardAttrMapIds
139 sal_uInt16 nLinespacing,
140 nAdjust,
141 nTabStop,
142 nHyphenzone,
143 nLRSpace,
144 nULSpace,
145 nBrush,
146 nBox,
147 nShadow,
148 nOutlineLvl,
149 nSplit,
150 nKeep,
151 nFontAlign,
152 nScriptSpace,
153 nHangPunct,
154 nForbRule,
155 nDirection
157 RTFPardAttrMapIds( const SfxItemPool& rPool );
161 class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser
163 std::vector<Color> maColorTable;
164 SvxRTFFontTbl m_FontTable;
165 SvxRTFStyleTbl m_StyleTable;
166 std::deque< std::unique_ptr<SvxRTFItemStackType> > aAttrStack;
167 SvxRTFItemStackList m_AttrSetList;
169 RTFPlainAttrMapIds aPlainMap;
170 RTFPardAttrMapIds aPardMap;
171 std::vector<sal_uInt16> aWhichMap;
173 std::unique_ptr<EditPosition> pInsPos;
174 SfxItemPool* pAttrPool;
175 std::optional<Color> mxDefaultColor;
176 std::unique_ptr<vcl::Font> pDfltFont;
177 std::unique_ptr<SfxItemSet> pRTFDefaults;
179 int nDfltFont;
181 bool bNewDoc : 1; // sal_False - Reading in an existing
182 bool bNewGroup : 1; // sal_True - there was an opening parenthesis
183 bool bIsSetDfltTab : 1; // sal_True - DefTab was loaded
184 bool bChkStyleAttr : 1; // sal_True - StyleSheets are evaluated
185 bool bCalcValue : 1; // sal_True - Twip values adapt to App
186 bool bIsLeftToRightDef : 1; // sal_True - in LeftToRight char run def.
187 // sal_False - in RightToLeft char run def.
188 bool bIsInReadStyleTab : 1; // sal_True - in ReadStyleTable
190 SvxRTFParser(SvxRTFParser const&) = delete;
191 void operator=(SvxRTFParser const&) = delete;
193 void ClearColorTbl();
194 void ClearAttrStack();
196 SvxRTFItemStackType* GetAttrSet_(); // Create new ItemStackType:s
197 void ClearStyleAttr_( SvxRTFItemStackType& rStkType );
199 // Sets all the attributes that are different from the current
200 void SetAttrSet( SvxRTFItemStackType &rSet );
201 void SetDefault( int nToken, int nValue );
203 // Execute pard / plain
204 void RTFPardPlain( bool bPard, SfxItemSet** ppSet );
206 void BuildWhichTable();
208 enum RTF_CharTypeDef
210 NOTDEF_CHARTYPE,
211 LOW_CHARTYPE,
212 HIGH_CHARTYPE,
213 DOUBLEBYTE_CHARTYPE
216 // set latin/asian/complex character attributes
217 void SetScriptAttr(
218 RTF_CharTypeDef eType, SfxItemSet& rSet, SfxPoolItem& rItem );
220 protected:
221 virtual void InsertPara() = 0;
223 static OUString& DelCharAtEnd( OUString& rStr, const sal_Unicode cDel );
225 // is called for each token that is recognized in CallParser
226 virtual void NextToken( int nToken ) override;
228 void ReadStyleTable();
229 void ReadColorTable();
230 void ReadFontTable();
231 void ReadAttr( int nToken, SfxItemSet* pSet );
232 void ReadTabAttr( int nToken, SfxItemSet& rSet );
234 inline SfxItemSet& GetAttrSet();
235 // no text yet inserted? (SttPos from the top stack entry!)
236 bool IsAttrSttPos();
237 void AttrGroupEnd(); // edit the current, delete from stack
238 void SetAllAttrOfStk(); // end all Attr. and set it into doc
241 virtual void InsertText() = 0;
242 virtual void MovePos( bool bForward = true ) = 0;
243 virtual void SetEndPrevPara( EditNodeIdx*& rpNodePos,
244 sal_Int32& rCntPos )=0;
245 virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
246 // for Tokens, which are not evaluated in ReadAttr
247 virtual void UnknownAttrToken( int nToken );
249 // if no-one would like to have any twips
250 virtual void CalcValue();
252 SvxRTFParser( SfxItemPool& rAttrPool, SvStream& rIn );
253 virtual ~SvxRTFParser() override;
255 void SetNewDoc( bool bFlag ) { bNewDoc = bFlag; }
256 bool IsChkStyleAttr() const { return bChkStyleAttr; }
257 void SetChkStyleAttr( bool bFlag ) { bChkStyleAttr = bFlag; }
258 bool IsCalcValue() const { return bCalcValue; }
259 void SetCalcValue( bool bFlag ) { bCalcValue = bFlag; }
261 // Query/Set the current insert position
262 void SetInsPos( const EditPosition& rNew );
263 SvxRTFStyleTbl& GetStyleTbl() { return m_StyleTable; }
265 public:
267 virtual SvParserState CallParser() override;
269 inline const Color& GetColor( size_t nId ) const;
270 const vcl::Font& GetFont( sal_uInt16 nId ); // Changes the default Font
272 virtual bool IsEndPara( EditNodeIdx* pNd, sal_Int32 nCnt ) const = 0;
274 // to set a different attribute pool. May only be done prior to CallParser!
275 // The maps are not generated anew!
276 void SetAttrPool( SfxItemPool* pNewPool ) { pAttrPool = pNewPool; }
277 // to set different WhichIds for a different pool.
278 RTFPardAttrMapIds& GetPardMap() { return aPardMap; }
279 // to be able to assign them from the outside as for example table cells
280 void ReadBorderAttr( int nToken, SfxItemSet& rSet, bool bTableDef=false );
281 void ReadBackgroundAttr( int nToken, SfxItemSet& rSet, bool bTableDef=false );
283 // for asynchronous read from the SvStream
284 virtual void Continue( int nToken ) override;
286 // get RTF default ItemSets. Must be used by pard/plain tokens or in
287 // reset of Style-Items
288 const SfxItemSet& GetRTFDefaults();
291 // The stack for the attributes:
292 // this class may only be used by SvxRTFParser!
293 class SvxRTFItemStackType
295 friend class SvxRTFParser;
297 SfxItemSet aAttrSet;
298 std::unique_ptr<EditNodeIdx> pSttNd;
299 EditNodeIdx *pEndNd;
300 sal_Int32 nSttCnt, nEndCnt;
301 std::unique_ptr<SvxRTFItemStackList> m_pChildList;
302 sal_uInt16 nStyleNo;
304 SvxRTFItemStackType(SvxRTFItemStackType const&) = delete;
305 void operator=(SvxRTFItemStackType const&) = delete;
307 SvxRTFItemStackType( SfxItemPool&, const sal_uInt16* pWhichRange,
308 const EditPosition& );
310 void Add(std::unique_ptr<SvxRTFItemStackType>);
311 void Compress( const SvxRTFParser& );
312 void DropChildList();
314 public:
315 SvxRTFItemStackType(const SvxRTFItemStackType&, const EditPosition&,
316 bool bCopyAttr);
317 ~SvxRTFItemStackType();
318 //cmc, I'm very suspicious about SetStartPos, it doesn't change
319 //its children's starting position, and the implementation looks
320 //bad, consider this deprecated.
321 void SetStartPos( const EditPosition& rPos );
323 const EditNodeIdx& GetSttNode() const { return *pSttNd; }
324 const EditNodeIdx& GetEndNode() const { return *pEndNd; }
326 sal_Int32 GetSttCnt() const { return nSttCnt; }
327 sal_Int32 GetEndCnt() const { return nEndCnt; }
329 SfxItemSet& GetAttrSet() { return aAttrSet; }
330 const SfxItemSet& GetAttrSet() const { return aAttrSet; }
332 sal_uInt16 StyleNo() const { return nStyleNo; }
334 void SetRTFDefaults( const SfxItemSet& rDefaults );
338 // ----------- Inline Implementations --------------
340 inline const Color& SvxRTFParser::GetColor( size_t nId ) const
342 if( nId < maColorTable.size() )
343 return maColorTable[ nId ];
344 return *mxDefaultColor;
347 inline SfxItemSet& SvxRTFParser::GetAttrSet()
349 SvxRTFItemStackType* pTmp;
350 if( bNewGroup || aAttrStack.empty() )
351 pTmp = GetAttrSet_();
352 else
354 pTmp = aAttrStack.back().get();
355 if ( pTmp == nullptr )
356 pTmp = GetAttrSet_();
358 return pTmp->aAttrSet;
362 #endif // INCLUDED_EDITENG_SVXRTF_HXX
364 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */