sc/qa/unit/data/ods/RowHeightTdf165003.ods |binary sc/qa/unit/subsequent_filters_test4.cxx | 23 +++++++++++ sc/source/core/data/column2.cxx | 57 ++++++++++++++++++----------- 3 files changed, 60 insertions(+), 20 deletions(-)
New commits: commit 625c2d11465e4bfe861f8e7a214d2e8e257518f3 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Feb 11 12:54:02 2025 +0200 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Mar 6 10:29:58 2025 +0100 tdf#165003 Row height wrong at writing direction 90° regression from commit f91a411340ae204ce1e6997f22e0352a4c6a8355 Author: Noel Grandin <noelgran...@gmail.com> Date: Thu May 23 15:09:52 2024 +0200 reduce cost of calc column height calculation This also fixes another bug in the above commit where the code did not update nValue for the "else if (bBreak && !bWidth)" case Change-Id: I367a56c2cb555336e1d510efb0c7acac1447525f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181417 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> (cherry picked from commit f2639e2a98f114f053a13da669440587d56a0dd8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/181422 Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182305 Reviewed-by: Andras Timar <andras.ti...@collabora.com> Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/qa/unit/data/ods/RowHeightTdf165003.ods b/sc/qa/unit/data/ods/RowHeightTdf165003.ods new file mode 100644 index 000000000000..b3672f929f82 Binary files /dev/null and b/sc/qa/unit/data/ods/RowHeightTdf165003.ods differ diff --git a/sc/qa/unit/subsequent_filters_test4.cxx b/sc/qa/unit/subsequent_filters_test4.cxx index 8105c3981e0a..eb8fe8f28e46 100644 --- a/sc/qa/unit/subsequent_filters_test4.cxx +++ b/sc/qa/unit/subsequent_filters_test4.cxx @@ -391,6 +391,29 @@ CPPUNIT_TEST_FIXTURE(ScFiltersTest4, testRowHeightODS) CPPUNIT_ASSERT_MESSAGE("Row should have an automatic height.", !bManual); } +CPPUNIT_TEST_FIXTURE(ScFiltersTest4, testRowHeightTdf165003) +{ + createScDoc("ods/RowHeightTdf165003.ods"); + + SCTAB nTab = 0; + SCROW nRow = 0; + ScDocument* pDoc = getScDoc(); + + int nHeight = pDoc->GetRowHeight(nRow, nTab, false); + CPPUNIT_ASSERT_EQUAL(256, nHeight); + nHeight = pDoc->GetRowHeight(++nRow, nTab, false); + CPPUNIT_ASSERT_EQUAL(256, nHeight); + nHeight = pDoc->GetRowHeight(++nRow, nTab, false); + CPPUNIT_ASSERT_EQUAL(256, nHeight); + nHeight = pDoc->GetRowHeight(++nRow, nTab, false); + CPPUNIT_ASSERT_EQUAL(256, nHeight); + // this row has 90-degree rotated text, and without the fix, would have had zero height. + nHeight = pDoc->GetRowHeight(++nRow, nTab, false); + CPPUNIT_ASSERT_EQUAL(582, nHeight); + nHeight = pDoc->GetRowHeight(++nRow, nTab, false); + CPPUNIT_ASSERT_EQUAL(256, nHeight); +} + CPPUNIT_TEST_FIXTURE(ScFiltersTest4, testRichTextContentODS) { createScDoc("ods/rich-text-cells.ods"); diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index 9cbccff50c1d..b3cb434cd94b 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -310,7 +310,10 @@ tools::Long ScColumn::GetNeededSize( tools::Long nWidth = 0; if ( eOrient != SvxCellOrientation::Standard ) { - nWidth = pDev->GetTextHeight(); + tools::Long nHeight = pDev->GetTextHeight(); + // swap width and height + nValue = bWidth ? nHeight : pDev->GetTextWidth( aValStr ); + nWidth = nHeight; } else if ( nRotate ) { @@ -363,7 +366,10 @@ tools::Long ScColumn::GetNeededSize( } } else if (bBreak && !bWidth) + { nWidth = pDev->GetTextWidth(aValStr); + nValue = pDev->GetTextHeight(); + } else // in the common case (height), avoid calling the expensive GetTextWidth nValue = bWidth ? pDev->GetTextWidth( aValStr ) : pDev->GetTextHeight(); commit 150b7e19a436681166730b2d2d05d50e73e497e4 Author: Mike Kaganski <mike.kagan...@collabora.com> AuthorDate: Fri May 24 14:46:05 2024 +0500 Commit: Andras Timar <andras.ti...@collabora.com> CommitDate: Thu Mar 6 10:29:47 2025 +0100 Avoid more cases of unneeded GetTextWidth Change-Id: I45ccf6e3c84f22d46b42c36179cb380ca803d08b Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168014 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kagan...@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/182552 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Andras Timar <andras.ti...@collabora.com> diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index f8fc1f5b8527..9cbccff50c1d 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -307,26 +307,33 @@ tools::Long ScColumn::GetNeededSize( { // SetFont is moved up - Size aSize; + tools::Long nWidth = 0; if ( eOrient != SvxCellOrientation::Standard ) { - aSize = Size( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); - tools::Long nTemp = aSize.Width(); - aSize.setWidth( aSize.Height() ); - aSize.setHeight( nTemp ); + nWidth = pDev->GetTextHeight(); } else if ( nRotate ) { //TODO: take different X/Y scaling into consideration - aSize = Size( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); + // avoid calling the expensive GetTextWidth when not needed + auto TextWidth = [&, w = std::optional<tools::Long>()]() mutable + { + if (!w) + w = pDev->GetTextWidth(aValStr); + return *w; + }; + auto TextHeight = [&, h = std::optional<tools::Long>()]() mutable + { + if (!h) + h = pDev->GetTextHeight(); + return *h; + }; double nRealOrient = toRadians(nRotate); double nCosAbs = fabs( cos( nRealOrient ) ); double nSinAbs = fabs( sin( nRealOrient ) ); - tools::Long nHeight = static_cast<tools::Long>( aSize.Height() * nCosAbs + aSize.Width() * nSinAbs ); - tools::Long nWidth; if ( eRotMode == SVX_ROTATE_MODE_STANDARD ) - nWidth = static_cast<tools::Long>( aSize.Width() * nCosAbs + aSize.Height() * nSinAbs ); + nWidth = static_cast<tools::Long>( TextWidth() * nCosAbs + TextHeight() * nSinAbs ); else if ( rOptions.bTotalSize ) { nWidth = conditionalScaleFunc(rDocument.GetColWidth( nCol,nTab ), nPPT); @@ -338,21 +345,25 @@ tools::Long ScColumn::GetNeededSize( (bInPrintTwips ? 1.0 : nPPT) * nCosAbs / nSinAbs ); } else - nWidth = static_cast<tools::Long>( aSize.Height() / nSinAbs ); //TODO: limit? + nWidth = static_cast<tools::Long>( TextHeight() / nSinAbs ); //TODO: limit? - if ( bBreak && !rOptions.bTotalSize ) + if (bWidth) + nValue = nWidth; + else { - // limit size for line break - tools::Long nCmp = pDev->GetFont().GetFontSize().Height() * SC_ROT_BREAK_FACTOR; - if ( nHeight > nCmp ) - nHeight = nCmp; + tools::Long nHeight = static_cast<tools::Long>( TextHeight() * nCosAbs + TextWidth() * nSinAbs ); + if ( bBreak && !rOptions.bTotalSize ) + { + // limit size for line break + tools::Long nCmp = pDev->GetFont().GetFontSize().Height() * SC_ROT_BREAK_FACTOR; + if ( nHeight > nCmp ) + nHeight = nCmp; + } + nValue = nHeight; } - - aSize = Size( nWidth, nHeight ); - nValue = bWidth ? aSize.Width() : aSize.Height(); } else if (bBreak && !bWidth) - aSize = Size( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); + nWidth = pDev->GetTextWidth(aValStr); else // in the common case (height), avoid calling the expensive GetTextWidth nValue = bWidth ? pDev->GetTextWidth( aValStr ) : pDev->GetTextHeight(); @@ -382,7 +393,7 @@ tools::Long ScColumn::GetNeededSize( pMargin->GetLeftMargin() - pMargin->GetRightMargin() - nIndent), nPPTX); nDocSize = (nDocSize * 9) / 10; // for safety - if ( aSize.Width() > nDocSize ) + if (nWidth > nDocSize) bEditEngine = true; } }