FT_Face is also not thread, protect getTextAsGlyphs

(cherry picked from commit 7b4abb1f7b)
This commit is contained in:
Mark Roszko 2023-02-17 14:39:52 +00:00
parent 4d4fdfff70
commit 62337f75b8
2 changed files with 10 additions and 0 deletions

View File

@ -335,6 +335,8 @@ VECTOR2I OUTLINE_FONT::getTextAsGlyphs( BOX2I* aBBox, std::vector<std::unique_pt
TEXT_STYLE_FLAGS aTextStyle ) const
{
VECTOR2D glyphSize = aSize;
std::lock_guard<std::mutex> guard( m_freeTypeMutex );
FT_Face face = m_face;
double scaler = faceSize();
@ -562,6 +564,9 @@ void OUTLINE_FONT::RenderToOpenGLCanvas( KIGFX::OPENGL_GAL& aGal, const wxString
unsigned int glyphCount;
hb_glyph_info_t* glyphInfo = hb_buffer_get_glyph_infos( buf, &glyphCount );
hb_glyph_position_t* glyphPos = hb_buffer_get_glyph_positions( buf, &glyphCount );
std::lock_guard<std::mutex> guard( m_freeTypeMutex );
hb_font_t* referencedFont = hb_ft_font_create_referenced( m_face );
hb_ft_font_set_funcs( referencedFont );

View File

@ -137,9 +137,14 @@ protected:
private:
// FreeType variables
/**
* Mutex for freetype access, FT_Library and FT_Face are not thread safe
*/
static std::mutex m_freeTypeMutex;
static FT_Library m_freeType;
FT_Face m_face;
const int m_faceSize;
bool m_fakeBold;
bool m_fakeItal;