1
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */
3
* Version: MPL 2.0 / LGPLv2.1+
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/.
9
* Major Contributor(s):
10
* Copyright (C) 2002-2004 William Lachance (wrlach@gmail.com)
11
* Copyright (C) 2002 Marc Maurer (uwog@uwog.net)
12
* Copyright (C) 2004 Fridrich Strba (fridrich.strba@bluewin.ch)
13
* Copyright (C) 2005 Net Integration Technologies (http://www.net-itech.com)
15
* For minor contributions see the git repository.
17
* Alternatively, the contents of this file may be used under the terms
18
* of the GNU Lesser General Public License Version 2.1 or later
19
* (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are
20
* applicable instead of those above.
22
* For further information visit http://libwpd.sourceforge.net
25
/* "This product is not manufactured, approved, or supported by
26
* Corel Corporation or Corel Corporation Limited."
31
#include "HtmlDocumentGenerator.h"
33
// use the BELL code to represent a TAB for now
34
#define UCS_TAB 0x0009
36
HtmlDocumentGenerator::HtmlDocumentGenerator() :
38
m_pOutputStream(&std::cout),
53
HtmlDocumentGenerator::~HtmlDocumentGenerator()
57
void HtmlDocumentGenerator::setDocumentMetaData(const WPXPropertyList &propList)
59
if (propList["meta:initial-creator"])
60
*m_pOutputStream << "<meta name=\"author\" content=\"" << propList["meta:initial-creator"]->getStr().cstr() << "\">" << std::endl;
61
if (propList["dc:creator"])
62
*m_pOutputStream << "<meta name=\"typist\" content=\"" << propList["dc:creator"]->getStr().cstr() << "\">" << std::endl;
63
if (propList["dc:subject"])
64
*m_pOutputStream << "<meta name=\"subject\" content=\"" << propList["dc:subject"]->getStr().cstr() << "\">" << std::endl;
65
if (propList["dc:publisher"])
66
*m_pOutputStream << "<meta name=\"publisher\" content=\"" << propList["dc:publisher"]->getStr().cstr() << "\">" << std::endl;
67
if (propList["meta:keyword"])
68
*m_pOutputStream << "<meta name=\"keywords\" content=\"" << propList["meta:keyword"]->getStr().cstr() << "\">" << std::endl;
69
if (propList["dc:language"])
70
*m_pOutputStream << "<meta name=\"language\" content=\"" << propList["dc:language"]->getStr().cstr() << "\">" << std::endl;
71
if (propList["dc:description"])
72
*m_pOutputStream << "<meta name=\"abstract\" content=\"" << propList["dc:description"]->getStr().cstr() << "\">" << std::endl;
73
if (propList["libwpd:descriptive-name"])
75
*m_pOutputStream << "<meta name=\"descriptive-name\" content=\"" << propList["libwpd:descriptive-name"]->getStr().cstr() << "\">" << std::endl;
76
*m_pOutputStream << "<title>" << propList["libwpd:descriptive-name"]->getStr().cstr() << "</title>" << std::endl;
78
if (propList["libwpd:descriptive-type"])
79
*m_pOutputStream << "<meta name=\"descriptive-type\" content=\"" << propList["libwpd:descriptive-type"]->getStr().cstr() << "\">" << std::endl;
82
void HtmlDocumentGenerator::startDocument()
84
*m_pOutputStream << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">" << std::endl;
85
*m_pOutputStream << "<html>" << std::endl;
86
*m_pOutputStream << "<head>" << std::endl;
87
*m_pOutputStream << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" >" << std::endl;
88
*m_pOutputStream << "</head>" << std::endl;
89
*m_pOutputStream << "<body>" << std::endl;
92
void HtmlDocumentGenerator::endDocument()
94
if (m_footNotesStream.str().length())
96
*m_pOutputStream << "<p><b>FOOTNOTES</b></p>" << std::endl;
97
*m_pOutputStream << m_footNotesStream.str() << std::endl;
99
if (m_endNotesStream.str().length())
101
*m_pOutputStream << "<p><b>ENDNOTES</b></p>" << std::endl;
102
*m_pOutputStream << m_endNotesStream.str() << std::endl;
104
if (m_commentsStream.str().length())
106
*m_pOutputStream << "<p><b>COMMENTS AND ANNOTATIONS</b></p>" << std::endl;
107
*m_pOutputStream << m_commentsStream.str() << std::endl;
109
if (m_textBoxesStream.str().length())
111
*m_pOutputStream << "<p><b>TEXT BOXES</b></p>" << std::endl;
112
*m_pOutputStream << m_textBoxesStream.str() << std::endl;
114
*m_pOutputStream << "</body>" << std::endl;
115
*m_pOutputStream << "</html>" << std::endl;
118
void HtmlDocumentGenerator::openHeader(const WPXPropertyList & /* propList */)
123
void HtmlDocumentGenerator::closeHeader()
129
void HtmlDocumentGenerator::openFooter(const WPXPropertyList & /* propList */)
134
void HtmlDocumentGenerator::closeFooter()
139
void HtmlDocumentGenerator::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector & /* tabStops */)
143
*m_pOutputStream << "<p style=\"";
145
if (propList["fo:text-align"])
148
if (propList["fo:text-align"]->getStr() == WPXString("end")) // stupid OOo convention..
149
*m_pOutputStream << "text-align:right;";
151
*m_pOutputStream << "text-align:" << propList["fo:text-align"]->getStr().cstr() << ";";
153
if (propList["fo:text-indent"])
154
*m_pOutputStream << "text-indent:" << propList["fo:text-indent"]->getStr().cstr() << ";";
156
if (propList["fo:line-height"] && propList["fo:line-height"]->getDouble() != 1.0)
157
*m_pOutputStream << "line-height:" << propList["fo:line-height"]->getDouble() << ";";
158
*m_pOutputStream << "\">";
162
void HtmlDocumentGenerator::closeParagraph()
166
*m_pOutputStream << "</p>" << std::endl;
170
void HtmlDocumentGenerator::openSpan(const WPXPropertyList &propList)
175
*m_pOutputStream << "<span style=\"";
176
if (propList["style:font-name"])
177
*m_pOutputStream << "font-family: \'" << propList["style:font-name"]->getStr().cstr() << "\';";
178
if (propList["fo:font-size"])
179
*m_pOutputStream << "font-size: " << propList["fo:font-size"]->getStr().cstr() << ";";
180
if (propList["fo:font-weight"])
181
*m_pOutputStream << "font-weight: " << propList["fo:font-weight"]->getStr().cstr() << ";";
182
if (propList["fo:font-style"])
183
*m_pOutputStream << "font-style: " << propList["fo:font-style"]->getStr().cstr() << ";";
184
if (propList["style:text-crossing-out"] && propList["style:text-crossing-out"]->getStr() == WPXString("single-line"))
185
*m_pOutputStream << "text-decoration:line-through;";
186
if (propList["style:text-underline"]) // don't know if double underline is possible
187
*m_pOutputStream << "text-decoration:underline;";
188
if (propList["style:text-blinking"])
189
*m_pOutputStream << "text-decoration:blink;";
190
if (propList["fo:color"])
191
*m_pOutputStream << "color:" << propList["fo:color"]->getStr().cstr() << ";";
192
if (propList["style:text-background-color"])
193
*m_pOutputStream << "background-color:" << propList["style:text-background-color"]->getStr().cstr() << ";";
195
*m_pOutputStream << "\">";
199
void HtmlDocumentGenerator::closeSpan()
203
*m_pOutputStream << "</span>" << std::endl;
207
void HtmlDocumentGenerator::insertTab()
211
// Does not have a lot of effect since tabs in html are ignorable white-space
212
*m_pOutputStream << "\t";
216
void HtmlDocumentGenerator::insertLineBreak()
221
*m_pOutputStream << "<br>" << std::endl;
225
void HtmlDocumentGenerator::insertText(const WPXString &text)
230
WPXString tempUTF8(text, true);
231
*m_pOutputStream << tempUTF8.cstr();
235
void HtmlDocumentGenerator::insertSpace()
239
*m_pOutputStream << " ";
243
void HtmlDocumentGenerator::openOrderedListLevel(const WPXPropertyList & /* propList */)
247
*m_pOutputStream << "<ol>" << std::endl;
251
void HtmlDocumentGenerator::closeOrderedListLevel()
255
*m_pOutputStream << "</ol>" << std::endl;
259
void HtmlDocumentGenerator::openUnorderedListLevel(const WPXPropertyList & /* propList */)
263
*m_pOutputStream << "<ul>" << std::endl;
267
void HtmlDocumentGenerator::closeUnorderedListLevel()
271
*m_pOutputStream << "</ul>" << std::endl;
276
void HtmlDocumentGenerator::openListElement(const WPXPropertyList & /* propList */, const WPXPropertyListVector &/* tabStops */)
280
*m_pOutputStream << "<li>";
284
void HtmlDocumentGenerator::closeListElement()
288
*m_pOutputStream << "</li>" << std::endl;
292
void HtmlDocumentGenerator::openFootnote(const WPXPropertyList &propList)
296
if (!m_footNotesCount++)
298
if (propList["libwpd:number"])
299
*m_pOutputStream << "<sup>(footnote: " << propList["libwpd:number"]->getStr().cstr() << ")</sup>";
300
m_pOutputStream = &m_footNotesStream;
302
if (propList["libwpd:number"])
303
*m_pOutputStream << "<p>" << propList["libwpd:number"]->getStr().cstr() << ":</p>";
305
*m_pOutputStream << "<p/>";
308
m_pOutputStream = &m_dummyStream;
312
void HtmlDocumentGenerator::closeFootnote()
316
if (!(--m_footNotesCount))
318
*m_pOutputStream << "<p/>" << std::endl;
319
m_pOutputStream = &std::cout;
324
void HtmlDocumentGenerator::openEndnote(const WPXPropertyList &propList)
328
if (!m_endNotesCount++)
330
if (propList["libwpd:number"])
331
*m_pOutputStream << "<sup>(endnote: " << propList["libwpd:number"]->getStr().cstr() << ")</sup>";
332
m_pOutputStream = &m_footNotesStream;
334
if (propList["libwpd:number"])
335
*m_pOutputStream << "<p>" << propList["libwpd:number"]->getStr().cstr() << ":</p>";
337
*m_pOutputStream << "<p/>";
340
m_pOutputStream = &m_dummyStream;
344
void HtmlDocumentGenerator::closeEndnote()
348
if (!(--m_endNotesCount))
350
*m_pOutputStream << "<p/>" << std::endl;
351
m_pOutputStream = &std::cout;
356
void HtmlDocumentGenerator::openComment(const WPXPropertyList & /*propList*/)
360
if (!m_commentsCount++)
362
*m_pOutputStream << "<sup>(comment: " << m_commentNumber << ")</sup>";
363
m_pOutputStream = &m_commentsStream;
364
*m_pOutputStream << "<p>Comment " << m_commentNumber++ << ":</p>" << std::endl;
365
*m_pOutputStream << "<p/>";
368
m_pOutputStream = &m_dummyStream;
372
void HtmlDocumentGenerator::closeComment()
376
if (!(--m_commentsCount))
378
*m_pOutputStream << "<p/>" << std::endl;
379
m_pOutputStream = &std::cout;
384
void HtmlDocumentGenerator::openTextBox(const WPXPropertyList & /*propList*/)
388
if (!m_textBoxesCount++)
390
*m_pOutputStream << "<sup>(text box: " << m_textBoxNumber << ")</sup>";
391
m_pOutputStream = &m_commentsStream;
392
*m_pOutputStream << "<p>Text Box " << m_textBoxNumber++ << ":</p>" << std::endl;
393
m_pOutputStream = &m_textBoxesStream;
394
*m_pOutputStream << "<p/>";
397
m_pOutputStream = &m_dummyStream;
401
void HtmlDocumentGenerator::closeTextBox()
405
if (!(--m_textBoxesCount))
407
*m_pOutputStream << "<p/>" << std::endl;
408
m_pOutputStream = &std::cout;
413
void HtmlDocumentGenerator::openTable(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* columns */)
417
*m_pOutputStream << "<table border=\"1\">" << std::endl;
418
*m_pOutputStream << "<tbody>" << std::endl;
422
void HtmlDocumentGenerator::openTableRow(const WPXPropertyList & /* propList */)
426
*m_pOutputStream << "<tr>" << std::endl;
430
void HtmlDocumentGenerator::closeTableRow()
434
*m_pOutputStream << "</tr>" << std::endl;
438
void HtmlDocumentGenerator::openTableCell(const WPXPropertyList &propList)
442
*m_pOutputStream << "<td style=\"";
443
if (propList["fo:background-color"])
444
*m_pOutputStream << "background-color:" << propList["fo:background-color"]->getStr().cstr() << ";";
446
*m_pOutputStream << "\" ";
448
if (propList["table:number-columns-spanned"])
449
*m_pOutputStream << "colspan=\"" << propList["table:number-columns-spanned"]->getInt() << "\" ";
450
if (propList["table:number-rows-spanned"])
451
*m_pOutputStream << "rowspan=\"" << propList["table:number-rows-spanned"]->getInt() << "\" ";
453
*m_pOutputStream << ">" << std::endl;
457
void HtmlDocumentGenerator::closeTableCell()
461
*m_pOutputStream << "</td>" << std::endl;
465
void HtmlDocumentGenerator::closeTable()
469
*m_pOutputStream << "</tbody>" << std::endl;
470
*m_pOutputStream << "</table>" << std::endl;
473
/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */