diff options
author | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2012-02-15 11:00:56 +0100 |
---|---|---|
committer | Fridrich Štrba <fridrich.strba@bluewin.ch> | 2012-02-15 11:00:56 +0100 |
commit | e07e23d50b383dad42207efc010df2eacce251a3 (patch) | |
tree | b926ce6036ab8de2be2494d5ff9417028c0ae1c9 /src | |
parent | e5fa75081a731af22efa8de830cbbeaf2c030995 (diff) |
Output a vector of SVG documents by the API
Diffstat (limited to 'src')
-rw-r--r-- | src/conv/svg/vsd2xhtml.cpp | 22 | ||||
-rw-r--r-- | src/lib/Makefile.am | 2 | ||||
-rw-r--r-- | src/lib/VSDSVGGenerator.cpp | 15 | ||||
-rw-r--r-- | src/lib/VSDSVGGenerator.h | 8 | ||||
-rw-r--r-- | src/lib/VSDStringVector.cpp | 93 | ||||
-rw-r--r-- | src/lib/VSDStringVector.h | 61 | ||||
-rw-r--r-- | src/lib/VisioDocument.cpp | 10 | ||||
-rw-r--r-- | src/lib/VisioDocument.h | 3 |
8 files changed, 188 insertions, 26 deletions
diff --git a/src/conv/svg/vsd2xhtml.cpp b/src/conv/svg/vsd2xhtml.cpp index 2b1904a..77dd346 100644 --- a/src/conv/svg/vsd2xhtml.cpp +++ b/src/conv/svg/vsd2xhtml.cpp @@ -76,12 +76,18 @@ int main(int argc, char *argv[]) return 1; } - ::WPXString output; + libvisio::VSDStringVector output; if (!libvisio::VisioDocument::generateSVG(&input, output)) { std::cerr << "ERROR: SVG Generation failed!" << std::endl; return 1; } + + if (output.empty()) + { + std::cerr << "ERROR: No SVG document generated!" << std::endl; + return 1; + } std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" << std::endl; std::cout << "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">" << std::endl; @@ -89,7 +95,19 @@ int main(int argc, char *argv[]) std::cout << "<body>" << std::endl; std::cout << "<?import namespace=\"svg\" urn=\"http://www.w3.org/2000/svg\"?>" << std::endl; - std::cout << output.cstr() << std::endl; + for (unsigned k = 0; k<output.size(); ++k) + { + if (k>0) + std::cout << "<hr/>\n"; + + std::cout << "<!-- \n"; + std::cout << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; + std::cout << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""; + std::cout << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; + std::cout << " -->\n"; + + std::cout << output[k].cstr() << std::endl; + } std::cout << "</body>" << std::endl; std::cout << "</html>" << std::endl; diff --git a/src/lib/Makefile.am b/src/lib/Makefile.am index 74af854..ebe1a9a 100644 --- a/src/lib/Makefile.am +++ b/src/lib/Makefile.am @@ -8,6 +8,7 @@ lib_LTLIBRARIES = libvisio-@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@.la libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_includedir = $(includedir)/libvisio-@VSD_MAJOR_VERSION@.@VSD_MINOR_VERSION@/libvisio libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_include_HEADERS = \ libvisio.h \ + VSDStringVector.h \ VisioDocument.h AM_CXXFLAGS = $(LIBVISIO_CXXFLAGS) $(DEBUG_CXXFLAGS) @@ -32,6 +33,7 @@ libvisio_@VSD_MAJOR_VERSION@_@VSD_MINOR_VERSION@_la_SOURCES = \ VSDXParser.cpp \ VSDXShapeList.cpp \ VSDXStencils.cpp \ + VSDStringVector.cpp \ VSDXStyles.cpp \ VSDXStylesCollector.cpp \ libvisio_utils.h \ diff --git a/src/lib/VSDSVGGenerator.cpp b/src/lib/VSDSVGGenerator.cpp index 11735ed..402d51b 100644 --- a/src/lib/VSDSVGGenerator.cpp +++ b/src/lib/VSDSVGGenerator.cpp @@ -73,7 +73,7 @@ static unsigned stringToColour(const ::WPXString &s) return val; } -libvisio::VSDSVGGenerator::VSDSVGGenerator(std::ostream &output_sink): m_gradient(), m_style(), m_gradientIndex(1), m_shadowIndex(1), m_isFirstPage(true), m_outputSink(output_sink) +libvisio::VSDSVGGenerator::VSDSVGGenerator(libvisio::VSDStringVector &vec): m_gradient(), m_style(), m_gradientIndex(1), m_shadowIndex(1), m_outputSink(), m_vec(vec) { } @@ -83,17 +83,6 @@ libvisio::VSDSVGGenerator::~VSDSVGGenerator() void libvisio::VSDSVGGenerator::startGraphics(const WPXPropertyList &propList) { - if (m_isFirstPage) - m_isFirstPage = false; - else - m_outputSink << "<hr/>\n"; - - m_outputSink << "<!-- \n"; - m_outputSink << "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"; - m_outputSink << "<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\""; - m_outputSink << " \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n"; - m_outputSink << " -->\n"; - m_outputSink << "<svg:svg version=\"1.1\" xmlns:svg=\"http://www.w3.org/2000/svg\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" "; if (propList["svg:width"]) m_outputSink << "width=\"" << doubleToString(72*(propList["svg:width"]->getDouble())) << "\" "; @@ -105,6 +94,8 @@ void libvisio::VSDSVGGenerator::startGraphics(const WPXPropertyList &propList) void libvisio::VSDSVGGenerator::endGraphics() { m_outputSink << "</svg:svg>\n"; + m_vec.append(m_outputSink.str().c_str()); + m_outputSink.clear(); } void libvisio::VSDSVGGenerator::setStyle(const ::WPXPropertyList &propList, const ::WPXPropertyListVector &gradient) diff --git a/src/lib/VSDSVGGenerator.h b/src/lib/VSDSVGGenerator.h index 15dbe94..d82ff75 100644 --- a/src/lib/VSDSVGGenerator.h +++ b/src/lib/VSDSVGGenerator.h @@ -33,8 +33,10 @@ #include <stdio.h> #include <iostream> +#include <sstream> #include <libwpd/libwpd.h> #include <libwpg/libwpg.h> +#include "VSDStringVector.h" namespace libvisio { @@ -42,7 +44,7 @@ namespace libvisio class VSDSVGGenerator : public libwpg::WPGPaintInterface { public: - VSDSVGGenerator(std::ostream &output_sink); + VSDSVGGenerator(VSDStringVector &vec); ~VSDSVGGenerator(); void startGraphics(const ::WPXPropertyList &propList); @@ -73,11 +75,11 @@ private: ::WPXPropertyList m_style; int m_gradientIndex; int m_shadowIndex; - bool m_isFirstPage; void writeStyle(bool isClosed=true); void drawPolySomething(const ::WPXPropertyListVector &vertices, bool isClosed); - std::ostream &m_outputSink; + std::ostringstream m_outputSink; + VSDStringVector &m_vec; }; } // namespace libvisio diff --git a/src/lib/VSDStringVector.cpp b/src/lib/VSDStringVector.cpp new file mode 100644 index 0000000..26bb5cd --- /dev/null +++ b/src/lib/VSDStringVector.cpp @@ -0,0 +1,93 @@ +/* -*- 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 procdrns of the GPLv2+ or the LGPLv2+ are applicable + * instead of those above. + */ + +#include <vector> +#include "VSDStringVector.h" + +namespace libvisio +{ +class VSDStringVectorImpl +{ +public: + VSDStringVectorImpl() : m_strings() {} + VSDStringVectorImpl(const VSDStringVectorImpl &impl) : m_strings(impl.m_strings) {} + ~VSDStringVectorImpl() {} + std::vector<WPXString> m_strings; +}; + +} // namespace libvisio + +libvisio::VSDStringVector::VSDStringVector() + : m_pImpl(new VSDStringVectorImpl()) +{ +} + +libvisio::VSDStringVector::VSDStringVector(const VSDStringVector &vec) + : m_pImpl(new VSDStringVectorImpl(*(vec.m_pImpl))) +{ +} + +libvisio::VSDStringVector::~VSDStringVector() +{ +} + +libvisio::VSDStringVector &libvisio::VSDStringVector::operator=(const VSDStringVector &vec) +{ + if (m_pImpl) + delete m_pImpl; + m_pImpl = new VSDStringVectorImpl(*(vec.m_pImpl)); + return *this; +} + +unsigned libvisio::VSDStringVector::size() const +{ + return (unsigned)(m_pImpl->m_strings.size()); +} + +bool libvisio::VSDStringVector::empty() const +{ + return m_pImpl->m_strings.empty(); +} + +const WPXString &libvisio::VSDStringVector::operator[](unsigned idx) const +{ + return m_pImpl->m_strings[idx]; +} + +void libvisio::VSDStringVector::append(const WPXString &str) +{ + m_pImpl->m_strings.push_back(str); +} + +void libvisio::VSDStringVector::clear() +{ + m_pImpl->m_strings.clear(); +} + +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VSDStringVector.h b/src/lib/VSDStringVector.h new file mode 100644 index 0000000..50c929f --- /dev/null +++ b/src/lib/VSDStringVector.h @@ -0,0 +1,61 @@ +/* -*- 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 __VSDSTRINGVECTOR_H__ +#define __VSDSTRINGVECTOR_H__ + +#include <libwpd/libwpd.h> + +namespace libvisio +{ +class VSDStringVectorImpl; + +class VSDStringVector +{ +public: + VSDStringVector(); + VSDStringVector(const VSDStringVector &vec); + ~VSDStringVector(); + + VSDStringVector &operator=(const VSDStringVector &vec); + + unsigned size() const; + bool empty() const; + const WPXString &operator[](unsigned idx) const; + void append(const WPXString &str); + void clear(); + +private: + VSDStringVectorImpl *m_pImpl; +}; + +} // namespace libvisio + +#endif /* __VSDSTRINGVECTOR_H__ */ +/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VisioDocument.cpp b/src/lib/VisioDocument.cpp index 83bdd10..d193ddd 100644 --- a/src/lib/VisioDocument.cpp +++ b/src/lib/VisioDocument.cpp @@ -29,7 +29,6 @@ */ #include <libwpd-stream/libwpd-stream.h> -#include <sstream> #include <string> #include "libvisio.h" #include "libvisio_utils.h" @@ -121,15 +120,10 @@ Provided as a convenience function for applications that support SVG internally. \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) +bool libvisio::VisioDocument::generateSVG(::WPXInputStream *input, libvisio::VSDStringVector &output) { - std::ostringstream tmpOutputStream; - libvisio::VSDSVGGenerator generator(tmpOutputStream); + libvisio::VSDSVGGenerator generator(output); bool result = libvisio::VisioDocument::parse(input, &generator); - if (result) - output = WPXString(tmpOutputStream.str().c_str()); - else - output = WPXString(""); return result; } /* vim:set shiftwidth=2 softtabstop=2 expandtab: */ diff --git a/src/lib/VisioDocument.h b/src/lib/VisioDocument.h index 913177f..e9c89de 100644 --- a/src/lib/VisioDocument.h +++ b/src/lib/VisioDocument.h @@ -33,6 +33,7 @@ #include <libwpd/libwpd.h> #include <libwpg/libwpg.h> +#include "VSDStringVector.h" class WPXInputStream; @@ -47,7 +48,7 @@ public: static bool parse(WPXInputStream *input, libwpg::WPGPaintInterface *painter); - static bool generateSVG(WPXInputStream *input, WPXString &output); + static bool generateSVG(WPXInputStream *input, VSDStringVector &output); }; } // namespace libvisio |