diff options
author | Campbell Barton <campbell@blender.org> | 2022-08-19 07:10:06 +0300 |
---|---|---|
committer | Campbell Barton <campbell@blender.org> | 2022-08-19 07:46:45 +0300 |
commit | 0322802314420fda3efee3c49c1a28102280ec05 (patch) | |
tree | a4a2c8387c6c5322f45c05556c955ba1a665a74f /source/blender/blenfont | |
parent | 1a3bc09e893308cb6d31640856d23006fac56292 (diff) |
Cleanup: minor changes to BLF API
- Use upper-case for defines.
- Use u-prefix for unsigned types.
- Use snake case for struct members.
- Use const struct for unicode_blocks & arguments.
- Use doxy style comments for struct members.
- Add doxy sections for recently added code.
- Correct code-comments (outdated references).
- Remove 'e' prefix from struct UnicodeBlock/FaceDetails
(normally used for enums).
Diffstat (limited to 'source/blender/blenfont')
-rw-r--r-- | source/blender/blenfont/intern/blf_font.c | 52 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_glyph.c | 113 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_internal_types.h | 148 | ||||
-rw-r--r-- | source/blender/blenfont/intern/blf_thumbs.c | 12 |
4 files changed, 173 insertions, 152 deletions
diff --git a/source/blender/blenfont/intern/blf_font.c b/source/blender/blenfont/intern/blf_font.c index 0a0b4bd328f..a9bc1bc55fe 100644 --- a/source/blender/blenfont/intern/blf_font.c +++ b/source/blender/blenfont/intern/blf_font.c @@ -409,7 +409,7 @@ static void blf_font_draw_ex(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info, - ft_pix pen_y) + const ft_pix pen_y) { GlyphBLF *g, *g_prev = NULL; ft_pix pen_x = 0; @@ -510,7 +510,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font, /* buffer specific vars */ FontBufInfoBLF *buf_info = &font->buf_info; const float *b_col_float = buf_info->col_float; - const unsigned char *b_col_char = buf_info->col_char; + const uchar *b_col_char = buf_info->col_char; int chx, chy; int y, x; @@ -599,7 +599,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font, const size_t buf_ofs = (((size_t)(chx + x) + ((size_t)(pen_y_px + y) * (size_t)buf_info->dims[0])) * (size_t)buf_info->ch); - unsigned char *cbuf = buf_info->cbuf + buf_ofs; + uchar *cbuf = buf_info->cbuf + buf_ofs; uchar font_pixel[4]; font_pixel[0] = b_col_char[0]; @@ -1156,7 +1156,7 @@ int blf_font_count_missing_chars(FontBLF *font, *r_tot_chars = 0; while (i < str_len) { - unsigned int c; + uint c; if ((c = str[i]) < GLYPH_ASCII_TABLE_SIZE) { i++; @@ -1399,10 +1399,10 @@ bool blf_ensure_face(FontBLF *font) /* Save TrueType table with bits to quickly test most unicode block coverage. */ TT_OS2 *os2_table = (TT_OS2 *)FT_Get_Sfnt_Table(font->face, FT_SFNT_OS2); if (os2_table) { - font->UnicodeRanges[0] = (uint)os2_table->ulUnicodeRange1; - font->UnicodeRanges[1] = (uint)os2_table->ulUnicodeRange2; - font->UnicodeRanges[2] = (uint)os2_table->ulUnicodeRange3; - font->UnicodeRanges[3] = (uint)os2_table->ulUnicodeRange4; + font->unicode_ranges[0] = (uint)os2_table->ulUnicodeRange1; + font->unicode_ranges[1] = (uint)os2_table->ulUnicodeRange2; + font->unicode_ranges[2] = (uint)os2_table->ulUnicodeRange3; + font->unicode_ranges[3] = (uint)os2_table->ulUnicodeRange4; } if (FT_IS_FIXED_WIDTH(font)) { @@ -1422,16 +1422,16 @@ bool blf_ensure_face(FontBLF *font) return true; } -typedef struct eFaceDetails { +struct FaceDetails { char name[50]; - unsigned int coverage1; - unsigned int coverage2; - unsigned int coverage3; - unsigned int coverage4; -} eFaceDetails; + uint coverage1; + uint coverage2; + uint coverage3; + uint coverage4; +}; /* Details about the fallback fonts we ship, so that we can load only when needed. */ -static const eFaceDetails static_face_details[] = { +static const struct FaceDetails static_face_details[] = { {"lastresort.woff2", UINT32_MAX, UINT32_MAX, UINT32_MAX, UINT32_MAX}, {"Noto Sans CJK Regular.woff2", 0x30000083L, 0x2BDF3C10L, 0x16L, 0}, {"NotoEmoji-VariableFont_wght.woff2", 0x80000003L, 0x241E4ACL, 0x14000000L, 0x4000000L}, @@ -1467,7 +1467,7 @@ static const eFaceDetails static_face_details[] = { */ FontBLF *blf_font_new_ex(const char *name, const char *filepath, - const unsigned char *mem, + const uchar *mem, const size_t mem_size, void *ft_library) { @@ -1497,16 +1497,16 @@ FontBLF *blf_font_new_ex(const char *name, bool face_needed = true; if (font->filepath) { - const eFaceDetails *static_details = NULL; + const struct FaceDetails *static_details = NULL; char filename[256]; for (int i = 0; i < (int)ARRAY_SIZE(static_face_details); i++) { BLI_split_file_part(font->filepath, filename, sizeof(filename)); if (STREQ(static_face_details[i].name, filename)) { static_details = &static_face_details[i]; - font->UnicodeRanges[0] = static_details->coverage1; - font->UnicodeRanges[1] = static_details->coverage2; - font->UnicodeRanges[2] = static_details->coverage3; - font->UnicodeRanges[3] = static_details->coverage4; + font->unicode_ranges[0] = static_details->coverage1; + font->unicode_ranges[1] = static_details->coverage2; + font->unicode_ranges[2] = static_details->coverage3; + font->unicode_ranges[3] = static_details->coverage4; face_needed = false; break; } @@ -1521,8 +1521,8 @@ FontBLF *blf_font_new_ex(const char *name, } /* Detect "Last resort" fonts. They have everything. Usually except last 5 bits. */ - if (font->UnicodeRanges[0] == 0xffffffffU && font->UnicodeRanges[1] == 0xffffffffU && - font->UnicodeRanges[2] == 0xffffffffU && font->UnicodeRanges[3] >= 0x7FFFFFFU) { + if (font->unicode_ranges[0] == 0xffffffffU && font->unicode_ranges[1] == 0xffffffffU && + font->unicode_ranges[2] == 0xffffffffU && font->unicode_ranges[3] >= 0x7FFFFFFU) { font->flags |= BLF_LAST_RESORT; } @@ -1534,12 +1534,12 @@ FontBLF *blf_font_new(const char *name, const char *filepath) return blf_font_new_ex(name, filepath, NULL, 0, NULL); } -FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem, const size_t mem_size) +FontBLF *blf_font_new_from_mem(const char *name, const uchar *mem, const size_t mem_size) { return blf_font_new_ex(name, NULL, mem, mem_size, NULL); } -void blf_font_attach_from_mem(FontBLF *font, const unsigned char *mem, const size_t mem_size) +void blf_font_attach_from_mem(FontBLF *font, const uchar *mem, const size_t mem_size) { FT_Open_Args open; @@ -1614,7 +1614,7 @@ void blf_ensure_size(FontBLF *font) BLI_assert_unreachable(); } -bool blf_font_size(FontBLF *font, float size, unsigned int dpi) +bool blf_font_size(FontBLF *font, float size, uint dpi) { if (!blf_ensure_face(font)) { return false; diff --git a/source/blender/blenfont/intern/blf_glyph.c b/source/blender/blenfont/intern/blf_glyph.c index bc404325fc7..6b36844cec8 100644 --- a/source/blender/blenfont/intern/blf_glyph.c +++ b/source/blender/blenfont/intern/blf_glyph.c @@ -23,9 +23,6 @@ #include "MEM_guardedalloc.h" -#include "DNA_userdef_types.h" -#include "DNA_vec_types.h" - #include "BLI_listbase.h" #include "BLI_rect.h" #include "BLI_threads.h" @@ -33,7 +30,6 @@ #include "BLF_api.h" #include "GPU_capabilities.h" -#include "GPU_immediate.h" #include "blf_internal.h" #include "blf_internal_types.h" @@ -67,7 +63,7 @@ static FT_Fixed to_16dot16(double val) /** \name Glyph Cache * \{ */ -static GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, float size, unsigned int dpi) +static GlyphCacheBLF *blf_glyph_cache_find(FontBLF *font, const float size, uint dpi) { GlyphCacheBLF *gc = (GlyphCacheBLF *)font->cache.first; while (gc) { @@ -174,7 +170,7 @@ void blf_glyph_cache_clear(FontBLF *font) * * \return NULL if not found. */ -static GlyphBLF *blf_glyph_cache_find_glyph(GlyphCacheBLF *gc, uint charcode) +static GlyphBLF *blf_glyph_cache_find_glyph(const GlyphCacheBLF *gc, uint charcode) { if (charcode < GLYPH_ASCII_TABLE_SIZE) { return gc->glyph_ascii_table[charcode]; @@ -203,10 +199,10 @@ static GlyphBLF *blf_glyph_cache_find_glyph(GlyphCacheBLF *gc, uint charcode) * heavy." * https://www.puredevsoftware.com/blog/2019/01/22/sub-pixel-gamma-correct-font-rendering/ */ -static char blf_glyph_gamma(char c) +static uchar blf_glyph_gamma(uchar c) { /* The following is `(char)(powf(c / 256.0f, 1.0f / 1.43f) * 256.0f)`. */ - static const char gamma[256] = { + static const uchar gamma[256] = { 0, 5, 9, 11, 14, 16, 19, 21, 23, 25, 26, 28, 30, 32, 34, 35, 37, 38, 40, 41, 43, 44, 46, 47, 49, 50, 52, 53, 54, 56, 57, 58, 60, 61, 62, 64, 65, 66, 67, 69, 70, 71, 72, 73, 75, 76, 77, 78, 79, 80, 82, 83, 84, 85, @@ -274,7 +270,7 @@ static GlyphBLF *blf_glyph_cache_add_glyph( memcpy(g->bitmap, glyph->bitmap.buffer, (size_t)buffer_size); } - unsigned int key = blf_hash(g->c); + const uint key = blf_hash(g->c); BLI_addhead(&(gc->bucket[key]), g); if (charcode < GLYPH_ASCII_TABLE_SIZE) { gc->glyph_ascii_table[charcode] = g; @@ -283,18 +279,24 @@ static GlyphBLF *blf_glyph_cache_add_glyph( return g; } -/* This table can be used to find a coverage bit based on a charcode. later we can get default - * language and script from codepoint. */ +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Glyph Unicode Block Lookup + * + * This table can be used to find a coverage bit based on a charcode. + * Later we can get default language and script from `codepoint`. + */ -typedef struct eUnicodeBlock { - unsigned int first; - unsigned int last; +struct UnicodeBlock { + uint first; + uint last; int coverage_bit; /* 0-122. -1 is N/A. */ /* Later we add primary script and language for Harfbuzz, data from * https://en.wikipedia.org/wiki/Unicode_block */ -} eUnicodeBlock; +}; -static eUnicodeBlock unicode_blocks[] = { +static const struct UnicodeBlock unicode_blocks[] = { /* Must be in ascending order by start of range. */ {0x0, 0x7F, 0}, /* Basic Latin. */ {0x80, 0xFF, 1}, /* Latin-1 Supplement. */ @@ -553,8 +555,10 @@ static eUnicodeBlock unicode_blocks[] = { {0xE0100, 0xE01EF, 91}, /* Variation Selectors. */ {0xF0000, 0x10FFFD, 90}}; /* Private Use Supplementary. */ -/* Find a unicode block that a charcode belongs to. */ -static eUnicodeBlock *blf_charcode_to_unicode_block(uint charcode) +/** + * Find a unicode block that a `charcode` belongs to. + */ +static const struct UnicodeBlock *blf_charcode_to_unicode_block(const uint charcode) { if (charcode < 0x80) { /* Shortcut to Basic Latin. */ @@ -565,14 +569,13 @@ static eUnicodeBlock *blf_charcode_to_unicode_block(uint charcode) int min = 0; int max = ARRAY_SIZE(unicode_blocks) - 1; - int mid; if (charcode < unicode_blocks[0].first || charcode > unicode_blocks[max].last) { return NULL; } while (max >= min) { - mid = (min + max) / 2; + const int mid = (min + max) / 2; if (charcode > unicode_blocks[mid].last) { min = mid + 1; } @@ -590,26 +593,26 @@ static eUnicodeBlock *blf_charcode_to_unicode_block(uint charcode) static int blf_charcode_to_coverage_bit(uint charcode) { int coverage_bit = -1; - eUnicodeBlock *block = blf_charcode_to_unicode_block(charcode); + const struct UnicodeBlock *block = blf_charcode_to_unicode_block(charcode); if (block) { coverage_bit = block->coverage_bit; } if (coverage_bit < 0 && charcode > 0xFFFF) { /* No coverage bit, but OpenType specs v.1.3+ says bit 57 implies that there - * are codepoints supported beyond the BMP, so only check fonts with this set. */ + * are code-points supported beyond the BMP, so only check fonts with this set. */ coverage_bit = 57; } return coverage_bit; } -static bool blf_font_has_coverage_bit(FontBLF *font, int coverage_bit) +static bool blf_font_has_coverage_bit(const FontBLF *font, int coverage_bit) { if (coverage_bit < 0) { return false; } - return (font->UnicodeRanges[(uint)coverage_bit >> 5] & (1u << ((uint)coverage_bit % 32))); + return (font->unicode_ranges[(uint)coverage_bit >> 5] & (1u << ((uint)coverage_bit % 32))); } /** @@ -666,6 +669,12 @@ static FT_UInt blf_glyph_index_from_charcode(FontBLF **font, const uint charcode return 0; } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Glyph Load + * \{ */ + /** * Load a glyph into the glyph slot of a font's face object. */ @@ -700,19 +709,19 @@ static FT_GlyphSlot blf_glyph_load(FontBLF *font, FT_UInt glyph_index) return NULL; } +/** \} */ + +/* -------------------------------------------------------------------- */ +/** \name Glyph Render + * \{ */ + /** * Convert a glyph from outlines to a bitmap that we can display. */ static bool blf_glyph_render_bitmap(FontBLF *font, FT_GlyphSlot glyph) { - int render_mode; - - if (font->flags & BLF_MONOCHROME) { - render_mode = FT_RENDER_MODE_MONO; - } - else { - render_mode = FT_RENDER_MODE_NORMAL; - } + const int render_mode = (font->flags & BLF_MONOCHROME) ? FT_RENDER_MODE_MONO : + FT_RENDER_MODE_NORMAL; /* Render the glyph curves to a bitmap. */ FT_Error err = FT_Render_Glyph(glyph, render_mode); @@ -751,17 +760,19 @@ static bool blf_glyph_render_bitmap(FontBLF *font, FT_GlyphSlot glyph) * * \param variations: Variation descriptors from `FT_Get_MM_Var`. * \param tag: Axis tag (4-character string as uint), like 'wght' - * \param axis_index: returns index of axis in variations array. + * \param r_axis_index: returns index of axis in variations array. */ -static FT_Var_Axis *blf_var_axis_by_tag(FT_MM_Var *variations, uint tag, int *axis_index) +static const FT_Var_Axis *blf_var_axis_by_tag(const FT_MM_Var *variations, + const uint tag, + int *r_axis_index) { - *axis_index = -1; + *r_axis_index = -1; if (!variations) { return NULL; } for (int i = 0; i < (int)variations->num_axis; i++) { if (variations->axis[i].tag == tag) { - *axis_index = i; + *r_axis_index = i; return &(variations->axis)[i]; break; } @@ -775,7 +786,7 @@ static FT_Var_Axis *blf_var_axis_by_tag(FT_MM_Var *variations, uint tag, int *ax * \param axis: Pointer to a design space axis structure. * \param factor: -1 to 1 with 0 meaning "default" */ -static FT_Fixed blf_factor_to_coordinate(FT_Var_Axis *axis, float factor) +static FT_Fixed blf_factor_to_coordinate(const FT_Var_Axis *axis, const float factor) { FT_Fixed value = axis->def; if (factor > 0) { @@ -796,13 +807,13 @@ static FT_Fixed blf_factor_to_coordinate(FT_Var_Axis *axis, float factor) * \param tag: Axis tag (4-character string as uint), like 'wght' * \param factor: -1 to 1 with 0 meaning "default" */ -static bool blf_glyph_set_variation_normalized(FontBLF *font, +static bool blf_glyph_set_variation_normalized(const FontBLF *font, FT_Fixed coords[], - uint tag, - float factor) + const uint tag, + const float factor) { int axis_index; - FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index); + const FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index); if (axis && (axis_index < BLF_VARIATIONS_MAX)) { coords[axis_index] = blf_factor_to_coordinate(axis, factor); return true; @@ -820,7 +831,7 @@ static bool blf_glyph_set_variation_normalized(FontBLF *font, static bool blf_glyph_set_variation_float(FontBLF *font, FT_Fixed coords[], uint tag, float value) { int axis_index; - FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index); + const FT_Var_Axis *axis = blf_var_axis_by_tag(font->variations, tag, &axis_index); if (axis && (axis_index < BLF_VARIATIONS_MAX)) { FT_Fixed int_value = to_16dot16(value); CLAMP(int_value, axis->minimum, axis->maximum); @@ -988,16 +999,16 @@ static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font, FT_Get_Var_Design_Coordinates(glyph_font->face, BLF_VARIATIONS_MAX, &coords[0]); /* Update design coordinates with new values. */ weight_done = blf_glyph_set_variation_normalized( - glyph_font, coords, blf_variation_axis_weight, weight); + glyph_font, coords, BLF_VARIATION_AXIS_WEIGHT, weight); slant_done = blf_glyph_set_variation_normalized( - glyph_font, coords, blf_variation_axis_slant, slant); + glyph_font, coords, BLF_VARIATION_AXIS_SLANT, slant); width_done = blf_glyph_set_variation_normalized( - glyph_font, coords, blf_variation_axis_width, width); + glyph_font, coords, BLF_VARIATION_AXIS_WIDTH, width); spacing_done = blf_glyph_set_variation_normalized( - glyph_font, coords, blf_variation_axis_spacing, spacing); + glyph_font, coords, BLF_VARIATION_AXIS_SPACING, spacing); /* Optical size, if available, is set to current font size. */ blf_glyph_set_variation_float( - glyph_font, coords, blf_variation_axis_optsize, settings_font->size); + glyph_font, coords, BLF_VARIATION_AXIS_OPTSIZE, settings_font->size); /* Save updated design coordinates. */ FT_Set_Var_Design_Coordinates(glyph_font->face, BLF_VARIATIONS_MAX, &coords[0]); } @@ -1032,7 +1043,7 @@ static FT_GlyphSlot blf_glyph_render(FontBLF *settings_font, return NULL; } -GlyphBLF *blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, uint charcode) +GlyphBLF *blf_glyph_ensure(FontBLF *font, GlyphCacheBLF *gc, const uint charcode) { GlyphBLF *g = blf_glyph_cache_find_glyph(gc, charcode); if (g) { @@ -1103,7 +1114,7 @@ static void blf_glyph_calc_rect_shadow( /** \name Glyph Drawing * \{ */ -static void blf_texture_draw(const unsigned char color[4], +static void blf_texture_draw(const uchar color[4], const int glyph_size[2], const int offset, const int x1, @@ -1129,7 +1140,7 @@ static void blf_texture_draw(const unsigned char color[4], } } -static void blf_texture5_draw(const unsigned char color_in[4], +static void blf_texture5_draw(const uchar color_in[4], const int glyph_size[2], const int offset, const int x1, @@ -1145,7 +1156,7 @@ static void blf_texture5_draw(const unsigned char color_in[4], blf_texture_draw(color_in, glyph_size_flag, offset, x1, y1, x2, y2); } -static void blf_texture3_draw(const unsigned char color_in[4], +static void blf_texture3_draw(const uchar color_in[4], const int glyph_size[2], const int offset, const int x1, diff --git a/source/blender/blenfont/intern/blf_internal_types.h b/source/blender/blenfont/intern/blf_internal_types.h index dfe24c1aa47..d64bd9c5452 100644 --- a/source/blender/blenfont/intern/blf_internal_types.h +++ b/source/blender/blenfont/intern/blf_internal_types.h @@ -12,16 +12,17 @@ #include FT_MULTIPLE_MASTERS_H /* Variable font support. */ -#define BLF_VARIATIONS_MAX 16 /* Maximum variation axes per font. */ +/** Maximum variation axes per font. */ +#define BLF_VARIATIONS_MAX 16 #define MAKE_DVAR_TAG(a, b, c, d) \ (((uint32_t)a << 24u) | ((uint32_t)b << 16u) | ((uint32_t)c << 8u) | ((uint32_t)d)) -#define blf_variation_axis_weight MAKE_DVAR_TAG('w', 'g', 'h', 't') /* 'wght' weight axis. */ -#define blf_variation_axis_slant MAKE_DVAR_TAG('s', 'l', 'n', 't') /* 'slnt' slant axis. */ -#define blf_variation_axis_width MAKE_DVAR_TAG('w', 'd', 't', 'h') /* 'wdth' width axis. */ -#define blf_variation_axis_spacing MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* 'spac' spacing axis. */ -#define blf_variation_axis_optsize MAKE_DVAR_TAG('o', 'p', 's', 'z') /* 'opsz' optical size. */ +#define BLF_VARIATION_AXIS_WEIGHT MAKE_DVAR_TAG('w', 'g', 'h', 't') /* 'wght' weight axis. */ +#define BLF_VARIATION_AXIS_SLANT MAKE_DVAR_TAG('s', 'l', 'n', 't') /* 'slnt' slant axis. */ +#define BLF_VARIATION_AXIS_WIDTH MAKE_DVAR_TAG('w', 'd', 't', 'h') /* 'wdth' width axis. */ +#define BLF_VARIATION_AXIS_SPACING MAKE_DVAR_TAG('s', 'p', 'a', 'c') /* 'spac' spacing axis. */ +#define BLF_VARIATION_AXIS_OPTSIZE MAKE_DVAR_TAG('o', 'p', 's', 'z') /* 'opsz' optical size. */ /* -------------------------------------------------------------------- */ /** \name Sub-Pixel Offset & Utilities @@ -38,10 +39,12 @@ typedef int32_t ft_pix; /* Macros copied from `include/freetype/internal/ftobjs.h`. */ -/* FIXME(@campbellbarton): Follow rounding from Blender 3.1x and older. +/** + * FIXME(@campbellbarton): Follow rounding from Blender 3.1x and older. * This is what users will expect and changing this creates wider spaced text. * Use this macro to communicate that rounding should be used, using floor is to avoid - * user visible changes, which can be reviewed and handled separately. */ + * user visible changes, which can be reviewed and handled separately. + */ #define USE_LEGACY_SPACING #define FT_PIX_FLOOR(x) ((x) & ~63) @@ -85,7 +88,7 @@ BLI_INLINE ft_pix ft_pix_from_float(float v) BLI_INLINE ft_pix ft_pix_round_advance(ft_pix v, ft_pix step) { - /* See #USE_LEGACY_SPACING, rounding logic could change here. */ + /** See #USE_LEGACY_SPACING, rounding logic could change here. */ return FT_PIX_DEFAULT_ROUNDING(v) + FT_PIX_DEFAULT_ROUNDING(step); } @@ -97,24 +100,27 @@ BLI_INLINE ft_pix ft_pix_round_advance(ft_pix v, ft_pix step) #define BLF_BATCH_DRAW_LEN_MAX 2048 /* in glyph */ -/* Number of characters in GlyphCacheBLF.glyph_ascii_table. */ +/** Number of characters in #GlyphCacheBLF.glyph_ascii_table. */ #define GLYPH_ASCII_TABLE_SIZE 128 -/* Number of characters in KerningCacheBLF.table. */ +/** Number of characters in #KerningCacheBLF.table. */ #define KERNING_CACHE_TABLE_SIZE 128 -/* A value in the kerning cache that indicates it is not yet set. */ +/** A value in the kerning cache that indicates it is not yet set. */ #define KERNING_ENTRY_UNSET INT_MAX typedef struct BatchBLF { - struct FontBLF *font; /* can only batch glyph from the same font */ + /** Can only batch glyph from the same font. */ + struct FontBLF *font; struct GPUBatch *batch; struct GPUVertBuf *verts; struct GPUVertBufRaw pos_step, col_step, offset_step, glyph_size_step; unsigned int pos_loc, col_loc, offset_loc, glyph_size_loc; unsigned int glyph_len; - int ofs[2]; /* copy of font->pos */ - float mat[4][4]; /* previous call modelmatrix. */ + /** Copy of `font->pos`. */ + int ofs[2]; + /* Previous call `modelmatrix`. */ + float mat[4][4]; bool enabled, active, simple_shader; struct GlyphCacheBLF *glyph_cache; } BatchBLF; @@ -133,11 +139,12 @@ typedef struct GlyphCacheBLF { struct GlyphCacheBLF *next; struct GlyphCacheBLF *prev; - /* font size. */ + /** Font size. */ float size; - /* and DPI. */ + /** DPI. */ unsigned int dpi; + float char_weight; float char_slant; float char_width; @@ -146,16 +153,16 @@ typedef struct GlyphCacheBLF { bool bold; bool italic; - /* Column width when printing monospaced. */ + /** Column width when printing monospaced. */ int fixed_width; - /* and the glyphs. */ + /** The glyphs. */ ListBase bucket[257]; - /* fast ascii lookup */ + /** Fast ascii lookup */ struct GlyphBLF *glyph_ascii_table[GLYPH_ASCII_TABLE_SIZE]; - /* texture array, to draw the glyphs. */ + /** Texture array, to draw the glyphs. */ GPUTexture *texture; char *bitmap_result; int bitmap_len; @@ -168,13 +175,13 @@ typedef struct GlyphBLF { struct GlyphBLF *next; struct GlyphBLF *prev; - /* and the character, as UTF-32 */ + /** The character, as UTF-32. */ unsigned int c; - /* freetype2 index, to speed-up the search. */ + /** Freetype2 index, to speed-up the search. */ FT_UInt idx; - /* glyph box. */ + /** Glyph bounding-box. */ ft_pix box_xmin; ft_pix box_xmax; ft_pix box_ymin; @@ -182,19 +189,20 @@ typedef struct GlyphBLF { ft_pix advance_x; - /* The difference in bearings when hinting is active, zero otherwise. */ + /** The difference in bearings when hinting is active, zero otherwise. */ ft_pix lsb_delta; ft_pix rsb_delta; - /* position inside the texture where this glyph is store. */ + /** Position inside the texture where this glyph is store. */ int offset; - /* Bitmap data, from freetype. Take care that this + /** + * Bitmap data, from freetype. Take care that this * can be NULL. */ unsigned char *bitmap; - /* Glyph width and height. */ + /** Glyph width and height. */ int dims[2]; int pitch; @@ -209,56 +217,57 @@ typedef struct GlyphBLF { } GlyphBLF; typedef struct FontBufInfoBLF { - /* for draw to buffer, always set this to NULL after finish! */ + /** For draw to buffer, always set this to NULL after finish! */ float *fbuf; - /* the same but unsigned char */ + /** The same but unsigned char. */ unsigned char *cbuf; /** Buffer size, keep signed so comparisons with negative values work. */ int dims[2]; - /* number of channels. */ + /** Number of channels. */ int ch; - /* display device used for color management */ + /** Display device used for color management. */ struct ColorManagedDisplay *display; - /* and the color, the alphas is get from the glyph! - * color is sRGB space */ + /** The color, the alphas is get from the glyph! (color is sRGB space). */ float col_init[4]; - /* cached conversion from 'col_init' */ + /** Cached conversion from 'col_init'. */ unsigned char col_char[4]; float col_float[4]; } FontBufInfoBLF; typedef struct FontBLF { - /* font name. */ + /** Font name. */ char *name; - /* # of times this font was loaded */ - unsigned int reference_count; - - /* Full path to font file or NULL if from memory. */ + /** Full path to font file or NULL if from memory. */ char *filepath; - /* Pointer to in-memory font, or NULL if from file. */ + /** Pointer to in-memory font, or NULL if from file. */ void *mem; size_t mem_size; - /* Copied from the SFNT OS/2 table. Bit flags for unicode blocks and ranges + /** + * Copied from the SFNT OS/2 table. Bit flags for unicode blocks and ranges * considered "functional". Cached here because face might not always exist. - * See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur */ - uint UnicodeRanges[4]; + * See: https://docs.microsoft.com/en-us/typography/opentype/spec/os2#ur + */ + uint unicode_ranges[4]; - /* aspect ratio or scale. */ + /** Number of times this font was loaded. */ + unsigned int reference_count; + + /** Aspect ratio or scale. */ float aspect[3]; - /* initial position for draw the text. */ + /** Initial position for draw the text. */ int pos[3]; - /* angle in radians. */ + /** Angle in radians. */ float angle; #if 0 /* BLF_BLUR_ENABLE */ @@ -266,49 +275,50 @@ typedef struct FontBLF { int blur; #endif - /* shadow level. */ + /** Shadow level. */ int shadow; - /* and shadow offset. */ + /** And shadow offset. */ int shadow_x; int shadow_y; - /* shadow color. */ + /** Shadow color. */ unsigned char shadow_color[4]; - /* main text color. */ + /** Main text color. */ unsigned char color[4]; - /* Multiplied this matrix with the current one before - * draw the text! see blf_draw__start. + /** + * Multiplied this matrix with the current one before draw the text! + * see #blf_draw_gl__start. */ float m[16]; - /* clipping rectangle. */ + /** Clipping rectangle. */ rcti clip_rec; - /* the width to wrap the text, see BLF_WORD_WRAP */ + /** The width to wrap the text, see #BLF_WORD_WRAP. */ int wrap_width; - /* Font DPI (default 72). */ + /** Font DPI (default 72). */ unsigned int dpi; - /* font size. */ + /** Font size. */ float size; - /* Axes data for Adobe MM, TrueType GX, or OpenType variation fonts. */ + /** Axes data for Adobe MM, TrueType GX, or OpenType variation fonts. */ FT_MM_Var *variations; - /* Character variation; 0=default, -1=min, +1=max. */ + /** Character variation; 0=default, -1=min, +1=max. */ float char_weight; float char_slant; float char_width; float char_spacing; - /* max texture size. */ + /** Max texture size. */ int tex_size_max; - /* font options. */ + /** Font options. */ int flags; /** @@ -317,25 +327,25 @@ typedef struct FontBLF { */ ListBase cache; - /* Cache of unscaled kerning values. Will be NULL if font does not have kerning. */ + /** Cache of unscaled kerning values. Will be NULL if font does not have kerning. */ KerningCacheBLF *kerning_cache; - /* freetype2 lib handle. */ + /** Freetype2 lib handle. */ FT_Library ft_lib; - /* freetype2 face. */ + /** Freetype2 face. */ FT_Face face; - /* Point to face->size or to cache's size. */ + /** Point to face->size or to cache's size. */ FT_Size ft_size; - /* Copy of the font->face->face_flags, in case we don't have a face loaded. */ + /** Copy of the font->face->face_flags, in case we don't have a face loaded. */ FT_Long face_flags; - /* data for buffer usage (drawing into a texture buffer) */ + /** Data for buffer usage (drawing into a texture buffer) */ FontBufInfoBLF buf_info; - /* Mutex lock for glyph cache. */ + /** Mutex lock for glyph cache. */ ThreadMutex glyph_cache_mutex; } FontBLF; @@ -343,6 +353,6 @@ typedef struct DirBLF { struct DirBLF *next; struct DirBLF *prev; - /* full path where search fonts. */ + /** Full path where search fonts. */ char *path; } DirBLF; diff --git a/source/blender/blenfont/intern/blf_thumbs.c b/source/blender/blenfont/intern/blf_thumbs.c index 676d5ab2362..bafa927a440 100644 --- a/source/blender/blenfont/intern/blf_thumbs.c +++ b/source/blender/blenfont/intern/blf_thumbs.c @@ -32,15 +32,15 @@ void BLF_thumb_preview(const char *filepath, const char **draw_str, const char **i18n_draw_str, - const unsigned char draw_str_lines, + const uchar draw_str_lines, const float font_color[4], const int font_size, - unsigned char *buf, - int w, - int h, - int channels) + uchar *buf, + const int w, + const int h, + const int channels) { - const unsigned int dpi = 72; + const uint dpi = 72; const int font_size_min = 6; int font_size_curr; /* shrink 1/th each line */ |