diff options
author | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-09-08 10:46:12 +0200 |
---|---|---|
committer | Zolnai Tamás <zolnaitamas2000@gmail.com> | 2013-09-08 11:23:46 +0200 |
commit | 05e1439107deacb8416c9aee1b6fb2c72a171eaf (patch) | |
tree | 333dc102d1faf5144b859e964b4a534f25e2f508 | |
parent | cfc64c7e895d990023400573d8416ce80cf0da29 (diff) |
CharBrd 9.3: RTF filters
-Use sprm:CBrc attribute for all MS filter (for ooxml too).
-Extract general code to FormatCharBorder() method, it selects
the border side and decides whether add shadow to the border.
-RTF export has a color table, which must be filled with border
colors before the actual export.temp
Change-Id: Ic3ceae6e19ddc2ed5aaa8de85617f9a592289b4f
-rw-r--r-- | sw/qa/extras/ooxmlexport/data/charborder.odt | bin | 8042 -> 8052 bytes | |||
-rw-r--r-- | sw/qa/extras/rtfexport/data/charborder.odt | bin | 0 -> 8052 bytes | |||
-rw-r--r-- | sw/qa/extras/rtfexport/rtfexport.cxx | 40 | ||||
-rw-r--r-- | sw/source/filter/ww8/attributeoutputbase.hxx | 5 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.cxx | 39 | ||||
-rw-r--r-- | sw/source/filter/ww8/docxattributeoutput.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.cxx | 11 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfattributeoutput.hxx | 2 | ||||
-rw-r--r-- | sw/source/filter/ww8/rtfexport.cxx | 13 | ||||
-rw-r--r-- | sw/source/filter/ww8/wrtw8nds.cxx | 4 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8atr.cxx | 39 | ||||
-rw-r--r-- | sw/source/filter/ww8/ww8attributeoutput.hxx | 2 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.cxx | 17 | ||||
-rw-r--r-- | writerfilter/source/rtftok/rtfdocumentimpl.hxx | 3 |
14 files changed, 132 insertions, 45 deletions
diff --git a/sw/qa/extras/ooxmlexport/data/charborder.odt b/sw/qa/extras/ooxmlexport/data/charborder.odt Binary files differindex 149abfc6ffe7..67dd89b099e0 100644 --- a/sw/qa/extras/ooxmlexport/data/charborder.odt +++ b/sw/qa/extras/ooxmlexport/data/charborder.odt diff --git a/sw/qa/extras/rtfexport/data/charborder.odt b/sw/qa/extras/rtfexport/data/charborder.odt Binary files differnew file mode 100644 index 000000000000..bea79c147153 --- /dev/null +++ b/sw/qa/extras/rtfexport/data/charborder.odt diff --git a/sw/qa/extras/rtfexport/rtfexport.cxx b/sw/qa/extras/rtfexport/rtfexport.cxx index 81340e43af36..2cd5cfa4dbf5 100644 --- a/sw/qa/extras/rtfexport/rtfexport.cxx +++ b/sw/qa/extras/rtfexport/rtfexport.cxx @@ -68,6 +68,7 @@ public: void testTextframeTable(); void testFdo66682(); void testParaShadow(); + void testCharacterBorder(); CPPUNIT_TEST_SUITE(Test); #if !defined(MACOSX) && !defined(WNT) @@ -125,6 +126,7 @@ void Test::run() {"textframe-table.rtf", &Test::testTextframeTable}, {"fdo66682.rtf", &Test::testFdo66682}, {"para-shadow.rtf", &Test::testParaShadow}, + {"charborder.odt", &Test::testCharacterBorder}, }; // Don't test the first import of these, for some reason those tests fail const char* aBlacklist[] = { @@ -633,6 +635,44 @@ void Test::testParaShadow() CPPUNIT_ASSERT_EQUAL(sal_Int16(TWIP_TO_MM100(60)), aShadow.ShadowWidth); } +void Test::testCharacterBorder() +{ + uno::Reference<beans::XPropertySet> xRun(getRun(getParagraph(1),1), uno::UNO_QUERY); + // RTF has just one border attribute(chbrdr) for text border so all side has + // the same border with the same padding + // Border + { + const table::BorderLine2 aTopBorder = getProperty<table::BorderLine2>(xRun,"CharTopBorder"); + CPPUNIT_ASSERT_EQUAL_BORDER(table::BorderLine2(16737792,0,318,0,0,318), aTopBorder); + CPPUNIT_ASSERT_EQUAL_BORDER(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharLeftBorder")); + CPPUNIT_ASSERT_EQUAL_BORDER(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharBottomBorder")); + CPPUNIT_ASSERT_EQUAL_BORDER(aTopBorder, getProperty<table::BorderLine2>(xRun,"CharRightBorder")); + } + + // Padding (brsp) + { + const sal_Int32 nTopPadding = getProperty<sal_Int32>(xRun,"CharTopBorderDistance"); + // In the original odt file it is 150, but the unit conversion round it down. + CPPUNIT_ASSERT_EQUAL(sal_Int32(141), nTopPadding); + CPPUNIT_ASSERT_EQUAL(nTopPadding, getProperty<sal_Int32>(xRun,"CharLeftBorderDistance")); + CPPUNIT_ASSERT_EQUAL(nTopPadding, getProperty<sal_Int32>(xRun,"CharBottomBorderDistance")); + CPPUNIT_ASSERT_EQUAL(nTopPadding, getProperty<sal_Int32>(xRun,"CharRightBorderDistance")); + } + + // Shadow (brdrsh) + /* RTF use just one bool value for shadow so the next conversions + are made during an export-import round + color: any -> black + location: any -> bottom-right + width: any -> border width */ + { + const table::ShadowFormat aShadow = getProperty<table::ShadowFormat>(xRun, "CharShadowFormat"); + CPPUNIT_ASSERT_EQUAL(COL_BLACK, sal_uInt32(aShadow.Color)); + CPPUNIT_ASSERT_EQUAL(table::ShadowLocation_BOTTOM_RIGHT, aShadow.Location); + CPPUNIT_ASSERT_EQUAL(sal_Int16(318), aShadow.ShadowWidth); + } +} + CPPUNIT_TEST_SUITE_REGISTRATION(Test); CPPUNIT_PLUGIN_IMPLEMENT(); diff --git a/sw/source/filter/ww8/attributeoutputbase.hxx b/sw/source/filter/ww8/attributeoutputbase.hxx index 646030ada11f..259503cbe94c 100644 --- a/sw/source/filter/ww8/attributeoutputbase.hxx +++ b/sw/source/filter/ww8/attributeoutputbase.hxx @@ -118,6 +118,8 @@ class SwLineNumberInfo; class SwNumRule; class wwFont; +using ::editeng::SvxBorderLine; + class String; namespace rtl { class OUString; } @@ -439,7 +441,8 @@ protected: virtual void CharHidden( const SvxCharHiddenItem& ) = 0; /// Sfx item RES_CHRATR_BOX - virtual void CharBorder( const SvxBoxItem& rBox ) = 0; + void FormatCharBorder( const SvxBoxItem& rBox ); + virtual void CharBorder( const SvxBorderLine* pAllBorder, const sal_uInt16 nDist, const bool bShadow ) = 0; /// Sfx item RES_TXTATR_INETFMT virtual void TextINetFormat( const SwFmtINetFmt& ) = 0; diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index cddb20bed9cd..c5b78ff8a578 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -112,8 +112,6 @@ #include <stdio.h> #endif -using ::editeng::SvxBorderLine; - using namespace oox; using namespace docx; using namespace sax_fastparser; @@ -4081,41 +4079,10 @@ void DocxAttributeOutput::CharHidden( const SvxCharHiddenItem& rHidden ) m_pSerializer->singleElementNS( XML_w, XML_vanish, FSNS( XML_w, XML_val ), "false", FSEND ); } -void DocxAttributeOutput::CharBorder( const SvxBoxItem& rBox ) +void DocxAttributeOutput::CharBorder( + const SvxBorderLine* pAllBorder, const sal_uInt16 nDist, const bool bShadow ) { - // Get one of the borders (if there is any border then in docx also will be) - const SvxBorderLine* pBorderLine = 0; - sal_uInt16 nDist = 0; - if( rBox.GetTop() ) - { - pBorderLine = rBox.GetTop(); - nDist = rBox.GetDistance( BOX_LINE_TOP ); - } - else if( rBox.GetLeft() ) - { - pBorderLine = rBox.GetLeft(); - nDist = rBox.GetDistance( BOX_LINE_LEFT ); - } - else if( rBox.GetBottom() ) - { - pBorderLine = rBox.GetBottom(); - nDist = rBox.GetDistance( BOX_LINE_BOTTOM ); - } - else if( rBox.GetRight() ) - { - pBorderLine = rBox.GetRight(); - nDist = rBox.GetDistance( BOX_LINE_RIGHT ); - } - - if( pBorderLine ) - { - const SfxPoolItem* pItem = GetExport().HasItem( RES_CHRATR_SHADOW ); - const bool bShadow = - pItem && - static_cast<const SvxShadowItem*>(pItem)->GetLocation() != SVX_SHADOW_NONE; - - impl_borderLine( m_pSerializer, XML_bdr, pBorderLine, nDist, bShadow ); - } + impl_borderLine( m_pSerializer, XML_bdr, pAllBorder, nDist, bShadow ); } void DocxAttributeOutput::TextINetFormat( const SwFmtINetFmt& rLink ) diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index c217fb95ff61..8333517f031d 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -473,7 +473,7 @@ protected: virtual void CharHidden( const SvxCharHiddenItem& rHidden ); /// Sfx item RES_CHRATR_BOX - virtual void CharBorder( const SvxBoxItem& rBox ); + virtual void CharBorder( const SvxBorderLine* pAllBorder, const sal_uInt16 nDist, const bool bShadow ); /// Sfx item RES_TXTATR_INETFMT virtual void TextINetFormat( const SwFmtINetFmt& ); diff --git a/sw/source/filter/ww8/rtfattributeoutput.cxx b/sw/source/filter/ww8/rtfattributeoutput.cxx index 065278c807f0..c4d3b29289cf 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.cxx +++ b/sw/source/filter/ww8/rtfattributeoutput.cxx @@ -101,7 +101,6 @@ #include <com/sun/star/i18n/ScriptType.hpp> -using ::editeng::SvxBorderLine; using namespace nsSwDocInfoSubType; using namespace nsFieldFlags; using namespace sw::util; @@ -2361,6 +2360,16 @@ void RtfAttributeOutput::CharHidden( const SvxCharHiddenItem& rHidden ) m_aStyles.append((sal_Int32)0); } +void RtfAttributeOutput::CharBorder( + const SvxBorderLine* pAllBorder, const sal_uInt16 nDist, const bool bShadow ) +{ + SAL_INFO("sw.rtf", OSL_THIS_FUNC); + + m_aStyles.append( + OutBorderLine(m_rExport, pAllBorder, OOO_STRING_SVTOOLS_RTF_CHBRDR, + nDist, bShadow ? SVX_SHADOW_BOTTOMRIGHT : SVX_SHADOW_NONE)); +} + void RtfAttributeOutput::TextINetFormat( const SwFmtINetFmt& rURL ) { SAL_INFO("sw.rtf", OSL_THIS_FUNC); diff --git a/sw/source/filter/ww8/rtfattributeoutput.hxx b/sw/source/filter/ww8/rtfattributeoutput.hxx index b332dd31e7f8..51fdcef6e17e 100644 --- a/sw/source/filter/ww8/rtfattributeoutput.hxx +++ b/sw/source/filter/ww8/rtfattributeoutput.hxx @@ -313,7 +313,7 @@ protected: virtual void CharHidden( const SvxCharHiddenItem& rHidden ); /// Sfx item RES_CHRATR_BOX - virtual void CharBorder( const SvxBoxItem& /*rBox*/ ){}; + virtual void CharBorder( const SvxBorderLine* pAllBorder, const sal_uInt16 nDist, const bool bShadow ); /// Sfx item RES_TXTATR_INETFMT virtual void TextINetFormat( const SwFmtINetFmt& ); diff --git a/sw/source/filter/ww8/rtfexport.cxx b/sw/source/filter/ww8/rtfexport.cxx index 0787f37acb11..87dd8d3034f6 100644 --- a/sw/source/filter/ww8/rtfexport.cxx +++ b/sw/source/filter/ww8/rtfexport.cxx @@ -1005,7 +1005,20 @@ void RtfExport::OutColorTable() { if( 0 != (pBox = (const SvxBoxItem*)rPool.GetItem2( RES_BOX, n ) )) InsColorLine( *pBox ); + } } + + { + const SvxBoxItem* pCharBox; + if( 0 != ( pCharBox = (const SvxBoxItem*)rPool.GetPoolDefaultItem( + RES_CHRATR_BOX ) )) + InsColorLine( *pCharBox ); + nMaxItem = rPool.GetItemCount2(RES_CHRATR_BOX); + for (sal_uInt32 n = 0; n < nMaxItem; ++n) + { + if( 0 != (pCharBox = (const SvxBoxItem*)rPool.GetItem2( RES_CHRATR_BOX, n ) )) + InsColorLine( *pCharBox ); + } } for (size_t n = 0; n < m_aColTbl.size(); ++n) diff --git a/sw/source/filter/ww8/wrtw8nds.cxx b/sw/source/filter/ww8/wrtw8nds.cxx index 1df63f7e185e..0c34fc72403e 100644 --- a/sw/source/filter/ww8/wrtw8nds.cxx +++ b/sw/source/filter/ww8/wrtw8nds.cxx @@ -463,7 +463,7 @@ void SwWW8AttrIter::OutAttr( xub_StrLen nSwPos, bool bRuby ) sw::PoolItems aExportItems; GetPoolItems( aExportSet, aExportItems, false ); - if( nSwPos == 0 ) + if( rNd.GetpSwpHints() == 0 ) m_rExport.SetCurItemSet(&aExportSet); sw::cPoolItemIter aEnd = aRangeItems.end(); @@ -486,7 +486,7 @@ void SwWW8AttrIter::OutAttr( xub_StrLen nSwPos, bool bRuby ) m_rExport.pOutFmtNode = pOldMod; } - if( nSwPos == 0 ) + if( rNd.GetpSwpHints() == 0 ) m_rExport.SetCurItemSet(0); OSL_ENSURE( pFont, "must be *some* font associated with this txtnode" ); diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx index fef7f4fd3351..b504ccfb75ed 100644 --- a/sw/source/filter/ww8/ww8atr.cxx +++ b/sw/source/filter/ww8/ww8atr.cxx @@ -5149,7 +5149,7 @@ void AttributeOutputBase::OutputItem( const SfxPoolItem& rHt ) CharHidden( static_cast< const SvxCharHiddenItem& >( rHt ) ); break; case RES_CHRATR_BOX: - CharBorder( static_cast< const SvxBoxItem& >( rHt ) ); + FormatCharBorder( static_cast< const SvxBoxItem& >( rHt ) ); break; case RES_TXTATR_INETFMT: @@ -5318,4 +5318,41 @@ void AttributeOutputBase::OutputStyleItemSet( const SfxItemSet& rSet, sal_Bool b } } +void AttributeOutputBase::FormatCharBorder( const SvxBoxItem& rBox ) +{ + // Get one of the borders (if there is any border then in docx also will be) + const SvxBorderLine* pBorderLine = 0; + sal_uInt16 nDist = 0; + if( rBox.GetTop() ) + { + pBorderLine = rBox.GetTop(); + nDist = rBox.GetDistance( BOX_LINE_TOP ); + } + else if( rBox.GetLeft() ) + { + pBorderLine = rBox.GetLeft(); + nDist = rBox.GetDistance( BOX_LINE_LEFT ); + } + else if( rBox.GetBottom() ) + { + pBorderLine = rBox.GetBottom(); + nDist = rBox.GetDistance( BOX_LINE_BOTTOM ); + } + else if( rBox.GetRight() ) + { + pBorderLine = rBox.GetRight(); + nDist = rBox.GetDistance( BOX_LINE_RIGHT ); + } + + if( pBorderLine ) + { + const SfxPoolItem* pItem = GetExport().HasItem( RES_CHRATR_SHADOW ); + const bool bShadow = + pItem && + static_cast<const SvxShadowItem*>(pItem)->GetLocation() != SVX_SHADOW_NONE; + + CharBorder( pBorderLine, nDist, bShadow ); + } +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/filter/ww8/ww8attributeoutput.hxx b/sw/source/filter/ww8/ww8attributeoutput.hxx index 3ab2e799bb40..d5483efbbee4 100644 --- a/sw/source/filter/ww8/ww8attributeoutput.hxx +++ b/sw/source/filter/ww8/ww8attributeoutput.hxx @@ -294,7 +294,7 @@ protected: virtual void CharHidden( const SvxCharHiddenItem& ); /// Sfx item RES_CHRATR_BOX - virtual void CharBorder( const SvxBoxItem& /*rBox*/ ){}; + virtual void CharBorder( const SvxBorderLine* /*pAllBorder*/, const sal_uInt16 /*nDist*/, const bool /*bShadow*/ ){}; /// Sfx item RES_TXTATR_INETFMT virtual void TextINetFormat( const SwFmtINetFmt& ); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx index b0835e1b0573..d73c5bd600fe 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx @@ -140,6 +140,15 @@ static void lcl_putBorderProperty(std::stack<RTFParserState>& aStates, Id nId, R rAttributes.set(nId, pValue); } } + else if (aStates.top().nBorderState == BORDER_CHARACTER) + { + RTFValue::Pointer_t pPointer = aStates.top().aCharacterSprms.find(NS_ooxml::LN_EG_RPrBase_bdr); + if (pPointer.get()) + { + RTFSprms& rAttributes = pPointer->getAttributes(); + rAttributes.set(nId, pValue); + } + } // Attributes of the last border type else if (aStates.top().nBorderState == BORDER_PARAGRAPH) pAttributes = &lcl_getLastAttributes(aStates.top().aParagraphSprms, NS_ooxml::LN_CT_PrBase_pBdr); @@ -2414,6 +2423,14 @@ int RTFDocumentImpl::dispatchFlag(RTFKeyword nKeyword) m_aStates.top().nBorderState = BORDER_PARAGRAPH; } break; + case RTF_CHBRDR: + { + RTFSprms aAttributes; + RTFValue::Pointer_t pValue(new RTFValue(aAttributes)); + m_aStates.top().aCharacterSprms.set(NS_ooxml::LN_EG_RPrBase_bdr, pValue); + m_aStates.top().nBorderState = BORDER_CHARACTER; + } + break; case RTF_CLVMGF: { RTFValue::Pointer_t pValue(new RTFValue(NS_ooxml::LN_Value_ST_Merge_restart)); diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.hxx b/writerfilter/source/rtftok/rtfdocumentimpl.hxx index 276ca933a6c5..a0b1076f3a03 100644 --- a/writerfilter/source/rtftok/rtfdocumentimpl.hxx +++ b/writerfilter/source/rtftok/rtfdocumentimpl.hxx @@ -36,7 +36,8 @@ namespace writerfilter { BORDER_PARAGRAPH, BORDER_PARAGRAPH_BOX, BORDER_CELL, - BORDER_PAGE + BORDER_PAGE, + BORDER_CHARACTER }; /// Minimalistic buffer of elements for nested cells. |