summaryrefslogtreecommitdiff
path: root/vcl/source/gdi/CommonSalLayout.cxx
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2017-11-07 12:03:33 +0100
committerMiklos Vajna <vmiklos@collabora.co.uk>2017-11-07 21:11:53 +0100
commit1ad3f06427fc6c9da106666768fdf5b16a7bfc6b (patch)
treede6e607fd345f5753ef7ce1e9d60abc6678472dd /vcl/source/gdi/CommonSalLayout.cxx
parentf71427293fcf85818dda72b295177259c41fb80a (diff)
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 b66a7cbd8491fe436126e11975c360f47ae346ed. Change-Id: Ic34cc5b60e401562c73b239a58176a59fe4bf9be Reviewed-on: https://gerrit.libreoffice.org/44398 Reviewed-by: Khaled Hosny <khaledhosny@eglug.org> Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk>
Diffstat (limited to 'vcl/source/gdi/CommonSalLayout.cxx')
-rw-r--r--vcl/source/gdi/CommonSalLayout.cxx88
1 files changed, 53 insertions, 35 deletions
diff --git a/vcl/source/gdi/CommonSalLayout.cxx b/vcl/source/gdi/CommonSalLayout.cxx
index 2871b99c7ddb..9b2d7e492a29 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -34,14 +34,19 @@
#include <QtGui/QRawFont>
#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[1] = (char)(nTableTag >> 16);
pTagName[2] = (char)(nTableTag >> 8);
pTagName[3] = (char)nTableTag;
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;
#if defined(_WIN32)
@@ -67,23 +72,9 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
pFont->GetFontTable(pTagName, pBuffer);
}
#else
- const char* pBuffer = nullptr;
- CommonSalLayout *pLayout = static_cast<CommonSalLayout*>( pUserData );
-#if ENABLE_QT5
- 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) );
- }
+ FreetypeFont* pFont = static_cast<FreetypeFont*>( pUserData );
+ const char* pBuffer = reinterpret_cast<const char*>(
+ pFont->GetTable(pTagName, &nLength) );
#endif
hb_blob_t* pBlob = nullptr;
@@ -98,6 +89,25 @@ static hb_blob_t* getFontTable(hb_face_t* /*face*/, hb_tag_t nTableTag, void* pU
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)
{
hb_font_t* pHbFont = hb_font_create(pHbFace);
@@ -254,6 +264,17 @@ CommonSalLayout::CommonSalLayout(const CoreTextStyle& rCoreTextStyle)
#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
CommonSalLayout::CommonSalLayout(const FontSelectPattern &rFSP,
FreetypeFont *pFreetypeFont,
@@ -265,18 +286,21 @@ CommonSalLayout::CommonSalLayout(const FontSelectPattern &rFSP,
, mpVertGlyphs(nullptr)
{
if (mbUseQt5)
+ {
+ assert( pQt5Font && !pFreetypeFont );
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
- mpHbFont = mpFreetypeFont->GetHbFont();
- if (!mpHbFont)
{
- hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, this, nullptr);
-
- mpHbFont = createHbFont(pHbFace);
- if (mbUseQt5)
- mpQFont->SetHbFont(mpHbFont);
- else
- mpFreetypeFont->SetHbFont(mpHbFont);
+ assert( !pQt5Font && pFreetypeFont );
+ InitFromFreetypeFont();
}
}
@@ -299,13 +323,7 @@ CommonSalLayout::CommonSalLayout(FreetypeFont& rFreetypeFont)
, mpFreetypeFont(&rFreetypeFont)
, mpVertGlyphs(nullptr)
{
- mpHbFont = mpFreetypeFont->GetHbFont();
- if (!mpHbFont)
- {
- hb_face_t* pHbFace = hb_face_create_for_tables(getFontTable, this, nullptr);
- mpHbFont = createHbFont(pHbFace);
- mpFreetypeFont->SetHbFont(mpHbFont);
- }
+ InitFromFreetypeFont();
}
#endif