From 22ada96fb35824a5f8abaa4af31e62e1c20385d8 Mon Sep 17 00:00:00 2001 From: Fridrich Štrba Date: Wed, 25 Jul 2012 21:53:52 +0200 Subject: Reorder pointers to streams according to the list --- src/lib/VSDXParser.cpp | 39 +++++++++++++++++++++++++++++++-------- 1 file changed, 31 insertions(+), 8 deletions(-) diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp index 493635e..650dbc8 100644 --- a/src/lib/VSDXParser.cpp +++ b/src/lib/VSDXParser.cpp @@ -126,12 +126,13 @@ void libvisio::VSDXParser::handleStreams(WPXInputStream *input, unsigned shift, input->seek(shift, WPX_SEEK_SET); unsigned offset = readU32(input); input->seek(offset+shift-4, WPX_SEEK_SET); - /* unsigned listSize = */ - readU32(input); + unsigned listSize = readU32(input); unsigned pointerCount = readU32(input); input->seek(4, WPX_SEEK_CUR); - std::vector > PtrList; - for (unsigned i = 0; i < pointerCount; i++) + std::map PtrList; + std::map FontFaces; + unsigned i = 0; + for (i = 0; i < pointerCount; i++) { Pointer ptr; ptr.Type = readU32(input); @@ -140,12 +141,34 @@ void libvisio::VSDXParser::handleStreams(WPXInputStream *input, unsigned shift, ptr.Length = readU32(input); ptr.Format = readU16(input); if (ptr.Type == VSD_FONTFACES) - PtrList.insert(PtrList.begin(),std::make_pair(i, ptr)); + FontFaces[i] = ptr; else if (ptr.Type != 0) - PtrList.push_back(std::make_pair(i, ptr)); + PtrList[i] = ptr; } - for (unsigned j = 0; j < PtrList.size(); j++) - handleStream(PtrList[j].second, PtrList[j].first, level+1); + std::vector pointerOrder; + for (i = 0; i < listSize; ++i) + pointerOrder.push_back(readU32(input)); + + std::map::iterator iter; + + for (iter = FontFaces.begin(); iter != FontFaces.end(); ++iter) + handleStream(iter->second, iter->first, level+1); + + if (!pointerOrder.empty()) + { + for (i=0; i < pointerOrder.size(); ++i) + { + iter = PtrList.find(pointerOrder[i]); + if (iter != PtrList.end()) + { + handleStream(iter->second, iter->first, level+1); + PtrList.erase(iter); + } + } + } + for (iter = PtrList.begin(); iter != PtrList.end(); ++iter) + handleStream(iter->second, iter->first, level+1); + } -- cgit v1.2.3