From: Fridrich S. <str...@us...> - 2007-10-26 08:16:13
|
Update of /cvsroot/libwpg/libwpg/src/lib In directory sc8-pr-cvs6.sourceforge.net:/tmp/cvs-serv6823/src/lib Modified Files: WPGraphics.cpp Log Message: hide the OLE2 bits from the user of libwpg inside the WPGraphics class Index: WPGraphics.cpp =================================================================== RCS file: /cvsroot/libwpg/libwpg/src/lib/WPGraphics.cpp,v retrieving revision 1.11 retrieving revision 1.12 diff -u -d -r1.11 -r1.12 --- WPGraphics.cpp 8 Oct 2007 20:47:26 -0000 1.11 +++ WPGraphics.cpp 26 Oct 2007 08:16:07 -0000 1.12 @@ -43,11 +43,33 @@ */ bool libwpg::WPGraphics::isSupported(WPXInputStream* input) { + WPXInputStream *graphics = 0; + bool isDocumentOLE = false; + + if (input->isOLEStream()) + { + graphics = input->getDocumentOLEStream("PerfectOffice_MAIN"); + 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; } /** @@ -62,6 +84,20 @@ { WPGXParser *parser = 0; + WPXInputStream *graphics = 0; + bool isDocumentOLE = false; + + if (input->isOLEStream()) + { + graphics = input->getDocumentOLEStream("PerfectOffice_MAIN"); + if (graphics) + isDocumentOLE = true; + else + return false; + } + else + graphics = input; + WPG_DEBUG_MSG(("Loading header...\n")); unsigned char tmpMajorVersion = 0x00; if (fileFormat == WPG_WPG1) @@ -69,43 +105,53 @@ else if (fileFormat == WPG_WPG2) tmpMajorVersion = 0x02; WPGHeader header; - if(!header.load(input)) + if(!header.load(graphics)) + { + if (graphics && isDocumentOLE) + delete graphics; return false; + } if(!header.isSupported() && (fileFormat == WPG_AUTODETECT)) { WPG_DEBUG_MSG(("Unsupported file format!\n")); + if (graphics && isDocumentOLE) + delete graphics; return false; } else if (header.isSupported()) { // seek to the start of document - input->seek(header.startOfDocument(), WPX_SEEK_SET); + graphics->seek(header.startOfDocument(), WPX_SEEK_SET); tmpMajorVersion = header.majorVersion(); } else // here we force parsing of headerless pictures - input->seek(0, WPX_SEEK_SET); + graphics->seek(0, WPX_SEEK_SET); bool retval; switch (tmpMajorVersion) { 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; } |