[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - desktop/source filter/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Feb 8 21:27:47 UTC 2019


 desktop/source/lib/init.cxx     |   26 ++++++++++++++
 filter/source/pdf/pdfexport.cxx |   74 ++++++++++++++++++++++++++++++++++++++++
 filter/source/pdf/pdfexport.hxx |    2 +
 3 files changed, 102 insertions(+)

New commits:
commit 41a22ef27df7242ab074a3fd83720c739362263d
Author:     merttumer <mert.tumer at collabora.com>
AuthorDate: Fri Feb 8 20:26:46 2019 +0300
Commit:     Andras Timar <andras.timar at collabora.com>
CommitDate: Fri Feb 8 22:27:24 2019 +0100

    Added Tiled Watermark Feature for pdf export
    
    Change-Id: I1f01e16e6958b0be4f82b13c2f3c5a91a8f05558
    Signed-off-by: merttumer <mert.tumer at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/67551
    Reviewed-by: Andras Timar <andras.timar at collabora.com>
    Tested-by: Andras Timar <andras.timar at collabora.com>

diff --git a/desktop/source/lib/init.cxx b/desktop/source/lib/init.cxx
index 739b21dbaf11..a1f4dea54c41 100644
--- a/desktop/source/lib/init.cxx
+++ b/desktop/source/lib/init.cxx
@@ -1839,6 +1839,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
@@ -1867,6 +1886,13 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
         aSaveMediaDescriptor["Overwrite"] <<= true;
         aSaveMediaDescriptor["FilterName"] <<= aFilterName;
         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 ca454bbd65f7..6c9e7b90320c 100644
--- a/filter/source/pdf/pdfexport.cxx
+++ b/filter/source/pdf/pdfexport.cxx
@@ -499,6 +499,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;
@@ -1038,7 +1040,13 @@ bool 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()) );
+    }
 
     return true;
 }
@@ -1111,4 +1119,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( "Helvetica" ), Size( 0, 40 ) );
+    aFont.SetItalic( ITALIC_NONE );
+    aFont.SetWidthType( WIDTH_NORMAL );
+    aFont.SetWeight( WEIGHT_BOLD );
+    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 4a371433263a..9d302900cdee 100644
--- a/filter/source/pdf/pdfexport.hxx
+++ b/filter/source/pdf/pdfexport.hxx
@@ -66,6 +66,7 @@ private:
     bool                mbRemoveTransparencies;
 
     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)
@@ -106,6 +107,7 @@ 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