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