summaryrefslogtreecommitdiffstats
path: root/oox
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>2017-12-07 13:16:15 +0100
commit3e4e3ee3dba7fa65263e71da0bc0091d4e950d33 (patch)
treee8cf0c8bb2c9fcdf16c78c54c8b745dfde7d431f /oox
parenttdf#113037 create Watermark with correct ratio (diff)
downloadcore-3e4e3ee3dba7fa65263e71da0bc0091d4e950d33.tar.gz
core-3e4e3ee3dba7fa65263e71da0bc0091d4e950d33.zip
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>
Diffstat (limited to 'oox')
-rw-r--r--oox/source/export/vmlexport.cxx18
-rw-r--r--oox/source/vml/vmlshape.cxx68
2 files changed, 84 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() ) );