summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2019-01-29 23:02:22 +0300
committerAndras Timar <andras.timar@collabora.com>2019-03-27 21:42:48 +0100
commite4f9c34a1b21674289d42bea1e4a3b94879bc731 (patch)
treed071ba3222d4e5f5ba5bf8d4f9e588a1e34d8251 /filter
parent54087433e7495a7fa74661e5bfebac95b5648598 (diff)
Support bitmap PDF export for Redaction
* Add a new parameter IsRedactMode (SID_IS_REDACT_MODE) to .uno:ExportDirectToPDF * Make sure the new param makes it into PDFExport as part of FilterData * Hijack the metafile before being sent to ImplExportPage(), convert to bitmap, and replace the original * Add a new entry to GenericCommands.xcu to make our button with param visible * Nitpick: For things to be included in the bitmap conversion, they need to be added to the metafile before the conversion in PDFExport::ExportSelection(). Things added after that point (inside ImplExportPage() for example) will not be bitmapped/pixelized Change-Id: Iec7020917da920a968ea969b98e53f17eadaa275 Reviewed-on: https://gerrit.libreoffice.org/67108 Tested-by: Jenkins Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/69833 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/pdf/pdfexport.cxx25
-rw-r--r--filter/source/pdf/pdfexport.hxx2
-rw-r--r--filter/source/pdf/pdffilter.cxx36
3 files changed, 62 insertions, 1 deletions
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 31adb9788e1d..9013c63e2973 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -114,6 +114,8 @@ PDFExport::PDFExport( const Reference< XComponent >& rxSrcDoc,
mnProgressValue ( 0 ),
mbRemoveTransparencies ( false ),
+ mbIsRedactMode ( false ),
+
mbHideViewerToolbar ( false ),
mbHideViewerMenubar ( false ),
mbHideViewerWindowControls ( false ),
@@ -225,7 +227,27 @@ bool PDFExport::ExportSelection( vcl::PDFWriter& rPDFWriter,
if( aMtf.GetActionSize() &&
( !mbSkipEmptyPages || aPageSize.Width || aPageSize.Height ) )
+ {
+ // We convert the whole metafile into a bitmap to get rid of the
+ // text covered by redaction shapes
+ if (mbIsRedactMode)
+ {
+ try
+ {
+ Graphic aGraph(aMtf);
+ BitmapEx bmp = aGraph.GetBitmapEx();
+ Graphic bgraph(bmp);
+ aMtf = bgraph.GetGDIMetaFile();
+ }
+ catch(const Exception& e)
+ {
+ SAL_WARN("filter.pdf", "Something went wrong while converting metafile to bitmap. Exception: "
+ << e.Message);
+ }
+ }
+
bRet = ImplExportPage(rPDFWriter, rPDFExtOutDevData, aMtf) || bRet;
+ }
pOut->Pop();
@@ -555,6 +577,9 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >&
rFilterData[ nData ].Value >>= mbExportPlaceholders;
else if ( rFilterData[ nData ].Name == "UseReferenceXObject" )
rFilterData[ nData ].Value >>= mbUseReferenceXObject;
+ // Redaction & bitmap related stuff
+ else if ( rFilterData[ nData ].Name == "IsRedactMode" )
+ rFilterData[ nData ].Value >>= mbIsRedactMode;
}
aContext.URL = aURL.GetMainURL(INetURLObject::DecodeMechanism::ToIUri);
diff --git a/filter/source/pdf/pdfexport.hxx b/filter/source/pdf/pdfexport.hxx
index 9d302900cdee..da7ca044ea60 100644
--- a/filter/source/pdf/pdfexport.hxx
+++ b/filter/source/pdf/pdfexport.hxx
@@ -65,6 +65,8 @@ private:
sal_Int32 mnProgressValue;
bool mbRemoveTransparencies;
+ bool mbIsRedactMode;
+
OUString msWatermark;
OUString msTiledWatermark;
diff --git a/filter/source/pdf/pdffilter.cxx b/filter/source/pdf/pdffilter.cxx
index 2a32408bb0c3..71b874dbb4e6 100644
--- a/filter/source/pdf/pdffilter.cxx
+++ b/filter/source/pdf/pdffilter.cxx
@@ -44,11 +44,12 @@ bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
Sequence< PropertyValue > aFilterData;
sal_Int32 nLength = rDescriptor.getLength();
const PropertyValue* pValue = rDescriptor.getConstArray();
+ bool bIsRedactMode = false;
bool bRet = false;
Reference< task::XStatusIndicator > xStatusIndicator;
Reference< task::XInteractionHandler > xIH;
- for ( sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
+ for (sal_Int32 i = 0 ; ( i < nLength ) && !xOStm.is(); ++i)
{
if ( pValue[ i ].Name == "OutputStream" )
pValue[ i ].Value >>= xOStm;
@@ -60,6 +61,12 @@ bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
pValue[i].Value >>= xIH;
}
+ for (sal_Int32 i = 0 ; i < nLength; ++i)
+ {
+ if ( pValue[i].Name == "IsRedactMode")
+ pValue[i].Value >>= bIsRedactMode;
+ }
+
/* we don't get FilterData if we are exporting directly
to pdf, but we have to use the last user settings (especially for the CompressMode) */
if ( !aFilterData.getLength() )
@@ -104,9 +111,36 @@ bool PDFFilter::implExport( const Sequence< PropertyValue >& rDescriptor )
aCfgItem.ReadBool( "ExportBookmarks", true );
aCfgItem.ReadBool( "ExportHiddenSlides", false );
aCfgItem.ReadInt32( "OpenBookmarkLevels", -1 );
+
+ aCfgItem.ReadBool( "IsRedactMode", false);
+
aFilterData = aCfgItem.GetFilterData();
}
+
+ if (bIsRedactMode)
+ {
+ bool bFound = false;
+
+ for (int i = 0; i < aFilterData.getLength(); ++i)
+ {
+ if (aFilterData[i].Name == "IsRedactMode")
+ {
+ aFilterData[i].Value <<= bIsRedactMode;
+ bFound = true;
+ break;
+ }
+ }
+
+ if (!bFound)
+ {
+ sal_Int32 nNewSize = aFilterData.getLength() + 1;
+ aFilterData.realloc( nNewSize );
+ aFilterData[nNewSize - 1].Name = "IsRedactMode";
+ aFilterData[nNewSize - 1].Value <<= bIsRedactMode;
+ }
+ }
+
if( mxSrcDoc.is() && xOStm.is() )
{
PDFExport aExport( mxSrcDoc, xStatusIndicator, xIH, mxContext );