summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Meeks <michael.meeks@collabora.com>2019-07-20 11:07:01 +0100
committerMichael Meeks <michael.meeks@collabora.com>2019-07-20 11:07:01 +0100
commit5fc8f0d923ee85c6b9e1998bf769b96678f2e905 (patch)
tree3d03aea7f4e16655a6a349dd007f4b2b96d4ed2c
parent0a3b5b30c8bdc8c3e159edd1552713d55948dedc (diff)
LOK: Copy Graphics as embedded PNG in HTML
Change-Id: Id8c14d7304d30bfcd956b126dfe291ef044f62bf
-rw-r--r--desktop/source/lib/init.cxx36
-rw-r--r--vcl/source/treelist/transfer.cxx3
2 files changed, 37 insertions, 2 deletions
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 167b05bebf60..4c8f37804810 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>
@@ -3313,6 +3314,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)
@@ -3340,6 +3350,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;
}
@@ -3376,7 +3410,7 @@ static bool getFromTransferrable(
aRet = OString(reinterpret_cast<sal_Char*>(aSequence.getArray()), aSequence.getLength());
}
- return true;;
+ return true;
}
// Tolerate embedded \0s etc.
diff --git a/vcl/source/treelist/transfer.cxx b/vcl/source/treelist/transfer.cxx
index c5f61cb850c4..10782592f5a2 100644
--- a/vcl/source/treelist/transfer.cxx
+++ b/vcl/source/treelist/transfer.cxx
@@ -390,7 +390,8 @@ Any SAL_CALL TransferableHelper::getTransferData2( const DataFlavor& rFlavor, co
sal_Bool SAL_CALL TransferableHelper::isComplex()
{
- //FIXME: get from each document.
+ // By default everything is complex, until proven otherwise
+ // in the respective document type transferable handler.
return sal_True;
}