sw/qa/extras/ooxmlexport/data/table-theme-preservation.docx |binary sw/qa/extras/ooxmlexport/ooxmlexport.cxx | 5 sw/source/filter/ww8/docxattributeoutput.cxx | 97 ++++++++---- sw/source/filter/ww8/docxattributeoutput.hxx | 4 writerfilter/source/dmapper/DomainMapperTableHandler.cxx | 30 +++ 5 files changed, 105 insertions(+), 31 deletions(-)
New commits: commit 42ced106ff6ed5688385a5d2b40d4b5caea68406 Author: Jacobo Aragunde Pérez <jaragu...@igalia.com> Date: Thu Apr 3 16:49:33 2014 +0200 oox: use HasItem instead of GetItemState Code looks cleaner like this. Change-Id: I43bd8d2ac40960347d60e687dcae4c17357991b0 diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 1f4c301..a37282a 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2703,10 +2703,8 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t FSEND ); // Look for the table style property in the table grab bag - const SfxPoolItem *pI = NULL; - std::map<OUString, com::sun::star::uno::Any> aGrabBag; - if ( SFX_ITEM_ON == pTblFmt->GetAttrSet().GetItemState( RES_FRMATR_GRABBAG, false, &pI ) ) - aGrabBag = dynamic_cast<const SfxGrabBagItem *>(pI)->GetGrabBag(); + std::map<OUString, com::sun::star::uno::Any> aGrabBag = + sw::util::HasItem<SfxGrabBagItem>( pTblFmt->GetAttrSet(), RES_FRMATR_GRABBAG )->GetGrabBag(); // Extract properties from grab bag std::map<OUString, com::sun::star::uno::Any>::iterator aGrabBagElement; @@ -2829,19 +2827,13 @@ void DocxAttributeOutput::TableBackgrounds( ww8::WW8TableNodeInfoInner::Pointer_ { const SwTableBox *pTblBox = pTableTextNodeInfoInner->getTableBox( ); const SwFrmFmt *pFmt = pTblBox->GetFrmFmt( ); - const SfxPoolItem *pI = NULL; - - Color aColor; - if ( SFX_ITEM_ON == pFmt->GetAttrSet().GetItemState( RES_BACKGROUND, false, &pI ) ) - aColor = dynamic_cast<const SvxBrushItem *>(pI)->GetColor(); - else - aColor = COL_AUTO; + const SvxBrushItem *aColorProp = sw::util::HasItem<SvxBrushItem>( pFmt->GetAttrSet(), RES_BACKGROUND ); + Color aColor = aColorProp ? aColorProp->GetColor() : COL_AUTO; OString sColor = msfilter::util::ConvertColor( aColor ); - std::map<OUString, com::sun::star::uno::Any> aGrabBag; - if ( SFX_ITEM_ON == pFmt->GetAttrSet().GetItemState( RES_FRMATR_GRABBAG, false, &pI ) ) - aGrabBag = dynamic_cast<const SfxGrabBagItem *>(pI)->GetGrabBag(); + std::map<OUString, com::sun::star::uno::Any> aGrabBag = + sw::util::HasItem<SfxGrabBagItem>( pFmt->GetAttrSet(), RES_FRMATR_GRABBAG )->GetGrabBag(); OString sOriginalColor; std::map<OUString, com::sun::star::uno::Any>::iterator aGrabBagElement = aGrabBag.find("fill"); commit ae61569eea0719a882010cfbb260a1a0d690d974 Author: Jacobo Aragunde Pérez <jaragu...@igalia.com> Date: Thu Apr 3 16:27:37 2014 +0200 oox: Do not overwrite table style properties Some table properties can be defined by the table style but cells can overwrite them in their cell properties section. Our exporter was writing all the cell properties in all cases, regardless of them being defined by the theme or not, and we shouldn't do that if we want the document to work properly in Word. To fix the issue I store the style-defined cell properties (the format of all four borders) in the table grab bag. The exporter recovers them and compares with the cell properties before writing them; if the cell property matches the stlye-defined one, we don't write it to the document. An existing unit test was slightly modified to check that the actual cell properties are not being skipped. Change-Id: I3aa12d76fb8f73d3fd300f254d19e1683fb6146c diff --git a/sw/qa/extras/ooxmlexport/data/table-theme-preservation.docx b/sw/qa/extras/ooxmlexport/data/table-theme-preservation.docx index fe6b953..522dac8 100644 Binary files a/sw/qa/extras/ooxmlexport/data/table-theme-preservation.docx and b/sw/qa/extras/ooxmlexport/data/table-theme-preservation.docx differ diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx index b68b872..1e1fd6d 100644 --- a/sw/qa/extras/ooxmlexport/ooxmlexport.cxx +++ b/sw/qa/extras/ooxmlexport/ooxmlexport.cxx @@ -1956,6 +1956,11 @@ DECLARE_OOXMLEXPORT_TEST(testTableThemePreservation, "table-theme-preservation.d // check table style has been preserved assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tblPr/w:tblStyle", "val", "Sombreadoclaro-nfasis1"); + // check table style is not overwritten by other properties + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[2]/w:tcPr/w:tcBorders/*", 0); + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[3]/w:tcPr/w:tcBorders/*", 0); + // check that one cell attribute present in the original document has been preserved + assertXPath(pXmlDocument, "/w:document/w:body/w:tbl/w:tr[1]/w:tc[1]/w:tcPr/w:tcBorders/*", 1); } diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx index 947cd16..1f4c301 100644 --- a/sw/source/filter/ww8/docxattributeoutput.cxx +++ b/sw/source/filter/ww8/docxattributeoutput.cxx @@ -2075,7 +2075,8 @@ void DocxAttributeOutput::ParagraphStyle( sal_uInt16 nStyle ) m_pSerializer->singleElementNS( XML_w, XML_pStyle, FSNS( XML_w, XML_val ), aStyleId.getStr(), FSEND ); } -static void impl_borderLine( FSHelperPtr pSerializer, sal_Int32 elementToken, const SvxBorderLine* pBorderLine, sal_uInt16 nDist, bool bWriteShadow = false ) +static void impl_borderLine( FSHelperPtr pSerializer, sal_Int32 elementToken, const SvxBorderLine* pBorderLine, sal_uInt16 nDist, + bool bWriteShadow = false, const table::BorderLine2* rStyleProps = NULL ) { FastAttributeList* pAttr = pSerializer->createAttrList(); @@ -2141,6 +2142,19 @@ static void impl_borderLine( FSHelperPtr pSerializer, sal_Int32 elementToken, co break; } } + else if( rStyleProps == NULL ) + // no line, and no line set by the style either: + // there is no need to write the property + return; + + // compare the properties with the theme properties before writing them: + // if they are equal, it means that they were style-defined and there is + // no need to write them. + if( rStyleProps != NULL && pBorderLine && !pBorderLine->isEmpty() && + pBorderLine->GetBorderLineStyle() == rStyleProps->LineStyle && + pBorderLine->GetColor() == rStyleProps->Color && + pBorderLine->GetWidth() == MM100_TO_TWIP_UNSIGNED( rStyleProps->LineWidth ) ) + return; pAttr->add( FSNS( XML_w, XML_val ), OString( pVal ) ); @@ -2235,7 +2249,8 @@ static bool boxHasLineLargerThan31(const SvxBoxItem& rBox) ); } -static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const OutputBorderOptions& rOptions, PageMargins* pageMargins) +static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const OutputBorderOptions& rOptions, PageMargins* pageMargins, + std::map<sal_uInt16, css::table::BorderLine2> &rTableStyleConf ) { static const sal_uInt16 aBorders[] = { @@ -2267,6 +2282,9 @@ static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const for( int i = 0; i < 4; ++i, ++pBrd ) { const SvxBorderLine* pLn = rBox.GetLine( *pBrd ); + const table::BorderLine2 *aStyleProps = NULL; + if( rTableStyleConf.find( *pBrd ) != rTableStyleConf.end() ) + aStyleProps = &rTableStyleConf[ *pBrd ]; if (!tagWritten && rOptions.bWriteTag) { @@ -2326,7 +2344,7 @@ static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const } } - impl_borderLine( pSerializer, aXmlElements[i], pLn, nDist, bWriteShadow ); + impl_borderLine( pSerializer, aXmlElements[i], pLn, nDist, bWriteShadow, aStyleProps ); // When exporting default borders, we need to export these 2 attr if ( rOptions.bWriteInsideHV) { @@ -2337,9 +2355,19 @@ static void impl_borders( FSHelperPtr pSerializer, const SvxBoxItem& rBox, const } } if (bWriteInsideH) - impl_borderLine( pSerializer, XML_insideH, rBox.GetLine(BOX_LINE_BOTTOM), 0 ); + { + const table::BorderLine2 *aStyleProps = NULL; + if( rTableStyleConf.find( BOX_LINE_BOTTOM ) != rTableStyleConf.end() ) + aStyleProps = &rTableStyleConf[ BOX_LINE_BOTTOM ]; + impl_borderLine( pSerializer, XML_insideH, rBox.GetLine(BOX_LINE_BOTTOM), 0, false, aStyleProps ); + } if (bWriteInsideV) - impl_borderLine( pSerializer, XML_insideV, rBox.GetLine(BOX_LINE_RIGHT), 0 ); + { + const table::BorderLine2 *aStyleProps = NULL; + if( rTableStyleConf.find( BOX_LINE_RIGHT ) != rTableStyleConf.end() ) + aStyleProps = &rTableStyleConf[ BOX_LINE_RIGHT ]; + impl_borderLine( pSerializer, XML_insideV, rBox.GetLine(BOX_LINE_RIGHT), 0, false, aStyleProps ); + } if (tagWritten && rOptions.bWriteTag) { pSerializer->endElementNS( XML_w, rOptions.tag ); } @@ -2450,7 +2478,7 @@ void DocxAttributeOutput::TableCellProperties( ww8::WW8TableNodeInfoInner::Point const SvxBoxItem& rDefaultBox = (*tableFirstCells.rbegin())->getTableBox( )->GetFrmFmt( )->GetBox( ); { // The cell borders - impl_borders( m_pSerializer, rBox, lcl_getTableCellBorderOptions(bEcma), NULL ); + impl_borders( m_pSerializer, rBox, lcl_getTableCellBorderOptions(bEcma), NULL, m_aTableStyleConf ); } TableBackgrounds( pTableTextNodeInfoInner ); @@ -2549,6 +2577,8 @@ void DocxAttributeOutput::EndTable() // Cleans the table helper delete m_pTableWrt, m_pTableWrt = NULL; + + m_aTableStyleConf.clear(); } void DocxAttributeOutput::StartTableRow( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner ) @@ -2678,14 +2708,25 @@ void DocxAttributeOutput::TableDefinition( ww8::WW8TableNodeInfoInner::Pointer_t if ( SFX_ITEM_ON == pTblFmt->GetAttrSet().GetItemState( RES_FRMATR_GRABBAG, false, &pI ) ) aGrabBag = dynamic_cast<const SfxGrabBagItem *>(pI)->GetGrabBag(); - // Write table style property if it exists - std::map<OUString, com::sun::star::uno::Any>::iterator aGrabBagElement = aGrabBag.find("TableStyleName"); - if( aGrabBagElement != aGrabBag.end() ) + // Extract properties from grab bag + std::map<OUString, com::sun::star::uno::Any>::iterator aGrabBagElement; + for( aGrabBagElement = aGrabBag.begin(); aGrabBagElement != aGrabBag.end(); ++aGrabBagElement ) { - OString sStyleName = OUStringToOString( aGrabBagElement->second.get<OUString>(), RTL_TEXTENCODING_UTF8 ); - m_pSerializer->singleElementNS( XML_w, XML_tblStyle, - FSNS( XML_w, XML_val ), sStyleName.getStr(), - FSEND ); + if( aGrabBagElement->first == "TableStyleName") + { + OString sStyleName = OUStringToOString( aGrabBagElement->second.get<OUString>(), RTL_TEXTENCODING_UTF8 ); + m_pSerializer->singleElementNS( XML_w, XML_tblStyle, + FSNS( XML_w, XML_val ), sStyleName.getStr(), + FSEND ); + } + else if( aGrabBagElement->first == "TableStyleTopBorder" ) + m_aTableStyleConf[ BOX_LINE_TOP ] = aGrabBagElement->second.get<table::BorderLine2>(); + else if( aGrabBagElement->first == "TableStyleBottomBorder" ) + m_aTableStyleConf[ BOX_LINE_BOTTOM ] = aGrabBagElement->second.get<table::BorderLine2>(); + else if( aGrabBagElement->first == "TableStyleLeftBorder" ) + m_aTableStyleConf[ BOX_LINE_LEFT ] = aGrabBagElement->second.get<table::BorderLine2>(); + else if( aGrabBagElement->first == "TableStyleRightBorder" ) + m_aTableStyleConf[ BOX_LINE_RIGHT ] = aGrabBagElement->second.get<table::BorderLine2>(); } // Output the table alignement @@ -2771,7 +2812,7 @@ void DocxAttributeOutput::TableDefaultBorders( ww8::WW8TableNodeInfoInner::Point bool bEcma = GetExport().GetFilter().getVersion( ) == oox::core::ECMA_DIALECT; // the defaults of the table are taken from the top-left cell - impl_borders( m_pSerializer, pFrmFmt->GetBox( ), lcl_getTableDefaultBorderOptions(bEcma), NULL ); + impl_borders( m_pSerializer, pFrmFmt->GetBox( ), lcl_getTableDefaultBorderOptions(bEcma), NULL, m_aTableStyleConf ); } void DocxAttributeOutput::TableDefaultCellMargins( ww8::WW8TableNodeInfoInner::Pointer_t pTableTextNodeInfoInner ) @@ -4623,7 +4664,9 @@ void DocxAttributeOutput::SectionPageBorders( const SwFrmFmt* pFmt, const SwFrmF aOutputBorderOptions.aShadowLocation = pShadowItem->GetLocation(); } - impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins ); + std::map<sal_uInt16, css::table::BorderLine2> aEmptyMap; // empty styles map + impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins, + aEmptyMap ); m_pSerializer->endElementNS( XML_w, XML_pgBorders ); } @@ -6804,7 +6847,9 @@ void DocxAttributeOutput::FormatBox( const SvxBoxItem& rBox ) // Open the paragraph's borders tag m_pSerializer->startElementNS( XML_w, XML_pBdr, FSEND ); - impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins ); + std::map<sal_uInt16, css::table::BorderLine2> aEmptyMap; // empty styles map + impl_borders( m_pSerializer, rBox, aOutputBorderOptions, &m_pageMargins, + aEmptyMap ); // Close the paragraph's borders tag m_pSerializer->endElementNS( XML_w, XML_pBdr ); diff --git a/sw/source/filter/ww8/docxattributeoutput.hxx b/sw/source/filter/ww8/docxattributeoutput.hxx index 8deff4f..ba26fba 100644 --- a/sw/source/filter/ww8/docxattributeoutput.hxx +++ b/sw/source/filter/ww8/docxattributeoutput.hxx @@ -39,6 +39,8 @@ #include <oox/export/drawingml.hxx> #include <docxtablestyleexport.hxx> +#include <com/sun/star/table/BorderLine2.hpp> + #include <boost/scoped_ptr.hpp> class SwGrfNode; @@ -868,6 +870,8 @@ private: ::sax_fastparser::FastAttributeList *m_pRunSdtPrTokenChildren; ::sax_fastparser::FastAttributeList *m_pRunSdtPrDataBindingAttrs; + std::map<sal_uInt16, css::table::BorderLine2> m_aTableStyleConf; + public: DocxAttributeOutput( DocxExport &rExport, ::sax_fastparser::FSHelperPtr pSerializer, oox::drawingml::DrawingML* pDrawingML ); diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index 7ed56aa..08d1919 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -340,7 +340,7 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo PropertyMap::iterator aTableStyleIter = m_aTableProperties->find(META_PROP_TABLE_STYLE_NAME); - uno::Sequence< beans::PropertyValue > aGrabBag( 1 ); + uno::Sequence< beans::PropertyValue > aGrabBag( 5 ); sal_Int32 nGrabBagSize = 0; if(aTableStyleIter != m_aTableProperties->end()) { @@ -366,6 +366,33 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo PropertyMapPtr pMergedProperties = lcl_SearchParentStyleSheetAndMergeProperties(pStyleSheet, pStyleSheetTable); + table::BorderLine2 aBorderLine; + TableInfo rStyleInfo; + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_TOP_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag[1].Name = "TableStyleTopBorder"; + aGrabBag[1].Value = uno::makeAny( aBorderLine ); + nGrabBagSize++; + } + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_BOTTOM_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag[2].Name = "TableStyleBottomBorder"; + aGrabBag[2].Value = uno::makeAny( aBorderLine ); + nGrabBagSize++; + } + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_LEFT_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag[3].Name = "TableStyleLeftBorder"; + aGrabBag[3].Value = uno::makeAny( aBorderLine ); + nGrabBagSize++; + } + if (lcl_extractTableBorderProperty(pMergedProperties, PROP_RIGHT_BORDER, rStyleInfo, aBorderLine)) + { + aGrabBag[4].Name = "TableStyleRightBorder"; + aGrabBag[4].Value = uno::makeAny( aBorderLine ); + nGrabBagSize++; + } + #ifdef DEBUG_DMAPPER_TABLE_HANDLER dmapper_logger->startElement("mergedProps"); pMergedProperties->dumpXml( dmapper_logger ); @@ -402,6 +429,7 @@ TableStyleSheetEntry * DomainMapperTableHandler::endTableGetTableStyle(TableInfo if( nGrabBagSize > 0 ) { + aGrabBag.realloc( nGrabBagSize ); m_aTableProperties->Insert( PROP_TABLE_INTEROP_GRAB_BAG, uno::makeAny( aGrabBag ) ); }
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits