svtools: less text layout calls in Ruler
Number of GenericSalLayout::LayoutText() calls during Writer startup: 2603 -> 1616 (18 -> 1 layouts / included number). Change-Id: I9a1a1131707bb6bc31683bbf609319f4bc22de92 Reviewed-on: https://gerrit.libreoffice.org/60087 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins
This commit is contained in:
@@ -28,6 +28,7 @@
|
||||
#include <vcl/window.hxx>
|
||||
#include <vcl/virdev.hxx>
|
||||
#include <vcl/field.hxx>
|
||||
#include <vcl/vcllayout.hxx>
|
||||
|
||||
#include <svtools/accessibleruler.hxx>
|
||||
|
||||
@@ -661,6 +662,8 @@ private:
|
||||
|
||||
rtl::Reference<SvtRulerAccessible> mxAccContext;
|
||||
|
||||
std::map<OUString, SalLayoutGlyphs> maTextGlyphs;
|
||||
|
||||
SVT_DLLPRIVATE void ImplVDrawLine(vcl::RenderContext& rRenderContext, long nX1, long nY1, long nX2, long nY2 );
|
||||
SVT_DLLPRIVATE void ImplVDrawRect(vcl::RenderContext& rRenderContext, long nX1, long nY1, long nX2, long nY2 );
|
||||
SVT_DLLPRIVATE void ImplVDrawText(vcl::RenderContext& rRenderContext, long nX, long nY, const OUString& rText,
|
||||
|
||||
@@ -1071,7 +1071,8 @@ public:
|
||||
*/
|
||||
bool GetTextBoundRect( tools::Rectangle& rRect,
|
||||
const OUString& rStr, sal_Int32 nBase = 0, sal_Int32 nIndex = 0, sal_Int32 nLen = -1,
|
||||
sal_uLong nLayoutWidth = 0, const long* pDXArray = nullptr ) const;
|
||||
sal_uLong nLayoutWidth = 0, const long* pDXArray = nullptr,
|
||||
const SalLayoutGlyphs* pGlyphs = nullptr ) const;
|
||||
|
||||
tools::Rectangle ImplGetTextBoundRect( const SalLayout& );
|
||||
|
||||
|
||||
@@ -62,6 +62,37 @@ using namespace ::com::sun::star::accessibility;
|
||||
#define RULER_UNIT_LINE 10
|
||||
#define RULER_UNIT_COUNT 11
|
||||
|
||||
namespace
|
||||
{
|
||||
/**
|
||||
* Pre-calculates glyph items for rText on rRenderContext. Subsequent calls
|
||||
* avoid the calculation and just return a pointer to rTextGlyphs.
|
||||
*/
|
||||
SalLayoutGlyphs* lcl_GetRulerTextGlyphs(vcl::RenderContext& rRenderContext, const OUString& rText,
|
||||
SalLayoutGlyphs& rTextGlyphs)
|
||||
{
|
||||
if (!rTextGlyphs.empty())
|
||||
// Use pre-calculated result.
|
||||
return &rTextGlyphs;
|
||||
|
||||
// Calculate glyph items.
|
||||
|
||||
std::unique_ptr<SalLayout> pLayout = rRenderContext.ImplLayout(
|
||||
rText, 0, rText.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.
|
||||
rTextGlyphs = *pGlyphs;
|
||||
|
||||
return &rTextGlyphs;
|
||||
}
|
||||
}
|
||||
|
||||
class ImplRulerData
|
||||
{
|
||||
friend class Ruler;
|
||||
@@ -311,7 +342,9 @@ void Ruler::ImplVDrawRect(vcl::RenderContext& rRenderContext, long nX1, long nY1
|
||||
void Ruler::ImplVDrawText(vcl::RenderContext& rRenderContext, long nX, long nY, const OUString& rText, long nMin, long nMax)
|
||||
{
|
||||
tools::Rectangle aRect;
|
||||
rRenderContext.GetTextBoundRect(aRect, rText);
|
||||
SalLayoutGlyphs* pTextLayout
|
||||
= lcl_GetRulerTextGlyphs(rRenderContext, rText, maTextGlyphs[rText]);
|
||||
rRenderContext.GetTextBoundRect(aRect, rText, 0, 0, -1, 0, nullptr, pTextLayout);
|
||||
|
||||
long nShiftX = ( aRect.GetWidth() / 2 ) + aRect.Left();
|
||||
long nShiftY = ( aRect.GetHeight() / 2 ) + aRect.Top();
|
||||
@@ -319,9 +352,11 @@ void Ruler::ImplVDrawText(vcl::RenderContext& rRenderContext, long nX, long nY,
|
||||
if ( (nX > -RULER_CLIP) && (nX < mnVirWidth + RULER_CLIP) && ( nX < nMax - nShiftX ) && ( nX > nMin + nShiftX ) )
|
||||
{
|
||||
if ( mnWinStyle & WB_HORZ )
|
||||
rRenderContext.DrawText(Point(nX - nShiftX, nY - nShiftY), rText);
|
||||
rRenderContext.DrawText(Point(nX - nShiftX, nY - nShiftY), rText, 0, -1, nullptr,
|
||||
nullptr, pTextLayout);
|
||||
else
|
||||
rRenderContext.DrawText(Point(nY - nShiftX, nX - nShiftY), rText);
|
||||
rRenderContext.DrawText(Point(nY - nShiftX, nX - nShiftY), rText, 0, -1, nullptr,
|
||||
nullptr, pTextLayout);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2344,7 +2344,8 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c
|
||||
bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
|
||||
const OUString& rStr, sal_Int32 nBase,
|
||||
sal_Int32 nIndex, sal_Int32 nLen,
|
||||
sal_uLong nLayoutWidth, const long* pDXAry ) const
|
||||
sal_uLong nLayoutWidth, const long* pDXAry,
|
||||
const SalLayoutGlyphs* pGlyphs ) const
|
||||
{
|
||||
bool bRet = false;
|
||||
rRect.SetEmpty();
|
||||
@@ -2368,7 +2369,8 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
|
||||
}
|
||||
}
|
||||
|
||||
pSalLayout = ImplLayout( rStr, nIndex, nLen, aPoint, nLayoutWidth, pDXAry );
|
||||
pSalLayout = ImplLayout(rStr, nIndex, nLen, aPoint, nLayoutWidth, pDXAry, SalLayoutFlags::NONE,
|
||||
nullptr, pGlyphs);
|
||||
tools::Rectangle aPixelRect;
|
||||
if( pSalLayout )
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user