From 2960391699ab3b417a17a0a2ac29e97e9c3d3c99 Mon Sep 17 00:00:00 2001 From: Akira TAGOH Date: Tue, 9 Jul 2019 06:22:43 +0000 Subject: [PATCH] Add English name first into a cache In some cases, non-English languages might appears first in current order. and when having English name with non-English language ID like Google Noto CJK TC, English name with English language ID will be dropped due to duplicate. This fixes that issue. --- src/fcfreetype.c | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/src/fcfreetype.c b/src/fcfreetype.c index 964f7a8..bc1ab3f 100644 --- a/src/fcfreetype.c +++ b/src/fcfreetype.c @@ -1152,6 +1152,23 @@ typedef struct unsigned int idx; } FcNameMapping; +static FcBool +_is_english(int platform, int language) +{ + FcBool ret = FcFalse; + + switch (platform) + { + case TT_PLATFORM_MACINTOSH: + ret = language == TT_MAC_LANGID_ENGLISH; + break; + case TT_PLATFORM_MICROSOFT: + ret = language == TT_MS_LANGID_ENGLISH_UNITED_STATES; + break; + } + return ret; +} + static int name_mapping_cmp (const void *pa, const void *pb) { @@ -1161,7 +1178,7 @@ name_mapping_cmp (const void *pa, const void *pb) if (a->platform_id != b->platform_id) return (int) a->platform_id - (int) b->platform_id; if (a->name_id != b->name_id) return (int) a->name_id - (int) b->name_id; if (a->encoding_id != b->encoding_id) return (int) a->encoding_id - (int) b->encoding_id; - if (a->language_id != b->language_id) return (int) a->language_id - (int) b->language_id; + if (a->language_id != b->language_id) return _is_english(a->platform_id, a->language_id) ? -1 : _is_english(b->platform_id, b->language_id) ? 1 : (int) a->language_id - (int) b->language_id; if (a->idx != b->idx) return (int) a->idx - (int) b->idx; return 0;