[Libreoffice-commits] core.git: oox/inc oox/source

Gülşah Köse (via logerrit) logerrit at kemper.freedesktop.org
Sat Nov 14 21:07:10 UTC 2020


 oox/inc/drawingml/textparagraphproperties.hxx           |    2 +
 oox/source/drawingml/textparagraph.cxx                  |   14 ++++++-
 oox/source/drawingml/textparagraphproperties.cxx        |    7 +++
 oox/source/drawingml/textparagraphpropertiescontext.cxx |   32 +++++++++++++++-
 4 files changed, 53 insertions(+), 2 deletions(-)

New commits:
commit c9619a5f6c351ede0dbfb3cf07df0ac9b74c2992
Author:     Gülşah Köse <gulsah.kose at collabora.com>
AuthorDate: Thu Nov 12 01:52:15 2020 +0300
Commit:     Gülşah Köse <gulsah.kose at collabora.com>
CommitDate: Sat Nov 14 22:06:22 2020 +0100

    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 at collabora.com>

diff --git a/oox/inc/drawingml/textparagraphproperties.hxx b/oox/inc/drawingml/textparagraphproperties.hxx
index 23a177d289f5..7dd41610024b 100644
--- a/oox/inc/drawingml/textparagraphproperties.hxx
+++ b/oox/inc/drawingml/textparagraphproperties.hxx
@@ -54,6 +54,7 @@ public:
     void setSuffixNone();
     void setSuffixMinusRight();
     void setBulletSize(sal_Int16 nSize);
+    void setBulletAspectRatio(double nAspectRatio);
     void setFontSize(sal_Int16 nSize);
     void setStyleName( const OUString& rStyleName ) { maStyleName <<= rStyleName; }
     void setGraphic( css::uno::Reference< css::graphic::XGraphic > const & rXGraphic );
@@ -68,6 +69,7 @@ public:
     css::uno::Any               msNumberingPrefix;
     css::uno::Any               msNumberingSuffix;
     css::uno::Any               mnSize;
+    css::uno::Any               mnAspectRatio; // Width/Height
     css::uno::Any               mnFontSize;
     css::uno::Any               maStyleName;
     css::uno::Any               maGraphic;
diff --git a/oox/source/drawingml/textparagraph.cxx b/oox/source/drawingml/textparagraph.cxx
index 21c8d44c0079..8aa4d8895040 100644
--- a/oox/source/drawingml/textparagraph.cxx
+++ b/oox/source/drawingml/textparagraph.cxx
@@ -144,11 +144,23 @@ void TextParagraph::insertAt(
             {
                 tools::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 8121edb156ff..197f0e51f28a 100644
--- a/oox/source/drawingml/textparagraphproperties.cxx
+++ b/oox/source/drawingml/textparagraphproperties.cxx
@@ -246,6 +246,11 @@ void BulletList::setBulletSize(sal_Int16 nSize)
     mnSize <<= nSize;
 }
 
+void BulletList::setBulletAspectRatio(double nAspectRatio)
+{
+    mnAspectRatio <<= nAspectRatio;
+}
+
 void BulletList::setFontSize(sal_Int16 nSize)
 {
     mnFontSize <<= nSize;
@@ -272,6 +277,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 b58d8952ca76..e81101f85ec2 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>
@@ -43,8 +46,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::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,
@@ -153,7 +180,10 @@ TextParagraphPropertiesContext::~TextParagraphPropertiesContext()
     }
 
     if (mxBlipProps && mxBlipProps->mxFillGraphic.is())
-        mrBulletList.setGraphic(mxBlipProps->mxFillGraphic);
+    {
+        mrBulletList.setGraphic( mxBlipProps->mxFillGraphic );
+        mrBulletList.setBulletAspectRatio( lclGetGraphicAspectRatio(mxBlipProps->mxFillGraphic) );
+    }
 
     if( mrBulletList.is() )
         rPropertyMap.setProperty( PROP_IsNumbering, true);


More information about the Libreoffice-commits mailing list