[Libreoffice-commits] core.git: include/svtools include/vcl svtools/source vcl/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Thu Sep 6 14:19:11 UTC 2018


 include/svtools/ruler.hxx        |    3 ++
 include/vcl/outdev.hxx           |    3 +-
 svtools/source/control/ruler.cxx |   41 ++++++++++++++++++++++++++++++++++++---
 vcl/source/outdev/text.cxx       |    6 +++--
 4 files changed, 47 insertions(+), 6 deletions(-)

New commits:
commit bcb9be395cd7e382777b041fc90869883f726850
Author:     Miklos Vajna <vmiklos at collabora.co.uk>
AuthorDate: Thu Sep 6 14:55:13 2018 +0200
Commit:     Miklos Vajna <vmiklos at collabora.co.uk>
CommitDate: Thu Sep 6 16:18:47 2018 +0200

    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 at collabora.co.uk>
    Tested-by: Jenkins

diff --git a/include/svtools/ruler.hxx b/include/svtools/ruler.hxx
index bcf4bc27acb3..c89550e3f6a2 100644
--- a/include/svtools/ruler.hxx
+++ b/include/svtools/ruler.hxx
@@ -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,
diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index ba15a974f78d..1aa842b46cd5 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -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& );
 
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);
     }
 }
 
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index e6b63a0a4286..820df543bc5d 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -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 )
     {


More information about the Libreoffice-commits mailing list