diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2012-09-21 16:59:54 +0200 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2012-09-21 16:59:54 +0200 |
commit | 496c9afaa4b48c9930cf6ee8c1b2c95116d712e6 (patch) | |
tree | b07f1060d2e4407576d58b9c893fdb7e4a5f1191 | |
parent | ccfdb3f0f9a3ea713e49692ba87c9c7d8a581c31 (diff) |
Add BIPU VDX parser
-rw-r--r-- | build/win32/libvisio.dsp | 8 | ||||
-rw-r--r-- | src/lib/Makefile.am | 2 | ||||
-rw-r--r-- | src/lib/VDXParser.cpp | 163 | ||||
-rw-r--r-- | src/lib/VDXParser.h | 79 | ||||
-rw-r--r-- | src/lib/VisioDocument.cpp | 6 | ||||
-rw-r--r-- | src/lib/makefile.mk | 1 |
6 files changed, 258 insertions, 1 deletions
diff --git a/build/win32/libvisio.dsp b/build/win32/libvisio.dsp index d28623f..f4919c9 100644 --- a/build/win32/libvisio.dsp +++ b/build/win32/libvisio.dsp @@ -91,6 +91,10 @@ SOURCE=..\..\src\lib\libvisio_utils.cpp # End Source File
# Begin Source File
+SOURCE=..\..\src\lib\VDXParser.cpp
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\lib\VisioDocument.cpp
# End Source File
# Begin Source File
@@ -187,6 +191,10 @@ SOURCE=..\..\src\lib\libvisio_utils.h # End Source File
# Begin Source File
+SOURCE=..\..\src\lib\VDXParser.h
+# End Source File
+# Begin Source File
+
SOURCE=..\..\src\lib\VisioDocument.h
# End Source File
# Begin Source File
diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 9639a30..17ae4b0 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -18,6 +18,7 @@ libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_la_DEPENDENCIES = @LIBVISIO_WIN libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_la_LDFLAGS = $(version_info) -export-dynamic -no-undefined libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_la_SOURCES = \ libvisio_utils.cpp \ + VDXParser.cpp \ VisioDocument.cpp \ VSD11Parser.cpp \ VSD6Parser.cpp \ @@ -40,6 +41,7 @@ libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_la_SOURCES = \ VSDXParser.cpp \ VSDZipStream.cpp \ libvisio_utils.h \ + VDXParser.h \ VSD11Parser.h \ VSD6Parser.h \ VSDInternalStream.h \ diff --git a/src/lib/VDXParser.cpp b/src/lib/VDXParser.cpp new file mode 100644 index 0000000..9e5d865 --- /dev/null +++ b/src/lib/VDXParser.cpp @@ -0,0 +1,163 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* libvisio + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <string.h> +#include <libxml/xmlIO.h> +#include <libxml/xmlstring.h> +#include <libwpd-stream/libwpd-stream.h> +#include <boost/algorithm/string.hpp> +#include "VDXParser.h" +#include "libvisio_utils.h" +#include "VSDContentCollector.h" +#include "VSDStylesCollector.h" +#include "VSDZipStream.h" +#include "VSDXMLHelper.h" + + +libvisio::VDXParser::VDXParser(WPXInputStream *input, libwpg::WPGPaintInterface *painter) + : m_input(input), m_painter(painter), m_collector(), m_stencils(), m_extractStencils(false) +{ +} + +libvisio::VDXParser::~VDXParser() +{ +} + +bool libvisio::VDXParser::parseMain() +{ + if (!m_input) + return false; + + WPXInputStream *tmpInput = 0; + try + { + std::vector<std::map<unsigned, XForm> > groupXFormsSequence; + std::vector<std::map<unsigned, unsigned> > groupMembershipsSequence; + std::vector<std::list<unsigned> > documentPageShapeOrders; + + VSDStylesCollector stylesCollector(groupXFormsSequence, groupMembershipsSequence, documentPageShapeOrders); + m_collector = &stylesCollector; + m_input->seek(0, WPX_SEEK_SET); + if (!processXmlDocument(m_input)) + return false; + + VSDStyles styles = stylesCollector.getStyleSheets(); + + VSDContentCollector contentCollector(m_painter, groupXFormsSequence, groupMembershipsSequence, documentPageShapeOrders, styles, m_stencils); + m_collector = &contentCollector; + m_input->seek(0, WPX_SEEK_SET); + if (!processXmlDocument(m_input)) + return false; + + return true; + } + catch (...) + { + if (tmpInput) + delete tmpInput; + return false; + } +} + +bool libvisio::VDXParser::extractStencils() +{ + m_extractStencils = true; + return parseMain(); +} + +bool libvisio::VDXParser::processXmlDocument(WPXInputStream *input) +{ + if (!input) + return false; + + xmlTextReaderPtr reader = xmlReaderForStream(input, 0, 0, XML_PARSE_NOENT|XML_PARSE_NOBLANKS|XML_PARSE_NONET); + if (!reader) + return false; + int ret = xmlTextReaderRead(reader); + while (ret == 1) + { + xmlChar *nodeName = xmlTextReaderName(reader); + processXmlNode(reader); + + xmlFree(nodeName); + ret = xmlTextReaderRead(reader); + } + xmlFreeTextReader(reader); + + if (ret) + { + VSD_DEBUG_MSG(("Failed to parse DiagramML document\n")); + return false; + } + + return true; +} + +void libvisio::VDXParser::processXmlNode(xmlTextReaderPtr reader) +{ + if (!reader) + return; +#ifdef DEBUG + xmlChar *name = xmlTextReaderName(reader); + if (!name) + name = xmlStrdup(BAD_CAST("")); + xmlChar *value = xmlTextReaderValue(reader); + int type = xmlTextReaderNodeType(reader); + int isEmptyElement = xmlTextReaderIsEmptyElement(reader); + + for (int i=0; i<xmlTextReaderDepth(reader); ++i) + { + VSD_DEBUG_MSG((" ")); + } + VSD_DEBUG_MSG(("%i %i %s", isEmptyElement, type, name)); + xmlFree(name); + if (xmlTextReaderNodeType(reader) == 1) + { + xmlChar *name1, *value1; + while (xmlTextReaderMoveToNextAttribute(reader)) + { + name1 = xmlTextReaderName(reader); + value1 = xmlTextReaderValue(reader); + printf(" %s=\"%s\"", name1, value1); + xmlFree(name1); + xmlFree(value1); + } + } + + if (!value) + VSD_DEBUG_MSG(("\n")); + else + { + VSD_DEBUG_MSG((" %s\n", value)); + xmlFree(value); + } +#endif +} + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VDXParser.h b/src/lib/VDXParser.h new file mode 100644 index 0000000..c4299ee --- /dev/null +++ b/src/lib/VDXParser.h @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ +/* libvisio + * Version: MPL 1.1 / GPLv2+ / LGPLv2+ + * + * The contents of this file are subject to the Mozilla Public License Version + * 1.1 (the "License"); you may not use this file except in compliance with + * the License or as specified alternatively below. You may obtain a copy of + * the License at http://www.mozilla.org/MPL/ + * + * Software distributed under the License is distributed on an "AS IS" basis, + * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License + * for the specific language governing rights and limitations under the + * License. + * + * Major Contributor(s): + * Copyright (C) 2012 Fridrich Strba <fridrich.strba@bluewin.ch> + * + * + * All Rights Reserved. + * + * For minor contributions see the git repository. + * + * Alternatively, the contents of this file may be used under the terms of + * either the GNU General Public License Version 2 or later (the "GPLv2+"), or + * the GNU Lesser General Public License Version 2 or later (the "LGPLv2+"), + * in which case the provisions of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#ifndef __VDXPARSER_H__ +#define __VDXPARSER_H__ + +#include <map> +#include <string> +#include <libwpd-stream/libwpd-stream.h> +#include <libwpg/libwpg.h> +#include "VSDXMLHelper.h" +#include "VSDStencils.h" + +namespace libvisio +{ + +class VSDCollector; + +class VDXParser +{ +public: + explicit VDXParser(WPXInputStream *input, libwpg::WPGPaintInterface *painter); + virtual ~VDXParser(); + bool parseMain(); + bool extractStencils(); + +private: + VDXParser(); + VDXParser(const VDXParser &); + VDXParser &operator=(const VDXParser &); + + // Functions to read teh DiagramML document structure + + bool processXmlDocument(WPXInputStream *input); + void processXmlNode(xmlTextReaderPtr reader); + + // Functions reading the DiagramML document content + + + // Private data + + WPXInputStream *m_input; + libwpg::WPGPaintInterface *m_painter; + VSDCollector *m_collector; + VSDStencils m_stencils; + + bool m_extractStencils; +}; + +} // namespace libvisio + +#endif // __VDXPARSER_H__ +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VisioDocument.cpp b/src/lib/VisioDocument.cpp index 2dfe880..ce656b7 100644 --- a/src/lib/VisioDocument.cpp +++ b/src/lib/VisioDocument.cpp @@ -32,6 +32,7 @@ #include <string> #include "libvisio.h" #include "libvisio_utils.h" +#include "VDXParser.h" #include "VSDSVGGenerator.h" #include "VSDParser.h" #include "VSDXParser.h" @@ -252,7 +253,10 @@ bool libvisio::VisioDocument::parse(::WPXInputStream *input, libwpg::WPGPaintInt { VSD_DEBUG_MSG(("Parsing Visio DrawingML Document\n")); input->seek(0, WPX_SEEK_SET); - return true; + VDXParser parser(input, painter); + if (parser.parseMain()) + return true; + return false; } return false; } diff --git a/src/lib/makefile.mk b/src/lib/makefile.mk index ca6ed30..f072ad1 100644 --- a/src/lib/makefile.mk +++ b/src/lib/makefile.mk @@ -40,6 +40,7 @@ INCPRE+=-I$(SOLARVER)$/$(INPATH)$/inc$/external/libxml SLOFILES= \ $(SLO)$/libvisio_utils.obj \ + $(SLO)$/VDXParser.obj \ $(SLO)$/VisioDocument.obj \ $(SLO)$/VSD11Parser.obj \ $(SLO)$/VSD6Parser.obj \ |