diff options
author | Gülşah Köse <gulsah.kose@collabora.com> | 2020-11-12 01:52:15 +0300 |
---|---|---|
committer | Gülşah Köse <gulsah.kose@collabora.com> | 2020-11-16 21:20:49 +0100 |
commit | 88ed0ab17cb647a785398650036593a8e82334f0 (patch) | |
tree | 2179aabcda1b37f11c923f918651d13a36f53bfe /oox/source | |
parent | e30fa3a342e2cdff131fc3ae17acf94e9afe521e (diff) |
tdf#138148 Protect aspect ratio of graphic bullets.
Change-Id: I166d547cdc01853fd81436c6cdc8d64b0fe817be
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105618
Tested-by: Jenkins
Reviewed-by: Gülşah Köse <gulsah.kose@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/105912
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Diffstat (limited to 'oox/source')
-rw-r--r-- | oox/source/drawingml/textparagraph.cxx | 14 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraphproperties.cxx | 7 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraphpropertiescontext.cxx | 32 |
3 files changed, 51 insertions, 2 deletions
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx index 078fd777bff4..b5635b58f2e9 100644 --- a/oox/source/drawingml/textparagraph.cxx +++ b/oox/source/drawingml/textparagraph.cxx @@ -144,11 +144,23 @@ void TextParagraph::insertAt( { long nFirstCharHeightMm = TransformMetric(nCharHeightFirst > 0 ? nCharHeightFirst : 1200, FieldUnit::POINT, FieldUnit::MM); float fBulletSizeRel = 1.f; + double fBulletAspectRatio = 1.0; + if( aParaProp.getBulletList().mnSize.hasValue() ) fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f; + if( aParaProp.getBulletList().mnAspectRatio.hasValue() ) + fBulletAspectRatio = aParaProp.getBulletList().mnAspectRatio.get<double>(); + css::awt::Size aBulletSize; - aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR); + if( fBulletAspectRatio != 1.0 ) + { + aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR); + aBulletSize.Width = aBulletSize.Height * fBulletAspectRatio; + } + else + aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR); + aioBulletList.setProperty( PROP_GraphicSize, aBulletSize); } diff --git a/oox/source/drawingml/textparagraphproperties.cxx b/oox/source/drawingml/textparagraphproperties.cxx index 9183c2f53e64..04262c15bf27 100644 --- a/oox/source/drawingml/textparagraphproperties.cxx +++ b/oox/source/drawingml/textparagraphproperties.cxx @@ -249,6 +249,11 @@ void BulletList::setBulletSize(sal_Int16 nSize) mnSize <<= nSize; } +void BulletList::setBulletAspectRatio(double nAspectRatio) +{ + mnAspectRatio <<= nAspectRatio; +} + void BulletList::setFontSize(sal_Int16 nSize) { mnFontSize <<= nSize; @@ -275,6 +280,8 @@ void BulletList::apply( const BulletList& rSource ) msNumberingSuffix = rSource.msNumberingSuffix; if ( rSource.mnSize.hasValue() ) mnSize = rSource.mnSize; + if ( rSource.mnAspectRatio.hasValue() ) + mnAspectRatio = rSource.mnAspectRatio; if ( rSource.mnFontSize.hasValue() ) mnFontSize = rSource.mnFontSize; if ( rSource.maStyleName.hasValue() ) diff --git a/oox/source/drawingml/textparagraphpropertiescontext.cxx b/oox/source/drawingml/textparagraphpropertiescontext.cxx index 8e02a7bdb694..c74542476f06 100644 --- a/oox/source/drawingml/textparagraphpropertiescontext.cxx +++ b/oox/source/drawingml/textparagraphpropertiescontext.cxx @@ -22,6 +22,9 @@ #include <com/sun/star/text/WritingMode2.hpp> #include <com/sun/star/style/ParagraphAdjust.hpp> #include <com/sun/star/xml/sax/SAXException.hpp> +#include <com/sun/star/graphic/XGraphic.hpp> +#include <com/sun/star/awt/Size.hpp> +#include <com/sun/star/uno/Reference.hxx> #include <svx/unopage.hxx> #include <sal/log.hxx> @@ -41,8 +44,32 @@ using namespace ::com::sun::star::uno; using namespace ::com::sun::star::xml::sax; using namespace ::com::sun::star::style; using namespace ::com::sun::star::text; +using namespace ::com::sun::star::graphic; namespace oox { namespace drawingml { +namespace { + +double lclGetGraphicAspectRatio( const Reference< XGraphic >& rxGraphic ) +{ + double fRatio = 1.0; + Reference< com::sun::star::beans::XPropertySet > xGraphicPropertySet( rxGraphic, UNO_QUERY_THROW ); + css::awt::Size aSizeHmm( 0, 0 ); + xGraphicPropertySet->getPropertyValue( "Size100thMM" ) >>= aSizeHmm; + + if( aSizeHmm.Width > 0 && aSizeHmm.Height > 0) + return double(aSizeHmm.Width)/double(aSizeHmm.Height); + else + { + css::awt::Size aSourceSizePixel( 0, 0 ); + xGraphicPropertySet->getPropertyValue( "SizePixel" ) >>= aSourceSizePixel; + + if( aSourceSizePixel.Width > 0 && aSourceSizePixel.Height > 0 ) + return double(aSourceSizePixel.Width)/double(aSourceSizePixel.Height); + } + return fRatio; +} + +} //namespace // CT_TextParagraphProperties TextParagraphPropertiesContext::TextParagraphPropertiesContext( ContextHandler2Helper const & rParent, @@ -151,7 +178,10 @@ TextParagraphPropertiesContext::~TextParagraphPropertiesContext() } if (mxBlipProps.get() && mxBlipProps->mxFillGraphic.is()) - mrBulletList.setGraphic(mxBlipProps->mxFillGraphic); + { + mrBulletList.setGraphic( mxBlipProps->mxFillGraphic ); + mrBulletList.setBulletAspectRatio( lclGetGraphicAspectRatio(mxBlipProps->mxFillGraphic) ); + } if( mrBulletList.is() ) rPropertyMap.setProperty( PROP_IsNumbering, true); |