Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SWPARRTF_HXX
30 : : #define _SWPARRTF_HXX
31 : :
32 : : #include <deque>
33 : : #include <vector>
34 : : #include <map>
35 : :
36 : : #include <editeng/svxrtf.hxx>
37 : : #include <editeng/numitem.hxx>
38 : : #include <editeng/boxitem.hxx>
39 : : #include <redline.hxx>
40 : :
41 : : #include <fltshell.hxx> // fuer den Attribut Stack
42 : : #include <ndindex.hxx>
43 : : #include "../inc/msfilter.hxx"
44 : : #include <svx/svdobj.hxx>
45 : :
46 : :
47 : : extern void GetLineIndex(SvxBoxItem &rBox, short nLineThickness, short nSpace, sal_uInt8 nCol, short nIdx,
48 : : sal_uInt16 nOOIndex, sal_uInt16 nWWIndex, short *pSize);
49 : :
50 : : class Font;
51 : : class Graphic;
52 : :
53 : : class SwNoTxtNode;
54 : : class Size;
55 : : class SwPaM;
56 : : class SwDoc;
57 : : class SwPageDesc;
58 : : class SwTxtFmtColl;
59 : : class SwTableNode;
60 : : class SwCharFmt;
61 : : class SwNumRule;
62 : : class SwRTFParser;
63 : : class SvxFontItem;
64 : : class SwRelNumRuleSpaces;
65 : : class SwNodeNum;
66 : : class SwTxtNode;
67 : : struct SvxRTFPictureType;
68 : :
69 [ # # ]: 0 : class RtfReader: public Reader
70 : : {
71 : : virtual sal_uLong Read( SwDoc &, const String& rBaseURL, SwPaM &,const String &);
72 : : public:
73 : : virtual sal_uLong Read( SvStream* pStrm, SwDoc &, const String& rBaseURL, SwPaM &);
74 : : };
75 : :
76 [ # # ][ # # ]: 0 : class SwNodeIdx : public SvxNodeIdx
77 : : {
78 : : SwNodeIndex aIdx;
79 : : public:
80 [ # # ]: 0 : SwNodeIdx( const SwNodeIndex& rIdx ) : aIdx( rIdx ) {}
81 : : virtual sal_uLong GetIdx() const;
82 : : virtual SvxNodeIdx* Clone() const;
83 : : };
84 : :
85 : 0 : class BookmarkPosition
86 : : {
87 : : public:
88 : : SwNodeIndex maMkNode;
89 : : xub_StrLen mnMkCntnt;
90 : : BookmarkPosition(const SwPaM &rPaM);
91 : : BookmarkPosition(const BookmarkPosition &rEntry);
92 : :
93 : : bool operator==(const BookmarkPosition);
94 : : private:
95 : : //No assignment
96 : : BookmarkPosition& operator=(const BookmarkPosition&);
97 : :
98 : : };
99 : :
100 [ # # ]: 0 : class SwxPosition : public SvxPosition
101 : : {
102 : : SwPaM* pPam;
103 : : public:
104 : 0 : SwxPosition( SwPaM* pCrsr ) : pPam( pCrsr ) {}
105 : :
106 : : virtual sal_uLong GetNodeIdx() const;
107 : : virtual xub_StrLen GetCntIdx() const;
108 : :
109 : : // erzeuge von sich selbst eine Kopie
110 : : virtual SvxPosition* Clone() const;
111 : : // erzeuge vom NodeIndex eine Kopie
112 : : virtual SvxNodeIdx* MakeNodeIdx() const;
113 : : };
114 : :
115 : :
116 : : // zum zwischenspeichern der Flys:
117 [ # # ][ # # ]: 0 : struct SwFlySave
118 : : {
119 : : SfxItemSet aFlySet;
120 : : SwNodeIndex nSttNd, nEndNd;
121 : : xub_StrLen nEndCnt;
122 : : SwTwips nPageWidth;
123 : : sal_uInt16 nDropLines, nDropAnchor;
124 : :
125 : : SwFlySave( const SwPaM& rPam, SfxItemSet& rSet );
126 : : int IsEqualFly( const SwPaM& rPos, SfxItemSet& rSet );
127 : : void SetFlySize( const SwTableNode& rTblNd );
128 : : };
129 : :
130 : : struct SwListEntry
131 : : {
132 : : long nListId, nListTemplateId, nListNo;
133 : : sal_uInt16 nListDocPos;
134 : : sal_Bool bRuleUsed;
135 : :
136 : 0 : SwListEntry()
137 : : : nListId( 0 ), nListTemplateId( 0 ), nListNo( 0 ), nListDocPos( 0 ),
138 : 0 : bRuleUsed( sal_False )
139 : 0 : {}
140 : 0 : SwListEntry( long nLstId, long nLstTmplId, sal_uInt16 nLstDocPos )
141 : : : nListId( nLstId ), nListTemplateId( nLstTmplId ), nListNo( 0 ),
142 : 0 : nListDocPos( nLstDocPos ), bRuleUsed( sal_False )
143 : 0 : {}
144 : :
145 : 0 : void Clear() { nListId = nListTemplateId = nListNo = 0, nListDocPos = 0;
146 : 0 : bRuleUsed = sal_False; }
147 : : };
148 : :
149 : : class SwFlySaveArr : public std::vector<SwFlySave*>
150 : : {
151 : : public:
152 : 0 : SwFlySaveArr() : ::std::vector<SwFlySave*>() {}
153 : 0 : SwFlySaveArr(const SwFlySaveArr& rOther)
154 : 0 : : ::std::vector<SwFlySave*>(rOther)
155 : 0 : {}
156 : :
157 : 0 : ~SwFlySaveArr()
158 : 0 : {
159 [ # # ][ # # ]: 0 : for(const_iterator it = begin(); it != end(); ++it)
[ # # ]
160 [ # # ][ # # ]: 0 : delete *it;
161 : 0 : }
162 : : };
163 : :
164 : : typedef std::deque< SwListEntry > SwListArr;
165 : :
166 : 0 : struct DocPageInformation
167 : : {
168 : : SvxBoxItem maBox;
169 : : long mnPaperw;
170 : : long mnPaperh;
171 : : long mnMargl;
172 : : long mnMargr;
173 : : long mnMargt;
174 : : long mnMargb;
175 : : long mnGutter;
176 : : long mnPgnStart;
177 : : bool mbFacingp;
178 : : bool mbLandscape;
179 : : bool mbRTLdoc;
180 : : DocPageInformation();
181 : : };
182 : :
183 [ # # ][ # # ]: 0 : struct SectPageInformation
184 : : {
185 : : std::vector<long> maColumns;
186 : : SvxBoxItem maBox;
187 : : SvxNumberType maNumType;
188 : : SwPageDesc *mpTitlePageHdFt;
189 : : SwPageDesc *mpPageHdFt;
190 : : long mnPgwsxn;
191 : : long mnPghsxn;
192 : : long mnMarglsxn;
193 : : long mnMargrsxn;
194 : : long mnMargtsxn;
195 : : long mnMargbsxn;
196 : : long mnGutterxsn;
197 : : long mnHeadery;
198 : : long mnFootery;
199 : : long mnPgnStarts;
200 : : long mnCols;
201 : : long mnColsx;
202 : : long mnStextflow;
203 : : int mnBkc;
204 : : bool mbLndscpsxn;
205 : : bool mbTitlepg;
206 : : bool mbFacpgsxn;
207 : : bool mbRTLsection;
208 : : bool mbPgnrestart;
209 : : bool mbTitlePageHdFtUsed;
210 : : bool mbPageHdFtUsed;
211 : : SectPageInformation(const DocPageInformation &rDoc);
212 : : SectPageInformation(const SectPageInformation &rSect);
213 : : };
214 : :
215 [ # # ][ # # ]: 0 : class rtfSection
216 : : {
217 : : public:
218 : : rtfSection(const SwPosition &rPos,
219 : : const SectPageInformation &rPageInfo);
220 : : SwNodeIndex maStart;
221 : : SectPageInformation maPageInfo;
222 : : SwSection *mpSection;
223 : : SwPageDesc *mpTitlePage;
224 : : SwPageDesc *mpPage;
225 : :
226 : 0 : bool IsContinous() const { return maPageInfo.mnBkc == 0; }
227 : 0 : long NoCols() const { return maPageInfo.mnCols; }
228 : 0 : long StandardColSeperation() const { return maPageInfo.mnColsx; }
229 : 0 : bool HasTitlePage() const { return maPageInfo.mbTitlepg; }
230 : 0 : long PageStartAt() const { return maPageInfo.mnPgnStarts; }
231 : 0 : bool PageRestartNo() const { return maPageInfo.mbPgnrestart; }
232 : 0 : bool IsBiDi() const { return maPageInfo.mbRTLsection; }
233 : 0 : long GetPageWidth() const { return maPageInfo.mnPgwsxn; }
234 : 0 : long GetPageHeight() const { return maPageInfo.mnPghsxn; }
235 : 0 : long GetPageLeft() const { return maPageInfo.mnMarglsxn; }
236 : 0 : long GetPageRight() const { return maPageInfo.mnMargrsxn; }
237 : 0 : bool IsLandScape() const { return maPageInfo.mbLndscpsxn; }
238 : : };
239 : :
240 : 0 : class rtfSections
241 : : {
242 : : private:
243 : : SwRTFParser &mrReader;
244 : : std::deque<rtfSection> maSegments;
245 : : typedef std::deque<rtfSection>::iterator mySegIter;
246 : : typedef std::deque<rtfSection>::reverse_iterator mySegrIter;
247 : :
248 : : struct wwULSpaceData
249 : : {
250 : : bool bHasHeader, bHasFooter;
251 : : short nSwHLo, nHdUL, nSwFUp, nFtUL, nSwUp, nSwLo;
252 : 0 : wwULSpaceData() : bHasHeader(false), bHasFooter(false), nSwHLo(0), nHdUL(0), nSwFUp(0), nFtUL(0), nSwUp(0), nSwLo(0) {}
253 : : };
254 : :
255 : : void SetSegmentToPageDesc(const rtfSection &rSection, bool bTitlePage,
256 : : bool bIgnoreCols);
257 : : SwSectionFmt *InsertSection(SwPaM& rMyPaM, rtfSection &rSection);
258 : : void SetPage(SwPageDesc &rInPageDesc, SwFrmFmt &rFmt,
259 : : const rtfSection &rSection, bool bIgnoreCols);
260 : : void GetPageULData(const rtfSection &rSection, bool bFirst,
261 : : wwULSpaceData& rData);
262 : : void SetPageULSpaceItems(SwFrmFmt &rFmt, wwULSpaceData& rData);
263 : : bool SetCols(SwFrmFmt &rFmt, const rtfSection &rSection,
264 : : sal_uInt16 nNettoWidth);
265 : : void SetHdFt(rtfSection &rSection);
266 : : void CopyFrom(const SwPageDesc &rFrom, SwPageDesc &rDest);
267 : : void MoveFrom(SwPageDesc &rFrom, SwPageDesc &rDest);
268 : : public:
269 : 0 : bool empty() const { return maSegments.empty(); }
270 : 0 : int size() const { return maSegments.size(); }
271 : : void push_back(const rtfSection &rSect);
272 : 0 : void pop_back() { maSegments.pop_back(); }
273 : 0 : rtfSection& back() { return maSegments.back(); }
274 : : const rtfSection& back() const { return maSegments.back(); }
275 : : void InsertSegments(bool bIsNewDoc);
276 [ # # ]: 0 : rtfSections(SwRTFParser &rReader) : mrReader(rReader) {}
277 : : std::vector<sal_uInt16> maDummyPageNos;
278 : : typedef std::vector<sal_uInt16>::reverse_iterator myrDummyIter;
279 : : void PrependedInlineNode(const SwPosition &rPos,
280 : : const SwNode &rNode);
281 : : };
282 : :
283 : :
284 : :
285 : :
286 : : class SwRTFParser : public SvxRTFParser
287 : : {
288 : : /*
289 : : Knows which writer style a given word style should be imported as.
290 : : */
291 : : sw::util::ParaStyleMapper maParaStyleMapper;
292 : : sw::util::CharStyleMapper maCharStyleMapper;
293 : :
294 : : std::vector<String> aRevTbl;
295 : :
296 : : friend class rtfSections;
297 : : DocPageInformation maPageDefaults;
298 : : rtfSections maSegments;
299 : :
300 : : sw::util::InsertedTablesManager maInsertedTables;
301 : : std::map<sal_Int32,SwTxtFmtColl*> aTxtCollTbl;
302 : : std::map<sal_Int32,SwCharFmt*> aCharFmtTbl;
303 : : SwFlySaveArr aFlyArr; // Flys als Letzes im Doc setzen
304 : : std::vector<bool> aMergeBoxes; // Flags fuer gemergte Zellen
305 : : SwListArr aListArr;
306 : : std::vector<SwCharFmt*> aRubyCharFmts;
307 : : BookmarkPosition* mpBookmarkStart;
308 : : sw::util::RedlineStack *mpRedlineStack;
309 : : sw::util::AuthorInfos m_aAuthorInfos;
310 : :
311 : : SfxItemSet* pGrfAttrSet;
312 : : SwTableNode* pTableNode, *pOldTblNd; // fuers Lesen von Tabellen: akt. Tab
313 : : SwNodeIndex* pSttNdIdx;
314 : : SwNodeIndex* pRegionEndIdx;
315 : : SwDoc* pDoc;
316 : : SwPaM* pPam; // SwPosition duerfte doch reichen, oder ??
317 : : SwRelNumRuleSpaces* pRelNumRule; // Liste aller benannten NumRules
318 : :
319 : : String sNestedFieldStr;
320 : : SwFltRedline *pRedlineInsert;
321 : : SwFltRedline *pRedlineDelete;
322 : :
323 : : String sBaseURL;
324 : :
325 : : sal_uInt16 nAktPageDesc, nAktFirstPageDesc;
326 : : sal_uInt16 m_nCurrentBox;
327 : : sal_uInt16 nInsTblRow; // beim nach \row kein \pard -> neue Line anlegen
328 : : sal_uInt16 nNewNumSectDef; // jeder SectionWechsel kann neue Rules definieren
329 : : sal_uInt16 nRowsToRepeat;
330 : :
331 : : bool bSwPageDesc;
332 : : bool bReadSwFly; // lese Swg-Fly (wichtig fuer Bitmaps!)
333 : : bool mbReadCellWhileReadSwFly; // #i83368#
334 : : bool mbReadNoTbl; // verhinder Tabelle in Tabelle/FootNote
335 : : bool mbIsFootnote;
336 : : bool bFootnoteAutoNum; // automatische Numerierung ?
337 : : bool bStyleTabValid; // Styles schon erzeugt ?
338 : : bool bInPgDscTbl; // beim PageDescTbl lesen
339 : : bool bNewNumList; // Word 7.0 NumList gelesen, 6.0 ueberspringen
340 : : bool bFirstContinue; // 1.Call ins Continue
341 : : bool bContainsPara; // If there is no paragraph in the section
342 : : bool bContainsTablePara; // If there is an table in this section
343 : : bool bForceNewTable; // Forces a beginning of a new table
344 : : bool bNestedField;
345 : : bool bTrowdRead; // True, iff an \trowd definition was read after the last \row
346 : :
347 : : int nReadFlyDepth;
348 : :
349 : : int nZOrder;
350 : : /*
351 : : #i9243#
352 : : In a footnote tables are not possible (for some obscure reason!)
353 : : */
354 [ # # ][ # # ]: 0 : bool CantUseTables() const { return mbReadNoTbl || mbIsFootnote; }
355 : :
356 : : virtual void InsertPara();
357 : : virtual void InsertText();
358 : : virtual void MovePos( int bForward = sal_True );
359 : : virtual void SetEndPrevPara( SvxNodeIdx*& rpNodePos, xub_StrLen& rCntPos );
360 : : void EnterEnvironment();
361 : : void LeaveEnvironment();
362 : :
363 : : SwFmtPageDesc* GetCurrentPageDesc(SwPaM *pPam);
364 : : void CheckInsNewTblLine();
365 : :
366 : : // setze RTF-Werte auf Swg-Werte
367 : : void SetSwgValues( SfxItemSet& rSet );
368 : :
369 : : virtual void ReadInfo( const sal_Char* pChkForVerNo = 0 );
370 : :
371 : : void ReadUserProperties();
372 : :
373 : : void ReadListLevel( SwNumRule& rRule, sal_uInt8 nLvl );
374 : : void SetBorderLine(SvxBoxItem& rBox, sal_uInt16 nLine);
375 : : void ReadListTable();
376 : : sal_uInt16 ReadRevTbl();
377 : : void ReadShpRslt();
378 : : void ReadShpTxt(String &shpTxt);
379 : : void ReadDrawingObject();
380 : : void InsertShpObject(SdrObject* pStroke, int nZOrder);
381 : : void ReadShapeObject();
382 : : void ReadListOverrideTable();
383 : : SwNumRule *ReadNumSecLevel( int nToken );
384 : : SwNumRule* GetNumRuleOfListNo( long nListNo,
385 : : sal_Bool bRemoveFromList = sal_False );
386 : : void RemoveUnusedNumRule( SwNumRule* );
387 : : void RemoveUnusedNumRules();
388 : : const Font* FindFontOfItem( const SvxFontItem& rItem ) const;
389 : :
390 : : // 3 Methoden zum Aufbauen der Styles
391 : : SwTxtFmtColl* MakeColl( const String&, sal_uInt16 nPos, sal_uInt8 nOutlineLevel,
392 : : bool& rbCollExist );
393 : : SwCharFmt* MakeCharFmt( const String& rName, sal_uInt16 nPos,
394 : : int& rbCollExist );
395 : : void SetStyleAttr( SfxItemSet& rCollSet,
396 : : const SfxItemSet& rStyleSet,
397 : : const SfxItemSet& rDerivedSet );
398 : : SwTxtFmtColl* MakeStyle( sal_uInt16 nNo, const SvxRTFStyleType& rStyle );
399 : : SwCharFmt* MakeCharStyle( sal_uInt16 nNo, const SvxRTFStyleType& rStyle );
400 : : void MakeStyleTab();
401 : :
402 : : int MakeFieldInst( String& rFieldStr );
403 : :
404 : : // einlesen/einfuegen von Bitmaps
405 : : void InsPicture( const String& rNm,
406 : : const Graphic* = 0, const SvxRTFPictureType* = 0 );
407 : : void _SetPictureSize( const SwNoTxtNode& rNd, const SwNodeIndex& rAnchor,
408 : : SfxItemSet& rSet, const SvxRTFPictureType* = 0 );
409 : :
410 : : void SetFlysInDoc();
411 : : void GetPageSize( Size& rSize ); // Groesse der PagePrintArea
412 : :
413 : : // fuers Einlesen von Tabellen
414 : : void GotoNextBox();
415 : : void NewTblLine();
416 : :
417 : : void DelLastNode(); // loesche den letzten Node (Tabelle/Fly/Ftn/..)
418 : :
419 : : void AddNumRule( SwNumRule* pRule );
420 : : void SetNumRelSpaces();
421 : : void SetOultineRelSpaces( const SwNodeIndex& rStt,
422 : : const SwNodeIndex& rEnd );
423 : : void SetNumLSpace( SwTxtNode& rNd, const SwNodeNum& rNum,
424 : : const SwNumRule& rRule );
425 : : long GetSafePos(long nPos);
426 : :
427 : : protected:
428 : : // wird fuer jedes Token gerufen, das in CallParser erkannt wird
429 : : virtual void NextToken( int nToken );
430 : :
431 : : // virtual void ReadUnknownData();
432 : : virtual void ReadBitmapData();
433 : : #ifdef READ_OLE_OBJECT
434 : : virtual void ReadOLEData();
435 : : #endif
436 : : virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
437 : : virtual bool UncompressableStackEntry(const SvxRTFItemStackType &rSet) const;
438 : : // fuer Tokens, die im ReadAttr nicht ausgewertet werden
439 : : virtual void UnknownAttrToken( int nToken, SfxItemSet* pSet );
440 : :
441 : : void ReadPrtData();
442 : : void ReadField();
443 : : void ReadXEField();
444 : : void ReadHeaderFooter( int nToken, SwPageDesc* pPageDesc = 0 );
445 : : void ReadDocControls( int nToken );
446 : : void SetPageInformationAsDefault(const DocPageInformation &rInfo);
447 : : void ReadSectControls( int nToken );
448 : : void DoHairyWriterPageDesc(int nToken);
449 : : void ReadFly( int nToken, SfxItemSet* pFillSet = 0 );
450 : : void ReadTable( int nToken );
451 : : void ReadPageDescTbl();
452 : : void SkipPageDescTbl();
453 : : bool IsBorderToken(int nToken);
454 : :
455 : 0 : const String& GetBaseURL() const { return sBaseURL;}
456 : :
457 : : virtual ~SwRTFParser();
458 : :
459 : : public:
460 : : SwRTFParser( SwDoc* pD,
461 : : ::com::sun::star::uno::Reference<
462 : : ::com::sun::star::document::XDocumentProperties> i_xDocProps,
463 : : const SwPaM& rCrsr, SvStream& rIn,
464 : : const String& rBaseURL,
465 : : int bReadNewDoc = sal_True );
466 : :
467 : : virtual SvParserState CallParser(); // Aufruf des Parsers
468 : : virtual int IsEndPara( SvxNodeIdx* pNd, xub_StrLen nCnt ) const;
469 : :
470 : : // fuers asynchrone lesen aus dem SvStream
471 : : // virtual void SaveState( int nToken );
472 : : // virtual void RestoreState();
473 : : virtual void Continue( int nToken );
474 : : };
475 : :
476 : :
477 : : #endif
478 : :
479 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|