From: Fridrich S. <str...@us...> - 2007-12-07 16:14:15
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv4520/src/lib Modified Files: Tag: STABLE-0-1-0 WPGraphics.cpp Log Message: handle ole in the WPGraphics class Index: WPGraphics.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGraphics.cpp,v retrieving revision 1.10 retrieving revision 1.10.2.1 diff -u -d -r1.10 -r1.10.2.1 --- WPGraphics.cpp 3 Jul 2007 13:03:19 -0000 1.10 +++ WPGraphics.cpp 7 Dec 2007 16:14:10 -0000 1.10.2.1 @@ -1,5 +1,6 @@ /* libwpg * Copyright (C) 2006 Ariya Hidayat (ar...@kd...) + * Copyright (C) 2007 Fridrich Strba (fri...@bl...) * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public @@ -42,11 +43,34 @@ */ bool libwpg::WPGraphics::isSupported(WPXInputStream* input) { + input->seek(0, WPX_SEEK_SET); + WPXInputStream *graphics = 0; + bool isDocumentOLE = false; + + if (input->isOLEStream()) + { + graphics = input->getDocumentOLEStream(); + if (graphics) + isDocumentOLE = true; + else + return false; + } + else + graphics = input; + WPGHeader header; - if(!header.load(input)) + if(!header.load(graphics)) + { + if (graphics && isDocumentOLE) + delete graphics; return false; + } - return header.isSupported(); + bool retVal = header.isSupported(); + + if (graphics && isDocumentOLE) + delete graphics; + return retVal; } /** @@ -57,43 +81,67 @@ \param painter A WPGPainterInterface implementation \return A value that indicates whether the parsing was successful */ -bool libwpg::WPGraphics::parse(WPXInputStream* input, libwpg::WPGPaintInterface* painter) +bool libwpg::WPGraphics::parse(::WPXInputStream* input, libwpg::WPGPaintInterface* painter) { + input->seek(0, WPX_SEEK_CUR); WPGXParser *parser = 0; + WPXInputStream *graphics = 0; + bool isDocumentOLE = false; + + if (input->isOLEStream()) + { + graphics = input->getDocumentOLEStream(); + if (graphics) + isDocumentOLE = true; + else + return false; + } + else + graphics = input; + WPG_DEBUG_MSG(("Loading header...\n")); WPGHeader header; - if(!header.load(input)) + if(!header.load(graphics)) + { + if (graphics && isDocumentOLE) + delete graphics; return false; + } if(!header.isSupported()) { WPG_DEBUG_MSG(("Unsupported file format!\n")); + if (graphics && isDocumentOLE) + delete graphics; return false; } - - // seek to the start of document - input->seek(header.startOfDocument(), WPX_SEEK_SET); + + graphics->seek(header.startOfDocument(), WPX_SEEK_SET); bool retval; switch (header.majorVersion()) { case 0x01: // WPG1 WPG_DEBUG_MSG(("Parsing WPG1\n")); - parser = new WPG1Parser(input, painter); + parser = new WPG1Parser(graphics, painter); retval = parser->parse(); break; case 0x02: // WPG2 WPG_DEBUG_MSG(("Parsing WPG2\n")); - parser = new WPG2Parser(input, painter); + parser = new WPG2Parser(graphics, painter); retval = parser->parse(); break; default: // other :-) WPG_DEBUG_MSG(("Unknown format\n")); + if (graphics && isDocumentOLE) + delete graphics; return false; } if (parser) delete parser; + if (graphics && isDocumentOLE) + delete graphics; return retval; } |