[Libreoffice-commits] core.git: sw/source

Jacobo Aragunde Pérez jaragunde at igalia.com
Mon Dec 23 06:38:37 PST 2013


 sw/source/filter/ww8/docxattributeoutput.cxx |  273 +++++++++++----------------
 sw/source/filter/ww8/docxattributeoutput.hxx |    3 
 2 files changed, 119 insertions(+), 157 deletions(-)

New commits:
commit 5d3b3b9fc15bac8bba286e64a6a0e28f2dbb8529
Author: Jacobo Aragunde Pérez <jaragunde at igalia.com>
Date:   Mon Dec 23 11:13:19 2013 +0100

    sw: small code refactor
    
    Created method DocxAttributeOutput::AddToAttrList which encapsulates
    a piece of code that was widely repeated in that class:
    
      if( some attribute list does not exist )
          create the list
    
      add some value to the list
      add some other value to the list
    
    Change-Id: Ibef031395927a7cedbf84a372008cb2e2677ae36
    Reviewed-on: https://gerrit.libreoffice.org/7187
    Reviewed-by: Jacobo Aragunde Pérez <jaragunde at igalia.com>
    Tested-by: Jacobo Aragunde Pérez <jaragunde at igalia.com>
    Tested-by: LibreOffice gerrit bot <gerrit at libreoffice.org>
    Reviewed-by: Miklos Vajna <vmiklos at collabora.co.uk>
    Tested-by: Miklos Vajna <vmiklos at collabora.co.uk>

diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 20cdf08..3a5c9d4 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -4314,10 +4314,7 @@ void DocxAttributeOutput::CharColor( const SvxColorItem& rColor )
 
     aColorString = msfilter::util::ConvertColor( aColor );
 
-    if( !m_pColorAttrList )
-        m_pColorAttrList = m_pSerializer->createAttrList();
-
-    m_pColorAttrList->add( FSNS( XML_w, XML_val ), aColorString.getStr() );
+    AddToAttrList( m_pColorAttrList, FSNS( XML_w, XML_val ), aColorString.getStr() );
 }
 
 void DocxAttributeOutput::CharContour( const SvxContourItem& rContour )
@@ -4386,13 +4383,12 @@ void DocxAttributeOutput::CharEscapement( const SvxEscapementItem& rEscapement )
 
 void DocxAttributeOutput::CharFont( const SvxFontItem& rFont)
 {
-    if (!m_pFontsAttrList)
-        m_pFontsAttrList = m_pSerializer->createAttrList();
     GetExport().GetId( rFont ); // ensure font info is written to fontTable.xml
     OUString sFontName(rFont.GetFamilyName());
     OString sFontNameUtf8 = OUStringToOString(sFontName, RTL_TEXTENCODING_UTF8);
-    m_pFontsAttrList->add(FSNS(XML_w, XML_ascii), sFontNameUtf8);
-    m_pFontsAttrList->add(FSNS(XML_w, XML_hAnsi), sFontNameUtf8);
+    AddToAttrList( m_pFontsAttrList, 2,
+            FSNS( XML_w, XML_ascii ), sFontNameUtf8.getStr(),
+            FSNS( XML_w, XML_hAnsi ), sFontNameUtf8.getStr() );
 }
 
 void DocxAttributeOutput::CharFontSize( const SvxFontHeightItem& rFontSize)
@@ -4419,9 +4415,6 @@ void DocxAttributeOutput::CharKerning( const SvxKerningItem& rKerning )
 
 void DocxAttributeOutput::CharLanguage( const SvxLanguageItem& rLanguage )
 {
-    if (!m_pCharLangAttrList)
-        m_pCharLangAttrList = m_pSerializer->createAttrList();
-
     OString aLanguageCode( OUStringToOString(
                 LanguageTag( rLanguage.GetLanguage()).getBcp47(),
                 RTL_TEXTENCODING_UTF8));
@@ -4429,13 +4422,13 @@ void DocxAttributeOutput::CharLanguage( const SvxLanguageItem& rLanguage )
     switch ( rLanguage.Which() )
     {
         case RES_CHRATR_LANGUAGE:
-            m_pCharLangAttrList->add(FSNS(XML_w, XML_val), aLanguageCode);
+            AddToAttrList( m_pCharLangAttrList, FSNS( XML_w, XML_val ), aLanguageCode.getStr() );
             break;
         case RES_CHRATR_CJK_LANGUAGE:
-            m_pCharLangAttrList->add(FSNS(XML_w, XML_eastAsia), aLanguageCode);
+            AddToAttrList( m_pCharLangAttrList, FSNS( XML_w, XML_eastAsia ), aLanguageCode.getStr() );
             break;
         case RES_CHRATR_CTL_LANGUAGE:
-            m_pCharLangAttrList->add(FSNS(XML_w, XML_bidi), aLanguageCode);
+            AddToAttrList( m_pCharLangAttrList, FSNS( XML_w, XML_bidi ), aLanguageCode.getStr() );
             break;
     }
 }
@@ -4546,11 +4539,9 @@ void DocxAttributeOutput::CharBackground( const SvxBrushItem& rBrush )
 
 void DocxAttributeOutput::CharFontCJK( const SvxFontItem& rFont )
 {
-    if (!m_pFontsAttrList)
-        m_pFontsAttrList = m_pSerializer->createAttrList();
     OUString sFontName(rFont.GetFamilyName());
     OString sFontNameUtf8 = OUStringToOString(sFontName, RTL_TEXTENCODING_UTF8);
-    m_pFontsAttrList->add(FSNS(XML_w, XML_eastAsia), sFontNameUtf8);
+    AddToAttrList( m_pFontsAttrList, FSNS( XML_w, XML_eastAsia ), sFontNameUtf8.getStr() );
 }
 
 void DocxAttributeOutput::CharPostureCJK( const SvxPostureItem& rPosture )
@@ -4571,11 +4562,9 @@ void DocxAttributeOutput::CharWeightCJK( const SvxWeightItem& rWeight )
 
 void DocxAttributeOutput::CharFontCTL( const SvxFontItem& rFont )
 {
-    if (!m_pFontsAttrList)
-        m_pFontsAttrList = m_pSerializer->createAttrList();
     OUString sFontName(rFont.GetFamilyName());
     OString sFontNameUtf8 = OUStringToOString(sFontName, RTL_TEXTENCODING_UTF8);
-    m_pFontsAttrList->add(FSNS(XML_w, XML_cs), sFontNameUtf8);
+    AddToAttrList( m_pFontsAttrList, FSNS( XML_w, XML_cs ), sFontNameUtf8.getStr() );
 
 }
 
@@ -4601,13 +4590,10 @@ void DocxAttributeOutput::CharRotate( const SvxCharRotateItem& rRotate)
     if ( !rRotate.GetValue() || m_bBtLr || m_bFrameBtLr)
         return;
 
-    if (!m_pEastAsianLayoutAttrList)
-        m_pEastAsianLayoutAttrList = m_pSerializer->createAttrList();
-    OString sTrue((sal_Char *)"true");
-    m_pEastAsianLayoutAttrList->add(FSNS(XML_w, XML_vert), sTrue);
+    AddToAttrList( m_pEastAsianLayoutAttrList, FSNS( XML_w, XML_vert ), "true" );
 
     if (rRotate.IsFitToLine())
-        m_pEastAsianLayoutAttrList->add(FSNS(XML_w, XML_vertCompress), sTrue);
+        AddToAttrList( m_pEastAsianLayoutAttrList, FSNS( XML_w, XML_vertCompress ), "true" );
 }
 
 void DocxAttributeOutput::CharEmphasisMark( const SvxEmphasisMarkItem& rEmphasisMark )
@@ -4631,10 +4617,7 @@ void DocxAttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines )
     if ( !rTwoLines.GetValue() )
         return;
 
-    if (!m_pEastAsianLayoutAttrList)
-        m_pEastAsianLayoutAttrList = m_pSerializer->createAttrList();
-    OString sTrue((sal_Char *)"true");
-    m_pEastAsianLayoutAttrList->add(FSNS(XML_w, XML_combine), sTrue);
+    AddToAttrList( m_pEastAsianLayoutAttrList, FSNS( XML_w, XML_combine ), "true" );
 
     sal_Unicode cStart = rTwoLines.GetStartBracket();
     sal_Unicode cEnd = rTwoLines.GetEndBracket();
@@ -4651,7 +4634,7 @@ void DocxAttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines )
         sBracket = (sal_Char *)"square";
     else
         sBracket = (sal_Char *)"round";
-    m_pEastAsianLayoutAttrList->add(FSNS(XML_w, XML_combineBrackets), sBracket);
+    AddToAttrList( m_pEastAsianLayoutAttrList, FSNS( XML_w, XML_combineBrackets ), sBracket.getStr() );
 }
 
 void DocxAttributeOutput::CharScaleWidth( const SvxCharScaleWidthItem& rScaleWidth )
@@ -5078,26 +5061,26 @@ void DocxAttributeOutput::SectFootnoteEndnotePr()
 
 void DocxAttributeOutput::ParaLineSpacing_Impl( short nSpace, short nMulti )
 {
-    if ( !m_pParagraphSpacingAttrList )
-        m_pParagraphSpacingAttrList = m_pSerializer->createAttrList();
-
     if ( nSpace < 0 )
     {
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_lineRule ), "exact" );
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_line ), OString::number( -nSpace ) );
+        AddToAttrList( m_pParagraphSpacingAttrList, 2,
+                FSNS( XML_w, XML_lineRule ), "exact",
+                FSNS( XML_w, XML_line ), OString::number( -nSpace ).getStr() );
     }
     else if( nMulti )
     {
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_lineRule ), "auto" );
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_line ), OString::number( nSpace ) );
+        AddToAttrList( m_pParagraphSpacingAttrList, 2,
+                FSNS( XML_w, XML_lineRule ), "auto",
+                FSNS( XML_w, XML_line ), OString::number( nSpace ).getStr() );
     }
     else if ( nSpace > 0 )
     {
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_lineRule ), "atLeast" );
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_line ), OString::number( nSpace ) );
+        AddToAttrList( m_pParagraphSpacingAttrList, 2,
+                FSNS( XML_w, XML_lineRule ), "atLeast",
+                FSNS( XML_w, XML_line ), OString::number( nSpace ).getStr() );
     }
     else
-        m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_lineRule ), "auto" );
+        AddToAttrList( m_pParagraphSpacingAttrList, FSNS( XML_w, XML_lineRule ), "auto" );
 }
 
 void DocxAttributeOutput::ParaAdjust( const SvxAdjustItem& rAdjust )
@@ -5331,21 +5314,18 @@ void DocxAttributeOutput::FormatFrameSize( const SwFmtFrmSize& rSize )
     }
     else if ( m_rExport.bOutFlyFrmAttrs )
     {
-        if ( !m_pFlyAttrList )
-            m_pFlyAttrList = m_pSerializer->createAttrList( );
-
         if ( rSize.GetWidth() && rSize.GetWidthSizeType() == ATT_FIX_SIZE )
-        {
-            m_pFlyAttrList->add( FSNS( XML_w, XML_w ), OString::number( rSize.GetWidth( ) ) );
-        }
+            AddToAttrList( m_pFlyAttrList,
+                    FSNS( XML_w, XML_w ), OString::number( rSize.GetWidth( ) ).getStr() );
 
         if ( rSize.GetHeight() )
         {
             OString sRule( "exact" );
             if ( rSize.GetHeightSizeType() == ATT_MIN_SIZE )
                 sRule = OString( "atLeast" );
-            m_pFlyAttrList->add( FSNS( XML_w, XML_hRule ), sRule );
-            m_pFlyAttrList->add( FSNS( XML_w, XML_h ), OString::number( rSize.GetHeight( ) ) );
+            AddToAttrList( m_pFlyAttrList, 2,
+                    FSNS( XML_w, XML_hRule ), sRule.getStr(),
+                    FSNS( XML_w, XML_h ), OString::number( rSize.GetHeight( ) ).getStr() );
         }
     }
     else if ( m_rExport.bOutPageDescs )
@@ -5383,18 +5363,12 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace )
     }
     else if ( m_rExport.bOutFlyFrmAttrs )
     {
-        if ( !m_pFlyAttrList )
-            m_pFlyAttrList = m_pSerializer->createAttrList();
-
-        m_pFlyAttrList->add( FSNS( XML_w, XML_hSpace ),
+        AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_hSpace ),
                 OString::number(
-                    ( rLRSpace.GetLeft() + rLRSpace.GetRight() ) / 2 ) );
+                    ( rLRSpace.GetLeft() + rLRSpace.GetRight() ) / 2 ).getStr() );
     }
     else if ( m_rExport.bOutPageDescs )
     {
-        if ( !m_pSectionSpacingAttrList )
-            m_pSectionSpacingAttrList = m_pSerializer->createAttrList();
-
         m_pageMargins.nPageMarginLeft = 0;
         m_pageMargins.nPageMarginRight = 0;
 
@@ -5410,8 +5384,9 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace )
         m_pageMargins.nPageMarginLeft = m_pageMargins.nPageMarginLeft + (sal_uInt16)rLRSpace.GetLeft();
         m_pageMargins.nPageMarginRight = m_pageMargins.nPageMarginRight + (sal_uInt16)rLRSpace.GetRight();
 
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_left ), OString::number( m_pageMargins.nPageMarginLeft ) );
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_right ), OString::number( m_pageMargins.nPageMarginRight ) );
+        AddToAttrList( m_pSectionSpacingAttrList, 2,
+                FSNS( XML_w, XML_left ), OString::number( m_pageMargins.nPageMarginLeft ).getStr(),
+                FSNS( XML_w, XML_right ), OString::number( m_pageMargins.nPageMarginRight ).getStr() );
     }
     else
     {
@@ -5442,12 +5417,9 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace )
     }
     else if ( m_rExport.bOutFlyFrmAttrs )
     {
-        if ( !m_pFlyAttrList )
-            m_pFlyAttrList = m_pSerializer->createAttrList();
-
-        m_pFlyAttrList->add( FSNS( XML_w, XML_vSpace ),
+        AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_vSpace ),
                 OString::number(
-                    ( rULSpace.GetLower() + rULSpace.GetUpper() ) / 2 ) );
+                    ( rULSpace.GetLower() + rULSpace.GetUpper() ) / 2 ).getStr() );
     }
     else if (m_rExport.bOutPageDescs )
     {
@@ -5455,64 +5427,57 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace )
         if ( !m_rExport.GetCurItemSet() )
             return;
 
-        if ( !m_pSectionSpacingAttrList )
-            m_pSectionSpacingAttrList = m_pSerializer->createAttrList();
-
         HdFtDistanceGlue aDistances( *m_rExport.GetCurItemSet() );
 
         sal_Int32 nHeader = 0;
         if ( aDistances.HasHeader() )
             nHeader = sal_Int32( aDistances.dyaHdrTop );
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_header ), OString::number( nHeader ) );
 
         // Page top
         m_pageMargins.nPageMarginTop = aDistances.dyaTop;
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_top ),
-                OString::number( m_pageMargins.nPageMarginTop ) );
 
         sal_Int32 nFooter = 0;
         if ( aDistances.HasFooter() )
             nFooter = sal_Int32( aDistances.dyaHdrBottom );
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_footer ), OString::number( nFooter ) );
 
         // Page Bottom
         m_pageMargins.nPageMarginBottom = aDistances.dyaBottom;
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_bottom ),
-                OString::number( m_pageMargins.nPageMarginBottom ) );
 
-        // FIXME Page Gutter is not handled ATM, setting to 0 as it's mandatory for OOXML
-        m_pSectionSpacingAttrList->add( FSNS( XML_w, XML_gutter ),
-                OString::number( 0 ) );
+        AddToAttrList( m_pSectionSpacingAttrList, 5,
+                FSNS( XML_w, XML_header ), OString::number( nHeader ).getStr(),
+                FSNS( XML_w, XML_top ), OString::number( m_pageMargins.nPageMarginTop ).getStr(),
+                FSNS( XML_w, XML_footer ), OString::number( nFooter ).getStr(),
+                FSNS( XML_w, XML_bottom ), OString::number( m_pageMargins.nPageMarginBottom ).getStr(),
+                // FIXME Page Gutter is not handled ATM, setting to 0 as it's mandatory for OOXML
+                FSNS( XML_w, XML_gutter ), "0" );
     }
     else
     {
-        if ( !m_pParagraphSpacingAttrList )
-            m_pParagraphSpacingAttrList = m_pSerializer->createAttrList();
         SAL_INFO("sw.ww8", "DocxAttributeOutput::FormatULSpace: setting spacing" << rULSpace.GetUpper() );
         // check if before auto spacing was set during import and spacing we get from actual object is same
         // that we set in import. If yes just write beforeAutoSpacing tag.
         if (m_bParaBeforeAutoSpacing && m_nParaBeforeSpacing == rULSpace.GetUpper())
         {
-            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_beforeAutospacing ),
-                    "1" );
+            AddToAttrList( m_pParagraphSpacingAttrList,
+                    FSNS( XML_w, XML_beforeAutospacing ), "1" );
         }
         else
         {
-            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_before ),
-                    OString::number( rULSpace.GetUpper() ) );
+            AddToAttrList( m_pParagraphSpacingAttrList,
+                    FSNS( XML_w, XML_before ), OString::number( rULSpace.GetUpper() ).getStr() );
         }
         m_bParaBeforeAutoSpacing = false;
         // check if after auto spacing was set during import and spacing we get from actual object is same
         // that we set in import. If yes just write afterAutoSpacing tag.
         if (m_bParaAfterAutoSpacing && m_nParaAfterSpacing == rULSpace.GetLower())
         {
-            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_afterAutospacing ),
-                    "1" );
+            AddToAttrList( m_pParagraphSpacingAttrList,
+                    FSNS( XML_w, XML_afterAutospacing ), "1" );
         }
         else
         {
-            m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_after ),
-                    OString::number( rULSpace.GetLower()) );
+            AddToAttrList( m_pParagraphSpacingAttrList,
+                    FSNS( XML_w, XML_after ), OString::number( rULSpace.GetLower()).getStr() );
         }
         m_bParaAfterAutoSpacing = false;
 
@@ -5565,9 +5530,6 @@ void DocxAttributeOutput::FormatSurround( const SwFmtSurround& rSurround )
     }
     else if ( m_rExport.bOutFlyFrmAttrs )
     {
-        if ( !m_pFlyAttrList )
-            m_pFlyAttrList = m_pSerializer->createAttrList();
-
         OString sWrap( "auto" );
         switch ( rSurround.GetSurround( ) )
         {
@@ -5585,7 +5547,7 @@ void DocxAttributeOutput::FormatSurround( const SwFmtSurround& rSurround )
                 sWrap = OString( "around" );
         }
 
-        m_pFlyAttrList->add( FSNS( XML_w, XML_wrap ), sWrap );
+        AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_wrap ), sWrap.getStr() );
     }
 }
 
@@ -5600,9 +5562,6 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert
     }
     else if ( m_rExport.bOutFlyFrmAttrs )
     {
-        if ( !m_pFlyAttrList )
-            m_pFlyAttrList = m_pSerializer->createAttrList();
-
         OString sAlign;
         switch( rFlyVert.GetVertOrient() )
         {
@@ -5624,10 +5583,10 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert
         }
 
         if ( !sAlign.isEmpty() )
-            m_pFlyAttrList->add( FSNS( XML_w, XML_yAlign ), sAlign );
+            AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_yAlign ), sAlign.getStr() );
         else
-            m_pFlyAttrList->add( FSNS( XML_w, XML_y ),
-                OString::number( rFlyVert.GetPos() ) );
+            AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_y ),
+                OString::number( rFlyVert.GetPos() ).getStr() );
 
         OString sVAnchor( "page" );
         switch ( rFlyVert.GetRelationOrient( ) )
@@ -5650,7 +5609,7 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert
                 break;
         }
 
-        m_pFlyAttrList->add( FSNS( XML_w, XML_vAnchor ), sVAnchor );
+        AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_vAnchor ), sVAnchor.getStr() );
     }
 }
 
@@ -5665,9 +5624,6 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor
     }
     else if ( m_rExport.bOutFlyFrmAttrs )
     {
-        if ( !m_pFlyAttrList )
-            m_pFlyAttrList = m_pSerializer->createAttrList();
-
         OString sAlign;
         switch( rFlyHori.GetHoriOrient() )
         {
@@ -5687,10 +5643,10 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor
         }
 
         if ( !sAlign.isEmpty() )
-            m_pFlyAttrList->add( FSNS( XML_w, XML_xAlign ), sAlign );
+            AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_xAlign ), sAlign.getStr() );
         else
-            m_pFlyAttrList->add( FSNS( XML_w, XML_x ),
-                OString::number( rFlyHori.GetPos() ) );
+            AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_x ),
+                OString::number( rFlyHori.GetPos() ).getStr() );
 
         OString sHAnchor( "page" );
         switch ( rFlyHori.GetRelationOrient( ) )
@@ -5712,7 +5668,7 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor
                 break;
         }
 
-        m_pFlyAttrList->add( FSNS( XML_w, XML_hAnchor ), sHAnchor );
+        AddToAttrList( m_pFlyAttrList, FSNS( XML_w, XML_hAnchor ), sHAnchor.getStr() );
     }
 }
 
@@ -5750,15 +5706,13 @@ void DocxAttributeOutput::FormatBackground( const SvxBrushItem& rBrush )
             // Calculate opacity value
             // Consider oox/source/vml/vmlformatting.cxx : decodeColor() function.
             double fOpacity = (double)(*oAlpha) * 65535 / ::oox::drawingml::MAX_PERCENT;
-            OUString sOpacity = OUString::number(fOpacity);
-
-            if ( !m_pFlyFillAttrList )
-                m_pFlyFillAttrList = m_pSerializer->createAttrList();
+            OUString sOpacity = OUString::number(fOpacity) + "f";
 
-            m_pFlyFillAttrList->add(XML_opacity, OUStringToOString(sOpacity, RTL_TEXTENCODING_UTF8) + "f");
+            AddToAttrList( m_pFlyFillAttrList, XML_opacity, OUStringToOString(sOpacity, RTL_TEXTENCODING_UTF8).getStr() );
         }
 
-        m_pFlyAttrList->add(XML_fillcolor, "#" + sColor);
+        sColor = "#" + sColor;
+        AddToAttrList( m_pFlyAttrList, XML_fillcolor, sColor.getStr() );
     }
     else if (m_bDMLTextFrameSyntax)
     {
@@ -5808,10 +5762,7 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad
 {
     if (m_oFillStyle && *m_oFillStyle == XFILL_GRADIENT && !m_bDMLTextFrameSyntax)
     {
-        if ( !m_pFlyFillAttrList )
-            m_pFlyFillAttrList = m_pSerializer->createAttrList();
-
-        m_pFlyFillAttrList->add(XML_type, "gradient");
+        AddToAttrList( m_pFlyFillAttrList, XML_type, "gradient" );
 
         const XGradient& rGradient = rFillGradient.GetGradientValue();
         OString sStartColor = msfilter::util::ConvertColor(rGradient.GetStartColor());
@@ -5826,7 +5777,8 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad
         nReverseAngle = nReverseAngle / 10;
         nReverseAngle = (270 - nReverseAngle) % 360;
         if (nReverseAngle != 0)
-            m_pFlyFillAttrList->add(XML_angle, OString::number(nReverseAngle));
+            AddToAttrList( m_pFlyFillAttrList,
+                    XML_angle, OString::number( nReverseAngle ).getStr() );
 
         OString sColor1 = sStartColor;
         OString sColor2 = sEndColor;
@@ -5834,7 +5786,7 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad
         switch (rGradient.GetGradientStyle())
         {
             case XGRAD_AXIAL:
-                m_pFlyFillAttrList->add(XML_focus, "50%");
+                AddToAttrList( m_pFlyFillAttrList, XML_focus, "50%" );
                 // If it is an 'axial' gradient - swap the colors
                 // (because in the import process they were imported swapped)
                 sColor1 = sEndColor;
@@ -5847,8 +5799,10 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad
             case XGRAD_RECT: break;
         }
 
-        m_pFlyAttrList->add(XML_fillcolor , "#" + sColor1);
-        m_pFlyFillAttrList->add(XML_color2, "#" + sColor2);
+        sColor1 = "#" + sColor1;
+        sColor2 = "#" + sColor2;
+        AddToAttrList( m_pFlyAttrList, XML_fillcolor, sColor1.getStr() );
+        AddToAttrList( m_pFlyFillAttrList, XML_color2, sColor2.getStr() );
     }
     else if (m_oFillStyle && *m_oFillStyle == XFILL_GRADIENT && m_bDMLTextFrameSyntax)
     {
@@ -5895,8 +5849,8 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox )
             {
                 if (m_bTextFrameSyntax)
                 {
-                    m_pFlyAttrList->add(XML_stroked, "f");
-                    m_pFlyAttrList->add(XML_strokeweight, "0pt");
+                    AddToAttrList( m_pFlyAttrList, 2,
+                            XML_stroked, "f", XML_strokeweight, "0pt" );
                 }
             }
             else
@@ -5907,15 +5861,17 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox )
                 if (m_bTextFrameSyntax)
                 {
                     sColor = "#" + sColor;
-                    m_pFlyAttrList->add(XML_strokecolor, sColor);
                     sal_Int32 nWidth = sal_Int32(fConverted / 20);
-                    m_pFlyAttrList->add(XML_strokeweight, OString::number(nWidth) + "pt");
+                    OString sWidth = OString::number(nWidth) + "pt";
+                    AddToAttrList( m_pFlyAttrList, 2,
+                            XML_strokecolor, sColor.getStr(),
+                            XML_strokeweight, sWidth.getStr() );
                 }
                 else
                 {
-                    OString aWidth(OString::number(TwipsToEMU(fConverted)));
+                    OString sWidth(OString::number(TwipsToEMU(fConverted)));
                     m_pSerializer->startElementNS(XML_a, XML_ln,
-                            XML_w, aWidth.getStr(),
+                            XML_w, sWidth.getStr(),
                             FSEND);
                     m_pSerializer->startElementNS(XML_a, XML_solidFill, FSEND);
                     m_pSerializer->singleElementNS(XML_a, XML_srgbClr,
@@ -6168,14 +6124,9 @@ void DocxAttributeOutput::ParaGrabBag(const SfxGrabBagItem& rItem)
                 else if (aGrabBagSeq[j].Name == "fill")
                     aGrabBagSeq[j].Value >>= sOriginalFill;
             }
-
-            if (!m_pBackgroundAttrList)
-                m_pBackgroundAttrList = m_pSerializer->createAttrList();
-
-            m_pBackgroundAttrList->add(FSNS(XML_w, XML_themeFill),
-                                       OUStringToOString(sThemeFill, RTL_TEXTENCODING_UTF8));
-            m_pBackgroundAttrList->add(FSNS(XML_w, XML_fill),
-                                       OUStringToOString(sOriginalFill, RTL_TEXTENCODING_UTF8));
+            AddToAttrList(m_pBackgroundAttrList, 2,
+                    FSNS(XML_w, XML_themeFill), OUStringToOString(sThemeFill, RTL_TEXTENCODING_UTF8).getStr(),
+                    FSNS(XML_w, XML_fill), OUStringToOString(sOriginalFill, RTL_TEXTENCODING_UTF8).getStr());
         }
         else
             SAL_INFO("sw.ww8", "DocxAttributeOutput::ParaGrabBag: unhandled grab bag property " << i->first );
@@ -6227,54 +6178,40 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem )
         if ( i->first == "CharThemeNameAscii" && bWriteAsciiTheme )
         {
             i->second >>= str;
-            if (!m_pFontsAttrList)
-                m_pFontsAttrList = m_pSerializer->createAttrList();
-            m_pFontsAttrList->add( FSNS( XML_w, XML_asciiTheme ),
-                                   OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+            AddToAttrList( m_pFontsAttrList, FSNS( XML_w, XML_asciiTheme ),
+                    OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
         else if ( i->first == "CharThemeNameCs" && bWriteCSTheme )
         {
             i->second >>= str;
-            if (!m_pFontsAttrList)
-                m_pFontsAttrList = m_pSerializer->createAttrList();
-            m_pFontsAttrList->add( FSNS( XML_w, XML_cstheme ),
-                                   OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+            AddToAttrList( m_pFontsAttrList, FSNS( XML_w, XML_cstheme ),
+                    OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
         else if ( i->first == "CharThemeNameEastAsia" && bWriteEastAsiaTheme )
         {
             i->second >>= str;
-            if (!m_pFontsAttrList)
-                m_pFontsAttrList = m_pSerializer->createAttrList();
-            m_pFontsAttrList->add( FSNS( XML_w, XML_eastAsiaTheme ),
-                                   OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+            AddToAttrList( m_pFontsAttrList, FSNS( XML_w, XML_eastAsiaTheme ),
+                    OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
         else if ( i->first == "CharThemeNameHAnsi" && bWriteAsciiTheme )
         // this is not a mistake: in LibO we don't directly support the hAnsi family
         // of attributes so we save the same value from ascii attributes instead
         {
             i->second >>= str;
-            if (!m_pFontsAttrList)
-                m_pFontsAttrList = m_pSerializer->createAttrList();
-            m_pFontsAttrList->add( FSNS( XML_w, XML_hAnsiTheme ),
-                                   OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+            AddToAttrList( m_pFontsAttrList, FSNS( XML_w, XML_hAnsiTheme ),
+                    OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
         else if ( i->first == "CharThemeColor" && bWriteThemeFontColor )
         {
             i->second >>= str;
-            if( !m_pColorAttrList )
-                m_pColorAttrList = m_pSerializer->createAttrList();
-
-            m_pColorAttrList->add( FSNS( XML_w, XML_themeColor ),
-                                   OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+            AddToAttrList( m_pColorAttrList, FSNS( XML_w, XML_themeColor ),
+                    OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
         else if ( i->first == "CharThemeColorShade" )
         {
             i->second >>= str;
-            if( !m_pColorAttrList )
-                m_pColorAttrList = m_pSerializer->createAttrList();
-
-            m_pColorAttrList->add( FSNS( XML_w, XML_themeShade ),
-                                   OUStringToOString( str, RTL_TEXTENCODING_UTF8 ) );
+            AddToAttrList( m_pColorAttrList, FSNS( XML_w, XML_themeShade ),
+                    OUStringToOString( str, RTL_TEXTENCODING_UTF8 ).getStr() );
         }
         else if( i->first == "CharThemeFontNameCs"   ||
                 i->first == "CharThemeFontNameAscii" ||
@@ -6426,4 +6363,26 @@ void DocxAttributeOutput::BulletDefinition(int nId, const Graphic& rGraphic, Siz
     m_pSerializer->endElementNS(XML_w, XML_numPicBullet);
 }
 
+void DocxAttributeOutput::AddToAttrList( ::sax_fastparser::FastAttributeList* &pAttrList, sal_Int32 nAttrName, const sal_Char* sAttrValue )
+{
+    AddToAttrList( pAttrList, 1, nAttrName, sAttrValue );
+}
+
+void DocxAttributeOutput::AddToAttrList( ::sax_fastparser::FastAttributeList* &pAttrList, sal_Int32 nAttrs, ... )
+{
+    if( !pAttrList )
+        pAttrList = m_pSerializer->createAttrList();
+
+    va_list args;
+    va_start( args, nAttrs );
+    for( sal_Int32 i = 0; i<nAttrs; i++)
+    {
+        sal_Int32 nName = va_arg( args, sal_Int32 );
+        const char* pValue = va_arg( args, const char* );
+        if( pValue )
+            pAttrList->add( nName, pValue );
+    }
+    va_end( args );
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx
index fb75459..9ccbc52 100644
--- a/sw/source/filter/ww8/docxattributeoutput.hxx
+++ b/sw/source/filter/ww8/docxattributeoutput.hxx
@@ -672,6 +672,9 @@ private:
     void CmdField_Impl( FieldInfos& rInfos );
     void EndField_Impl( FieldInfos& rInfos );
 
+    void AddToAttrList( ::sax_fastparser::FastAttributeList* &pAttrList, sal_Int32 nAttrName, const sal_Char* sAttrValue );
+    void AddToAttrList( ::sax_fastparser::FastAttributeList* &pAttrList, sal_Int32 nArgs, ... );
+
     ::sax_fastparser::FastAttributeList *m_pFontsAttrList, *m_pEastAsianLayoutAttrList;
     ::sax_fastparser::FastAttributeList *m_pCharLangAttrList;
     ::sax_fastparser::FastAttributeList *m_pSectionSpacingAttrList;


More information about the Libreoffice-commits mailing list