From: Fridrich S. <str...@us...> - 2008-12-03 05:28:37
|
Update of /cvsroot/libwpd/libwpd2/src/conv/html In directory ddv4jf1.ch3.sourceforge.com:/tmp/cvs-serv14836/src/conv/html Modified Files: HtmlDocumentGenerator.cpp HtmlDocumentGenerator.h Log Message: adding an WPXPropertyListVector::operator= + making wpd2html a little bit more useful Index: HtmlDocumentGenerator.h =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/conv/html/HtmlDocumentGenerator.h,v retrieving revision 1.4 retrieving revision 1.5 diff -u -d -r1.4 -r1.5 --- HtmlDocumentGenerator.h 29 Oct 2008 19:58:54 -0000 1.4 +++ HtmlDocumentGenerator.h 3 Dec 2008 05:28:07 -0000 1.5 @@ -27,6 +27,8 @@ #ifndef HTMLLISTENERIMPL_H #define HTMLLISTENERIMPL_H +#include <ostream> +#include <sstream> #include "WPXDocumentInterface.h" class HtmlDocumentGenerator : public WPXDocumentInterface @@ -91,6 +93,10 @@ private: bool m_ignore; + std::ostream *m_pOutputStream; + std::ostringstream m_footNotesStream, m_endNotesStream, m_commentsStream, m_textBoxesStream, m_dummyStream; + unsigned m_footNotesCount, m_endNotesCount, m_commentsCount, m_textBoxesCount; + unsigned m_commentNumber, m_textBoxNumber; }; Index: HtmlDocumentGenerator.cpp =================================================================== RCS file: /cvsroot/libwpd/libwpd2/src/conv/html/HtmlDocumentGenerator.cpp,v retrieving revision 1.3 retrieving revision 1.4 diff -u -d -r1.3 -r1.4 --- HtmlDocumentGenerator.cpp 9 Nov 2007 16:02:41 -0000 1.3 +++ HtmlDocumentGenerator.cpp 3 Dec 2008 05:28:07 -0000 1.4 @@ -26,13 +26,21 @@ */ #include <stdio.h> +#include <iostream> #include "HtmlDocumentGenerator.h" // use the BELL code to represent a TAB for now #define UCS_TAB 0x0009 HtmlDocumentGenerator::HtmlDocumentGenerator() : - m_ignore(false) + m_ignore(false), + m_pOutputStream(&std::cout), + m_footNotesCount(0), + m_endNotesCount(0), + m_commentsCount(0), + m_textBoxesCount(0), + m_commentNumber(1), + m_textBoxNumber(1) { } @@ -43,38 +51,57 @@ void HtmlDocumentGenerator::setDocumentMetaData(const WPXPropertyList &propList) { if (propList["author"]) - printf("<meta name=\"author\" content=\"%s\">\n", propList["author"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"author\" content=\"" << propList["author"]->getStr().cstr() << "\">" << std::endl; if (propList["subject"]) - printf("<meta name=\"subject\" content=\"%s\">\n", propList["subject"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"subject\" content=\"" << propList["subject"]->getStr().cstr() << "\">" << std::endl; if (propList["publisher"]) - printf("<meta name=\"publisher\" content=\"%s\">\n", propList["publisher"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"publisher\" content=\"" << propList["publisher"]->getStr().cstr() << "\">" << std::endl; if (propList["keywords"]) - printf("<meta name=\"keywords\" content=\"%s\">\n", propList["keywords"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"keywords\" content=\"" << propList["keywords"]->getStr().cstr() << "\">" << std::endl; if (propList["language"]) - printf("<meta name=\"language\" content=\"%s\">\n", propList["language"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"language\" content=\"" << propList["language"]->getStr().cstr() << "\">" << std::endl; if (propList["abstract"]) - printf("<meta name=\"abstract\" content=\"%s\">\n", propList["abstract"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"abstract\" content=\"" << propList["abstract"]->getStr().cstr() << "\">" << std::endl; if (propList["descriptive-name"]) - printf("<meta name=\"descriptive-name\" content=\"%s\">\n", propList["descriptive-name"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"descriptive-name\" content=\"" << propList["descriptive-name"]->getStr().cstr() << "\">" << std::endl; if (propList["descriptive-type"]) - printf("<meta name=\"descriptive-type\" content=\"%s\">\n", propList["descriptive-type"]->getStr().cstr()); + *m_pOutputStream << "<meta name=\"descriptive-type\" content=\"" << propList["descriptive-type"]->getStr().cstr() << "\">" << std::endl; } void HtmlDocumentGenerator::startDocument() { - printf("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">\n"); - printf("<html>\n"); - printf("<head>\n"); - printf("<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" >\n"); - printf("</head>\n"); - printf("<body>\n"); + *m_pOutputStream << "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\" \"http://www.w3.org/TR/REC-html40/loose.dtd\">" << std::endl; + *m_pOutputStream << "<html>" << std::endl; + *m_pOutputStream << "<head>" << std::endl; + *m_pOutputStream << "<meta http-equiv=\"content-type\" content=\"text/html; charset=UTF-8\" >" << std::endl; + *m_pOutputStream << "</head>" << std::endl; + *m_pOutputStream << "<body>" << std::endl; } void HtmlDocumentGenerator::endDocument() { - printf("\n"); - printf("</body>\n"); - printf("</html>\n"); + if (m_footNotesStream.str().length()) + { + *m_pOutputStream << "<p><b>FOOTNOTES</b></p>" << std::endl; + *m_pOutputStream << m_footNotesStream.str() << std::endl; + } + if (m_endNotesStream.str().length()) + { + *m_pOutputStream << "<p><b>ENDNOTES</b></p>" << std::endl; + *m_pOutputStream << m_endNotesStream.str() << std::endl; + } + if (m_commentsStream.str().length()) + { + *m_pOutputStream << "<p><b>COMMENTS AND ANNOTATIONS</b></p>" << std::endl; + *m_pOutputStream << m_commentsStream.str() << std::endl; + } + if (m_textBoxesStream.str().length()) + { + *m_pOutputStream << "<p><b>TEXT BOXES</b></p>" << std::endl; + *m_pOutputStream << m_textBoxesStream.str() << std::endl; + } + *m_pOutputStream << "</body>" << std::endl; + *m_pOutputStream << "</html>" << std::endl; } void HtmlDocumentGenerator::openHeader(const WPXPropertyList & /* propList */) @@ -102,22 +129,22 @@ { if (!m_ignore) { - printf("<p style=\""); + *m_pOutputStream << "<p style=\""; if (propList["fo:text-align"]) { if (propList["fo:text-align"]->getStr() == WPXString("end")) // stupid OOo convention.. - printf("text-align:right;"); + *m_pOutputStream << "text-align:right;"; else - printf("text-align:%s;", propList["fo:text-align"]->getStr().cstr()); + *m_pOutputStream << "text-align:" << propList["fo:text-align"]->getStr().cstr() << ";"; } if (propList["fo:text-indent"]) - printf("text-indent:%s;", propList["fo:text-indent"]->getStr().cstr()); + *m_pOutputStream << "text-indent:" << propList["fo:text-indent"]->getStr().cstr() << ";"; if (propList["fo:line-height"] && propList["fo:line-height"]->getFloat() != 1.0f) - printf("line-height:%f;", propList["fo:line-height"]->getFloat()); - printf("\">"); + *m_pOutputStream << "line-height:" << propList["fo:line-height"]->getFloat() << ";"; + *m_pOutputStream << "\">"; } } @@ -125,7 +152,7 @@ { if (!m_ignore) { - printf("</p>\n"); + *m_pOutputStream << "</p>" << std::endl; } } @@ -134,27 +161,27 @@ if (!m_ignore) { - printf("<span style=\""); + *m_pOutputStream << "<span style=\""; if (propList["style:font-name"]) - printf("font-family: \'%s\';", propList["style:font-name"]->getStr().cstr()); + *m_pOutputStream << "font-family: \'" << propList["style:font-name"]->getStr().cstr() << "\';"; if (propList["fo:font-size"]) - printf("font-size: %s;", propList["fo:font-size"]->getStr().cstr()); + *m_pOutputStream << "font-size: " << propList["fo:font-size"]->getStr().cstr() << ";"; if (propList["fo:font-weight"]) - printf("font-weight: %s;", propList["fo:font-weight"]->getStr().cstr()); + *m_pOutputStream << "font-weight: " << propList["fo:font-weight"]->getStr().cstr() << ";"; if (propList["fo:font-style"]) - printf("font-style: %s;", propList["fo:font-style"]->getStr().cstr()); + *m_pOutputStream << "font-style: " << propList["fo:font-style"]->getStr().cstr() << ";"; if (propList["style:text-crossing-out"] && propList["style:text-crossing-out"]->getStr() == WPXString("single-line")) - printf("text-decoration:line-through;"); + *m_pOutputStream << "text-decoration:line-through;"; if (propList["style:text-underline"]) // don't know if double underline is possible - printf("text-decoration:underline;"); + *m_pOutputStream << "text-decoration:underline;"; if (propList["style:text-blinking"]) - printf("text-decoration:blink;"); + *m_pOutputStream << "text-decoration:blink;"; if (propList["fo:color"]) - printf("color:%s;", propList["fo:color"]->getStr().cstr()); + *m_pOutputStream << "color:" << propList["fo:color"]->getStr().cstr() << ";"; if (propList["style:text-background-color"]) - printf("background-color:%s;", propList["style:text-background-color"]->getStr().cstr()); + *m_pOutputStream << "background-color:" << propList["style:text-background-color"]->getStr().cstr() << ";"; - printf("\">"); + *m_pOutputStream << "\">"; } } @@ -162,7 +189,7 @@ { if (!m_ignore) { - printf("</span>\n"); + *m_pOutputStream << "</span>" << std::endl; } } @@ -170,8 +197,8 @@ { if (!m_ignore) { - - printf("%c", UCS_TAB); + // Does not have a lot of effect since tabs in html are ignorable white-space + *m_pOutputStream << "\t"; } } @@ -180,7 +207,7 @@ if (!m_ignore) { - printf("<br>\n"); + *m_pOutputStream << "<br>" << std::endl; } } @@ -190,7 +217,7 @@ { WPXString tempUTF8(text, true); - printf("%s", tempUTF8.cstr()); + *m_pOutputStream << tempUTF8.cstr(); } } @@ -198,7 +225,7 @@ { if (!m_ignore) { - printf("<ol>\n"); + *m_pOutputStream << "<ol>" << std::endl; } } @@ -206,7 +233,7 @@ { if (!m_ignore) { - printf("</ol>\n"); + *m_pOutputStream << "</ol>" << std::endl; } } @@ -214,7 +241,7 @@ { if (!m_ignore) { - printf("<ul>\n"); + *m_pOutputStream << "<ul>" << std::endl; } } @@ -222,7 +249,7 @@ { if (!m_ignore) { - printf("</ul>\n"); + *m_pOutputStream << "</ul>" << std::endl; } } @@ -231,7 +258,7 @@ { if (!m_ignore) { - printf("<li>"); + *m_pOutputStream << "<li>"; } } @@ -239,7 +266,7 @@ { if (!m_ignore) { - printf("</li>\n"); + *m_pOutputStream << "</li>" << std::endl; } } @@ -247,11 +274,19 @@ { if (!m_ignore) { - // Cheesey hack.. - if (propList["libwpd:number"]) - printf("<p>%s:</p>", propList["libwpd:number"]->getStr().cstr()); + if (!m_footNotesCount++) + { + if (propList["libwpd:number"]) + *m_pOutputStream << "<sup>(footnote: " << propList["libwpd:number"]->getStr().cstr() << ")</sup>"; + m_pOutputStream = &m_footNotesStream; + // Cheesey hack.. + if (propList["libwpd:number"]) + *m_pOutputStream << "<p>" << propList["libwpd:number"]->getStr().cstr() << ":</p>"; + else + *m_pOutputStream << "<p/>"; + } else - printf("<p/>"); + m_pOutputStream = &m_dummyStream; } } @@ -259,7 +294,11 @@ { if (!m_ignore) { - printf("<p/>\n"); + if (!(--m_footNotesCount)) + { + *m_pOutputStream << "<p/>" << std::endl; + m_pOutputStream = &std::cout; + } } } @@ -267,11 +306,19 @@ { if (!m_ignore) { - // Cheesey hack.. - if (propList["libwpd:number"]) - printf("<p>%s:</p>", propList["libwpd:number"]->getStr().cstr()); + if (!m_endNotesCount++) + { + if (propList["libwpd:number"]) + *m_pOutputStream << "<sup>(endnote: " << propList["libwpd:number"]->getStr().cstr() << ")</sup>"; + m_pOutputStream = &m_footNotesStream; + // Cheesey hack.. + if (propList["libwpd:number"]) + *m_pOutputStream << "<p>" << propList["libwpd:number"]->getStr().cstr() << ":</p>"; + else + *m_pOutputStream << "<p/>"; + } else - printf("<p/>"); + m_pOutputStream = &m_dummyStream; } } @@ -279,7 +326,11 @@ { if (!m_ignore) { - printf("<p/>\n"); + if (!(--m_endNotesCount)) + { + *m_pOutputStream << "<p/>" << std::endl; + m_pOutputStream = &std::cout; + } } } @@ -287,7 +338,15 @@ { if (!m_ignore) { - printf("<p/>"); + if (!m_commentsCount++) + { + *m_pOutputStream << "<sup>(comment: " << m_commentNumber << ")</sup>"; + m_pOutputStream = &m_commentsStream; + *m_pOutputStream << "<p>Comment " << m_commentNumber++ << ":</p>" << std::endl; + *m_pOutputStream << "<p/>"; + } + else + m_pOutputStream = &m_dummyStream; } } @@ -295,7 +354,11 @@ { if (!m_ignore) { - printf("<p/>\n"); + if (!(--m_commentsCount)) + { + *m_pOutputStream << "<p/>" << std::endl; + m_pOutputStream = &std::cout; + } } } @@ -303,7 +366,16 @@ { if (!m_ignore) { - printf("<p/>"); + if (!m_textBoxesCount) + { + *m_pOutputStream << "<sup>(text box: " << m_textBoxNumber << ")</sup>"; + m_pOutputStream = &m_commentsStream; + *m_pOutputStream << "<p>Text Box " << m_textBoxNumber++ << ":</p>" << std::endl; + m_pOutputStream = &m_textBoxesStream; + *m_pOutputStream << "<p/>"; + } + else + m_pOutputStream = &m_dummyStream; } } @@ -311,7 +383,11 @@ { if (!m_ignore) { - printf("<p/>\n"); + if (!(--m_textBoxesCount)) + { + *m_pOutputStream << "<p/>" << std::endl; + m_pOutputStream = &std::cout; + } } } @@ -319,8 +395,8 @@ { if (!m_ignore) { - printf("<table border=\"1\">\n"); - printf("<tbody>\n"); + *m_pOutputStream << "<table border=\"1\">" << std::endl; + *m_pOutputStream << "<tbody>" << std::endl; } } @@ -328,7 +404,7 @@ { if (!m_ignore) { - printf("<tr>\n"); + *m_pOutputStream << "<tr>" << std::endl; } } @@ -336,7 +412,7 @@ { if (!m_ignore) { - printf("</tr>\n"); + *m_pOutputStream << "</tr>" << std::endl; } } @@ -344,18 +420,18 @@ { if (!m_ignore) { - printf("<td style=\""); + *m_pOutputStream << "<td style=\""; if (propList["fo:background-color"]) - printf("background-color:%s;", propList["fo:background-color"]->getStr().cstr()); + *m_pOutputStream << "background-color:" << propList["fo:background-color"]->getStr().cstr() << ";"; - printf("\" "); + *m_pOutputStream << "\" "; if (propList["table:number-columns-spanned"]) - printf("colspan=\"%d\" ", propList["table:number-columns-spanned"]->getInt()); + *m_pOutputStream << "colspan=\"" << propList["table:number-columns-spanned"]->getInt() << "\" "; if (propList["table:number-rows-spanned"]) - printf("rowspan=\"%d\" ", propList["table:number-rows-spanned"]->getInt()); + *m_pOutputStream << "rowspan=\"" << propList["table:number-rows-spanned"]->getInt() << "\" "; - printf(">\n"); + *m_pOutputStream << ">" << std::endl; } } @@ -363,7 +439,7 @@ { if (!m_ignore) { - printf("</td>\n"); + *m_pOutputStream << "</td>" << std::endl; } } @@ -371,7 +447,7 @@ { if (!m_ignore) { - printf("</tbody>\n"); - printf("</table>\n"); + *m_pOutputStream << "</tbody>" << std::endl; + *m_pOutputStream << "</table>" << std::endl; } } |