From d7237089f294963eafe06f3cec08f84732517bfb Mon Sep 17 00:00:00 2001 From: Fridrich Štrba Date: Mon, 18 Jun 2012 17:31:52 +0200 Subject: Some more rework of text encoding conversions --- src/lib/VSDXContentCollector.cpp | 7 ++----- src/lib/VSDXTypes.h | 15 ++++++++++++++- src/lib/libvisio_utils.cpp | 28 ++++++++++++++++------------ src/lib/libvisio_utils.h | 3 ++- 4 files changed, 34 insertions(+), 19 deletions(-) diff --git a/src/lib/VSDXContentCollector.cpp b/src/lib/VSDXContentCollector.cpp index 2cef0f5..703b1c8 100644 --- a/src/lib/VSDXContentCollector.cpp +++ b/src/lib/VSDXContentCollector.cpp @@ -845,7 +845,7 @@ void libvisio::VSDXContentCollector::_flushText() max = (m_charFormats[charIndex].charCount == 0 && m_textStream.size()) ? m_textStream.size() : max; std::vector tmpBuffer(max); memcpy(&tmpBuffer[0], &pTextBuffer[textBufferPosition], max); - appendCharacters(text, tmpBuffer, 0); + appendCharacters(text, tmpBuffer, m_textFormat); textBufferPosition += max; } WPXPropertyList textProps; @@ -2111,10 +2111,7 @@ void libvisio::VSDXContentCollector::_convertDataToString(WPXString &result, con return; std::vector tmpData(data.size()); memcpy(&tmpData[0], data.getDataBuffer(), data.size()); - if (format == VSD_TEXT_ANSI) - appendCharacters(result, tmpData, 0); - else if (format == VSD_TEXT_UTF16) - appendCharacters(result, tmpData); + appendCharacters(result, tmpData, format); } void libvisio::VSDXContentCollector::collectName(unsigned id, unsigned level, const WPXBinaryData &name, TextFormat format) diff --git a/src/lib/VSDXTypes.h b/src/lib/VSDXTypes.h index 4c9b8d2..401ba71 100644 --- a/src/lib/VSDXTypes.h +++ b/src/lib/VSDXTypes.h @@ -176,7 +176,20 @@ struct ForeignData data(fd.data) {} }; -enum TextFormat { VSD_TEXT_ANSI, VSD_TEXT_UTF16 }; +enum TextFormat +{ + VSD_TEXT_ANSI = 0, + VSD_TEXT_GREEK, + VSD_TEXT_TURKISH, + VSD_TEXT_VIETNAMESE, + VSD_TEXT_HEBREW, + VSD_TEXT_ARABIC, + VSD_TEXT_BALTIC, + VSD_TEXT_RUSSIAN, + VSD_TEXT_THAI, + VSD_TEXT_CENTRAL_EUROPE, + VSD_TEXT_UTF16 +}; class VSDXName { diff --git a/src/lib/libvisio_utils.cpp b/src/lib/libvisio_utils.cpp index 5ac2e92..9fd0eb9 100644 --- a/src/lib/libvisio_utils.cpp +++ b/src/lib/libvisio_utils.cpp @@ -164,8 +164,11 @@ double libvisio::readDouble(WPXInputStream *input) return tmpUnion.d; } -void libvisio::appendCharacters(WPXString &text, const std::vector &characters, unsigned short charset) +void libvisio::appendCharacters(WPXString &text, const std::vector &characters, TextFormat format) { + if (format == VSD_TEXT_UTF16) + return appendCharacters(text, characters); + static const unsigned short cp874map[] = { 0x20AC, 0x0020, 0x0020, 0x0020, 0x0020, 0x2026, 0x0020, 0x0020, @@ -365,6 +368,7 @@ void libvisio::appendCharacters(WPXString &text, const std::vector::const_iterator iter = characters.begin(); while (iter != characters.end()) { @@ -383,36 +387,36 @@ void libvisio::appendCharacters(WPXString &text, const std::vector #include #include +#include "VSDXTypes.h" #ifdef _MSC_VER @@ -94,7 +95,7 @@ uint64_t readU64(WPXInputStream *input); double readDouble(WPXInputStream *input); -void appendCharacters(WPXString &text, const std::vector &characters, unsigned short charset); +void appendCharacters(WPXString &text, const std::vector &characters, TextFormat format); void appendCharacters(WPXString &text, const std::vector &characters); class EndOfStreamException -- cgit v1.2.3