Fix inherited script font selection

This commit is contained in:
Benau 2019-06-20 15:37:53 +08:00
parent d0fac726d3
commit 13b6a6b25c

View File

@ -31,6 +31,7 @@
#ifndef SERVER_ONLY
#include <fribidi/fribidi.h>
#include <harfbuzz/hb.h>
#include <raqm.h>
#endif
@ -358,18 +359,43 @@ void FontManager::shape(const std::u32string& text,
return;
}
FT_Face prev_face = NULL;
for (int i = 0; i < length; i++)
{
FT_Face cur_face = m_faces.front();
for (unsigned j = 0; j < m_faces.size(); j++)
bool use_prev_face = false;
if (prev_face != NULL && i != 0)
{
unsigned glyph_index = FT_Get_Char_Index(m_faces[j], str[i]);
if (glyph_index > 0)
hb_script_t prev_script = hb_unicode_script(
hb_unicode_funcs_get_default(), str[i - 1]);
hb_script_t cur_script = hb_unicode_script(
hb_unicode_funcs_get_default(), str[i]);
if (cur_script == HB_SCRIPT_INHERITED ||
(prev_script == HB_SCRIPT_ARABIC &&
// Those exists in the default arabic font
(str[i] == U'.' || str[i] == U'!' || str[i] == U':')))
{
cur_face = m_faces[j];
break;
// For inherited script (like punctation with arabic or
// join marks), try to use the previous face so it is not
// hb_shape separately
cur_face = prev_face;
use_prev_face = true;
}
}
if (!use_prev_face)
{
for (unsigned j = 0; j < m_faces.size(); j++)
{
unsigned glyph_index =
FT_Get_Char_Index(m_faces[j], str[i]);
if (glyph_index > 0)
{
cur_face = m_faces[j];
break;
}
}
}
prev_face = cur_face;
if (!FT_HAS_COLOR(cur_face))
{
checkFTError(FT_Set_Pixel_Sizes(cur_face, 0,