diff options
author | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-09-06 14:55:13 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.co.uk> | 2018-09-06 16:18:47 +0200 |
commit | bcb9be395cd7e382777b041fc90869883f726850 (patch) | |
tree | d47b73dfed123ff067fd56735d836533270aeb52 /svtools | |
parent | e75c8384c4663b0603a30f66d0d8e390d03a3bf6 (diff) |
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
Diffstat (limited to 'svtools')
-rw-r--r-- | svtools/source/control/ruler.cxx | 41 |
1 files changed, 38 insertions, 3 deletions
diff --git a/svtools/source/control/ruler.cxx b/svtools/source/control/ruler.cxx index acfea2528f31..d343532e40a0 100644 --- a/svtools/source/control/ruler.cxx +++ b/svtools/source/control/ruler.cxx @@ -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); } } |