summaryrefslogtreecommitdiff
path: root/writerperfect/source
diff options
context:
space:
mode:
authorFridrich Štrba <fridrich.strba@bluewin.ch>2012-04-08 21:56:42 +0200
committerFridrich Štrba <fridrich.strba@bluewin.ch>2012-04-08 22:07:07 +0200
commit04950bf3c339f074588fbcff7121fdff76f00163 (patch)
tree154d8b396fa4a4f5674d318f31321f4bf7188b7c /writerperfect/source
parent00e60cf7c9b1c9dcd0cee90bd67877b02be46c32 (diff)
Allow conversion of embedded images to another binary image format
Diffstat (limited to 'writerperfect/source')
-rw-r--r--writerperfect/source/filter/OdtGenerator.cxx58
-rw-r--r--writerperfect/source/filter/OdtGenerator.hxx2
2 files changed, 50 insertions, 10 deletions
diff --git a/writerperfect/source/filter/OdtGenerator.cxx b/writerperfect/source/filter/OdtGenerator.cxx
index ecb29bb3079e..8f6ae1bc4395 100644
--- a/writerperfect/source/filter/OdtGenerator.cxx
+++ b/writerperfect/source/filter/OdtGenerator.cxx
@@ -118,6 +118,7 @@ public:
void _closeListLevel();
OdfEmbeddedObject _findEmbeddedObjectHandler(const WPXString &mimeType);
+ OdfEmbeddedImage _findEmbeddedImageHandler(const WPXString &mimeType);
OdfDocumentHandler *mpHandler;
bool mbUsed; // whether or not it has been before (you can only use me once!)
@@ -148,6 +149,7 @@ public:
// embedded object handlers
std::map<WPXString, OdfEmbeddedObject, ltstr > mObjectHandlers;
+ std::map<WPXString, OdfEmbeddedImage, ltstr > mImageHandlers;
// metadata
std::vector<DocumentElement *> mMetaData;
@@ -187,7 +189,7 @@ OdtGeneratorPrivate::OdtGeneratorPrivate(OdfDocumentHandler *pHandler, const Odf
mWriterListStates(),
mParagraphManager(), mSpanManager(), mFontManager(),
mSectionStyles(), mTableStyles(), mFrameStyles(), mFrameAutomaticStyles(),
- mObjectHandlers(), mMetaData(),
+ mObjectHandlers(), mImageHandlers(), mMetaData(),
miNumListStyles(0),
mBodyElements(),
mpCurrentContentElements(&mBodyElements),
@@ -267,6 +269,15 @@ OdfEmbeddedObject OdtGeneratorPrivate::_findEmbeddedObjectHandler(const WPXStrin
return 0;
}
+OdfEmbeddedImage OdtGeneratorPrivate::_findEmbeddedImageHandler(const WPXString &mimeType)
+{
+ std::map<WPXString, OdfEmbeddedImage, ltstr>::iterator i = mImageHandlers.find(mimeType);
+ if (i != mImageHandlers.end())
+ return i->second;
+
+ return 0;
+}
+
OdtGenerator::OdtGenerator(OdfDocumentHandler *pHandler, const OdfStreamType streamType) :
mpImpl(new OdtGeneratorPrivate(pHandler, streamType))
{
@@ -1247,18 +1258,40 @@ void OdtGenerator::insertBinaryObject(const WPXPropertyList &propList, const WPX
return;
OdfEmbeddedObject tmpObjectHandler = mpImpl->_findEmbeddedObjectHandler(propList["libwpd:mimetype"]->getStr());
+ OdfEmbeddedImage tmpImageHandler = mpImpl->_findEmbeddedImageHandler(propList["libwpd:mimetype"]->getStr());
- if (tmpObjectHandler)
+ if (tmpObjectHandler || tmpImageHandler)
{
- std::vector<DocumentElement *> tmpContentElements;
- InternalHandler tmpHandler(&tmpContentElements);
-
- if (tmpObjectHandler(data, &tmpHandler, ODF_FLAT_XML) && !tmpContentElements.empty())
+ if (tmpObjectHandler)
{
- mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:object"));
- for (std::vector<DocumentElement *>::const_iterator iter = tmpContentElements.begin(); iter != tmpContentElements.end(); ++iter)
- mpImpl->mpCurrentContentElements->push_back(*iter);
- mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:object"));
+ std::vector<DocumentElement *> tmpContentElements;
+ InternalHandler tmpHandler(&tmpContentElements);
+
+ if (tmpObjectHandler(data, &tmpHandler, ODF_FLAT_XML) && !tmpContentElements.empty())
+ {
+ mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:object"));
+ for (std::vector<DocumentElement *>::const_iterator iter = tmpContentElements.begin(); iter != tmpContentElements.end(); ++iter)
+ mpImpl->mpCurrentContentElements->push_back(*iter);
+ mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:object"));
+ }
+ }
+ if (tmpImageHandler)
+ {
+ WPXBinaryData output;
+ if (tmpImageHandler(data, output))
+ {
+ mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("draw:image"));
+
+ mpImpl->mpCurrentContentElements->push_back(new TagOpenElement("office:binary-data"));
+
+ WPXString binaryBase64Data = output.getBase64Data();
+
+ mpImpl->mpCurrentContentElements->push_back(new CharDataElement(binaryBase64Data.cstr()));
+
+ mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("office:binary-data"));
+
+ mpImpl->mpCurrentContentElements->push_back(new TagCloseElement("draw:image"));
+ }
}
}
else
@@ -1346,4 +1379,9 @@ void OdtGenerator::registerEmbeddedObjectHandler(const WPXString &mimeType, OdfE
mpImpl->mObjectHandlers[mimeType] = objectHandler;
}
+void OdtGenerator::registerEmbeddedImageHandler(const WPXString &mimeType, OdfEmbeddedImage imageHandler)
+{
+ mpImpl->mImageHandlers[mimeType] = imageHandler;
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerperfect/source/filter/OdtGenerator.hxx b/writerperfect/source/filter/OdtGenerator.hxx
index 12c6df39978e..1275c1c2d5bc 100644
--- a/writerperfect/source/filter/OdtGenerator.hxx
+++ b/writerperfect/source/filter/OdtGenerator.hxx
@@ -38,6 +38,7 @@
typedef bool (*OdfEmbeddedObject)(const WPXBinaryData &data, OdfDocumentHandler *pHandler, const OdfStreamType streamType);
+typedef bool (*OdfEmbeddedImage)(const WPXBinaryData &input, WPXBinaryData &output);
class OdtGeneratorPrivate;
@@ -113,6 +114,7 @@ public:
// Register special converter for certain embedded binary objects
void registerEmbeddedObjectHandler(const WPXString &mimeType, OdfEmbeddedObject objectHandler);
+ void registerEmbeddedImageHandler(const WPXString &mimeType, OdfEmbeddedImage imageHandler);
private:
OdtGeneratorPrivate *mpImpl;