xref: /trunk/main/sw/source/filter/ww8/wrtww8.hxx (revision cea84f56765a2ac06f0f5a2718f45f6430edc781) !
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 _WRTWW8_HXX
25 #define _WRTWW8_HXX
26 
27 #include <tools/solar.h>        // UINTXX
28 #include <tools/gen.hxx>
29 #ifndef _SVSTDARR_HXX
30 #define _SVSTDARR_ULONGS
31 #include <svl/svstdarr.hxx>
32 #endif
33 #include <editeng/editdata.hxx>
34 
35 #include <map>
36 #include <vector>
37 
38 #include <shellio.hxx>
39 #include <wrt_fn.hxx>
40 #include <filter/msfilter/msocximex.hxx>
41 
42 #include "ww8struc.hxx"
43 #include "ww8scan.hxx"
44 #include "fields.hxx"
45 #include "types.hxx"
46 #include "writerhelper.hxx"
47 #include "../inc/msfilter.hxx"
48 #include <expfld.hxx>
49 
50 #include <vcl/graph.hxx>
51 class SvxBrushItem;
52 
53 // einige Forward Deklarationen
54 namespace msfilter
55 {
56     class MSCodec_Std97;
57 }
58 
59 class WW8SwAttrIter;
60 class AttributeOutputBase;
61 class DocxAttributeOutput;
62 class RtfAttributeOutput;
63 class BitmapPalette;
64 class SwEscherEx;
65 class DateTime;
66 class Font;
67 class MSWordExportBase;
68 class SdrObject;
69 class SfxItemSet;
70 class SvStream;
71 class SvxBorderLine;
72 class SvxFontItem;
73 class SvxBoxItem;
74 class SwAttrSet;
75 class SwCharFmt;
76 class SwCntntNode;
77 class SwField;
78 class SwFmt;
79 class SwFmtCntnt;
80 class SwFmtFtn;
81 class SwFrmFmt;
82 class SwGrfNode;
83 class SwModify;
84 class SwNumFmt;
85 class SwNumRule;
86 class SwNumRuleTbl;
87 class SwPageDesc;
88 class SwFmtPageDesc;
89 class SwOLENode;
90 class SwPostItField;
91 class SwRedlineData;
92 class SwSection;
93 class SwSectionFmt;
94 class SwSectionNode;
95 class SwTableNode;
96 class SwTOXType;
97 class SwTxtAttr;
98 class SwTxtFmtColl;
99 class SwTxtNode;
100 class SwWW8WrGrf;
101 class SwWW8Writer;
102 class MSWordStyles;
103 class WW8AttributeOutput;
104 class WW8Bytes;
105 class WW8Export;
106 class MSWordAttrIter;
107 class WW8_WrFkp;
108 class WW8_WrPlc0;
109 class WW8_WrPlc1;
110 class WW8_WrPlcFld;
111 class WW8_WrMagicTable;
112 class WW8_WrPlcFtnEdn;
113 class WW8_WrPlcPn;
114 class WW8_WrPlcAnnotations;
115 class MSWordSections;
116 class WW8_WrPlcTxtBoxes;
117 class WW8_WrPct;            // Verwaltung
118 class WW8_WrPcPtrs;
119 class WW8_WrtBookmarks;
120 class WW8_WrtRedlineAuthor;
121 class SvxMSExportOLEObjects;
122 class SwMSConvertControls;
123 class WW8OleMaps;
124 class SvStorageRef;
125 struct WW8_PdAttrDesc;
126 class SvxBrushItem;
127 
128 #include "WW8TableInfo.hxx"
129 
130 #define GRF_MAGIC_1 0x12    // 3 magic Bytes fuer PicLocFc-Attribute
131 #define GRF_MAGIC_2 0x34
132 #define GRF_MAGIC_3 0x56
133 #define GRF_MAGIC_321 0x563412L
134 
135 #define OLE_PREVIEW_AS_EMF  //If we want to export ole2 previews as emf in ww8+
136 
137 typedef sal_uInt8 FieldFlags;
138 namespace nsFieldFlags // for InsertField- Method
139 {
140     const FieldFlags WRITEFIELD_START         = 0x01;
141     const FieldFlags WRITEFIELD_CMD_START     = 0x02;
142     const FieldFlags WRITEFIELD_CMD_END     = 0x04;
143     const FieldFlags WRITEFIELD_END         = 0x10;
144     const FieldFlags WRITEFIELD_CLOSE         = 0x20;
145     const FieldFlags WRITEFIELD_ALL         = 0xFF;
146 }
147 
148 enum TxtTypes  //enums for TextTypes
149 {
150     TXT_MAINTEXT = 0, /*TXT_FTNEDN = 1,*/ TXT_HDFT = 2, TXT_FTN = 3,
151     TXT_EDN = 4, TXT_ATN = 5, TXT_TXTBOX = 6, TXT_HFTXTBOX= 7
152 };
153 
154 SV_DECL_VARARR( WW8Bytes, sal_uInt8, 128, 128 )
155 
156 struct WW8_SepInfo
157 {
158     const SwPageDesc* pPageDesc;
159     const SwSectionFmt* pSectionFmt;
160     const SwNode* pPDNd;
161     const SwTxtNode* pNumNd;
162     sal_uLong  nLnNumRestartNo;
163     sal_uInt16 nPgRestartNo;
164 
WW8_SepInfoWW8_SepInfo165     WW8_SepInfo()
166         : pPageDesc(0), pSectionFmt(0), pPDNd(0), pNumNd(0), nLnNumRestartNo(0), nPgRestartNo(0)
167 
168     {}
169 
WW8_SepInfoWW8_SepInfo170     WW8_SepInfo( const SwPageDesc* pPD, const SwSectionFmt* pFmt,
171         sal_uLong nLnRestart, sal_uInt16 nPgRestart = 0, const SwNode* pNd = NULL )
172         : pPageDesc( pPD ), pSectionFmt( pFmt ), pPDNd( pNd ), pNumNd( 0 ),
173           nLnNumRestartNo( nLnRestart ), nPgRestartNo( nPgRestart )
174     {}
175 
176     bool IsProtected() const;
177 };
178 
179 SV_DECL_VARARR( WW8_WrSepInfoPtrs, WW8_SepInfo, 4, 4 )
180 
181 /// Class to collect and output the sections/headers/footers.
182 // Plc fuer PageDescs -> Sepx ( Section Extensions )
183 class MSWordSections
184 {
185 protected:
186     bool mbDocumentIsProtected;
187     WW8_WrSepInfoPtrs aSects;   // PTRARR von SwPageDesc und SwSectionFmt
188 
189     void CheckForFacinPg( WW8Export& rWrt ) const;
190     void WriteOlst( WW8Export& rWrt, const WW8_SepInfo& rSectionInfo );
191     void NeedsDocumentProtected(const WW8_SepInfo &rInfo);
192 
193     //No copy, no assign
194     MSWordSections( const MSWordSections& );
195     MSWordSections& operator=( const MSWordSections& );
196 public:
197     MSWordSections( MSWordExportBase& rExport );
198     virtual ~MSWordSections();
199 
200     virtual bool HeaderFooterWritten();
201 
202     void AppendSection( const SwPageDesc* pPd,
203                     const SwSectionFmt* pSectionFmt = 0,
204                     sal_uLong nLnNumRestartNo = 0 );
205     void AppendSection( const SwFmtPageDesc& rPd,
206                     const SwNode& rNd,
207                     const SwSectionFmt* pSectionFmt,
208                     sal_uLong nLnNumRestartNo );
209     void SetNum( const SwTxtNode* pNumNd );
210 
211     /// Number of columns based on the most recent WW8_SepInfo.
212     sal_uInt16 CurrentNumberOfColumns( const SwDoc &rDoc ) const;
213 
214     /// Number of columns of the provided WW8_SepInfo.
215     sal_uInt16 NumberOfColumns( const SwDoc &rDoc, const WW8_SepInfo& rInfo ) const;
216 
DocumentIsProtected() const217     bool DocumentIsProtected() const { return mbDocumentIsProtected; }
218 
219     /// The most recent WW8_SepInfo.
220     const WW8_SepInfo* CurrentSectionInfo();
221 
222     static void SetHeaderFlag( sal_uInt8& rHeadFootFlags, const SwFmt& rFmt,
223                                   sal_uInt8 nFlag );
224     static void SetFooterFlag( sal_uInt8& rHeadFootFlags, const SwFmt& rFmt,
225                                    sal_uInt8 nFlag );
226 
227     /// Should we output borders?
228     static int HasBorderItem( const SwFmt& rFmt );
229 };
230 
231 class WW8_WrPlcSepx : public MSWordSections
232 {
233     SvULongs aCps;              // PTRARR von CPs
234     ::std::vector< ::boost::shared_ptr<WW8_PdAttrDesc> > m_SectionAttributes;
235     // HACK to prevent adding sections in endnotes
236     bool m_bHeaderFooterWritten;
237     WW8_WrPlc0* pTxtPos;        // Pos der einzelnen Header / Footer
238 
239     // No copy, no assign
240     WW8_WrPlcSepx( const WW8_WrPlcSepx& );
241     WW8_WrPlcSepx& operator=( const WW8_WrPlcSepx& );
242 
243 public:
244     WW8_WrPlcSepx( MSWordExportBase& rExport );
245     ~WW8_WrPlcSepx();
246 
247     virtual bool HeaderFooterWritten(); // override
248 
249     void AppendSep( WW8_CP nStartCp,
250                     const SwPageDesc* pPd,
251                     const SwSectionFmt* pSectionFmt = 0,
252                     sal_uLong nLnNumRestartNo = 0 );
253     void AppendSep( WW8_CP nStartCp, const SwFmtPageDesc& rPd,
254                     const SwNode& rNd,
255                     const SwSectionFmt* pSectionFmt,
256                     sal_uLong nLnNumRestartNo );
Finish(WW8_CP nEndCp)257     void Finish( WW8_CP nEndCp ) { aCps.Insert( nEndCp, aCps.Count() ); }
258 
259     bool WriteKFTxt( WW8Export& rWrt );
260     void WriteSepx( SvStream& rStrm ) const;
261     void WritePlcSed( WW8Export& rWrt ) const;
262     void WritePlcHdd( WW8Export& rWrt ) const;
263 
264 private:
265     void WriteFtnEndTxt( WW8Export& rWrt, sal_uLong nCpStt );
266 public:
267     void OutHeaderFooter(WW8Export& rWrt, bool bHeader,
268             const SwFmt& rFmt, sal_uLong& rCpPos, sal_uInt8 nHFFlags, sal_uInt8 nFlag,  sal_uInt8 nBreakCode);
269 };
270 
271 //--------------------------------------------------------------------------
272 // class WW8_WrPct zum Aufbau der Piece-Table
273 //--------------------------------------------------------------------------
274 class WW8_WrPct
275 {
276     WW8_WrPcPtrs* pPcts;
277     WW8_FC nOldFc;
278     bool bIsUni;
279 public:
280     WW8_WrPct(WW8_FC nStartFc, bool bSaveUniCode);
281     ~WW8_WrPct();
282     void AppendPc(WW8_FC nStartFc, bool bIsUnicode);
283     void WritePc( WW8Export& rWrt );
284     void SetParaBreak();
IsUnicode() const285     bool IsUnicode() const  { return bIsUni; }
286     WW8_CP Fc2Cp( sal_uLong nFc ) const;
287 };
288 
289 /// Collects and outputs fonts.
290 class wwFont
291 {
292 //In some future land the stream could be converted to a nice stream interface
293 //and we could have harmony
294 private:
295     sal_uInt8 maWW8_FFN[6];
296     String msFamilyNm;
297     String msAltNm;
298     bool mbAlt;
299     bool mbWrtWW8;
300     FontPitch mePitch;
301     FontFamily meFamily;
302     rtl_TextEncoding meChrSet;
303 public:
304     wwFont( const String &rFamilyName, FontPitch ePitch, FontFamily eFamily,
305         rtl_TextEncoding eChrSet, bool bWrtWW8 );
306     bool Write( SvStream *pTableStram ) const;
307 #ifdef DOCX
308     void WriteDocx( const DocxAttributeOutput* rAttrOutput ) const;
309 #endif
310     void WriteRtf( const RtfAttributeOutput* rAttrOutput ) const;
GetFamilyName() const311     rtl::OUString GetFamilyName() const { return rtl::OUString( msFamilyNm ); }
312     friend bool operator < (const wwFont &r1, const wwFont &r2);
313 };
314 
315 class wwFontHelper
316 {
317 private:
318     /// Keep track of fonts that need to be exported.
319     ::std::map<wwFont, sal_uInt16> maFonts;
320     bool mbWrtWW8;
321 
322     /// Convert from fast insertion map to linear vector in the order that we want to write.
323     ::std::vector< const wwFont* > AsVector() const;
324 
325 public:
wwFontHelper()326     wwFontHelper() : mbWrtWW8(false), bLoadAllFonts(false) {}
327     /// rDoc used only to get the initial standard font(s) in use.
328     void InitFontTable(bool bWrtWW8, const SwDoc& rDoc);
329     sal_uInt16 GetId(const Font& rFont);
330     sal_uInt16 GetId(const SvxFontItem& rFont);
331     sal_uInt16 GetId(const wwFont& rFont);
332     void WriteFontTable( SvStream *pTableStream, WW8Fib& pFib );
333 #ifdef DOCX
334     void WriteFontTable( const DocxAttributeOutput& rAttrOutput );
335 #endif
336     void WriteFontTable( const RtfAttributeOutput& rAttrOutput );
337 
338     /// If true, all fonts are loaded before processing the document.
339     sal_uInt8 bLoadAllFonts: 1;
340 };
341 
342 class DrawObj
343 {
344 public:
345     WW8_CP mnCp;                // CP-Pos der Verweise
346     sal_uInt32 mnShapeId;           // ShapeId for the SwFrmFmts
347     sw::Frame maCntnt;          // the frame itself
348     Point maParentPos;          // Points
349     sal_Int32 mnThick;              // Border Thicknesses
350     short mnDirection;          // If BiDi or not
351     unsigned int mnHdFtIndex;   // 0 for main text, +1 for each subsequent
352                                 // msword hd/ft
353 
DrawObj(const sw::Frame & rCntnt,WW8_CP nCp,Point aParentPos,short nDir,unsigned int nHdFtIndex)354     DrawObj(const sw::Frame &rCntnt, WW8_CP nCp, Point aParentPos, short nDir,
355             unsigned int nHdFtIndex)
356         : mnCp(nCp), mnShapeId(0), maCntnt(rCntnt), maParentPos(aParentPos),
357         mnThick(0), mnDirection(nDir), mnHdFtIndex(nHdFtIndex) {}
358     void SetShapeDetails(sal_uInt32 nId, sal_Int32 nThick);
359     DrawObj& operator=(const DrawObj &rOther);
360     DrawObj(const DrawObj&) = default;
361 };
362 
363 typedef std::vector<DrawObj> DrawObjVector;
364 typedef DrawObjVector::iterator DrawObjIter;
365 typedef DrawObjVector::const_iterator cDrawObjIter;
366 
367 typedef std::vector<DrawObj *> DrawObjPointerVector;
368 typedef DrawObjPointerVector::iterator DrawObjPointerIter;
369 
370 class PlcDrawObj // PC for DrawObjects and Text-/OLE-/GRF-Boxes
371 {
372 private:
373     DrawObjVector maDrawObjs;  // vector of drawobjs
374 protected:
375     virtual void RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
376         sal_uInt32 nLen) const = 0;
377     virtual WW8_CP GetCpOffset(const WW8Fib &rFib) const = 0;
378 public:
PlcDrawObj()379     PlcDrawObj() {}
380     void WritePlc( WW8Export& rWrt ) const;
381     bool Append( WW8Export&, WW8_CP nCp, const sw::Frame& rFmt,
382         const Point& rNdTopLeft );
size()383     int size() { return maDrawObjs.size(); };
GetObjArr()384     DrawObjVector &GetObjArr() { return maDrawObjs; }
385     virtual ~PlcDrawObj();
386 private:
387     //No copying
388     PlcDrawObj(const PlcDrawObj&);
389     PlcDrawObj& operator=(const PlcDrawObj&);
390 };
391 
392 class MainTxtPlcDrawObj : public PlcDrawObj
393 {
394 public:
MainTxtPlcDrawObj()395     MainTxtPlcDrawObj() {}
396 private:
397     virtual void RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
398         sal_uInt32 nLen) const;
399     virtual WW8_CP GetCpOffset(const WW8Fib &) const;
400 private:
401     //No copying
402     MainTxtPlcDrawObj(const MainTxtPlcDrawObj&);
403     MainTxtPlcDrawObj& operator=(const MainTxtPlcDrawObj&);
404 };
405 
406 class HdFtPlcDrawObj : public PlcDrawObj
407 {
408 public:
HdFtPlcDrawObj()409     HdFtPlcDrawObj() {}
410 private:
411     virtual void RegisterWithFib(WW8Fib &rFib, sal_uInt32 nStart,
412         sal_uInt32 nLen) const;
413     virtual WW8_CP GetCpOffset(const WW8Fib &rFib) const;
414 private:
415     //No copying
416     HdFtPlcDrawObj(const HdFtPlcDrawObj&);
417     HdFtPlcDrawObj& operator=(const HdFtPlcDrawObj&);
418 };
419 
420 typedef ::std::pair<String, sal_uLong> aPair;
421 typedef std::vector<aPair> SwImplBookmarks;
422 typedef std::vector<aPair>::iterator SwImplBookmarksIter;
423 
424 class WW8_WrtRedlineAuthor : public sw::util::WrtRedlineAuthor
425 {
426     public:
427     virtual void Write(Writer &rWrt);
428 };
429 
430 /** Structure that is used to save some of the WW8Export/DocxExport data.
431 
432     It is used to be able to recurse inside of the WW8Export/DocxExport (eg.
433     for the needs of the tables) - you need to tall WriteText() from there with
434     new values of PaM etc.
435 
436     It must contain all the stuff that might be saved either in WW8Export or in
437     DocxExport, because it makes no sense to do it abstract, and specialize it
438     for each of the cases.  If you implement other *Export, just add the needed
439     members here, and store them in the appropriate SaveData() method.
440  */
441 struct MSWordSaveData
442 {
443     Point* pOldFlyOffset;
444     RndStdIds eOldAnchorType;
445     WW8Bytes* pOOld;                ///< WW8Export only
446     WW8Bytes* mpTableAtOld;         ///< WW8Export only: Additional buffer for the output of the tables
447     sal_uInt16 mnTableStdAtLenOld;  ///< WW8Export only: Standard length of mpTableAt
448     SwPaM* pOldPam, *pOldEnd;
449     const sw::Frame* pOldFlyFmt;
450     const SwPageDesc* pOldPageDesc;
451 
452     sal_uInt8 bOldWriteAll : 1;          ///< WW8Export only
453     sal_uInt8 bOldOutTable : 1;
454     sal_uInt8 bOldIsInTable: 1;
455     sal_uInt8 bOldFlyFrmAttrs : 1;
456     sal_uInt8 bOldStartTOX : 1;
457     sal_uInt8 bOldInWriteTOX : 1;
458     // bOutPageDesc muss nicht gesichert werden, da es nur nicht waehrend der
459     // Ausgabe von Spezial-Texten veraendert wird.
460 };
461 
462 /// Base class for WW8Export and DocxExport
463 class MSWordExportBase
464 {
465 public:
466     wwFontHelper maFontHelper;
467     std::vector<sal_uLong> maChapterFieldLocs;
468     typedef std::vector<sal_uLong>::const_iterator mycCFIter;
469     String aMainStg;
470     SvPtrarr aTOXArr;
471     const SfxItemSet* pISet;    // fuer Doppel-Attribute
472     WW8_WrPct*  pPiece;         // Pointer auf Piece-Table
473     SwNumRuleTbl* pUsedNumTbl;  // alle used NumRules
474     const SwTxtNode *mpTopNodeOfHdFtPage; ///< Top node of host page when in hd/ft
475     std::map< sal_uInt16, sal_uInt16 > aRuleDuplicates; //map to Duplicated numrules
476     std::stack< xub_StrLen > m_aCurrentCharPropStarts; ///< To remember the position in a run.
477     WW8_WrtBookmarks* pBkmks;
478     WW8_WrtRedlineAuthor* pRedlAuthors;
479     BitmapPalette* pBmpPal;
480     boost::shared_ptr<NfKeywordTable> pKeyMap;
481     SvxMSExportOLEObjects* pOLEExp;
482     SwMSConvertControls* pOCXExp;
483     WW8OleMaps* pOleMap;
484     ww8::WW8TableInfo::Pointer_t mpTableInfo;
485 
486     sal_uInt16 nCharFmtStart;
487     sal_uInt16 nFmtCollStart;
488     sal_uInt16 nStyleBeforeFly;     ///< Style-Nummer des Nodes,
489                                 ///<       in/an dem ein Fly verankert ist
490     sal_uInt16 nLastFmtId;          ///< Style of last TxtNode in normal range
491     sal_uInt16 nUniqueList;         ///< current number for creating unique list names
492     unsigned int mnHdFtIndex;
493 
494     sal_uInt16 mnRedlineMode;       ///< Remember the original redline mode
495 
496 public:
497     /* implicit bookmark vector containing pairs of node indexes and bookmark names */
498     SwImplBookmarks maImplicitBookmarks;
499     sw::Frames maFrames;             // The floating frames in this document
500     const SwPageDesc *pAktPageDesc;
501     WW8_WrPlcPn* pPapPlc;
502     WW8_WrPlcPn* pChpPlc;
503     MSWordAttrIter* pChpIter;
504     MSWordStyles* pStyles;
505     WW8_WrPlcAnnotations* pAtn;
506     WW8_WrPlcTxtBoxes *pTxtBxs, *pHFTxtBxs;
507 
508     const sw::Frame *mpParentFrame; //If set we are exporting content inside
509                                     //a frame, e.g. a graphic node
510 
511     Point* pFlyOffset;              // zur Justierung eines im Writer als
512     RndStdIds eNewAnchorType;       // Zeichen gebundenen Flys, der im WW
513                                     // Absatzgebunden wird.
514 
515     WW8_WrPlcFld* pFldMain;         // Felder im Haupttext
516     WW8_WrPlcFld* pFldHdFt;         // Felder in Header/Footer
517     WW8_WrPlcFld* pFldFtn;          // Felder in FootNotes
518     WW8_WrPlcFld* pFldEdn;          // Felder in EndNotes
519     WW8_WrPlcFld* pFldAtn;          // Felder in Annotations
520     WW8_WrPlcFld* pFldTxtBxs;       // fields in textboxes
521     WW8_WrPlcFld* pFldHFTxtBxs;     // fields in header/footer textboxes
522     WW8_WrMagicTable *pMagicTable;  // keeps track of table cell positions, and
523                                     // marks those that contain graphics,
524                                     // which is required to make word display
525                                     // graphics inside tables
526     SwWW8WrGrf* pGrf;
527     const SwAttrSet* pStyAttr;      // StyleAttr fuer Tabulatoren
528     const SwModify* pOutFmtNode;    // write Format or Node
529     const SwFmt *pCurrentStyle;     // iff bStyDef=true, then this store the current style
530 
531     MainTxtPlcDrawObj *pSdrObjs;   // Draw-/Fly-Objects
532     HdFtPlcDrawObj *pHFSdrObjs;     // Draw-/Fly-Objects in header or footer
533 
534     SwEscherEx* pEscher;            // escher export class
535     // --> OD 2007-04-19 #i43447# - removed
536 //    SwTwips nFlyWidth, nFlyHeight;  // Fuer Anpassung Graphic
537     // <--
538 
539     sal_uInt8 nTxtTyp;
540 
541     sal_uInt8 bStyDef : 1;           // wird Style geschrieben ?
542     sal_uInt8 bBreakBefore : 1;      // Breaks werden 2mal ausgegeben
543     sal_uInt8 bOutKF : 1;            // Kopf/Fusstexte werden ausgegeben
544     sal_uInt8 bOutFlyFrmAttrs : 1;   // Rahmen-Attr von Flys werden ausgegeben
545     sal_uInt8 bOutPageDescs : 1;     ///< PageDescs (section properties) are being written
546     sal_uInt8 bOutFirstPage : 1;     // write Attrset of FirstPageDesc
547     sal_uInt8 bOutTable : 1;         // Tabelle wird ausgegeben
548                                 //    ( wird zB bei Flys in Tabelle zurueckgesetzt )
549     sal_uInt8 bOutGrf : 1;           // Grafik wird ausgegeben
550     sal_uInt8 bInWriteEscher : 1;    // in write textboxes
551     sal_uInt8 bStartTOX : 1;         // true: a TOX is startet
552     sal_uInt8 bInWriteTOX : 1;       // true: all content are in a TOX
553     sal_uInt8 bFtnAtTxtEnd : 1;      // true: all FTN at Textend
554     sal_uInt8 bEndAtTxtEnd : 1;      // true: all END at Textend
555     sal_uInt8 bHasHdr : 1;
556     sal_uInt8 bHasFtr : 1;
557     sal_uInt8 bSubstituteBullets : 1; // true: SubstituteBullet() gets called
558 
559     bool mbExportModeRTF;
560     bool mbOutOutlineOnly;   // export outline nodes, only (send outline to clipboard/presentation)
561 
562     SwDoc *pDoc;
563     SwPaM *pCurPam, *pOrigPam;
564 
565     /// Stack to remember the nesting (see MSWordSaveData for more)
566     ::std::stack< MSWordSaveData > maSaveData;
567 
568     /// Used to split the runs according to the bookmarks start and ends
569     typedef std::vector< ::sw::mark::IMark* > IMarkVector;
570     IMarkVector m_rSortedMarksStart;
571     IMarkVector m_rSortedMarksEnd;
572 
573 public:
574     /// The main function to export the document.
575     void ExportDocument( bool bWriteAll );
576 
577     /// Iterate through the nodes and call the appropriate OutputNode() on them.
578     void WriteText();
579 
580     /// Return whether currently exported node is in table.
581     bool IsInTable() const;
582 
583     /// Set the pCurPam appropriately and call WriteText().
584     ///
585     /// Used to export paragraphs in footnotes/endnotes/etc.
586     void WriteSpecialText( sal_uLong nStart, sal_uLong nEnd, sal_uInt8 nTTyp );
587 
588     /// Export the pool items to attributes (through an attribute output class).
589     void ExportPoolItemsToCHP( sw::PoolItems &rItems, sal_uInt16 nScript );
590 
591     /// Return the numeric id of the numbering rule
592     sal_uInt16 GetId( const SwNumRule& rNumRule );
593 
594     /// Return the numeric id of the style.
595     sal_uInt16 GetId( const SwTxtFmtColl& rColl ) const;
596 
597     /// Return the numeric id of the style.
598     sal_uInt16 GetId( const SwCharFmt& rFmt ) const;
599 
600     sal_uInt16 GetId( const SwTOXType& rTOXType );
601 
602     const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const;
603 
604     /// Find the reference.
605     bool HasRefToObject( sal_uInt16 nTyp, const String* pName, sal_uInt16 nSeqNo );
606 
607     /// Find the bookmark name.
608     String GetBookmarkName( sal_uInt16 nTyp, const String* pName, sal_uInt16 nSeqNo );
609 
610     /// Add a bookmark converted to a Word name.
611     void AppendWordBookmark( const String& rName );
612 
613     /// Use OutputItem() on an item set according to the parameters.
614     void OutputItemSet( const SfxItemSet& rSet, bool bPapFmt, bool bChpFmt, sal_uInt16 nScript, bool bExportParentItemSet );
615 
616     short GetDefaultFrameDirection( ) const;
617 
618     /// Right to left?
619     short TrueFrameDirection( const SwFrmFmt& rFlyFmt ) const;
620 
621     /// Right to left?
622     short GetCurrentPageDirection() const;
623 
624     /// In case of numbering restart.
625 
626     /// List is set to restart at a particular value so for export make a
627     /// completely new list based on this one and export that instead,
628     /// which duplicates words behaviour in this respect.
629     sal_uInt16 DuplicateNumRule( const SwNumRule *pRule, sal_uInt8 nLevel, sal_uInt16 nVal );
630 
631     /// Access to the attribute output class.
632     virtual AttributeOutputBase& AttrOutput() const = 0;
633 
634     /// Access to the sections/headers/footres.
635     virtual MSWordSections& Sections() const = 0;
636 
637     /// Hack, unfortunately necessary at some places for now.
638     /// FIXME remove it when possible.
639     virtual bool HackIsWW8OrHigher() const = 0;
640 
641     /// Guess the script (asian/western).
642     ///
643     /// Sadly word does not have two different sizes for asian font size and
644     /// western font size, it has two different fonts, but not sizes, so we
645     /// have to use our guess as to the script used and disable the export of
646     /// one type. The same occurs for font weight and posture (bold and
647     /// italic).
648     ///
649     /// In addition WW7- has only one character language identifier while WW8+
650     /// has two
651     virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich ) = 0;
652 
653     virtual void AppendBookmarks( const SwTxtNode& rNd, xub_StrLen nAktPos, xub_StrLen nLen ) = 0;
654 
655     virtual void AppendBookmark( const rtl::OUString& rName, bool bSkip = false ) = 0;
656     //For i120928,add this interface to export graphic of bullet
657     virtual void ExportGrfBullet(const SwTxtNode& rNd) = 0;
658 
659     // FIXME probably a hack...
660     virtual void WriteCR( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t() ) = 0;
661 
662     // FIXME definitely a hack, must not be here - it can't do anything
663     // sensible for docx
664     virtual void WriteChar( sal_Unicode c ) = 0;
665 
666     /// Output attributes.
667     void OutputFormat( const SwFmt& rFmt, bool bPapFmt, bool bChpFmt, bool bFlyFmt = false );
668 
669     /// Getter for pISet.
GetCurItemSet() const670     const SfxItemSet* GetCurItemSet() const { return pISet; }
671 
672     /// Setter for pISet.
SetCurItemSet(const SfxItemSet * pS)673     void SetCurItemSet( const SfxItemSet* pS ) { pISet = pS; }
674 
675     /// Remember some of the members so that we can recurse in WriteText().
676     virtual void SaveData( sal_uLong nStt, sal_uLong nEnd );
677 
678     /// Restore what was saved in SaveData().
679     virtual void RestoreData();
680 
681     /// The return value indicates, if a follow page desc is written.
682     bool OutputFollowPageDesc( const SfxItemSet* pSet,
683                                const SwTxtNode* pNd );
684 
685     /// Write header/footer text.
686     void WriteHeaderFooterText( const SwFmt& rFmt, bool bHeader);
687 
688     /// Format of the section.
689     const SwSectionFmt* GetSectionFormat( const SwNode& rNd ) const;
690 
691     /// Line number of the section start.
692     sal_uLong GetSectionLineNo( const SfxItemSet* pSet, const SwNode& rNd ) const;
693 
694     /// Start new section.
695     void OutputSectionBreaks( const SfxItemSet *pSet, const SwNode& rNd );
696 
697     /// Write section properties.
698     ///
699     /// pA is ignored for docx.
700     void SectionProperties( const WW8_SepInfo& rSectionInfo, WW8_PdAttrDesc* pA = NULL );
701 
702     /// Output the numbering table.
703     virtual void WriteNumbering() = 0;
704 
705     /// Write static data of SwNumRule - LSTF
706     void NumberingDefinitions();
707 
708     /// Write all Levels for all SwNumRules - LVLF
709     void AbstractNumberingDefinitions();
710 
711     // Convert the bullet according to the font.
712     void SubstituteBullet( String& rNumStr, rtl_TextEncoding& rChrSet,
713         String& rFontName ) const;
714 
715     /// No-op for the newer WW versions.
OutputOlst(const SwNumRule &)716     virtual void OutputOlst( const SwNumRule& /*rRule*/ ) {}
717 
718     /// Setup the pA's info.
SetupSectionPositions(WW8_PdAttrDesc *)719     virtual void SetupSectionPositions( WW8_PdAttrDesc* /*pA*/ ) {}
720 
721     /// Top node of host page when in header/footer.
SetHdFtPageRoot(const SwTxtNode * pNd)722     void SetHdFtPageRoot( const SwTxtNode *pNd ) { mpTopNodeOfHdFtPage = pNd; }
723 
724     /// Top node of host page when in header/footer.
GetHdFtPageRoot() const725     const SwTxtNode *GetHdFtPageRoot() const { return mpTopNodeOfHdFtPage; }
726 
727     /// Output the actual headers and footers.
728     virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
729             const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt,
730         sal_uInt8 nBreakCode) = 0;
731 
732     /// Write the field
733     virtual void OutputField( const SwField* pFld, ww::eField eFldType,
734             const String& rFldCmd, sal_uInt8 nMode = nsFieldFlags::WRITEFIELD_ALL ) = 0;
735 
736     /// Write the data of the form field
737     virtual void WriteFormData( const ::sw::mark::IFieldmark& rFieldmark ) = 0;
738     virtual void WriteHyperlinkData( const ::sw::mark::IFieldmark& rFieldmark ) = 0;
739 
740     virtual void DoComboBox(const rtl::OUString &rName,
741                     const rtl::OUString &rHelp,
742                     const rtl::OUString &ToolTip,
743                     const rtl::OUString &rSelected,
744                     com::sun::star::uno::Sequence<rtl::OUString> &rListItems) = 0;
745 
746     virtual void DoFormText(const SwInputField * pFld) = 0;
747 
748     static bool NoPageBreakSection( const SfxItemSet *pSet );
749 
750     // Compute the number format for WW dates
751     bool GetNumberFmt(const SwField& rFld, String& rStr);
752 
753     virtual sal_uLong ReplaceCr( sal_uInt8 nChar ) = 0;
754 
755     const SfxPoolItem* HasItem( sal_uInt16 nWhich ) const;
756 
757 
758 protected:
759     /// Format-dependant part of the actual export.
760     virtual void ExportDocument_Impl() = 0;
761 
762     /// Get the next position in the text node to output
763     virtual xub_StrLen GetNextPos( WW8SwAttrIter* pAttrIter, const SwTxtNode& rNode, xub_StrLen nAktPos );
764 
765     /// Update the information for GetNextPos().
766     virtual void UpdatePosition( WW8SwAttrIter* pAttrIter, xub_StrLen nAktPos, xub_StrLen nEnd );
767 
768     /// Output SwTxtNode
769     void OutputTextNode( const SwTxtNode& );
770 
771     /// Output SwTableNode
772     void OutputTableNode( const SwTableNode& );
773 
774     /// Setup the chapter fields (maChapterFieldLocs).
775     void GatherChapterFields();
776 
777     void AddLinkTarget( const String& rURL );
778     void CollectOutlineBookmarks( const SwDoc &rDoc );
779 
780     bool SetAktPageDescFromNode(const SwNode &rNd);
781     bool CntntContainsChapterField(const SwFmtCntnt &rCntnt) const;
782     bool FmtHdFtContainsChapterField(const SwFrmFmt &rFmt) const;
783 
784     virtual void SectionBreaksAndFrames( const SwTxtNode& rNode ) = 0;
785 
786     virtual void PrepareNewPageDesc( const SfxItemSet* pSet,
787                                      const SwNode& rNd,
788                                      const SwFmtPageDesc* pNewPgDescFmt = 0,
789                                      const SwPageDesc* pNewPgDesc = 0 ) = 0;
790 
791     /// Return value indicates if an inherited outline numbering is suppressed.
792     virtual bool DisallowInheritingOutlineNumbering(const SwFmt &rFmt) = 0;
793 
794 protected:
795     /// Output SwStartNode
796     virtual void OutputStartNode( const SwStartNode& );
797 
798     /// Output SwEndNode
799     virtual void OutputEndNode( const SwEndNode& );
800 
801     /// Output SwGrfNode
802     virtual void OutputGrfNode( const SwGrfNode& ) = 0;
803 
804     /// Output SwOLENode
805     virtual void OutputOLENode( const SwOLENode& ) = 0;
806 
807     /// Output SwSectionNode
808     virtual void OutputSectionNode( const SwSectionNode& );
809 
810     virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum ) = 0;
811 
812     /// Call the right (virtual) function according to the type of the item.
813     ///
814     /// One of OutputTextNode(), OutputGrfNode(), or OutputOLENode()
815     void OutputContentNode( const SwCntntNode& );
816 
817     /// Find the nearest bookmark from the current position.
818     ///
819     /// Returns false when there is no bookmark.
820     bool NearestBookmark( xub_StrLen& rNearest, const xub_StrLen nAktPos, bool bNextPositionOnly );
821 
822     void GetSortedBookmarks( const SwTxtNode& rNd, xub_StrLen nAktPos,
823                 xub_StrLen nLen );
824 
825     bool GetBookmarks(
826         const SwTxtNode& rNd,
827         const xub_StrLen nStt,
828         const xub_StrLen nEnd,
829         IMarkVector& rArr );
830 
831     const NfKeywordTable & GetNfKeywordTable();
832 
833 public:
834     MSWordExportBase( SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam );
835     virtual ~MSWordExportBase();
836 
837     // TODO move as much as possible here from WW8Export! ;-)
838 
839     static void CorrectTabStopInSet( SfxItemSet& rSet, sal_uInt16 nAbsLeft );
840 
841 private:
842     /// No copying.
843     MSWordExportBase( const MSWordExportBase& );
844     /// No copying.
845     MSWordExportBase& operator=( const MSWordExportBase& );
846 };
847 
848 /// The writer class that gets called for the WW8 filter.
849 class SwWW8Writer: public StgWriter
850 {
851 // friends to get access to m_pExport
852 // FIXME avoid that, this is probably not what we want
853 // (if yes, remove the friends, and provide here a GetExport() method)
854 friend void WW8_WrtRedlineAuthor::Write(Writer &rWrt);
855 
856     bool       m_bWrtWW8;
857     WW8Export *m_pExport;
858     SfxMedium *mpMedium;
859 
860 public:
861     SwWW8Writer( const String& rFltName, const String& rBaseURL );
862     virtual ~SwWW8Writer();
863 
864     virtual sal_uLong WriteStorage();
865     virtual sal_uLong WriteMedium( SfxMedium& );
866 
867     // TODO most probably we want to be able to get these in
868     // MSExportFilterBase
869     using Writer::getIDocumentSettingAccess;
870 
871 public:
872 #if 1
873     /// Prefer ww::bytes to WW8Bytes, migrate away from the other ones.
874     static void InsUInt16(ww::bytes &rO, sal_uInt16 n);
875     static void InsUInt32(ww::bytes &rO, sal_uInt32 n);
876     static void InsAsString16(ww::bytes &rO, const String& rStr);
877     static void InsAsString8(ww::bytes & O, const String& rStr,
878         rtl_TextEncoding eCodeSet);
879 #endif
880 
881     static void InsUInt16( WW8Bytes& rO, sal_uInt16 );
882     static void InsUInt32( WW8Bytes& rO, sal_uInt32 );
883     static void InsAsString16( WW8Bytes& rO, const String& );
884     static void InsAsString8( WW8Bytes& rO, const String& rStr,
885                                 rtl_TextEncoding eCodeSet );
886 
887     static sal_uLong FillUntil( SvStream& rStrm, sal_uLong nEndPos = 0 );
888     static void FillCount( SvStream& rStrm, sal_uLong nCount );
889 
WriteShort(SvStream & rStrm,sal_Int16 nVal)890     static void WriteShort( SvStream& rStrm, sal_Int16 nVal ) { rStrm << nVal; }
891     static void WriteShort( SvStream& rStrm, sal_uLong nPos, sal_Int16 nVal );
892 
WriteLong(SvStream & rStrm,sal_Int32 nVal)893     static void WriteLong( SvStream& rStrm, sal_Int32 nVal ) { rStrm << nVal; }
894     static void WriteLong( SvStream& rStrm, sal_uLong nPos, sal_Int32 nVal );
895 
896     static void WriteString16(SvStream& rStrm, const String& rStr,
897         bool bAddZero);
898     static void WriteString8(SvStream& rStrm, const String& rStr,
899         bool bAddZero, rtl_TextEncoding eCodeSet);
900 
901     static void WriteString_xstz(SvStream& rStrm, const String& rStr, bool bAddZero);
902 
903     bool InitStd97CodecUpdateMedium( ::msfilter::MSCodec_Std97& rCodec );
904 
905     using StgWriter::Write;
906     virtual sal_uLong Write( SwPaM&, SfxMedium&, const String* = 0 );
907     //Seems not an expected to provide method to access the private member
GetMedia()908     SfxMedium* GetMedia(){ return mpMedium;};
909 
910 private:
911     /// No copying.
912     SwWW8Writer(const SwWW8Writer&);
913     /// No copying.
914     SwWW8Writer& operator=(const SwWW8Writer&);
915 };
916 
917 /// Exporter of the binary Word file formats.
918 class WW8Export : public MSWordExportBase
919 {
920 public:
921     WW8Bytes* pO;                       ///< Buffer
922     WW8Bytes* mpTableAt;                ///< Additional buffer for the output of the tables
923     sal_uInt16 mnTableStdAtLen;         ///< Standard length of mpTableAt
924 
925     SvStream *pTableStrm, *pDataStrm;   ///< Streams for WW97 Export
926 
927     WW8Fib* pFib;                       ///< File Information Block
928     WW8Dop* pDop;                       ///< DOcument Properties
929     WW8_WrPlcFtnEdn *pFtn;              ///< Footnotes - structure to remember them, and output
930     WW8_WrPlcFtnEdn *pEdn;              ///< Endnotes - structure to remember them, and output
931     WW8_WrPlcSepx* pSepx;               ///< Sections/headers/footers
932 
933     sal_uInt8 bWrtWW8 : 1;                   ///< Write WW95 (false) or WW97 (true) file format
934 
935         //For i120928,this vector is to record all the graphics of bullets
936     mutable std::vector<const Graphic*> m_vecBulletPic;
937 
938 protected:
939     SwWW8Writer        *m_pWriter;      ///< Pointer to the writer
940     WW8AttributeOutput *m_pAttrOutput;  ///< Converting attributes to stream data
941 
942 private:
943     SvStorageRef       xEscherStg;      /// memory leak #i120098#, to hold the reference to unnamed SotStorage obj
944 
945 public:
946     /// Access to the attribute output class.
947     virtual AttributeOutputBase& AttrOutput() const;
948 
949     /// Access to the sections/headers/footres.
950     virtual MSWordSections& Sections() const;
951 
952     /// False for WW6, true for WW8.
HackIsWW8OrHigher() const953     virtual bool HackIsWW8OrHigher() const { return bWrtWW8; }
954 
955 private:
956     /// Format-dependant part of the actual export.
957     virtual void ExportDocument_Impl();
958 
959     void PrepareStorage();
960     void WriteFkpPlcUsw();
961     void WriteMainText();
962     void StoreDoc1();
963     void Out_WwNumLvl( sal_uInt8 nWwLevel );
964     void BuildAnlvBulletBase( WW8_ANLV& rAnlv, sal_uInt8*& rpCh, sal_uInt16& rCharLen,
965                               const SwNumFmt& rFmt );
966     static void BuildAnlvBase( WW8_ANLV& rAnlv, sal_uInt8*& rpCh, sal_uInt16& rCharLen,
967                    const SwNumRule& rRul, const SwNumFmt& rFmt, sal_uInt8 nSwLevel );
968 
969     void Out_BorderLine(WW8Bytes& rO, const SvxBorderLine* pLine,
970         sal_uInt16 nDist, sal_uInt16 nSprmNo, bool bShadow);
971 
972     /// Output the numbering table.
973     virtual void WriteNumbering();
974 
975     void OutOverrideListTab();
976     void OutListNamesTab();
977 
978     void RestoreMacroCmds();
979 
980     void InitFontTable();
981 
982     void DoComboBox(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> xPropSet);
983     void DoCheckBox(com::sun::star::uno::Reference<com::sun::star::beans::XPropertySet> xPropSet);
984 
985 public:
986     virtual void OutputOlst( const SwNumRule& rRule );
987 
988     /// Setup the pA's info.
989     virtual void SetupSectionPositions( WW8_PdAttrDesc* pA );
990 
991     void Out_SwNumLvl( sal_uInt8 nSwLevel );
992     void Out_NumRuleAnld( const SwNumRule& rRul, const SwNumFmt& rFmt,
993                           sal_uInt8 nSwLevel );
994 
995     bool MiserableFormFieldExportHack(const SwFrmFmt& rFrmFmt);
996 
GetOLEExp()997     SvxMSExportOLEObjects& GetOLEExp()      { return *pOLEExp; }
GetOCXExp()998     SwMSConvertControls& GetOCXExp()        { return *pOCXExp; }
GetOLEMap()999     WW8OleMaps& GetOLEMap()                 { return *pOleMap; }
1000     void ExportDopTypography(WW8DopTypography &rTypo);
1001 
1002     using MSWordExportBase::GetId;
GetId(const SvxFontItem & rFont)1003     sal_uInt16 GetId( const SvxFontItem& rFont)
1004     {
1005         return maFontHelper.GetId(rFont);
1006     }
1007 
1008     sal_uInt16 AddRedlineAuthor( sal_uInt16 nId );
1009 
1010     void WriteFtnBegin( const SwFmtFtn& rFtn, WW8Bytes* pO = 0 );
1011     void WritePostItBegin( WW8Bytes* pO = 0 );
1012     const SvxBrushItem* GetCurrentPageBgBrush() const;
1013     SvxBrushItem TrueFrameBgBrush(const SwFrmFmt &rFlyFmt) const;
1014 
1015     /// Output all textframes anchored as character for the winword 7- format.
1016     void OutWW6FlyFrmsInCntnt( const SwTxtNode& rNd );
1017 
1018     void AppendFlyInFlys(const sw::Frame& rFrmFmt, const Point& rNdTopLeft);
1019     void WriteOutliner(const OutlinerParaObject& rOutliner, sal_uInt8 nTyp);
1020     void WriteSdrTextObj(const SdrObject& rObj, sal_uInt8 nTyp);
1021 
1022     sal_uInt32 GetSdrOrdNum( const SwFrmFmt& rFmt ) const;
1023     void CreateEscher();
1024     void WriteEscher();
1025 
1026     bool Out_SwNum(const SwTxtNode* pNd);
1027 
1028     /// Write the field
1029     virtual void OutputField( const SwField* pFld, ww::eField eFldType,
1030             const String& rFldCmd, sal_uInt8 nMode = nsFieldFlags::WRITEFIELD_ALL );
1031 
1032     void StartCommentOutput( const String& rName );
1033     void EndCommentOutput(   const String& rName );
1034     void OutGrf(const sw::Frame &rFrame);
1035     bool TestOleNeedsGraphic(const SwAttrSet& rSet, SvStorageRef xOleStg,
1036         SvStorageRef xObjStg, String &rStorageName, SwOLENode *pOLENd);
1037 
1038     virtual void AppendBookmarks( const SwTxtNode& rNd, xub_StrLen nAktPos, xub_StrLen nLen );
1039     virtual void AppendBookmark( const rtl::OUString& rName, bool bSkip = false );
1040 
1041     virtual void ExportGrfBullet(const SwTxtNode& rNd);
1042     int CollectGrfsOfBullets() const;
1043     void OutGrfBullets(const sw::Frame &rFrame);
1044     int GetGrfIndex(const SvxBrushItem& rBrush);
1045 
1046     void MoveFieldMarks(sal_uLong nFrom, sal_uLong nTo);
1047 
1048     void WriteAsStringTable(const ::std::vector<String>&, sal_Int32& rfcSttbf,
1049         sal_Int32& rlcbSttbf, sal_uInt16 nExtraLen = 0);
1050 
1051     virtual sal_uLong ReplaceCr( sal_uInt8 nChar );
1052 
1053     virtual void WriteCR( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t() );
1054     void WriteChar( sal_Unicode c );
1055 #if 0
1056     sal_uInt16 StartTableFromFrmFmt(WW8Bytes &rAt, const SwFrmFmt *pFmt,
1057         SwTwips &rPageSize);
1058 #endif
1059 
1060     void OutSwString(const String&, xub_StrLen nStt, xub_StrLen nLen,
1061         bool bUnicode, rtl_TextEncoding eChrSet);
1062 
Fc2Cp(sal_uLong nFc) const1063     WW8_CP Fc2Cp( sal_uLong nFc ) const          { return pPiece->Fc2Cp( nFc ); }
1064 
1065             // einige z.T. static halb-interne Funktions-Deklarationen
1066 
OutSprmBytes(sal_uInt8 * pBytes,sal_uInt16 nSiz)1067     void OutSprmBytes( sal_uInt8* pBytes, sal_uInt16 nSiz )
1068                                 { pO->Insert( pBytes, nSiz, pO->Count() ); }
1069 
IsUnicode() const1070     inline bool IsUnicode() const           { return pPiece->IsUnicode(); }
1071 
1072     virtual void SectionBreaksAndFrames( const SwTxtNode& rNode );
1073 
1074     /// Helper method for OutputSectionBreaks() and OutputFollowPageDesc().
1075     // OD 2007-05-29 #i76300#
1076     virtual void PrepareNewPageDesc( const SfxItemSet* pSet,
1077                                      const SwNode& rNd,
1078                                      const SwFmtPageDesc* pNewPgDescFmt = 0,
1079                                      const SwPageDesc* pNewPgDesc = 0 );
1080 
1081     void Out_SwFmtBox(const SvxBoxItem& rBox, bool bShadow);
1082     void Out_SwFmtTableBox( WW8Bytes& rO, const SvxBoxItem * rBox );
1083     sal_uInt8 TransCol( const Color& rCol );
1084     bool TransBrush(const Color& rCol, WW8_SHD& rShd);
1085     WW8_BRC TranslateBorderLine(const SvxBorderLine& pLine,
1086         sal_uInt16 nDist, bool bShadow);
1087 
1088     // --> OD 2007-06-04 #i77805#
1089     // new return value indicates, if an inherited outline numbering is suppressed
1090     virtual bool DisallowInheritingOutlineNumbering(const SwFmt &rFmt);
1091     // <--
1092 
GetHdFtIndex() const1093     unsigned int GetHdFtIndex() const { return mnHdFtIndex; }
SetHdFtIndex(unsigned int nHdFtIndex)1094     void SetHdFtIndex(unsigned int nHdFtIndex) { mnHdFtIndex = nHdFtIndex; }
IncrementHdFtIndex()1095     void IncrementHdFtIndex() { ++mnHdFtIndex; }
1096 
1097     static long GetDTTM( const DateTime& rDT );
1098 
1099     /// Convert the SVX numbering type to id
1100     static sal_uInt8 GetNumId( sal_uInt16 eNumType );
1101 
1102     /// Guess the script (asian/western).
1103     virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich );
1104 
1105     sal_uInt16 DupNumRuleWithLvlStart(const SwNumRule *pRule,sal_uInt8 nLvl,sal_uInt16 nVal);
1106 
1107     SwTwips CurrentPageWidth(SwTwips &rLeft, SwTwips &rRight) const;
1108 
1109     /// Nasty swap for bidi if necessary
1110     bool MiserableRTLFrmFmtHack(SwTwips &rLeft, SwTwips &rRight,
1111         const sw::Frame &rFrmFmt);
1112 
InsUInt16(sal_uInt16 n)1113     void InsUInt16( sal_uInt16 n )      { SwWW8Writer::InsUInt16( *pO, n ); }
InsUInt32(sal_uInt32 n)1114     void InsUInt32( sal_uInt32 n )      { SwWW8Writer::InsUInt32( *pO, n ); }
InsAsString16(const String & rStr)1115     void InsAsString16( const String& rStr )
1116                         { SwWW8Writer::InsAsString16( *pO, rStr ); }
InsAsString8(const String & rStr,rtl_TextEncoding eCodeSet)1117     void InsAsString8( const String& rStr, rtl_TextEncoding eCodeSet )
1118                         { SwWW8Writer::InsAsString8( *pO, rStr, eCodeSet ); }
1119     void WriteStringAsPara( const String& rTxt, sal_uInt16 nStyleId = 0 );
1120 
1121     /// Setup the exporter.
1122     WW8Export( SwWW8Writer *pWriter,
1123             SwDoc *pDocument, SwPaM *pCurrentPam, SwPaM *pOriginalPam,
1124             bool bIsWW8 );
1125     virtual ~WW8Export();
1126 
1127     virtual void DoComboBox(const rtl::OUString &rName,
1128                     const rtl::OUString &rHelp,
1129                     const rtl::OUString &ToolTip,
1130                     const rtl::OUString &rSelected,
1131                     com::sun::star::uno::Sequence<rtl::OUString> &rListItems);
1132 
1133     virtual void DoFormText(const SwInputField * pFld);
1134 
1135     void GetCurrentItems(WW8Bytes &rItems) const;
1136 
1137     /// Write the data of the form field
1138     virtual void WriteFormData( const ::sw::mark::IFieldmark& rFieldmark );
1139     virtual void WriteHyperlinkData( const ::sw::mark::IFieldmark& rFieldmark );
1140 
1141     /// Fields.
1142     WW8_WrPlcFld* CurrentFieldPlc() const;
1143 
GetWriter() const1144     SwWW8Writer& GetWriter() const { return *m_pWriter; }
Strm() const1145     SvStream& Strm() const { return m_pWriter->Strm(); }
1146 
1147     /// Remember some of the members so that we can recurse in WriteText().
1148     virtual void SaveData( sal_uLong nStt, sal_uLong nEnd );
1149 
1150     /// Restore what was saved in SaveData().
1151     virtual void RestoreData();
1152 
1153     /// Output the actual headers and footers.
1154     virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
1155             const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt,
1156         sal_uInt8 nBreakCode);
1157 
1158 protected:
1159     /// Output SwGrfNode
1160     virtual void OutputGrfNode( const SwGrfNode& );
1161 
1162     /// Output SwOLENode
1163     virtual void OutputOLENode( const SwOLENode& );
1164 
1165     virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum );
1166 
1167 private:
1168     /// No copying.
1169     WW8Export(const WW8Export&);
1170     /// No copying.
1171     WW8Export& operator=(const WW8Export&);
1172 };
1173 
1174 class WW8_WrPlcSubDoc   // Doppel-Plc fuer Foot-/Endnotes und Postits
1175 {
1176 private:
1177     //No copying
1178     WW8_WrPlcSubDoc(const WW8_WrPlcSubDoc&);
1179     WW8_WrPlcSubDoc& operator=(const WW8_WrPlcSubDoc&);
1180 protected:
1181     SvULongs aCps;                  // PTRARR CP-Pos der Verweise
1182     SvPtrarr aCntnt;                // PTRARR von SwFmtFtn/PostIts/..
1183     WW8_WrPlc0* pTxtPos;            // Pos der einzelnen Texte
1184     SvPtrarr aSpareFmts;            //a backup for aCntnt: if there's no SdrObject, stores the fmt directly here
1185 
1186     WW8_WrPlcSubDoc();
1187     virtual ~WW8_WrPlcSubDoc();
1188 
1189     bool WriteGenericTxt( WW8Export& rWrt, sal_uInt8 nTTyp, WW8_CP& rCount );
1190     void WriteGenericPlc( WW8Export& rWrt, sal_uInt8 nTTyp, WW8_FC& rTxtStt,
1191         sal_Int32& rTxtCnt, WW8_FC& rRefStt, sal_Int32& rRefCnt ) const;
1192 
1193     virtual const SvULongs* GetShapeIdArr() const;
1194 };
1195 
1196 // Doppel-Plc fuer Footnotes/Endnotes
1197 class WW8_WrPlcFtnEdn : public WW8_WrPlcSubDoc
1198 {
1199 private:
1200     sal_uInt8 nTyp;
1201 
1202     //No copying
1203     WW8_WrPlcFtnEdn(const WW8_WrPlcFtnEdn&);
1204     WW8_WrPlcFtnEdn& operator=(WW8_WrPlcFtnEdn &);
1205 public:
WW8_WrPlcFtnEdn(sal_uInt8 nTTyp)1206     WW8_WrPlcFtnEdn( sal_uInt8 nTTyp ) : nTyp( nTTyp ) {}
1207 
1208     bool WriteTxt( WW8Export& rWrt );
1209     void WritePlc( WW8Export& rWrt ) const;
1210 
1211     void Append( WW8_CP nCp, const SwFmtFtn& rFtn );
1212 };
1213 
1214 struct WW8_Annotation
1215 {
1216     const OutlinerParaObject* mpRichText;
1217     String msSimpleText;
1218     String msOwner;
1219     DateTime maDateTime;
1220     WW8_Annotation(const SwPostItField* pPostIt);
1221     WW8_Annotation(const SwRedlineData* pRedline);
1222 };
1223 
1224 class WW8_WrPlcAnnotations : public WW8_WrPlcSubDoc  // Doppel-Plc fuer PostIts
1225 {
1226 private:
1227     //No copying
1228     WW8_WrPlcAnnotations(const WW8_WrPlcAnnotations&);
1229     WW8_WrPlcAnnotations& operator=(WW8_WrPlcAnnotations&);
1230     std::set<const SwRedlineData*> maProcessedRedlines;
1231 public:
WW8_WrPlcAnnotations()1232     WW8_WrPlcAnnotations() {}
1233     ~WW8_WrPlcAnnotations();
1234 
1235     void Append( WW8_CP nCp, const SwPostItField* pPostIt );
1236     void Append( WW8_CP nCp, const SwRedlineData* pRedLine );
1237     bool IsNewRedlineComment( const SwRedlineData* pRedLine );
1238     bool WriteTxt( WW8Export& rWrt );
1239     void WritePlc( WW8Export& rWrt ) const;
1240 };
1241 
1242 class WW8_WrPlcTxtBoxes : public WW8_WrPlcSubDoc // Doppel-Plc fuer Textboxen
1243 {                        // Rahmen/DrawTextboxes!
1244 private:
1245     sal_uInt8 nTyp;
1246     SvULongs aShapeIds;        // VARARR of ShapeIds for the SwFrmFmts
1247     virtual const SvULongs* GetShapeIdArr() const;
1248 
1249     //No copying
1250     WW8_WrPlcTxtBoxes(const WW8_WrPlcTxtBoxes&);
1251     WW8_WrPlcTxtBoxes& operator=(WW8_WrPlcTxtBoxes&);
1252 public:
WW8_WrPlcTxtBoxes(sal_uInt8 nTTyp)1253     WW8_WrPlcTxtBoxes( sal_uInt8 nTTyp ) : nTyp( nTTyp ) {}
1254 
1255     bool WriteTxt( WW8Export& rWrt );
1256     void WritePlc( WW8Export& rWrt ) const;
1257     void Append( const SdrObject& rObj, sal_uInt32 nShapeId );
1258     void Append( const SwFrmFmt* pFmt, sal_uInt32 nShapeId );
Count() const1259     sal_uInt16 Count() const { return aCntnt.Count(); }
GetPos(const VoidPtr & p) const1260     sal_uInt16 GetPos( const VoidPtr& p ) const { return aCntnt.GetPos( p ); }
1261 };
1262 
1263 typedef WW8_WrFkp* WW8_FkpPtr;  // Plc fuer Chpx und Papx ( incl PN-Plc )
1264 SV_DECL_PTRARR( WW8_WrFkpPtrs, WW8_FkpPtr, 4, 4 )
1265 
1266 class WW8_WrPlcPn                   // Plc fuer Page Numbers
1267 {
1268 private:
1269     WW8Export& rWrt;
1270     WW8_WrFkpPtrs aFkps;            // PTRARR
1271     sal_uInt16 nFkpStartPage;
1272     ePLCFT ePlc;
1273     bool bWrtWW8;                   // Fuer Writererkennung
1274     sal_uInt16 nMark;
1275 
1276     //No copying
1277     WW8_WrPlcPn(const WW8_WrPlcPn&);
1278     WW8_WrPlcPn& operator=(const WW8_WrPlcPn&);
1279 public:
1280     WW8_WrPlcPn( WW8Export& rWrt, ePLCFT ePl, WW8_FC nStartFc );
1281     ~WW8_WrPlcPn();
1282     void AppendFkpEntry(WW8_FC nEndFc,short nVarLen = 0,const sal_uInt8* pSprms = 0);
1283     void WriteFkps();
1284     void WritePlc();
1285     sal_uInt8 *CopyLastSprms(sal_uInt8 &rLen);
1286 };
1287 
1288 // class WW8_WrPlc1 ist erstmal nur fuer Felder
1289 class WW8_WrPlc1
1290 {
1291 private:
1292     SvULongs aPos;              // PTRARR von CPs
1293     sal_uInt8* pData;                // Inhalte ( Strukturen )
1294     sal_uLong nDataLen;
1295     sal_uInt16 nStructSiz;
1296 
1297     //No copying
1298     WW8_WrPlc1(const WW8_WrPlc1&);
1299     WW8_WrPlc1& operator=(const WW8_WrPlc1&);
1300 protected:
Count() const1301     sal_uInt16 Count() const { return aPos.Count(); }
1302     void Write( SvStream& rStrm );
1303     WW8_CP Prev() const;
1304 public:
1305     WW8_WrPlc1( sal_uInt16 nStructSz );
1306     ~WW8_WrPlc1();
1307     void Append( WW8_CP nCp, const void* pData );
1308     void Finish( sal_uLong nLastCp, sal_uLong nStartCp );
1309 };
1310 
1311 // class WW8_WrPlcFld ist fuer Felder
1312 class WW8_WrPlcFld : public WW8_WrPlc1
1313 {
1314 private:
1315     sal_uInt8 nTxtTyp;
1316     sal_uInt16 nResults;
1317 
1318     //No copying
1319     WW8_WrPlcFld(const WW8_WrPlcFld&);
1320     WW8_WrPlcFld& operator=(const WW8_WrPlcFld&);
1321 public:
WW8_WrPlcFld(sal_uInt16 nStructSz,sal_uInt8 nTTyp)1322     WW8_WrPlcFld( sal_uInt16 nStructSz, sal_uInt8 nTTyp )
1323         : WW8_WrPlc1( nStructSz ), nTxtTyp( nTTyp ), nResults(0)
1324     {}
1325     bool Write( WW8Export& rWrt );
ResultAdded()1326     void ResultAdded() { ++nResults; }
ResultCount() const1327     sal_uInt16 ResultCount() const { return nResults; }
1328 };
1329 
1330 class WW8_WrMagicTable : public WW8_WrPlc1
1331 {
1332 private:
1333     //No copying
1334     WW8_WrMagicTable(const WW8_WrMagicTable&);
1335     WW8_WrMagicTable& operator=(const WW8_WrMagicTable&);
1336 public:
WW8_WrMagicTable()1337     WW8_WrMagicTable() : WW8_WrPlc1( 4 ) {Append(0,0);}
1338     void Append( WW8_CP nCp, sal_uLong nData );
1339     bool Write( WW8Export& rWrt );
1340 };
1341 
1342 class GraphicDetails
1343 {
1344 public:
1345     sw::Frame maFly;            // Umgebende FlyFrms dazu
1346     sal_uLong mnPos;                // FilePos der Grafiken
1347     sal_uInt16 mnWid;               // Breite der Grafiken
1348     sal_uInt16 mnHei;               // Hoehe der Grafiken
1349 
GraphicDetails(const sw::Frame & rFly,sal_uInt16 nWid,sal_uInt16 nHei)1350     GraphicDetails(const sw::Frame &rFly, sal_uInt16 nWid, sal_uInt16 nHei)
1351         : maFly(rFly), mnPos(0), mnWid(nWid), mnHei(nHei)
1352     {}
1353     GraphicDetails& operator=(const GraphicDetails& rOther);
1354     GraphicDetails(const GraphicDetails&) = default;
1355 
operator ==(const GraphicDetails & rIn) const1356     bool operator==(const GraphicDetails& rIn) const
1357     {
1358         return (
1359                  (mnWid == rIn.mnWid) && (mnHei == rIn.mnHei) &&
1360                  (maFly.RefersToSameFrameAs(rIn.maFly))
1361                );
1362     }
1363 };
1364 
1365 // class SwWW8WrGrf sammelt Grafiken und gibt sie aus
1366 class SwWW8WrGrf
1367 {
1368 private:
1369     /// for access to the variables
1370     WW8Export& rWrt;
1371 
1372     std::vector<GraphicDetails> maDetails;
1373     typedef std::vector<GraphicDetails>::iterator myiter;
1374     sal_uInt16 mnIdx;       // Index in File-Positionen
1375 
1376     void WritePICFHeader(SvStream& rStrm, const sw::Frame &rFly,
1377             sal_uInt16 mm, sal_uInt16 nWidth, sal_uInt16 nHeight,
1378             const SwAttrSet* pAttrSet = 0);
1379     void WriteGraphicNode(SvStream& rStrm, const GraphicDetails &rItem);
1380     void WriteGrfFromGrfNode(SvStream& rStrm, const SwGrfNode &rNd,
1381         const sw::Frame &rFly, sal_uInt16 nWidth, sal_uInt16 nHeight);
1382 
1383     void WritePICBulletFHeader(SvStream& rStrm, const Graphic &rGrf, sal_uInt16 mm, sal_uInt16 nWidth, sal_uInt16 nHeight);
1384     void WriteGrfForBullet(SvStream& rStrm,  const Graphic &rGrf, sal_uInt16 nWidth, sal_uInt16 nHeight);
1385 
1386     //No copying
1387     SwWW8WrGrf(const SwWW8WrGrf&);
1388     SwWW8WrGrf& operator=(const SwWW8WrGrf&);
1389 public:
SwWW8WrGrf(WW8Export & rW)1390     SwWW8WrGrf( WW8Export& rW ) : rWrt( rW ), mnIdx( 0 ) {}
1391     void Insert(const sw::Frame &rFly);
1392     void Write();
GetFPos()1393     sal_uLong GetFPos()
1394         { return (mnIdx < maDetails.size()) ? maDetails[mnIdx++].mnPos : 0; }
1395 };
1396 
1397 /** The class MSWordAttrIter is a helper class to build the Fkp.chpx.
1398     This class may be overloaded for output the SwTxtAttrs and the
1399     EditEngineTxtAttrs.
1400 */
1401 class MSWordAttrIter
1402 {
1403 private:
1404     MSWordAttrIter* pOld;
1405     //No copying
1406     MSWordAttrIter(const MSWordAttrIter&);
1407     MSWordAttrIter& operator=(const MSWordAttrIter&);
1408 protected:
1409     MSWordExportBase& m_rExport;
1410 public:
1411     MSWordAttrIter( MSWordExportBase& rExport );
1412     virtual ~MSWordAttrIter();
1413 
1414     virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const = 0;
1415     virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const = 0;
1416 };
1417 
1418 class MSWord_SdrAttrIter : public MSWordAttrIter
1419 {
1420 private:
1421     const EditTextObject* pEditObj;
1422     const SfxItemPool* pEditPool;
1423     EECharAttribArray aTxtAtrArr;
1424     SvPtrarr aChrTxtAtrArr;
1425     SvUShorts aChrSetArr;
1426     sal_uInt16 nPara;
1427     xub_StrLen nAktSwPos;
1428     xub_StrLen nTmpSwPos;                   // for HasItem()
1429     rtl_TextEncoding eNdChrSet;
1430     sal_uInt16 nScript;
1431     sal_uInt8 mnTyp;
1432 
1433     xub_StrLen SearchNext( xub_StrLen nStartPos );
1434     void SetCharSet(const EECharAttrib& rTxtAttr, bool bStart);
1435 
1436     //No copying
1437     MSWord_SdrAttrIter(const MSWord_SdrAttrIter&);
1438     MSWord_SdrAttrIter& operator=(const MSWord_SdrAttrIter&);
1439 public:
1440     MSWord_SdrAttrIter( MSWordExportBase& rWr, const EditTextObject& rEditObj,
1441         sal_uInt8 nType );
1442     void NextPara( sal_uInt16 nPar );
1443     void OutParaAttr(bool bCharAttr);
1444     void OutEEField(const SfxPoolItem& rHt);
1445 
1446     bool IsTxtAttr(xub_StrLen nSwPos);
1447 
NextPos()1448     void NextPos() { nAktSwPos = SearchNext( nAktSwPos + 1 ); }
1449 
1450     void OutAttr( xub_StrLen nSwPos );
1451     virtual const SfxPoolItem* HasTextItem( sal_uInt16 nWhich ) const;
1452     virtual const SfxPoolItem& GetItem( sal_uInt16 nWhich ) const;
1453     bool OutAttrWithRange(xub_StrLen nPos);
WhereNext() const1454     xub_StrLen WhereNext() const                { return nAktSwPos; }
1455     rtl_TextEncoding GetNextCharSet() const;
GetNodeCharSet() const1456     rtl_TextEncoding GetNodeCharSet() const     { return eNdChrSet; }
1457 };
1458 
1459 /// Class to collect and output the styles table.
1460 class MSWordStyles
1461 {
1462     MSWordExportBase& m_rExport;
1463     SwFmt** pFmtA;
1464     sal_uInt16 nUsedSlots;
1465 
1466     /// Create the style table, called from the constructor.
1467     void BuildStylesTable();
1468 
1469     /// Get slot number during building the style table.
1470     sal_uInt16 BuildGetSlot( const SwFmt& rFmt );
1471 
1472     /// Return information about one style.
1473     void GetStyleData( SwFmt* pFmt, bool& bFmtColl, sal_uInt16& nBase, sal_uInt16& nNext );
1474 
1475     /// Outputs attributes of one style.
1476     void WriteProperties( const SwFmt* pFmt, bool bPap, sal_uInt16 nPos, bool bInsDefCharSiz );
1477 
1478     sal_uInt16 GetWWId( const SwFmt& rFmt ) const;
1479 
1480     void SetStyleDefaults( const SwFmt& rFmt, bool bPap );
1481 
1482     /// Outputs one style - called (in a loop) from OutputStylesTable().
1483     void OutputStyle( SwFmt* pFmt, sal_uInt16 nPos );
1484 
1485     // No copying
1486     MSWordStyles( const MSWordStyles& );
1487     MSWordStyles& operator=( const MSWordStyles& );
1488 
1489 public:
1490     MSWordStyles( MSWordExportBase& rExport );
1491     ~MSWordStyles();
1492 
1493     /// Output the styles table.
1494     void OutputStylesTable();
1495 
1496     /// Get id of the style (rFmt).
1497     sal_uInt16 GetSlot( const SwFmt& rFmt ) const;
1498 
GetSwFmt()1499     SwFmt* GetSwFmt() { return (*pFmtA); }
1500 };
1501 
1502 sal_Int16 GetWordFirstLineOffset(const SwNumFmt &rFmt);
1503 //A bit of a bag on the side for now
1504 String FieldString(ww::eField eIndex);
1505 String BookmarkToWord(const String &rBookmark);
1506 
1507 class WW8SHDLong
1508 {
1509     sal_uInt32 m_cvFore;
1510     sal_uInt32 m_cvBack;
1511     sal_uInt16 m_ipat;
1512 
1513 public:
WW8SHDLong()1514     WW8SHDLong() : m_cvFore(0), m_cvBack(0), m_ipat(0) {}
~WW8SHDLong()1515     virtual ~WW8SHDLong() {}
1516 
1517     void Write(WW8Export & rExport);
setCvFore(sal_uInt32 cvFore)1518     void setCvFore(sal_uInt32 cvFore) { m_cvFore = cvFore; }
setCvBack(sal_uInt32 cvBack)1519     void setCvBack(sal_uInt32 cvBack) { m_cvBack = cvBack; }
setIPat(sal_uInt16 ipat)1520     void setIPat(sal_uInt16 ipat) { m_ipat = ipat; }
1521 };
1522 
1523 #endif  //  _WRTWW8_HXX
1524 
1525 /* vi:set tabstop=4 shiftwidth=4 expandtab: */
1526