[Bf-blender-cvs] [03228023144] master: Cleanup: minor changes to BLF API
Campbell Barton
noreply at git.blender.org
Fri Aug 19 06:48:17 CEST 2022
Commit: 0322802314420fda3efee3c49c1a28102280ec05
Author: Campbell Barton
Date: Fri Aug 19 14:10:06 2022 +1000
Branches: master
https://developer.blender.org/rB0322802314420fda3efee3c49c1a28102280ec05
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).
===================================================================
M source/blender/blenfont/intern/blf_font.c
M source/blender/blenfont/intern/blf_glyph.c
M source/blender/blenfont/intern/blf_internal_types.h
M source/blender/blenfont/intern/blf_thumbs.c
===================================================================
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;
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list