summaryrefslogtreecommitdiffstats
path: root/src/extension/internal/libwpg/WPGraphics.cpp
diff options
context:
space:
mode:
authorTed Gould <ted@gould.cx>2007-02-25 06:54:05 +0000
committergouldtj <gouldtj@users.sourceforge.net>2007-02-25 06:54:05 +0000
commit3075cb6ff679e7efe68d17109a3608c692e44090 (patch)
tree8f33748e591f51dfdb7dd4f0dc8732b0fc602f3b /src/extension/internal/libwpg/WPGraphics.cpp
parentAdd flood fill tool (diff)
downloadinkscape-3075cb6ff679e7efe68d17109a3608c692e44090.tar.gz
inkscape-3075cb6ff679e7efe68d17109a3608c692e44090.zip
r14551@tres: ted | 2007-02-24 15:22:47 -0800
Merging in the latest libwpg and some code chages to make it work with everything. (bzr r2433)
Diffstat (limited to 'src/extension/internal/libwpg/WPGraphics.cpp')
-rw-r--r--src/extension/internal/libwpg/WPGraphics.cpp56
1 files changed, 45 insertions, 11 deletions
diff --git a/src/extension/internal/libwpg/WPGraphics.cpp b/src/extension/internal/libwpg/WPGraphics.cpp
index e120b802e..ce91e2f61 100644
--- a/src/extension/internal/libwpg/WPGraphics.cpp
+++ b/src/extension/internal/libwpg/WPGraphics.cpp
@@ -30,10 +30,16 @@
#include "WPG1Parser.h"
#include "WPG2Parser.h"
#include "libwpg_utils.h"
+#include "WPGSVGGenerator.h"
+#include <sstream>
-using namespace libwpg;
-
-bool WPGraphics::isSupported(WPGInputStream* input)
+/**
+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 WordPerfect Graphics that libwpg is able to parse
+*/
+bool libwpg::WPGraphics::isSupported(libwpg::WPGInputStream* input)
{
WPGHeader header;
if(!header.load(input))
@@ -42,7 +48,15 @@ bool WPGraphics::isSupported(WPGInputStream* input)
return header.isSupported();
}
-bool WPGraphics::parse(WPGInputStream* input, WPGPaintInterface* painter)
+/**
+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 libwpg::WPGraphics::parse(libwpg::WPGInputStream* input, libwpg::WPGPaintInterface* painter)
{
WPGXParser *parser = 0;
@@ -59,25 +73,45 @@ bool WPGraphics::parse(WPGInputStream* input, WPGPaintInterface* painter)
// seek to the start of document
input->seek(header.startOfDocument());
-
+
+ bool retval;
switch (header.majorVersion()) {
case 0x01: // WPG1
WPG_DEBUG_MSG(("Parsing WPG1\n"));
parser = new WPG1Parser(input, painter);
- parser->parse();
+ retval = parser->parse();
break;
case 0x02: // WPG2
WPG_DEBUG_MSG(("Parsing WPG2\n"));
parser = new WPG2Parser(input, painter);
- parser->parse();
+ retval = parser->parse();
break;
default: // other :-)
WPG_DEBUG_MSG(("Unknown format\n"));
- break;
+ return false;
}
- delete parser;
+ if (parser)
+ delete parser;
- return false;
+ return retval;
+}
+
+/**
+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 libwpg::WPGraphics::generateSVG(libwpg::WPGInputStream* input, libwpg::WPGString& output)
+{
+ std::ostringstream tmpOutputStream;
+ libwpg::WPGSVGGenerator generator(tmpOutputStream);
+ bool result;
+ if (result = libwpg::WPGraphics::parse(input, &generator))
+ output = WPGString(tmpOutputStream.str().c_str());
+ else
+ output = WPGString("");
+ return result;
}
-