diff options
author | David Tardon <dtardon@redhat.com> | 2013-11-30 21:48:13 +0100 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2013-11-30 21:54:04 +0100 |
commit | 6d750d9f2cb98df071ebb9f107ada8d0522dc0c7 (patch) | |
tree | f5185fa21feda83dbcbf74dae3113696f6589d8f /src | |
parent | 3529ff25e73c9b67c405c3d61641ff52176b34eb (diff) |
switch to librevenge
Diffstat (limited to 'src')
-rw-r--r-- | src/conv/html/HtmlDocumentGenerator.cpp | 458 | ||||
-rw-r--r-- | src/conv/html/HtmlDocumentGenerator.h | 108 | ||||
-rw-r--r-- | src/conv/html/Makefile.am | 11 | ||||
-rw-r--r-- | src/conv/html/text6022html.cpp | 23 | ||||
-rw-r--r-- | src/conv/raw/Makefile.am | 11 | ||||
-rw-r--r-- | src/conv/raw/RawDocumentGenerator.cpp | 426 | ||||
-rw-r--r-- | src/conv/raw/RawDocumentGenerator.h | 139 | ||||
-rw-r--r-- | src/conv/raw/text6022raw.cpp | 9 | ||||
-rw-r--r-- | src/conv/text/Makefile.am | 11 | ||||
-rw-r--r-- | src/conv/text/TextDocumentGenerator.cpp | 79 | ||||
-rw-r--r-- | src/conv/text/TextDocumentGenerator.h | 98 | ||||
-rw-r--r-- | src/conv/text/text6022text.cpp | 24 | ||||
-rw-r--r-- | src/lib/Makefile.am | 6 | ||||
-rw-r--r-- | src/lib/WT602Document.cpp | 26 | ||||
-rw-r--r-- | src/lib/WT602Header.cpp | 4 | ||||
-rw-r--r-- | src/lib/WT602Header.h | 4 | ||||
-rw-r--r-- | src/lib/WT602MemoryStream.cpp | 29 | ||||
-rw-r--r-- | src/lib/WT602MemoryStream.h | 15 | ||||
-rw-r--r-- | src/lib/WT602OLEStream.cpp | 1020 | ||||
-rw-r--r-- | src/lib/WT602OLEStream.h | 135 | ||||
-rw-r--r-- | src/lib/WT602Parser.cpp | 40 | ||||
-rw-r--r-- | src/lib/WT602Parser.h | 12 | ||||
-rw-r--r-- | src/lib/libtext602_utils.cpp | 26 | ||||
-rw-r--r-- | src/lib/libtext602_utils.h | 20 |
24 files changed, 145 insertions, 2589 deletions
diff --git a/src/conv/html/HtmlDocumentGenerator.cpp b/src/conv/html/HtmlDocumentGenerator.cpp deleted file mode 100644 index 8c8ff2d..0000000 --- a/src/conv/html/HtmlDocumentGenerator.cpp +++ /dev/null @@ -1,458 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* libtext602 - * Version: MPL 2.0 / LGPLv2.1+ - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU Lesser General Public License Version 2.1 or later - * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are - * applicable instead of those above. - * - * For further information visit http://libtext602.sourceforge.net - */ - -#include <iostream> -#include <stdio.h> - -#include "HtmlDocumentGenerator.h" - -// use the BELL code to represent a TAB for now -#define UCS_TAB 0x0009 - -HtmlDocumentGenerator::HtmlDocumentGenerator() : - m_ignore(false), - m_pOutputStream(&std::cout), - m_footNotesStream(), - m_endNotesStream(), - m_commentsStream(), - m_textBoxesStream(), - m_dummyStream(), - m_footNotesCount(0), - m_endNotesCount(0), - m_commentsCount(0), - m_textBoxesCount(0), - m_commentNumber(1), - m_textBoxNumber(1) -{ -} - -HtmlDocumentGenerator::~HtmlDocumentGenerator() -{ -} - -void HtmlDocumentGenerator::setDocumentMetaData(const WPXPropertyList &propList) -{ - if (propList["author"]) - *m_pOutputStream << "<meta name=\"author\" content=\"" << propList["author"]->getStr().cstr() << "\">" << std::endl; - if (propList["subject"]) - *m_pOutputStream << "<meta name=\"subject\" content=\"" << propList["subject"]->getStr().cstr() << "\">" << std::endl; - if (propList["publisher"]) - *m_pOutputStream << "<meta name=\"publisher\" content=\"" << propList["publisher"]->getStr().cstr() << "\">" << std::endl; - if (propList["keywords"]) - *m_pOutputStream << "<meta name=\"keywords\" content=\"" << propList["keywords"]->getStr().cstr() << "\">" << std::endl; - if (propList["language"]) - *m_pOutputStream << "<meta name=\"language\" content=\"" << propList["language"]->getStr().cstr() << "\">" << std::endl; - if (propList["abstract"]) - *m_pOutputStream << "<meta name=\"abstract\" content=\"" << propList["abstract"]->getStr().cstr() << "\">" << std::endl; - if (propList["descriptive-name"]) - *m_pOutputStream << "<meta name=\"descriptive-name\" content=\"" << propList["descriptive-name"]->getStr().cstr() << "\">" << std::endl; - if (propList["descriptive-type"]) - *m_pOutputStream << "<meta name=\"descriptive-type\" content=\"" << propList["descriptive-type"]->getStr().cstr() << "\">" << std::endl; -} - -void HtmlDocumentGenerator::startDocument() -{ - *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() -{ - 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 */) -{ - m_ignore = true; -} - -void HtmlDocumentGenerator::closeHeader() -{ - m_ignore = false; -} - - -void HtmlDocumentGenerator::openFooter(const WPXPropertyList & /* propList */) -{ - m_ignore = true; -} - -void HtmlDocumentGenerator::closeFooter() -{ - m_ignore = false; -} - -void HtmlDocumentGenerator::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector & /* tabStops */) -{ - if (!m_ignore) - { - *m_pOutputStream << "<p style=\""; - - if (propList["fo:text-align"]) - { - - if (propList["fo:text-align"]->getStr() == WPXString("end")) // stupid OOo convention.. - *m_pOutputStream << "text-align:right;"; - else - *m_pOutputStream << "text-align:" << propList["fo:text-align"]->getStr().cstr() << ";"; - } - if (propList["fo:text-indent"]) - *m_pOutputStream << "text-indent:" << propList["fo:text-indent"]->getStr().cstr() << ";"; - - if (propList["fo:line-height"] && propList["fo:line-height"]->getDouble() != 1.0) - *m_pOutputStream << "line-height:" << propList["fo:line-height"]->getDouble() << ";"; - *m_pOutputStream << "\">"; - } -} - -void HtmlDocumentGenerator::closeParagraph() -{ - if (!m_ignore) - { - *m_pOutputStream << "</p>" << std::endl; - } -} - -void HtmlDocumentGenerator::openSpan(const WPXPropertyList &propList) -{ - if (!m_ignore) - { - - *m_pOutputStream << "<span style=\""; - if (propList["style:font-name"]) - *m_pOutputStream << "font-family: \'" << propList["style:font-name"]->getStr().cstr() << "\';"; - if (propList["fo:font-size"]) - *m_pOutputStream << "font-size: " << propList["fo:font-size"]->getStr().cstr() << ";"; - if (propList["fo:font-weight"]) - *m_pOutputStream << "font-weight: " << propList["fo:font-weight"]->getStr().cstr() << ";"; - if (propList["fo:font-style"]) - *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")) - *m_pOutputStream << "text-decoration:line-through;"; - if (propList["style:text-underline"]) // don't know if double underline is possible - *m_pOutputStream << "text-decoration:underline;"; - if (propList["style:text-blinking"]) - *m_pOutputStream << "text-decoration:blink;"; - if (propList["fo:color"]) - *m_pOutputStream << "color:" << propList["fo:color"]->getStr().cstr() << ";"; - if (propList["style:text-background-color"]) - *m_pOutputStream << "background-color:" << propList["style:text-background-color"]->getStr().cstr() << ";"; - - *m_pOutputStream << "\">"; - } -} - -void HtmlDocumentGenerator::closeSpan() -{ - if (!m_ignore) - { - *m_pOutputStream << "</span>" << std::endl; - } -} - -void HtmlDocumentGenerator::insertTab() -{ - if (!m_ignore) - { - // Does not have a lot of effect since tabs in html are ignorable white-space - *m_pOutputStream << "\t"; - } -} - -void HtmlDocumentGenerator::insertLineBreak() -{ - if (!m_ignore) - { - - *m_pOutputStream << "<br>" << std::endl; - } -} - -void HtmlDocumentGenerator::insertText(const WPXString &text) -{ - if (!m_ignore) - { - - WPXString tempUTF8(text, true); - *m_pOutputStream << tempUTF8.cstr(); - } -} - -void HtmlDocumentGenerator::insertSpace() -{ - if (!m_ignore) - { - *m_pOutputStream << " "; - } -} - -void HtmlDocumentGenerator::openOrderedListLevel(const WPXPropertyList & /* propList */) -{ - if (!m_ignore) - { - *m_pOutputStream << "<ol>" << std::endl; - } -} - -void HtmlDocumentGenerator::closeOrderedListLevel() -{ - if (!m_ignore) - { - *m_pOutputStream << "</ol>" << std::endl; - } -} - -void HtmlDocumentGenerator::openUnorderedListLevel(const WPXPropertyList & /* propList */) -{ - if (!m_ignore) - { - *m_pOutputStream << "<ul>" << std::endl; - } -} - -void HtmlDocumentGenerator::closeUnorderedListLevel() -{ - if (!m_ignore) - { - *m_pOutputStream << "</ul>" << std::endl; - } -} - - -void HtmlDocumentGenerator::openListElement(const WPXPropertyList & /* propList */, const WPXPropertyListVector &/* tabStops */) -{ - if (!m_ignore) - { - *m_pOutputStream << "<li>"; - } -} - -void HtmlDocumentGenerator::closeListElement() -{ - if (!m_ignore) - { - *m_pOutputStream << "</li>" << std::endl; - } -} - -void HtmlDocumentGenerator::openFootnote(const WPXPropertyList &propList) -{ - if (!m_ignore) - { - 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 - m_pOutputStream = &m_dummyStream; - } -} - -void HtmlDocumentGenerator::closeFootnote() -{ - if (!m_ignore) - { - if (!(--m_footNotesCount)) - { - *m_pOutputStream << "<p/>" << std::endl; - m_pOutputStream = &std::cout; - } - } -} - -void HtmlDocumentGenerator::openEndnote(const WPXPropertyList &propList) -{ - if (!m_ignore) - { - 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 - m_pOutputStream = &m_dummyStream; - } -} - -void HtmlDocumentGenerator::closeEndnote() -{ - if (!m_ignore) - { - if (!(--m_endNotesCount)) - { - *m_pOutputStream << "<p/>" << std::endl; - m_pOutputStream = &std::cout; - } - } -} - -void HtmlDocumentGenerator::openComment(const WPXPropertyList & /*propList*/) -{ - if (!m_ignore) - { - 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; - } -} - -void HtmlDocumentGenerator::closeComment() -{ - if (!m_ignore) - { - if (!(--m_commentsCount)) - { - *m_pOutputStream << "<p/>" << std::endl; - m_pOutputStream = &std::cout; - } - } -} - -void HtmlDocumentGenerator::openTextBox(const WPXPropertyList & /*propList*/) -{ - if (!m_ignore) - { - 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; - } -} - -void HtmlDocumentGenerator::closeTextBox() -{ - if (!m_ignore) - { - if (!(--m_textBoxesCount)) - { - *m_pOutputStream << "<p/>" << std::endl; - m_pOutputStream = &std::cout; - } - } -} - -void HtmlDocumentGenerator::openTable(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* columns */) -{ - if (!m_ignore) - { - *m_pOutputStream << "<table border=\"1\">" << std::endl; - *m_pOutputStream << "<tbody>" << std::endl; - } -} - -void HtmlDocumentGenerator::openTableRow(const WPXPropertyList & /* propList */) -{ - if (!m_ignore) - { - *m_pOutputStream << "<tr>" << std::endl; - } -} - -void HtmlDocumentGenerator::closeTableRow() -{ - if (!m_ignore) - { - *m_pOutputStream << "</tr>" << std::endl; - } -} - -void HtmlDocumentGenerator::openTableCell(const WPXPropertyList &propList) -{ - if (!m_ignore) - { - *m_pOutputStream << "<td style=\""; - if (propList["fo:background-color"]) - *m_pOutputStream << "background-color:" << propList["fo:background-color"]->getStr().cstr() << ";"; - - *m_pOutputStream << "\" "; - - if (propList["table:number-columns-spanned"]) - *m_pOutputStream << "colspan=\"" << propList["table:number-columns-spanned"]->getInt() << "\" "; - if (propList["table:number-rows-spanned"]) - *m_pOutputStream << "rowspan=\"" << propList["table:number-rows-spanned"]->getInt() << "\" "; - - *m_pOutputStream << ">" << std::endl; - } -} - -void HtmlDocumentGenerator::closeTableCell() -{ - if (!m_ignore) - { - *m_pOutputStream << "</td>" << std::endl; - } -} - -void HtmlDocumentGenerator::closeTable() -{ - if (!m_ignore) - { - *m_pOutputStream << "</tbody>" << std::endl; - *m_pOutputStream << "</table>" << std::endl; - } -} - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/conv/html/HtmlDocumentGenerator.h b/src/conv/html/HtmlDocumentGenerator.h deleted file mode 100644 index 9078edc..0000000 --- a/src/conv/html/HtmlDocumentGenerator.h +++ /dev/null @@ -1,108 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* libtext602 - * Version: MPL 2.0 / LGPLv2.1+ - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU Lesser General Public License Version 2.1 or later - * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are - * applicable instead of those above. - * - * For further information visit http://libtext602.sourceforge.net - */ - -#ifndef HTMLDOCUMENTGENERATOR_H_INCLUDED -#define HTMLDOCUMENTGENERATOR_H_INCLUDED - -#include <ostream> -#include <sstream> - -#include <libwpd/libwpd.h> -#include <libwpd-stream/libwpd-stream.h> - -class HtmlDocumentGenerator : public WPXDocumentInterface -{ -public: - HtmlDocumentGenerator(); - virtual ~HtmlDocumentGenerator(); - - virtual void setDocumentMetaData(const WPXPropertyList &propList); - - virtual void startDocument(); - virtual void endDocument(); - - virtual void definePageStyle(const WPXPropertyList &) {} - virtual void openPageSpan(const WPXPropertyList & /* propList */) {} - virtual void closePageSpan() {} - virtual void openHeader(const WPXPropertyList &propList); - virtual void closeHeader(); - virtual void openFooter(const WPXPropertyList &propList); - virtual void closeFooter(); - - virtual void defineSectionStyle(const WPXPropertyList &, const WPXPropertyListVector &) {} - virtual void openSection(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* columns */) {} - virtual void closeSection() {} - - virtual void defineParagraphStyle(const WPXPropertyList &, const WPXPropertyListVector &) {} - virtual void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void closeParagraph(); - - virtual void defineCharacterStyle(const WPXPropertyList &) {} - virtual void openSpan(const WPXPropertyList &propList); - virtual void closeSpan(); - - virtual void insertTab(); - virtual void insertText(const WPXString &text); - virtual void insertSpace(); - virtual void insertLineBreak(); - virtual void insertField(const WPXString & /* type */, const WPXPropertyList & /* propList */) {} - - virtual void defineOrderedListLevel(const WPXPropertyList & /* propList */) {} - virtual void defineUnorderedListLevel(const WPXPropertyList & /* propList */) {} - virtual void openOrderedListLevel(const WPXPropertyList &propList); - virtual void openUnorderedListLevel(const WPXPropertyList &propList); - virtual void closeOrderedListLevel(); - virtual void closeUnorderedListLevel(); - virtual void openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void closeListElement(); - - virtual void openFootnote(const WPXPropertyList &propList); - virtual void closeFootnote(); - virtual void openEndnote(const WPXPropertyList &propList); - virtual void closeEndnote(); - virtual void openComment(const WPXPropertyList &propList); - virtual void closeComment(); - virtual void openTextBox(const WPXPropertyList &propList); - virtual void closeTextBox(); - - virtual void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns); - virtual void openTableRow(const WPXPropertyList &propList); - virtual void closeTableRow(); - virtual void openTableCell(const WPXPropertyList &propList); - virtual void closeTableCell(); - virtual void insertCoveredTableCell(const WPXPropertyList & /* propList */) {} - virtual void closeTable(); - - virtual void openFrame(const WPXPropertyList & /* propList */) {} - virtual void closeFrame() {} - - virtual void insertBinaryObject(const WPXPropertyList & /* propList */, const WPXBinaryData & /* data */) {} - virtual void insertEquation(const WPXPropertyList & /* propList */, const WPXString & /* data */) {} - -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; - // Unimplemented to prevent compiler from creating crasher ones - HtmlDocumentGenerator(const HtmlDocumentGenerator &); - HtmlDocumentGenerator &operator=(const HtmlDocumentGenerator &); -}; - -#endif // HTMLDOCUMENTGENERATOR_H_INCLUDED - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/conv/html/Makefile.am b/src/conv/html/Makefile.am index a221d15..4a202c5 100644 --- a/src/conv/html/Makefile.am +++ b/src/conv/html/Makefile.am @@ -1,20 +1,17 @@ bin_PROGRAMS = text6022html -AM_CXXFLAGS = -I$(top_srcdir)/inc $(WPD_CFLAGS) $(DEBUG_CXXFLAGS) +AM_CXXFLAGS = -I$(top_srcdir)/inc $(REVENGE_CFLAGS) $(REVENGE_GENERATORS_CFLAGS) $(REVENGE_STREAM_CFLAGS) $(DEBUG_CXXFLAGS) text6022html_DEPENDENCIES = @TEXT6022HTML_WIN32_RESOURCE@ if STATIC_TOOLS -text6022html_LDADD = ../../lib/@TEXT602_OBJDIR@/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.a $(WPD_LIBS) @TEXT6022HTML_WIN32_RESOURCE@ +text6022html_LDADD = ../../lib/@TEXT602_OBJDIR@/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.a $(REVENGE_LIBS) $(REVENGE_GENERATORS_LIBS) $(REVENGE_STREAM_LIBS) @TEXT6022HTML_WIN32_RESOURCE@ text6022html_LDFLAGS = -all-static else -text6022html_LDADD = ../../lib/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.la $(WPD_LIBS) @TEXT6022HTML_WIN32_RESOURCE@ +text6022html_LDADD = ../../lib/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.la $(REVENGE_LIBS) $(REVENGE_GENERATORS_LIBS) $(REVENGE_STREAM_LIBS) @TEXT6022HTML_WIN32_RESOURCE@ endif -text6022html_SOURCES = \ - HtmlDocumentGenerator.cpp \ - HtmlDocumentGenerator.h \ - text6022html.cpp +text6022html_SOURCES = text6022html.cpp if OS_WIN32 diff --git a/src/conv/html/text6022html.cpp b/src/conv/html/text6022html.cpp index 9454dd3..4ba57dd 100644 --- a/src/conv/html/text6022html.cpp +++ b/src/conv/html/text6022html.cpp @@ -17,12 +17,11 @@ #include <stdio.h> #include <string.h> -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge-generators/librevenge-generators.h> +#include <librevenge-stream/librevenge-stream.h> #include <libtext602/libtext602.h> -#include "HtmlDocumentGenerator.h" - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -74,12 +73,22 @@ int main(int argc, char *argv[]) if (!file) return printUsage(); - WPXFileStream input(file); + librevenge::RVNGFileStream input(file); + + librevenge::RVNGString document; + librevenge::RVNGHTMLTextGenerator documentGenerator(document); + + if (!WT602Document::isSupported(&input)) + fprintf(stderr, "unsupported file format\n"); + return 1; - HtmlDocumentGenerator documentGenerator; + if (!WT602Document::parse(&input, &documentGenerator)) + { + fprintf(stderr, "parsing failed\n"); + return 1; + } - if (WT602Document::isSupported(&input)) - return WT602Document::parse(&input, &documentGenerator); + printf("%s", document.cstr()); return 0; } diff --git a/src/conv/raw/Makefile.am b/src/conv/raw/Makefile.am index e038e22..5ceb0a3 100644 --- a/src/conv/raw/Makefile.am +++ b/src/conv/raw/Makefile.am @@ -1,20 +1,17 @@ bin_PROGRAMS = text6022raw -AM_CXXFLAGS = -I$(top_srcdir)/inc $(WPD_CFLAGS) $(DEBUG_CXXFLAGS) +AM_CXXFLAGS = -I$(top_srcdir)/inc $(REVENGE_CFLAGS) $(REVENGE_GENERATORS_CFLAGS) $(REVENGE_STREAM_CFLAGS) $(DEBUG_CXXFLAGS) text6022raw_DEPENDENCIES = @TEXT6022RAW_WIN32_RESOURCE@ if STATIC_TOOLS -text6022raw_LDADD = ../../lib/@TEXT602_OBJDIR@/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.a $(WPD_LIBS) @TEXT6022RAW_WIN32_RESOURCE@ +text6022raw_LDADD = ../../lib/@TEXT602_OBJDIR@/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.a $(REVENGE_LIBS) $(REVENGE_GENERATORS_LIBS) $(REVENGE_STREAM_LIBS) @TEXT6022RAW_WIN32_RESOURCE@ text6022raw_LDFLAGS = -all-static else -text6022raw_LDADD = ../../lib/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.la $(WPD_LIBS) @TEXT6022RAW_WIN32_RESOURCE@ +text6022raw_LDADD = ../../lib/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.la $(REVENGE_LIBS) $(REVENGE_GENERATORS_LIBS) $(REVENGE_STREAM_LIBS) @TEXT6022RAW_WIN32_RESOURCE@ endif -text6022raw_SOURCES = \ - RawDocumentGenerator.cpp \ - RawDocumentGenerator.h \ - text6022raw.cpp +text6022raw_SOURCES = text6022raw.cpp if OS_WIN32 diff --git a/src/conv/raw/RawDocumentGenerator.cpp b/src/conv/raw/RawDocumentGenerator.cpp deleted file mode 100644 index b6c9371..0000000 --- a/src/conv/raw/RawDocumentGenerator.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* libtext602 - * Version: MPL 2.0 / LGPLv2.1+ - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU Lesser General Public License Version 2.1 or later - * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are - * applicable instead of those above. - * - * For further information visit http://libtext602.sourceforge.net - */ - -#include <stdarg.h> -#include <stdio.h> - -#include "RawDocumentGenerator.h" - -#ifdef _U -#undef _U -#endif - -#define _U(M, L) \ - m_atLeastOneCallback = true; \ - if (!m_printCallgraphScore) \ - __iuprintf M; \ - else \ - m_callStack.push(L); - -#ifdef _D -#undef _D -#endif - -#define _D(M, L) \ - m_atLeastOneCallback = true; \ - if (!m_printCallgraphScore) \ - __idprintf M; \ - else \ - { \ - ListenerCallback lc = m_callStack.top(); \ - if (lc != L) \ - m_callbackMisses++; \ - m_callStack.pop(); \ - } - -RawDocumentGenerator::RawDocumentGenerator(bool printCallgraphScore) : - m_indent(0), - m_callbackMisses(0), - m_atLeastOneCallback(false), - m_printCallgraphScore(printCallgraphScore), - m_callStack() -{ -} - -RawDocumentGenerator::~RawDocumentGenerator() -{ - if (m_printCallgraphScore) - printf("%d\n", m_atLeastOneCallback ? (int)(m_callStack.size() + m_callbackMisses) : -1); -} - -void RawDocumentGenerator::__iprintf(const char *format, ...) -{ - m_atLeastOneCallback = true; - if (m_printCallgraphScore) return; - - va_list args; - va_start(args, format); - for (int i=0; i<m_indent; i++) - printf(" "); - vprintf(format, args); - va_end(args); -} - -void RawDocumentGenerator::__iuprintf(const char *format, ...) -{ - m_atLeastOneCallback = true; - va_list args; - va_start(args, format); - for (int i=0; i<m_indent; i++) - printf(" "); - vprintf(format, args); - __indentUp(); - va_end(args); -} - -void RawDocumentGenerator::__idprintf(const char *format, ...) -{ - m_atLeastOneCallback = true; - va_list args; - va_start(args, format); - __indentDown(); - for (int i=0; i<m_indent; i++) - printf(" "); - vprintf(format, args); - va_end(args); -} - -WPXString getPropString(const WPXPropertyList &propList) -{ - WPXString propString; - WPXPropertyList::Iter i(propList); - if (!i.last()) - { - propString.append(i.key()); - propString.append(": "); - propString.append(i()->getStr().cstr()); - for (; i.next(); ) - { - propString.append(", "); - propString.append(i.key()); - propString.append(": "); - propString.append(i()->getStr().cstr()); - } - } - - return propString; -} - -WPXString getPropString(const WPXPropertyListVector &itemList) -{ - WPXString propString; - - propString.append("("); - WPXPropertyListVector::Iter i(itemList); - - if (!i.last()) - { - propString.append("("); - propString.append(getPropString(i())); - propString.append(")"); - - for (; i.next();) - { - propString.append(", ("); - propString.append(getPropString(i())); - propString.append(")"); - } - - } - propString.append(")"); - - return propString; -} - -void RawDocumentGenerator::setDocumentMetaData(const WPXPropertyList &propList) -{ - if (m_printCallgraphScore) - return; - - __iprintf("setDocumentMetaData(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::startDocument() -{ - _U(("startDocument()\n"), LC_START_DOCUMENT); -} - -void RawDocumentGenerator::endDocument() -{ - _D(("endDocument()\n"), LC_START_DOCUMENT); -} - -void RawDocumentGenerator::definePageStyle(const WPXPropertyList &propList) -{ - __iprintf("definePageStyle(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::openPageSpan(const WPXPropertyList &propList) -{ - _U(("openPageSpan(%s)\n", getPropString(propList).cstr()), - LC_OPEN_PAGE_SPAN); -} - -void RawDocumentGenerator::closePageSpan() -{ - _D(("closePageSpan()\n"), - LC_OPEN_PAGE_SPAN); -} - -void RawDocumentGenerator::openHeader(const WPXPropertyList &propList) -{ - _U(("openHeader(%s)\n", - getPropString(propList).cstr()), - LC_OPEN_HEADER_FOOTER); -} - -void RawDocumentGenerator::closeHeader() -{ - _D(("closeHeader()\n"), - LC_OPEN_HEADER_FOOTER); -} - -void RawDocumentGenerator::openFooter(const WPXPropertyList &propList) -{ - _U(("openFooter(%s)\n", - getPropString(propList).cstr()), - LC_OPEN_HEADER_FOOTER); -} - -void RawDocumentGenerator::closeFooter() -{ - _D(("closeFooter()\n"), - LC_OPEN_HEADER_FOOTER); -} - -void RawDocumentGenerator::defineParagraphStyle(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) -{ - __iprintf("defineParagraphStyle(%s, tab-stops: %s)\n", getPropString(propList).cstr(), getPropString(tabStops).cstr()); -} - -void RawDocumentGenerator::openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) -{ - _U(("openParagraph(%s, tab-stops: %s)\n", getPropString(propList).cstr(), getPropString(tabStops).cstr()), - LC_OPEN_PARAGRAPH); -} - -void RawDocumentGenerator::closeParagraph() -{ - _D(("closeParagraph()\n"), LC_OPEN_PARAGRAPH); -} - -void RawDocumentGenerator::defineCharacterStyle(const WPXPropertyList &propList) -{ - __iprintf("defineCharacterStyle(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::openSpan(const WPXPropertyList &propList) -{ - _U(("openSpan(%s)\n", getPropString(propList).cstr()), LC_OPEN_SPAN); -} - -void RawDocumentGenerator::closeSpan() -{ - _D(("closeSpan()\n"), LC_OPEN_SPAN); -} - -void RawDocumentGenerator::defineSectionStyle(const WPXPropertyList &propList, const WPXPropertyListVector &columns) -{ - __iprintf("defineSectionStyle(%s, columns: %s)\n", getPropString(propList).cstr(), getPropString(columns).cstr()); -} - -void RawDocumentGenerator::openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns) -{ - _U(("openSection(%s, columns: %s)\n", getPropString(propList).cstr(), getPropString(columns).cstr()), LC_OPEN_SECTION); -} - -void RawDocumentGenerator::closeSection() -{ - _D(("closeSection()\n"), LC_OPEN_SECTION); -} - -void RawDocumentGenerator::insertTab() -{ - __iprintf("insertTab()\n"); -} - -void RawDocumentGenerator::insertSpace() -{ - __iprintf("insertSpace()\n"); -} - -void RawDocumentGenerator::insertText(const WPXString &text) -{ - __iprintf("insertText(text: %s)\n", text.cstr()); -} - -void RawDocumentGenerator::insertLineBreak() -{ - __iprintf("insertLineBreak()\n"); -} - -void RawDocumentGenerator::insertField(const WPXString &type, const WPXPropertyList &propList) -{ - __iprintf("insertField(type: %s, %s)\n", type.cstr(), getPropString(propList).cstr()); -} - -void RawDocumentGenerator::defineOrderedListLevel(const WPXPropertyList &propList) -{ - __iprintf("defineOrderedListLevel(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::defineUnorderedListLevel(const WPXPropertyList &propList) -{ - __iprintf("defineUnorderedListLevel(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::openOrderedListLevel(const WPXPropertyList &propList) -{ - _U(("openOrderedListLevel(%s)\n", getPropString(propList).cstr()), - LC_OPEN_ORDERED_LIST_LEVEL); -} - -void RawDocumentGenerator::openUnorderedListLevel(const WPXPropertyList &propList) -{ - _U(("openUnorderedListLevel(%s)\n", getPropString(propList).cstr()), - LC_OPEN_UNORDERED_LIST_LEVEL); -} - -void RawDocumentGenerator::closeOrderedListLevel() -{ - _D(("closeOrderedListLevel()\n"), - LC_OPEN_ORDERED_LIST_LEVEL); -} - -void RawDocumentGenerator::closeUnorderedListLevel() -{ - _D(("closeUnorderedListLevel()\n"), LC_OPEN_UNORDERED_LIST_LEVEL); -} - -void RawDocumentGenerator::openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops) -{ - _U(("openListElement(%s, tab-stops: %s)\n", getPropString(propList).cstr(), getPropString(tabStops).cstr()), - LC_OPEN_LIST_ELEMENT); -} - -void RawDocumentGenerator::closeListElement() -{ - _D(("closeListElement()\n"), LC_OPEN_LIST_ELEMENT); -} - -void RawDocumentGenerator::openFootnote(const WPXPropertyList &propList) -{ - _U(("openFootnote(%s)\n", getPropString(propList).cstr()), - LC_OPEN_FOOTNOTE); -} - -void RawDocumentGenerator::closeFootnote() -{ - _D(("closeFootnote()\n"), LC_OPEN_FOOTNOTE); -} - -void RawDocumentGenerator::openEndnote(const WPXPropertyList &propList) -{ - _U(("openEndnote(number: %s)\n", getPropString(propList).cstr()), - LC_OPEN_ENDNOTE); -} - -void RawDocumentGenerator::closeEndnote() -{ - _D(("closeEndnote()\n"), LC_OPEN_ENDNOTE); -} - -void RawDocumentGenerator::openComment(const WPXPropertyList &propList) -{ - _U(("openComment(%s)\n", getPropString(propList).cstr()), - LC_OPEN_COMMENT); -} - -void RawDocumentGenerator::closeComment() -{ - _D(("closeComment()\n"), LC_OPEN_COMMENT); -} - -void RawDocumentGenerator::openTextBox(const WPXPropertyList &propList) -{ - _U(("openTextBox(%s)\n", getPropString(propList).cstr()), - LC_OPEN_TEXT_BOX); -} - -void RawDocumentGenerator::closeTextBox() -{ - _D(("closeTextBox()\n"), LC_OPEN_TEXT_BOX); -} - -void RawDocumentGenerator::openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns) -{ - _U(("openTable(%s, columns: %s)\n", getPropString(propList).cstr(), getPropString(columns).cstr()), LC_OPEN_TABLE); -} - -void RawDocumentGenerator::openTableRow(const WPXPropertyList &propList) -{ - _U(("openTableRow(%s)\n", getPropString(propList).cstr()), - LC_OPEN_TABLE_ROW); -} - -void RawDocumentGenerator::closeTableRow() -{ - _D(("closeTableRow()\n"), LC_OPEN_TABLE_ROW); -} - -void RawDocumentGenerator::openTableCell(const WPXPropertyList &propList) -{ - _U(("openTableCell(%s)\n", getPropString(propList).cstr()), - LC_OPEN_TABLE_CELL); -} - -void RawDocumentGenerator::closeTableCell() -{ - _D(("closeTableCell()\n"), LC_OPEN_TABLE_CELL); -} - -void RawDocumentGenerator::insertCoveredTableCell(const WPXPropertyList &propList) -{ - __iprintf("insertCoveredTableCell(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::closeTable() -{ - _D(("closeTable()\n"), LC_OPEN_TABLE); -} - -void RawDocumentGenerator::openFrame(const WPXPropertyList &propList) -{ - _U(("openFrame(%s)\n", getPropString(propList).cstr()), - LC_OPEN_FRAME); -} - -void RawDocumentGenerator::closeFrame() -{ - _D(("closeFrame()\n"), LC_OPEN_FRAME); -} - -void RawDocumentGenerator::insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData & /* data */) -{ - __iprintf("insertBinaryObject(%s)\n", getPropString(propList).cstr()); -} - -void RawDocumentGenerator::insertEquation(const WPXPropertyList &propList, const WPXString &data) -{ - __iprintf("insertEquation(%s, text: %s)\n", getPropString(propList).cstr(), data.cstr()); -} - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/conv/raw/RawDocumentGenerator.h b/src/conv/raw/RawDocumentGenerator.h deleted file mode 100644 index f2da532..0000000 --- a/src/conv/raw/RawDocumentGenerator.h +++ /dev/null @@ -1,139 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* libtext602 - * Version: MPL 2.0 / LGPLv2.1+ - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU Lesser General Public License Version 2.1 or later - * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are - * applicable instead of those above. - * - * For further information visit http://libtext602.sourceforge.net - */ - -#ifndef RAWDOCUMENTGENERATOR_H_INCLUDED -#define RAWDOCUMENTGENERATOR_H_INCLUDED - -#include <stack> - -#include <libwpd/libwpd.h> -#include <libwpd-stream/libwpd-stream.h> - -enum ListenerCallback -{ - LC_START_DOCUMENT = 0, - LC_OPEN_PAGE_SPAN, - LC_OPEN_HEADER_FOOTER, - LC_OPEN_PARAGRAPH, - LC_OPEN_SPAN, - LC_OPEN_SECTION, - LC_OPEN_ORDERED_LIST_LEVEL, - LC_OPEN_UNORDERED_LIST_LEVEL, - LC_OPEN_LIST_ELEMENT, - LC_OPEN_FOOTNOTE, - LC_OPEN_ENDNOTE, - LC_OPEN_TABLE, - LC_OPEN_TABLE_ROW, - LC_OPEN_TABLE_CELL, - LC_OPEN_COMMENT, - LC_OPEN_TEXT_BOX, - LC_OPEN_FRAME -}; - -class RawDocumentGenerator : public WPXDocumentInterface -{ -public: - RawDocumentGenerator(bool printCallgraphScore); - virtual ~RawDocumentGenerator(); - - virtual void setDocumentMetaData(const WPXPropertyList &propList); - - virtual void startDocument(); - virtual void endDocument(); - - virtual void definePageStyle(const WPXPropertyList &propList); - virtual void openPageSpan(const WPXPropertyList &propList); - virtual void closePageSpan(); - virtual void openHeader(const WPXPropertyList &propList); - virtual void closeHeader(); - virtual void openFooter(const WPXPropertyList &propList); - virtual void closeFooter(); - - virtual void defineParagraphStyle(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void openParagraph(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void closeParagraph(); - - virtual void defineCharacterStyle(const WPXPropertyList &propList); - virtual void openSpan(const WPXPropertyList &propList); - virtual void closeSpan(); - - virtual void defineSectionStyle(const WPXPropertyList &propList, const WPXPropertyListVector &columns); - virtual void openSection(const WPXPropertyList &propList, const WPXPropertyListVector &columns); - virtual void closeSection(); - - virtual void insertTab(); - virtual void insertSpace(); - virtual void insertText(const WPXString &text); - virtual void insertLineBreak(); - virtual void insertField(const WPXString &type, const WPXPropertyList &propList); - - virtual void defineOrderedListLevel(const WPXPropertyList &propList); - virtual void defineUnorderedListLevel(const WPXPropertyList &propList); - virtual void openOrderedListLevel(const WPXPropertyList &propList); - virtual void openUnorderedListLevel(const WPXPropertyList &propList); - virtual void closeOrderedListLevel(); - virtual void closeUnorderedListLevel(); - virtual void openListElement(const WPXPropertyList &propList, const WPXPropertyListVector &tabStops); - virtual void closeListElement(); - - virtual void openFootnote(const WPXPropertyList &propList); - virtual void closeFootnote(); - virtual void openEndnote(const WPXPropertyList &propList); - virtual void closeEndnote(); - virtual void openComment(const WPXPropertyList &propList); - virtual void closeComment(); - virtual void openTextBox(const WPXPropertyList &propList); - virtual void closeTextBox(); - - virtual void openTable(const WPXPropertyList &propList, const WPXPropertyListVector &columns); - virtual void openTableRow(const WPXPropertyList &propList); - virtual void closeTableRow(); - virtual void openTableCell(const WPXPropertyList &propList); - virtual void closeTableCell(); - virtual void insertCoveredTableCell(const WPXPropertyList &propList); - virtual void closeTable(); - - virtual void openFrame(const WPXPropertyList &propList); - virtual void closeFrame(); - - virtual void insertBinaryObject(const WPXPropertyList &propList, const WPXBinaryData &data); - virtual void insertEquation(const WPXPropertyList &propList, const WPXString &data); - -private: - int m_indent; - int m_callbackMisses; - bool m_atLeastOneCallback; - bool m_printCallgraphScore; - std::stack<ListenerCallback> m_callStack; - - void __indentUp() - { - m_indent++; - } - void __indentDown() - { - if (m_indent > 0) m_indent--; - } - - void __iprintf(const char *format, ...); - void __iuprintf(const char *format, ...); - void __idprintf(const char *format, ...); - -}; - -#endif // RAWDOCUMENTGENERATOR_H_INCLUDED - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/conv/raw/text6022raw.cpp b/src/conv/raw/text6022raw.cpp index 0c51121..19de191 100644 --- a/src/conv/raw/text6022raw.cpp +++ b/src/conv/raw/text6022raw.cpp @@ -17,12 +17,11 @@ #include <stdio.h> #include <string.h> -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge-generators/librevenge-generators.h> +#include <librevenge-stream/librevenge-stream.h> #include <libtext602/libtext602.h> -#include "RawDocumentGenerator.h" - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -78,9 +77,9 @@ int main(int argc, char *argv[]) if (!file) return printUsage(); - WPXFileStream input(file); + librevenge::RVNGFileStream input(file); - RawDocumentGenerator documentGenerator(printIndentLevel); + librevenge::RVNGRawTextGenerator documentGenerator(printIndentLevel); if (WT602Document::isSupported(&input)) return WT602Document::parse(&input, &documentGenerator); diff --git a/src/conv/text/Makefile.am b/src/conv/text/Makefile.am index 69b1424..c8b492c 100644 --- a/src/conv/text/Makefile.am +++ b/src/conv/text/Makefile.am @@ -1,20 +1,17 @@ bin_PROGRAMS = text6022text -AM_CXXFLAGS = -I$(top_srcdir)/inc $(WPD_CFLAGS) $(DEBUG_CXXFLAGS) +AM_CXXFLAGS = -I$(top_srcdir)/inc $(REVENGE_CFLAGS) $(REVENGE_GENERATORS_CFLAGS) $(REVENGE_STREAM_CFLAGS) $(DEBUG_CXXFLAGS) text6022text_DEPENDENCIES = @TEXT6022TEXT_WIN32_RESOURCE@ if STATIC_TOOLS -text6022text_LDADD = ../../lib/@TEXT602_OBJDIR@/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.a $(WPD_LIBS) @TEXT6022TEXT_WIN32_RESOURCE@ +text6022text_LDADD = ../../lib/@TEXT602_OBJDIR@/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.a $(REVENGE_LIBS) $(REVENGE_GENERATORS_LIBS) $(REVENGE_STREAM_LIBS) @TEXT6022TEXT_WIN32_RESOURCE@ text6022text_LDFLAGS = -all-static else -text6022text_LDADD = ../../lib/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.la $(WPD_LIBS) @TEXT6022TEXT_WIN32_RESOURCE@ +text6022text_LDADD = ../../lib/libtext602-@TEXT602_MAJOR_VERSION@.@TEXT602_MINOR_VERSION@.la $(REVENGE_LIBS) $(REVENGE_GENERATORS_LIBS) $(REVENGE_STREAM_LIBS) @TEXT6022TEXT_WIN32_RESOURCE@ endif -text6022text_SOURCES = \ - TextDocumentGenerator.cpp \ - TextDocumentGenerator.h \ - text6022text.cpp +text6022text_SOURCES = text6022text.cpp if OS_WIN32 diff --git a/src/conv/text/TextDocumentGenerator.cpp b/src/conv/text/TextDocumentGenerator.cpp deleted file mode 100644 index ff60ca5..0000000 --- a/src/conv/text/TextDocumentGenerator.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* libtext602 - * Version: MPL 2.0 / LGPLv2.1+ - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU Lesser General Public License Version 2.1 or later - * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are - * applicable instead of those above. - * - * For further information visit http://libtext602.sourceforge.net - */ - -#include <stdio.h> - -#include "TextDocumentGenerator.h" - -// use the BELL code to represent a TAB for now -#define UCS_TAB 0x0009 - -TextDocumentGenerator::TextDocumentGenerator(const bool isInfo) : - m_isInfo(isInfo) -{ -} - -TextDocumentGenerator::~TextDocumentGenerator() -{ -} - -void TextDocumentGenerator::setDocumentMetaData(const WPXPropertyList &propList) -{ - if (!m_isInfo) - return; - WPXPropertyList::Iter propIter(propList); - for (propIter.rewind(); propIter.next(); ) - { - printf("%s %s\n", propIter.key(), propIter()->getStr().cstr()); - } -} - -void TextDocumentGenerator::closeParagraph() -{ - if (m_isInfo) - return; - printf("\n"); -} - -void TextDocumentGenerator::insertTab() -{ - if (m_isInfo) - return; - printf("%c", UCS_TAB); -} - -void TextDocumentGenerator::insertText(const WPXString &text) -{ - if (m_isInfo) - return; - printf("%s", text.cstr()); -} - -void TextDocumentGenerator::insertSpace() -{ - if (m_isInfo) - return; - printf(" "); -} - -void TextDocumentGenerator::insertLineBreak() -{ - if (m_isInfo) - return; - printf("\n"); -} - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/conv/text/TextDocumentGenerator.h b/src/conv/text/TextDocumentGenerator.h deleted file mode 100644 index e9ce786..0000000 --- a/src/conv/text/TextDocumentGenerator.h +++ /dev/null @@ -1,98 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* libtext602 - * Version: MPL 2.0 / LGPLv2.1+ - * - * This Source Code Form is subject to the terms of the Mozilla Public - * License, v. 2.0. If a copy of the MPL was not distributed with this - * file, You can obtain one at http://mozilla.org/MPL/2.0/. - * - * Alternatively, the contents of this file may be used under the terms - * of the GNU Lesser General Public License Version 2.1 or later - * (LGPLv2.1+), in which case the provisions of the LGPLv2.1+ are - * applicable instead of those above. - * - * For further information visit http://libtext602.sourceforge.net - */ - -#ifndef TEXTDOCUMENTGENERATOR_H_INCLUDED -#define TEXTDOCUMENTGENERATOR_H_INCLUDED - -#include <libwpd/libwpd.h> -#include <libwpd-stream/libwpd-stream.h> - -class TextDocumentGenerator : public WPXDocumentInterface -{ -public: - TextDocumentGenerator(const bool isInfo=false); - virtual ~TextDocumentGenerator(); - - virtual void setDocumentMetaData(const WPXPropertyList &propList); - - virtual void startDocument() {} - virtual void endDocument() {} - - virtual void definePageStyle(const WPXPropertyList &) {} - virtual void openPageSpan(const WPXPropertyList & /* propList */) {} - virtual void closePageSpan() {} - virtual void openHeader(const WPXPropertyList & /* propList */) {} - virtual void closeHeader() {} - virtual void openFooter(const WPXPropertyList & /* propList */) {} - virtual void closeFooter() {} - - virtual void defineSectionStyle(const WPXPropertyList &, const WPXPropertyListVector &) {} - virtual void openSection(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* columns */) {} - virtual void closeSection() {} - - virtual void defineParagraphStyle(const WPXPropertyList &, const WPXPropertyListVector &) {} - virtual void openParagraph(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* tabStops */) {} - virtual void closeParagraph(); - - virtual void defineCharacterStyle(const WPXPropertyList &) {} - virtual void openSpan(const WPXPropertyList & /* propList */) {} - virtual void closeSpan() {} - - virtual void insertTab(); - virtual void insertText(const WPXString &text); - virtual void insertSpace(); - virtual void insertLineBreak(); - virtual void insertField(const WPXString & /* type */, const WPXPropertyList & /* propList */) {} - - virtual void defineOrderedListLevel(const WPXPropertyList & /* propList */) {} - virtual void defineUnorderedListLevel(const WPXPropertyList & /* propList */) {} - virtual void openOrderedListLevel(const WPXPropertyList & /* propList */) {} - virtual void openUnorderedListLevel(const WPXPropertyList & /* propList */) {} - virtual void closeOrderedListLevel() {} - virtual void closeUnorderedListLevel() {} - virtual void openListElement(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* tabStops */) {} - virtual void closeListElement() {} - - virtual void openFootnote(const WPXPropertyList & /* propList */) {} - virtual void closeFootnote() {} - virtual void openEndnote(const WPXPropertyList & /* propList */) {} - virtual void closeEndnote() {} - virtual void openComment(const WPXPropertyList & /* propList */) {} - virtual void closeComment() {} - virtual void openTextBox(const WPXPropertyList & /* propList */) {} - virtual void closeTextBox() {} - - virtual void openTable(const WPXPropertyList & /* propList */, const WPXPropertyListVector & /* columns */) {} - virtual void openTableRow(const WPXPropertyList & /* propList */) {} - virtual void closeTableRow() {} - virtual void openTableCell(const WPXPropertyList & /* propList */) {} - virtual void closeTableCell() {} - virtual void insertCoveredTableCell(const WPXPropertyList & /* propList */) {} - virtual void closeTable() {} - - virtual void openFrame(const WPXPropertyList & /* propList */) {} - virtual void closeFrame() {} - - virtual void insertBinaryObject(const WPXPropertyList & /* propList */, const WPXBinaryData & /* object */) {} - virtual void insertEquation(const WPXPropertyList & /* propList */, const WPXString & /* data */) {} - -private: - bool m_isInfo; -}; - -#endif // TEXTDOCUMENTGENERATOR_H_INCLUDED - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/conv/text/text6022text.cpp b/src/conv/text/text6022text.cpp index 11455d5..9c57cd8 100644 --- a/src/conv/text/text6022text.cpp +++ b/src/conv/text/text6022text.cpp @@ -17,12 +17,11 @@ #include <stdio.h> #include <string.h> -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge-generators/librevenge-generators.h> +#include <librevenge-stream/librevenge-stream.h> #include <libtext602/libtext602.h> -#include "TextDocumentGenerator.h" - #ifdef HAVE_CONFIG_H #include "config.h" #endif @@ -78,12 +77,23 @@ int main(int argc, char *argv[]) if (!szInputFile) return printUsage(); - WPXFileStream input(szInputFile); + librevenge::RVNGFileStream input(szInputFile); + + librevenge::RVNGString document; + librevenge::RVNGTextTextGenerator documentGenerator(document, isInfo); + + if (!WT602Document::isSupported(&input)) + fprintf(stderr, "unsupported file format\n"); + return 1; + + if (!WT602Document::parse(&input, &documentGenerator)) + { + fprintf(stderr, "parsing failed\n"); + return 1; + } - TextDocumentGenerator documentGenerator(isInfo); + printf("%s", document.cstr()); - if (WT602Document::isSupported(&input)) - return WT602Document::parse(&input, &documentGenerator); return 0; } diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 62343af..6888b1f 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -10,9 +10,9 @@ libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_include_HEADERS = \ $(top_srcdir)/inc/libtext602/libtext602.h \ $(top_srcdir)/inc/libtext602/WT602Document.h -AM_CXXFLAGS = -I$(top_srcdir)/inc $(WPD_CFLAGS) $(DEBUG_CXXFLAGS) +AM_CXXFLAGS = -I$(top_srcdir)/inc $(REVENGE_CFLAGS) $(REVENGE_STREAM_CFLAGS) $(DEBUG_CXXFLAGS) -libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_la_LIBADD = $(WPD_LIBS) @LIBTEXT602_WIN32_RESOURCE@ +libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_la_LIBADD = $(REVENGE_LIBS) @LIBTEXT602_WIN32_RESOURCE@ libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_la_DEPENDENCIES = @LIBTEXT602_WIN32_RESOURCE@ libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_la_LDFLAGS = $(version_info) -export-dynamic -no-undefined libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_la_SOURCES = \ @@ -21,8 +21,6 @@ libtext602_@TEXT602_MAJOR_VERSION@_@TEXT602_MINOR_VERSION@_la_SOURCES = \ WT602Header.h \ WT602MemoryStream.cpp \ WT602MemoryStream.h \ - WT602OLEStream.cpp \ - WT602OLEStream.h \ WT602Parser.cpp \ WT602Parser.h \ libtext602_utils.cpp \ diff --git a/src/lib/WT602Document.cpp b/src/lib/WT602Document.cpp index 2ed036d..ab0d74e 100644 --- a/src/lib/WT602Document.cpp +++ b/src/lib/WT602Document.cpp @@ -14,12 +14,11 @@ * For further information visit http://libtext602.sourceforge.net */ -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge-stream/librevenge-stream.h> #include <libtext602/WT602Document.h> #include "WT602Header.h" -#include "WT602OLEStream.h" #include "WT602Parser.h" using std::string; @@ -30,26 +29,25 @@ namespace libtext602 namespace { -WPXInputStreamPtr getContent(WPXInputStream *const ip) +RVNGInputStreamPtr getContent(librevenge::RVNGInputStream *const ip) { - const WPXInputStreamPtr input(ip, WT602_shared_ptr_noop_deleter<WPXInputStream>()); - Storage storage(input); + const RVNGInputStreamPtr input(ip, WT602_shared_ptr_noop_deleter<librevenge::RVNGInputStream>()); - WPXInputStreamPtr strm; - if (storage.isOLEStream()) - strm = storage.getDocumentOLEStream(string("CONTENTS")); + RVNGInputStreamPtr strm; + if (input->isStructured()) + strm.reset(input->getSubStreamByName("CONTENTS")); return strm; } } -bool WT602Document::isSupported(WPXInputStream *input) try +bool WT602Document::isSupported(librevenge::RVNGInputStream *input) try { - WPXInputStreamPtr content = getContent(input); + RVNGInputStreamPtr content = getContent(input); if (bool(content)) { - content->seek(0, WPX_SEEK_SET); + content->seek(0, librevenge::RVNG_SEEK_SET); WT602Header header(content.get()); return header.isValid(); } @@ -61,15 +59,15 @@ catch (...) return false; } -bool WT602Document::parse(WPXInputStream *input, WPXDocumentInterface *document) try +bool WT602Document::parse(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document) try { if (!WT602Document::isSupported(input)) return false; - WPXInputStreamPtr content = getContent(input); + RVNGInputStreamPtr content = getContent(input); if (bool(content)) { - content->seek(0, WPX_SEEK_SET); + content->seek(0, librevenge::RVNG_SEEK_SET); WT602Parser parser(content.get(), document); return parser.parse(); } diff --git a/src/lib/WT602Header.cpp b/src/lib/WT602Header.cpp index c0a11ed..36fa95a 100644 --- a/src/lib/WT602Header.cpp +++ b/src/lib/WT602Header.cpp @@ -16,7 +16,7 @@ #include <algorithm> -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge-stream/librevenge-stream.h> #include "libtext602_utils.h" #include "WT602Header.h" @@ -24,7 +24,7 @@ namespace libtext602 { -WT602Header::WT602Header(WPXInputStream *const input) +WT602Header::WT602Header(librevenge::RVNGInputStream *const input) : m_length(0) , m_valid(false) { diff --git a/src/lib/WT602Header.h b/src/lib/WT602Header.h index 7fd7862..19d4365 100644 --- a/src/lib/WT602Header.h +++ b/src/lib/WT602Header.h @@ -17,7 +17,7 @@ #ifndef WT602HEADER_H_INCLUDED #define WT602HEADER_H_INCLUDED -class WPXInputStream; +#include <librevenge-stream/librevenge-stream.h> namespace libtext602 { @@ -25,7 +25,7 @@ namespace libtext602 class WT602Header { public: - explicit WT602Header(WPXInputStream *input); + explicit WT602Header(librevenge::RVNGInputStream *input); bool isValid() const; diff --git a/src/lib/WT602MemoryStream.cpp b/src/lib/WT602MemoryStream.cpp index 630fa29..b934746 100644 --- a/src/lib/WT602MemoryStream.cpp +++ b/src/lib/WT602MemoryStream.cpp @@ -36,12 +36,27 @@ WT602MemoryStream::~WT602MemoryStream() delete[] m_data; } -bool WT602MemoryStream::isOLEStream() +bool WT602MemoryStream::isStructured() { return false; } -WPXInputStream *WT602MemoryStream::getDocumentOLEStream(const char *) +unsigned WT602MemoryStream::subStreamCount() +{ + return 0; +} + +const char *WT602MemoryStream::subStreamName(unsigned) +{ + return 0; +} + +librevenge::RVNGInputStream *WT602MemoryStream::getSubStreamByName(const char *) +{ + return 0; +} + +librevenge::RVNGInputStream *WT602MemoryStream::getSubStreamById(unsigned) { return 0; } @@ -67,18 +82,18 @@ catch (...) return 0; } -int WT602MemoryStream::seek(const long offset, WPX_SEEK_TYPE seekType) try +int WT602MemoryStream::seek(const long offset, librevenge::RVNG_SEEK_TYPE seekType) try { long pos = 0; switch (seekType) { - case WPX_SEEK_SET : + case librevenge::RVNG_SEEK_SET : pos = offset; break; - case WPX_SEEK_CUR : + case librevenge::RVNG_SEEK_CUR : pos = offset + m_pos; break; - case WPX_SEEK_END : + case librevenge::RVNG_SEEK_END : pos = offset + m_length; break; default : @@ -101,7 +116,7 @@ long WT602MemoryStream::tell() return m_pos; } -bool WT602MemoryStream::atEOS() +bool WT602MemoryStream::isEnd() { return m_length == m_pos; } diff --git a/src/lib/WT602MemoryStream.h b/src/lib/WT602MemoryStream.h index b1604fd..2e3701e 100644 --- a/src/lib/WT602MemoryStream.h +++ b/src/lib/WT602MemoryStream.h @@ -17,12 +17,12 @@ #ifndef WT602MEMORYSTREAM_H_INCLUDED #define WT602MEMORYSTREAM_H_INCLUDED -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge-stream/librevenge-stream.h> namespace libtext602 { -class WT602MemoryStream : public WPXInputStream +class WT602MemoryStream : public librevenge::RVNGInputStream { // disable copying WT602MemoryStream(const WT602MemoryStream &other); @@ -32,13 +32,16 @@ public: WT602MemoryStream(const unsigned char *data, unsigned length); virtual ~WT602MemoryStream(); - virtual bool isOLEStream(); - virtual WPXInputStream *getDocumentOLEStream(const char *name); + virtual bool isStructured(); + virtual unsigned subStreamCount(); + virtual const char *subStreamName(unsigned id); + virtual librevenge::RVNGInputStream *getSubStreamByName(const char *name); + virtual librevenge::RVNGInputStream *getSubStreamById(unsigned id); virtual const unsigned char *read(unsigned long numBytes, unsigned long &numBytesRead); - virtual int seek(long offset, WPX_SEEK_TYPE seekType); + virtual int seek(long offset, librevenge::RVNG_SEEK_TYPE seekType); virtual long tell(); - virtual bool atEOS(); + virtual bool isEnd(); private: const unsigned char *m_data; diff --git a/src/lib/WT602OLEStream.cpp b/src/lib/WT602OLEStream.cpp deleted file mode 100644 index bf8b47b..0000000 --- a/src/lib/WT602OLEStream.cpp +++ /dev/null @@ -1,1020 +0,0 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ -/* POLE - Portable C++ library to access OLE Storage - Copyright (C) 2002-2005 Ariya Hidayat <ariya@kde.org> - - Performance optimization: Dmitry Fedorov - Copyright 2009 <www.bioimage.ucsb.edu> <www.dimin.net> - - Fix for more than 236 mbat block entries : Michel Boudinot - Copyright 2010 <Michel.Boudinot@inaf.cnrs-gif.fr> - - Version: 0.4 - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the authors nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. -*/ - -/* - This file is largly inspirated from libwpd WPXOLEStream.cpp -*/ - -#include <cstring> -#include <iostream> -#include <list> -#include <set> -#include <sstream> -#include <string> -#include <vector> - -#include <libwpd-stream/libwpd-stream.h> - -#include "WT602MemoryStream.h" -#include "WT602OLEStream.h" - -namespace libtext602 -{ - -namespace -{ - -static inline unsigned long readU16( const unsigned char *ptr ) -{ - return (unsigned long)(ptr[0]+(ptr[1]<<8)); -} - -static inline unsigned long readU32( const unsigned char *ptr ) -{ - return (unsigned long)(ptr[0]+(ptr[1]<<8)+(ptr[2]<<16)+(ptr[3]<<24)); -} - -} - -class Header -{ -public: - unsigned char id[8]; // signature, or magic identifier - unsigned b_shift; // bbat->blockSize = 1 << b_shift - unsigned s_shift; // sbat->blockSize = 1 << s_shift - unsigned num_bat; // blocks allocated for big bat - unsigned dirent_start; // starting block for directory info - unsigned threshold; // switch from small to big file (usually 4K) - unsigned sbat_start; // starting block index to store small bat - unsigned num_sbat; // blocks allocated for small bat - unsigned mbat_start; // starting block to store meta bat - unsigned num_mbat; // blocks allocated for meta bat - unsigned long bb_blocks[109]; - - Header(); - bool valid(); - void load( const unsigned char *buffer, unsigned long size ); -}; - -class AllocTable -{ -public: - static const unsigned Eof; - static const unsigned Avail; - static const unsigned Bat; - static const unsigned MetaBat; - unsigned blockSize; - AllocTable(); - void clear(); - unsigned long count(); - void resize( unsigned long newsize ); - void set( unsigned long index, unsigned long val ); - std::vector<unsigned long> follow( unsigned long start ); - unsigned long operator[](unsigned long index ); - void load( const unsigned char *buffer, unsigned len ); -private: - std::vector<unsigned long> data; - AllocTable( const AllocTable & ); - AllocTable &operator=( const AllocTable & ); -}; - -class DirEntry -{ -public: - DirEntry() : valid(false), name(), dir(false), size(0), start(0), - prev(0), next(0), child(0) {}; - bool valid; // false if invalid (should be skipped) - std::string name; // the name, not in unicode anymore - bool dir; // true if directory - unsigned long size; // size (not valid if directory) - unsigned long start; // starting block - unsigned prev; // previous sibling - unsigned next; // next sibling - unsigned child; // first child -}; - -class DirTree -{ -public: - static const unsigned End; - DirTree(); - void clear(); - unsigned entryCount(); - DirEntry *entry( unsigned index ); - DirEntry *entry( const std::string &name ); - unsigned find_child( unsigned index, const std::string &name ); - void load( unsigned char *buffer, unsigned len ); - std::vector<std::string> getOLENames(); - -private: - void getOLENames(unsigned index, const std::string &prefix, - std::vector<std::string> &res, std::set<unsigned> &seen); - std::vector<DirEntry> entries; - DirTree( const DirTree & ); - DirTree &operator=( const DirTree & ); -}; - -class StorageIO -{ -public: - Storage *storage; // owner - shared_ptr<WPXInputStream> input; - int result; // result of operation - - Header *header; // storage header - DirTree *dirtree; // directory tree - AllocTable *bbat; // allocation table for big blocks - AllocTable *sbat; // allocation table for small blocks - - std::vector<unsigned long> sb_blocks; // blocks for "small" files - - bool isLoadDone; - - StorageIO( Storage *storage, shared_ptr<WPXInputStream> is ); - ~StorageIO(); - - bool isOLEStream(); - void load(); - - unsigned long loadBigBlocks( std::vector<unsigned long> blocks, unsigned char *buffer, unsigned long maxlen ); - - unsigned long loadBigBlock( unsigned long block, unsigned char *buffer, unsigned long maxlen ); - - unsigned long loadSmallBlocks( std::vector<unsigned long> blocks, unsigned char *buffer, unsigned long maxlen ); - - unsigned long loadSmallBlock( unsigned long block, unsigned char *buffer, unsigned long maxlen ); - - StreamIO *streamIO( const std::string &name ); - - std::vector<std::string> getOLENames(); -private: - // no copy or assign - StorageIO( const StorageIO & ); - StorageIO &operator=( const StorageIO & ); - -}; - -class StreamIO -{ -public: - StorageIO *io; - DirEntry *entry; - std::string fullName; - bool eof; - bool fail; - - StreamIO( StorageIO *io, DirEntry *entry ); - ~StreamIO(); - unsigned long size(); - unsigned long tell(); - unsigned long read( unsigned char *data, unsigned long maxlen ); - unsigned long read( unsigned long pos, unsigned char *data, unsigned long maxlen ); - - -private: - std::vector<unsigned long> blocks; - - // no copy or assign - StreamIO( const StreamIO & ); - StreamIO &operator=( const StreamIO & ); - - // pointer for read - unsigned long m_pos; - - // simple cache system to speed-up getch() - std::vector<unsigned char> cache_data; - unsigned long cache_size; - unsigned long cache_pos; - void updateCache(); -}; - -} // namespace libtext602 - -static const unsigned char text602ole_magic[] = -{ 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 }; - - -// =========== Header ========== - -libtext602::Header::Header() : - b_shift(9), - s_shift(6), - num_bat(0), - dirent_start(0), - threshold(4096), - sbat_start(0), - num_sbat(0), - mbat_start(0), - num_mbat(0) -{ - for( unsigned i = 0; i < 8; i++ ) - id[i] = text602ole_magic[i]; - for( unsigned j=0; j<109; j++ ) - bb_blocks[j] = libtext602::AllocTable::Avail; -} - -bool libtext602::Header::valid() -{ - if( threshold != 4096 ) return false; - if( num_bat == 0 ) return false; - if( (num_bat > 109) && (num_bat > (num_mbat * 127) + 109)) return false; - if( (num_bat < 109) && (num_mbat != 0) ) return false; - if( s_shift > b_shift ) return false; - if( b_shift <= 6 ) return false; - if( b_shift >=31 ) return false; - - return true; -} - -void libtext602::Header::load( const unsigned char *buffer, unsigned long size ) -{ - if (size < 512) - return; - b_shift = (unsigned int) readU16( buffer + 0x1e ); - s_shift = (unsigned int) readU16( buffer + 0x20 ); - num_bat = (unsigned int) readU32( buffer + 0x2c ); - dirent_start = (unsigned int) readU32( buffer + 0x30 ); - threshold = (unsigned int) readU32( buffer + 0x38 ); - sbat_start = (unsigned int) readU32( buffer + 0x3c ); - num_sbat = (unsigned int) readU32( buffer + 0x40 ); - mbat_start = (unsigned int) readU32( buffer + 0x44 ); - num_mbat = (unsigned int) readU32( buffer + 0x48 ); - - for( unsigned i = 0; i < 8; i++ ) - id[i] = buffer[i]; - for( unsigned j=0; j<109; j++ ) - bb_blocks[j] = readU32( buffer + 0x4C+j*4 ); -} - - - -// =========== AllocTable ========== - -const unsigned libtext602::AllocTable::Avail = 0xffffffff; -const unsigned libtext602::AllocTable::Eof = 0xfffffffe; -const unsigned libtext602::AllocTable::Bat = 0xfffffffd; -const unsigned libtext602::AllocTable::MetaBat = 0xfffffffc; - -libtext602::AllocTable::AllocTable() : - blockSize(4096), - data() -{ - // initial size - resize( 128 ); -} - -unsigned long libtext602::AllocTable::count() -{ - return data.size(); -} - -void libtext602::AllocTable::resize( unsigned long newsize ) -{ - unsigned oldsize = unsigned(data.size()); - data.resize( newsize ); - if( newsize > oldsize ) - for( unsigned i = oldsize; i<newsize; i++ ) - data[i] = Avail; -} - -unsigned long libtext602::AllocTable::operator[]( unsigned long index ) -{ - unsigned long result; - result = data[index]; - return result; -} - -void libtext602::AllocTable::set( unsigned long index, unsigned long value ) -{ - if( index >= count() ) resize( index + 1); - data[ index ] = value; -} - -// TODO: optimize this with better search -static bool already_exist(const std::vector<unsigned long> &chain, - unsigned long item) -{ - for(unsigned i = 0; i < chain.size(); i++) - if(chain[i] == item) return true; - - return false; -} - -// follow -std::vector<unsigned long> libtext602::AllocTable::follow( unsigned long start ) -{ - std::vector<unsigned long> chain; - - if( start >= count() ) return chain; - - unsigned long p = start; - while( p < count() ) - { - if( p == (unsigned long)Eof ) break; - if( p == (unsigned long)Bat ) break; - if( p == (unsigned long)MetaBat ) break; - if( already_exist(chain, p) ) break; - chain.push_back( p ); - if( data[p] >= count() ) break; - p = data[ p ]; - } - - return chain; -} - -void libtext602::AllocTable::load( const unsigned char *buffer, unsigned len ) -{ - resize( len / 4 ); - for( unsigned i = 0; i < count(); i++ ) - set( i, readU32( buffer + i*4 ) ); -} - -// =========== DirTree ========== - -const unsigned libtext602::DirTree::End = 0xffffffff; - -libtext602::DirTree::DirTree() : - entries() -{ - clear(); -} - -void libtext602::DirTree::clear() -{ - // leave only root entry - entries.resize( 1 ); - entries[0].valid = true; - entries[0].name = "Root Entry"; - entries[0].dir = true; - entries[0].size = 0; - entries[0].start = End; - entries[0].prev = End; - entries[0].next = End; - entries[0].child = End; -} - -unsigned libtext602::DirTree::entryCount() -{ - return unsigned(entries.size()); -} - -libtext602::DirEntry *libtext602::DirTree::entry( unsigned index ) -{ - if( index >= entryCount() ) return (libtext602::DirEntry *) 0; - return &entries[ index ]; -} - -// given a fullname (e.g "/ObjectPool/_1020961869"), find the entry -libtext602::DirEntry *libtext602::DirTree::entry( const std::string &name ) -{ - - if( !name.length() ) return (libtext602::DirEntry *)0; - - // quick check for "/" (that's root) - if( name == "/" ) return entry( 0 ); - - // split the names, e.g "/ObjectPool/_1020961869" will become: - // "ObjectPool" and "_1020961869" - std::list<std::string> names; - std::string::size_type start = 0, end = 0; - if( name[0] == '/' ) start++; - while( start < name.length() ) - { - end = name.find_first_of( '/', start ); - if( end == std::string::npos ) end = name.length(); - names.push_back( name.substr( start, end-start ) ); - start = end+1; - } - - // start from root - unsigned index = 0 ; - - // trace one by one - std::list<std::string>::iterator it; - - for( it = names.begin(); it != names.end(); ++it ) - { - unsigned child = 0; - // dima: performace optimisation of the previous - child = find_child( index, *it ); - // traverse to the child - if( child > 0 ) index = child; - else return (libtext602::DirEntry *)0; - } - - return entry( index ); -} - -static unsigned dirtree_find_sibling( libtext602::DirTree *dirtree, unsigned index, const std::string &name ) -{ - - unsigned count = dirtree->entryCount(); - libtext602::DirEntry *e = dirtree->entry( index ); - if (!e || !e->valid) return 0; - if (e->name == name) return index; - - if (e->next>0 && e->next<count) - { - unsigned r = dirtree_find_sibling( dirtree, e->next, name ); - if (r>0) return r; - } - - if (e->prev>0 && e->prev<count) - { - unsigned r = dirtree_find_sibling( dirtree, e->prev, name ); - if (r>0) return r; - } - - return 0; -} - -unsigned libtext602::DirTree::find_child( unsigned index, const std::string &name ) -{ - - unsigned count = entryCount(); - libtext602::DirEntry *p = entry( index ); - if (p && p->valid && p->child < count ) - return dirtree_find_sibling( this, p->child, name ); - - return 0; -} - -void libtext602::DirTree::load( unsigned char *buffer, unsigned size ) -{ - entries.clear(); - - for( unsigned i = 0; i < size/128; i++ ) - { - unsigned p = i * 128; - - // parse name of this entry, which stored as Unicode 16-bit - std::string name; - unsigned name_len = (unsigned) readU16( buffer + 0x40+p ); - if( name_len > 64 ) name_len = 64; - for( unsigned j=0; ( buffer[j+p]) && (j<name_len); j+= 2 ) - name.append( 1, char(buffer[j+p]) ); - - // would be < 32 if first char in the name isn't printable - // first char isn't printable ? remove it... - if( buffer[p] < 32 ) - name.erase( 0,1 ); - - // 2 = file (aka stream), 1 = directory (aka storage), 5 = root - unsigned type = buffer[ 0x42 + p]; - - libtext602::DirEntry e; - e.valid = true; - e.name = name; - e.start = (unsigned int) readU32( buffer + 0x74+p ); - e.size = (unsigned int) readU32( buffer + 0x78+p ); - e.prev = (unsigned int) readU32( buffer + 0x44+p ); - e.next = (unsigned int) readU32( buffer + 0x48+p ); - e.child = (unsigned int) readU32( buffer + 0x4C+p ); - e.dir = ( type!=2 ); - - // sanity checks - if( (type != 2) && (type != 1 ) && (type != 5 ) ) e.valid = false; - if( name_len < 1 ) e.valid = false; - - entries.push_back( e ); - } -} - -std::vector<std::string> libtext602::DirTree::getOLENames() -{ - std::vector<std::string> res; - std::set<unsigned> seens; - getOLENames(0, "", res, seens); - return res; -} - -void libtext602::DirTree::getOLENames(unsigned index, const std::string &prefix, - std::vector<std::string> &res, - std::set<unsigned> &seen) -{ - if (seen.find(index) != seen.end()) - return; - seen.insert(index); - unsigned count = entryCount(); - libtext602::DirEntry *p = entry( index ); - if (!p || !p->valid) - return; - std::string name(prefix); - if (index) - { - if (p->name.length()) - name+= p->name; - else - return; - } - if (!p->dir) - { - res.push_back(name); - return; - } - if (index) - name += "/"; - std::set<unsigned> siblingsSeen; - std::vector<unsigned> siblingsStack; - siblingsStack.push_back(p->child); - siblingsSeen.insert(p->child); - while(siblingsStack.size()) - { - unsigned child = siblingsStack.back(); - siblingsStack.pop_back(); - if (seen.find(child) == seen.end()) - getOLENames(child, name, res, seen); - // look for next sibling - DirEntry *e = entry( child ); - if (!e || !e->valid) continue; - child = e->next; - if (child > 0 && child <= count - && siblingsSeen.find(child) == siblingsSeen.end()) - { - siblingsStack.push_back(child); - siblingsSeen.insert(child); - } - child = e->prev; - if (child > 0 && child <= count - && siblingsSeen.find(child) == siblingsSeen.end()) - { - siblingsStack.push_back(child); - siblingsSeen.insert(child); - } - } -} - -// =========== StorageIO ========== - -libtext602::StorageIO::StorageIO( libtext602::Storage *st, shared_ptr<WPXInputStream> is ) : - storage(st), - input( is ), - result(libtext602::Storage::Ok), - header(new libtext602::Header()), - dirtree(new libtext602::DirTree()), - bbat(new libtext602::AllocTable()), - sbat(new libtext602::AllocTable()), - sb_blocks(), - isLoadDone(false) -{ - bbat->blockSize = 1 << header->b_shift; - sbat->blockSize = 1 << header->s_shift; -} - -libtext602::StorageIO::~StorageIO() -{ - delete sbat; - delete bbat; - delete dirtree; - delete header; -} - -bool libtext602::StorageIO::isOLEStream() -{ - if (!input) return false; - long actPos = input->tell(); - load(); - input->seek(actPos, WPX_SEEK_SET); - return (result == libtext602::Storage::Ok); -} - -void libtext602::StorageIO::load() -{ - if (isLoadDone) - return; - isLoadDone = true; - std::vector<unsigned long> blocks; - - // load header - unsigned long numBytesRead = 0; - input->seek(0, WPX_SEEK_SET); - const unsigned char *buf = input->read(512, numBytesRead); - - result = libtext602::Storage::NotOLE; - if (numBytesRead < 512) - return; - - header->load( buf, numBytesRead ); - - // check OLE magic id - for( unsigned i=0; i<8; i++ ) - if( header->id[i] != text602ole_magic[i] ) - return; - - // sanity checks - result = libtext602::Storage::BadOLE; - if( !header->valid() ) return; - if( header->threshold != 4096 ) return; - - // important block size - bbat->blockSize = 1 << header->b_shift; - sbat->blockSize = 1 << header->s_shift; - - // find blocks allocated to store big bat - // the first 109 blocks are in header, the rest in meta bat - blocks.clear(); - blocks.resize( header->num_bat ); - for( unsigned j = 0; j < 109; j++ ) - if( j >= header->num_bat ) break; - else blocks[j] = header->bb_blocks[j]; - if( (header->num_bat > 109) && (header->num_mbat > 0) ) - { - std::vector<unsigned char> buffer2( bbat->blockSize ); - unsigned k = 109; - unsigned long sector; - for( unsigned r = 0; r < header->num_mbat; r++ ) - { - if(r == 0) // 1st meta bat location is in file header. - sector = header->mbat_start; - else // next meta bat location is the last current block value. - sector = blocks[--k]; - loadBigBlock( sector, &buffer2[0], bbat->blockSize ); - for( unsigned s=0; s < bbat->blockSize; s+=4 ) - { - if( k >= header->num_bat ) break; - else blocks[k++] = readU32( &buffer2[s] ); - } - } - } - - // load big bat - if( blocks.size()*bbat->blockSize > 0 ) - { - std::vector<unsigned char> buffer( blocks.size()*bbat->blockSize ); - loadBigBlocks( blocks, &buffer[0], buffer.size() ); - bbat->load( &buffer[0], (unsigned int)buffer.size() ); - } - - // load small bat - blocks.clear(); - blocks = bbat->follow( header->sbat_start ); - if( blocks.size()*bbat->blockSize > 0 ) - { - std::vector<unsigned char> buffer( blocks.size()*bbat->blockSize ); - loadBigBlocks( blocks, &buffer[0], buffer.size() ); - sbat->load( &buffer[0], (unsigned int) buffer.size() ); - } - - // load directory tree - blocks.clear(); - blocks = bbat->follow( header->dirent_start ); - if (blocks.size()*bbat->blockSize) - { - std::vector<unsigned char> buffer(blocks.size()*bbat->blockSize); - loadBigBlocks( blocks, &buffer[0], buffer.size() ); - dirtree->load( &buffer[0], (unsigned int) buffer.size() ); - if (buffer.size() >= 0x74 + 4) - { - unsigned sb_start = (unsigned) readU32( &buffer[0x74] ); - - // fetch block chain as data for small-files - sb_blocks = bbat->follow( sb_start ); // small files - - // so far so good - result = libtext602::Storage::Ok; - } - } -} - -libtext602::StreamIO *libtext602::StorageIO::streamIO( const std::string &name ) -{ - // sanity check - if( !name.length() ) return (libtext602::StreamIO *)0; - - load(); - // search in the entries - libtext602::DirEntry *entry = dirtree->entry( name ); - if( !entry ) return (libtext602::StreamIO *)0; - if( entry->dir ) return (libtext602::StreamIO *)0; - - libtext602::StreamIO *res = new libtext602::StreamIO( this, entry ); - res->fullName = name; - - return res; -} - -unsigned long libtext602::StorageIO::loadBigBlocks( std::vector<unsigned long> blocks, - unsigned char *data, unsigned long maxlen ) -{ - // sentinel - if( !data ) return 0; - if( blocks.size() < 1 ) return 0; - if( maxlen == 0 ) return 0; - - // read block one by one, seems fast enough - unsigned long bytes = 0; - for( unsigned long i=0; (i < blocks.size() ) & ( bytes<maxlen ); i++ ) - { - unsigned long block = blocks[i]; - unsigned long pos = bbat->blockSize * ( block+1 ); - unsigned long p = (bbat->blockSize < maxlen-bytes) ? bbat->blockSize : maxlen-bytes; - - input->seek(long(pos), WPX_SEEK_SET); - unsigned long numBytesRead = 0; - const unsigned char *buf = input->read(p, numBytesRead); - memcpy(data+bytes, buf, numBytesRead); - bytes += numBytesRead; - } - - return bytes; -} - -unsigned long libtext602::StorageIO::loadBigBlock( unsigned long block, - unsigned char *data, unsigned long maxlen ) -{ - // sentinel - if( !data ) return 0; - - // wraps call for loadBigBlocks - std::vector<unsigned long> blocks; - blocks.resize( 1 ); - blocks[ 0 ] = block; - - return loadBigBlocks( blocks, data, maxlen ); -} - -// return number of bytes which has been read -unsigned long libtext602::StorageIO::loadSmallBlocks( std::vector<unsigned long> blocks, - unsigned char *data, unsigned long maxlen ) -{ - // sentinel - if( !data ) return 0; - if( blocks.size() < 1 ) return 0; - if( maxlen == 0 ) return 0; - - // our own local buffer - std::vector<unsigned char> tmpBuf( bbat->blockSize ); - - // read small block one by one - unsigned long bytes = 0; - for( unsigned long i=0; ( i<blocks.size() ) & ( bytes<maxlen ); i++ ) - { - unsigned long block = blocks[i]; - - // find where the small-block exactly is - unsigned long pos = block * sbat->blockSize; - unsigned long bbindex = pos / bbat->blockSize; - if( bbindex >= sb_blocks.size() ) break; - - loadBigBlock( sb_blocks[ bbindex ], &tmpBuf[0], bbat->blockSize ); - - // copy the data - unsigned offset = unsigned(pos % bbat->blockSize); - unsigned long p = (maxlen-bytes < bbat->blockSize-offset ) ? maxlen-bytes : bbat->blockSize-offset; - p = (sbat->blockSize<p ) ? sbat->blockSize : p; - memcpy( data + bytes, &tmpBuf[offset], p ); - bytes += p; - } - - return bytes; -} - -unsigned long libtext602::StorageIO::loadSmallBlock( unsigned long block, - unsigned char *data, unsigned long maxlen ) -{ - // sentinel - if( !data ) return 0; - - // wraps call for loadSmallBlocks - std::vector<unsigned long> blocks; - blocks.resize( 1 ); - blocks.assign( 1, block ); - - return loadSmallBlocks( blocks, data, maxlen ); -} - -std::vector<std::string> libtext602::StorageIO::getOLENames() -{ - if (!dirtree) - return std::vector<std::string>(); - return dirtree->getOLENames(); -} - -// =========== StreamIO ========== - -libtext602::StreamIO::StreamIO( libtext602::StorageIO *s, libtext602::DirEntry *e) : - io(s), - entry(e), - fullName(), - eof(false), - fail(false), - blocks(), - m_pos(0), - cache_data(), - cache_size(4096), - cache_pos(0) -{ - if( entry->size >= io->header->threshold ) - blocks = io->bbat->follow( entry->start ); - else - blocks = io->sbat->follow( entry->start ); - - // prepare cache - cache_data = std::vector<unsigned char>(cache_size); - updateCache(); -} - -// FIXME tell parent we're gone -libtext602::StreamIO::~StreamIO() -{ -} - -unsigned long libtext602::StreamIO::tell() -{ - return m_pos; -} - -unsigned long libtext602::StreamIO::read( unsigned long pos, unsigned char *data, unsigned long maxlen ) -{ - // sanity checks - if( !data ) return 0; - if( maxlen == 0 ) return 0; - - unsigned long totalbytes = 0; - - if ( entry->size < io->header->threshold ) - { - // small file - unsigned long index = pos / io->sbat->blockSize; - - if( index >= blocks.size() ) return 0; - - std::vector<unsigned char> buf( io->sbat->blockSize ); - unsigned long offset = pos % io->sbat->blockSize; - while( totalbytes < maxlen ) - { - if( index >= blocks.size() ) break; - io->loadSmallBlock( blocks[index], &buf[0], io->bbat->blockSize ); - unsigned long count = io->sbat->blockSize - offset; - if( count > maxlen-totalbytes ) count = maxlen-totalbytes; - memcpy( data+totalbytes, &buf[offset], count ); - totalbytes += count; - offset = 0; - index++; - } - } - else - { - // big file - unsigned long index = pos / io->bbat->blockSize; - - if( index >= blocks.size() ) return 0; - - std::vector<unsigned char> buf( io->bbat->blockSize ); - unsigned long offset = pos % io->bbat->blockSize; - while( totalbytes < maxlen ) - { - if( index >= blocks.size() ) break; - io->loadBigBlock( blocks[index], &buf[0], io->bbat->blockSize ); - unsigned long count = io->bbat->blockSize - offset; - if( count > maxlen-totalbytes ) count = maxlen-totalbytes; - memcpy( data+totalbytes, &buf[offset], count ); - totalbytes += count; - index++; - offset = 0; - } - } - - return totalbytes; -} - -unsigned long libtext602::StreamIO::read( unsigned char *data, unsigned long maxlen ) -{ - unsigned long bytes = read( tell(), data, maxlen ); - m_pos += bytes; - return bytes; -} - -void libtext602::StreamIO::updateCache() -{ - // sanity check - if( cache_data.empty() ) return; - - cache_pos = m_pos - ( m_pos % cache_size ); - unsigned long bytes = cache_size; - if( cache_pos + bytes > entry->size ) bytes = entry->size - cache_pos; - cache_size = read( cache_pos, &cache_data[0], bytes ); -} - - -// =========== Storage ========== - -libtext602::Storage::Storage( shared_ptr<WPXInputStream> is ) : io(0) -{ - io = new StorageIO( this, is ); -} - -libtext602::Storage::~Storage() -{ - delete io; -} - -int libtext602::Storage::result() -{ - return io->result; -} - -bool libtext602::Storage::isOLEStream() -{ - return io->isOLEStream(); -} - -std::vector<std::string> libtext602::Storage::getOLENames() -{ - return io->getOLENames(); -} - -shared_ptr<WPXInputStream> libtext602::Storage::getDocumentOLEStream(const std::string &name) -{ - shared_ptr<WPXInputStream> res; - if (!isOLEStream() || !name.length()) - return res; - Stream stream(this, name); - unsigned long sz = stream.size(); - if (result() != Ok || !sz) - return res; - - unsigned char *buf = new unsigned char[sz]; - if (buf == 0) return res; - - unsigned long oleLength = stream.read(buf, sz); - if (oleLength != sz) - { - TEXT602_DEBUG_MSG(("libtext602::Storage::getDocumentOLEStream: Ole=%s expected length %ld but read %ld\n", - name.c_str(), sz, oleLength)); - - // we ignore this error, if we read a ole in the root directory - // and we read at least 50% of the data. This may help to read - // a damaged file. - bool rootDir = name.find('/', 0) == std::string::npos; - if (!rootDir || oleLength <= (sz+1)/2) - { - delete [] buf; - return res; - } - // continue - TEXT602_DEBUG_MSG(("libtext602::Storage::getDocumentOLEStream: tries to use damaged OLE: %s\n", name.c_str())); - } - - res.reset(new WT602MemoryStream(buf, (unsigned int) oleLength)); - delete [] buf; - return res; -} - -// =========== Stream ========== -libtext602::Stream::Stream( libtext602::Storage *storage, const std::string &name ) : - io(storage->io->streamIO( name )) -{ -} - -// FIXME tell parent we're gone -libtext602::Stream::~Stream() -{ - delete io; -} - -unsigned long libtext602::Stream::size() -{ - return io ? io->entry->size : 0; -} - -unsigned long libtext602::Stream::read( unsigned char *data, unsigned long maxlen ) -{ - return io ? io->read( data, maxlen ) : 0; -} - -/* vim:set shiftwidth=4 softtabstop=4 noexpandtab: */ diff --git a/src/lib/WT602OLEStream.h b/src/lib/WT602OLEStream.h deleted file mode 100644 index 250abbf..0000000 --- a/src/lib/WT602OLEStream.h +++ /dev/null @@ -1,135 +0,0 @@ -/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ -/* POLE - Portable C++ library to access OLE Storage - Copyright (C) 2002-2005 Ariya Hidayat <ariya@kde.org> - - Redistribution and use in source and binary forms, with or without - modification, are permitted provided that the following conditions - are met: - * Redistributions of source code must retain the above copyright notice, - this list of conditions and the following disclaimer. - * Redistributions in binary form must reproduce the above copyright notice, - this list of conditions and the following disclaimer in the documentation - and/or other materials provided with the distribution. - * Neither the name of the authors nor the names of its contributors may be - used to endorse or promote products derived from this software without - specific prior written permission. - - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" - AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF - THE POSSIBILITY OF SUCH DAMAGE. -*/ - -#ifndef WT602OLESTREAM_H_INCLUDED -#define WT602OLESTREAM_H_INCLUDED - -#include <string> -#include <fstream> -#include <vector> - -#include "libtext602_utils.h" - -class WPXInputStream; - -namespace libtext602 -{ - -class StorageIO; -class Stream; -class StreamIO; - -class Storage -{ - friend class Stream; - -public: - - // for Storage::result() - enum { Ok, OpenFailed, NotOLE, BadOLE, UnknownError }; - - /** - * Constructs a storage with data. - **/ - Storage( shared_ptr<WPXInputStream> is ); - - /** - * Destroys the storage. - **/ - ~Storage(); - - /** - * Checks whether the storage is OLE2 storage. - **/ - bool isOLEStream(); - - /** - * Returns the error code of last operation. - **/ - int result(); - - /** - * Returns the list of all ole leaves names - **/ - std::vector<std::string> getOLENames(); - - /** - * Returns a WPXInputStream corresponding to a name - **/ - shared_ptr<WPXInputStream> getDocumentOLEStream(const std::string &name); - -private: - StorageIO *io; - - // no copy or assign - Storage( const Storage & ); - Storage &operator=( const Storage & ); - -}; - -class Stream -{ - friend class Storage; - friend class StorageIO; - -public: - - /** - * Creates a new stream. - */ - Stream( Storage *storage, const std::string &name ); - - /** - * Destroys the stream. - */ - ~Stream(); - - /** - * Returns the stream size. - **/ - unsigned long size(); - - /** - * Reads a block of data. - **/ - unsigned long read( unsigned char *data, unsigned long maxlen ); - -private: - StreamIO *io; - - // no copy or assign - Stream( const Stream & ); - Stream &operator=( const Stream & ); -}; - -} // namespace libtext602 - -#endif // WPXOLESTREAM_H_INCLUDED - -/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/WT602Parser.cpp b/src/lib/WT602Parser.cpp index 7b70bda..96a0da6 100644 --- a/src/lib/WT602Parser.cpp +++ b/src/lib/WT602Parser.cpp @@ -19,12 +19,8 @@ #include <vector> #include <utility> -#include <libwpd/WPXDocumentInterface.h> -#include <libwpd/WPXPropertyList.h> -#include <libwpd/WPXPropertyListVector.h> -#include <libwpd/WPXString.h> - -#include <libwpd-stream/libwpd-stream.h> +#include <librevenge/librevenge.h> +#include <librevenge-stream/librevenge-stream.h> #include "WT602MemoryStream.h" #include "WT602Parser.h" @@ -50,17 +46,17 @@ class WT602SectionMap typedef std::pair<unsigned, unsigned> Section_t; public: - explicit WT602SectionMap(WPXInputStream *input); + explicit WT602SectionMap(librevenge::RVNGInputStream *input); bool isPresent(WT602Section section) const; - WPXInputStreamPtr getSectionStream(WPXInputStream *input, WT602Section section) const; + RVNGInputStreamPtr getSectionStream(librevenge::RVNGInputStream *input, WT602Section section) const; private: std::vector<Section_t> m_sections; }; -WT602SectionMap::WT602SectionMap(WPXInputStream *const input) +WT602SectionMap::WT602SectionMap(librevenge::RVNGInputStream *const input) : m_sections(SECTION_COUNT) { std::fill_n(m_sections.begin(), SECTION_COUNT, std::make_pair(0, 0)); @@ -93,16 +89,16 @@ bool WT602SectionMap::isPresent(const WT602Section section) const return false; } -WPXInputStreamPtr WT602SectionMap::getSectionStream(WPXInputStream *const input, const WT602Section section) const +RVNGInputStreamPtr WT602SectionMap::getSectionStream(librevenge::RVNGInputStream *const input, const WT602Section section) const { - WPXInputStreamPtr strm; + RVNGInputStreamPtr strm; if (isPresent(section)) { const Section_t &limits = m_sections[section]; const unsigned length = limits.second - limits.first; - input->seek(limits.first, WPX_SEEK_SET); + input->seek(limits.first, librevenge::RVNG_SEEK_SET); const unsigned char *const data = readNBytes(input, length); strm.reset(new WT602MemoryStream(data, length)); @@ -116,7 +112,7 @@ WPXInputStreamPtr WT602SectionMap::getSectionStream(WPXInputStream *const input, namespace libtext602 { -WT602Parser::WT602Parser(WPXInputStream *const input, WPXDocumentInterface *const document) +WT602Parser::WT602Parser(librevenge::RVNGInputStream *const input, librevenge::RVNGTextInterface *const document) : m_header(input) , m_input(input) , m_document(document) @@ -128,9 +124,9 @@ bool WT602Parser::parse() { m_sectionMap.reset(new WT602SectionMap(m_input)); - m_document->setDocumentMetaData(WPXPropertyList()); + m_document->setDocumentMetaData(librevenge::RVNGPropertyList()); m_document->startDocument(); - m_document->openPageSpan(WPXPropertyList()); + m_document->openPageSpan(librevenge::RVNGPropertyList()); readText(); @@ -142,8 +138,8 @@ bool WT602Parser::parse() void WT602Parser::readText() { - const WPXInputStreamPtr textInput(getSection(WT602_SECTION_TEXT)); - const WPXInputStreamPtr textInfoInput(getSection(WT602_SECTION_TEXT_INFO)); + const RVNGInputStreamPtr textInput(getSection(WT602_SECTION_TEXT)); + const RVNGInputStreamPtr textInfoInput(getSection(WT602_SECTION_TEXT_INFO)); const unsigned textLength = readU32(textInput.get()); const unsigned spanCount = readU32(textInfoInput.get()); @@ -151,7 +147,7 @@ void WT602Parser::readText() if (0 != textLength) { - m_document->openParagraph(WPXPropertyList(), WPXPropertyListVector()); + m_document->openParagraph(librevenge::RVNGPropertyList()); for (unsigned i = 0; i != spanCount; ++i) { @@ -165,12 +161,12 @@ void WT602Parser::readText() if (0x100 & flags) { m_document->closeParagraph(); - m_document->openParagraph(WPXPropertyList(), WPXPropertyListVector()); + m_document->openParagraph(librevenge::RVNGPropertyList()); } if (0 != length) { - WPXPropertyList props; + librevenge::RVNGPropertyList props; if (0x2 & format) props.insert("fo:font-weight", "bold"); @@ -183,7 +179,7 @@ void WT602Parser::readText() std::string text(reinterpret_cast<const char *>(data), length); m_document->openSpan(props); - m_document->insertText(WPXString(text.c_str())); + m_document->insertText(librevenge::RVNGString(text.c_str())); m_document->closeSpan(); } } @@ -192,7 +188,7 @@ void WT602Parser::readText() } } -WPXInputStreamPtr WT602Parser::getSection(const WT602Section section) const +RVNGInputStreamPtr WT602Parser::getSection(const WT602Section section) const { return m_sectionMap->getSectionStream(m_input, section); } diff --git a/src/lib/WT602Parser.h b/src/lib/WT602Parser.h index be946c1..2065c6f 100644 --- a/src/lib/WT602Parser.h +++ b/src/lib/WT602Parser.h @@ -17,11 +17,11 @@ #ifndef WT602PARSER_H_INCLUDED #define WT602PARSER_H_INCLUDED +#include <librevenge/librevenge.h> + #include "libtext602_utils.h" #include "WT602Header.h" -class WPXDocumentInterface; - namespace libtext602 { @@ -75,19 +75,19 @@ class WT602Parser WT602Parser &operator=(const WT602Parser &other); public: - WT602Parser(WPXInputStream *input, WPXDocumentInterface *document); + WT602Parser(librevenge::RVNGInputStream *input, librevenge::RVNGTextInterface *document); bool parse(); private: void readText(); - WPXInputStreamPtr getSection(WT602Section section) const; + RVNGInputStreamPtr getSection(WT602Section section) const; private: WT602Header m_header; - WPXInputStream *m_input; - WPXDocumentInterface *m_document; + librevenge::RVNGInputStream *m_input; + librevenge::RVNGTextInterface *m_document; shared_ptr<WT602SectionMap> m_sectionMap; }; diff --git a/src/lib/libtext602_utils.cpp b/src/lib/libtext602_utils.cpp index 83485db..693567c 100644 --- a/src/lib/libtext602_utils.cpp +++ b/src/lib/libtext602_utils.cpp @@ -18,9 +18,9 @@ #include "libtext602_utils.h" -uint8_t libtext602::readU8(WPXInputStream *input, bool /* bigEndian */) +uint8_t libtext602::readU8(librevenge::RVNGInputStream *input, bool /* bigEndian */) { - if (!input || input->atEOS()) + if (!input || input->isEnd()) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); @@ -34,9 +34,9 @@ uint8_t libtext602::readU8(WPXInputStream *input, bool /* bigEndian */) throw EndOfStreamException(); } -uint16_t libtext602::readU16(WPXInputStream *input, bool bigEndian) +uint16_t libtext602::readU16(librevenge::RVNGInputStream *input, bool bigEndian) { - if (!input || input->atEOS()) + if (!input || input->isEnd()) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); @@ -54,9 +54,9 @@ uint16_t libtext602::readU16(WPXInputStream *input, bool bigEndian) throw EndOfStreamException(); } -uint32_t libtext602::readU32(WPXInputStream *input, bool bigEndian) +uint32_t libtext602::readU32(librevenge::RVNGInputStream *input, bool bigEndian) { - if (!input || input->atEOS()) + if (!input || input->isEnd()) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); @@ -74,9 +74,9 @@ uint32_t libtext602::readU32(WPXInputStream *input, bool bigEndian) throw EndOfStreamException(); } -uint64_t libtext602::readU64(WPXInputStream *input, bool bigEndian) +uint64_t libtext602::readU64(librevenge::RVNGInputStream *input, bool bigEndian) { - if (!input || input->atEOS()) + if (!input || input->isEnd()) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); @@ -94,9 +94,9 @@ uint64_t libtext602::readU64(WPXInputStream *input, bool bigEndian) throw EndOfStreamException(); } -const unsigned char *libtext602::readNBytes(WPXInputStream *const input, const unsigned long numBytes) +const unsigned char *libtext602::readNBytes(librevenge::RVNGInputStream *const input, const unsigned long numBytes) { - if (!input || input->atEOS()) + if (!input || input->isEnd()) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); @@ -114,15 +114,15 @@ const unsigned char *libtext602::readNBytes(WPXInputStream *const input, const u return s; } -void libtext602::skip(WPXInputStream *input, unsigned long numBytes) +void libtext602::skip(librevenge::RVNGInputStream *input, unsigned long numBytes) { - if (!input || input->atEOS()) + if (!input || input->isEnd()) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); } - if (0 != input->seek(static_cast<long>(numBytes), WPX_SEEK_CUR)) + if (0 != input->seek(static_cast<long>(numBytes), librevenge::RVNG_SEEK_CUR)) { TEXT602_DEBUG_MSG(("Throwing EndOfStreamException\n")); throw EndOfStreamException(); diff --git a/src/lib/libtext602_utils.h b/src/lib/libtext602_utils.h index bc14793..0b8ae6c 100644 --- a/src/lib/libtext602_utils.h +++ b/src/lib/libtext602_utils.h @@ -21,8 +21,8 @@ #include <cstdio> #endif -#include <libwpd-stream/libwpd-stream.h> -#include <libwpd/libwpd.h> +#include <librevenge-stream/librevenge-stream.h> +#include <librevenge/librevenge.h> #ifdef _MSC_VER @@ -69,14 +69,14 @@ using std::shared_ptr; using boost::shared_ptr; #endif -/** an noop deleter used to transform a libwpd pointer in a false shared_ptr */ +/** an noop deleter used to transform a librevenge pointer in a false shared_ptr */ template <class T> struct WT602_shared_ptr_noop_deleter { void operator() (T *) {} }; -typedef shared_ptr<WPXInputStream> WPXInputStreamPtr; +typedef shared_ptr<librevenge::RVNGInputStream> RVNGInputStreamPtr; // debug message includes source file and line number //#define VERBOSE_DEBUG 1 @@ -100,14 +100,14 @@ typedef shared_ptr<WPXInputStream> WPXInputStreamPtr; namespace libtext602 { -uint8_t readU8(WPXInputStream *input, bool = false); -uint16_t readU16(WPXInputStream *input, bool bigEndian=false); -uint32_t readU32(WPXInputStream *input, bool bigEndian=false); -uint64_t readU64(WPXInputStream *input, bool bigEndian=false); +uint8_t readU8(librevenge::RVNGInputStream *input, bool = false); +uint16_t readU16(librevenge::RVNGInputStream *input, bool bigEndian=false); +uint32_t readU32(librevenge::RVNGInputStream *input, bool bigEndian=false); +uint64_t readU64(librevenge::RVNGInputStream *input, bool bigEndian=false); -const unsigned char *readNBytes(WPXInputStream *input, unsigned long numBytes); +const unsigned char *readNBytes(librevenge::RVNGInputStream *input, unsigned long numBytes); -void skip(WPXInputStream *input, unsigned long numBytes); +void skip(librevenge::RVNGInputStream *input, unsigned long numBytes); class EndOfStreamException { |