Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_SW_SOURCE_FILTER_WW8_DOCXEXPORT_HXX
21 : #define INCLUDED_SW_SOURCE_FILTER_WW8_DOCXEXPORT_HXX
22 :
23 : #include "wrtww8.hxx"
24 :
25 : #include <sax/fshelper.hxx>
26 : #include <sax/fastattribs.hxx>
27 : #include <rtl/ustring.hxx>
28 :
29 : #include <cstdio>
30 : #include <vector>
31 : #include <boost/optional.hpp>
32 : #include <ndole.hxx>
33 :
34 : class DocxAttributeOutput;
35 : class DocxExportFilter;
36 : class SwNode;
37 : class SwEndNode;
38 : class SwTableNode;
39 : class SwTxtNode;
40 : class SwGrfNode;
41 : class SwOLENode;
42 : class DocxSdrExport;
43 :
44 : namespace oox {
45 : namespace drawingml { class DrawingML; }
46 : namespace vml { class VMLExport; }
47 : }
48 :
49 : namespace com { namespace sun { namespace star {
50 : namespace frame { class XModel; }
51 : namespace drawing { class XShape; }
52 : } } }
53 :
54 : /// Data to be written in the document settings part of the document
55 : struct DocxSettingsData
56 : {
57 : DocxSettingsData();
58 : bool hasData() const; /// returns true if there are any non-default settings (i.e. something to write)
59 : bool evenAndOddHeaders;
60 : int defaultTabStop;
61 : bool trackRevisions; // Should 'Track Revisions' be set
62 : };
63 :
64 : /// The class that does all the actual DOCX export-related work.
65 : class DocxExport : public MSWordExportBase
66 : {
67 : /// Pointer to the filter that owns us.
68 : DocxExportFilter *m_pFilter;
69 :
70 : /// Fast serializer for the document output.
71 : ::sax_fastparser::FSHelperPtr m_pDocumentFS;
72 :
73 : /// Fast serializer to output the data.
74 : ::sax_fastparser::FSHelperPtr mpFS;
75 :
76 : /// Access to the DrawingML writer.
77 : oox::drawingml::DrawingML *m_pDrawingML;
78 :
79 : /// Attribute output for document.
80 : DocxAttributeOutput *m_pAttrOutput;
81 :
82 : /// Sections/headers/footers
83 : MSWordSections *m_pSections;
84 :
85 : /// Header counter.
86 : sal_Int32 m_nHeaders;
87 :
88 : /// Footer counter.
89 : sal_Int32 m_nFooters;
90 :
91 : /// OLE objects counter.
92 : sal_Int32 m_nOLEObjects;
93 :
94 : ///Footer and Header counter in Section properties
95 : sal_Int32 m_nHeadersFootersInSection;
96 :
97 : /// Exporter of the VML shapes.
98 : oox::vml::VMLExport *m_pVMLExport;
99 :
100 : /// Exporter of drawings.
101 : DocxSdrExport* m_pSdrExport;
102 :
103 : DocxSettingsData m_aSettings;
104 :
105 : public:
106 :
107 21650 : DocxExportFilter& GetFilter() { return *m_pFilter; };
108 6496 : const DocxExportFilter& GetFilter() const { return *m_pFilter; };
109 :
110 : /// Access to the attribute output class.
111 : virtual AttributeOutputBase& AttrOutput() const SAL_OVERRIDE;
112 :
113 : /// Access to the derived attribute output class.
114 : virtual DocxAttributeOutput& DocxAttrOutput() const;
115 :
116 : /// Access to the sections/headers/footres.
117 : virtual MSWordSections& Sections() const SAL_OVERRIDE;
118 :
119 : /// Determines if the format is expected to support unicode.
120 69118 : virtual bool SupportsUnicode() const SAL_OVERRIDE { return true; }
121 :
122 164 : virtual bool SupportsOneColumnBreak() const SAL_OVERRIDE { return true; }
123 :
124 22 : virtual bool FieldsQuoted() const SAL_OVERRIDE { return true; }
125 :
126 18 : virtual bool AddSectionBreaksForTOX() const SAL_OVERRIDE { return true; }
127 :
128 : virtual bool ignoreAttributeForStyles( sal_uInt16 nWhich ) const SAL_OVERRIDE;
129 :
130 334 : virtual bool PreferPageBreakBefore() const SAL_OVERRIDE { return false; }
131 :
132 : /// Guess the script (asian/western).
133 : virtual bool CollapseScriptsforWordOk( sal_uInt16 nScript, sal_uInt16 nWhich ) SAL_OVERRIDE;
134 :
135 : virtual void AppendBookmarks( const SwTxtNode& rNode, sal_Int32 nAktPos, sal_Int32 nLen ) SAL_OVERRIDE;
136 :
137 : virtual void AppendBookmark( const OUString& rName, bool bSkip = false ) SAL_OVERRIDE;
138 :
139 : virtual void AppendAnnotationMarks( const SwTxtNode& rNode, sal_Int32 nAktPos, sal_Int32 nLen ) SAL_OVERRIDE;
140 :
141 : virtual void ExportGrfBullet(const SwTxtNode&) SAL_OVERRIDE;
142 :
143 : /// Returns the relationd id
144 : OString AddRelation( const OUString& rType, const OUString& rTarget );
145 :
146 12482 : virtual void WriteCR( ww8::WW8TableNodeInfoInner::Pointer_t /*pTableTextNodeInfoInner = ww8::WW8TableNodeInfoInner::Pointer_t()*/ ) SAL_OVERRIDE { /* FIXME no-op for docx, most probably should not even be in MSWordExportBase */ }
147 0 : virtual void WriteChar( sal_Unicode ) SAL_OVERRIDE { /* FIXME */ fprintf( stderr, "HACK! WriteChar() has nothing to do for docx.\n" ); }
148 :
149 : /// Return value indicates if an inherited outline numbering is suppressed.
150 : virtual bool DisallowInheritingOutlineNumbering( const SwFmt &rFmt ) SAL_OVERRIDE;
151 :
152 : /// Output the actual headers and footers.
153 : virtual void WriteHeadersFooters( sal_uInt8 nHeadFootFlags,
154 : const SwFrmFmt& rFmt, const SwFrmFmt& rLeftFmt, const SwFrmFmt& rFirstPageFmt, sal_uInt8 nBreakCode ) SAL_OVERRIDE;
155 :
156 : /// Write the field
157 : virtual void OutputField( const SwField* pFld, ww::eField eFldType,
158 : const OUString& rFldCmd, sal_uInt8 nMode = nsFieldFlags::WRITEFIELD_ALL ) SAL_OVERRIDE;
159 :
160 : /// Write the data of the form field
161 : virtual void WriteFormData( const ::sw::mark::IFieldmark& rFieldmark ) SAL_OVERRIDE;
162 : virtual void WriteHyperlinkData( const ::sw::mark::IFieldmark& rFieldmark ) SAL_OVERRIDE;
163 :
164 : virtual void DoComboBox(const OUString &rName,
165 : const OUString &rHelp,
166 : const OUString &ToolTip,
167 : const OUString &rSelected,
168 : com::sun::star::uno::Sequence<OUString> &rListItems) SAL_OVERRIDE;
169 :
170 : virtual void DoFormText(const SwInputField * pFld) SAL_OVERRIDE;
171 :
172 : virtual sal_uLong ReplaceCr( sal_uInt8 nChar ) SAL_OVERRIDE;
173 :
174 : /// Returns the relationd id
175 : OString OutputChart( com::sun::star::uno::Reference< com::sun::star::frame::XModel >& xModel, sal_Int32 nCount, ::sax_fastparser::FSHelperPtr m_pSerializer );
176 : OString WriteOLEObject( SwOLEObj& rObject, const OUString& sMediaType, const OUString& sRelationType, const OUString& sFileExtension );
177 : bool lcl_CopyStream( css::uno::Reference< css::io::XInputStream> xIn, css::uno::Reference< css::io::XOutputStream > xOut );
178 :
179 : /// Writes the shape using drawingML syntax.
180 : void OutputDML( com::sun::star::uno::Reference< com::sun::star::drawing::XShape >& xShape );
181 :
182 : void WriteOutliner(const OutlinerParaObject& rOutliner, sal_uInt8 nTyp);
183 :
184 : protected:
185 : /// Format-dependent part of the actual export.
186 : virtual void ExportDocument_Impl() SAL_OVERRIDE;
187 :
188 : /// Output page/section breaks
189 : virtual void OutputPageSectionBreaks( const SwTxtNode& );
190 :
191 : /// Output SwEndNode
192 : virtual void OutputEndNode( const SwEndNode& ) SAL_OVERRIDE;
193 :
194 : /// Output SwTableNode
195 : virtual void OutputTableNode( const SwTableNode& );
196 :
197 : /// Output SwGrfNode
198 : virtual void OutputGrfNode( const SwGrfNode& ) SAL_OVERRIDE;
199 :
200 : /// Output SwOLENode
201 : virtual void OutputOLENode( const SwOLENode& ) SAL_OVERRIDE;
202 :
203 : virtual void OutputLinkedOLE( const OUString& ) SAL_OVERRIDE;
204 :
205 : virtual void AppendSection( const SwPageDesc *pPageDesc, const SwSectionFmt* pFmt, sal_uLong nLnNum ) SAL_OVERRIDE;
206 :
207 12490 : virtual void SectionBreaksAndFrames( const SwTxtNode& /*rNode*/ ) SAL_OVERRIDE {}
208 :
209 : /// Get ready for a new section.
210 : virtual void PrepareNewPageDesc( const SfxItemSet* pSet,
211 : const SwNode& rNd,
212 : const SwFmtPageDesc* pNewPgDescFmt = 0,
213 : const SwPageDesc* pNewPgDesc = 0 ) SAL_OVERRIDE;
214 :
215 : private:
216 : /// Setup pStyles and write styles.xml
217 : void InitStyles();
218 :
219 : /// Write footnotes.xml and endnotes.xml.
220 : void WriteFootnotesEndnotes();
221 :
222 : /// Write comments.xml
223 : void WritePostitFields();
224 :
225 : /// Write the numbering table.
226 : virtual void WriteNumbering() SAL_OVERRIDE;
227 :
228 : /// Write reference to a header/foorter + the actual xml containing the text.
229 : void WriteHeaderFooter( const SwFmt& rFmt, bool bHeader, const char* pType );
230 :
231 : /// Write word/fontTable.xml.
232 : void WriteFonts();
233 :
234 : /// Write docProps/core.xml
235 : void WriteProperties();
236 :
237 : /// Write word/settings.xml
238 : void WriteSettings();
239 :
240 : /// Write word/theme/theme1.xml
241 : void WriteTheme();
242 :
243 : void WriteGlossary();
244 :
245 : /// Write customXml/item[n].xml and customXml/itemProps[n].xml
246 : void WriteCustomXml();
247 :
248 : /// Write word/activeX/activeX[n].xml
249 : void WriteActiveX();
250 :
251 : /// Write word/embeddings/Worksheet[n].xlsx
252 : void WriteEmbeddings();
253 :
254 : /// Get background color of the document, if there is one.
255 : boost::optional<SvxBrushItem> getBackground();
256 :
257 : /// return true if Page Layout is set as Mirrored
258 : bool isMirroredMargin();
259 :
260 : public:
261 : /// All xml namespaces to be used at the top of any text .xml file (main doc, headers, footers,...)
262 : sax_fastparser::XFastAttributeListRef MainXmlNamespaces( sax_fastparser::FSHelperPtr serializer );
263 :
264 : /// FIXME this is temporary, remotely reminding the method of the same
265 : /// name in WW8Export.
266 : void WriteMainText();
267 :
268 : /// Pass the pDocument, pCurrentPam and pOriginalPam to the base class.
269 : DocxExport( DocxExportFilter *pFilter, SwDoc *pDocument,
270 : SwPaM *pCurrentPam, SwPaM *pOriginalPam );
271 :
272 : /// Destructor.
273 : virtual ~DocxExport();
274 :
275 : /// Reference to the VMLExport instance for the main document.
276 672 : oox::vml::VMLExport& VMLExporter() { return *m_pVMLExport; }
277 :
278 : /// Reference to the DocxSdrExport instance for the main document.
279 113558 : DocxSdrExport& SdrExporter() { return *m_pSdrExport; }
280 :
281 : /// Set the document default tab stop.
282 2228 : void setDefaultTabStop( int stop ) { m_aSettings.defaultTabStop = stop; }
283 :
284 28 : ::sax_fastparser::FSHelperPtr GetFS() { return mpFS; }
285 :
286 : void SetFS(::sax_fastparser::FSHelperPtr mpFS);
287 :
288 : private:
289 : /// No copying.
290 : DocxExport( const DocxExport& );
291 :
292 : /// No copying.
293 : DocxExport& operator=( const DocxExport& );
294 : };
295 :
296 : #endif // INCLUDED_SW_SOURCE_FILTER_WW8_DOCXEXPORT_HXX
297 :
298 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|