summaryrefslogtreecommitdiffstats
path: root/svtools
diff options
context:
space:
mode:
authorHenry Castro <hcastro@collabora.com>2019-11-22 18:25:00 -0400
committerHenry Castro <hcastro@collabora.com>2019-11-25 14:32:12 +0100
commit218856c511c09deb930967ae836cdd8d9e9569cb (patch)
treec06dd2674034ecfc7b30a217a80d565c0b551ba8 /svtools
parentLOK: sd: fix unit-tests and add a couple simple ones (diff)
downloadcore-218856c511c09deb930967ae836cdd8d9e9569cb.tar.gz
core-218856c511c09deb930967ae836cdd8d9e9569cb.zip
svtools: encode Base64 the images of the items of the control "ValueSet"
Unfortunately the "Table Design" panel has a "ValueSet" control with images constructed with the function "CreateDesignPreview". I have no other choice to export the images to base64 and send it to client. Perhaps later we can optimize the function "CreateDesignPreview", to accept SVG pattern or something related. Change-Id: I34bc8374ffd2a16fbb8fbc2fcd6a41a96bda57a5 Reviewed-on: https://gerrit.libreoffice.org/83538 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com> Reviewed-by: Henry Castro <hcastro@collabora.com>
Diffstat (limited to 'svtools')
-rw-r--r--svtools/source/control/valueset.cxx34
1 files changed, 32 insertions, 2 deletions
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index 8886e0dbd530..2cd3211175e3 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -18,10 +18,13 @@
*/
#include <tools/debug.hxx>
+#include <comphelper/base64.hxx>
#include <vcl/builderfactory.hxx>
#include <vcl/decoview.hxx>
+#include <vcl/graph.hxx>
#include <vcl/svapp.hxx>
#include <vcl/scrbar.hxx>
+#include <vcl/cvtgrf.hxx>
#include <vcl/help.hxx>
#include <vcl/settings.hxx>
#include <vcl/commandevent.hxx>
@@ -1443,6 +1446,9 @@ boost::property_tree::ptree ValueSet::DumpAsPropertyTree()
boost::property_tree::ptree aTree(Control::DumpAsPropertyTree());
boost::property_tree::ptree aEntries;
+ ErrCode nErrCode;
+ OUStringBuffer aBuffer;
+ SvMemoryStream aStream;
const size_t nSize = mItemList.size();
for ( size_t nIt = 0; nIt < nSize; ++nIt )
@@ -1450,8 +1456,32 @@ boost::property_tree::ptree ValueSet::DumpAsPropertyTree()
boost::property_tree::ptree aEntry;
ValueSetItem* pItem = mItemList[nIt].get();
aEntry.put("id", pItem->mnId);
- aEntry.put("image", pItem->maImage.GetStock());
- if (mnSelItemId == pItem->mnId) {
+ if ( !pItem->maImage.GetStock().isEmpty() )
+ {
+ aEntry.put("image", pItem->maImage.GetStock());
+ }
+ else
+ {
+ Graphic aGraphic(pItem->maImage);
+
+ nErrCode = GraphicConverter::Export(aStream, aGraphic, ConvertDataFormat::PNG);
+ if ( nErrCode )
+ {
+ SAL_WARN("svt", "GraphicConverter::Export() invalid Graphic? error: " << nErrCode );
+ }
+ else
+ {
+ css::uno::Sequence<sal_Int8> aSeq(static_cast<sal_Int8 const *>(aStream.GetData()), aStream.TellEnd());
+ aStream.Seek(0);
+
+ aBuffer.append("data:image/png;base64,");
+ ::comphelper::Base64::encode(aBuffer, aSeq);
+ aEntry.put("image64", aBuffer.makeStringAndClear().toUtf8());
+ }
+ }
+
+ if (mnSelItemId == pItem->mnId)
+ {
aEntry.put("selected", true);
}