summaryrefslogtreecommitdiff
path: root/desktop
diff options
context:
space:
mode:
authorAshod Nakashian <ashod.nakashian@collabora.co.uk>2019-07-20 11:07:01 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-08-02 11:41:49 -0400
commitb7b091ed71557213e9ce9123dfed727393e86b4b (patch)
tree83d4284b0a54774ce030a83f85a2b2b3d4474cb6 /desktop
parentab8a6d596f2850b600bc3bc2f08f008b96fc65cd (diff)
LOK: Copy Graphics as embedded PNG in HTML
Change-Id: Id8c14d7304d30bfcd956b126dfe291ef044f62bf
Diffstat (limited to 'desktop')
-rw-r--r--desktop/source/lib/init.cxx36
1 files changed, 35 insertions, 1 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 6b0e8863bbd9..af4f531e89ba 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -47,6 +47,7 @@
#include <rtl/strbuf.hxx>
#include <rtl/uri.hxx>
#include <cppuhelper/bootstrap.hxx>
+#include <comphelper/base64.hxx>
#include <comphelper/dispatchcommand.hxx>
#include <comphelper/lok.hxx>
#include <comphelper/processfactory.hxx>
@@ -3415,6 +3416,15 @@ static void doc_setTextSelection(LibreOfficeKitDocument* pThis, int nType, int n
pDoc->setTextSelection(nType, nX, nY);
}
+static OUString getGenerator()
+{
+ OUString sGenerator(
+ Translate::ExpandVariables("%PRODUCTNAME %PRODUCTVERSION%PRODUCTEXTENSION (%1)"));
+ OUString os("$_OS");
+ ::rtl::Bootstrap::expandMacros(os);
+ return sGenerator.replaceFirst("%1", os);
+}
+
static bool getFromTransferrable(
const css::uno::Reference<css::datatransfer::XTransferable> &xTransferable,
const OString &aInMimeType, OString &aRet)
@@ -3442,6 +3452,30 @@ static bool getFromTransferrable(
if (!xTransferable->isDataFlavorSupported(aFlavor))
{
+ // If html is not supported, might be a graphic-selection, which supports png.
+ if (aInMimeType == "text/html" && getFromTransferrable(xTransferable, "image/png", aRet))
+ {
+ // Encode in base64.
+ auto aSeq = Sequence<sal_Int8>(reinterpret_cast<const sal_Int8*>(aRet.getStr()),
+ aRet.getLength());
+ OUStringBuffer aBase64Data;
+ comphelper::Base64::encode(aBase64Data, aSeq);
+
+ // Embed in HTML.
+ static const OString aHeader
+ = "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">"
+ "<html><head>"
+ "<meta http-equiv=\"content-type\" content=\"text/html; charset=utf-8\"/><meta "
+ "name=\"generator\" content=\""
+ + getGenerator().toUtf8()
+ + "\"/>"
+ "</head><body><img src=\"data:image/png;charset=utf-8;base64,";
+
+ aRet = aHeader + aBase64Data.makeStringAndClear().toUtf8() + "\"/></body></html>";
+
+ return true;
+ }
+
SetLastExceptionMsg("Flavor " + aFlavor.MimeType + " is not supported");
return false;
}
@@ -3478,7 +3512,7 @@ static bool getFromTransferrable(
aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
}
- return true;;
+ return true;
}
// Tolerate embedded \0s etc.