summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2018-12-06 12:10:13 +0300
committerAndras Timar <andras.timar@collabora.com>2019-03-27 21:39:00 +0100
commitcbbe3edc5668fa21f8507a6435547dbfe5eef4d0 (patch)
treed83c3b2171c9ba7fbd958533238d912df4968f80 /sfx2
parente90f3cc7a73abf99a27d0f3149f187d7d0a130dc (diff)
Redaction: First steps
- Add an uno command to create an empty draw document - Create a meta file from the first page of a Writer document - Insert meta file to the draw page - Doesn't work with normal/default view on big/high-res screens because of a bug in the MapModes. Manually setting zoom level to %200 or "Page Width" (to get rid of the extra space around the actual page) works for now as workaround. Change-Id: I05a987617efdda6690400ef550b81b58b21aa27e Reviewed-on: https://gerrit.libreoffice.org/64858 Tested-by: Jenkins Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/69728 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r--sfx2/sdi/docslots.sdi5
-rw-r--r--sfx2/sdi/sfx.sdi17
-rw-r--r--sfx2/source/appl/appuno.cxx4
-rw-r--r--sfx2/source/doc/objserv.cxx76
4 files changed, 100 insertions, 2 deletions
diff --git a/sfx2/sdi/docslots.sdi b/sfx2/sdi/docslots.sdi
index 811467cd94be..5b878b8ff051 100644
--- a/sfx2/sdi/docslots.sdi
+++ b/sfx2/sdi/docslots.sdi
@@ -248,6 +248,11 @@ shell SfxObjectShell
ExecMethod = ExecFile_Impl ;
StateMethod = GetState_Impl ;
]
+ SID_REDACTDOC
+ [
+ ExecMethod = ExecFile_Impl ;
+ StateMethod = GetState_Impl ;
+ ]
SID_SIGNATURE
[
ExecMethod = ExecFile_Impl;
diff --git a/sfx2/sdi/sfx.sdi b/sfx2/sdi/sfx.sdi
index 83d26d5797e8..240cb0be10f0 100644
--- a/sfx2/sdi/sfx.sdi
+++ b/sfx2/sdi/sfx.sdi
@@ -4777,6 +4777,23 @@ SfxVoidItem ExportDirectToEPUB SID_DIRECTEXPORTDOCASEPUB
GroupId = SfxGroupId::Document;
]
+SfxVoidItem RedactDoc SID_REDACTDOC
+(SfxStringItem URL SID_FILE_NAME, SfxStringItem FilterName SID_FILTER_NAME)
+[
+ AutoUpdate = FALSE,
+ FastCall = FALSE,
+ ReadOnlyDoc = TRUE,
+ Toggle = FALSE,
+ Container = TRUE,
+ RecordAbsolute = FALSE,
+ RecordPerSet;
+
+ AccelConfig = TRUE,
+ MenuConfig = TRUE,
+ ToolBoxConfig = TRUE,
+ GroupId = SfxGroupId::Document;
+]
+
SfxImageItem ImageOrientation SID_IMAGE_ORIENTATION
[
diff --git a/sfx2/source/appl/appuno.cxx b/sfx2/source/appl/appuno.cxx
index a0bf23d483f6..bed21cc2b91b 100644
--- a/sfx2/source/appl/appuno.cxx
+++ b/sfx2/source/appl/appuno.cxx
@@ -172,7 +172,7 @@ static bool isMediaDescriptor( sal_uInt16 nSlotId )
nSlotId == SID_SAVETO || nSlotId == SID_SAVEACOPY ||
nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF ||
nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB ||
- nSlotId == SID_SAVEACOPYITEM);
+ nSlotId == SID_REDACTDOC || nSlotId == SID_SAVEACOPYITEM);
}
void TransformParameters( sal_uInt16 nSlotId, const uno::Sequence<beans::PropertyValue>& rArgs, SfxAllItemSet& rSet, const SfxSlot* pSlot )
@@ -1335,7 +1335,7 @@ void TransformItems( sal_uInt16 nSlotId, const SfxItemSet& rSet, uno::Sequence<b
if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC || nSlotId == SID_SAVEDOC ||
nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF ||
nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB ||
- nSlotId == SID_SAVEACOPY )
+ nSlotId == SID_REDACTDOC || nSlotId == SID_SAVEACOPY )
{
const SfxPoolItem *pItem=nullptr;
if ( rSet.GetItemState( SID_COMPONENTDATA, false, &pItem ) == SfxItemState::SET )
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index 2f98fc4f7628..689dc36b42e7 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -61,7 +61,11 @@
#include <unotools/useroptions.hxx>
#include <unotools/saveopt.hxx>
#include <svtools/asynclink.hxx>
+#include <svtools/DocumentToGraphicRenderer.hxx>
+#include <vcl/gdimtf.hxx>
+#include <comphelper/fileformat.h>
#include <comphelper/documentconstants.hxx>
+#include <comphelper/propertyvalue.hxx>
#include <comphelper/storagehelper.hxx>
#include <tools/link.hxx>
@@ -97,6 +101,11 @@
#include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/document/XDocumentProperties.hpp>
+#include <com/sun/star/text/XPageCursor.hpp>
+#include <com/sun/star/text/XTextViewCursorSupplier.hpp>
+
+#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
+#include <com/sun/star/drawing/XDrawPageSupplier.hpp>
#include <helpids.h>
@@ -107,6 +116,8 @@
#include <unotools/ucbstreamhelper.hxx>
#include <unotools/streamwrap.hxx>
+#include <svx/unoshape.hxx>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno;
@@ -515,6 +526,70 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
return;
}
+ case SID_REDACTDOC:
+ {
+ css::uno::Reference<css::frame::XModel> xModel = GetModel();
+ if(!xModel.is())
+ return;
+
+ uno::Reference<text::XTextViewCursorSupplier> xTextViewCursorSupplier(
+ xModel->getCurrentController(), uno::UNO_QUERY);
+ if(!xTextViewCursorSupplier.is())
+ return;
+
+ uno::Reference<text::XPageCursor> xCursor(xTextViewCursorSupplier->getViewCursor(),
+ uno::UNO_QUERY);
+ if(!xCursor.is())
+ return;
+
+ uno::Reference< lang::XComponent > xSourceDoc( xModel );
+ DocumentToGraphicRenderer aRenderer(xSourceDoc, /*bSelectionOnly=*/false);
+
+ // Only take the first page for now
+ sal_Int16 nPage = 1;
+
+ ::Size aDocumentSizePixel = aRenderer.getDocumentSizeInPixels(nPage);
+ ::Size aLogic = aRenderer.getDocumentSizeIn100mm(nPage);
+ // FIXME: This is a temporary hack. Need to figure out a proper way to derive this scale factor.
+ ::Size aTargetSize(aDocumentSizePixel.Width() * 1.23, aDocumentSizePixel.Height() * 1.23);
+
+ Graphic aGraphic = aRenderer.renderToGraphic(nPage, aDocumentSizePixel, aTargetSize, COL_TRANSPARENT);
+ auto& rGDIMetaFile = const_cast<GDIMetaFile&>(aGraphic.GetGDIMetaFile());
+
+ // Set preferred map unit and size on the metafile, so the Shape size
+ // will be correct in MM.
+ MapMode aMapMode;
+ aMapMode.SetMapUnit(MapUnit::Map100thMM);
+ rGDIMetaFile.SetPrefMapMode(aMapMode);
+ rGDIMetaFile.SetPrefSize(aLogic);
+
+ // Create an empty Draw component.
+ uno::Reference<frame::XDesktop2> xDesktop = css::frame::Desktop::create(comphelper::getProcessComponentContext());
+ uno::Reference<frame::XComponentLoader> xComponentLoader(xDesktop, uno::UNO_QUERY);
+ uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL("private:factory/sdraw", "_default", 0, {});
+
+ // Access the draw pages
+ uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XDrawPages> xDrawPages = xDrawPagesSupplier->getDrawPages();
+ uno::Reference< drawing::XDrawPage > xPage( xDrawPages->getByIndex( 0 ), uno::UNO_QUERY_THROW );
+
+ uno::Reference<graphic::XGraphic> xGraph = aGraphic.GetXGraphic();
+
+ // Create and insert the shape
+ uno::Reference<css::lang::XMultiServiceFactory> xFactory(xComponent, uno::UNO_QUERY);
+ uno::Reference<drawing::XShape> xShape(
+ xFactory->createInstance("com.sun.star.drawing.GraphicObjectShape"), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xShapeProperySet(xShape, uno::UNO_QUERY);
+ xShapeProperySet->setPropertyValue("Graphic", uno::Any( xGraph ));
+
+ // Set size and position
+ xShape->setSize(awt::Size(rGDIMetaFile.GetPrefSize().Width(),rGDIMetaFile.GetPrefSize().Height()) );
+
+ xPage->add(xShape);
+
+ return;
+ }
+
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
case SID_EXPORTDOCASPDF:
case SID_DIRECTEXPORTDOCASPDF:
@@ -995,6 +1070,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
case SID_DIRECTEXPORTDOCASPDF:
case SID_EXPORTDOCASEPUB:
case SID_DIRECTEXPORTDOCASEPUB:
+ case SID_REDACTDOC:
{
break;
}