sc/inc/document.hxx | 2 sc/qa/unit/uicalc/data/tdf99913.xlsx |binary sc/qa/unit/uicalc/uicalc.cxx | 9 ++++ sc/source/filter/oox/worksheethelper.cxx | 65 ++++++++++++++++++++++++++----- vcl/source/fontsubset/sft.cxx | 24 ++++++++++- 5 files changed, 87 insertions(+), 13 deletions(-)
New commits: commit ae60c27f936642ecd4391d11fcd73a6d461d0b7f Author: Tünde Tóth <toth.tu...@nisz.hu> AuthorDate: Wed Mar 24 14:07:15 2021 +0100 Commit: László Németh <nem...@numbertext.org> CommitDate: Tue Mar 30 13:36:24 2021 +0200 tdf#99913 XLSX import: set filtered flag for rows hidden by AutoFilter to support copying the result of filtering. Unlike ODS and XLS, XLSX doesn't differentiates filtered and manually hidden rows, and without this fix, copy of the unupdated data of the loaded filtering contained the hidden rows, too. Change-Id: I390d1a84b9bf275f3d3782756553b2f236487758 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113040 Tested-by: László Németh <nem...@numbertext.org> Reviewed-by: László Németh <nem...@numbertext.org> diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index fb5980cc5b5e..72f84cd9ba9b 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -1947,7 +1947,7 @@ public: SC_DLLPUBLIC SCROW LastVisibleRow(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; SCROW CountVisibleRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; - bool RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const; + SC_DLLPUBLIC bool RowFiltered(SCROW nRow, SCTAB nTab, SCROW* pFirstRow = nullptr, SCROW* pLastRow = nullptr) const; bool HasFilteredRows(SCROW nStartRow, SCROW nEndRow, SCTAB nTab) const; bool ColFiltered(SCCOL nCol, SCTAB nTab) const; SC_DLLPUBLIC void SetRowFiltered(SCROW nStartRow, SCROW nEndRow, SCTAB nTab, bool bFiltered); diff --git a/sc/qa/unit/uicalc/data/tdf99913.xlsx b/sc/qa/unit/uicalc/data/tdf99913.xlsx new file mode 100644 index 000000000000..3fd18a12984a Binary files /dev/null and b/sc/qa/unit/uicalc/data/tdf99913.xlsx differ diff --git a/sc/qa/unit/uicalc/uicalc.cxx b/sc/qa/unit/uicalc/uicalc.cxx index 818361ec9d83..48cde55df479 100644 --- a/sc/qa/unit/uicalc/uicalc.cxx +++ b/sc/qa/unit/uicalc/uicalc.cxx @@ -1387,6 +1387,15 @@ CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf116215) CPPUNIT_ASSERT_EQUAL(OUString("=SUM(A2:B2)"), aFormula); } +CPPUNIT_TEST_FIXTURE(ScUiCalcTest, testTdf99913) +{ + ScModelObj* pModelObj = createDoc("tdf99913.xlsx"); + ScDocument* pDoc = pModelObj->GetDocument(); + CPPUNIT_ASSERT(pDoc); + + CPPUNIT_ASSERT(pDoc->RowFiltered(2, 0)); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/filter/oox/worksheethelper.cxx b/sc/source/filter/oox/worksheethelper.cxx index fe30d788b623..6d07bfd57cad 100644 --- a/sc/source/filter/oox/worksheethelper.cxx +++ b/sc/source/filter/oox/worksheethelper.cxx @@ -68,6 +68,8 @@ #include <stlsheet.hxx> #include <stlpool.hxx> #include <cellvalue.hxx> +#include <columnspanset.hxx> +#include <dbdata.hxx> #include <svl/stritem.hxx> #include <editeng/eeitem.hxx> @@ -341,9 +343,12 @@ private: void convertColumns( OutlineLevelVec& orColLevels, const ValueRange& rColRange, const ColumnModel& rModel ); /** Converts row properties for all rows in the sheet. */ - void convertRows(); + void convertRows(const std::vector<sc::ColRowSpan>& rSpans); /** Converts row properties. */ - void convertRows( OutlineLevelVec& orRowLevels, const ValueRange& rRowRange, const RowModel& rModel, double fDefHeight = -1.0 ); + void convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange, + const RowModel& rModel, + const std::vector<sc::ColRowSpan>& rSpans, + double fDefHeight = -1.0); /** Converts outline grouping for the passed column or row. */ void convertOutlines( OutlineLevelVec& orLevels, sal_Int32 nColRow, sal_Int32 nLevel, bool bCollapsed, bool bRows ); @@ -947,7 +952,37 @@ void WorksheetGlobals::finalizeWorksheetImport() lclUpdateProgressBar( mxFinalProgress, 0.5 ); convertColumns(); - convertRows(); + + // tdf#99913 rows hidden by filter need extra flag + ScDocument& rDoc = getScDocument(); + std::vector<sc::ColRowSpan> aSpans; + SCTAB nTab = getSheetIndex(); + ScDBData* pDBData = rDoc.GetAnonymousDBData(nTab); + if (pDBData && pDBData->HasAutoFilter()) + { + ScRange aRange; + pDBData->GetArea(aRange); + SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row()); + SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row()); + aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow)); + } + ScDBCollection* pDocColl = rDoc.GetDBCollection(); + if (!pDocColl->empty()) + { + ScDBCollection::NamedDBs& rDBs = pDocColl->getNamedDBs(); + for (const auto& rxDB : rDBs) + { + if (rxDB->GetTab() == nTab && rxDB->HasAutoFilter()) + { + ScRange aRange; + rxDB->GetArea(aRange); + SCCOLROW nStartRow = static_cast<SCCOLROW>(aRange.aStart.Row()); + SCCOLROW nEndRow = static_cast<SCCOLROW>(aRange.aEnd.Row()); + aSpans.push_back(sc::ColRowSpan(nStartRow, nEndRow)); + } + } + } + convertRows(aSpans); lclUpdateProgressBar( mxFinalProgress, 1.0 ); } @@ -1201,7 +1236,7 @@ void WorksheetGlobals::convertColumns( OutlineLevelVec& orColLevels, convertOutlines( orColLevels, rColRange.mnFirst, rModel.mnLevel, rModel.mbCollapsed, false ); } -void WorksheetGlobals::convertRows() +void WorksheetGlobals::convertRows(const std::vector<sc::ColRowSpan>& rSpans) { sal_Int32 nNextRow = 0; sal_Int32 nMaxRow = mrMaxApiPos.Row(); @@ -1214,21 +1249,23 @@ void WorksheetGlobals::convertRows() ValueRange aRowRange( ::std::max( rowModel.first, nNextRow ), ::std::min( rowModel.second.second, nMaxRow ) ); // process gap between two row models, use default row model if( nNextRow < aRowRange.mnFirst ) - convertRows( aRowLevels, ValueRange( nNextRow, aRowRange.mnFirst - 1 ), maDefRowModel ); + convertRows(aRowLevels, ValueRange(nNextRow, aRowRange.mnFirst - 1), maDefRowModel, + rSpans); // process the row model - convertRows( aRowLevels, aRowRange, rowModel.second.first, maDefRowModel.mfHeight ); + convertRows(aRowLevels, aRowRange, rowModel.second.first, rSpans, maDefRowModel.mfHeight); // cache next row to be processed nNextRow = aRowRange.mnLast + 1; } // remaining default rows to end of sheet - convertRows( aRowLevels, ValueRange( nNextRow, nMaxRow ), maDefRowModel ); + convertRows(aRowLevels, ValueRange(nNextRow, nMaxRow), maDefRowModel, rSpans); // close remaining row outlines spanning to end of sheet convertOutlines( aRowLevels, nMaxRow + 1, 0, false, true ); } -void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels, - const ValueRange& rRowRange, const RowModel& rModel, double fDefHeight ) +void WorksheetGlobals::convertRows(OutlineLevelVec& orRowLevels, const ValueRange& rRowRange, + const RowModel& rModel, + const std::vector<sc::ColRowSpan>& rSpans, double fDefHeight) { // row height: convert points to row height in 1/100 mm double fHeight = (rModel.mfHeight >= 0.0) ? rModel.mfHeight : fDefHeight; @@ -1251,6 +1288,16 @@ void WorksheetGlobals::convertRows( OutlineLevelVec& orRowLevels, { ScDocument& rDoc = getScDocument(); rDoc.SetRowHidden( nStartRow, nEndRow, nTab, true ); + for (const auto& rSpan : rSpans) + { + // tdf#99913 rows hidden by filter need extra flag + if (rSpan.mnStart <= nStartRow && nStartRow <= rSpan.mnEnd) + { + SCROW nLast = ::std::min(nEndRow, rSpan.mnEnd); + rDoc.SetRowFiltered(nStartRow, nLast, nTab, true); + break; + } + } } // outline settings for this row range commit 7622d225efa0459ceaecbf947c0912823b5ff5c8 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Tue Mar 30 10:17:47 2021 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Tue Mar 30 13:36:15 2021 +0200 cid#1222237 Untrusted loop bound Change-Id: Ic7d5da2242498aa5d53d77d6479042c71b87f057 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113342 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> diff --git a/vcl/source/fontsubset/sft.cxx b/vcl/source/fontsubset/sft.cxx index a02e179dca93..bd5cb5c188c6 100644 --- a/vcl/source/fontsubset/sft.cxx +++ b/vcl/source/fontsubset/sft.cxx @@ -1803,11 +1803,29 @@ static void DumpSfnts(FILE *outf, sal_uInt8 *sfntP, sal_uInt32 sfntLen) else { sal_uInt8 *glyf = pRecordStart; + sal_uInt8 *eof = pRecordStart + nMaxLenPossible; for (sal_uInt32 j = 0; j < go->nGlyphs - 1; j++) { - sal_uInt32 o = go->offs[j]; - sal_uInt32 l = go->offs[j + 1] - o; - HexFmtBlockWrite(h, glyf + o, l); + sal_uInt32 nStartOffset = go->offs[j]; + sal_uInt8 *pSubRecordStart = glyf + nStartOffset; + if (pSubRecordStart > eof) + { + SAL_WARN( "vcl.fonts", "DumpSfnts start glyf claims offset of " + << pSubRecordStart - sfntP << " but max possible is " << eof - sfntP); + break; + } + + sal_uInt32 nEndOffset = go->offs[j + 1]; + sal_uInt8 *pSubRecordEnd = glyf + nEndOffset; + if (pSubRecordEnd > eof) + { + SAL_WARN( "vcl.fonts", "DumpSfnts end glyf offset of " + << pSubRecordEnd - sfntP << " but max possible is " << eof - sfntP); + break; + } + + sal_uInt32 l = nEndOffset - nStartOffset; + HexFmtBlockWrite(h, pSubRecordStart, l); } } HexFmtBlockWrite(h, pad, (4 - (len & 3)) & 3); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits