diff options
author | Muhammet Kara <muhammet.kara@collabora.com> | 2018-12-06 12:10:13 +0300 |
---|---|---|
committer | Muhammet Kara <muhammet.kara@collabora.com> | 2019-01-03 21:05:28 +0100 |
commit | 1f6506ca9d34ab2576e7659986ed2c3d3bf81d90 (patch) | |
tree | 44dd2aa62cbfcd2b878396dcf59748207b7833ff | |
parent | 0ea4c1ae099e53e20babc3eaae0c1c377cc3ded5 (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>
-rw-r--r-- | include/sfx2/sfxsids.hrc | 3 | ||||
-rw-r--r-- | officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu | 14 | ||||
-rw-r--r-- | sfx2/sdi/docslots.sdi | 5 | ||||
-rw-r--r-- | sfx2/sdi/sfx.sdi | 17 | ||||
-rw-r--r-- | sfx2/source/appl/appuno.cxx | 4 | ||||
-rw-r--r-- | sfx2/source/doc/objserv.cxx | 76 |
6 files changed, 116 insertions, 3 deletions
diff --git a/include/sfx2/sfxsids.hrc b/include/sfx2/sfxsids.hrc index 80d262e20625..badaedad4d26 100644 --- a/include/sfx2/sfxsids.hrc +++ b/include/sfx2/sfxsids.hrc @@ -134,6 +134,7 @@ class SfxDocumentInfoItem; #define SID_DIRECTEXPORTDOCASPDF (SID_SFX_START + 1674) #define SID_EXPORTDOCASEPUB (SID_SFX_START + 1677) #define SID_DIRECTEXPORTDOCASEPUB (SID_SFX_START + 1678) +#define SID_REDACTDOC (SID_SFX_START + 1732) #define SID_UPDATEDOCMODE (SID_SFX_START + 1668) #define SID_CHECKOUT (SID_SFX_START + 512) #define SID_CANCELCHECKOUT (SID_SFX_START + 513) @@ -256,7 +257,7 @@ class SfxDocumentInfoItem; // not required for preview, but interferes with not-yet-saved embedded data source for main document. #define SID_NO_EMBEDDED_DS TypedWhichId<SfxBoolItem>(SID_SFX_START + 1731) -// SID_SFX_free_START (SID_SFX_START + 1732) +// SID_SFX_free_START (SID_SFX_START + 1733) // SID_SFX_free_END (SID_SFX_START + 3999) #define SID_OPEN_NEW_VIEW (SID_SFX_START + 520) diff --git a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu index f880d3717521..9df09104437e 100644 --- a/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu +++ b/officecfg/registry/data/org/openoffice/Office/UI/GenericCommands.xcu @@ -4997,6 +4997,20 @@ <value>1</value> </prop> </node> + <node oor:name=".uno:RedactDoc" oor:op="replace"> + <prop oor:name="Label" oor:type="xs:string"> + <value xml:lang="en-US">Redact</value> + </prop> + <prop oor:name="ContextLabel" oor:type="xs:string"> + <value xml:lang="en-US">Redact</value> + </prop> + <prop oor:name="TooltipLabel" oor:type="xs:string"> + <value xml:lang="en-US">Redact Document</value> + </prop> + <prop oor:name="Properties" oor:type="xs:int"> + <value>1</value> + </prop> + </node> <node oor:name=".uno:ConfigureDialog" oor:op="replace"> <prop oor:name="Label" oor:type="xs:string"> <value xml:lang="en-US">~Customize...</value> 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 11225f17868e..f8fbcd49d3b5 100644 --- a/sfx2/sdi/sfx.sdi +++ b/sfx2/sdi/sfx.sdi @@ -4814,6 +4814,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 2ce0f060184a..57bc154ad891 100644 --- a/sfx2/source/appl/appuno.cxx +++ b/sfx2/source/appl/appuno.cxx @@ -175,7 +175,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 ) @@ -1338,7 +1338,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 2c2617e9a111..b4d06c000a0e 100644 --- a/sfx2/source/doc/objserv.cxx +++ b/sfx2/source/doc/objserv.cxx @@ -62,8 +62,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> @@ -99,6 +102,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 <guisaveas.hxx> #include <saveastemplatedlg.hxx> @@ -107,6 +115,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; @@ -520,6 +530,71 @@ 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, + /*bExtOutDevData=*/true); + 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: @@ -1002,6 +1077,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) case SID_DIRECTEXPORTDOCASPDF: case SID_EXPORTDOCASEPUB: case SID_DIRECTEXPORTDOCASEPUB: + case SID_REDACTDOC: { break; } |