Kaydet (Commit) 1ad3f064 authored tarafından Jan-Marek Glogowski's avatar Jan-Marek Glogowski Kaydeden (comit) Miklos Vajna

Fix harfbuzz font lifecycle in CommonSalLayout

The harfbuzz font is attached to the system font face and
therefore inherits its lifecycle. This means it can be used in
multiple CommonSalLayout objects, so the user data parameter of
hb_face_create_for_tables can't be the layout, but must be the
font.

This moves the special Qt5Font handling into it's own function,
so accessing the switching parameter mbUseQt5 is not needed.

Regression from commit b66a7cbd.

Change-Id: Ic34cc5b60e401562c73b239a58176a59fe4bf9be
Reviewed-on: https://gerrit.libreoffice.org/44398Reviewed-by: 's avatarKhaled Hosny <khaledhosny@eglug.org>
Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarMiklos Vajna <vmiklos@collabora.co.uk>
üst f7142729
...@@ -60,7 +60,12 @@ class VCL_DLLPUBLIC CommonSalLayout : public GenericSalLayout ...@@ -60,7 +60,12 @@ class VCL_DLLPUBLIC CommonSalLayout : public GenericSalLayout
#if ENABLE_QT5 #if ENABLE_QT5
const bool mbUseQt5; const bool mbUseQt5;
Qt5Font* mpQFont; Qt5Font* mpQFont;
explicit CommonSalLayout(const FontSelectPattern &rFSP,
FreetypeFont *pFreetypeFont,
Qt5Font *pFont, bool bUseQt5);
#endif #endif
void InitFromFreetypeFont();
#endif #endif
void ParseFeatures(const OUString& name); void ParseFeatures(const OUString& name);
...@@ -88,9 +93,6 @@ public: ...@@ -88,9 +93,6 @@ public:
explicit CommonSalLayout(FreetypeFont&); explicit CommonSalLayout(FreetypeFont&);
const FreetypeFont* getFreetypeFont() const { return mpFreetypeFont; } const FreetypeFont* getFreetypeFont() const { return mpFreetypeFont; }
#if ENABLE_QT5 #if ENABLE_QT5
explicit CommonSalLayout(const FontSelectPattern &rFSP,
FreetypeFont *pFreetypeFont,
Qt5Font *pFont, bool bUseQt5);
explicit CommonSalLayout(Qt5Font&); explicit CommonSalLayout(Qt5Font&);
const Qt5Font* getQt5Font() const { return mpQFont; } const Qt5Font* getQt5Font() const { return mpQFont; }
bool useQt5() const { return mbUseQt5; } bool useQt5() const { return mbUseQt5; }
......
...@@ -34,14 +34,19 @@ ...@@ -34,14 +34,19 @@
#include <QtGui/QRawFont> #include <QtGui/QRawFont>
#endif #endif
static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData) static inline void decode_hb_tag( const hb_tag_t nTableTag, char *pTagName )
{ {
char pTagName[5];
pTagName[0] = (char)(nTableTag >> 24); pTagName[0] = (char)(nTableTag >> 24);
pTagName[1] = (char)(nTableTag >> 16); pTagName[1] = (char)(nTableTag >> 16);
pTagName[2] = (char)(nTableTag >> 8); pTagName[2] = (char)(nTableTag >> 8);
pTagName[3] = (char)nTableTag; pTagName[3] = (char)nTableTag;
pTagName[4] = 0; pTagName[4] = 0;
}
static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData)
{
char pTagName[5];
decode_hb_tag( nTableTag, pTagName );
sal_uLong nLength = 0; sal_uLong nLength = 0;
#if defined(_WIN32) #if defined(_WIN32)
...@@ -67,23 +72,9 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU ...@@ -67,23 +72,9 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
pFont->GetFontTable(pTagName, pBuffer); pFont->GetFontTable(pTagName, pBuffer);
} }
#else #else
const char* pBuffer = nullptr; FreetypeFont* pFont = static_cast<FreetypeFont*>( pUserData );
CommonSalLayout *pLayout = static_cast<CommonSalLayout*>( pUserData ); const char* pBuffer = reinterpret_cast<const char*>(
#if ENABLE_QT5 pFont->GetTable(pTagName, &nLength) );
QByteArray aTable;
if ( pLayout->useQt5() )
{
QRawFont aRawFont( QRawFont::fromFont( *pLayout->getQt5Font() ) );
aTable = aRawFont.fontTable( pTagName );
pBuffer = reinterpret_cast<const char*>( aTable.data() );
nLength = aTable.size();
}
else
#endif
{
pBuffer = reinterpret_cast<const char*>(
pLayout->getFreetypeFont()->GetTable(pTagName, &nLength) );
}
#endif #endif
hb_blob_t* pBlob = nullptr; hb_blob_t* pBlob = nullptr;
...@@ -98,6 +89,25 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU ...@@ -98,6 +89,25 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
return pBlob; return pBlob;
} }
#if ENABLE_QT5
static hb_blob_t* getFontTable_Qt5Font(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pUserData)
{
char pTagName[5];
decode_hb_tag( nTableTag, pTagName );
Qt5Font *pFont = static_cast<Qt5Font*>( pUserData );
QRawFont aRawFont( QRawFont::fromFont( *pFont ) );
QByteArray aTable = aRawFont.fontTable( pTagName );
const sal_uLong nLength = aTable.size();
hb_blob_t* pBlob = nullptr;
if (nLength > 0)
pBlob = hb_blob_create(reinterpret_cast<const char*>( aTable.data() ),
nLength, HB_MEMORY_MODE_READONLY, nullptr, nullptr);
return pBlob;
}
#endif
static hb_font_t* createHbFont(hb_face_t* pHbFace) static hb_font_t* createHbFont(hb_face_t* pHbFace)
{ {
hb_font_t* pHbFont = hb_font_create(pHbFace); hb_font_t* pHbFont = hb_font_create(pHbFace);
...@@ -254,6 +264,17 @@ CommonSalLayout::CommonSalLayout(const CoreTextStyle& rCoreTextStyle) ...@@ -254,6 +264,17 @@ CommonSalLayout::CommonSalLayout(const CoreTextStyle& rCoreTextStyle)
#else #else
void CommonSalLayout::InitFromFreetypeFont()
{
mpHbFont = mpFreetypeFont->GetHbFont();
if (!mpHbFont)
{
hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, mpFreetypeFont, nullptr);
mpHbFont = createHbFont(pHbFace);
mpFreetypeFont->SetHbFont(mpHbFont);
}
}
#if ENABLE_QT5 #if ENABLE_QT5
CommonSalLayout::CommonSalLayout(const FontSelectPattern &rFSP, CommonSalLayout::CommonSalLayout(const FontSelectPattern &rFSP,
FreetypeFont *pFreetypeFont, FreetypeFont *pFreetypeFont,
...@@ -265,18 +286,21 @@ CommonSalLayout::CommonSalLayout(const FontSelectPattern &rFSP, ...@@ -265,18 +286,21 @@ CommonSalLayout::CommonSalLayout(const FontSelectPattern &rFSP,
, mpVertGlyphs(nullptr) , mpVertGlyphs(nullptr)
{ {
if (mbUseQt5) if (mbUseQt5)
{
assert( pQt5Font && !pFreetypeFont );
mpHbFont = mpQFont->GetHbFont(); mpHbFont = mpQFont->GetHbFont();
if (!mpHbFont)
{
hb_face_t* pHbFace = hb_face_create_for_tables(
getFontTable_Qt5Font, pQt5Font, nullptr);
mpHbFont = createHbFont(pHbFace);
mpQFont->SetHbFont(mpHbFont);
}
}
else else
mpHbFont = mpFreetypeFont->GetHbFont();
if (!mpHbFont)
{ {
hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, this, nullptr); assert( !pQt5Font && pFreetypeFont );
InitFromFreetypeFont();
mpHbFont = createHbFont(pHbFace);
if (mbUseQt5)
mpQFont->SetHbFont(mpHbFont);
else
mpFreetypeFont->SetHbFont(mpHbFont);
} }
} }
...@@ -299,13 +323,7 @@ CommonSalLayout::CommonSalLayout(FreetypeFont& rFreetypeFont) ...@@ -299,13 +323,7 @@ CommonSalLayout::CommonSalLayout(FreetypeFont& rFreetypeFont)
, mpFreetypeFont(&rFreetypeFont) , mpFreetypeFont(&rFreetypeFont)
, mpVertGlyphs(nullptr) , mpVertGlyphs(nullptr)
{ {
mpHbFont = mpFreetypeFont->GetHbFont(); InitFromFreetypeFont();
if (!mpHbFont)
{
hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, this, nullptr);
mpHbFont = createHbFont(pHbFace);
mpFreetypeFont->SetHbFont(mpHbFont);
}
} }
#endif #endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment