diff options
author | David Tardon <dtardon@redhat.com> | 2013-06-30 16:38:09 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2013-06-30 16:38:30 +0200 |
commit | 47223bf920187a13f50733a8f7931afd98903c5a (patch) | |
tree | 8ae0a87831cff7990503c5aa147c1463b7a36a69 | |
parent | c5178caaac468b7f40ac717fcb7bfe8e883ed9a6 (diff) |
add BIPU support for text
-rw-r--r-- | src/lib/WT602Parser.cpp | 75 |
1 files changed, 71 insertions, 4 deletions
diff --git a/src/lib/WT602Parser.cpp b/src/lib/WT602Parser.cpp index 97708cf..2fa05d5 100644 --- a/src/lib/WT602Parser.cpp +++ b/src/lib/WT602Parser.cpp @@ -19,9 +19,13 @@ #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 "WT602MemoryStream.h" #include "WT602Parser.h" namespace libtext602 @@ -90,10 +94,19 @@ bool WT602SectionMap::isPresent(const WT602Section section) const WPXInputStreamPtr WT602SectionMap::getSectionStream(WPXInputStream *const input, const WT602Section section) const { - // TODO: implement me - (void) input; - (void) section; WPXInputStreamPtr 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); + const unsigned char *const data = readNBytes(input, length); + + strm.reset(new WT602MemoryStream(data, length)); + } + return strm; } @@ -114,14 +127,68 @@ bool WT602Parser::parse() { m_sectionMap.reset(new WT602SectionMap(m_input)); + m_document->setDocumentMetaData(WPXPropertyList()); + m_document->startDocument(); + m_document->openPageSpan(WPXPropertyList()); + readText(); + m_document->closePageSpan(); + m_document->endDocument(); + return true; } void WT602Parser::readText() { - // TODO: implement me + const WPXInputStreamPtr textInput(getSection(WT602_SECTION_TEXT)); + const WPXInputStreamPtr textInfoInput(getSection(WT602_SECTION_TEXT_INFO)); + + const unsigned textLength = readU32(textInput.get()); + const unsigned spanCount = readU32(textInfoInput.get()); + skip(textInfoInput.get(), 6); + + if (0 != textLength) + { + m_document->openParagraph(WPXPropertyList(), WPXPropertyListVector()); + + for (unsigned i = 0; i != spanCount; ++i) + { + skip(textInfoInput.get(), 4); + const unsigned flags = readU16(textInfoInput.get()); + skip(textInfoInput.get(), 6); + const unsigned format = readU16(textInfoInput.get()); + const unsigned length = readU16(textInfoInput.get()); + skip(textInfoInput.get(), 12); + + if (0x100 & flags) + { + m_document->closeParagraph(); + m_document->openParagraph(WPXPropertyList(), WPXPropertyListVector()); + } + + if (0 != length) + { + WPXPropertyList props; + + if (0x2 & format) + props.insert("fo:font-weight", "bold"); + if (0x4 & format) + props.insert("fo:font-style", "italic"); + if (0x8 & format) + props.insert("style:text-underline-type", "single"); + + const unsigned char *const data = readNBytes(textInput.get(), length); + std::string text(reinterpret_cast<const char *>(data), length); + + m_document->openSpan(props); + m_document->insertText(WPXString(text.c_str())); + m_document->closeSpan(); + } + } + + m_document->closeParagraph(); + } } WPXInputStreamPtr WT602Parser::getSection(const WT602Section section) const |