diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-11-18 22:27:42 +0100 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2011-11-18 22:27:42 +0100 |
commit | 0dab3c1de6aa33f22d2145231624f14cdd636c55 (patch) | |
tree | 88ab1cdb82887d5b49e24b925ada52ca00fa06ed | |
parent | aa22e620a22ed4fe44b1fe297a70e025944fb4c2 (diff) |
Move that format string -> formatId parser and acctually use it
-rw-r--r-- | src/lib/VSDXCollector.h | 4 | ||||
-rw-r--r-- | src/lib/VSDXContentCollector.cpp | 46 | ||||
-rw-r--r-- | src/lib/VSDXContentCollector.h | 5 | ||||
-rw-r--r-- | src/lib/VSDXFieldList.cpp | 48 | ||||
-rw-r--r-- | src/lib/VSDXFieldList.h | 19 | ||||
-rw-r--r-- | src/lib/VSDXParser.cpp | 10 | ||||
-rw-r--r-- | src/lib/VSDXStylesCollector.cpp | 4 | ||||
-rw-r--r-- | src/lib/VSDXStylesCollector.h | 4 |
8 files changed, 75 insertions, 65 deletions
diff --git a/src/lib/VSDXCollector.h b/src/lib/VSDXCollector.h index 92de8bd..35597ab 100644 --- a/src/lib/VSDXCollector.h +++ b/src/lib/VSDXCollector.h @@ -111,8 +111,8 @@ public: // Field list virtual void collectFieldList(unsigned id, unsigned level) = 0; - virtual void collectTextField(unsigned id, unsigned level, int nameId) = 0; - virtual void collectNumericField(unsigned id, unsigned level, unsigned short format, double number) = 0; + virtual void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId) = 0; + virtual void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId) = 0; // Temporary hack virtual void startPage() = 0; diff --git a/src/lib/VSDXContentCollector.cpp b/src/lib/VSDXContentCollector.cpp index a53bab5..4313752 100644 --- a/src/lib/VSDXContentCollector.cpp +++ b/src/lib/VSDXContentCollector.cpp @@ -29,6 +29,8 @@ */ #include <stack> +#include <boost/spirit/include/classic.hpp> + #include "VSDXContentCollector.h" #include "VSDXParser.h" #include "VSDInternalStream.h" @@ -1873,7 +1875,7 @@ void libvisio::VSDXContentCollector::collectFieldList(unsigned /* id */, unsigne m_fields.clear(); } -void libvisio::VSDXContentCollector::collectTextField(unsigned id, unsigned level, int nameId) +void libvisio::VSDXContentCollector::collectTextField(unsigned id, unsigned level, int nameId, int formatStringId) { _handleLevelChange(level); VSDXFieldListElement *element = m_stencilFields.getElement(m_fields.size()); @@ -1891,12 +1893,12 @@ void libvisio::VSDXContentCollector::collectTextField(unsigned id, unsigned leve } else { - VSDXTextField tmpField(id, level, nameId); + VSDXTextField tmpField(id, level, nameId, formatStringId); m_fields.push_back(tmpField.getString(m_names)); } } -void libvisio::VSDXContentCollector::collectNumericField(unsigned id, unsigned level, unsigned short format, double number) +void libvisio::VSDXContentCollector::collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId) { _handleLevelChange(level); VSDXFieldListElement *pElement = m_stencilFields.getElement(m_fields.size()); @@ -1906,15 +1908,21 @@ void libvisio::VSDXContentCollector::collectNumericField(unsigned id, unsigned l if (element) { element->setValue(number); + if (format == 0xffff) + { + if (formatStringId >= 0 && (unsigned)formatStringId < m_names.size()) + parseFormatId(m_names[formatStringId].cstr(), format); + } if (format != 0xffff) element->setFormat(format); + m_fields.push_back(element->getString(m_names)); delete element; } } else { - VSDXNumericField tmpField(id, level, format, number); + VSDXNumericField tmpField(id, level, format, number, formatStringId); m_fields.push_back(tmpField.getString(m_names)); } } @@ -2120,4 +2128,34 @@ void libvisio::VSDXContentCollector::_appendUCS4(WPXString &text, unsigned ucs4C text.append(outbuf[i]); } +bool libvisio::VSDXContentCollector::parseFormatId( const char *formatString, unsigned short &result ) +{ + using namespace ::boost::spirit::classic; + + result = 0xffff; + + uint_parser<unsigned short,10,1,5> ushort_p; + if (parse(formatString, + // Begin grammar + ( + ( + str_p("{<") >> + ushort_p[assign_a(result)] + >> str_p(">}") + ) + | + ( + str_p("esc(") >> + ushort_p[assign_a(result)] + >> ')' + ) + )>> end_p, + // End grammar + space_p).full ) + { + return true; + } + return false; +} + /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VSDXContentCollector.h b/src/lib/VSDXContentCollector.h index 45160fd..d69f9c1 100644 --- a/src/lib/VSDXContentCollector.h +++ b/src/lib/VSDXContentCollector.h @@ -132,8 +132,8 @@ public: // Field list void collectFieldList(unsigned id, unsigned level); - void collectTextField(unsigned id, unsigned level, int nameId); - void collectNumericField(unsigned id, unsigned level, unsigned short format, double number); + void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId); + void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId); void startPage(); void endPage(); @@ -174,6 +174,7 @@ private: unsigned shadowPattern, Colour shfgc, double shadowOffsetX, double shadowOffsetY); void _convertDataToString(WPXString &result, const WPXBinaryData &data, TextFormat format); + bool parseFormatId( const char *formatString, unsigned short &result ); bool m_isPageStarted; double m_pageWidth; diff --git a/src/lib/VSDXFieldList.cpp b/src/lib/VSDXFieldList.cpp index 1e85ff1..4e62c56 100644 --- a/src/lib/VSDXFieldList.cpp +++ b/src/lib/VSDXFieldList.cpp @@ -32,46 +32,14 @@ #include "VSDXCollector.h" #include "VSDXFieldList.h" -#include <boost/spirit/include/classic.hpp> - -bool libvisio::VSDXFieldListElement::parseFormatId( const char *formatString, unsigned short &result ) -{ - using namespace ::boost::spirit::classic; - - result = 0xffff; - - uint_parser<unsigned short,10,1,5> ushort_p; - if (parse(formatString, - // Begin grammar - ( - ( - str_p("{<") >> - ushort_p[assign_a(result)] - >> str_p(">}") - ) - | - ( - str_p("esc(") >> - ushort_p[assign_a(result)] - >> ')' - ) - )>> end_p, - // End grammar - space_p).full ) - { - return true; - } - return false; -} - void libvisio::VSDXTextField::handle(VSDXCollector *collector) { - collector->collectTextField(m_id, m_level, m_nameId); + collector->collectTextField(m_id, m_level, m_nameId, m_formatStringId); } libvisio::VSDXFieldListElement *libvisio::VSDXTextField::clone() { - return new VSDXTextField(m_id, m_level, m_nameId); + return new VSDXTextField(m_id, m_level, m_nameId, m_formatStringId); } WPXString libvisio::VSDXTextField::getString(const std::vector<WPXString> &strVec) @@ -90,12 +58,12 @@ void libvisio::VSDXTextField::setNameId(int nameId) void libvisio::VSDXNumericField::handle(VSDXCollector *collector) { - collector->collectNumericField(m_id, m_level, m_format, m_number); + collector->collectNumericField(m_id, m_level, m_format, m_number, m_formatStringId); } libvisio::VSDXFieldListElement *libvisio::VSDXNumericField::clone() { - return new VSDXNumericField(m_id, m_level, m_format, m_number); + return new VSDXNumericField(m_id, m_level, m_format, m_number, m_formatStringId); } #define MAX_BUFFER 1024 @@ -259,14 +227,14 @@ void libvisio::VSDXFieldList::addFieldList(unsigned id, unsigned level) m_level = level; } -void libvisio::VSDXFieldList::addTextField(unsigned id, unsigned level, int nameId) +void libvisio::VSDXFieldList::addTextField(unsigned id, unsigned level, int nameId, int formatStringId) { - m_elements[id] = new VSDXTextField(id, level, nameId); + m_elements[id] = new VSDXTextField(id, level, nameId, formatStringId); } -void libvisio::VSDXFieldList::addNumericField(unsigned id, unsigned level, unsigned short format, double number) +void libvisio::VSDXFieldList::addNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId) { - m_elements[id] = new VSDXNumericField(id, level, format, number); + m_elements[id] = new VSDXNumericField(id, level, format, number, formatStringId); } void libvisio::VSDXFieldList::handle(VSDXCollector *collector) diff --git a/src/lib/VSDXFieldList.h b/src/lib/VSDXFieldList.h index d881e2e..f292927 100644 --- a/src/lib/VSDXFieldList.h +++ b/src/lib/VSDXFieldList.h @@ -53,17 +53,16 @@ public: virtual void setNameId(int) = 0; virtual void setFormat(unsigned short) = 0; virtual void setValue(double) = 0; -protected: - bool parseFormatId( const char *formatString, unsigned short &result ); }; class VSDXTextField : public VSDXFieldListElement { public: - VSDXTextField(unsigned id, unsigned level, int nameId) + VSDXTextField(unsigned id, unsigned level, int nameId, int formatStringId) : m_id(id), m_level(level), - m_nameId(nameId) {} + m_nameId(nameId), + m_formatStringId(formatStringId) {} ~VSDXTextField() {} void handle(VSDXCollector *collector); VSDXFieldListElement *clone(); @@ -73,17 +72,18 @@ public: void setValue(double) {} private: unsigned m_id, m_level; - int m_nameId; + int m_nameId, m_formatStringId; }; class VSDXNumericField : public VSDXFieldListElement { public: - VSDXNumericField(unsigned id, unsigned level, unsigned short format, double number) + VSDXNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId) : m_id(id), m_level(level), m_format(format), - m_number(number) {} + m_number(number), + m_formatStringId(formatStringId) {} ~VSDXNumericField() {} void handle(VSDXCollector *collector); VSDXFieldListElement *clone(); @@ -96,6 +96,7 @@ private: unsigned m_id, m_level; unsigned short m_format; double m_number; + int m_formatStringId; }; class VSDXFieldList @@ -107,8 +108,8 @@ public: VSDXFieldList &operator=(const VSDXFieldList &fieldList); void setElementsOrder(const std::vector<unsigned> &m_elementsOrder); void addFieldList(unsigned id, unsigned level); - void addTextField(unsigned id, unsigned level, int nameId); - void addNumericField(unsigned id, unsigned level, unsigned short format, double number); + void addTextField(unsigned id, unsigned level, int nameId, int formatStringId); + void addNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId); void addClonedField(unsigned id); void handle(VSDXCollector *collector); void clear(); diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp index c45b1de..b409bc7 100644 --- a/src/lib/VSDXParser.cpp +++ b/src/lib/VSDXParser.cpp @@ -1575,15 +1575,17 @@ void libvisio::VSDXParser::readTextField(WPXInputStream *input) { int nameId = (int)readU32(input); input->seek(6, WPX_SEEK_CUR); + int formatStringId = (int)readU32(input); if (m_isStencilStarted) - m_stencilShape.m_fields.addTextField(m_header.id, m_header.level, nameId); + m_stencilShape.m_fields.addTextField(m_header.id, m_header.level, nameId, formatStringId); else - m_fieldList.addTextField(m_header.id, m_header.level, nameId); + m_fieldList.addTextField(m_header.id, m_header.level, nameId, formatStringId); } else { double numericValue = readDouble(input); input->seek(2, WPX_SEEK_CUR); + int formatStringId = (int)readU32(input); unsigned blockIdx = 0; unsigned length = 0; @@ -1633,9 +1635,9 @@ void libvisio::VSDXParser::readTextField(WPXInputStream *input) } if (m_isStencilStarted) - m_stencilShape.m_fields.addNumericField(m_header.id, m_header.level, formatNumber, numericValue); + m_stencilShape.m_fields.addNumericField(m_header.id, m_header.level, formatNumber, numericValue, formatStringId); else - m_fieldList.addNumericField(m_header.id, m_header.level, formatNumber, numericValue); + m_fieldList.addNumericField(m_header.id, m_header.level, formatNumber, numericValue, formatStringId); } } diff --git a/src/lib/VSDXStylesCollector.cpp b/src/lib/VSDXStylesCollector.cpp index f37dfad..796021f 100644 --- a/src/lib/VSDXStylesCollector.cpp +++ b/src/lib/VSDXStylesCollector.cpp @@ -349,12 +349,12 @@ void libvisio::VSDXStylesCollector::collectFieldList(unsigned /* id */, unsigned _handleLevelChange(level); } -void libvisio::VSDXStylesCollector::collectTextField(unsigned /* id */, unsigned level, int /* nameId */) +void libvisio::VSDXStylesCollector::collectTextField(unsigned /* id */, unsigned level, int /* nameId */, int /* formatStringId */) { _handleLevelChange(level); } -void libvisio::VSDXStylesCollector::collectNumericField(unsigned /* id */, unsigned level, unsigned short /* format */, double /* number */) +void libvisio::VSDXStylesCollector::collectNumericField(unsigned /* id */, unsigned level, unsigned short /* format */, double /* number */, int /* formatStringId */) { _handleLevelChange(level); } diff --git a/src/lib/VSDXStylesCollector.h b/src/lib/VSDXStylesCollector.h index 897bd65..0373f99 100644 --- a/src/lib/VSDXStylesCollector.h +++ b/src/lib/VSDXStylesCollector.h @@ -122,8 +122,8 @@ public: // Field list void collectFieldList(unsigned id, unsigned level); - void collectTextField(unsigned id, unsigned level, int nameId); - void collectNumericField(unsigned id, unsigned level, unsigned short format, double number); + void collectTextField(unsigned id, unsigned level, int nameId, int formatStringId); + void collectNumericField(unsigned id, unsigned level, unsigned short format, double number, int formatStringId); // Temporary hack void startPage(); |