diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2017-12-07 16:09:47 +0100 |
---|---|---|
committer | Andras Timar <andras.timar@collabora.com> | 2017-12-10 00:20:55 +0100 |
commit | 1aca81256407be27fd4a7e027e27c51486c2dc31 (patch) | |
tree | effdcd60e5bdc971283c4cd8d102e4d2d0f791f1 /oox | |
parent | ffe4d766a0bd9f3b936d6e742d26ca0f1e6554b4 (diff) |
tdf#114308 Export Watermark size as is
* refactoring
* removed size hack
* export/import "trim" attribute
* DOC: export set of parameters to fit shape & frame
Change-Id: Ib00654626ae1e10ac5110d22eada7528e03357e7
Reviewed-on: https://gerrit.libreoffice.org/46036
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/46154
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.cxx | 3 | ||||
-rw-r--r-- | oox/source/vml/vmlformatting.cxx | 27 | ||||
-rw-r--r-- | oox/source/vml/vmlshape.cxx | 69 | ||||
-rw-r--r-- | oox/source/vml/vmlshapecontext.cxx | 1 |
4 files changed, 32 insertions, 68 deletions
diff --git a/oox/source/export/vmlexport.cxx b/oox/source/export/vmlexport.cxx index bc2f377f0fd5..48e6fde5fe22 100644 --- a/oox/source/export/vmlexport.cxx +++ b/oox/source/export/vmlexport.cxx @@ -864,6 +864,9 @@ void VMLExport::Commit( EscherPropertyContainer& rProps, const Rectangle& rRect OUString aSize = OUString::number(nSizeF); aStyle += ";font-size:" + aSize + "pt"; } + if (IsWaterMarkShape(m_pSdrObject->GetName())) + pAttrList->add(XML_trim, "t"); + if (!aStyle.isEmpty()) pAttrList->add(XML_style, OUStringToOString(aStyle, RTL_TEXTENCODING_UTF8)); m_pSerializer->singleElementNS(XML_v, XML_textpath, XFastAttributeListRef(pAttrList)); diff --git a/oox/source/vml/vmlformatting.cxx b/oox/source/vml/vmlformatting.cxx index dc1edd877271..7722b1bcf388 100644 --- a/oox/source/vml/vmlformatting.cxx +++ b/oox/source/vml/vmlformatting.cxx @@ -20,6 +20,7 @@ #include <com/sun/star/beans/PropertyValue.hpp> #include <com/sun/star/beans/XPropertySet.hpp> +#include <com/sun/star/drawing/XShape.hpp> #include <com/sun/star/drawing/EnhancedCustomShapeTextPathMode.hpp> #include <com/sun/star/table/ShadowFormat.hpp> #include <com/sun/star/text/XTextRange.hpp> @@ -34,6 +35,9 @@ #include "oox/helper/graphichelper.hxx" #include <oox/token/properties.hxx> #include <oox/token/tokens.hxx> +#include <svx/svdtrans.hxx> +#include <comphelper/propertysequence.hxx> +#include <vcl/virdev.hxx> namespace oox { namespace vml { @@ -868,6 +872,8 @@ beans::PropertyValue lcl_createTextpathProps() void TextpathModel::pushToPropMap(ShapePropertyMap& rPropMap, const uno::Reference<drawing::XShape>& xShape, const GraphicHelper& rGraphicHelper) const { + OUString sFont = ""; + if (moString.has()) { uno::Reference<text::XTextRange> xTextRange(xShape, uno::UNO_QUERY); @@ -911,6 +917,7 @@ void TextpathModel::pushToPropMap(ShapePropertyMap& rPropMap, const uno::Referen uno::Reference<beans::XPropertySet> xPropertySet(xShape, uno::UNO_QUERY); xPropertySet->setPropertyValue("CharFontName", uno::makeAny(aValue)); + sFont = aValue; } else if (aName == "font-size") { @@ -923,6 +930,26 @@ void TextpathModel::pushToPropMap(ShapePropertyMap& rPropMap, const uno::Referen } } } + if (!moTrim.has() || !moTrim.get()) + { + OUString sText = moString.get(); + double fRatio = 0; + VclPtr<VirtualDevice> pDevice = VclPtr<VirtualDevice>::Create(); + vcl::Font aFont = pDevice->GetFont(); + aFont.SetFamilyName(sFont); + aFont.SetFontSize(Size(0, 96)); + pDevice->SetFont(aFont); + + auto nTextWidth = pDevice->GetTextWidth(sText); + if (nTextWidth) + { + fRatio = pDevice->GetTextHeight(); + fRatio /= nTextWidth; + + sal_Int32 nNewHeight = fRatio * xShape->getSize().Width; + xShape->setSize(awt::Size(xShape->getSize().Width, nNewHeight)); + } + } } } // namespace vml diff --git a/oox/source/vml/vmlshape.cxx b/oox/source/vml/vmlshape.cxx index d82076315acb..27730de50ccf 100644 --- a/oox/source/vml/vmlshape.cxx +++ b/oox/source/vml/vmlshape.cxx @@ -1103,79 +1103,12 @@ 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; - VclPtr<VirtualDevice> pDevice = VclPtr<VirtualDevice>::Create(); - vcl::Font aFont = pDevice->GetFont(); - aFont.SetFamilyName( sFont ); - aFont.SetFontSize( Size( 0, 96 ) ); - pDevice->SetFont( aFont ); - - auto nTextWidth = pDevice->GetTextWidth( sText ); - if( nTextWidth ) - { - fRatio = pDevice->GetTextHeight(); - fRatio /= nTextWidth; - - 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, aShapeRect ); + Reference< XShape > xShape = SimpleShape::implConvertAndInsert( rxShapes, rShapeRect ); 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/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx index 8f4170b40f49..ba587e1b3236 100644 --- a/oox/source/vml/vmlshapecontext.cxx +++ b/oox/source/vml/vmlshapecontext.cxx @@ -392,6 +392,7 @@ ContextHandlerRef ShapeTypeContext::onCreateContext( sal_Int32 nElement, const A case VML_TOKEN( textpath ): mrTypeModel.maTextpathModel.moString.assignIfUsed(rAttribs.getString(XML_string)); mrTypeModel.maTextpathModel.moStyle.assignIfUsed(rAttribs.getString(XML_style)); + mrTypeModel.maTextpathModel.moTrim.assignIfUsed(lclDecodeBool(rAttribs, XML_trim)); break; } return nullptr; |