diff options
author | Noel Grandin <noel@peralex.com> | 2021-10-26 13:59:26 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-10-26 18:16:02 +0200 |
commit | 95cc31f15712bcd2b9829a4f9708374647af6e74 (patch) | |
tree | c608d9c83b0619b4821125d6bf23e4ff2b4eb36e /vcl | |
parent | b94921fb8eecbb784a6711e36f1e5b4b1a6afaf6 (diff) |
tdf#144513 improve perf when breaking long lines
use the clip rectangle to stop early when the text exceeds the height
of the cell
Change-Id: I63dadc5b63c1f6c0852e0ba86a58f18c2b207cca
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124221
Tested-by: Noel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'vcl')
-rw-r--r-- | vcl/source/gdi/pdfwriter_impl.cxx | 2 | ||||
-rw-r--r-- | vcl/source/outdev/text.cxx | 13 |
2 files changed, 11 insertions, 4 deletions
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx index 45e2a844da18..a342cba1854d 100644 --- a/vcl/source/gdi/pdfwriter_impl.cxx +++ b/vcl/source/gdi/pdfwriter_impl.cxx @@ -6571,7 +6571,7 @@ void PDFWriterImpl::drawText( const tools::Rectangle& rRect, const OUString& rOr { vcl::DefaultTextLayout aLayout( *this ); OUString aLastLine; - OutputDevice::ImplGetTextLines( aMultiLineInfo, nWidth, aStr, nStyle, aLayout ); + OutputDevice::ImplGetTextLines( rRect, nTextHeight, aMultiLineInfo, nWidth, aStr, nStyle, aLayout ); sal_Int32 nLines = nHeight/nTextHeight; nFormatLines = aMultiLineInfo.Count(); if ( !nLines ) diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx index 58e0b0e6a8b9..ed3eefba56e2 100644 --- a/vcl/source/outdev/text.cxx +++ b/vcl/source/outdev/text.cxx @@ -478,7 +478,8 @@ void OutputDevice::ImplDrawText( SalLayout& rSalLayout ) ImplDrawTextDirect( rSalLayout, mbTextLines ); } -tools::Long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo, +tools::Long OutputDevice::ImplGetTextLines( const tools::Rectangle& rRect, const tools::Long nTextHeight, + ImplMultiTextLineInfo& rLineInfo, tools::Long nWidth, const OUString& rStr, DrawTextFlags nStyle, const vcl::ITextLayout& _rLayout ) { @@ -491,6 +492,8 @@ tools::Long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo, if (rStr.isEmpty()) return 0; + const bool bClipping = (nStyle & DrawTextFlags::Clip) && !(nStyle & DrawTextFlags::EndEllipsis); + tools::Long nMaxLineWidth = 0; const bool bHyphenate = (nStyle & DrawTextFlags::WordBreakHyphenation) == DrawTextFlags::WordBreakHyphenation; css::uno::Reference< css::linguistic2::XHyphenator > xHyph; @@ -505,6 +508,7 @@ tools::Long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo, css::uno::Reference<css::i18n::XBreakIterator> xBI; sal_Int32 nPos = 0; sal_Int32 nLen = rStr.getLength(); + sal_Int32 nCurrentTextY = 0; while ( nPos < nLen ) { sal_Int32 nBreakPos = nPos; @@ -541,6 +545,9 @@ tools::Long OutputDevice::ImplGetTextLines( ImplMultiTextLineInfo& rLineInfo, if ( ( nPos < nLen ) && ( rStr[ nPos ] == '\n' ) && ( rStr[ nPos-1 ] == '\r' ) ) nPos++; } + nCurrentTextY += nTextHeight; + if (bClipping && nCurrentTextY > rRect.GetHeight()) + break; } #ifdef DBG_UTIL @@ -1528,7 +1535,7 @@ void OutputDevice::ImplDrawText( OutputDevice& rTargetDevice, const tools::Recta if ( nTextHeight ) { - tools::Long nMaxTextWidth = ImplGetTextLines( aMultiLineInfo, nWidth, aStr, nStyle, _rLayout ); + tools::Long nMaxTextWidth = ImplGetTextLines( rRect, nTextHeight, aMultiLineInfo, nWidth, aStr, nStyle, _rLayout ); sal_Int32 nLines = static_cast<sal_Int32>(nHeight/nTextHeight); OUString aLastLine; nFormatLines = aMultiLineInfo.Count(); @@ -1814,7 +1821,7 @@ tools::Rectangle OutputDevice::GetTextRect( const tools::Rectangle& rRect, nMaxWidth = 0; vcl::DefaultTextLayout aDefaultLayout( *const_cast< OutputDevice* >( this ) ); - ImplGetTextLines( aMultiLineInfo, nWidth, aStr, nStyle, _pTextLayout ? *_pTextLayout : aDefaultLayout ); + ImplGetTextLines( rRect, nTextHeight, aMultiLineInfo, nWidth, aStr, nStyle, _pTextLayout ? *_pTextLayout : aDefaultLayout ); nFormatLines = aMultiLineInfo.Count(); if ( !nTextHeight ) nTextHeight = 1; |