summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2012-07-25 11:36:21 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2012-07-25 13:13:51 +0200
commite185f81a99945dbd02de495ed2f2455f0fa0ae0a (patch)
tree66e6311b227b228708c20a90ff4bad8cd99bce5a
parenta634e573f4c0c49d7971b8910f00542a18f5d71d (diff)
Get rid of handlePages function
-rw-r--r--src/lib/VSDXParser.cpp151
-rw-r--r--src/lib/VSDXParser.h5
2 files changed, 36 insertions, 120 deletions
diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index 04d3e13..cfa7252 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -125,7 +125,8 @@ void libvisio::VSDXParser::handleStreams(WPXInputStream *input, unsigned shift,
// Parse out pointers to streams
input->seek(shift, WPX_SEEK_SET);
unsigned offset = readU32(input);
- input->seek(offset+shift, WPX_SEEK_SET);
+ input->seek(offset+shift-4, WPX_SEEK_SET);
+ /* unsigned listSize = */ readU32(input);
unsigned pointerCount = readU32(input);
input->seek(4, WPX_SEEK_CUR);
std::vector<libvisio::Pointer> PtrList;
@@ -143,11 +144,11 @@ void libvisio::VSDXParser::handleStreams(WPXInputStream *input, unsigned shift,
PtrList.push_back(ptr);
}
for (unsigned j = 0; j < PtrList.size(); j++)
- handleStream(PtrList[j], level+1);
+ handleStream(PtrList[j], j, level+1);
}
-void libvisio::VSDXParser::handleStream(const Pointer &ptr, unsigned level)
+void libvisio::VSDXParser::handleStream(const Pointer &ptr, unsigned idx, unsigned level)
{
bool compressed = ((ptr.Format & 2) == 2);
m_input->seek(ptr.Offset, WPX_SEEK_SET);
@@ -162,9 +163,16 @@ void libvisio::VSDXParser::handleStream(const Pointer &ptr, unsigned level)
case VSD_COLORS:
readColours(&tmpInput);
return;
+ case VSD_FONTFACE: // substreams of FONTAFACES stream, ver 11 only
+ readFont(&tmpInput, idx);
+ return;
case VSD_STYLES:
- handleStyles(&tmpInput);
+ m_isInStyles = true;
return;
+ case VSD_PAGE:
+ m_currentPageID = idx;
+ m_collector->startPage();
+ break;
default:
break;
}
@@ -173,6 +181,25 @@ void libvisio::VSDXParser::handleStream(const Pointer &ptr, unsigned level)
handleChunks(&tmpInput);
else if ((ptr.Format >> 4) == 0x5)
handleStreams(&tmpInput, shift, level+1);
+
+ switch (ptr.Type)
+ {
+ case VSD_STYLES:
+ m_isInStyles = false;
+ return;
+ case VSD_PAGE:
+ m_collector->endPage();
+ break;
+ case VSD_PAGES:
+ {
+ std::vector<unsigned> pageOrder;
+ m_collector->endPages(pageOrder);
+ break;
+ }
+ default:
+ break;
+ }
+
}
void libvisio::VSDXParser::handleChunks(WPXInputStream *input)
@@ -303,6 +330,9 @@ void libvisio::VSDXParser::handleChunks(WPXInputStream *input)
case VSD_TEXT_FIELD:
readTextField(input);
break;
+ case VSD_STYLE_SHEET:
+ readStyleSheet(input);
+ break;
default:
m_collector->collectUnhandledChunk(m_header.id, m_header.level);
}
@@ -311,119 +341,6 @@ void libvisio::VSDXParser::handleChunks(WPXInputStream *input)
}
}
-void libvisio::VSDXParser::handlePages(WPXInputStream *input, unsigned shift)
-{
- unsigned ptrType;
- unsigned ptrOffset;
- unsigned ptrLength;
- unsigned ptrFormat;
-
- input->seek(shift, WPX_SEEK_CUR);
- unsigned offset = readU32(input);
- input->seek(offset+shift-4, WPX_SEEK_SET);
- unsigned listSize = readU32(input);
- unsigned pointerCount = readU32(input);
- input->seek(4, WPX_SEEK_CUR); // Ignore 0x0 dword
-
- unsigned numPages = 0;
- unsigned i = 0;
- for (i = 0 ; i < pointerCount; i++)
- {
- ptrType = readU32(input);
- input->seek(4, WPX_SEEK_CUR); // Skip dword
- ptrOffset = readU32(input);
- ptrLength = readU32(input);
- ptrFormat = readU16(input);
-
- bool compressed = ((ptrFormat & 2) == 2);
- m_input->seek(ptrOffset, WPX_SEEK_SET);
- VSDInternalStream tmpInput(m_input, ptrLength, compressed);
- m_currentPageID = 0;
- switch (ptrType)
- {
- case VSD_PAGE:
- m_currentPageID = i;
- numPages++;
- m_collector->startPage();
- try
- {
- handleChunks(&tmpInput);
- }
- catch (EndOfStreamException &)
- {
- }
- _handleLevelChange(0);
- m_collector->endPage();
- break;
- case VSD_PAGES: // shouldn't happen
- handleStreams(&tmpInput, shift, 0);
- break;
- case VSD_COLORS: // shouldn't happen
- readColours(&tmpInput);
- break;
- case VSD_FONTFACE: // substreams of FONTAFACES stream, ver 11 only
- readFont(&tmpInput, i);
- break;
- default:
- break;
- }
- }
- std::vector<unsigned> pageOrder;
- for (i = 0; i < listSize; ++i)
- pageOrder.push_back(readU32(input));
- m_collector->endPages(pageOrder);
-}
-
-void libvisio::VSDXParser::handleStyles(WPXInputStream *input)
-{
- m_isInStyles = true;
-
- try
- {
- long endPos = 0;
-
- while (!input->atEOS())
- {
- getChunkHeader(input);
- endPos = m_header.dataLength+m_header.trailer+input->tell();
-
- _handleLevelChange(m_header.level);
- switch (m_header.chunkType)
- {
- case VSD_STYLE_SHEET:
- readStyleSheet(input);
- break;
- case VSD_LINE:
- readLine(input);
- break;
- case VSD_FILL_AND_SHADOW:
- readFillAndShadow(input);
- break;
- case VSD_CHAR_IX:
- readCharIX(input);
- break;
- case VSD_PARA_IX:
- readParaIX(input);
- break;
- case VSD_TEXT_BLOCK:
- readTextBlock(input);
- break;
- default:
- m_collector->collectUnhandledChunk(m_header.id, m_header.level);
- }
-
- input->seek(endPos, WPX_SEEK_SET);
- }
- _handleLevelChange(0);
- }
- catch (EndOfStreamException)
- {
- _handleLevelChange(0);
- }
-
- m_isInStyles = false;
-}
-
void libvisio::VSDXParser::handleStencils(WPXInputStream *input, unsigned shift)
{
if (m_stencils.count() > 0) return;
diff --git a/src/lib/VSDXParser.h b/src/lib/VSDXParser.h
index 8daf2bc..f9d0d5d 100644
--- a/src/lib/VSDXParser.h
+++ b/src/lib/VSDXParser.h
@@ -57,6 +57,7 @@ struct Pointer
unsigned Offset;
unsigned Length;
unsigned short Format;
+ unsigned ListSize;
};
class VSDXParser
@@ -121,11 +122,9 @@ protected:
// Stream handlers
void handleStreams(WPXInputStream *input, unsigned shift, unsigned level);
- void handleStream(const Pointer &ptr, unsigned level);
+ void handleStream(const Pointer &ptr, unsigned idx, unsigned level);
void handleChunks(WPXInputStream *input);
- void handlePages(WPXInputStream *input, unsigned shift);
- void handleStyles(WPXInputStream *input);
void handleStencils(WPXInputStream *input, unsigned shift);
void handleStencilPage(WPXInputStream *input, unsigned shift);
void handleStencilForeign(WPXInputStream *input, unsigned shift);