diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2012-06-18 17:31:52 +0200 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2012-06-18 17:31:52 +0200 |
commit | d7237089f294963eafe06f3cec08f84732517bfb (patch) | |
tree | 97fb610baa59de14b37058bf3ba90429cda5063d | |
parent | 72c9e4d27a366decc34979722d2b3f6179483388 (diff) |
Some more rework of text encoding conversions
-rw-r--r-- | src/lib/VSDXContentCollector.cpp | 7 | ||||
-rw-r--r-- | src/lib/VSDXTypes.h | 15 | ||||
-rw-r--r-- | src/lib/libvisio_utils.cpp | 28 | ||||
-rw-r--r-- | 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<unsigned char> 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<unsigned char> 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<unsigned char> &characters, unsigned short charset) +void libvisio::appendCharacters(WPXString &text, const std::vector<unsigned char> &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<unsigned char 0x0111, 0x00F1, 0x0323, 0x00F3, 0x00F4, 0x01A1, 0x00F6, 0x00F7, 0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x01B0, 0x20AB, 0x00FF }; + std::vector<unsigned char>::const_iterator iter = characters.begin(); while (iter != characters.end()) { @@ -383,36 +387,36 @@ void libvisio::appendCharacters(WPXString &text, const std::vector<unsigned char } else { - switch (charset) + switch (format) { - case 0: // ANSI + case VSD_TEXT_ANSI: ucs4Character = cp1252map[*iter++ - 0x80]; break; - case 0xa1: // GREEEK + case VSD_TEXT_GREEK: ucs4Character = cp1253map[*iter++ - 0x80]; break; - case 0xa2: // TURKISH + case VSD_TEXT_TURKISH: ucs4Character = cp1254map[*iter++ - 0x80]; break; - case 0xa3: // VIETNAMESE + case VSD_TEXT_VIETNAMESE: ucs4Character = cp1258map[*iter++ - 0x80]; break; - case 0xb1: // HEBREW + case VSD_TEXT_HEBREW: ucs4Character = cp1255map[*iter++ - 0x80]; break; - case 0xb2: // ARABIC + case VSD_TEXT_ARABIC: ucs4Character = cp1256map[*iter++ - 0x80]; break; - case 0xba: // BALTIC + case VSD_TEXT_BALTIC: ucs4Character = cp1257map[*iter++ - 0x80]; break; - case 0xcc: // RUSSIAN + case VSD_TEXT_RUSSIAN: ucs4Character = cp1251map[*iter++ - 0x80]; break; - case 0xde: // THAI + case VSD_TEXT_THAI: ucs4Character = cp874map[*iter++ - 0x80]; break; - case 0xee: // CENTRAL EUROPE + case VSD_TEXT_CENTRAL_EUROPE: ucs4Character = cp1250map[*iter++ - 0x80]; break; default: diff --git a/src/lib/libvisio_utils.h b/src/lib/libvisio_utils.h index 030a46e..912f32b 100644 --- a/src/lib/libvisio_utils.h +++ b/src/lib/libvisio_utils.h @@ -34,6 +34,7 @@ #include <vector> #include <stdio.h> #include <libwpd/libwpd.h> +#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<unsigned char> &characters, unsigned short charset); +void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters, TextFormat format); void appendCharacters(WPXString &text, const std::vector<unsigned char> &characters); class EndOfStreamException |