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