[Libreoffice-commits] core.git: include/vcl vcl/headless vcl/inc vcl/qa vcl/quartz vcl/source vcl/unx vcl/win

Noel Grandin noel.grandin at collabora.co.uk
Tue Nov 14 09:20:09 UTC 2017


 include/vcl/outdev.hxx                   |    9 +++-
 vcl/headless/svptext.cxx                 |    2 -
 vcl/inc/headless/svpgdi.hxx              |    3 +
 vcl/inc/quartz/salgdi.h                  |    3 +
 vcl/inc/salgdi.hxx                       |    3 +
 vcl/inc/sallayout.hxx                    |    6 +--
 vcl/inc/textrender.hxx                   |    3 +
 vcl/inc/unx/cairotextrender.hxx          |    3 +
 vcl/inc/unx/genpspgraphics.h             |    3 +
 vcl/inc/unx/salgdi.h                     |    3 +
 vcl/inc/win/salgdi.h                     |    3 +
 vcl/qa/cppunit/complextext.cxx           |    2 +
 vcl/quartz/salgdi.cxx                    |    4 +-
 vcl/source/gdi/pdfwriter_impl.cxx        |    9 +---
 vcl/source/gdi/print2.cxx                |    6 +--
 vcl/source/gdi/sallayout.cxx             |   10 ++---
 vcl/source/outdev/font.cxx               |   20 ++++------
 vcl/source/outdev/text.cxx               |   61 ++++++++++---------------------
 vcl/source/outdev/textline.cxx           |    4 --
 vcl/source/window/status.cxx             |   12 ++----
 vcl/unx/generic/gdi/cairotextrender.cxx  |    4 +-
 vcl/unx/generic/gdi/font.cxx             |    2 -
 vcl/unx/generic/print/genpspgraphics.cxx |    4 +-
 vcl/win/gdi/winlayout.cxx                |    4 +-
 24 files changed, 82 insertions(+), 101 deletions(-)

New commits:
commit 8f54136caa786523fd224f6c98fc8e7c45cd805d
Author: Noel Grandin <noel.grandin at collabora.co.uk>
Date:   Tue Oct 17 13:40:38 2017 +0200

    use std::unique_ptr for SalLayout
    
    to make the ownership passing around more obvious
    
    Change-Id: I147ec6d9cfe7566cf3600685e0730ed741c2d90d
    Reviewed-on: https://gerrit.libreoffice.org/43454
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/include/vcl/outdev.hxx b/include/vcl/outdev.hxx
index dab8630eab47..e5d496a29e97 100644
--- a/include/vcl/outdev.hxx
+++ b/include/vcl/outdev.hxx
@@ -1315,7 +1315,8 @@ public:
     SAL_DLLPRIVATE void         ReMirror( vcl::Region &rRegion ) const;
     SAL_DLLPRIVATE bool         ImplIsRecordLayout() const;
     virtual bool                HasMirroredGraphics() const;
-    SAL_DLLPRIVATE SalLayout*   ImplLayout( const OUString&, sal_Int32 nIndex, sal_Int32 nLen,
+    SAL_DLLPRIVATE std::unique_ptr<SalLayout>
+                                ImplLayout( const OUString&, sal_Int32 nIndex, sal_Int32 nLen,
                                             const Point& rLogicPos = Point(0,0), long nLogicWidth=0,
                                             const long* pLogicDXArray=nullptr, SalLayoutFlags flags = SalLayoutFlags::NONE,
                                             vcl::TextLayoutCache const* = nullptr) const;
@@ -1323,9 +1324,11 @@ public:
                                                          DeviceCoordinate nPixelWidth, const DeviceCoordinate* pPixelDXArray,
                                                          SalLayoutFlags flags = SalLayoutFlags::NONE,
                                                          vcl::TextLayoutCache const* = nullptr) const;
-    SAL_DLLPRIVATE SalLayout*   ImplGlyphFallbackLayout( SalLayout*, ImplLayoutArgs& ) const;
+    SAL_DLLPRIVATE std::unique_ptr<SalLayout>
+                                ImplGlyphFallbackLayout( std::unique_ptr<SalLayout>, ImplLayoutArgs& ) const;
     // tells whether this output device is RTL in an LTR UI or LTR in a RTL UI
-    SAL_DLLPRIVATE SalLayout*   getFallbackFont(
+    SAL_DLLPRIVATE std::unique_ptr<SalLayout>
+                                getFallbackFont(
                                     FontSelectPattern &rFontSelData, int nFallbackLevel,
                                     ImplLayoutArgs& rLayoutArgs) const;
 
diff --git a/vcl/headless/svptext.cxx b/vcl/headless/svptext.cxx
index 1149e5ca1b49..47f158d56b51 100644
--- a/vcl/headless/svptext.cxx
+++ b/vcl/headless/svptext.cxx
@@ -101,7 +101,7 @@ bool SvpSalGraphics::GetGlyphOutline(const GlyphItem& rGlyph, basegfx::B2DPolyPo
     return m_aTextRenderImpl.GetGlyphOutline(rGlyph, rPolyPoly);
 }
 
-SalLayout* SvpSalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
+std::unique_ptr<SalLayout> SvpSalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
 {
     return m_aTextRenderImpl.GetTextLayout(rArgs, nFallbackLevel);
 }
diff --git a/vcl/inc/headless/svpgdi.hxx b/vcl/inc/headless/svpgdi.hxx
index 6fe1b07a2af9..8204538cb132 100644
--- a/vcl/inc/headless/svpgdi.hxx
+++ b/vcl/inc/headless/svpgdi.hxx
@@ -164,7 +164,8 @@ public:
                                             Ucs2UIntMap& rUnicodeEnc ) override;
     virtual bool            GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
     virtual bool            GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
-    virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
+    virtual std::unique_ptr<SalLayout>
+                            GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
     virtual void            DrawTextLayout( const CommonSalLayout& ) override;
     virtual bool            supportsOperation( OutDevSupportType ) const override;
     virtual void            drawPixel( long nX, long nY ) override;
diff --git a/vcl/inc/quartz/salgdi.h b/vcl/inc/quartz/salgdi.h
index 47d53e7fdcdb..5a346b6a2098 100644
--- a/vcl/inc/quartz/salgdi.h
+++ b/vcl/inc/quartz/salgdi.h
@@ -378,7 +378,8 @@ public:
     virtual bool            GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
     virtual bool            GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
 
-    virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
+    virtual std::unique_ptr<SalLayout>
+                            GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
     virtual void            DrawTextLayout( const CommonSalLayout& ) override;
     virtual bool            supportsOperation( OutDevSupportType ) const override;
 
diff --git a/vcl/inc/salgdi.hxx b/vcl/inc/salgdi.hxx
index 1a9157ca9747..32b51f6630d9 100644
--- a/vcl/inc/salgdi.hxx
+++ b/vcl/inc/salgdi.hxx
@@ -192,7 +192,8 @@ public:
     virtual bool                GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) = 0;
     virtual bool                GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) = 0;
 
-    virtual SalLayout*          GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
+    virtual std::unique_ptr<SalLayout>
+                                GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
     virtual void                DrawTextLayout( const CommonSalLayout& ) = 0;
 
     virtual bool                supportsOperation( OutDevSupportType ) const = 0;
diff --git a/vcl/inc/sallayout.hxx b/vcl/inc/sallayout.hxx
index 9b169eabcd29..04d488d45fff 100644
--- a/vcl/inc/sallayout.hxx
+++ b/vcl/inc/sallayout.hxx
@@ -221,8 +221,8 @@ public:
     virtual bool    IsKashidaPosValid(int nCharPos) const override;
 
     // used only by OutputDevice::ImplLayout, TODO: make friend
-    explicit        MultiSalLayout( SalLayout& rBaseLayout );
-    void            AddFallback( SalLayout& rFallbackLayout,
+    explicit        MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout );
+    void            AddFallback( std::unique_ptr<SalLayout> pFallbackLayout,
                                  ImplLayoutRuns const &, const PhysicalFontFace* pFallbackFont );
     virtual bool    LayoutText( ImplLayoutArgs& ) override;
     virtual void    AdjustLayout( ImplLayoutArgs& ) override;
@@ -230,7 +230,7 @@ public:
 
     void SetIncomplete(bool bIncomplete);
 
-protected:
+public:
     virtual         ~MultiSalLayout() override;
 
 private:
diff --git a/vcl/inc/textrender.hxx b/vcl/inc/textrender.hxx
index ca21add07484..3866a54c6b6f 100644
--- a/vcl/inc/textrender.hxx
+++ b/vcl/inc/textrender.hxx
@@ -61,7 +61,8 @@ public:
 
     virtual bool                    GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) = 0;
     virtual bool                    GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) = 0;
-    virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
+    virtual std::unique_ptr<SalLayout>
+                                    GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) = 0;
     virtual void                    DrawTextLayout(const CommonSalLayout&) = 0;
 #if ENABLE_CAIRO_CANVAS
     virtual SystemFontData          GetSysFontData( int nFallbackLevel ) const = 0;
diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx
index 4670a6e61bae..5cc641a945d8 100644
--- a/vcl/inc/unx/cairotextrender.hxx
+++ b/vcl/inc/unx/cairotextrender.hxx
@@ -77,7 +77,8 @@ public:
 
     virtual bool                GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
     virtual bool                GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
-    virtual SalLayout*          GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
+    virtual std::unique_ptr<SalLayout>
+                                GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
     virtual void                DrawTextLayout(const CommonSalLayout&) override;
 #if ENABLE_CAIRO_CANVAS
     virtual SystemFontData      GetSysFontData( int nFallbackLevel ) const override;
diff --git a/vcl/inc/unx/genpspgraphics.h b/vcl/inc/unx/genpspgraphics.h
index 6e9511d49906..7c01d57e0786 100644
--- a/vcl/inc/unx/genpspgraphics.h
+++ b/vcl/inc/unx/genpspgraphics.h
@@ -113,7 +113,8 @@ public:
                                             Ucs2UIntMap& rUnicodeEnc ) override;
     virtual bool            GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
     virtual bool            GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
-    virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
+    virtual std::unique_ptr<SalLayout>
+                            GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
     virtual void            DrawTextLayout( const CommonSalLayout& ) override;
     virtual bool            supportsOperation( OutDevSupportType ) const override;
     virtual void            drawPixel( long nX, long nY ) override;
diff --git a/vcl/inc/unx/salgdi.h b/vcl/inc/unx/salgdi.h
index 4c5406354bdc..887039b6b1d3 100644
--- a/vcl/inc/unx/salgdi.h
+++ b/vcl/inc/unx/salgdi.h
@@ -143,7 +143,8 @@ public:
 
     virtual bool                    GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
     virtual bool                    GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
-    virtual SalLayout*              GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
+    virtual std::unique_ptr<SalLayout>
+                                    GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
     virtual void                    DrawTextLayout( const CommonSalLayout& ) override;
 
     virtual bool                    supportsOperation( OutDevSupportType ) const override;
diff --git a/vcl/inc/win/salgdi.h b/vcl/inc/win/salgdi.h
index caaa3f802631..2431b388c67b 100644
--- a/vcl/inc/win/salgdi.h
+++ b/vcl/inc/win/salgdi.h
@@ -380,7 +380,8 @@ public:
     virtual bool            GetGlyphBoundRect(const GlyphItem&, tools::Rectangle&) override;
     virtual bool            GetGlyphOutline(const GlyphItem&, basegfx::B2DPolyPolygon&) override;
 
-    virtual SalLayout*      GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
+    virtual std::unique_ptr<SalLayout>
+                            GetTextLayout( ImplLayoutArgs&, int nFallbackLevel ) override;
     virtual void            DrawTextLayout( const CommonSalLayout& ) override;
 
     virtual bool            supportsOperation( OutDevSupportType ) const override;
diff --git a/vcl/qa/cppunit/complextext.cxx b/vcl/qa/cppunit/complextext.cxx
index a0fba312aa9f..a9795c742640 100644
--- a/vcl/qa/cppunit/complextext.cxx
+++ b/vcl/qa/cppunit/complextext.cxx
@@ -15,6 +15,8 @@ std::ostream& operator<<(std::ostream& rStream, const std::vector<long>& rVec);
 #include <test/bootstrapfixture.hxx>
 
 #include <vcl/wrkwin.hxx>
+// workaround MSVC2015 issue with std::unique_ptr
+#include <sallayout.hxx>
 
 #include <osl/file.hxx>
 #include <osl/process.h>
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 89b92e6bc0c5..7db6c7b00927 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -512,10 +512,10 @@ void AquaSalGraphics::SetFont(const FontSelectPattern* pReqFont, int nFallbackLe
             );
 }
 
-SalLayout* AquaSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
+std::unique_ptr<SalLayout> AquaSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
 {
     if (mpTextStyle[nFallbackLevel])
-        return new CommonSalLayout(*mpTextStyle[nFallbackLevel]);
+        return std::unique_ptr<SalLayout>(new CommonSalLayout(*mpTextStyle[nFallbackLevel]));
 
     return nullptr;
 }
diff --git a/vcl/source/gdi/pdfwriter_impl.cxx b/vcl/source/gdi/pdfwriter_impl.cxx
index e9fa6ad99673..33ea6b0f194e 100644
--- a/vcl/source/gdi/pdfwriter_impl.cxx
+++ b/vcl/source/gdi/pdfwriter_impl.cxx
@@ -7039,11 +7039,10 @@ void PDFWriterImpl::drawText( const Point& rPos, const OUString& rText, sal_Int3
 
     // get a layout from the OutputDevice's SalGraphics
     // this also enforces font substitution and sets the font on SalGraphics
-    SalLayout* pLayout = m_pReferenceDevice->ImplLayout( rText, nIndex, nLen, rPos );
+    std::unique_ptr<SalLayout> pLayout = m_pReferenceDevice->ImplLayout( rText, nIndex, nLen, rPos );
     if( pLayout )
     {
         drawLayout( *pLayout, rText, bTextLines );
-        delete pLayout;
     }
 }
 
@@ -7055,11 +7054,10 @@ void PDFWriterImpl::drawTextArray( const Point& rPos, const OUString& rText, con
 
     // get a layout from the OutputDevice's SalGraphics
     // this also enforces font substitution and sets the font on SalGraphics
-    SalLayout* pLayout = m_pReferenceDevice->ImplLayout( rText, nIndex, nLen, rPos, 0, pDXArray );
+    std::unique_ptr<SalLayout> pLayout = m_pReferenceDevice->ImplLayout( rText, nIndex, nLen, rPos, 0, pDXArray );
     if( pLayout )
     {
         drawLayout( *pLayout, rText, true );
-        delete pLayout;
     }
 }
 
@@ -7071,11 +7069,10 @@ void PDFWriterImpl::drawStretchText( const Point& rPos, sal_uLong nWidth, const
 
     // get a layout from the OutputDevice's SalGraphics
     // this also enforces font substitution and sets the font on SalGraphics
-    SalLayout* pLayout = m_pReferenceDevice->ImplLayout( rText, nIndex, nLen, rPos, nWidth );
+    std::unique_ptr<SalLayout> pLayout = m_pReferenceDevice->ImplLayout( rText, nIndex, nLen, rPos, nWidth );
     if( pLayout )
     {
         drawLayout( *pLayout, rText, true );
-        delete pLayout;
     }
 }
 
diff --git a/vcl/source/gdi/print2.cxx b/vcl/source/gdi/print2.cxx
index 75f55716995c..75c5c1ae5b0d 100644
--- a/vcl/source/gdi/print2.cxx
+++ b/vcl/source/gdi/print2.cxx
@@ -585,14 +585,13 @@ tools::Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevic
             if( !aString.isEmpty() )
             {
                 // #105987# ImplLayout takes everything in logical coordinates
-                SalLayout* pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
+                std::unique_ptr<SalLayout> pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
                                                          rTextAct.GetLen(), rTextAct.GetPoint(),
                                                          0, rTextAct.GetDXArray() );
                 if( pSalLayout )
                 {
                     tools::Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
                     aActionBounds = rOut.PixelToLogic( aBoundRect );
-                    delete pSalLayout;
                 }
             }
         }
@@ -615,14 +614,13 @@ tools::Rectangle ImplCalcActionBounds( const MetaAction& rAct, const OutputDevic
             if( !aString.isEmpty() )
             {
                 // #105987# ImplLayout takes everything in logical coordinates
-                SalLayout* pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
+                std::unique_ptr<SalLayout> pSalLayout = rOut.ImplLayout( rTextAct.GetText(), rTextAct.GetIndex(),
                                                          rTextAct.GetLen(), rTextAct.GetPoint(),
                                                          rTextAct.GetWidth() );
                 if( pSalLayout )
                 {
                     tools::Rectangle aBoundRect( const_cast<OutputDevice&>(rOut).ImplGetTextBoundRect( *pSalLayout ) );
                     aActionBounds = rOut.PixelToLogic( aBoundRect );
-                    delete pSalLayout;
                 }
             }
         }
diff --git a/vcl/source/gdi/sallayout.cxx b/vcl/source/gdi/sallayout.cxx
index e277e661f61e..6184d18e2ca9 100644
--- a/vcl/source/gdi/sallayout.cxx
+++ b/vcl/source/gdi/sallayout.cxx
@@ -1024,15 +1024,15 @@ void GenericSalLayout::Simplify( bool bIsBase )
     m_GlyphItems.erase(m_GlyphItems.begin() + j, m_GlyphItems.end());
 }
 
-MultiSalLayout::MultiSalLayout( SalLayout& rBaseLayout )
+MultiSalLayout::MultiSalLayout( std::unique_ptr<SalLayout> pBaseLayout )
 :   SalLayout()
 ,   mnLevel( 1 )
 ,   mbIncomplete( false )
 {
     //maFallbackRuns[0].Clear();
     mpFallbackFonts[ 0 ] = nullptr;
-    mpLayouts[ 0 ]  = &rBaseLayout;
-    mnUnitsPerPixel = rBaseLayout.GetUnitsPerPixel();
+    mpLayouts[ 0 ]  = pBaseLayout.release();
+    mnUnitsPerPixel = mpLayouts[ 0 ]->GetUnitsPerPixel();
 }
 
 void MultiSalLayout::SetIncomplete(bool bIncomplete)
@@ -1047,14 +1047,14 @@ MultiSalLayout::~MultiSalLayout()
         delete mpLayouts[ i ];
 }
 
-void MultiSalLayout::AddFallback( SalLayout& rFallback,
+void MultiSalLayout::AddFallback( std::unique_ptr<SalLayout> pFallback,
     ImplLayoutRuns const & rFallbackRuns, const PhysicalFontFace* pFallbackFont )
 {
     if( mnLevel >= MAX_FALLBACK )
         return;
 
     mpFallbackFonts[ mnLevel ]  = pFallbackFont;
-    mpLayouts[ mnLevel ]        = &rFallback;
+    mpLayouts[ mnLevel ]        = pFallback.release();
     maFallbackRuns[ mnLevel-1 ] = rFallbackRuns;
     ++mnLevel;
 }
diff --git a/vcl/source/outdev/font.cxx b/vcl/source/outdev/font.cxx
index c018113a9ff5..2a5d88852fb2 100644
--- a/vcl/source/outdev/font.cxx
+++ b/vcl/source/outdev/font.cxx
@@ -1295,7 +1295,7 @@ void OutputDevice::ImplDrawEmphasisMarks( SalLayout& rSalLayout )
     mpMetaFile = pOldMetaFile;
 }
 
-SalLayout* OutputDevice::getFallbackFont(
+std::unique_ptr<SalLayout> OutputDevice::getFallbackFont(
     FontSelectPattern &rFontSelData, int nFallbackLevel,
     ImplLayoutArgs& rLayoutArgs) const
 {
@@ -1307,7 +1307,7 @@ SalLayout* OutputDevice::getFallbackFont(
     mpGraphics->SetFont( &rFontSelData, nFallbackLevel );
 
     rLayoutArgs.ResetPos();
-    SalLayout* pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel );
+    std::unique_ptr<SalLayout> pFallback = mpGraphics->GetTextLayout( rLayoutArgs, nFallbackLevel );
 
     if (!pFallback)
         return nullptr;
@@ -1315,7 +1315,6 @@ SalLayout* OutputDevice::getFallbackFont(
     if (!pFallback->LayoutText(rLayoutArgs))
     {
         // there is no need for a font that couldn't resolve anything
-        delete pFallback;
         return nullptr;
     }
 
@@ -1324,7 +1323,7 @@ SalLayout* OutputDevice::getFallbackFont(
     return pFallback;
 }
 
-SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLayoutArgs& rLayoutArgs ) const
+std::unique_ptr<SalLayout> OutputDevice::ImplGlyphFallbackLayout( std::unique_ptr<SalLayout> pSalLayout, ImplLayoutArgs& rLayoutArgs ) const
 {
     // This function relies on a valid mpFontInstance, if it doesn't exist bail out
     // - we'd have crashed later on anyway. At least here we can catch the error in debug
@@ -1337,7 +1336,7 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
     }
 
     // prepare multi level glyph fallback
-    MultiSalLayout* pMultiSalLayout = nullptr;
+    std::unique_ptr<MultiSalLayout> pMultiSalLayout;
     ImplLayoutRuns aLayoutRuns = rLayoutArgs.maRuns;
     rLayoutArgs.PrepareFallback();
     rLayoutArgs.mnFlags |= SalLayoutFlags::ForFallback;
@@ -1382,13 +1381,13 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
         }
 
         // create and add glyph fallback layout to multilayout
-        SalLayout* pFallback = getFallbackFont(aFontSelData,
+        std::unique_ptr<SalLayout> pFallback = getFallbackFont(aFontSelData,
             nFallbackLevel, rLayoutArgs);
         if (pFallback)
         {
             if( !pMultiSalLayout )
-                pMultiSalLayout = new MultiSalLayout( *pSalLayout );
-            pMultiSalLayout->AddFallback( *pFallback,
+                pMultiSalLayout.reset( new MultiSalLayout( std::move(pSalLayout) ) );
+            pMultiSalLayout->AddFallback( std::move(pFallback),
                 rLayoutArgs.maRuns, aFontSelData.mpFontData );
             if (nFallbackLevel == MAX_FALLBACK-1)
                 pMultiSalLayout->SetIncomplete(true);
@@ -1402,7 +1401,7 @@ SalLayout* OutputDevice::ImplGlyphFallbackLayout( SalLayout* pSalLayout, ImplLay
     }
 
     if( pMultiSalLayout && pMultiSalLayout->LayoutText( rLayoutArgs ) )
-        pSalLayout = pMultiSalLayout;
+        pSalLayout = std::move(pMultiSalLayout);
 
     // restore orig font settings
     pSalLayout->InitFont();
@@ -1426,7 +1425,7 @@ sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt,
                                             sal_Int32* pKashidaPosDropped ) const
 {
    // do layout
-    SalLayout* pSalLayout = ImplLayout( rTxt, nIdx, nLen );
+    std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rTxt, nIdx, nLen );
     if( !pSalLayout )
         return 0;
     sal_Int32 nDropped = 0;
@@ -1438,7 +1437,6 @@ sal_Int32 OutputDevice::ValidateKashidas ( const OUString& rTxt,
             ++nDropped;
         }
     }
-    delete pSalLayout;
     return nDropped;
 }
 
diff --git a/vcl/source/outdev/text.cxx b/vcl/source/outdev/text.cxx
index 7b1a8f957d38..1d93f7730aae 100644
--- a/vcl/source/outdev/text.cxx
+++ b/vcl/source/outdev/text.cxx
@@ -864,13 +864,11 @@ void OutputDevice::DrawText( const Point& rStartPt, const OUString& rStr,
     // without cache
     if(!pLayoutCache)
     {
-        SalLayout* pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt);
+        std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt);
         if(pSalLayout)
         {
             ImplDrawText( *pSalLayout );
-            delete pSalLayout;
         }
-
     }
     else
     {
@@ -953,11 +951,10 @@ void OutputDevice::DrawTextArray( const Point& rStartPt, const OUString& rStr,
     if( mbOutputClipped )
         return;
 
-    SalLayout* pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags);
+    std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry, flags);
     if( pSalLayout )
     {
         ImplDrawText( *pSalLayout );
-        delete pSalLayout;
     }
 
     if( mpAlphaVDev )
@@ -977,13 +974,15 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
         nLen = rStr.getLength() - nIndex;
     }
 
+    std::unique_ptr<SalLayout> xSalLayout;
     const SalLayout*  pSalLayout = pSalLayoutCache;
 
     if(!pSalLayoutCache)
     {
         // do layout
-        pSalLayout = ImplLayout(rStr, nIndex, nLen,
+        xSalLayout = ImplLayout(rStr, nIndex, nLen,
                 Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache);
+        pSalLayout = xSalLayout.get();
         if( !pSalLayout )
         {
             // The caller expects this to init the elements of pDXAry.
@@ -1009,9 +1008,6 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
     DeviceCoordinate nWidth = pSalLayout->FillDXArray( pDXPixelArray.get() );
     int nWidthFactor = pSalLayout->GetUnitsPerPixel();
 
-    if(!pSalLayoutCache)
-        delete pSalLayout;
-
     // convert virtual char widths to virtual absolute positions
     if( pDXPixelArray )
     {
@@ -1056,9 +1052,6 @@ long OutputDevice::GetTextArray( const OUString& rStr, long* pDXAry,
     long nWidth = pSalLayout->FillDXArray( pDXAry );
     int nWidthFactor = pSalLayout->GetUnitsPerPixel();
 
-    if(!pSalLayoutCache)
-        delete pSalLayout;
-
     // convert virtual char widths to virtual absolute positions
     if( pDXAry )
         for( int i = 1; i < nLen; ++i )
@@ -1094,14 +1087,13 @@ bool OutputDevice::GetCaretPositions( const OUString& rStr, long* pCaretXArray,
         nLen = rStr.getLength() - nIndex;
 
     // layout complex text
-    SalLayout* pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0) );
+    std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rStr, nIndex, nLen, Point(0,0) );
     if( !pSalLayout )
         return false;
 
     int nWidthFactor = pSalLayout->GetUnitsPerPixel();
     pSalLayout->GetCaretPositions( 2*nLen, pCaretXArray );
     long nWidth = pSalLayout->GetTextWidth();
-    delete pSalLayout;
 
     // fixup unknown caret positions
     int i;
@@ -1157,11 +1149,10 @@ void OutputDevice::DrawStretchText( const Point& rStartPt, sal_uLong nWidth,
     if ( !IsDeviceOutputNecessary() )
         return;
 
-    SalLayout* pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, nWidth);
+    std::unique_ptr<SalLayout> pSalLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, nWidth);
     if( pSalLayout )
     {
         ImplDrawText( *pSalLayout );
-        delete pSalLayout;
     }
 
     if( mpAlphaVDev )
@@ -1258,7 +1249,7 @@ ImplLayoutArgs OutputDevice::ImplPrepareLayoutArgs( OUString& rStr,
     return aLayoutArgs;
 }
 
-SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
+std::unique_ptr<SalLayout> OutputDevice::ImplLayout(const OUString& rOrigStr,
                                     sal_Int32 nMinIndex, sal_Int32 nLen,
                                     const Point& rLogicalPos, long nLogicalWidth,
                                     const long* pDXArray, SalLayoutFlags flags,
@@ -1334,13 +1325,12 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
             nPixelWidth, pDXPixelArray, flags, pLayoutCache);
 
     // get matching layout object for base font
-    SalLayout* pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 );
+    std::unique_ptr<SalLayout> pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 );
 
     // layout text
     if( pSalLayout && !pSalLayout->LayoutText( aLayoutArgs ) )
     {
-        delete pSalLayout;
-        pSalLayout = nullptr;
+        pSalLayout.reset();
     }
 
     if( !pSalLayout )
@@ -1349,7 +1339,7 @@ SalLayout* OutputDevice::ImplLayout(const OUString& rOrigStr,
     // do glyph fallback if needed
     // #105768# avoid fallback for very small font sizes
     if (aLayoutArgs.NeedFallback() && mpFontInstance->maFontSelData.mnHeight >= 3)
-        pSalLayout = ImplGlyphFallbackLayout(pSalLayout, aLayoutArgs);
+        pSalLayout = ImplGlyphFallbackLayout(std::move(pSalLayout), aLayoutArgs);
 
     // position, justify, etc. the layout
     pSalLayout->AdjustLayout( aLayoutArgs );
@@ -1379,12 +1369,11 @@ std::shared_ptr<vcl::TextLayoutCache> OutputDevice::CreateTextLayoutCache(
     ImplLayoutArgs aLayoutArgs = ImplPrepareLayoutArgs(copyBecausePrepareModifiesIt,
             0, rString.getLength(), 0, nullptr);
 
-    SalLayout *const pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 );
+    std::unique_ptr<SalLayout> pSalLayout = mpGraphics->GetTextLayout( aLayoutArgs, 0 );
     if (!pSalLayout)
         return nullptr;
     std::shared_ptr<vcl::TextLayoutCache> const ret(
             pSalLayout->CreateTextLayoutCache(copyBecausePrepareModifiesIt));
-    delete pSalLayout;
     return ret;
 }
 
@@ -1404,7 +1393,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
                                        long nCharExtra,
          vcl::TextLayoutCache const*const pLayoutCache) const
 {
-    SalLayout *const pSalLayout = ImplLayout( rStr, nIndex, nLen,
+    std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rStr, nIndex, nLen,
             Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache);
     sal_Int32 nRetVal = -1;
     if( pSalLayout )
@@ -1424,8 +1413,6 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
             nExtraPixelWidth = LogicWidthToDeviceCoordinate( nCharExtra );
         }
         nRetVal = pSalLayout->GetTextBreak( nTextPixelWidth, nExtraPixelWidth, nSubPixelFactor );
-
-        delete pSalLayout;
     }
 
     return nRetVal;
@@ -1439,7 +1426,7 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
 {
     rHyphenPos = -1;
 
-    SalLayout *const pSalLayout = ImplLayout( rStr, nIndex, nLen,
+    std::unique_ptr<SalLayout> pSalLayout = ImplLayout( rStr, nIndex, nLen,
             Point(0,0), 0, nullptr, SalLayoutFlags::NONE, pLayoutCache);
     sal_Int32 nRetVal = -1;
     if( pSalLayout )
@@ -1465,12 +1452,11 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
 
         // calculate hyphenated break position
         OUString aHyphenStr(nHyphenChar);
-        SalLayout* pHyphenLayout = ImplLayout( aHyphenStr, 0, 1 );
+        std::unique_ptr<SalLayout> pHyphenLayout = ImplLayout( aHyphenStr, 0, 1 );
         if( pHyphenLayout )
         {
             // calculate subpixel width of hyphenation character
             long nHyphenPixelWidth = pHyphenLayout->GetTextWidth() * nSubPixelFactor;
-            delete pHyphenLayout;
 
             // calculate hyphenated break position
             nTextPixelWidth -= nHyphenPixelWidth;
@@ -1482,8 +1468,6 @@ sal_Int32 OutputDevice::GetTextBreak( const OUString& rStr, long nTextWidth,
             if( rHyphenPos > nRetVal )
                 rHyphenPos = nRetVal;
         }
-
-        delete pSalLayout;
     }
 
     return nRetVal;
@@ -2328,7 +2312,7 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c
 
     if ( !IsDeviceOutputNecessary() ) return aSysLayoutData;
 
-    SalLayout* pLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry);
+    std::unique_ptr<SalLayout> pLayout = ImplLayout(rStr, nIndex, nLen, rStartPt, 0, pDXAry);
 
     if ( !pLayout ) return aSysLayoutData;
 
@@ -2350,8 +2334,6 @@ SystemTextLayoutData OutputDevice::GetSysTextLayoutData(const Point& rStartPt, c
     // Get font data
     aSysLayoutData.orientation = pLayout->GetOrientation();
 
-    delete pLayout;
-
     return aSysLayoutData;
 }
 
@@ -2363,7 +2345,7 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
     bool bRet = false;
     rRect.SetEmpty();
 
-    SalLayout* pSalLayout = nullptr;
+    std::unique_ptr<SalLayout> pSalLayout;
     const Point aPoint;
     // calculate offset when nBase!=nIndex
     long nXOffset = 0;
@@ -2376,7 +2358,6 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
         {
             nXOffset = pSalLayout->GetTextWidth();
             nXOffset /= pSalLayout->GetUnitsPerPixel();
-            delete pSalLayout;
             // TODO: fix offset calculation for Bidi case
             if( nBase < nIndex)
                 nXOffset = -nXOffset;
@@ -2413,8 +2394,6 @@ bool OutputDevice::GetTextBoundRect( tools::Rectangle& rRect,
             if( mbMap )
                 rRect += Point( maMapRes.mnMapOfsX, maMapRes.mnMapOfsY );
         }
-
-        delete pSalLayout;
     }
 
     return bRet;
@@ -2450,7 +2429,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
         const_cast<OutputDevice&>(*this).mbNewFont = true;
     }
 
-    SalLayout* pSalLayout = nullptr;
+    std::unique_ptr<SalLayout> pSalLayout;
 
     // calculate offset when nBase!=nIndex
     long nXOffset = 0;
@@ -2462,7 +2441,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
         if( pSalLayout )
         {
             nXOffset = pSalLayout->GetTextWidth();
-            delete pSalLayout;
+            pSalLayout.reset();
             // TODO: fix offset calculation for Bidi case
             if( nBase > nIndex)
                 nXOffset = -nXOffset;
@@ -2500,7 +2479,7 @@ bool OutputDevice::GetTextOutlines( basegfx::B2DPolyPolygonVector& rVector,
             }
         }
 
-        delete pSalLayout;
+        pSalLayout.reset();
     }
 
     if( bOldMap )
diff --git a/vcl/source/outdev/textline.cxx b/vcl/source/outdev/textline.cxx
index 513e22f09aa6..7d1d44075823 100644
--- a/vcl/source/outdev/textline.cxx
+++ b/vcl/source/outdev/textline.cxx
@@ -600,11 +600,10 @@ void OutputDevice::ImplDrawStrikeoutChar( long nBaseX, long nBaseY,
 
     // calculate approximation of strikeout atom size
     long nStrikeoutWidth = 0;
-    SalLayout* pLayout = ImplLayout( aStrikeoutTest, 0, nTestStrLen );
+    std::unique_ptr<SalLayout> pLayout = ImplLayout( aStrikeoutTest, 0, nTestStrLen );
     if( pLayout )
     {
         nStrikeoutWidth = pLayout->GetTextWidth() / (nTestStrLen * pLayout->GetUnitsPerPixel());
-        delete pLayout;
     }
     if( nStrikeoutWidth <= 0 ) // sanity check
         return;
@@ -664,7 +663,6 @@ void OutputDevice::ImplDrawStrikeoutChar( long nBaseX, long nBaseY,
 
     pLayout->DrawText( *mpGraphics );
 
-    delete pLayout;
     Pop();
 
     SetTextColor( aOldColor );
diff --git a/vcl/source/window/status.cxx b/vcl/source/window/status.cxx
index e24a153896cb..11a2480323ff 100644
--- a/vcl/source/window/status.cxx
+++ b/vcl/source/window/status.cxx
@@ -376,11 +376,9 @@ void StatusBar::ImplDrawItem(vcl::RenderContext& rRenderContext, bool bOffScreen
 
     if(!pLayoutCache)
     {
-        pLayoutCache = rRenderContext.ImplLayout(pItem->maText, 0, -1);
-
         // update cache
-        if(pLayoutCache)
-            pItem->mxLayoutCache.reset(pLayoutCache);
+        pItem->mxLayoutCache = rRenderContext.ImplLayout(pItem->maText, 0, -1);
+        pLayoutCache = pItem->mxLayoutCache.get();
     }
 
     Size aTextSize(rRenderContext.GetTextWidth(pItem->maText,0,-1,nullptr,pLayoutCache), rRenderContext.GetTextHeight());
@@ -1168,11 +1166,11 @@ void StatusBar::SetItemText( sal_uInt16 nItemId, const OUString& rText )
             // adjust item width - see also DataChanged()
             long nFudge = GetTextHeight()/4;
 
-            SalLayout* pSalLayout = ImplLayout(pItem->maText,0,-1);
-            long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pSalLayout ) + nFudge;
+            std::unique_ptr<SalLayout> pSalLayout = ImplLayout(pItem->maText,0,-1);
+            long nWidth = GetTextWidth( pItem->maText,0,-1,nullptr,pSalLayout.get() ) + nFudge;
 
             // update cache
-            pItem->mxLayoutCache.reset(pSalLayout);
+            pItem->mxLayoutCache = std::move(pSalLayout);
 
             if( (nWidth > pItem->mnWidth + STATUSBAR_OFFSET) ||
                 ((nWidth < pItem->mnWidth) && (mnDX - STATUSBAR_OFFSET) < mnItemsWidth  ))
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index 210f38385600..e4314ea41243 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -457,10 +457,10 @@ bool CairoTextRender::GetGlyphOutline(const GlyphItem& rGlyph,
     return pSF->GetGlyphOutline(rGlyph, rPolyPoly);
 }
 
-SalLayout* CairoTextRender::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
+std::unique_ptr<SalLayout> CairoTextRender::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
 {
     if (mpFreetypeFont[nFallbackLevel])
-        return new CommonSalLayout(*mpFreetypeFont[nFallbackLevel]);
+        return std::unique_ptr<SalLayout>(new CommonSalLayout(*mpFreetypeFont[nFallbackLevel]));
 
     return nullptr;
 }
diff --git a/vcl/unx/generic/gdi/font.cxx b/vcl/unx/generic/gdi/font.cxx
index bae13f646037..23458223f9f1 100644
--- a/vcl/unx/generic/gdi/font.cxx
+++ b/vcl/unx/generic/gdi/font.cxx
@@ -117,7 +117,7 @@ bool X11SalGraphics::GetGlyphOutline(const GlyphItem& rGlyph,
     return mxTextRenderImpl->GetGlyphOutline(rGlyph, rPolyPoly);
 }
 
-SalLayout* X11SalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
+std::unique_ptr<SalLayout> X11SalGraphics::GetTextLayout( ImplLayoutArgs& rArgs, int nFallbackLevel )
 {
     return mxTextRenderImpl->GetTextLayout(rArgs, nFallbackLevel);
 }
diff --git a/vcl/unx/generic/print/genpspgraphics.cxx b/vcl/unx/generic/print/genpspgraphics.cxx
index c835b2d5922c..40004fac5bf0 100644
--- a/vcl/unx/generic/print/genpspgraphics.cxx
+++ b/vcl/unx/generic/print/genpspgraphics.cxx
@@ -777,10 +777,10 @@ bool GenPspGraphics::GetGlyphOutline(const GlyphItem& rGlyph,
     return pSF->GetGlyphOutline(rGlyph, rB2DPolyPoly);
 }
 
-SalLayout* GenPspGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
+std::unique_ptr<SalLayout> GenPspGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
 {
     if (m_pFreetypeFont[nFallbackLevel])
-        return new PspCommonSalLayout(*m_pPrinterGfx, *m_pFreetypeFont[nFallbackLevel]);
+        return std::unique_ptr<SalLayout>(new PspCommonSalLayout(*m_pPrinterGfx, *m_pFreetypeFont[nFallbackLevel]));
 
     return nullptr;
 }
diff --git a/vcl/win/gdi/winlayout.cxx b/vcl/win/gdi/winlayout.cxx
index f157f7b81772..d6b9cd4b57c4 100644
--- a/vcl/win/gdi/winlayout.cxx
+++ b/vcl/win/gdi/winlayout.cxx
@@ -285,14 +285,14 @@ bool ExTextOutRenderer::operator ()(CommonSalLayout const &rLayout,
     return true;
 }
 
-SalLayout* WinSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
+std::unique_ptr<SalLayout> WinSalGraphics::GetTextLayout(ImplLayoutArgs& /*rArgs*/, int nFallbackLevel)
 {
     if (!mpWinFontEntry[nFallbackLevel])
         return nullptr;
 
     assert(mpWinFontData[nFallbackLevel]);
 
-    return new CommonSalLayout(getHDC(), *mpWinFontEntry[nFallbackLevel], *mpWinFontData[nFallbackLevel]);
+    return std::unique_ptr<SalLayout>(new CommonSalLayout(getHDC(), *mpWinFontEntry[nFallbackLevel], *mpWinFontData[nFallbackLevel]));
 }
 
 LogicalFontInstance * WinSalGraphics::GetWinFontEntry(int const nFallbackLevel)


More information about the Libreoffice-commits mailing list