Kaydet (Commit) 7b073527 authored tarafından Jacobo Aragunde Pérez's avatar Jacobo Aragunde Pérez

sw: small code refactor

Created method DocxAttributeOutput::pushToAttrList which encapsulates
a piece of code that was widely repeated in that class:

  if( some attribute list does not exist )
      create the list

  push some value to the list
  push some other value to the list

Change-Id: Ia648802f5237bd7c97bf225d33b305dbef1b72dd
üst 1d18297e
...@@ -4308,10 +4308,7 @@ void DocxAttributeOutput::CharColor( const SvxColorItem& rColor ) ...@@ -4308,10 +4308,7 @@ void DocxAttributeOutput::CharColor( const SvxColorItem& rColor )
aColorString = msfilter::util::ConvertColor( aColor ); aColorString = msfilter::util::ConvertColor( aColor );
if( !m_pColorAttrList ) pushToAttrList( &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 )
...@@ -4380,13 +4377,12 @@ void DocxAttributeOutput::CharEscapement( const SvxEscapementItem& rEscapement ) ...@@ -4380,13 +4377,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); pushToAttrList(&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)
...@@ -4413,9 +4409,6 @@ void DocxAttributeOutput::CharKerning( const SvxKerningItem& rKerning ) ...@@ -4413,9 +4409,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));
...@@ -4423,13 +4416,13 @@ void DocxAttributeOutput::CharLanguage( const SvxLanguageItem& rLanguage ) ...@@ -4423,13 +4416,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); pushToAttrList(&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); pushToAttrList(&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); pushToAttrList(&m_pCharLangAttrList, FSNS(XML_w, XML_bidi), aLanguageCode.getStr());
break; break;
} }
} }
...@@ -4540,11 +4533,9 @@ void DocxAttributeOutput::CharBackground( const SvxBrushItem& rBrush ) ...@@ -4540,11 +4533,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); pushToAttrList(&m_pFontsAttrList, FSNS(XML_w, XML_eastAsia), sFontNameUtf8.getStr());
} }
void DocxAttributeOutput::CharPostureCJK( const SvxPostureItem& rPosture ) void DocxAttributeOutput::CharPostureCJK( const SvxPostureItem& rPosture )
...@@ -4565,11 +4556,9 @@ void DocxAttributeOutput::CharWeightCJK( const SvxWeightItem& rWeight ) ...@@ -4565,11 +4556,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); pushToAttrList(&m_pFontsAttrList, FSNS(XML_w, XML_cs), sFontNameUtf8.getStr());
} }
...@@ -4595,13 +4584,10 @@ void DocxAttributeOutput::CharRotate( const SvxCharRotateItem& rRotate) ...@@ -4595,13 +4584,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) pushToAttrList(&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); pushToAttrList(&m_pEastAsianLayoutAttrList, FSNS(XML_w, XML_vertCompress), "true");
} }
void DocxAttributeOutput::CharEmphasisMark( const SvxEmphasisMarkItem& rEmphasisMark ) void DocxAttributeOutput::CharEmphasisMark( const SvxEmphasisMarkItem& rEmphasisMark )
...@@ -4625,10 +4611,7 @@ void DocxAttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines ) ...@@ -4625,10 +4611,7 @@ void DocxAttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines )
if ( !rTwoLines.GetValue() ) if ( !rTwoLines.GetValue() )
return; return;
if (!m_pEastAsianLayoutAttrList) pushToAttrList(&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();
...@@ -4645,7 +4628,7 @@ void DocxAttributeOutput::CharTwoLines( const SvxTwoLinesItem& rTwoLines ) ...@@ -4645,7 +4628,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); pushToAttrList(&m_pEastAsianLayoutAttrList, FSNS(XML_w, XML_combineBrackets), sBracket.getStr());
} }
void DocxAttributeOutput::CharScaleWidth( const SvxCharScaleWidthItem& rScaleWidth ) void DocxAttributeOutput::CharScaleWidth( const SvxCharScaleWidthItem& rScaleWidth )
...@@ -5072,26 +5055,26 @@ void DocxAttributeOutput::SectFootnoteEndnotePr() ...@@ -5072,26 +5055,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" ); pushToAttrList( &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" ); pushToAttrList( &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" ); pushToAttrList( &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" ); pushToAttrList( &m_pParagraphSpacingAttrList, FSNS( XML_w, XML_lineRule ), "auto" );
} }
void DocxAttributeOutput::ParaAdjust( const SvxAdjustItem& rAdjust ) void DocxAttributeOutput::ParaAdjust( const SvxAdjustItem& rAdjust )
...@@ -5325,21 +5308,18 @@ void DocxAttributeOutput::FormatFrameSize( const SwFmtFrmSize& rSize ) ...@@ -5325,21 +5308,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 )
{ pushToAttrList( &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 ); pushToAttrList( &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 )
...@@ -5377,18 +5357,12 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace ) ...@@ -5377,18 +5357,12 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace )
} }
else if ( m_rExport.bOutFlyFrmAttrs ) else if ( m_rExport.bOutFlyFrmAttrs )
{ {
if ( !m_pFlyAttrList ) pushToAttrList( &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;
...@@ -5404,8 +5378,9 @@ void DocxAttributeOutput::FormatLRSpace( const SvxLRSpaceItem& rLRSpace ) ...@@ -5404,8 +5378,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 ) ); pushToAttrList( &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
{ {
...@@ -5436,12 +5411,9 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace ) ...@@ -5436,12 +5411,9 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace )
} }
else if ( m_rExport.bOutFlyFrmAttrs ) else if ( m_rExport.bOutFlyFrmAttrs )
{ {
if ( !m_pFlyAttrList ) pushToAttrList( &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 )
{ {
...@@ -5449,64 +5421,57 @@ void DocxAttributeOutput::FormatULSpace( const SvxULSpaceItem& rULSpace ) ...@@ -5449,64 +5421,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 pushToAttrList( &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 ), pushToAttrList( &m_pParagraphSpacingAttrList,
"1" ); FSNS( XML_w, XML_beforeAutospacing ), "1" );
} }
else else
{ {
m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_before ), pushToAttrList( &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 ), pushToAttrList( &m_pParagraphSpacingAttrList,
"1" ); FSNS( XML_w, XML_afterAutospacing ), "1" );
} }
else else
{ {
m_pParagraphSpacingAttrList->add( FSNS( XML_w, XML_after ), pushToAttrList( &m_pParagraphSpacingAttrList,
OString::number( rULSpace.GetLower()) ); FSNS( XML_w, XML_after ), OString::number( rULSpace.GetLower()).getStr() );
} }
m_bParaAfterAutoSpacing = false; m_bParaAfterAutoSpacing = false;
...@@ -5559,9 +5524,6 @@ void DocxAttributeOutput::FormatSurround( const SwFmtSurround& rSurround ) ...@@ -5559,9 +5524,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( ) )
{ {
...@@ -5579,7 +5541,7 @@ void DocxAttributeOutput::FormatSurround( const SwFmtSurround& rSurround ) ...@@ -5579,7 +5541,7 @@ void DocxAttributeOutput::FormatSurround( const SwFmtSurround& rSurround )
sWrap = OString( "around" ); sWrap = OString( "around" );
} }
m_pFlyAttrList->add( FSNS( XML_w, XML_wrap ), sWrap ); pushToAttrList(&m_pFlyAttrList, FSNS( XML_w, XML_wrap ), sWrap.getStr() );
} }
} }
...@@ -5594,9 +5556,6 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert ...@@ -5594,9 +5556,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() )
{ {
...@@ -5618,10 +5577,10 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert ...@@ -5618,10 +5577,10 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert
} }
if ( !sAlign.isEmpty() ) if ( !sAlign.isEmpty() )
m_pFlyAttrList->add( FSNS( XML_w, XML_yAlign ), sAlign ); pushToAttrList( &m_pFlyAttrList, FSNS( XML_w, XML_yAlign ), sAlign.getStr() );
else else
m_pFlyAttrList->add( FSNS( XML_w, XML_y ), pushToAttrList( &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( ) )
...@@ -5644,7 +5603,7 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert ...@@ -5644,7 +5603,7 @@ void DocxAttributeOutput::FormatVertOrientation( const SwFmtVertOrient& rFlyVert
break; break;
} }
m_pFlyAttrList->add( FSNS( XML_w, XML_vAnchor ), sVAnchor ); pushToAttrList( &m_pFlyAttrList, FSNS( XML_w, XML_vAnchor ), sVAnchor.getStr() );
} }
} }
...@@ -5659,9 +5618,6 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor ...@@ -5659,9 +5618,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() )
{ {
...@@ -5681,10 +5637,10 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor ...@@ -5681,10 +5637,10 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor
} }
if ( !sAlign.isEmpty() ) if ( !sAlign.isEmpty() )
m_pFlyAttrList->add( FSNS( XML_w, XML_xAlign ), sAlign ); pushToAttrList( &m_pFlyAttrList, FSNS( XML_w, XML_xAlign ), sAlign.getStr() );
else else
m_pFlyAttrList->add( FSNS( XML_w, XML_x ), pushToAttrList( &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( ) )
...@@ -5706,7 +5662,7 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor ...@@ -5706,7 +5662,7 @@ void DocxAttributeOutput::FormatHorizOrientation( const SwFmtHoriOrient& rFlyHor
break; break;
} }
m_pFlyAttrList->add( FSNS( XML_w, XML_hAnchor ), sHAnchor ); pushToAttrList( &m_pFlyAttrList, FSNS( XML_w, XML_hAnchor ), sHAnchor.getStr() );
} }
} }
...@@ -5744,15 +5700,13 @@ void DocxAttributeOutput::FormatBackground( const SvxBrushItem& rBrush ) ...@@ -5744,15 +5700,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 ) pushToAttrList( &m_pFlyFillAttrList, XML_opacity, OUStringToOString(sOpacity, RTL_TEXTENCODING_UTF8).getStr() );
m_pFlyFillAttrList = m_pSerializer->createAttrList();
m_pFlyFillAttrList->add(XML_opacity, OUStringToOString(sOpacity, RTL_TEXTENCODING_UTF8) + "f");
} }
m_pFlyAttrList->add(XML_fillcolor, "#" + sColor); sColor = "#" + sColor;
pushToAttrList( &m_pFlyAttrList, XML_fillcolor, sColor.getStr() );
} }
else if (m_bDMLTextFrameSyntax) else if (m_bDMLTextFrameSyntax)
{ {
...@@ -5785,10 +5739,7 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad ...@@ -5785,10 +5739,7 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad
{ {
if (*m_oFillStyle == XFILL_GRADIENT) if (*m_oFillStyle == XFILL_GRADIENT)
{ {
if ( !m_pFlyFillAttrList ) pushToAttrList(&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());
...@@ -5803,7 +5754,8 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad ...@@ -5803,7 +5754,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)); pushToAttrList(&m_pFlyFillAttrList,
XML_angle, OString::number(nReverseAngle).getStr());
OString sColor1 = sStartColor; OString sColor1 = sStartColor;
OString sColor2 = sEndColor; OString sColor2 = sEndColor;
...@@ -5811,7 +5763,7 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad ...@@ -5811,7 +5763,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%"); pushToAttrList(&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;
...@@ -5824,8 +5776,10 @@ void DocxAttributeOutput::FormatFillGradient( const XFillGradientItem& rFillGrad ...@@ -5824,8 +5776,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;
pushToAttrList(&m_pFlyAttrList, XML_fillcolor , sColor1.getStr());
pushToAttrList(&m_pFlyFillAttrList, XML_color2, sColor2.getStr());
} }
m_oFillStyle.reset(); m_oFillStyle.reset();
} }
...@@ -5848,8 +5802,8 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox ) ...@@ -5848,8 +5802,8 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox )
{ {
if (m_bTextFrameSyntax) if (m_bTextFrameSyntax)
{ {
m_pFlyAttrList->add(XML_stroked, "f"); pushToAttrList(&m_pFlyAttrList, 2,
m_pFlyAttrList->add(XML_strokeweight, "0pt"); XML_stroked, "f", XML_strokeweight, "0pt");
} }
} }
else else
...@@ -5860,15 +5814,17 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox ) ...@@ -5860,15 +5814,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";
pushToAttrList(&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,
...@@ -6159,54 +6115,40 @@ void DocxAttributeOutput::CharGrabBag( const SfxGrabBagItem& rItem ) ...@@ -6159,54 +6115,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) pushToAttrList( &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) pushToAttrList( &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) pushToAttrList( &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) pushToAttrList( &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 ) pushToAttrList( &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 ) pushToAttrList( &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" ||
...@@ -6355,4 +6297,26 @@ void DocxAttributeOutput::BulletDefinition(int nId, const Graphic& rGraphic, Siz ...@@ -6355,4 +6297,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::pushToAttrList( ::sax_fastparser::FastAttributeList **pAttrList, sal_Int32 nAttrName, const sal_Char* sAttrValue )
{
pushToAttrList( pAttrList, 1, nAttrName, sAttrValue );
}
void DocxAttributeOutput::pushToAttrList( ::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 pushToAttrList( ::sax_fastparser::FastAttributeList **pAttrList, sal_Int32 nAttrName, const sal_Char* sAttrValue );
void pushToAttrList( ::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