DOCX import: improve btLr table cell support

The problem was that in case the contents didn't fit into a single line,
multiple lines were created, which is not what btLr wants. Set the size
type to fixed in this case.

Change-Id: Ibab1313f95dc16dd0366d21a00109a6f38fa3526
This commit is contained in:
Miklos Vajna
2013-02-22 17:08:39 +01:00
parent 5dff2d0822
commit 0208ead70a
5 changed files with 37 additions and 1 deletions

Binary file not shown.

View File

@@ -51,6 +51,7 @@
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <com/sun/star/table/BorderLine2.hpp>
#include <com/sun/star/table/TableBorder2.hpp>
#include <com/sun/star/text/SizeType.hpp>
#include <vcl/svapp.hxx>
@@ -115,6 +116,7 @@ public:
void testN793998();
void testGroupshapeLine();
void testN779642();
void testTbLrHeight();
CPPUNIT_TEST_SUITE(Test);
#if !defined(MACOSX) && !defined(WNT)
@@ -182,6 +184,7 @@ void Test::run()
{"n793998.docx", &Test::testN793998},
{"groupshape-line.docx", &Test::testGroupshapeLine},
{"n779642.docx", &Test::testN779642},
{"tblr-height.docx", &Test::testTbLrHeight},
};
header();
for (unsigned int i = 0; i < SAL_N_ELEMENTS(aMethods); ++i)
@@ -1183,6 +1186,16 @@ void Test::testN779642()
CPPUNIT_ASSERT_EQUAL_MESSAGE("Wrong vertical orientation relation", nValue, text::RelOrientation::PAGE_PRINT_AREA);
}
void Test::testTbLrHeight()
{
uno::Reference<text::XTextTablesSupplier> xTextTablesSupplier(mxComponent, uno::UNO_QUERY);
uno::Reference<container::XIndexAccess> xTables(xTextTablesSupplier->getTextTables(), uno::UNO_QUERY);
uno::Reference<text::XTextTable> xTable(xTables->getByIndex(0), uno::UNO_QUERY);
uno::Reference<table::XTableRows> xTableRows(xTable->getRows(), uno::UNO_QUERY);
// btLr text direction was imported as MIN, it should be FIX to avoid incorrectly large height in case of too much content.
CPPUNIT_ASSERT_EQUAL(text::SizeType::FIX, getProperty<sal_Int16>(xTableRows->getByIndex(0), "SizeType"));
}
CPPUNIT_TEST_SUITE_REGISTRATION(Test);
CPPUNIT_PLUGIN_IMPLEMENT();

View File

@@ -52,6 +52,7 @@ DomainMapperTableManager::DomainMapperTableManager(bool bOOXML) :
m_nTableWidth(0),
m_bOOXML( bOOXML ),
m_bPushCurrentWidth(false),
m_bRowSizeTypeInserted(false),
m_pTablePropsHandler( new TablePropertiesHandler( bOOXML ) )
{
m_pTablePropsHandler->SetTableManager( this );
@@ -261,10 +262,18 @@ bool DomainMapperTableManager::sprm(Sprm & rSprm)
SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue );
break;
case 3: // btLr
{
// We have to fake this text direction
pPropMap->Insert( PROP_FRM_DIRECTION, false, uno::makeAny( text::WritingMode2::LR_TB ));
pPropMap->Insert( PROP_CHAR_ROTATION, false, uno::makeAny( sal_Int16( 900 ) ));
SAL_INFO( "writerfilter", "Have inserted textDirection " << nIntValue );
// We're faking a text direction, so don't allow multiple lines.
TablePropertyMapPtr pRowPropMap( new TablePropertyMap );
pRowPropMap->Insert(PROP_SIZE_TYPE, false, uno::makeAny(text::SizeType::FIX));
m_bRowSizeTypeInserted = true;
insertRowProps(pRowPropMap);
}
break;
case 4: // lrTbV
pPropMap->Insert( PROP_FRM_DIRECTION, false, uno::makeAny( text::WritingMode2::LR_TB ));
@@ -583,6 +592,7 @@ void DomainMapperTableManager::endOfRowAction()
pCellWidths->clear();
m_nGridBefore = m_nGridAfter = 0;
m_bRowSizeTypeInserted = false;
#ifdef DEBUG_DOMAINMAPPER
dmapper_logger->endElement();

View File

@@ -54,6 +54,8 @@ class DomainMapperTableManager : public DomainMapperTableManager_Base_t
bool m_bPushCurrentWidth;
/// Individual table cell width values, used only in case the number of cells doesn't match the table grid.
::std::vector< IntVectorPtr > m_aCellWidths;
/// Remember if a cell already set this, then it should not be set at a row level.
bool m_bRowSizeTypeInserted;
TablePropertiesHandler *m_pTablePropsHandler;
PropertyMapPtr m_pStyleProps;
@@ -119,6 +121,11 @@ public:
DomainMapperTableManager_Base_t::insertTableProps( pProps );
};
bool IsRowSizeTypeInserted() const
{
return m_bRowSizeTypeInserted;
}
};
}}

View File

@@ -24,6 +24,7 @@
#include "MeasureHandler.hxx"
#include "TablePropertiesHandler.hxx"
#include "TDefTableHandler.hxx"
#include "DomainMapperTableManager.hxx"
#include <ooxml/resourceids.hxx>
#include <doctok/sprmids.hxx>
@@ -92,7 +93,12 @@ namespace dmapper {
MeasureHandlerPtr pMeasureHandler( new MeasureHandler );
pProperties->resolve(*pMeasureHandler);
TablePropertyMapPtr pPropMap( new TablePropertyMap );
pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ));
// In case a cell already wanted fixed size, we should not overwrite it here.
DomainMapperTableManager* pManager = dynamic_cast<DomainMapperTableManager*>(m_pTableManager);
if (!pManager || !pManager->IsRowSizeTypeInserted())
pPropMap->Insert( PROP_SIZE_TYPE, false, uno::makeAny( pMeasureHandler->GetRowHeightSizeType() ), false);
pPropMap->Insert( PROP_HEIGHT, false, uno::makeAny(pMeasureHandler->getMeasureValue() ));
insertRowProps(pPropMap);
}