LibreOffice Module editeng (master) 1
svxrtf.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#ifndef INCLUDED_EDITENG_SVXRTF_HXX
21#define INCLUDED_EDITENG_SVXRTF_HXX
22
23#include <svl/itemset.hxx>
24#include <svtools/parrtf.hxx>
25#include <rtl/ustring.hxx>
26#include <tools/color.hxx>
27#include <vcl/font.hxx>
28
30
31#include <optional>
32#include <vector>
33#include <map>
34#include <memory>
35
36struct SvxRTFStyleType;
38class SvxRTFItemStackList : public std::vector<std::unique_ptr<SvxRTFItemStackType>> {};
39
40// Mapper-Classes for the various requirements on Document positions
41// Swg - NodePosition is a SwContentIndex, which is used internally
42// EditEngine - ULONG to list of paragraphs
43
44class EditEngine;
45class ContentNode;
47{
48public:
50 sal_Int32 GetIdx() const;
51 ContentNode* GetNode() { return mpNode; }
52private:
55};
56
57class EditSelection;
59{
60private:
63
64public:
66
67 sal_Int32 GetNodeIdx() const;
68 sal_Int32 GetCntIdx() const;
69
70 // clone NodeIndex
72};
73
74typedef std::map<short, vcl::Font> SvxRTFFontTbl;
75
76// own helper classes for the RTF Parser
78{
79 SfxItemSet aAttrSet; // the attributes of Style (+ derivated!)
80 OUString sName;
81 sal_uInt16 nBasedOn;
83
84 SvxRTFStyleType(SfxItemPool& rPool, const WhichRangesContainer& pWhichRange);
85};
86
87typedef std::map<sal_uInt16, SvxRTFStyleType> SvxRTFStyleTbl;
88
90{
91 std::vector<Color> maColorTable;
94 std::deque< std::unique_ptr<SvxRTFItemStackType> > aAttrStack;
96
98 {
99 std::map<sal_uInt16, sal_uInt16> data;
100 template<class T>
102 template<class T>
103 void set(TypedWhichId<T> in, TypedWhichId<T> out) { data[in] = out; }
104 };
108
109 std::optional<EditPosition> mxInsertPosition;
111 std::optional<Color> mxDefaultColor;
112 std::optional<vcl::Font> pDfltFont;
113 std::unique_ptr<SfxItemSet> pRTFDefaults;
114
116
117 bool bNewDoc : 1; // sal_False - Reading in an existing
118 bool bNewGroup : 1; // sal_True - there was an opening parenthesis
119 bool bIsSetDfltTab : 1; // sal_True - DefTab was loaded
120 bool bChkStyleAttr : 1; // sal_True - StyleSheets are evaluated
121 bool bCalcValue : 1; // sal_True - Twip values adapt to App
122 bool bIsLeftToRightDef : 1; // sal_True - in LeftToRight char run def.
123 // sal_False - in RightToLeft char run def.
124 bool bIsInReadStyleTab : 1; // sal_True - in ReadStyleTable
125
126 SvxRTFParser(SvxRTFParser const&) = delete;
127 void operator=(SvxRTFParser const&) = delete;
128
129 void ClearColorTbl();
130 void ClearAttrStack();
131
132 SvxRTFItemStackType* GetAttrSet_(); // Create new ItemStackType:s
133 void ClearStyleAttr_( SvxRTFItemStackType& rStkType );
134
135 // Sets all the attributes that are different from the current
136 void SetAttrSet( SvxRTFItemStackType &rSet );
137 void SetDefault( int nToken, int nValue );
138
139 // Execute pard / plain
140 void RTFPardPlain( bool bPard, SfxItemSet** ppSet );
141
142 void BuildWhichTable();
143
145 {
149 DOUBLEBYTE_CHARTYPE
150 };
151
152 // set latin/asian/complex character attributes
153 void SetScriptAttr(
154 RTF_CharTypeDef eType, SfxItemSet& rSet, SfxPoolItem& rItem );
155
156protected:
157 virtual void InsertPara() = 0;
158
159 static void DelCharAtEnd( OUStringBuffer& rStr, const sal_Unicode cDel );
160
161 // is called for each token that is recognized in CallParser
162 virtual void NextToken( int nToken ) override;
163
164 void ReadStyleTable();
165 void ReadColorTable();
166 void ReadFontTable();
167 void ReadAttr( int nToken, SfxItemSet* pSet );
168 void ReadTabAttr( int nToken, SfxItemSet& rSet );
169
170 inline SfxItemSet& GetAttrSet();
171 // no text yet inserted? (SttPos from the top stack entry!)
172 bool IsAttrSttPos();
173 void AttrGroupEnd(); // edit the current, delete from stack
174 void SetAllAttrOfStk(); // end all Attr. and set it into doc
175
176
177 virtual void InsertText() = 0;
178 virtual void MovePos( bool bForward = true ) = 0;
179 virtual void SetEndPrevPara( std::optional<EditNodeIdx>& rpNodePos,
180 sal_Int32& rCntPos )=0;
181 virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
182 // for Tokens, which are not evaluated in ReadAttr
183 virtual void UnknownAttrToken( int nToken );
184
185 // if no-one would like to have any twips
186 virtual void CalcValue();
187
188 SvxRTFParser( SfxItemPool& rAttrPool, SvStream& rIn );
189 virtual ~SvxRTFParser() override;
190
191 void SetNewDoc( bool bFlag ) { bNewDoc = bFlag; }
192 bool IsChkStyleAttr() const { return bChkStyleAttr; }
193 void SetChkStyleAttr( bool bFlag ) { bChkStyleAttr = bFlag; }
194 bool IsCalcValue() const { return bCalcValue; }
195 void SetCalcValue( bool bFlag ) { bCalcValue = bFlag; }
196
197 // Query/Set the current insert position
198 void SetInsPos( const EditPosition& rNew );
199 SvxRTFStyleTbl& GetStyleTbl() { return m_StyleTable; }
200
201public:
202
203 virtual SvParserState CallParser() override;
204
205 inline const Color& GetColor( size_t nId ) const;
206 const vcl::Font& GetFont( sal_uInt16 nId ); // Changes the default Font
207
208 virtual bool IsEndPara( EditNodeIdx* pNd, sal_Int32 nCnt ) const = 0;
209
210 // to set a different attribute pool. May only be done prior to CallParser!
211 // The maps are not generated anew!
212 void SetAttrPool( SfxItemPool* pNewPool ) { pAttrPool = pNewPool; }
213 // to set different WhichIds for a different pool.
214 template<class T>
215 void SetPardMap(TypedWhichId<T> wid, TypedWhichId<T> widTrue) { aPardMap.set(wid, widTrue); }
216 // to be able to assign them from the outside as for example table cells
217 void ReadBorderAttr( int nToken, SfxItemSet& rSet, bool bTableDef=false );
218 void ReadBackgroundAttr( int nToken, SfxItemSet& rSet, bool bTableDef=false );
219
220 // for asynchronous read from the SvStream
221 virtual void Continue( int nToken ) override;
222
223 // get RTF default ItemSets. Must be used by pard/plain tokens or in
224 // reset of Style-Items
225 const SfxItemSet& GetRTFDefaults();
226};
227
228// The stack for the attributes:
229// this class may only be used by SvxRTFParser!
231{
232 friend class SvxRTFParser;
233
235 std::optional<EditNodeIdx> mxStartNodeIdx;
236 std::optional<EditNodeIdx> mxEndNodeIdx;
237 sal_Int32 nSttCnt, nEndCnt;
239 sal_uInt16 nStyleNo;
240
242 void operator=(SvxRTFItemStackType const&) = delete;
243
245 const EditPosition& );
246
247 static std::unique_ptr<SvxRTFItemStackType> createSvxRTFItemStackType(
248 SfxItemPool&, const WhichRangesContainer& pWhichRange, const EditPosition&);
249
250 void Add(std::unique_ptr<SvxRTFItemStackType>);
251 void Compress( const SvxRTFParser& );
252 void DropChildList();
253
254public:
256 bool bCopyAttr);
258 //cmc, I'm very suspicious about SetStartPos, it doesn't change
259 //its children's starting position, and the implementation looks
260 //bad, consider this deprecated.
261 void SetStartPos( const EditPosition& rPos );
262
263 const EditNodeIdx& GetSttNode() const { return *mxStartNodeIdx; }
264 const EditNodeIdx& GetEndNode() const { return *mxEndNodeIdx; }
265
266 sal_Int32 GetSttCnt() const { return nSttCnt; }
267 sal_Int32 GetEndCnt() const { return nEndCnt; }
268
270 const SfxItemSet& GetAttrSet() const { return aAttrSet; }
271
272 sal_uInt16 StyleNo() const { return nStyleNo; }
273
274 void SetRTFDefaults( const SfxItemSet& rDefaults );
275};
276
277
278// ----------- Inline Implementations --------------
279
280inline const Color& SvxRTFParser::GetColor( size_t nId ) const
281{
282 if( nId < maColorTable.size() )
283 return maColorTable[ nId ];
284 return *mxDefaultColor;
285}
286
288{
290 if( bNewGroup || aAttrStack.empty() )
291 pTmp = GetAttrSet_();
292 else
293 {
294 pTmp = aAttrStack.back().get();
295 if ( pTmp == nullptr )
296 pTmp = GetAttrSet_();
297 }
298 return pTmp->aAttrSet;
299}
300
301
302#endif // INCLUDED_EDITENG_SVXRTF_HXX
303
304/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
ContentNode * mpNode
Definition: svxrtf.hxx:54
EditNodeIdx(EditEngine *pEE, ContentNode *pNd)
Definition: eertfpar.cxx:607
EditEngine * mpEditEngine
Definition: svxrtf.hxx:53
ContentNode * GetNode()
Definition: svxrtf.hxx:51
sal_Int32 GetIdx() const
Definition: eertfpar.cxx:610
EditPosition(EditEngine *pIEE, EditSelection *pSel)
EditSelection * mpCurSel
Definition: svxrtf.hxx:62
sal_Int32 GetCntIdx() const
EditNodeIdx MakeNodeIdx() const
EditEngine * mpEditEngine
Definition: svxrtf.hxx:61
sal_Int32 GetNodeIdx() const
virtual void NextToken(T nToken)=0
virtual void Continue(int nToken) override
virtual SvParserState CallParser() override
SvxRTFItemStackList maChildList
Definition: svxrtf.hxx:238
const SfxItemSet & GetAttrSet() const
Definition: svxrtf.hxx:270
sal_Int32 GetEndCnt() const
Definition: svxrtf.hxx:267
SvxRTFItemStackType(SvxRTFItemStackType const &)=delete
void SetRTFDefaults(const SfxItemSet &rDefaults)
Definition: svxrtf.cxx:1146
sal_uInt16 nStyleNo
Definition: svxrtf.hxx:239
const EditNodeIdx & GetSttNode() const
Definition: svxrtf.hxx:263
SfxItemSet aAttrSet
Definition: svxrtf.hxx:234
sal_Int32 nSttCnt
Definition: svxrtf.hxx:237
std::optional< EditNodeIdx > mxStartNodeIdx
Definition: svxrtf.hxx:235
std::optional< EditNodeIdx > mxEndNodeIdx
Definition: svxrtf.hxx:236
const EditNodeIdx & GetEndNode() const
Definition: svxrtf.hxx:264
void SetStartPos(const EditPosition &rPos)
Definition: svxrtf.cxx:1059
void operator=(SvxRTFItemStackType const &)=delete
static std::unique_ptr< SvxRTFItemStackType > createSvxRTFItemStackType(SfxItemPool &, const WhichRangesContainer &pWhichRange, const EditPosition &)
Definition: svxrtf.cxx:607
void Compress(const SvxRTFParser &)
Definition: svxrtf.cxx:1066
SfxItemSet & GetAttrSet()
Definition: svxrtf.hxx:269
sal_Int32 GetSttCnt() const
Definition: svxrtf.hxx:266
sal_Int32 nEndCnt
Definition: svxrtf.hxx:237
void Add(std::unique_ptr< SvxRTFItemStackType >)
Definition: svxrtf.cxx:1054
sal_uInt16 StyleNo() const
Definition: svxrtf.hxx:272
bool bNewGroup
Definition: svxrtf.hxx:118
SvxRTFParser(SvxRTFParser const &)=delete
SfxItemPool * pAttrPool
Definition: svxrtf.hxx:110
bool bChkStyleAttr
Definition: svxrtf.hxx:120
bool bIsSetDfltTab
Definition: svxrtf.hxx:119
void operator=(SvxRTFParser const &)=delete
PlainOrPardMap aPlainMap
Definition: svxrtf.hxx:105
void SetChkStyleAttr(bool bFlag)
Definition: svxrtf.hxx:193
WhichRangesContainer aWhichMap
Definition: svxrtf.hxx:107
virtual void InsertText()=0
bool bCalcValue
Definition: svxrtf.hxx:121
@ NOTDEF_CHARTYPE
Definition: svxrtf.hxx:146
bool IsChkStyleAttr() const
Definition: svxrtf.hxx:192
virtual void InsertPara()=0
std::optional< Color > mxDefaultColor
Definition: svxrtf.hxx:111
virtual void SetEndPrevPara(std::optional< EditNodeIdx > &rpNodePos, sal_Int32 &rCntPos)=0
SvxRTFStyleTbl m_StyleTable
Definition: svxrtf.hxx:93
virtual bool IsEndPara(EditNodeIdx *pNd, sal_Int32 nCnt) const =0
std::vector< Color > maColorTable
Definition: svxrtf.hxx:91
std::optional< vcl::Font > pDfltFont
Definition: svxrtf.hxx:112
std::optional< EditPosition > mxInsertPosition
Definition: svxrtf.hxx:109
SvxRTFStyleTbl & GetStyleTbl()
Definition: svxrtf.hxx:199
SvxRTFFontTbl m_FontTable
Definition: svxrtf.hxx:92
bool bIsLeftToRightDef
Definition: svxrtf.hxx:122
std::unique_ptr< SfxItemSet > pRTFDefaults
Definition: svxrtf.hxx:113
int nDfltFont
Definition: svxrtf.hxx:115
void SetPardMap(TypedWhichId< T > wid, TypedWhichId< T > widTrue)
Definition: svxrtf.hxx:215
void SetCalcValue(bool bFlag)
Definition: svxrtf.hxx:195
void SetNewDoc(bool bFlag)
Definition: svxrtf.hxx:191
bool bIsInReadStyleTab
Definition: svxrtf.hxx:124
SvxRTFItemStackList m_AttrSetList
Definition: svxrtf.hxx:95
PlainOrPardMap aPardMap
Definition: svxrtf.hxx:106
SfxItemSet & GetAttrSet()
Definition: svxrtf.hxx:287
void SetAttrPool(SfxItemPool *pNewPool)
Definition: svxrtf.hxx:212
const Color & GetColor(size_t nId) const
Definition: svxrtf.hxx:280
bool IsCalcValue() const
Definition: svxrtf.hxx:194
SvxRTFItemStackType * GetAttrSet_()
Definition: svxrtf.cxx:620
std::deque< std::unique_ptr< SvxRTFItemStackType > > aAttrStack
Definition: svxrtf.hxx:94
bool bNewDoc
Definition: svxrtf.hxx:117
virtual void MovePos(bool bForward=true)=0
#define EDITENG_DLLPUBLIC
Definition: editengdllapi.h:28
vcl::Font GetFont(vcl::Font const &rFont, DrawModeFlags nDrawMode, StyleSettings const &rStyleSettings)
sal_Int16 nId
TypedWhichId< T > operator[](TypedWhichId< T > in) const
Definition: svxrtf.hxx:101
void set(TypedWhichId< T > in, TypedWhichId< T > out)
Definition: svxrtf.hxx:103
std::map< sal_uInt16, sal_uInt16 > data
Definition: svxrtf.hxx:99
sal_uInt16 nBasedOn
Definition: svxrtf.hxx:81
SfxItemSet aAttrSet
Definition: svxrtf.hxx:79
sal_uInt8 nOutlineNo
Definition: svxrtf.hxx:82
SvxRTFStyleType(SfxItemPool &rPool, const WhichRangesContainer &pWhichRange)
Definition: svxrtf.cxx:971
OUString sName
Definition: svxrtf.hxx:80
SvParserState
std::map< short, vcl::Font > SvxRTFFontTbl
Definition: svxrtf.hxx:74
std::map< sal_uInt16, SvxRTFStyleType > SvxRTFStyleTbl
Definition: svxrtf.hxx:87
unsigned char sal_uInt8
sal_uInt16 sal_Unicode