summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorBalazs Varga <balazs.varga.extern@allotropia.de>2023-01-16 11:10:00 +0100
committerThorsten Behrens <thorsten.behrens@allotropia.de>2023-11-19 18:18:12 +0100
commita09b1b9e68c2285289fbf36c7f5fb6a1677e8c39 (patch)
treedfa8b0ee9fff312d2720365debb2f391604cfd7b /sfx2
parent346e9d3c363046a645e55d736f372d2127b9d52c (diff)
WASM: headless conversion without QT5 and with unique html
Building and using soffice.html generated by emscripten and modified for headless conversion. Change-Id: Ic3800bc0632d241dce382f244f355f56f79ffec4
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/source/doc/objstor.cxx65
-rw-r--r--sfx2/source/doc/objxtor.cxx2
2 files changed, 66 insertions, 1 deletions
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index b39b5d14ee38..3a722f026678 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -3006,6 +3006,37 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
if( bOk )
{
+#ifdef EMSCRIPTEN
+ if (aFilterName.endsWith("pdf_Export"))
+ {
+ try
+ {
+ sal_Int32 nRead;
+ Reference<io::XInputStream> aTempInput = pNewFile->GetInputStream();
+ sal_Int32 nBufferSize = 32767;
+ Sequence<sal_Int8> aSequence(nBufferSize);
+ emscripten::val contentArray = emscripten::val::array();
+ do
+ {
+ nRead = aTempInput->readBytes(aSequence, nBufferSize);
+ if (nRead < nBufferSize)
+ {
+ Sequence<sal_Int8> aTempBuf(aSequence.getConstArray(), nRead);
+ ReadWASMFile(contentArray, nRead, aTempBuf);
+ }
+ else
+ {
+ ReadWASMFile(contentArray, nRead, aSequence);
+ }
+ } while (nRead == nBufferSize);
+ WriteWASMFile(contentArray, pNewFile->GetName());
+ }
+ catch (const Exception&)
+ {
+ }
+ }
+#endif
+
if( !bCopyTo )
SetModified( false );
}
@@ -3051,6 +3082,40 @@ bool SfxObjectShell::PreDoSaveAs_Impl(const OUString& rFileName, const OUString&
}
+#ifdef EMSCRIPTEN
+void SfxObjectShell::ReadWASMFile(emscripten::val& contentArray, sal_Int32 nRead, css::uno::Sequence<sal_Int8>& aContent)
+{
+ emscripten::val fileContentView = emscripten::val(emscripten::typed_memory_view(
+ nRead,
+ reinterpret_cast<const char*>(aContent.getConstArray())));
+ emscripten::val fileContentCopy = emscripten::val::global("ArrayBuffer").new_(nRead);
+ emscripten::val fileContentCopyView = emscripten::val::global("Uint8Array").new_(fileContentCopy);
+ fileContentCopyView.call<void>("set", fileContentView);
+ contentArray.call<void>("push", fileContentCopyView);
+}
+void SfxObjectShell::WriteWASMFile(emscripten::val& contentArray, const OUString& rFileName)
+{
+ INetURLObject aURL(rFileName);
+ OUString aNewname = aURL.GetLastName(INetURLObject::DecodeMechanism::WithCharset);
+ emscripten::val document = emscripten::val::global("document");
+ emscripten::val window = emscripten::val::global("window");
+ emscripten::val type = emscripten::val::object();
+ type.set("type","application/octet-stream");
+ emscripten::val contentBlob = emscripten::val::global("Blob").new_(contentArray, type);
+ emscripten::val contentUrl = window["URL"].call<emscripten::val>("createObjectURL", contentBlob);
+ emscripten::val contentLink = document.call<emscripten::val>("createElement", std::string("a"));
+ contentLink.set("href", contentUrl);
+ contentLink.set("download", aNewname.toUtf8().getStr());
+ contentLink.set("style", "display:none");
+ emscripten::val body = document["body"];
+ body.call<void>("appendChild", contentLink);
+ contentLink.call<void>("click");
+ body.call<void>("removeChild", contentLink);
+ window["URL"].call<emscripten::val>("revokeObjectURL", contentUrl);
+}
+#endif
+
+
bool SfxObjectShell::LoadFrom( SfxMedium& /*rMedium*/ )
{
SAL_WARN( "sfx.doc", "Base implementation, must not be called in general!" );
diff --git a/sfx2/source/doc/objxtor.cxx b/sfx2/source/doc/objxtor.cxx
index 2fd5df242fcc..5ee43348d0b2 100644
--- a/sfx2/source/doc/objxtor.cxx
+++ b/sfx2/source/doc/objxtor.cxx
@@ -877,6 +877,7 @@ void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComp
if ( _rxComponent == xOldCurrentComp )
// nothing to do
return;
+ rTheCurrentComponent = _rxComponent;
// note that "_rxComponent.get() == s_xCurrentComponent.get().get()" is /sufficient/, but not
// /required/ for "_rxComponent == s_xCurrentComponent.get()".
// In other words, it's still possible that we here do something which is not necessary,
@@ -884,7 +885,6 @@ void SfxObjectShell::SetCurrentComponent( const Reference< XInterface >& _rxComp
#if HAVE_FEATURE_SCRIPTING
BasicManager* pAppMgr = SfxApplication::GetBasicManager();
- rTheCurrentComponent = _rxComponent;
if ( !pAppMgr )
return;