diff options
author | merttumer <mert.tumer@collabora.com> | 2019-03-15 20:11:15 +0300 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-07-25 14:35:33 +0200 |
commit | e6bbfd641c6c65ebdebae92f2382689d3ea4a089 (patch) | |
tree | 9f8bc4c3558ae06d8f21c5ba5fe488c87b14b5df | |
parent | d14f10ae64876c394a04fa1ca2b067033a79b0a8 (diff) |
Make pdf export watermarks look like watermarks on online
Change-Id: Ib5af8c61dd9a539c63594a91b8ec17ff07327feb
Signed-off-by: merttumer <mert.tumer@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/69317
Reviewed-by: Jan Holesovsky <kendy@collabora.com>
Tested-by: Jan Holesovsky <kendy@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/76289
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | filter/source/pdf/pdfexport.cxx | 55 |
1 files changed, 42 insertions, 13 deletions
diff --git a/filter/source/pdf/pdfexport.cxx b/filter/source/pdf/pdfexport.cxx index bae05fe1c394..051f73fc66b8 100644 --- a/filter/source/pdf/pdfexport.cxx +++ b/filter/source/pdf/pdfexport.cxx @@ -1159,6 +1159,24 @@ void PDFExport::ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSi void PDFExport::ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize ) { + OUString watermark = msTiledWatermark; + int watermarkLength = watermark.getLength(); + // Maximum number of characters in one line. + // it is set to 21 to make it look like tiled watermaks as online in secure view + const int lineLength = 21; + int lnIndex = lineLength; + int lnCount = watermarkLength / lineLength; + + while(lnCount) + { + OUString tempstr = watermark; + watermark = watermark.copy(0, lnIndex); + watermark += "\n"; + watermark += tempstr.copy(lnIndex); + lnIndex += lineLength; + lnCount--; + } + vcl::Font aFont( "Liberation Sans", Size( 0, 40 ) ); aFont.SetItalic( ITALIC_NONE ); aFont.SetWidthType( WIDTH_NORMAL ); @@ -1172,8 +1190,14 @@ void PDFExport::ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rP pDev->SetFont(aFont); pDev->SetMapMode( MapMode( MapUnit::MapPoint ) ); int w = 0; - long nTextWidth = (rPageSize.Width()-60) / 4; - while((w = pDev->GetTextWidth(msTiledWatermark)) > nTextWidth) + int watermarkcount = ((rPageSize.Width()) / 200)+1; + long nTextWidth = rPageSize.Width() / (watermarkcount*1.5); + OUString oneLineText = watermark; + + if(watermark.getLength() > lineLength) + oneLineText = watermark.copy(0, lineLength); + + while((w = pDev->GetTextWidth(oneLineText)) > nTextWidth) { if(w==0) break; @@ -1182,27 +1206,32 @@ void PDFExport::ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rP aFont.SetFontHeight(nNewHeight); pDev->SetFont( aFont ); } + + // maximum number of watermark count for the width + if(watermarkcount > 8) + watermarkcount = 8; + 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); + // center watermarks horizontally + Point aTextPoint( (rPageSize.Width()/2) - (((nTextWidth*watermarkcount)+(watermarkcount-1)*(nTextWidth/2))/2), + pDev->GetTextHeight()); - for( int i = 0; i < 3; i ++) + for( int i = 0; i < watermarkcount; i ++) { - while(aTextPoint.getY()+pDev->GetTextHeight() <= rPageSize.Height()-40) + while(aTextPoint.getY()+pDev->GetTextHeight()*2 <= rPageSize.Height()) { - aTextRect = tools::Rectangle(Point(aTextPoint.getX(), aTextPoint.getY()-pDev->GetTextHeight()), Size(pDev->GetTextWidth(msTiledWatermark),pDev->GetTextHeight())); + tools::Rectangle aTextRect(aTextPoint, Size(nTextWidth,pDev->GetTextHeight()*2)); pDev->Push(); rWriter.SetClipRegion(); rWriter.BeginTransparencyGroup(); rWriter.SetTextColor( Color(19,20,22) ); - rWriter.DrawText(aTextPoint, msTiledWatermark); + rWriter.DrawText(aTextRect, watermark, DrawTextFlags::MultiLine|DrawTextFlags::Center|DrawTextFlags::VCenter); rWriter.EndTransparencyGroup( aTextRect, 50 ); pDev->Pop(); @@ -1210,14 +1239,14 @@ void PDFExport::ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rP rWriter.SetClipRegion(); rWriter.BeginTransparencyGroup(); rWriter.SetTextColor( Color(236,235,233) ); - rWriter.DrawText(aTextPoint, msTiledWatermark); + rWriter.DrawText(aTextRect, watermark, DrawTextFlags::MultiLine|DrawTextFlags::Center|DrawTextFlags::VCenter); rWriter.EndTransparencyGroup( aTextRect, 50 ); pDev->Pop(); - aTextPoint.Move(0,(rPageSize.Height()-40)/4); + aTextPoint.Move(0, pDev->GetTextHeight()*3); } - aTextPoint=Point( aTextPoint.getX(), 80 ); - aTextPoint.Move( (rPageSize.Width()-120)/3, 0 ); + aTextPoint=Point( aTextPoint.getX(), pDev->GetTextHeight() ); + aTextPoint.Move( nTextWidth*1.5, 0 ); } rWriter.Pop(); |