summaryrefslogtreecommitdiff
path: root/filter
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2019-01-29 23:02:22 +0300
committerMuhammet Kara <muhammet.kara@collabora.com>2019-06-17 21:22:10 +0200
commit40e27c01c502269005395db06bfea39cf9c85ec3 (patch)
tree27e7a698e030d44438fcf2266a0dad18295878a4 /filter
parent3969cd979a4f5cb6b0bc5f9f9d629e77002889d4 (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/74201 Tested-by: Muhammet Kara <muhammet.kara@collabora.com>
Diffstat (limited to 'filter')
-rw-r--r--filter/source/pdf/pdfexport.cxx23
-rw-r--r--filter/source/pdf/pdfexport.hxx2
-rw-r--r--filter/source/pdf/pdffilter.cxx36
3 files changed, 60 insertions, 1 deletions
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 88f212fbb609..8e5b9eefdcc5 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 ),
@@ -226,6 +228,24 @@ 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);
+ }
+ }
+
ImplExportPage(rPDFWriter, rPDFExtOutDevData, aMtf);
bRet = true;
}
@@ -556,6 +576,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 01befed55986..ac9362a01fb2 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;
// these variable are here only to have a location in filter/pdf to set the default
diff --git a/filter/source/pdf/pdffilter.cxx b/filter/source/pdf/pdffilter.cxx
index 5bddb7e1f671..872c515e0543 100644
--- a/filter/source/pdf/pdffilter.cxx
+++ b/filter/source/pdf/pdffilter.cxx
@@ -46,11 +46,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;
@@ -62,6 +63,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() )
@@ -109,9 +116,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 );