From eff81a79fa09ce17ba77319b01e8a91a805a42c0 Mon Sep 17 00:00:00 2001 From: Miklos Vajna Date: Thu, 14 Aug 2014 13:54:18 +0200 Subject: bnc#865381 DOCX import: handle table cell property (cherry picked from commit d1278ef4849661b9ae0eb7aaf4d74fbf91ccaf11) Conflicts: writerfilter/source/dmapper/PropertyIds.cxx writerfilter/source/dmapper/PropertyIds.hxx Change-Id: Id0dd34110376168e34df4956869608895b86abfe Reviewed-on: https://gerrit.libreoffice.org/10922 Reviewed-by: David Tardon Tested-by: David Tardon --- .../source/dmapper/DomainMapperTableHandler.cxx | 48 ++++++++++++++++++++++ writerfilter/source/dmapper/PropertyIds.cxx | 1 + writerfilter/source/dmapper/PropertyIds.hxx | 1 + .../source/dmapper/TablePropertiesHandler.cxx | 8 ++++ 4 files changed, 58 insertions(+) (limited to 'writerfilter') diff --git a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx index a8650a52d86d..33f70cc9cbd0 100644 --- a/writerfilter/source/dmapper/DomainMapperTableHandler.cxx +++ b/writerfilter/source/dmapper/DomainMapperTableHandler.cxx @@ -29,9 +29,11 @@ #include #include #include +#include #include #include #include +#include #ifdef DEBUG_DMAPPER_TABLE_HANDLER #include @@ -886,12 +888,50 @@ CellPropertyValuesSeq_t DomainMapperTableHandler::endTableGetCellProperties(Tabl return aCellProperties; } +/// Do all cells in this row have a CellHideMark property? +bool lcl_hideMarks(PropertyMapVector1& rCellProperties) +{ + for (size_t nCell = 0; nCell < rCellProperties.size(); ++nCell) + if (rCellProperties[nCell]->find(PROP_CELL_HIDE_MARK) == rCellProperties[nCell]->end()) + return false; + return true; +} + +/// Are all cells in this row empty? +bool lcl_emptyRow(TableSequence_t& rTableSeq, sal_Int32 nRow) +{ + if (nRow >= rTableSeq.getLength()) + { + SAL_WARN("writerfilter", "m_aCellProperties not in sync with m_pTableSeq?"); + return false; + } + + RowSequence_t rRowSeq = rTableSeq[nRow]; + uno::Reference xTextRangeCompare(rRowSeq[0][0]->getText(), uno::UNO_QUERY); + try + { + for (sal_Int32 nCell = 0; nCell < rRowSeq.getLength(); ++nCell) + // See SwXText::Impl::ConvertCell(), we need to compare the start of + // the start and the end of the end. However for our text ranges, only + // the starts are set, so compareRegionStarts() does what we need. + if (xTextRangeCompare->compareRegionStarts(rRowSeq[nCell][0], rRowSeq[nCell][1]) != 0) + return false; + } + catch (lang::IllegalArgumentException& e) + { + SAL_WARN("writerfilter", "compareRegionStarts() failed: " << e.Message); + return false; + } + return true; +} + RowPropertyValuesSeq_t DomainMapperTableHandler::endTableGetRowProperties() { #ifdef DEBUG_DMAPPER_TABLE_HANDLER dmapper_logger->startElement("getRowProperties"); #endif + static const int MINLAY = 23; // sw/inc/swtypes.hxx, minimal possible size of frames. RowPropertyValuesSeq_t aRowProperties( m_aRowProperties.size() ); PropertyMapVector1::const_iterator aRowIter = m_aRowProperties.begin(); PropertyMapVector1::const_iterator aRowIterEnd = m_aRowProperties.end(); @@ -911,6 +951,14 @@ RowPropertyValuesSeq_t DomainMapperTableHandler::endTableGetRowProperties() if (aIter != aRowIter->get()->end()) aRowIter->get()->erase(aIter); + if (lcl_hideMarks(m_aCellProperties[nRow]) && lcl_emptyRow(*m_pTableSeq, nRow)) + { + // We have CellHideMark on all cells, and also all cells are empty: + // Set the row height to minimal as Word does. + (*aRowIter)->Insert(PROP_SIZE_TYPE, uno::makeAny(text::SizeType::FIX)); + (*aRowIter)->Insert(PROP_HEIGHT, uno::makeAny(static_cast(ConversionHelper::convertTwipToMM100(MINLAY)))); + } + aRowProperties[nRow] = (*aRowIter)->GetPropertyValues(); #ifdef DEBUG_DMAPPER_TABLE_HANDLER ((*aRowIter)->dumpXml( dmapper_logger )); diff --git a/writerfilter/source/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx index e5b9918adfb1..3f5fa0571cdd 100644 --- a/writerfilter/source/dmapper/PropertyIds.cxx +++ b/writerfilter/source/dmapper/PropertyIds.cxx @@ -393,6 +393,7 @@ OUString PropertyNameSupplier::GetName( PropertyIds eId ) const case PROP_TABLE_INTEROP_GRAB_BAG : sName = "TableInteropGrabBag"; break; case PROP_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING : sName = "ApplyParagraphMarkFormatToNumbering"; break; case PROP_CELL_DIRECTION: sName = "CellDirection"; break; + case PROP_CELL_HIDE_MARK: sName = "CellHideMark"; break; } ::std::pair aInsertIt = m_pImpl->aNameMap.insert( PropertyNameMap_t::value_type( eId, sName )); diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx index f1543befba4f..3510e6274771 100644 --- a/writerfilter/source/dmapper/PropertyIds.hxx +++ b/writerfilter/source/dmapper/PropertyIds.hxx @@ -365,6 +365,7 @@ enum PropertyIds ,PROP_INDEX_ENTRY_TYPE ,PROP_APPLY_PARAGRAPH_MARK_FORMAT_TO_NUMBERING ,PROP_CELL_DIRECTION + ,PROP_CELL_HIDE_MARK }; struct PropertyNameSupplier_Impl; class PropertyNameSupplier diff --git a/writerfilter/source/dmapper/TablePropertiesHandler.cxx b/writerfilter/source/dmapper/TablePropertiesHandler.cxx index 64172a0a4d56..21160f753fdf 100644 --- a/writerfilter/source/dmapper/TablePropertiesHandler.cxx +++ b/writerfilter/source/dmapper/TablePropertiesHandler.cxx @@ -380,6 +380,14 @@ namespace dmapper { insertTableProps(pTblIndMap); } } + break; + case NS_ooxml::LN_CT_TcPrBase_hideMark: + if (nIntValue) + { + TablePropertyMapPtr pPropMap(new TablePropertyMap()); + pPropMap->Insert(PROP_CELL_HIDE_MARK, uno::makeAny(nIntValue)); + cellProps(pPropMap); + } break; default: // Not handled here, give the next handler a chance. -- cgit v1.2.3