tdf#128434 correctly release fonts in destructors
This adds ReleaseFonts() calls to all destructors of SalGraphics
and TextRenderImpl derivated classes, which implement SetFont.
During destruction a base class can't call into derivated classes,
as these are already destructed, so we have to spread these calls
manually.
Change-Id: Ia57db04f7df665e5205212ce512119e2f60e3379
Reviewed-on: https://gerrit.libreoffice.org/82967
Tested-by: Jenkins
Reviewed-by: Jan-Marek Glogowski <glogow@fbihome.de>
(cherry picked from commit f8e1f8652255cadd80a991aa3e059ee631b333b8)
Reviewed-on: https://gerrit.libreoffice.org/83149
(cherry picked from commit a00bdc999344db34d5926dc77ed5ca895295b0ee)
Reviewed-on: https://gerrit.libreoffice.org/83197
Reviewed-by: Michael Weghorn <m.weghorn@posteo.de>
diff --git a/vcl/headless/svpgdi.cxx b/vcl/headless/svpgdi.cxx
index 467de73..8a445b2 100644
--- a/vcl/headless/svpgdi.cxx
+++ b/vcl/headless/svpgdi.cxx
@@ -607,6 +607,7 @@ SvpSalGraphics::SvpSalGraphics()
SvpSalGraphics::~SvpSalGraphics()
{
ReleaseFonts();
}
void SvpSalGraphics::setSurface(cairo_surface_t* pSurface, const basegfx::B2IVector& rSize)
diff --git a/vcl/inc/textrender.hxx b/vcl/inc/textrender.hxx
index 063b5d4..99360a5 100644
--- a/vcl/inc/textrender.hxx
+++ b/vcl/inc/textrender.hxx
@@ -32,10 +32,12 @@ class PhysicalFontFace;
class TextRenderImpl
{
public:
// can't call ReleaseFonts here, as the destructor just calls this classes SetFont (pure virtual)!
virtual ~TextRenderImpl() {}
virtual void SetTextColor( Color nColor ) = 0;
virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) = 0;
void ReleaseFonts() { SetFont(nullptr, 0); }
virtual void GetFontMetric( ImplFontMetricDataRef&, int nFallbackLevel ) = 0;
virtual const FontCharMapRef GetFontCharMap() const = 0;
virtual bool GetFontCapabilities(vcl::FontCapabilities &rFontCapabilities) const = 0;
diff --git a/vcl/inc/unx/cairotextrender.hxx b/vcl/inc/unx/cairotextrender.hxx
index ca9cfcd..6b011a0 100644
--- a/vcl/inc/unx/cairotextrender.hxx
+++ b/vcl/inc/unx/cairotextrender.hxx
@@ -42,13 +42,11 @@ protected:
virtual void getSurfaceOffset(double& nDX, double& nDY) = 0;
virtual void releaseCairoContext(cairo_t* cr) = 0;
void setFont(LogicalFontInstance *pEntry, int nFallbackLevel);
virtual void clipRegion(cairo_t* cr) = 0;
public:
CairoTextRender();
virtual ~CairoTextRender() override;
virtual void SetTextColor( Color nColor ) override;
virtual void SetFont(LogicalFontInstance*, int nFallbackLevel) override;
diff --git a/vcl/qt5/Qt5Graphics.cxx b/vcl/qt5/Qt5Graphics.cxx
index 5192f0b..8228699a 100644
--- a/vcl/qt5/Qt5Graphics.cxx
+++ b/vcl/qt5/Qt5Graphics.cxx
@@ -44,16 +44,7 @@ Qt5Graphics::Qt5Graphics( Qt5Frame *pFrame, QImage *pQImage )
m_pWidgetDraw.reset(new Qt5Graphics_Controls());
}
Qt5Graphics::~Qt5Graphics()
{
// release the text styles
for (int i = 0; i < MAX_FALLBACK; ++i)
{
if (!m_pTextStyle[i])
break;
m_pTextStyle[i].clear();
}
}
Qt5Graphics::~Qt5Graphics() { ReleaseFonts(); }
void Qt5Graphics::ChangeQImage(QImage* pQImage)
{
diff --git a/vcl/quartz/salgdi.cxx b/vcl/quartz/salgdi.cxx
index 846b7ab..8d7308f 100644
--- a/vcl/quartz/salgdi.cxx
+++ b/vcl/quartz/salgdi.cxx
@@ -223,12 +223,7 @@ AquaSalGraphics::~AquaSalGraphics()
CGPathRelease( mxClipPath );
}
for (int i = 0; i < MAX_FALLBACK; ++i)
{
if (!mpTextStyle[i])
break;
mpTextStyle[i].clear();
}
ReleaseFonts();
if( mpXorEmulation )
delete mpXorEmulation;
diff --git a/vcl/source/gdi/salgdilayout.cxx b/vcl/source/gdi/salgdilayout.cxx
index 789e323..97ba1aa 100644
--- a/vcl/source/gdi/salgdilayout.cxx
+++ b/vcl/source/gdi/salgdilayout.cxx
@@ -83,6 +83,7 @@ bool SalGraphics::initWidgetDrawBackends(bool bForce)
SalGraphics::~SalGraphics()
{
// can't call ReleaseFonts here, as the destructor just calls this classes SetFont (pure virtual)!
}
#if HAVE_FEATURE_OPENGL
diff --git a/vcl/unx/generic/gdi/cairotextrender.cxx b/vcl/unx/generic/gdi/cairotextrender.cxx
index aa006fa..0871356 100644
--- a/vcl/unx/generic/gdi/cairotextrender.cxx
+++ b/vcl/unx/generic/gdi/cairotextrender.cxx
@@ -84,7 +84,12 @@ CairoTextRender::CairoTextRender()
rp = nullptr;
}
void CairoTextRender::setFont(LogicalFontInstance *pEntry, int nFallbackLevel)
CairoTextRender::~CairoTextRender()
{
ReleaseFonts();
}
void CairoTextRender::SetFont(LogicalFontInstance *pEntry, int nFallbackLevel)
{
// release all no longer needed font resources
for( int i = nFallbackLevel; i < MAX_FALLBACK; ++i )
@@ -384,11 +389,6 @@ bool CairoTextRender::GetFontCapabilities(vcl::FontCapabilities &rGetImplFontCap
// SalGraphics
void CairoTextRender::SetFont(LogicalFontInstance *pEntry, int nFallbackLevel)
{
setFont(pEntry, nFallbackLevel);
}
void
CairoTextRender::SetTextColor( Color nColor )
{