Commit: 4e7983e0732015d9fe52ecd12e203a230b30af16 Author: Harley Acheson Date: Sat Sep 24 10:55:46 2022 -0700 Branches: master https://developer.blender.org/rB4e7983e0732015d9fe52ecd12e203a230b30af16
UI: Improved Font Thumbnails Thumbnails of fonts that better show design, shapes, contents, intent, and intended language. Previews almost every known language - living and dead - and symbol, specialty fonts, etc. See D12032 for more details and samples. Differential Revision: https://developer.blender.org/D12032 Reviewed by Campbell Barton =================================================================== M source/blender/blenfont/BLF_api.h M source/blender/blenfont/intern/blf_font.c M source/blender/blenfont/intern/blf_internal.h M source/blender/blenfont/intern/blf_thumbs.c M source/blender/blentranslation/intern/blt_lang.c M source/blender/editors/space_file/filelist.cc M source/blender/imbuf/IMB_thumbs.h M source/blender/imbuf/intern/thumbs_font.c M source/blender/windowmanager/intern/wm_init_exit.c =================================================================== diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index 992107a30e9..af2e4fd1784 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -290,16 +290,8 @@ void BLF_dir_free(char **dirs, int count) ATTR_NONNULL(); * * \note called from a thread, so it bypasses the normal BLF_* api (which isn't thread-safe). */ -void BLF_thumb_preview(const char *filepath, - const char **draw_str, - const char **i18n_draw_str, - unsigned char draw_str_lines, - const float font_color[4], - int font_size, - unsigned char *buf, - int w, - int h, - int channels) ATTR_NONNULL(); +bool BLF_thumb_preview(const char *filename, unsigned char *buf, int w, int h, int channels) + ATTR_NONNULL(); /* blf_default.c */ diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 3d7e83bc22f..9ea7e529df2 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -1145,38 +1145,6 @@ void blf_font_draw_buffer__wrap(FontBLF *font, /** \} */ -/* -------------------------------------------------------------------- */ -/** \name Text Evaluation: Count Missing Characters - * \{ */ - -int blf_font_count_missing_chars(FontBLF *font, - const char *str, - const size_t str_len, - int *r_tot_chars) -{ - int missing = 0; - size_t i = 0; - - *r_tot_chars = 0; - while (i < str_len) { - uint c; - - if ((c = str[i]) < GLYPH_ASCII_TABLE_SIZE) { - i++; - } - else { - c = BLI_str_utf8_as_unicode_step(str, str_len, &i); - if (blf_get_char_index(font, c) == 0) { - missing++; - } - } - (*r_tot_chars)++; - } - return missing; -} - -/** \} */ - /* -------------------------------------------------------------------- */ /** \name Font Query: Attributes * \{ */ diff --git a/source/blender/blenfont/intern/blf_internal.h b/source/blender/blenfont/intern/blf_internal.h index e1001cfc1ba..28f433a3018 100644 --- a/source/blender/blenfont/intern/blf_internal.h +++ b/source/blender/blenfont/intern/blf_internal.h @@ -149,11 +149,6 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font, void *user_data, struct ResultBLF *r_info); -int blf_font_count_missing_chars(struct FontBLF *font, - const char *str, - size_t str_len, - int *r_tot_chars); - void blf_font_free(struct FontBLF *font); struct GlyphCacheBLF *blf_glyph_cache_acquire(struct FontBLF *font); diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c index cba4bb96f73..8ad880edf30 100644 --- a/source/blender/blenfont/intern/blf_thumbs.c +++ b/source/blender/blenfont/intern/blf_thumbs.c @@ -8,16 +8,20 @@ * Isolate since this needs to be called by #ImBuf code (bad level call). */ -#include <stdio.h> #include <stdlib.h> -#include <string.h> #include <ft2build.h> #include FT_FREETYPE_H +#include FT_ADVANCES_H /* For FT_Get_Advance */ +#include FT_TRUETYPE_IDS_H /* Codepoint coverage constants. */ +#include FT_TRUETYPE_TABLES_H /* For TT_OS2 */ #include "BLI_listbase.h" +#include "BLI_math_bits.h" #include "BLI_rect.h" +#include "BLI_string.h" +#include "BLI_string_utf8.h" #include "BLI_threads.h" #include "BLI_utildefines.h" @@ -25,89 +29,378 @@ #include "blf_internal_types.h" #include "BLF_api.h" -#include "BLT_translation.h" #include "BLI_strict_flags.h" -void BLF_thumb_preview(const char *filepath, - const char **draw_str, - const char **i18n_draw_str, - const uchar draw_str_lines, - const float font_color[4], - const int font_size, - uchar *buf, - const int w, - const int h, - const int channels) +/* Maximum length of text sample in char32_t, including NULL terminator. */ +#define BLF_SAMPLE_LEN 5 + +typedef struct UnicodeSample { + char32_t sample[BLF_SAMPLE_LEN]; + char field; /* ‘OS/2’ table ulUnicodeRangeX field (1-4). */ + long mask; /* ‘OS/2’ table ulUnicodeRangeX bit mask. */ +} UnicodeSample; + +/* The seemingly arbitrary order that follows is to help quickly find the most-likely designed + * intent of the font. Many feature-specific fonts contain Latin, Greek, & Coptic characters so + * those need to be checked last. */ +static const UnicodeSample unicode_samples[] = { + /* Chinese, Japanese, Korean, ordered specific to general. */ + {U"\uc870\uc120\uae00", 2, TT_UCR_HANGUL}, /* 조선글 */ + {U"\u3042\u30a2\u4e9c", 2, TT_UCR_HIRAGANA}, /* あア亜 */ + {U"\u30a2\u30a4\u4e9c", 2, TT_UCR_KATAKANA}, /* アイ亜 */ + {U"\u1956\u195b\u1966", 3, TT_UCR_TAI_LE}, /* ᥖᥛᥦ */ + {U"\u3105\u3106\u3107", 2, TT_UCR_BOPOMOFO}, /* ㄅㄆㄇ */ + {U"\ua840\ua841\ua85d", 2, TT_UCR_PHAGSPA}, /* ꡀꡁꡝ */ + {U"\u5e03\u4e01\u4f53", 2, TT_UCR_CJK_UNIFIED_IDEOGRAPHS}, /* 布丁体 */ + /* Languages in the BMP with a coverage bit. */ + {U"\u05d0\u05da\u05e4", 1, TT_UCR_HEBREW}, + {U"\ua500\ua502\ua549", 1, TT_UCR_VAI}, + {U"\ufee6\ufef4\ufeb3", 1, TT_UCR_ARABIC}, + {U"\u07C1\u07C2\u07C3", 1, TT_UCR_NKO}, + {U"\u0905\u093f\u092a", 1, TT_UCR_DEVANAGARI}, + {U"\u0986\u0987\u098c", 1, TT_UCR_BENGALI}, + {U"\u0a05\u0a16\u0a30", 1, TT_UCR_GURMUKHI}, + {U"\u0aaa\u0aaf\u0ab8", 1, TT_UCR_GUJARATI}, + {U"\u0b2a\u0b30\u0b37", 1, TT_UCR_ORIYA}, + {U"\u0b85\u0b88\u0b8f", 1, TT_UCR_TAMIL}, + {U"\u0c05\u0c0c\u0c36", 1, TT_UCR_TELUGU}, + {U"\u0c85\u0c87\u0c8e", 1, TT_UCR_KANNADA}, + {U"\u0d05\u0d09\u0d3d", 1, TT_UCR_MALAYALAM}, + {U"\u0e05\u0e06\u0e07", 1, TT_UCR_THAI}, + {U"\u0e81\u0e82\u0e84", 1, TT_UCR_LAO}, + {U"\u10a0\u10a1\u10a2", 1, TT_UCR_GEORGIAN}, + {U"\u1B05\u1B07\u1B09", 1, TT_UCR_BALINESE}, + {U"\u0f00\u0f04\u0f08", 3, TT_UCR_TIBETAN}, + {U"\u0710\u0717\u071c", 3, TT_UCR_SYRIAC}, + {U"\u0784\u0783\u0798", 3, TT_UCR_THAANA}, + {U"\u0d85\u0d89\u0daf", 3, TT_UCR_SINHALA}, + {U"\u1000\u1001\u1014", 3, TT_UCR_MYANMAR}, + {U"\u1202\u1207\u1250", 3, TT_UCR_ETHIOPIC}, + {U"\u13a3\u13a4\u13a8", 3, TT_UCR_CHEROKEE}, + {U"\u1401\u144d\u156e", 3, TT_UCR_CANADIAN_ABORIGINAL_SYLLABICS}, + {U"\u1681\u1687\u168b", 3, TT_UCR_OGHAM}, + {U"\u16A0\u16A4\u16AA", 3, TT_UCR_RUNIC}, + {U"\u1780\u1781\u1783", 3, TT_UCR_KHMER}, + {U"\u1820\u1826\u1845", 3, TT_UCR_MONGOLIAN}, + {U"\ua188\ua320\ua4bf", 3, TT_UCR_YI}, + {U"\u1900\u1901\u1902", 3, TT_UCR_LIMBU}, + {U"\u1950\u1951\u1952", 3, TT_UCR_TAI_LE}, + {U"\u1980\u1982\u1986", 3, TT_UCR_NEW_TAI_LUE}, + {U"\u1A00\u1A01\u1A02", 4, TT_UCR_BUGINESE}, + {U"\u2c01\u2c05\u2c0c", 4, TT_UCR_GLAGOLITIC}, + {U"\u2d31\u2d33\u2d37", 4, TT_UCR_TIFINAGH}, + {U"\u2d31\u2d33\u2d37", 4, TT_UCR_YIJING}, + {U"\u1B83\u1B84\u1B88", 4, TT_UCR_SUNDANESE}, + {U"\u1C00\u1C01\u1C02", 4, TT_UCR_LEPCHA}, + {U"\u1C50\u1C51\u1C52", 4, TT_UCR_OL_CHIKI}, + {U"\uA800\uA801\uA805", 4, TT_UCR_SYLOTI_NAGRI}, + {U"\uA882\uA88a\uA892", 4, TT_UCR_SAURASHTRA}, + {U"\uA901\uA902\uA904", 4, TT_UCR_KAYAH_LI}, + {U"\uA930\uA932\uA943", 4, TT_UCR_REJANG}, + {U"\uaa00\uaa02\uaa05", 4, TT_UCR_CHAM}, + /* Indexed languages in the Supplementary Multilingual Plane. */ + {U"\U00010000\U00010001\U00010002", 4, TT_UCR_LINEAR_B}, + {U"\U00010300\U00010301\U00010302", 3, TT_UCR_OLD_ITALIC}, + {U"\U00010330\U00010331\U00010332", 3, TT_UCR_GOTHIC}, + {U"\U00010380\U00010381\U00010382", 4, TT_UCR_UGARITIC}, + {U"\U000103A0\U000103A1\U000103A2", 4, TT_UCR_OLD_PERSIAN}, + {U"\U00010400\U00010401\U00010402", 3, TT_UCR_DESERET}, + {U"\U00010450\U00010451\U00010452", 4, TT_UCR_SHAVIAN}, + {U"\U00010480\U00010481\U00010482", 4, TT_UCR_OSMANYA}, + {U"\U00010800\U00010803\U00010805", 4, TT_UCR_CYPRIOT_SYLLABARY}, + {U"\U00010900\U00010901\U00010902", 2, TT_UCR_PHOENICIAN}, + {U"\U00010A10\U00010A11\U00010A12", 4, TT_UCR_KHAROSHTHI}, + {U"\U00012000\U00012001\U00012002", 4, TT_UCR_CUNEIFORM}, + /* Philippine languages use a single OS2 coverage bit. */ + {U"\u1700\u1701\u1702", 3, TT_UCR_PHILIPPINE}, /* Tagalog */ + {U"\u1720\u1721\u1722", 3, TT_UCR_PHILIPPINE}, /* Hanunoo */ + {U"\u1740\u1741\u1742", 3, TT_UCR_PHILIPPINE}, /* Buhid */ + {U"\u1760\u1761\u1762", 3, TT_UCR_PHILIPPINE}, /* Tagbanwa */ + /* Anatolian languages use a single OS2 coverage bit. */ + {U"\U000102A3\U000102A8\U000102CB", 4, TT_UCR_OLD_ANATOLIAN}, /* Carian */ + {U"\U00010280\U00010281\U00010282", 4, TT_UCR_OLD_ANATOLIAN}, /* Lycian */ + {U"\U00010920\U00010921\U00010922", 4, TT_UCR_OLD_ANATOLIAN}, /* Lydian */ + /* Symbol blocks. */ + {U"\U0001f600\U0001f638", 0, 0}, /* Emoticons 😀😸 */ + {U"\uf021\uf022\uf023", 0, 0}, /* MS Symbols */ + {U"\u280f\u2815\u283f", 3, TT_UCR_BRAILLE}, + {U"\U0001D11e\U0001D161\U0001D130", 3, TT_UCR_MUSICAL_SYMBOLS}, + {U"\u2700\u2708\u2709", 2, TT_UCR_DINGBATS}, + {U"\u2600\u2601\u2602", 2, TT_UCR_MISCELLANEOUS_SYMBOLS}, + {U"\ue000\ue001\ue002", 2, TT_UCR_PRIVATE_USE}, + {U"\ue702\ue703\ue704", 2, TT_UCR_PRIVATE_USE}, + {U"\U000F0001\U000F0002\U000F0003", 2, TT_UCR_PRIVATE_USE_SUPPLEMENTARY}, + /* Languages in the Supplementary Multilingual Plane. */ + {U"\U00010350\U00010352\U00010353", 2, TT_UCR_NON_PLANE_0}, /* Old Permic */ + {U"\U000104B0\U000104B6\U000104B8", 2, TT_UCR_NON_PLANE_0}, /* Osage */ + {U"\U00010500\U00010501\U00010502", 2, TT_UCR_NON_PLANE_0}, /* Elbasan */ + {U"\U00010530\U00010531\U00010532", 2, TT_UCR_NON_PLANE_0}, /* Caucasian Albania @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org List details, subscription details or unsubscribe: https://lists.blender.org/mailman/listinfo/bf-blender-cvs