xmloff/source/style/xmlnumi.cxx |  203 ++++++++++++++++------------------------
 1 file changed, 82 insertions(+), 121 deletions(-)

New commits:
commit 93605ab85a8b62dbfb59a9181a26b75a032b9a94
Author:     Vasily Melenchuk <vasily.melenc...@cib.de>
AuthorDate: Mon Jun 7 09:49:53 2021 +0300
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Tue Jun 8 10:49:23 2021 +0200

    Use containerToSequence for Sequence of dynamic size
    
    Instead of set of conditions to detect size of resulting Sequence
    this should be shorter and cleaner.
    
    Change-Id: I52c87ecf3f21f40a52be5ac180a14499f4512072
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116772
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/xmloff/source/style/xmlnumi.cxx b/xmloff/source/style/xmlnumi.cxx
index 778741501711..3f8040bbad6c 100644
--- a/xmloff/source/style/xmlnumi.cxx
+++ b/xmloff/source/style/xmlnumi.cxx
@@ -40,6 +40,8 @@
 #include <rtl/ustrbuf.hxx>
 #include <sal/log.hxx>
 #include <tools/diagnose_ex.h>
+#include <comphelper/sequence.hxx>
+#include <comphelper/propertyvalue.hxx>
 
 #include <tools/fontenum.hxx>
 #include <tools/color.hxx>
@@ -351,36 +353,27 @@ css::uno::Reference< css::xml::sax::XFastContextHandler > 
SvxXMLListLevelStyleCo
 
 Sequence<beans::PropertyValue> 
SvxXMLListLevelStyleContext_Impl::GetProperties()
 {
+    if (!bBullet && !bImage && !bNum)
+    {
+        return Sequence<beans::PropertyValue>();
+    }
+
     sal_Int16 eType = NumberingType::NUMBER_NONE;
+    std::vector<beans::PropertyValue> aProperties;
 
-    sal_Int32 nCount = 0;
     if( bBullet )
     {
         eType = NumberingType::CHAR_SPECIAL;
-        nCount = 15; // 'cBullet' will be written anyway if 'bBullet' is true
     }
     if( bImage )
     {
         eType = NumberingType::BITMAP;
-        nCount = 15;
-
-        if( !sImageURL.isEmpty() || xBase64Stream.is() )
-            nCount++;
     }
     if( bNum )
     {
         eType = NumberingType::ARABIC;
         GetImport().GetMM100UnitConverter().convertNumFormat(
                 eType, sNumFormat, sNumLetterSync, true );
-        nCount = 15;
-    }
-
-    if( ( bBullet || bNum ) && nRelSize )
-        nCount++;
-
-    if( !bImage && bHasColor )
-    {
-        nCount++;
     }
 
     if (bBullet && !sSuffix.isEmpty())
@@ -399,142 +392,110 @@ Sequence<beans::PropertyValue> 
SvxXMLListLevelStyleContext_Impl::GetProperties()
         }
     }
 
-    Sequence<beans::PropertyValue> aPropSeq( nCount );
-    if( nCount > 0 )
-    {
-        beans::PropertyValue *pProps = aPropSeq.getArray();
-        sal_Int32 nPos = 0;
-        pProps[nPos].Name = "NumberingType";
-        pProps[nPos++].Value <<= eType ;
+    aProperties.push_back(comphelper::makePropertyValue("NumberingType", 
eType));
 
-        pProps[nPos].Name = "Prefix";
-        pProps[nPos++].Value <<= sPrefix;
+    aProperties.push_back(comphelper::makePropertyValue("Prefix", sPrefix));
 
-        pProps[nPos].Name = "Suffix";
-        pProps[nPos++].Value <<= sSuffix;
+    aProperties.push_back(comphelper::makePropertyValue("Suffix", sSuffix));
 
-        pProps[nPos].Name = "Adjust";
-        pProps[nPos++].Value <<= eAdjust;
+    aProperties.push_back(comphelper::makePropertyValue("Adjust", eAdjust));
 
-        sal_Int32 nLeftMargin = nSpaceBefore + nMinLabelWidth;
-        pProps[nPos].Name = "LeftMargin";
-        pProps[nPos++].Value <<= nLeftMargin;
+    sal_Int32 nLeftMargin = nSpaceBefore + nMinLabelWidth;
+    aProperties.push_back(comphelper::makePropertyValue("LeftMargin", 
nLeftMargin));
 
-        sal_Int32 nFirstLineOffset = -nMinLabelWidth;
+    sal_Int32 nFirstLineOffset = -nMinLabelWidth;
+    aProperties.push_back(comphelper::makePropertyValue("FirstLineOffset", 
nFirstLineOffset));
 
-        pProps[nPos].Name = "FirstLineOffset";
-        pProps[nPos++].Value <<= nFirstLineOffset;
+    aProperties.push_back(comphelper::makePropertyValue("SymbolTextDistance", 
static_cast<sal_Int16>(nMinLabelDist)));
 
-        pProps[nPos].Name = "SymbolTextDistance";
-        pProps[nPos++].Value <<= static_cast<sal_Int16>(nMinLabelDist);
+    
aProperties.push_back(comphelper::makePropertyValue("PositionAndSpaceMode", 
ePosAndSpaceMode));
 
-        pProps[nPos].Name = "PositionAndSpaceMode";
-        pProps[nPos++].Value <<= ePosAndSpaceMode;
-        pProps[nPos].Name = "LabelFollowedBy";
-        pProps[nPos++].Value <<= eLabelFollowedBy;
-        pProps[nPos].Name = "ListtabStopPosition";
-        pProps[nPos++].Value <<= nListtabStopPosition;
-        pProps[nPos].Name = "FirstLineIndent";
-        pProps[nPos++].Value <<= nFirstLineIndent;
-        pProps[nPos].Name = "IndentAt";
-        pProps[nPos++].Value <<= nIndentAt;
+    aProperties.push_back(comphelper::makePropertyValue("LabelFollowedBy", 
eLabelFollowedBy));
 
-        OUString sDisplayTextStyleName = GetImport().GetStyleDisplayName(
-                                XmlStyleFamily::TEXT_TEXT, sTextStyleName  );
-        pProps[nPos].Name = "CharStyleName";
-        pProps[nPos++].Value <<= sDisplayTextStyleName;
+    aProperties.push_back(comphelper::makePropertyValue("ListtabStopPosition", 
nListtabStopPosition));
 
-        if( bBullet )
-        {
-            awt::FontDescriptor aFDesc;
-            aFDesc.Name = sBulletFontName;
-            if( !sBulletFontName.isEmpty() )
-            {
-                aFDesc.StyleName = sBulletFontStyleName;
-                aFDesc.Family = eBulletFontFamily;
-                aFDesc.Pitch = eBulletFontPitch;
-                aFDesc.CharSet = eBulletFontEncoding;
-                aFDesc.Weight = WEIGHT_DONTKNOW;
-                bool bStarSymbol = false;
-                if( aFDesc.Name.equalsIgnoreAsciiCase( gsStarBats ) )
-                {
-                    cBullet = GetImport().ConvStarBatsCharToStarSymbol( 
cBullet );
-                    bStarSymbol = true;
-                }
-                else if( aFDesc.Name.equalsIgnoreAsciiCase( gsStarMath ) )
-                {
-                    cBullet = GetImport().ConvStarMathCharToStarSymbol( 
cBullet );
-                    bStarSymbol = true;
-                }
-                if( bStarSymbol )
-                    aFDesc.Name = "StarSymbol" ;
-            }
+    aProperties.push_back(comphelper::makePropertyValue("FirstLineIndent", 
nFirstLineIndent));
 
-            // Must append 'cBullet' even if it is zero
-            // if 'bBullet' is true and 'cBullet' is zero - BulletChar 
property must be 0.
-            pProps[nPos].Name = "BulletChar";
-            pProps[nPos++].Value <<= OUString(&cBullet, 1);
+    aProperties.push_back(comphelper::makePropertyValue("IndentAt", 
nIndentAt));
 
-            pProps[nPos].Name = "BulletFont";
-            pProps[nPos++].Value <<= aFDesc;
+    OUString sDisplayTextStyleName = 
GetImport().GetStyleDisplayName(XmlStyleFamily::TEXT_TEXT, sTextStyleName);
+    aProperties.push_back(comphelper::makePropertyValue("CharStyleName", 
sDisplayTextStyleName));
 
-        }
-
-        if( bImage )
+    if( bBullet )
+    {
+        awt::FontDescriptor aFDesc;
+        aFDesc.Name = sBulletFontName;
+        if( !sBulletFontName.isEmpty() )
         {
-            uno::Reference<graphic::XGraphic> xGraphic;
-            if (!sImageURL.isEmpty())
-            {
-                xGraphic = GetImport().loadGraphicByURL(sImageURL);
-            }
-            else if( xBase64Stream.is() )
+            aFDesc.StyleName = sBulletFontStyleName;
+            aFDesc.Family = eBulletFontFamily;
+            aFDesc.Pitch = eBulletFontPitch;
+            aFDesc.CharSet = eBulletFontEncoding;
+            aFDesc.Weight = WEIGHT_DONTKNOW;
+            bool bStarSymbol = false;
+            if( aFDesc.Name.equalsIgnoreAsciiCase( gsStarBats ) )
             {
-                xGraphic = GetImport().loadGraphicFromBase64(xBase64Stream);
+                cBullet = GetImport().ConvStarBatsCharToStarSymbol( cBullet );
+                bStarSymbol = true;
             }
-
-            uno::Reference<awt::XBitmap> xBitmap;
-            if (xGraphic.is())
-                xBitmap.set(xGraphic, uno::UNO_QUERY);
-
-            if (xBitmap.is())
+            else if( aFDesc.Name.equalsIgnoreAsciiCase( gsStarMath ) )
             {
-                pProps[nPos].Name = "GraphicBitmap";
-                pProps[nPos++].Value <<= xBitmap;
+                cBullet = GetImport().ConvStarMathCharToStarSymbol( cBullet );
+                bStarSymbol = true;
             }
-
-            awt::Size aSize(nImageWidth, nImageHeight);
-            pProps[nPos].Name = "GraphicSize";
-            pProps[nPos++].Value <<= aSize;
-
-            pProps[nPos].Name = "VertOrient";
-            pProps[nPos++].Value <<= eImageVertOrient;
+            if( bStarSymbol )
+                aFDesc.Name = "StarSymbol" ;
         }
 
-        if( bNum )
-        {
-            pProps[nPos].Name = "StartWith";
-            pProps[nPos++].Value <<= nNumStartValue;
+        // Must append 'cBullet' even if it is zero
+        // if 'bBullet' is true and 'cBullet' is zero - BulletChar property 
must be 0.
+        aProperties.push_back(comphelper::makePropertyValue("BulletChar", 
OUString(&cBullet, 1)));
+        aProperties.push_back(comphelper::makePropertyValue("BulletFont", 
aFDesc));
+    }
 
-            pProps[nPos].Name = "ParentNumbering";
-            pProps[nPos++].Value <<= nNumDisplayLevels;
+    if( bImage )
+    {
+        uno::Reference<graphic::XGraphic> xGraphic;
+        if (!sImageURL.isEmpty())
+        {
+            xGraphic = GetImport().loadGraphicByURL(sImageURL);
         }
-
-        if( ( bNum || bBullet ) && nRelSize )
+        else if( xBase64Stream.is() )
         {
-            pProps[nPos].Name = "BulletRelSize";
-            pProps[nPos++].Value <<= nRelSize;
+            xGraphic = GetImport().loadGraphicFromBase64(xBase64Stream);
         }
 
-        if( !bImage && bHasColor )
+        uno::Reference<awt::XBitmap> xBitmap;
+        if (xGraphic.is())
+            xBitmap.set(xGraphic, uno::UNO_QUERY);
+
+        if (xBitmap.is())
         {
-            pProps[nPos].Name = "BulletColor";
-            pProps[nPos++].Value <<= m_nColor;
+            
aProperties.push_back(comphelper::makePropertyValue("GraphicBitmap", xBitmap));
         }
 
-        SAL_WARN_IF( nPos != nCount, "xmloff", "array under/overflow" );
+        awt::Size aSize(nImageWidth, nImageHeight);
+        aProperties.push_back(comphelper::makePropertyValue("GraphicSize", 
aSize));
+        aProperties.push_back(comphelper::makePropertyValue("VertOrient", 
eImageVertOrient));
+    }
+
+    if( bNum )
+    {
+        aProperties.push_back(comphelper::makePropertyValue("StartWith", 
nNumStartValue));
+        aProperties.push_back(comphelper::makePropertyValue("ParentNumbering", 
nNumDisplayLevels));
+    }
+
+    if( ( bNum || bBullet ) && nRelSize )
+    {
+        aProperties.push_back(comphelper::makePropertyValue("BulletRelSize", 
nRelSize));
+    }
+
+    if( !bImage && bHasColor )
+    {
+        aProperties.push_back(comphelper::makePropertyValue("BulletColor", 
m_nColor));
     }
 
-    return aPropSeq;
+    return comphelper::containerToSequence(aProperties);
 }
 
 SvxXMLListLevelStyleAttrContext_Impl::SvxXMLListLevelStyleAttrContext_Impl(
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to