summaryrefslogtreecommitdiffstats
path: root/libass/ass_font.c
diff options
context:
space:
mode:
authorOleg Oshmyan <chortos@inbox.lv>2024-01-20 21:13:20 +0200
committerOleg Oshmyan <chortos@inbox.lv>2024-01-23 19:28:11 +0200
commit58a8f09cccb4829239855791a305d1336d8ee773 (patch)
tree8e2707bbb7f73b63c3e0bec6937a01677627901c /libass/ass_font.c
parent9d7d5220f286bd4e9f0713687a752a62a89d574c (diff)
downloadlibass-58a8f09cccb4829239855791a305d1336d8ee773.tar.bz2
libass-58a8f09cccb4829239855791a305d1336d8ee773.tar.xz
font: prefer full-Unicode cmaps to BMP-only ones
Fixes: https://github.com/libass/libass/issues/634 Fixes: https://github.com/mpv-player/mpv/issues/13322
Diffstat (limited to 'libass/ass_font.c')
-rw-r--r--libass/ass_font.c30
1 files changed, 21 insertions, 9 deletions
diff --git a/libass/ass_font.c b/libass/ass_font.c
index edf42b0..d17258a 100644
--- a/libass/ass_font.c
+++ b/libass/ass_font.c
@@ -199,23 +199,35 @@ static uint32_t convert_unicode_to_mb(FT_Encoding encoding, uint32_t codepoint)
void ass_charmap_magic(ASS_Library *library, FT_Face face)
{
int i;
- int ms_cmap = -1;
+ int ms_cmap = -1, ms_unicode_cmap = -1;
// Search for a Microsoft Unicode cmap
for (i = 0; i < face->num_charmaps; ++i) {
FT_CharMap cmap = face->charmaps[i];
unsigned pid = cmap->platform_id;
unsigned eid = cmap->encoding_id;
- if (pid == 3 /*microsoft */
- && (eid == 1 /*unicode bmp */
- || eid == 10 /*full unicode */ )) {
- FT_Set_Charmap(face, cmap);
- return;
- } else if (pid == 3 && ms_cmap < 0)
- ms_cmap = i;
+ if (pid == TT_PLATFORM_MICROSOFT) {
+ switch (eid) {
+ case TT_MS_ID_UCS_4:
+ // Full Unicode cmap: select this immediately
+ FT_Set_Charmap(face, cmap);
+ return;
+ case TT_MS_ID_UNICODE_CS:
+ // BMP-only Unicode cmap: select this
+ // if no fuller Unicode cmap exists
+ if (ms_unicode_cmap < 0)
+ ms_unicode_cmap = ms_cmap = i;
+ break;
+ default:
+ // Non-Unicode cmap: select this if no Unicode cmap exists
+ if (ms_cmap < 0)
+ ms_cmap = i;
+ }
+ }
}
- // Try the first Microsoft cmap if no Microsoft Unicode cmap was found
+ // Try the first Microsoft BMP cmap if no MS cmap had full Unicode,
+ // or the first MS cmap of any kind if none of them had Unicode at all
if (ms_cmap >= 0) {
FT_CharMap cmap = face->charmaps[ms_cmap];
FT_Set_Charmap(face, cmap);