summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSzymon Kłos <szymon.klos@collabora.com>2017-11-02 19:53:53 +0100
committerAndras Timar <andras.timar@collabora.com>2018-01-17 08:39:30 +0100
commitecb450de54eb1a757eb1498597c20ec28e37a65d (patch)
tree695ce822a940b7bb996e204cc541fdae80be88ed
parent0f4e87dee94788bbaf61efc473981e715a33e7cb (diff)
tdf#113037 DOCX Watermark correct ratio
Import and export Watermark with padding like MSO does. Shape is scaled to save correct ratio. Reviewed-on: https://gerrit.libreoffice.org/44319 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Szymon Kłos <szymon.klos@collabora.com> (cherry picked from commit a3a917748892a6a3194ebfc4db64cfd764cc054a) Change-Id: Iebd8eb5f168e0030320406d4fd6b287e451267bd Reviewed-on: https://gerrit.libreoffice.org/45995 Reviewed-by: Andras Timar <andras.timar@collabora.com> Tested-by: Andras Timar <andras.timar@collabora.com> (cherry picked from commit 3e4e3ee3dba7fa65263e71da0bc0091d4e950d33)
-rw-r--r--oox/source/export/vmlexport.cxx18
-rw-r--r--oox/source/vml/vmlshape.cxx68
-rw-r--r--sw/qa/extras/ooxmlexport/data/watermark.docxbin14766 -> 19473 bytes
-rw-r--r--sw/qa/extras/ooxmlexport/ooxmlexport9.cxx17
4 files changed, 101 insertions, 2 deletions
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx
index cf6e5d6234f2..bc2f377f0fd5 100644
--- a/oox/source/export/vmlexport.cxx
+++ b/oox/source/export/vmlexport.cxx
@@ -19,6 +19,7 @@
#include <config_folders.h>
#include "rtl/bootstrap.hxx"
+#include <svl/itemset.hxx>
#include <oox/export/drawingml.hxx>
#include <oox/export/vmlexport.hxx>
@@ -393,7 +394,22 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect
if ( m_nShapeType == ESCHER_ShpInst_Line )
AddLineDimensions( rRect );
else
- AddRectangleDimensions( *m_pShapeStyle, rRect );
+ {
+ if ( IsWaterMarkShape( m_pSdrObject->GetName() ) )
+ {
+ // Watermark need some padding to be compatible with MSO
+ long nPaddingY = 0;
+ const SfxItemSet& rSet = m_pSdrObject->GetMergedItemSet();
+ if ( const SdrMetricItem* pItem = static_cast<const SdrMetricItem*>( rSet.GetItem( SDRATTR_TEXT_UPPERDIST ) ) )
+ nPaddingY += pItem->GetValue();
+
+ Rectangle aRect( rRect );
+ aRect.setHeight( aRect.getHeight() + nPaddingY );
+ AddRectangleDimensions( *m_pShapeStyle, aRect );
+ }
+ else
+ AddRectangleDimensions( *m_pShapeStyle, rRect );
+ }
// properties
bool bAlreadyWritten[ 0xFFF ];
diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx
index 814835fae503..a9d31b26c82d 100644
--- a/oox/source/vml/vmlshape.cxx
+++ b/oox/source/vml/vmlshape.cxx
@@ -66,6 +66,7 @@
#include <svx/svdoashp.hxx>
#include <comphelper/sequence.hxx>
#include <comphelper/propertyvalue.hxx>
+#include <vcl/svapp.hxx>
using ::com::sun::star::beans::XPropertySet;
using ::com::sun::star::uno::Any;
@@ -1101,12 +1102,77 @@ CustomShape::CustomShape( Drawing& rDrawing ) :
{
}
+static OUString lcl_getFontFamily( const oox::OptValue<OUString>& rStyle )
+{
+ OUString sFont = "";
+
+ if( rStyle.has() )
+ {
+ OUString aStyle = rStyle.get( OUString() );
+
+ sal_Int32 nIndex = 0;
+ while( nIndex >= 0 )
+ {
+ OUString aName;
+ if( ConversionHelper::separatePair( aName, sFont, aStyle.getToken( 0, ';', nIndex ), ':' ) )
+ {
+ if( aName == "font-family" )
+ {
+ // remove " (first, and last character)
+ if( sFont.getLength() > 2 )
+ sFont = sFont.copy( 1, sFont.getLength() - 2 );
+ }
+ }
+ }
+ }
+
+ return sFont;
+}
+
+/// modifies rShapeRect's height and returns difference
+sal_Int32 lcl_correctWatermarkRect( awt::Rectangle& rShapeRect, const OUString& sFont, const OUString& sText )
+{
+ sal_Int32 nPaddingY = 0;
+ double fRatio = 0;
+ OutputDevice* pOut = Application::GetDefaultDevice();
+ vcl::Font aFont( pOut->GetFont() );
+ aFont.SetFamilyName( sFont );
+
+ Rectangle aBoundingRect;
+ pOut->GetTextBoundRect( aBoundingRect, sText );
+ if( aBoundingRect.GetWidth() )
+ {
+ fRatio = (double)aBoundingRect.GetHeight() / aBoundingRect.GetWidth();
+
+ sal_Int32 nNewHeight = fRatio * rShapeRect.Width;
+ nPaddingY = rShapeRect.Height - nNewHeight;
+ rShapeRect.Height = nNewHeight;
+ }
+
+ return nPaddingY;
+}
+
Reference< XShape > CustomShape::implConvertAndInsert( const Reference< XShapes >& rxShapes, const awt::Rectangle& rShapeRect ) const
{
+ awt::Rectangle aShapeRect( rShapeRect );
+
+ // Add padding for Watermark like Word does
+ sal_Int32 nPaddingY = 0;
+ if( getShapeName().match( "PowerPlusWaterMarkObject" ) && maTypeModel.maTextpathModel.moString.has() )
+ {
+ OUString sText = maTypeModel.maTextpathModel.moString.get();
+ OUString sFont = lcl_getFontFamily( maTypeModel.maTextpathModel.moStyle );
+ nPaddingY = lcl_correctWatermarkRect( aShapeRect, sFont, sText );
+ }
+
// try to create a custom shape
- Reference< XShape > xShape = SimpleShape::implConvertAndInsert( rxShapes, rShapeRect );
+ Reference< XShape > xShape = SimpleShape::implConvertAndInsert( rxShapes, aShapeRect );
if( xShape.is() ) try
{
+ // Remember padding for Watermark
+ if( nPaddingY )
+ PropertySet( xShape ).setAnyProperty( PROP_TextUpperDistance, makeAny( nPaddingY ) );
+
// create the custom shape geometry
Reference< XEnhancedCustomShapeDefaulter > xDefaulter( xShape, UNO_QUERY_THROW );
xDefaulter->createCustomShapeDefaults( OUString::number( getShapeType() ) );
diff --git a/sw/qa/extras/ooxmlexport/data/watermark.docx b/sw/qa/extras/ooxmlexport/data/watermark.docx
index 8e279e3e857f..98c305af8cab 100644
--- a/sw/qa/extras/ooxmlexport/data/watermark.docx
+++ b/sw/qa/extras/ooxmlexport/data/watermark.docx
Binary files differ
diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
index 14731d28dbfa..9740bc954397 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport9.cxx
@@ -31,6 +31,7 @@
#include <ftninfo.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
+#include <editeng/unoprnms.hxx>
class Test : public SwModelTestBase
{
@@ -601,6 +602,22 @@ DECLARE_OOXMLEXPORT_TEST(testTdf67207_MERGEFIELD, "mailmerge.docx")
CPPUNIT_ASSERT_EQUAL(OUString("com.sun.star.text.fieldmaster.DataBase.Name"), sValue);
}
+DECLARE_OOXMLEXPORT_TEST(testWatermarkSize, "watermark.docx")
+{
+ uno::Reference<drawing::XShape> xShape(getShape(1), uno::UNO_QUERY);
+ uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY);
+
+ sal_Int32 nTotalHeight = 0;
+ xPropertySet->getPropertyValue(UNO_NAME_TEXT_UPPERDIST) >>= nTotalHeight;
+ nTotalHeight += xShape->getSize().Height;
+
+ // Rounding errors
+ sal_Int32 nDifference = 5198 - nTotalHeight;
+ std::stringstream ss;
+ ss << "Difference: " << nDifference;
+ CPPUNIT_ASSERT_MESSAGE(ss.str(), nDifference <= 4);
+}
+
CPPUNIT_PLUGIN_IMPLEMENT();
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */