diff --git a/vcl/inc/font/LogicalFontInstance.hxx b/vcl/inc/font/LogicalFontInstance.hxx index 40d3c57c4e67..c56752df1e6c 100644 --- a/vcl/inc/font/LogicalFontInstance.hxx +++ b/vcl/inc/font/LogicalFontInstance.hxx @@ -88,6 +88,7 @@ public: // TODO: make data members private void IgnoreFallbackForUnicode(sal_UCS4, FontWeight eWeight, std::u16string_view rFontName); inline hb_font_t* GetHbFont(); + void ClearHbFont(); bool IsGraphiteFont(); // NeedOffsetCorrection: Return if the font need offset correction in TTB direction. // nYOffset is the original offset. It is used to check if the correction is necessary. diff --git a/vcl/source/font/LogicalFontInstance.cxx b/vcl/source/font/LogicalFontInstance.cxx index 0c21cba47548..f474d46f9a63 100644 --- a/vcl/source/font/LogicalFontInstance.cxx +++ b/vcl/source/font/LogicalFontInstance.cxx @@ -175,6 +175,7 @@ bool LogicalFontInstance::GetGlyphBoundRect(sal_GlyphId nID, tools::Rectangle& r auto* pHbFont = const_cast(this)->GetHbFont(); hb_glyph_extents_t aExtents; bool res = hb_font_get_glyph_extents(pHbFont, nID, &aExtents); + const_cast(this)->ClearHbFont(); if (res) { @@ -235,6 +236,15 @@ double LogicalFontInstance::GetGlyphWidth(sal_GlyphId nGlyph, bool bVertical, bo return double(nWidth * nScale); } +void LogicalFontInstance::ClearHbFont() +{ + if (m_pHbFont) + { + hb_font_destroy(m_pHbFont); + m_pHbFont = nullptr; + } +} + bool LogicalFontInstance::IsGraphiteFont() { if (!m_xbIsGraphiteFont.has_value())