Kaydet (Commit) 5d3b3b9f authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez Kaydeden (comit) Miklos Vajna

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