Kaydet (Commit) 5aade07d authored tarafından Noel Power's avatar Noel Power Kaydeden (comit) Eike Rathke

correctly handle repeated row heights for empty rows ( fdo#59973 )

rollup of 9327467a and b75bf09a

it seems both xls & xlsx export suffer from problems with multiple row heights
repeated ( if those rows are empty )

better default row detection ( associated with fdo#55621 )

previous patch associated with fdo#55621 compared single instances of row
heights to determine the default height, it didn't take into account though
repeated rows. Additionally the limit of rows heights ( where rows were empty )
considered when exporting xlsx was the old 65535 limit.

Change-Id: I3ed68a81517a3e55d1de1954fcb99e7cb39be337
Reviewed-on: https://gerrit.libreoffice.org/2004Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
Tested-by: 's avatarEike Rathke <erack@redhat.com>
üst faffc3f8
...@@ -77,6 +77,7 @@ public: ...@@ -77,6 +77,7 @@ public:
void test(); void test();
void testPasswordExport(); void testPasswordExport();
void testConditionalFormatExportXLSX(); void testConditionalFormatExportXLSX();
void testMiscRowHeightExport();
CPPUNIT_TEST_SUITE(ScExportTest); CPPUNIT_TEST_SUITE(ScExportTest);
CPPUNIT_TEST(test); CPPUNIT_TEST(test);
...@@ -84,6 +85,7 @@ public: ...@@ -84,6 +85,7 @@ public:
CPPUNIT_TEST(testPasswordExport); CPPUNIT_TEST(testPasswordExport);
#endif #endif
CPPUNIT_TEST(testConditionalFormatExportXLSX); CPPUNIT_TEST(testConditionalFormatExportXLSX);
CPPUNIT_TEST(testMiscRowHeightExport);
CPPUNIT_TEST_SUITE_END(); CPPUNIT_TEST_SUITE_END();
private: private:
...@@ -297,6 +299,78 @@ void ScExportTest::testConditionalFormatExportXLSX() ...@@ -297,6 +299,78 @@ void ScExportTest::testConditionalFormatExportXLSX()
testCondFile(aCSVPath, pDoc, 0); testCondFile(aCSVPath, pDoc, 0);
} }
void ScExportTest::testMiscRowHeightExport()
{
struct TestParam
{
struct RowData
{
SCROW nStartRow;
SCROW nEndRow;
SCTAB nTab;
int nExpectedHeight;
};
const char* sTestDoc;
int nImportType;
int nExportType;
int nRowData;
RowData* pData;
};
TestParam::RowData DfltRowData[] =
{
{ 0, 4, 0, 529 },
{ 5, 10, 0, 1058 },
{ 17, 20, 0, 1767 },
{ 1048573, 1048575, 0, 529 },
};
TestParam::RowData EmptyRepeatRowData[] =
{
{ 0, 4, 0, 529 },
{ 5, 10, 0, 1058 },
{ 17, 20, 0, 1767 },
};
TestParam aTestValues[] =
{
{ "miscrowheights.", XLSX, XLSX, SAL_N_ELEMENTS(DfltRowData), DfltRowData },
{ "miscrowheights.", XLSX, XLS, SAL_N_ELEMENTS(DfltRowData), DfltRowData },
{ "miscemptyrepeatedrowheights.", ODS, XLSX, SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData },
{ "miscemptyrepeatedrowheights.", ODS, XLS, SAL_N_ELEMENTS(EmptyRepeatRowData), EmptyRepeatRowData },
};
for ( unsigned int index=0; index<SAL_N_ELEMENTS(aTestValues); ++index )
{
OUString sFileName = OUString::createFromAscii( aTestValues[ index ].sTestDoc );
printf("aTestValues[%d] %s\n", index, OUStringToOString( sFileName, RTL_TEXTENCODING_UTF8 ).getStr() );
int nImportType = aTestValues[ index ].nImportType;
int nExportType = aTestValues[ index ].nExportType;
ScDocShellRef xShell = loadDocument( sFileName, nImportType );
CPPUNIT_ASSERT(xShell.Is());
ScDocShellRef xDocSh = saveAndReload(&(*xShell), nExportType );
CPPUNIT_ASSERT(xDocSh.Is());
ScDocument* pDoc = xDocSh->GetDocument();
for (int i=0; i<aTestValues[ index ].nRowData; ++i)
{
SCROW nRow = aTestValues[ index ].pData[ i].nStartRow;
SCROW nEndRow = aTestValues[ index ].pData[ i ].nEndRow;
SCTAB nTab = aTestValues[ index ].pData[ i ].nTab;
int nExpectedHeight = aTestValues[ index ].pData[ i ].nExpectedHeight;
for ( ; nRow <= nEndRow; ++nRow )
{
printf("\t checking row %d for height %d\n", nRow, nExpectedHeight );
int nHeight = sc::TwipsToHMM( pDoc->GetRowHeight(nRow, nTab, false) );
CPPUNIT_ASSERT_EQUAL(nExpectedHeight, nHeight);
}
}
}
}
ScExportTest::ScExportTest() ScExportTest::ScExportTest()
: m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data")) : m_aBaseString(RTL_CONSTASCII_USTRINGPARAM("/sc/qa/unit/data"))
{ {
......
...@@ -1708,6 +1708,8 @@ XclExpRow::XclExpRow( const XclExpRoot& rRoot, sal_uInt32 nXclRow, ...@@ -1708,6 +1708,8 @@ XclExpRow::XclExpRow( const XclExpRoot& rRoot, sal_uInt32 nXclRow,
mnFlags( EXC_ROW_DEFAULTFLAGS ), mnFlags( EXC_ROW_DEFAULTFLAGS ),
mnXFIndex( EXC_XF_DEFAULTCELL ), mnXFIndex( EXC_XF_DEFAULTCELL ),
mnOutlineLevel( 0 ), mnOutlineLevel( 0 ),
mnXclRowRpt( 1 ),
mnCurrentRow( nXclRow ),
mbAlwaysEmpty( bAlwaysEmpty ), mbAlwaysEmpty( bAlwaysEmpty ),
mbEnabled( true ) mbEnabled( true )
{ {
...@@ -1921,7 +1923,11 @@ void XclExpRow::WriteCellList( XclExpStream& rStrm ) ...@@ -1921,7 +1923,11 @@ void XclExpRow::WriteCellList( XclExpStream& rStrm )
void XclExpRow::Save( XclExpStream& rStrm ) void XclExpRow::Save( XclExpStream& rStrm )
{ {
if( mbEnabled ) if( mbEnabled )
XclExpRecord::Save( rStrm ); {
mnCurrentRow = mnXclRow;
for ( sal_uInt32 i = 0; i < mnXclRowRpt; ++i, ++mnCurrentRow )
XclExpRecord::Save( rStrm );
}
} }
void XclExpRow::InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase ) void XclExpRow::InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase )
...@@ -1950,7 +1956,7 @@ void XclExpRow::InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase ...@@ -1950,7 +1956,7 @@ void XclExpRow::InsertCell( XclExpCellRef xCell, size_t nPos, bool bIsMergedBase
void XclExpRow::WriteBody( XclExpStream& rStrm ) void XclExpRow::WriteBody( XclExpStream& rStrm )
{ {
rStrm << static_cast< sal_uInt16 >(mnXclRow) rStrm << static_cast< sal_uInt16 >(mnCurrentRow)
<< GetFirstUsedXclCol() << GetFirstUsedXclCol()
<< GetFirstFreeXclCol() << GetFirstFreeXclCol()
<< mnHeight << mnHeight
...@@ -1965,23 +1971,27 @@ void XclExpRow::SaveXml( XclExpXmlStream& rStrm ) ...@@ -1965,23 +1971,27 @@ void XclExpRow::SaveXml( XclExpXmlStream& rStrm )
return; return;
sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream(); sax_fastparser::FSHelperPtr& rWorksheet = rStrm.GetCurrentStream();
bool haveFormat = ::get_flag( mnFlags, EXC_ROW_USEDEFXF ); bool haveFormat = ::get_flag( mnFlags, EXC_ROW_USEDEFXF );
rWorksheet->startElement( XML_row, mnCurrentRow = mnXclRow + 1;
XML_r, OString::valueOf( (sal_Int32) (mnXclRow+1) ).getStr(), for ( sal_uInt32 i=0; i<mnXclRowRpt; ++i )
// OOXTODO: XML_spans, optional {
XML_s, haveFormat ? lcl_GetStyleId( rStrm, mnXFIndex ).getStr() : NULL, rWorksheet->startElement( XML_row,
XML_customFormat, XclXmlUtils::ToPsz( haveFormat ), XML_r, OString::valueOf( (sal_Int32) (mnCurrentRow++) ).getStr(),
XML_ht, OString::valueOf( (double) mnHeight / 20.0 ).getStr(), // OOXTODO: XML_spans, optional
XML_hidden, XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_ROW_HIDDEN ) ), XML_s, haveFormat ? lcl_GetStyleId( rStrm, mnXFIndex ).getStr() : NULL,
XML_customHeight, XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_ROW_UNSYNCED ) ), XML_customFormat, XclXmlUtils::ToPsz( haveFormat ),
XML_outlineLevel, OString::valueOf( (sal_Int32) mnOutlineLevel ).getStr(), XML_ht, OString::valueOf( (double) mnHeight / 20.0 ).getStr(),
XML_collapsed, XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_ROW_COLLAPSED ) ), XML_hidden, XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_ROW_HIDDEN ) ),
// OOXTODO: XML_thickTop, bool XML_customHeight, XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_ROW_UNSYNCED ) ),
// OOXTODO: XML_thickBot, bool XML_outlineLevel, OString::valueOf( (sal_Int32) mnOutlineLevel ).getStr(),
// OOXTODO: XML_ph, bool XML_collapsed, XclXmlUtils::ToPsz( ::get_flag( mnFlags, EXC_ROW_COLLAPSED ) ),
FSEND ); // OOXTODO: XML_thickTop, bool
// OOXTODO: XML_extLst // OOXTODO: XML_thickBot, bool
maCellList.SaveXml( rStrm ); // OOXTODO: XML_ph, bool
rWorksheet->endElement( XML_row ); FSEND );
// OOXTODO: XML_extLst
maCellList.SaveXml( rStrm );
rWorksheet->endElement( XML_row );
}
} }
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
...@@ -2002,7 +2012,7 @@ void XclExpRowBuffer::AppendCell( XclExpCellRef xCell, bool bIsMergedBase ) ...@@ -2002,7 +2012,7 @@ void XclExpRowBuffer::AppendCell( XclExpCellRef xCell, bool bIsMergedBase )
void XclExpRowBuffer::CreateRows( SCROW nFirstFreeScRow ) void XclExpRowBuffer::CreateRows( SCROW nFirstFreeScRow )
{ {
if( nFirstFreeScRow > 0 ) if( nFirstFreeScRow > 0 )
GetOrCreateRow( static_cast< sal_uInt16 >( nFirstFreeScRow - 1 ), true ); GetOrCreateRow( ::std::max ( nFirstFreeScRow - 1, GetMaxPos().Row() ), true );
} }
void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt16Vec& rColXFIndexes ) void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt16Vec& rColXFIndexes )
...@@ -2023,6 +2033,9 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt ...@@ -2023,6 +2033,9 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt
XclExpDefaultRowData aMaxDefData; XclExpDefaultRowData aMaxDefData;
size_t nMaxDefCount = 0; size_t nMaxDefCount = 0;
// only look for default format in existing rows, if there are more than unused // only look for default format in existing rows, if there are more than unused
XclExpRow* pPrev = NULL;
typedef std::vector< XclExpRow* > XclRepeatedRows;
XclRepeatedRows aRepeated;
for (itr = itrBeg; itr != itrEnd; ++itr) for (itr = itrBeg; itr != itrEnd; ++itr)
{ {
const RowRef& rRow = itr->second; const RowRef& rRow = itr->second;
...@@ -2037,11 +2050,37 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt ...@@ -2037,11 +2050,37 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData, const ScfUInt
aMaxDefData = aDefData; aMaxDefData = aDefData;
} }
} }
if ( pPrev )
{
sal_uInt32 nRpt = rRow->GetXclRow() - pPrev->GetXclRow();
pPrev->SetXclRowRpt( nRpt );
if ( nRpt > 1 )
aRepeated.push_back( pPrev );
if ( pPrev->IsDefaultable())
{
XclExpDefaultRowData aDefData( *pPrev );
size_t& rnDefCount = aDefRowMap[ aDefData ];
rnDefCount += ( pPrev->GetXclRowRpt() - 1 );
if( rnDefCount > nMaxDefCount )
{
nMaxDefCount = rnDefCount;
aMaxDefData = aDefData;
}
}
}
pPrev = rRow.get();
} }
// return the default row format to caller // return the default row format to caller
rDefRowData = aMaxDefData; rDefRowData = aMaxDefData;
// now disable repeating extra (empty) rows that are equal to
// default row height
for ( XclRepeatedRows::iterator it = aRepeated.begin(), it_end = aRepeated.end(); it != it_end; ++it)
{
if ( (*it)->GetXclRowRpt() > 1 && (*it)->GetHeight() == rDefRowData.mnHeight )
(*it)->SetXclRowRpt( 1 );
}
// *** Disable unused ROW records, find used area *** --------------------- // *** Disable unused ROW records, find used area *** ---------------------
sal_uInt16 nFirstUsedXclCol = SAL_MAX_UINT16; sal_uInt16 nFirstUsedXclCol = SAL_MAX_UINT16;
......
...@@ -917,6 +917,8 @@ public: ...@@ -917,6 +917,8 @@ public:
virtual void Save( XclExpStream& rStrm ); virtual void Save( XclExpStream& rStrm );
virtual void SaveXml( XclExpXmlStream& rStrm ); virtual void SaveXml( XclExpXmlStream& rStrm );
inline sal_uInt32 GetXclRowRpt() const { return mnXclRowRpt; }
inline void SetXclRowRpt( sal_uInt32 nRpt ){ mnXclRowRpt = nRpt; }
private: private:
/** Initializes the record data. Called from constructors. */ /** Initializes the record data. Called from constructors. */
void Init( sal_uInt16 nXclRow, XclExpRowOutlineBuffer* pOutlineBfr ); void Init( sal_uInt16 nXclRow, XclExpRowOutlineBuffer* pOutlineBfr );
...@@ -935,6 +937,8 @@ private: ...@@ -935,6 +937,8 @@ private:
sal_uInt16 mnFlags; /// Flags for the ROW record. sal_uInt16 mnFlags; /// Flags for the ROW record.
sal_uInt16 mnXFIndex; /// Default row formatting. sal_uInt16 mnXFIndex; /// Default row formatting.
sal_uInt16 mnOutlineLevel; /// Outline Level (for OOXML) sal_uInt16 mnOutlineLevel; /// Outline Level (for OOXML)
sal_uInt32 mnXclRowRpt;
sal_uInt32 mnCurrentRow;
bool mbAlwaysEmpty; /// true = Do not add blank cells in Finalize(). bool mbAlwaysEmpty; /// true = Do not add blank cells in Finalize().
bool mbEnabled; /// true = Write this ROW record. bool mbEnabled; /// true = Write this ROW record.
}; };
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment