[Bf-blender-cvs] [485ab420757] master: BLF: Improved CJK Font Preview Differentiation

Harley Acheson noreply at git.blender.org
Tue Jan 10 06:40:19 CET 2023


Commit: 485ab420757bdad5ce4ec9b64ca31ab7fec78dd7
Author: Harley Acheson
Date:   Mon Jan 9 21:37:22 2023 -0800
Branches: master
https://developer.blender.org/rB485ab420757bdad5ce4ec9b64ca31ab7fec78dd7

BLF: Improved CJK Font Preview Differentiation

Use font's OS/2 table code page range bits to help differentiate
between Korean, Japanese, Simplified & Traditional Chinese fonts.

See D16484 for details.

Differential Revision: https://developer.blender.org/D16484

Reviewed by Brecht Van Lommel

===================================================================

M	source/blender/blenfont/intern/blf_thumbs.c
M	source/blender/imbuf/intern/thumbs_font.c

===================================================================

diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c
index 8a640ac86a7..0a0ae32af87 100644
--- a/source/blender/blenfont/intern/blf_thumbs.c
+++ b/source/blender/blenfont/intern/blf_thumbs.c
@@ -257,6 +257,22 @@ static const char32_t *blf_get_sample_text(FT_Face face)
                        count_bits_i((uint)os2_table->ulUnicodeRange3) +
                        count_bits_i((uint)os2_table->ulUnicodeRange4);
 
+  /* Use OS/2 Table code page range bits to differentiate between (combined) CJK fonts.
+   * See https://learn.microsoft.com/en-us/typography/opentype/spec/os2#cpr */
+  FT_ULong codepages = os2_table->ulCodePageRange1;
+  if (codepages & (1 << 19) || codepages & (1 << 21)) {
+    return U"\ud55c\uad6d\uc5b4"; /* 한국어 Korean. */
+  }
+  if (codepages & (1 << 20)) {
+    return U"\u7E41\u9AD4\u5B57"; /* 繁體字 Traditional Chinese. */
+  }
+  if (codepages & (1 << 17) && !(codepages & (1 << 18))) {
+    return U"\u65E5\u672C\u8A9E"; /* 日本語 Japanese. */
+  }
+  if (codepages & (1 << 18) && !(codepages & (1 << 17))) {
+    return U"\u7B80\u4F53\u5B57"; /* 简体字 Simplified Chinese. */
+  }
+
   for (uint i = 0; i < ARRAY_SIZE(unicode_samples); ++i) {
     const UnicodeSample *s = &unicode_samples[i];
     if (os2_table && s->field && s->mask) {
diff --git a/source/blender/imbuf/intern/thumbs_font.c b/source/blender/imbuf/intern/thumbs_font.c
index c3ed81698d9..64f6741a34b 100644
--- a/source/blender/imbuf/intern/thumbs_font.c
+++ b/source/blender/imbuf/intern/thumbs_font.c
@@ -17,7 +17,7 @@
 #include "../../blenfont/BLF_api.h"
 
 /* Only change if we need to update the previews in the on-disk cache. */
-#define FONT_THUMB_VERSION "1.0.0"
+#define FONT_THUMB_VERSION "1.0.1"
 
 struct ImBuf *IMB_thumb_load_font(const char *filename, uint x, uint y)
 {



More information about the Bf-blender-cvs mailing list