[Libreoffice-commits] core.git: desktop/source filter/source
Libreoffice Gerrit user
logerrit at kemper.freedesktop.org
Mon Mar 18 12:03:50 UTC 2019
desktop/source/lib/init.cxx | 26 ++++++++++++++
filter/source/pdf/pdfexport.cxx | 74 ++++++++++++++++++++++++++++++++++++++++
filter/source/pdf/pdfexport.hxx | 3 +
3 files changed, 103 insertions(+)
New commits:
commit dd3d5f7c15ab701c57d29f5c60e1164a0834ca00
Author: merttumer <mert.tumer at collabora.com>
AuthorDate: Wed Feb 13 17:59:30 2019 +0300
Commit: Mert Tümer <mert.tumer at collabora.com>
CommitDate: Mon Mar 18 13:03:28 2019 +0100
Added tiled watermark export option for pdf
Change-Id: I3f28ad64c13dd4bc1b2862e86d2190e46a0ced46
Signed-off-by: merttumer <mert.tumer at collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/67779
Tested-by: Jenkins
diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 4662fb616c6e..bc5c9b74beba 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1905,6 +1905,25 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
OUString aFilterOptions = getUString(pFilterOptions);
+ // Check if watermark for pdf is passed by filteroptions..
+ // It is not a real filter option so it must be filtered out.
+ OUString watermarkText;
+ int aIndex = -1;
+ if ((aIndex = aFilterOptions.indexOf(",Watermark=")) >= 0)
+ {
+ int bIndex = aFilterOptions.indexOf("WATERMARKEND");
+ watermarkText = aFilterOptions.copy(aIndex+11, bIndex-(aIndex+11));
+ if(aIndex > 0)
+ {
+ OUString temp = aFilterOptions.copy(0, aIndex);
+ aFilterOptions = temp + aFilterOptions.copy(bIndex+12);
+ }
+ else
+ {
+ aFilterOptions.clear();
+ }
+ }
+
// 'TakeOwnership' == this is a 'real' SaveAs (that is, the document
// gets a new name). When this is not provided, the meaning of
// saveAs() is more like save-a-copy, which allows saving to any
@@ -1930,6 +1949,13 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
auto aFilteredOptionSeq = comphelper::containerToSequence<OUString>(aFilteredOptionVec);
aFilterOptions = comphelper::string::convertCommaSeparated(aFilteredOptionSeq);
aSaveMediaDescriptor[MediaDescriptor::PROP_FILTEROPTIONS()] <<= aFilterOptions;
+ if(!watermarkText.isEmpty())
+ {
+ uno::Sequence< beans::PropertyValue > aFilterData( 1 );
+ aFilterData[ 0 ].Name = "TiledWatermark";
+ aFilterData[ 0 ].Value <<= watermarkText;
+ aSaveMediaDescriptor["FilterData"] <<= aFilterData;
+ }
// add interaction handler too
if (gImpl)
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx
index 2ca3829db36a..42ec1e8f23c6 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -525,6 +525,8 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >&
rFilterData[ nData ].Value >>= mbAddStream;
else if ( rFilterData[ nData ].Name == "Watermark" )
rFilterData[ nData ].Value >>= msWatermark;
+ else if ( rFilterData[ nData ].Name == "TiledWatermark" )
+ rFilterData[ nData ].Value >>= msTiledWatermark;
// now all the security related properties...
else if ( rFilterData[ nData ].Name == "EncryptFile" )
rFilterData[ nData ].Value >>= mbEncrypt;
@@ -1077,7 +1079,13 @@ void PDFExport::ImplExportPage( vcl::PDFWriter& rWriter, vcl::PDFExtOutDevData&
rPDFExtOutDevData.ResetSyncData();
if (!msWatermark.isEmpty())
+ {
ImplWriteWatermark( rWriter, Size(aRangePDF.getWidth(), aRangePDF.getHeight()) );
+ }
+ else if (!msTiledWatermark.isEmpty())
+ {
+ ImplWriteTiledWatermark( rWriter, Size(aRangePDF.getWidth(), aRangePDF.getHeight()) );
+ }
}
@@ -1148,4 +1156,70 @@ void PDFExport::ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSi
rWriter.Pop();
}
+void PDFExport::ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize )
+{
+ vcl::Font aFont( OUString( "Liberation Sans" ), Size( 0, 40 ) );
+ aFont.SetItalic( ITALIC_NONE );
+ aFont.SetWidthType( WIDTH_NORMAL );
+ aFont.SetWeight( WEIGHT_NORMAL );
+ aFont.SetAlignment( ALIGN_BOTTOM );
+ aFont.SetFontHeight(40);
+
+ OutputDevice* pDev = rWriter.GetReferenceDevice();
+ pDev->SetFont(aFont);
+ pDev->Push();
+ pDev->SetFont(aFont);
+ pDev->SetMapMode( MapMode( MapUnit::MapPoint ) );
+ int w = 0;
+ long nTextWidth = (rPageSize.Width()-60) / 4;
+ while((w = pDev->GetTextWidth(msTiledWatermark)) > nTextWidth)
+ {
+ if(w==0)
+ break;
+
+ long nNewHeight = aFont.GetFontHeight() * nTextWidth / w;
+ aFont.SetFontHeight(nNewHeight);
+ pDev->SetFont( aFont );
+ }
+ pDev->Pop();
+
+ rWriter.Push();
+ rWriter.SetMapMode( MapMode( MapUnit::MapPoint ) );
+ rWriter.SetFont(aFont);
+ rWriter.SetTextColor( Color(19,20,22) );
+ Point aTextPoint;
+ tools::Rectangle aTextRect;
+ aTextPoint = Point(70,80);
+
+ for( int i = 0; i < 3; i ++)
+ {
+ while(aTextPoint.getY()+pDev->GetTextHeight() <= rPageSize.Height()-40)
+ {
+ aTextRect = tools::Rectangle(Point(aTextPoint.getX(), aTextPoint.getY()-pDev->GetTextHeight()), Size(pDev->GetTextWidth(msTiledWatermark),pDev->GetTextHeight()));
+
+ pDev->Push();
+ rWriter.SetClipRegion();
+ rWriter.BeginTransparencyGroup();
+ rWriter.SetTextColor( Color(19,20,22) );
+ rWriter.DrawText(aTextPoint, msTiledWatermark);
+ rWriter.EndTransparencyGroup( aTextRect, 50 );
+ pDev->Pop();
+
+ pDev->Push();
+ rWriter.SetClipRegion();
+ rWriter.BeginTransparencyGroup();
+ rWriter.SetTextColor( Color(236,235,233) );
+ rWriter.DrawText(aTextPoint, msTiledWatermark);
+ rWriter.EndTransparencyGroup( aTextRect, 50 );
+ pDev->Pop();
+
+ aTextPoint.Move(0,(rPageSize.Height()-40)/4);
+ }
+ aTextPoint=Point( aTextPoint.getX(), 80 );
+ aTextPoint.Move( (rPageSize.Width()-120)/3, 0 );
+ }
+
+ rWriter.Pop();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/filter/source/pdf/pdfexport.hxx b/filter/source/pdf/pdfexport.hxx
index ac9362a01fb2..6d2d1ffd63e7 100644
--- a/filter/source/pdf/pdfexport.hxx
+++ b/filter/source/pdf/pdfexport.hxx
@@ -68,6 +68,7 @@ private:
bool mbIsRedactMode;
OUString msWatermark;
+ OUString msTiledWatermark;
// these variable are here only to have a location in filter/pdf to set the default
// to be used by the macro (when the FilterData are set by the macro itself)
@@ -108,6 +109,8 @@ private:
OUString msSignTSA;
void ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize );
+ void ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize );
+
public:
More information about the Libreoffice-commits
mailing list