Kaydet (Commit) dd3d5f7c authored tarafından merttumer's avatar merttumer Kaydeden (comit) Mert Tümer

Added tiled watermark export option for pdf

Change-Id: I3f28ad64c13dd4bc1b2862e86d2190e46a0ced46
Signed-off-by: 's avatarmerttumer <mert.tumer@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/67779
Tested-by: Jenkins
üst e8d8b827
...@@ -1905,6 +1905,25 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha ...@@ -1905,6 +1905,25 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
OUString aFilterOptions = getUString(pFilterOptions); 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 // 'TakeOwnership' == this is a 'real' SaveAs (that is, the document
// gets a new name). When this is not provided, the meaning of // gets a new name). When this is not provided, the meaning of
// saveAs() is more like save-a-copy, which allows saving to any // 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 ...@@ -1930,6 +1949,13 @@ static int doc_saveAs(LibreOfficeKitDocument* pThis, const char* sUrl, const cha
auto aFilteredOptionSeq = comphelper::containerToSequence<OUString>(aFilteredOptionVec); auto aFilteredOptionSeq = comphelper::containerToSequence<OUString>(aFilteredOptionVec);
aFilterOptions = comphelper::string::convertCommaSeparated(aFilteredOptionSeq); aFilterOptions = comphelper::string::convertCommaSeparated(aFilteredOptionSeq);
aSaveMediaDescriptor[MediaDescriptor::PROP_FILTEROPTIONS()] <<= aFilterOptions; 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 // add interaction handler too
if (gImpl) if (gImpl)
......
...@@ -525,6 +525,8 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >& ...@@ -525,6 +525,8 @@ bool PDFExport::Export( const OUString& rFile, const Sequence< PropertyValue >&
rFilterData[ nData ].Value >>= mbAddStream; rFilterData[ nData ].Value >>= mbAddStream;
else if ( rFilterData[ nData ].Name == "Watermark" ) else if ( rFilterData[ nData ].Name == "Watermark" )
rFilterData[ nData ].Value >>= msWatermark; rFilterData[ nData ].Value >>= msWatermark;
else if ( rFilterData[ nData ].Name == "TiledWatermark" )
rFilterData[ nData ].Value >>= msTiledWatermark;
// now all the security related properties... // now all the security related properties...
else if ( rFilterData[ nData ].Name == "EncryptFile" ) else if ( rFilterData[ nData ].Name == "EncryptFile" )
rFilterData[ nData ].Value >>= mbEncrypt; rFilterData[ nData ].Value >>= mbEncrypt;
...@@ -1077,7 +1079,13 @@ void PDFExport::ImplExportPage( vcl::PDFWriter& rWriter, vcl::PDFExtOutDevData& ...@@ -1077,7 +1079,13 @@ void PDFExport::ImplExportPage( vcl::PDFWriter& rWriter, vcl::PDFExtOutDevData&
rPDFExtOutDevData.ResetSyncData(); rPDFExtOutDevData.ResetSyncData();
if (!msWatermark.isEmpty()) if (!msWatermark.isEmpty())
{
ImplWriteWatermark( rWriter, Size(aRangePDF.getWidth(), aRangePDF.getHeight()) ); 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 ...@@ -1148,4 +1156,70 @@ void PDFExport::ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSi
rWriter.Pop(); 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: */ /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
...@@ -68,6 +68,7 @@ private: ...@@ -68,6 +68,7 @@ private:
bool mbIsRedactMode; bool mbIsRedactMode;
OUString msWatermark; OUString msWatermark;
OUString msTiledWatermark;
// these variable are here only to have a location in filter/pdf to set the default // 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) // to be used by the macro (when the FilterData are set by the macro itself)
...@@ -108,6 +109,8 @@ private: ...@@ -108,6 +109,8 @@ private:
OUString msSignTSA; OUString msSignTSA;
void ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize ); void ImplWriteWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize );
void ImplWriteTiledWatermark( vcl::PDFWriter& rWriter, const Size& rPageSize );
public: public:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment