1 /* -*- mode: C++; tab-width: 4; c-basic-offset: 4; -*- */
2 
3 /* AbiSource
4  *
5  * Copyright (C) 2008 Firat Kiyak <firatkiyak@gmail.com>
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20  * 02110-1301 USA.
21  */
22 
23 
24 #ifndef _IE_EXP_OPENXML_H_
25 #define _IE_EXP_OPENXML_H_
26 
27 // AbiWord includes
28 #include <ie_exp.h>
29 #include <ut_debugmsg.h>
30 #include <ut_types.h>
31 #include <ut_misc.h>
32 #include <ut_assert.h>
33 #include <ut_string_class.h>
34 #include <pp_Property.h>
35 
36 #include <OXML_Document.h>
37 #include <ie_exp_OpenXML_Listener.h>
38 
39 // External includes
40 #include <gsf/gsf-outfile.h>
41 #include <gsf/gsf-outfile-zip.h>
42 #include <gsf/gsf-output-stdio.h>
43 #include <gsf/gsf-output-memory.h>
44 #include <string>
45 #include <map>
46 
47 //target streams
48 #define TARGET_DOCUMENT 0
49 #define TARGET_STYLES 1
50 #define TARGET_DOCUMENT_RELATION 2
51 #define TARGET_RELATION 3
52 #define TARGET_CONTENT 4
53 #define TARGET_NUMBERING 5
54 #define TARGET_HEADER 6
55 #define TARGET_FOOTER 7
56 #define TARGET_SETTINGS 8
57 #define TARGET_FOOTNOTE 9
58 #define TARGET_ENDNOTE 10
59 
60 class OXML_Document;
61 
62 /**
63  * Class used to export OpenXML files
64  */
65 class IE_Exp_OpenXML : public IE_Exp
66 {
67 public:
68 	IE_Exp_OpenXML (PD_Document * pDocument);
69 	virtual ~IE_Exp_OpenXML ();
70 	UT_Error startDocument();
71 	UT_Error finishDocument();
72 	UT_Error startSection();
73 	UT_Error finishSection();
74 	UT_Error startSectionProperties();
75 	UT_Error finishSectionProperties();
76 	UT_Error startParagraph(int target);
77 	UT_Error finishParagraph(int target);
78 	UT_Error startText(int target);
79 	UT_Error writeText(int target, const UT_UCS4Char* text, bool list);
80 	UT_Error finishText(int target);
81 	UT_Error startMath();
82 	UT_Error writeMath(const char* omml);
83 	UT_Error finishMath();
84 	UT_Error startRun(int target);
85 	UT_Error finishRun(int target);
86 	UT_Error startRunProperties(int target);
87 	UT_Error finishRunProperties(int target);
88 	UT_Error startParagraphProperties(int target);
89 	UT_Error finishParagraphProperties(int target);
90 	UT_Error startCellProperties(int target);
91 	UT_Error finishCellProperties(int target);
92 	UT_Error startStyle(const std::string& name, const std::string& basedon, const std::string& followedby, const std::string& type);
93 	UT_Error finishStyle();
94 	UT_Error startDocumentDefaultProperties();
95 	UT_Error finishDocumentDefaultProperties();
96 	UT_Error startRunDefaultProperties();
97 	UT_Error finishRunDefaultProperties();
98 	UT_Error startParagraphDefaultProperties();
99 	UT_Error finishParagraphDefaultProperties();
100 	UT_Error startTable();
101 	UT_Error finishTable();
102 	UT_Error startTableProperties(int target);
103 	UT_Error finishTableProperties(int target);
104 	UT_Error startTableBorderProperties(int target);
105 	UT_Error finishTableBorderProperties(int target);
106 	UT_Error startCellBorderProperties(int target);
107 	UT_Error finishCellBorderProperties(int target);
108 	UT_Error startListProperties(int target);
109 	UT_Error finishListProperties(int target);
110 	UT_Error startAbstractNumbering(int target, UT_uint32 id);
111 	UT_Error finishAbstractNumbering(int target);
112 	UT_Error startTextBox(int target, const gchar* id);
113 	UT_Error finishTextBox(int target);
114 	UT_Error startTextBoxProperties(int target);
115 	UT_Error finishTextBoxProperties(int target);
116 	UT_Error startTextBoxContent(int target);
117 	UT_Error finishTextBoxContent(int target);
118 	UT_Error startNumbering(int target, UT_uint32 id);
119 	UT_Error finishNumbering(int target);
120 	UT_Error startNumberingLevel(int target, UT_uint32 level);
121 	UT_Error finishNumberingLevel(int target);
122 	UT_Error startRow();
123 	UT_Error finishRow();
124 	UT_Error startRowProperties(int target);
125 	UT_Error finishRowProperties(int target);
126 	UT_Error startCell();
127 	UT_Error finishCell();
128 	UT_Error startTableGrid(int target);
129 	UT_Error finishTableGrid(int target);
130 	UT_Error startExternalHyperlink(const gchar* id);
131 	UT_Error startInternalHyperlink(const gchar* anchor);
132 	UT_Error setHeaderRelation(const char* relId, const char* headerId);
133 	UT_Error setFooterRelation(const char* relId, const char* footerId);
134 	UT_Error finishHyperlink();
135 	UT_Error startBookmark(const gchar* id, const gchar* name);
136 	UT_Error finishBookmark(const gchar* id);
137 	UT_Error startFootnote(const gchar* id);
138 	UT_Error finishFootnote();
139 	UT_Error startEndnote(const gchar* id);
140 	UT_Error finishEndnote();
141 	UT_Error setBold(int target);
142 	UT_Error setItalic(int target);
143 	UT_Error setUnderline(int target);
144 	UT_Error setOverline();
145 	UT_Error setLineThrough(int target);
146 	UT_Error setSuperscript(int target);
147 	UT_Error setSubscript(int target);
148 	UT_Error setTextColor(int target, const gchar* color);
149 	UT_Error setBackgroundColor(int target, const gchar* color);
150 	UT_Error setTextAlignment(int target, const gchar* alignment);
151 	UT_Error setTextIndentation(int target, const gchar* indentation);
152 	UT_Error setParagraphStyle(int target, const gchar* style);
153 	UT_Error setParagraphLeftMargin(int target, const gchar* margin);
154 	UT_Error setParagraphRightMargin(int target, const gchar* margin);
155 	UT_Error setParagraphTopMargin(int target, const gchar* margin);
156 	UT_Error setParagraphBottomMargin(int target, const gchar* margin);
157 	UT_Error setLineHeight(int target, const gchar* height);
158 	UT_Error setTabstops(int target, const gchar* tabstops);
159 	UT_Error setFontSize(int target, const gchar* size);
160 	UT_Error setFontFamily(int target, const gchar* family);
161 	UT_Error setTextDirection(int target, const gchar* direction);
162 	UT_Error setWidows(int target, const gchar* widows);
163 	UT_Error setGridSpan(int target, UT_sint32 hspan);
164 	UT_Error setVerticalMerge(int target, const char* vmerge);
165 	UT_Error setTableBorder(int target, const char* border, const char* type, const char* color, const char* size);
166 	UT_Error setGridCol(int target, const char* column);
167 	UT_Error setColumnWidth(int target, const char* width);
168 	UT_Error setRowHeight(int target, const char* height);
169 	UT_Error setListLevel(int target, const char* level);
170 	UT_Error setListFormat(int target, const char* format);
171 	UT_Error setListStartValue(int target, UT_uint32 startValue);
172 	UT_Error setListLevelText(int target, const char* text);
173 	UT_Error setListType(int target, const char* type);
174 	UT_Error setAbstractNumberingId(int target, UT_uint32 id);
175 	UT_Error setNumberingFormat(int target, const char* format);
176 	UT_Error setMultilevelType(int target, const char* type);
177 	UT_Error setHyperlinkRelation(int target, const char* id, const char* addr, const char* mode);
178 	UT_Error setImage(const char* id, const char* relId, const char* filename, const char* width, const char* height);
179 	UT_Error setPositionedImage(const char* id, const char* relId, const char* filename, const char* width, const char* height, const char* xpos, const char* ypos, const char* wrapMode);
180 	UT_Error setImageRelation(const char* filename, const char* id);
181 	UT_Error writeImage(const char* filename, const UT_ByteBuf* data);
182 	UT_Error setSimpleField(int target, const char* instr, const char* value);
183 	UT_Error setHeaderReference(const char* id, const char* type);
184 	UT_Error setFooterReference(const char* id, const char* type);
185 	UT_Error setFootnoteReference(const char* id);
186 	UT_Error setFootnoteRef();
187 	UT_Error setEndnoteReference(const char* id);
188 	UT_Error setEndnoteRef();
189 	UT_Error startHeaderStream(const char* id);
190 	UT_Error finishHeaderStream();
191 	UT_Error startFooterStream(const char* id);
192 	UT_Error finishFooterStream();
193 	UT_Error setTitlePage();
194 	UT_Error setEvenAndOddHeaders();
195 	UT_Error setColumns(int target, const gchar* num, const gchar* sep);
196 	UT_Error setContinuousSection(int target);
197 	UT_Error setPageBreak(int target);
198 	UT_Error setPageSize(int target, const char* width, const char* height, const char* orientation);
199 	UT_Error setPageMargins(int target, const char* top, const char* left, const char* right, const char* bottom);
200 	UT_Error setLanguage(int target, const gchar* lang);
201 	UT_Error setNoProof(int target);
202 	UT_Error setTextBoxWidth(int target, const gchar* width);
203 	UT_Error setTextBoxHeight(int target, const gchar* height);
getDoc()204 	PD_Document* getDoc() {return m_pDoc;};
205 
206 protected:
207     virtual UT_Error _writeDocument(void);
208 
209 private:
210 	PD_Document* m_pDoc;
211 	GsfOutfile* root; //.docx file zip root
212 	GsfOutfile* relsDir; // _rels
213 	GsfOutfile* wordDir; // word
214 	GsfOutfile* wordRelsDir; // word/_rels
215 	GsfOutfile* wordMediaDir; // word/media
216 	GsfOutput* contentTypesStream; // [Content_Types].xml
217 	GsfOutput* relStream; // _rels/.rels
218 	GsfOutput* wordRelStream; // word/_rels/document.xml.rels
219 	GsfOutput* documentStream; // word/document.xml
220 	GsfOutput* settingsStream; // word/settings.xml
221 	GsfOutput* stylesStream; // word/styles.xml
222 	GsfOutput* numberingStream; // word/numbering.xml
223 	GsfOutput* headerStream; //word/headerXX.xml
224 	GsfOutput* footerStream; //word/footerXX.xml
225 	GsfOutput* footnoteStream; //word/footnotes.xml
226 	GsfOutput* endnoteStream; //word/endnotes.xml
227 	std::map<std::string, GsfOutput*> mediaStreams; // all image filename, stream pairs
228 	std::map<std::string, GsfOutput*> headerStreams; //all header id, stream pairs
229 	std::map<std::string, GsfOutput*> footerStreams; //all footer id, stream pairs
230 
231 	bool isOverline;
232 
233 	UT_Error startNumbering();
234 	UT_Error startStyles();
235 	UT_Error startContentTypes();
236 	UT_Error startRelations();
237 	UT_Error startWordRelations();
238 	UT_Error startWordMedia();
239 	UT_Error startMainPart();
240 	UT_Error startHeaders();
241 	UT_Error startFooters();
242 	UT_Error startSettings();
243 	UT_Error startFootnotes();
244 	UT_Error startEndnotes();
245 	UT_Error finishNumbering();
246 	UT_Error finishStyles();
247 	UT_Error finishContentTypes();
248 	UT_Error finishRelations();
249 	UT_Error finishWordRelations();
250 	UT_Error finishWordMedia();
251 	UT_Error finishMainPart();
252 	UT_Error finishHeaders();
253 	UT_Error finishFooters();
254 	UT_Error finishSettings();
255 	UT_Error finishFootnotes();
256 	UT_Error finishEndnotes();
257 	UT_Error writeXmlHeader(GsfOutput* file);
258 
259 	const gchar* convertToPoints(const gchar* str);
260 	const gchar* convertToTwips(const gchar* str);
261 	const gchar* convertToPositiveTwips(const gchar* str);
262 	const gchar* convertToPositiveEmus(const gchar* str);
263 	bool isNegativeQuantity(const gchar* quantity);
264 	const gchar* convertToLines(const gchar* str);
265 	const gchar* computeFontSize(const gchar* str);
266 	const gchar* computeBorderWidth(const gchar* str);
267 
268 	GsfOutput* getTargetStream(int target);
269 	UT_Error writeTargetStream(int target, const char* str);
270 
271 	bool isListBullet(const char* str);
272 
273 	void _cleanup();
274 };
275 
276 #endif //_IE_EXP_OPENXML_H_
277 
278