Font fallback: Fix the font used to render a character sometimes dependent on the order in which characters appear on screen

We ameliorate the performance hit by storing a hash table mapping cell
text to the loaded fallback font index so that lookups for previously
seen text are still fast.

Fixes #6865
This commit is contained in:
Kovid Goyal
2023-12-11 20:27:21 +05:30
parent 7cec82f453
commit d9ccbcd0ce
6 changed files with 85 additions and 14 deletions

View File

@@ -450,7 +450,15 @@ create_fallback_face(PyObject UNUSED *base_face, CPUCell* cell, bool bold, bool
size_t num = cell_as_unicode_for_fallback(cell, char_buf);
add_charset(pat, num);
PyObject *d = _fc_match(pat);
if (d) { ans = face_from_descriptor(d, fg); Py_CLEAR(d); }
if (d) {
ssize_t idx = -1;
PyObject *q;
while ((q = iter_fallback_faces(fg, &idx))) {
if (face_equals_descriptor(q, d)) { ans = PyLong_FromSsize_t(idx); Py_CLEAR(d); goto end; }
}
ans = face_from_descriptor(d, fg);
Py_CLEAR(d);
}
end:
if (pat != NULL) FcPatternDestroy(pat);
return ans;