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 #ifndef _RTFEXPORT_HXX_
23 #define _RTFEXPORT_HXX_
24
25 #include <set>
26 #include "rtfattributeoutput.hxx"
27 #include "wrtww8.hxx"
28
29 #include <rtl/ustring.hxx>
30
31 #include <cstdio>
32 #include <map>
33
34 class RtfExportFilter;
35 class RtfSdrExport;
36 typedef std::map<sal_uInt16,Color> RtfColorTbl;
37 typedef std::map<sal_uInt16,rtl::OString> RtfStyleTbl;
38 typedef std::map<String,sal_uInt16> RtfRedlineTbl;
39 class SwNode;
40 class SwEndNode;
41 class SwTableNode;
42 class SwTxtNode;
43 class SwGrfNode;
44 class SwOLENode;
45 class SwSectionNode;
46 class SwNumRuleTbl;
47 class SvStream;
48
operator <<(SvStream & s,const rtl::OString r)49 inline SvStream& operator<<( SvStream& s, const rtl::OString r) { return (s << r.getStr()); }
50
51 namespace com { namespace sun { namespace star {
52 namespace frame { class XModel; }
53 } } }
54
55 // The class that does all the actual RTF export-related work.
56 class RtfExport : public MSWordExportBase
57 {
58 // Pointer to the filter that owns us.
59 RtfExportFilter *m_pFilter;
60 Writer* m_pWriter;
61
62 // Attribute output for document.
63 RtfAttributeOutput *m_pAttrOutput;
64
65 // Sections/headers/footers
66 MSWordSections *m_pSections;
67
68 RtfSdrExport *m_pSdrExport;
69
70 public:
71 // Access to the attribute output class.
72 virtual AttributeOutputBase& AttrOutput() const;
73
74 // Access to the sections/headers/footers.
75 virtual MSWordSections& Sections() const;
76
77 // Access to the Rtf Sdr exporter.
78 virtual RtfSdrExport& SdrExporter() const;
79
80 // Hack, unfortunately necessary at some places for now.
81 virtual bool HackIsWW8OrHigher() const;
82
83 // Guess the script (asian/western).
84 virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich );
85
86 virtual void AppendBookmarks( const SwTxtNode& rNode, xub_StrLen nAktPos, xub_StrLen nLen );
87
88 virtual void AppendBookmark( const rtl::OUString& rName, bool bSkip = false );
89
90 // For i120928,add an interface to export graphic of bullet
91 virtual void ExportGrfBullet(const SwTxtNode& rNd);
92
WriteCR(ww8::WW8TableNodeInfoInner::Pointer_t)93 virtual void WriteCR( ww8::WW8TableNodeInfoInner::Pointer_t /*pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t()*/ ) { /* no-op for rtf, most probably should not even be in MSWordExportBase */ }
94 virtual void WriteChar( sal_Unicode );
95
96 // Write the numbering table.
97 virtual void WriteNumbering();
98
99 // Write the revision table.
100 virtual void WriteRevTab();
101
102 // Output the actual headers and footers.
103 virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
104 const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt, sal_uInt8 nBreakCode );
105
106 // Write the field
107 virtual void OutputField( const SwField* pFld, ww::eField eFldType,
108 const String& rFldCmd, sal_uInt8 nMode = nsFieldFlags::WRITEFIELD_ALL );
109
110 // Write the data of the form field
111 virtual void WriteFormData( const ::sw::mark::IFieldmark& rFieldmark );
112 virtual void WriteHyperlinkData( const ::sw::mark::IFieldmark& rFieldmark );
113
114 virtual void DoComboBox(const rtl::OUString &rName,
115 const rtl::OUString &rHelp,
116 const rtl::OUString &ToolTip,
117 const rtl::OUString &rSelected,
118 com::sun::star::uno::Sequence<rtl::OUString> &rListItems);
119
120 virtual void DoFormText(const SwInputField * pFld);
121
122 virtual sal_uLong ReplaceCr( sal_uInt8 nChar );
123
124 protected:
125 // Format-dependent part of the actual export.
126 virtual void ExportDocument_Impl();
127
SectionBreaksAndFrames(const SwTxtNode &)128 virtual void SectionBreaksAndFrames( const SwTxtNode& /*rNode*/ ) {}
129
130 // Get ready for a new section.
131 virtual void PrepareNewPageDesc( const SfxItemSet* pSet,
132 const SwNode& rNd,
133 const SwFmtPageDesc* pNewPgDescFmt = 0,
134 const SwPageDesc* pNewPgDesc = 0 );
135
136 // Return value indicates if an inherited outline numbering is suppressed.
137 virtual bool DisallowInheritingOutlineNumbering(const SwFmt &rFmt);
138
139 // Output SwGrfNode
140 virtual void OutputGrfNode( const SwGrfNode& );
141
142 // Output SwOLENode
143 virtual void OutputOLENode( const SwOLENode& );
144
145 virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum );
146
147 public:
148 // Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
149 RtfExport( RtfExportFilter *pFilter, SwDoc *pDocument,
150 SwPaM *pCurrentPam, SwPaM *pOriginalPam, Writer* pWriter );
151
152 // Destructor.
153 virtual ~RtfExport();
154
155 #if defined(UNX)
156 static const sal_Char sNewLine; // \012 or \015
157 #else
158 static const sal_Char __FAR_DATA sNewLine[]; // \015\012
159 #endif
160
161 rtl_TextEncoding eDefaultEncoding;
162 rtl_TextEncoding eCurrentEncoding;
163 // This is used by OutputFlyFrame_Impl() to control the written syntax
164 bool bRTFFlySyntax;
165
166 sal_Bool m_bOutStyleTab : 1;
167 SvStream& Strm();
168 SvStream& OutULong( sal_uLong nVal );
169 SvStream& OutLong( long nVal );
170 void OutUnicode(const sal_Char *pToken, const String &rContent);
171 void OutDateTime(const sal_Char* pStr, const util::DateTime& rDT );
172 static rtl::OString OutChar(sal_Unicode c, int *pUCMode, rtl_TextEncoding eDestEnc);
173 static rtl::OString OutString(const String &rStr, rtl_TextEncoding eDestEnc);
174 static rtl::OString OutHex(sal_uLong nHex, sal_uInt8 nLen);
175 void OutPageDescription( const SwPageDesc& rPgDsc, sal_Bool bWriteReset, sal_Bool bCheckForFirstPage );
176
177 sal_uInt16 GetColor( const Color& rColor ) const;
178 void InsColor( const Color& rCol );
179 void InsColorLine( const SvxBoxItem& rBox );
180 void OutColorTable();
181 sal_uInt16 GetRedline( const String& rAuthor );
182 const String* GetRedline( sal_uInt16 nId );
183
184 void InsStyle( sal_uInt16 nId, const rtl::OString& rStyle );
185 rtl::OString* GetStyle( sal_uInt16 nId );
186
187 private:
188 // No copying.
189 RtfExport( const RtfExport& );
190
191 // No copying.
192 RtfExport& operator=( const RtfExport& );
193
194 void WriteFonts();
195 void WriteStyles();
196 void WriteMainText();
197 void WriteInfo();
198 // Writes the writer-specific \pgdsctbl group.
199 void WritePageDescTable();
200 // This is necessary to have the numbering table ready before the main text is being processed.
201 void BuildNumbering();
202 void WriteHeaderFooter(const SfxPoolItem& rItem, bool bHeader);
203 void WriteHeaderFooter(const SwFrmFmt& rFmt, bool bHeader, const sal_Char* pStr);
204
205 RtfColorTbl m_aColTbl;
206 RtfStyleTbl m_aStyTbl;
207 RtfRedlineTbl m_aRedlineTbl;
208 };
209
210 #endif // _RTFEXPORT_HXX_
211
212 /* vim: set noet sw=4 ts=4: */
213