Kaydet (Commit) 433fce65 authored tarafından Miklos Vajna's avatar Miklos Vajna

vcl: less text layout calls in ListBox

Number of GenericSalLayout::LayoutText() calls during Writer startup at
this call-site: 1068 -> 614.

Change-Id: I3bef56e550294a6b2c9fe73c0c6531249c9f1f30
Reviewed-on: https://gerrit.libreoffice.org/60164
Tested-by: Jenkins
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst f3d6c44c
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
#include <vcl/button.hxx> #include <vcl/button.hxx>
#include <vcl/floatwin.hxx> #include <vcl/floatwin.hxx>
#include <vcl/quickselectionengine.hxx> #include <vcl/quickselectionengine.hxx>
#include <vcl/vcllayout.hxx>
#include <set> #include <set>
#include <vector> #include <vector>
...@@ -45,6 +46,7 @@ enum LB_EVENT_TYPE ...@@ -45,6 +46,7 @@ enum LB_EVENT_TYPE
struct ImplEntryType struct ImplEntryType
{ {
OUString maStr; OUString maStr;
SalLayoutGlyphs maStrGlyphs;
Image maImage; Image maImage;
void* mpUserData; void* mpUserData;
bool mbIsSelected; bool mbIsSelected;
...@@ -69,6 +71,9 @@ struct ImplEntryType ...@@ -69,6 +71,9 @@ struct ImplEntryType
mbIsSelected = false; mbIsSelected = false;
mpUserData = nullptr; mpUserData = nullptr;
} }
/// Computes maStr's text layout (glyphs), cached in maStrGlyphs.
SalLayoutGlyphs* GetTextGlyphs(OutputDevice* pOutputDevice);
}; };
class ImplEntryList class ImplEntryList
......
...@@ -601,6 +601,27 @@ struct ImplEntryMetrics ...@@ -601,6 +601,27 @@ struct ImplEntryMetrics
long nImgHeight; long nImgHeight;
}; };
SalLayoutGlyphs* ImplEntryType::GetTextGlyphs(OutputDevice* pOutputDevice)
{
if (!maStrGlyphs.empty())
// Use pre-calculated result.
return &maStrGlyphs;
std::unique_ptr<SalLayout> pLayout = pOutputDevice->ImplLayout(
maStr, 0, maStr.getLength(), Point(0, 0), 0, nullptr, SalLayoutFlags::GlyphItemsOnly);
if (!pLayout)
return nullptr;
const SalLayoutGlyphs* pGlyphs = pLayout->GetGlyphs();
if (!pGlyphs)
return nullptr;
// Remember the calculation result.
maStrGlyphs = *pGlyphs;
return &maStrGlyphs;
}
void ImplListBoxWindow::EnableQuickSelection( bool b ) void ImplListBoxWindow::EnableQuickSelection( bool b )
{ {
maQuickSelectionEngine.SetEnabled( b ); maQuickSelectionEngine.SetEnabled( b );
...@@ -637,7 +658,9 @@ void ImplListBoxWindow::ImplUpdateEntryMetrics( ImplEntryType& rEntry ) ...@@ -637,7 +658,9 @@ void ImplListBoxWindow::ImplUpdateEntryMetrics( ImplEntryType& rEntry )
else else
{ {
// normal single line case // normal single line case
aMetrics.nTextWidth = static_cast<sal_uInt16>(GetTextWidth( rEntry.maStr )); const SalLayoutGlyphs* pGlyphs = rEntry.GetTextGlyphs(this);
aMetrics.nTextWidth
= static_cast<sal_uInt16>(GetTextWidth(rEntry.maStr, 0, -1, nullptr, pGlyphs));
if( aMetrics.nTextWidth > mnMaxTxtWidth ) if( aMetrics.nTextWidth > mnMaxTxtWidth )
mnMaxTxtWidth = aMetrics.nTextWidth; mnMaxTxtWidth = aMetrics.nTextWidth;
aMetrics.nEntryWidth = mnMaxTxtWidth; aMetrics.nEntryWidth = mnMaxTxtWidth;
......
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