From e79c9c4c5a84f0409362361901fbdcb6a574ed87 Mon Sep 17 00:00:00 2001 From: Fridrich Štrba Date: Sun, 8 Apr 2012 22:11:52 +0200 Subject: Generate SVG preview of embedded WPG image --- .../source/wpdimp/WordPerfectImportFilter.cxx | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) (limited to 'writerperfect/source') diff --git a/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx b/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx index a82338f6727e..2dab43a0e82d 100644 --- a/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx +++ b/writerperfect/source/wpdimp/WordPerfectImportFilter.cxx @@ -85,7 +85,7 @@ using com::sun::star::xml::sax::XParser; void callHandler(uno::Reference < XDocumentHandler > xDocHandler); -static bool handleEmbeddedWPG(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType) +static bool handleEmbeddedWPGObject(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType) { OdgGenerator exporter(pHandler, streamType); @@ -97,6 +97,22 @@ static bool handleEmbeddedWPG(const WPXBinaryData &data, OdfDocumentHandler *pHa return libwpg::WPGraphics::parse(const_cast(data.getDataStream()), &exporter, fileFormat); } +static bool handleEmbeddedWPGImage(const WPXBinaryData &input, WPXBinaryData &output) +{ + WPXString svgOutput; + libwpg::WPGFileFormat fileFormat = libwpg::WPG_AUTODETECT; + + if (!libwpg::WPGraphics::isSupported(const_cast(input.getDataStream()))) + fileFormat = libwpg::WPG_WPG1; + + if (!libwpg::WPGraphics::generateSVG(const_cast(input.getDataStream()), svgOutput, fileFormat)) + return false; + + output.clear(); + output.append((unsigned char *)svgOutput.cstr(), strlen(svgOutput.cstr())); + return true; +} + sal_Bool SAL_CALL WordPerfectImportFilter::importImpl( const Sequence< ::com::sun::star::beans::PropertyValue >& aDescriptor ) throw (RuntimeException) { @@ -159,7 +175,8 @@ throw (RuntimeException) DocumentHandler xHandler(xInternalHandler); OdtGenerator collector(&xHandler, ODF_FLAT_XML); - collector.registerEmbeddedObjectHandler("image/x-wpg", &handleEmbeddedWPG); + collector.registerEmbeddedObjectHandler("image/x-wpg", &handleEmbeddedWPGObject); + collector.registerEmbeddedImageHandler("image/x-wpg", &handleEmbeddedWPGImage); if (WPD_OK == WPDocument::parse(&input, &collector, aUtf8Passwd.isEmpty() ? 0 : aUtf8Passwd.getStr())) return sal_True; return sal_False; -- cgit