diff options
author | Paul Trojahn <paul.trojahn@gmail.com> | 2017-11-13 18:27:22 +0100 |
---|---|---|
committer | Tamás Zolnai <tamas.zolnai@collabora.com> | 2017-12-18 15:46:40 +0100 |
commit | 3b4f14f4da046dab25362114db737968634cd720 (patch) | |
tree | 1d11378090d4d5d4e8b8a6cfa605c28b7a33830b /oox | |
parent | 61b1d631331551b43bc7d619be33bfbfeff7cad6 (diff) |
tdf#90626 PPTX: Fix image bullet size
This solution comes with a few limitations. The bullet isn't centered in
Powerpoint and has to be between 25% and 400% of the size of the first
character in the paragraph. This isn't optimal, but should produce
acceptable results under most circumstances.
Change-Id: I6c37169282aa351b81d78e06678424203b78f6d7
Reviewed-on: https://gerrit.libreoffice.org/44911
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Tamás Zolnai <tamas.zolnai@collabora.com>
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/drawingml/textparagraph.hxx | 2 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraph.cxx | 14 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraphproperties.cxx | 8 | ||||
-rw-r--r-- | oox/source/drawingml/textparagraphpropertiescontext.cxx | 2 | ||||
-rw-r--r-- | oox/source/export/drawingml.cxx | 30 |
5 files changed, 36 insertions, 20 deletions
diff --git a/oox/inc/drawingml/textparagraph.hxx b/oox/inc/drawingml/textparagraph.hxx index 10eb0ee35468..ec0d57686e1b 100644 --- a/oox/inc/drawingml/textparagraph.hxx +++ b/oox/inc/drawingml/textparagraph.hxx @@ -29,6 +29,8 @@ #include <drawingml/textliststyle.hxx> #include <drawingml/textparagraphproperties.hxx> +// The height the bullet is relative to is different in OOXML +#define OOX_BULLET_LIST_SCALE_FACTOR 0.7f namespace oox { namespace formulaimport { class XmlStreamBuilder; diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx index 02e5efa54f03..8f1e5d1b061c 100644 --- a/oox/source/drawingml/textparagraph.cxx +++ b/oox/source/drawingml/textparagraph.cxx @@ -20,6 +20,7 @@ #include <drawingml/textparagraph.hxx> #include <oox/drawingml/drawingmltypes.hxx> #include <drawingml/textcharacterproperties.hxx> +#include <svtools/unitconv.hxx> #include <rtl/ustring.hxx> #include <oox/mathml/importutils.hxx> @@ -133,6 +134,19 @@ void TextParagraph::insertAt( aioBulletList.setProperty( PROP_BulletColor, (*maRuns.begin())->getTextCharacterProperties().maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() )); if( !aioBulletList.hasProperty( PROP_BulletColor ) && aTextCharacterStyle.maFillProperties.moFillType.has() ) aioBulletList.setProperty( PROP_BulletColor, aTextCharacterStyle.maFillProperties.getBestSolidColor().getColor( rFilterBase.getGraphicHelper() )); + if( !aioBulletList.hasProperty( PROP_GraphicSize ) && maRuns.size() > 0 + && aParaProp.getBulletList().maGraphic.hasValue()) + { + float fFirstCharHeight = maRuns.front()->getTextCharacterProperties().getCharHeightPoints(12); + long nFirstCharHeightMm = TransformMetric(fFirstCharHeight * 100.f, FUNIT_POINT, FUNIT_MM); + float fBulletSizeRel = 1.f; + if( aParaProp.getBulletList().mnSize.hasValue() ) + fBulletSizeRel = aParaProp.getBulletList().mnSize.get<sal_Int16>() / 100.f; + + css::awt::Size aBulletSize; + aBulletSize.Width = aBulletSize.Height = std::lround(fBulletSizeRel * nFirstCharHeightMm * OOX_BULLET_LIST_SCALE_FACTOR); + aioBulletList.setProperty( PROP_GraphicSize, aBulletSize); + } float fCharacterSize = nCharHeight > 0 ? GetFontHeight ( nCharHeight ) : pTextParagraphStyle->getCharHeightPoints( 12 ); aParaProp.pushToPropSet( &rFilterBase, xProps, aioBulletList, &pTextParagraphStyle->getBulletList(), true, fCharacterSize, true ); diff --git a/oox/source/drawingml/textparagraphproperties.cxx b/oox/source/drawingml/textparagraphproperties.cxx index bc523073bfff..c36912bb9dca 100644 --- a/oox/source/drawingml/textparagraphproperties.cxx +++ b/oox/source/drawingml/textparagraphproperties.cxx @@ -411,14 +411,6 @@ void TextParagraphProperties::pushToPropSet( const ::oox::core::XmlFilterBase* p aPropSet.setProperty( PROP_ParaTopMargin, maParaTopMargin.toMargin( fCharacterSize != 0.0 ? fCharacterSize : getCharHeightPoints ( 12.0 ) ) ); if ( maParaBottomMargin.bHasValue || bPushDefaultValues ) aPropSet.setProperty( PROP_ParaBottomMargin, maParaBottomMargin.toMargin( fCharacterSize != 0.0 ? fCharacterSize : getCharHeightPoints ( 12.0 ) ) ); - if ( nNumberingType == NumberingType::BITMAP ) - { - fCharacterSize = getCharHeightPoints( fCharacterSize ); - - css::awt::Size aBulletSize; - aBulletSize.Width = aBulletSize.Height = static_cast< sal_Int32 >( ( fCharacterSize * ( 2540.0 / 72.0 ) * 0.8 ) ); - rioBulletMap.setProperty( PROP_GraphicSize, aBulletSize); - } boost::optional< sal_Int32 > noParaLeftMargin( moParaLeftMargin ); boost::optional< sal_Int32 > noFirstLineIndentation( moFirstLineIndentation ); diff --git a/oox/source/drawingml/textparagraphpropertiescontext.cxx b/oox/source/drawingml/textparagraphpropertiescontext.cxx index 616ec3d3cd0c..fdc9c3f210a9 100644 --- a/oox/source/drawingml/textparagraphpropertiescontext.cxx +++ b/oox/source/drawingml/textparagraphpropertiescontext.cxx @@ -182,7 +182,7 @@ ContextHandlerRef TextParagraphPropertiesContext::onCreateContext( sal_Int32 aEl mrBulletList.setBulletSize(100); break; case A_TOKEN( buSzPct ): // CT_TextBulletSizePercent - mrBulletList.setBulletSize( static_cast<sal_Int16>( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000 ) ); + mrBulletList.setBulletSize( std::lround( GetPercent( rAttribs.getString( XML_val ).get() ) / 1000.f ) ); break; case A_TOKEN( buSzPts ): // CT_TextBulletSizePoint mrBulletList.setBulletSize(0); diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx index f500036e1282..9e161bb16615 100644 --- a/oox/source/export/drawingml.cxx +++ b/oox/source/export/drawingml.cxx @@ -26,10 +26,12 @@ #include <oox/export/utils.hxx> #include <oox/drawingml/color.hxx> #include <drawingml/fillproperties.hxx> +#include <drawingml/textparagraph.hxx> #include <oox/token/namespaces.hxx> #include <oox/token/relationship.hxx> #include <oox/token/tokens.hxx> #include <oox/drawingml/drawingmltypes.hxx> +#include <svtools/unitconv.hxx> #include <cstdio> #include <com/sun/star/awt/CharSet.hpp> @@ -1872,7 +1874,7 @@ OUString GetAutoNumType(SvxNumType nNumberingType, bool bSDot, bool bPBehind, bo return OUString(); } -void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXPropSet, sal_Int16 nLevel ) +void DrawingML::WriteParagraphNumbering(const Reference< XPropertySet >& rXPropSet, float fFirstCharHeight, sal_Int16 nLevel ) { if( nLevel < 0 || !GETA( NumberingRules ) ) return; @@ -1906,6 +1908,7 @@ void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXProp sal_Int16 nStartWith = 1; sal_uInt32 nBulletColor = 0; bool bHasBulletColor = false; + awt::Size aGraphicSize; for ( sal_Int32 i = 0; i < nPropertyCount; i++ ) { @@ -1965,13 +1968,8 @@ void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXProp } else if ( aPropName == "GraphicSize" ) { - if (auto aSize = o3tl::tryAccess<awt::Size>(pPropValue[i].Value)) - { - // don't cast awt::Size to Size as on 64-bits they are not the same. - //aBuGraSize.nA = aSize.Width; - //aBuGraSize.nB = aSize.Height; - SAL_INFO("oox.shape", "graphic size: " << aSize->Width << "x" << aSize->Height); - } + aGraphicSize = *o3tl::doAccess<awt::Size>(pPropValue[i].Value); + SAL_INFO("oox.shape", "graphic size: " << aGraphicSize.Width << "x" << aGraphicSize.Height); } } @@ -1982,6 +1980,11 @@ void DrawingML::WriteParagraphNumbering( const Reference< XPropertySet >& rXProp { OUString sRelId = WriteImage( aGraphicURL ); + long nFirstCharHeightMm = TransformMetric(fFirstCharHeight * 100.f, FUNIT_POINT, FUNIT_MM); + float fBulletSizeRel = aGraphicSize.Height / static_cast<float>(nFirstCharHeightMm) / OOX_BULLET_LIST_SCALE_FACTOR; + + mpFS->singleElementNS( XML_a, XML_buSzPct, + XML_val, IS( std::max( static_cast<sal_Int32>(25000), std::min( static_cast<sal_Int32>(400000), static_cast<sal_Int32>( std::lround( 100000.f * fBulletSizeRel ) ) ) ) ), FSEND ); mpFS->startElementNS( XML_a, XML_buBlip, FSEND ); mpFS->singleElementNS( XML_a, XML_blip, FSNS( XML_r, XML_embed ), USS( sRelId ), FSEND ); mpFS->endElementNS( XML_a, XML_buBlip ); @@ -2099,7 +2102,7 @@ void DrawingML::WriteLinespacing( const LineSpacing& rSpacing ) } } -void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph ) +void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rParagraph, float fFirstCharHeight) { Reference< XPropertySet > rXPropSet( rParagraph, UNO_QUERY ); Reference< XPropertyState > rXPropState( rParagraph, UNO_QUERY ); @@ -2196,7 +2199,7 @@ void DrawingML::WriteParagraphProperties( const Reference< XTextContent >& rPara mpFS->endElementNS( XML_a, XML_spcAft ); } - WriteParagraphNumbering( rXPropSet, nLevel ); + WriteParagraphNumbering( rXPropSet, fFirstCharHeight, nLevel ); mpFS->endElementNS( XML_a, XML_pPr ); } @@ -2225,7 +2228,12 @@ void DrawingML::WriteParagraph( const Reference< XTextContent >& rParagraph, { if( !bPropertiesWritten ) { - WriteParagraphProperties( rParagraph ); + float fFirstCharHeight = rnCharHeight / 1000.; + Reference< XPropertySet > xFirstRunPropSet (run, UNO_QUERY); + Reference< XPropertySetInfo > xFirstRunPropSetInfo = xFirstRunPropSet->getPropertySetInfo(); + if( xFirstRunPropSetInfo->hasPropertyByName("CharHeight") ) + fFirstCharHeight = xFirstRunPropSet->getPropertyValue("CharHeight").get<float>(); + WriteParagraphProperties( rParagraph, fFirstCharHeight ); bPropertiesWritten = true; } WriteRun( run, rbOverridingCharHeight, rnCharHeight ); |