Kaydet (Commit) cbbe3edc authored tarafından Muhammet Kara's avatar Muhammet Kara Kaydeden (comit) Andras Timar

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: 's avatarMuhammet Kara <muhammet.kara@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/69728Reviewed-by: 's avatarAndras Timar <andras.timar@collabora.com>
Tested-by: 's avatarAndras Timar <andras.timar@collabora.com>
üst e90f3cc7
...@@ -127,6 +127,7 @@ ...@@ -127,6 +127,7 @@
#define SID_DIRECTEXPORTDOCASPDF (SID_SFX_START + 1674) #define SID_DIRECTEXPORTDOCASPDF (SID_SFX_START + 1674)
#define SID_EXPORTDOCASEPUB (SID_SFX_START + 1677) #define SID_EXPORTDOCASEPUB (SID_SFX_START + 1677)
#define SID_DIRECTEXPORTDOCASEPUB (SID_SFX_START + 1678) #define SID_DIRECTEXPORTDOCASEPUB (SID_SFX_START + 1678)
#define SID_REDACTDOC (SID_SFX_START + 1730)
#define SID_UPDATEDOCMODE (SID_SFX_START + 1668) #define SID_UPDATEDOCMODE (SID_SFX_START + 1668)
#define SID_CHECKOUT (SID_SFX_START + 512) #define SID_CHECKOUT (SID_SFX_START + 512)
#define SID_CANCELCHECKOUT (SID_SFX_START + 513) #define SID_CANCELCHECKOUT (SID_SFX_START + 513)
...@@ -245,7 +246,7 @@ ...@@ -245,7 +246,7 @@
#define SID_TOOLBAR_MODE (SID_SFX_START + 1728) #define SID_TOOLBAR_MODE (SID_SFX_START + 1728)
#define SID_NO_FILE_SYNC (SID_SFX_START + 1729) #define SID_NO_FILE_SYNC (SID_SFX_START + 1729)
// SID_SFX_free_START (SID_SFX_START + 1730) // SID_SFX_free_START (SID_SFX_START + 1731)
// SID_SFX_free_END (SID_SFX_START + 3999) // SID_SFX_free_END (SID_SFX_START + 3999)
#define SID_OPEN_NEW_VIEW (SID_SFX_START + 520) #define SID_OPEN_NEW_VIEW (SID_SFX_START + 520)
......
...@@ -4914,6 +4914,20 @@ ...@@ -4914,6 +4914,20 @@
<value>1</value> <value>1</value>
</prop> </prop>
</node> </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"> <node oor:name=".uno:ConfigureDialog" oor:op="replace">
<prop oor:name="Label" oor:type="xs:string"> <prop oor:name="Label" oor:type="xs:string">
<value xml:lang="en-US">~Customize...</value> <value xml:lang="en-US">~Customize...</value>
......
...@@ -248,6 +248,11 @@ shell SfxObjectShell ...@@ -248,6 +248,11 @@ shell SfxObjectShell
ExecMethod = ExecFile_Impl ; ExecMethod = ExecFile_Impl ;
StateMethod = GetState_Impl ; StateMethod = GetState_Impl ;
] ]
SID_REDACTDOC
[
ExecMethod = ExecFile_Impl ;
StateMethod = GetState_Impl ;
]
SID_SIGNATURE SID_SIGNATURE
[ [
ExecMethod = ExecFile_Impl; ExecMethod = ExecFile_Impl;
......
...@@ -4777,6 +4777,23 @@ SfxVoidItem ExportDirectToEPUB SID_DIRECTEXPORTDOCASEPUB ...@@ -4777,6 +4777,23 @@ SfxVoidItem ExportDirectToEPUB SID_DIRECTEXPORTDOCASEPUB
GroupId = SfxGroupId::Document; 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 SfxImageItem ImageOrientation SID_IMAGE_ORIENTATION
[ [
......
...@@ -172,7 +172,7 @@ static bool isMediaDescriptor( sal_uInt16 nSlotId ) ...@@ -172,7 +172,7 @@ static bool isMediaDescriptor( sal_uInt16 nSlotId )
nSlotId == SID_SAVETO || nSlotId == SID_SAVEACOPY || nSlotId == SID_SAVETO || nSlotId == SID_SAVEACOPY ||
nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF ||
nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB || 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 ) 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 ...@@ -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 || if ( nSlotId == SID_OPENDOC || nSlotId == SID_EXPORTDOC || nSlotId == SID_SAVEASDOC || nSlotId == SID_SAVEDOC ||
nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF || nSlotId == SID_SAVETO || nSlotId == SID_EXPORTDOCASPDF || nSlotId == SID_DIRECTEXPORTDOCASPDF ||
nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB || nSlotId == SID_EXPORTDOCASEPUB || nSlotId == SID_DIRECTEXPORTDOCASEPUB ||
nSlotId == SID_SAVEACOPY ) nSlotId == SID_REDACTDOC || nSlotId == SID_SAVEACOPY )
{ {
const SfxPoolItem *pItem=nullptr; const SfxPoolItem *pItem=nullptr;
if ( rSet.GetItemState( SID_COMPONENTDATA, false, &pItem ) == SfxItemState::SET ) if ( rSet.GetItemState( SID_COMPONENTDATA, false, &pItem ) == SfxItemState::SET )
......
...@@ -61,7 +61,11 @@ ...@@ -61,7 +61,11 @@
#include <unotools/useroptions.hxx> #include <unotools/useroptions.hxx>
#include <unotools/saveopt.hxx> #include <unotools/saveopt.hxx>
#include <svtools/asynclink.hxx> #include <svtools/asynclink.hxx>
#include <svtools/DocumentToGraphicRenderer.hxx>
#include <vcl/gdimtf.hxx>
#include <comphelper/fileformat.h>
#include <comphelper/documentconstants.hxx> #include <comphelper/documentconstants.hxx>
#include <comphelper/propertyvalue.hxx>
#include <comphelper/storagehelper.hxx> #include <comphelper/storagehelper.hxx>
#include <tools/link.hxx> #include <tools/link.hxx>
...@@ -97,6 +101,11 @@ ...@@ -97,6 +101,11 @@
#include <com/sun/star/embed/XTransactedObject.hpp> #include <com/sun/star/embed/XTransactedObject.hpp>
#include <com/sun/star/util/XCloneable.hpp> #include <com/sun/star/util/XCloneable.hpp>
#include <com/sun/star/document/XDocumentProperties.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> #include <helpids.h>
...@@ -107,6 +116,8 @@ ...@@ -107,6 +116,8 @@
#include <unotools/ucbstreamhelper.hxx> #include <unotools/ucbstreamhelper.hxx>
#include <unotools/streamwrap.hxx> #include <unotools/streamwrap.hxx>
#include <svx/unoshape.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
using namespace ::com::sun::star::lang; using namespace ::com::sun::star::lang;
using namespace ::com::sun::star::uno; using namespace ::com::sun::star::uno;
...@@ -515,6 +526,70 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq) ...@@ -515,6 +526,70 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
return; 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_EXPORTDOCASPDF:
case SID_DIRECTEXPORTDOCASPDF: case SID_DIRECTEXPORTDOCASPDF:
...@@ -995,6 +1070,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet) ...@@ -995,6 +1070,7 @@ void SfxObjectShell::GetState_Impl(SfxItemSet &rSet)
case SID_DIRECTEXPORTDOCASPDF: case SID_DIRECTEXPORTDOCASPDF:
case SID_EXPORTDOCASEPUB: case SID_EXPORTDOCASEPUB:
case SID_DIRECTEXPORTDOCASEPUB: case SID_DIRECTEXPORTDOCASEPUB:
case SID_REDACTDOC:
{ {
break; break;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment