bnc#865381 DOCX import: handle <w:hideMark> table cell property

Change-Id: Id0dd34110376168e34df4956869608895b86abfe
This commit is contained in:
Miklos Vajna 2014-08-14 13:54:18 +02:00
parent ffdc8780eb
commit d1278ef484
6 changed files with 71 additions and 0 deletions

Binary file not shown.

View file

@ -2320,6 +2320,19 @@ DECLARE_OOXMLIMPORT_TEST(testFloatingTableSectionColumns, "floating-table-sectio
CPPUNIT_ASSERT( tableWidth.toInt32() > 10000 );
}
DECLARE_OOXMLIMPORT_TEST(testHidemark, "hidemark.docx")
{
// Problem was that <w:hideMark> cell property was ignored.
uno::Reference<text::XTextTablesSupplier> xTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTablesSupplier->getTextTables( ), uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTextTable(xTables->getByIndex(0), uno::UNO_QUERY);
uno::Reference<table::XTableRows> xTableRows(xTextTable->getRows(), uno::UNO_QUERY);
// Height should be minimal
CPPUNIT_ASSERT_EQUAL(convertTwipToMm100(MINLAY), getProperty<sal_Int64>(xTableRows->getByIndex(1), "Height"));
// Size type was MIN, should be FIX to avoid considering the end of paragraph marker.
CPPUNIT_ASSERT_EQUAL(text::SizeType::FIX, getProperty<sal_Int16>(xTableRows->getByIndex(1), "SizeType"));
}
#endif
CPPUNIT_PLUGIN_IMPLEMENT();

View file

@ -29,9 +29,11 @@
#include <com/sun/star/text/RelOrientation.hpp>
#include <com/sun/star/text/SizeType.hpp>
#include <com/sun/star/text/VertOrientation.hpp>
#include <com/sun/star/text/XTextRangeCompare.hpp>
#include <com/sun/star/style/ParagraphAdjust.hpp>
#include <dmapperLoggers.hxx>
#include <TablePositionHandler.hxx>
#include <ConversionHelper.hxx>
#ifdef DEBUG_DOMAINMAPPER
#include <PropertyMapHelper.hxx>
@ -804,12 +806,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]->isSet(PROP_CELL_HIDE_MARK))
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<text::XTextRangeCompare> 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_DOMAINMAPPER
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();
@ -826,6 +866,14 @@ RowPropertyValuesSeq_t DomainMapperTableHandler::endTableGetRowProperties()
// tblHeader is only our property, remove before the property map hits UNO
(*aRowIter)->Erase(PROP_TBL_HEADER);
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<sal_Int32>(ConversionHelper::convertTwipToMM100(MINLAY))));
}
aRowProperties[nRow] = (*aRowIter)->GetPropertyValues();
#ifdef DEBUG_DOMAINMAPPER
((*aRowIter)->dumpXml( dmapper_logger ));

View file

@ -399,6 +399,7 @@ OUString PropertyNameSupplier::GetName( PropertyIds eId ) const
case PROP_PARA_CNF_STYLE: sName = "ParaCnfStyle"; break;
case PROP_CELL_CNF_STYLE: sName = "CellCnfStyle"; break;
case PROP_ROW_CNF_STYLE: sName = "RowCnfStyle"; break;
case PROP_CELL_HIDE_MARK: sName = "CellHideMark"; break;
}
::std::pair<PropertyNameMap_t::iterator,bool> aInsertIt =
m_pImpl->aNameMap.insert( PropertyNameMap_t::value_type( eId, sName ));

View file

@ -371,6 +371,7 @@ enum PropertyIds
,PROP_PARA_CNF_STYLE
,PROP_CELL_CNF_STYLE
,PROP_ROW_CNF_STYLE
,PROP_CELL_HIDE_MARK
};
struct PropertyNameSupplier_Impl;
class PropertyNameSupplier

View file

@ -383,6 +383,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.