/* libvisio * Copyright (C) 2011 Fridrich Strba * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Library General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Library General Public License for more details. * * You should have received a copy of the GNU Library General Public * License along with this library; if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02111-1301 USA */ #include #include #include #include "libvisio.h" #include "libvisio_utils.h" #include "VSDSVGGenerator.h" #include "VSDXParser.h" #include "VSD6Parser.h" #include "VSD11Parser.h" /** Analyzes the content of an input stream to see if it can be parsed \param input The input stream \return A value that indicates whether the content from the input stream is a Visio Document that libvisio able to parse */ bool libvisio::VisioDocument::isSupported(WPXInputStream* input) { WPXInputStream* tmpDocStream = input->getDocumentOLEStream("VisioDocument"); if (!tmpDocStream) return false; tmpDocStream->seek(0x1A, WPX_SEEK_SET); unsigned char version = readU8(tmpDocStream); delete tmpDocStream; VSD_DEBUG_MSG(("VisioDocument: version %i\n", version)); // Versions 2k (6) and 2k3 (11) if (version == 6 || version == 11) { return true; } return false; } /** Parses the input stream content. It will make callbacks to the functions provided by a WPGPaintInterface class implementation when needed. This is often commonly called the 'main parsing routine'. \param input The input stream \param painter A WPGPainterInterface implementation \return A value that indicates whether the parsing was successful */ bool libvisio::VisioDocument::parse(::WPXInputStream* input, libwpg::WPGPaintInterface* painter) { WPXInputStream* docStream = input->getDocumentOLEStream("VisioDocument"); if (!docStream) { return false; } docStream->seek(0x1A, WPX_SEEK_SET); unsigned char version = readU8(docStream); VSDXParser* parser; switch(version) { case 6: parser = new VSD6Parser(docStream, painter); break; case 11: parser = new VSD11Parser(docStream, painter); break; default: return false; } if (parser) { parser->parse(); } else { delete docStream; return false; } delete parser; delete docStream; return true; } /** Parses the input stream content and generates a valid Scalable Vector Graphics Provided as a convenience function for applications that support SVG internally. \param input The input stream \param output The output string whose content is the resulting SVG \return A value that indicates whether the SVG generation was successful. */ bool libvisio::VisioDocument::generateSVG(::WPXInputStream* input, WPXString& output) { std::ostringstream tmpOutputStream; libvisio::VSDSVGGenerator generator(tmpOutputStream); bool result = libvisio::VisioDocument::parse(input, &generator); if (result) output = WPXString(tmpOutputStream.str().c_str()); else output = WPXString(""); return result; }