Cleanup: rename len to str_len for BLF functions
Make it obvious which variable this is the length of.
This commit is contained in:
parent
aa067bef5e
commit
62f2204d65
|
@ -98,13 +98,13 @@ void BLF_batch_draw_flush(void);
|
|||
void BLF_batch_draw_end(void);
|
||||
|
||||
/* Draw the string using the current font. */
|
||||
void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void BLF_draw_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
|
||||
ATTR_NONNULL(2);
|
||||
void BLF_draw(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
|
||||
void BLF_draw_ascii_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void BLF_draw(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2);
|
||||
void BLF_draw_ascii_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
|
||||
ATTR_NONNULL(2);
|
||||
void BLF_draw_ascii(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
|
||||
int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth) ATTR_NONNULL(2);
|
||||
void BLF_draw_ascii(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2);
|
||||
int BLF_draw_mono(int fontid, const char *str, size_t str_len, int cwidth) ATTR_NONNULL(2);
|
||||
|
||||
typedef bool (*BLF_GlyphBoundsFn)(const char *str,
|
||||
const size_t str_step_ofs,
|
||||
|
@ -116,43 +116,45 @@ typedef bool (*BLF_GlyphBoundsFn)(const char *str,
|
|||
|
||||
void BLF_boundbox_foreach_glyph_ex(int fontid,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
BLF_GlyphBoundsFn user_fn,
|
||||
void *user_data,
|
||||
struct ResultBLF *r_info) ATTR_NONNULL(2);
|
||||
void BLF_boundbox_foreach_glyph(int fontid,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
BLF_GlyphBoundsFn user_fn,
|
||||
void *user_data) ATTR_NONNULL(2);
|
||||
|
||||
/* Get the string byte offset that fits within a given width */
|
||||
size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width, float *r_width)
|
||||
ATTR_NONNULL(2);
|
||||
size_t BLF_width_to_strlen(
|
||||
int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_NONNULL(2);
|
||||
/* Same as BLF_width_to_strlen but search from the string end */
|
||||
size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width, float *r_width)
|
||||
ATTR_NONNULL(2);
|
||||
size_t BLF_width_to_rstrlen(
|
||||
int fontid, const char *str, size_t str_len, float width, float *r_width) ATTR_NONNULL(2);
|
||||
|
||||
/* This function return the bounding box of the string
|
||||
* and are not multiplied by the aspect.
|
||||
*/
|
||||
void BLF_boundbox_ex(int fontid,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct rctf *box,
|
||||
struct ResultBLF *r_info) ATTR_NONNULL(2);
|
||||
void BLF_boundbox(int fontid, const char *str, size_t len, struct rctf *box) ATTR_NONNULL();
|
||||
void BLF_boundbox(int fontid, const char *str, size_t str_len, struct rctf *box) ATTR_NONNULL();
|
||||
|
||||
/* The next both function return the width and height
|
||||
* of the string, using the current font and both value
|
||||
* are multiplied by the aspect of the font.
|
||||
*/
|
||||
float BLF_width_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
float BLF_width_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
|
||||
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
|
||||
float BLF_width(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
||||
float BLF_height_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
float BLF_width(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL();
|
||||
float BLF_height_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
|
||||
ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2);
|
||||
float BLF_height(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL();
|
||||
float BLF_height(int fontid, const char *str, size_t str_len) ATTR_WARN_UNUSED_RESULT
|
||||
ATTR_NONNULL();
|
||||
|
||||
/* Return dimensions of the font without any sample text. */
|
||||
int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT;
|
||||
|
@ -163,8 +165,8 @@ float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT;
|
|||
/* The following function return the width and height of the string, but
|
||||
* just in one call, so avoid extra freetype2 stuff.
|
||||
*/
|
||||
void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height)
|
||||
ATTR_NONNULL();
|
||||
void BLF_width_and_height(
|
||||
int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL();
|
||||
|
||||
/* For fixed width fonts only, returns the width of a
|
||||
* character.
|
||||
|
@ -221,9 +223,9 @@ void BLF_buffer_col(int fontid, const float rgba[4]) ATTR_NONNULL(2);
|
|||
/* Draw the string into the buffer, this function draw in both buffer,
|
||||
* float and unsigned char _BUT_ it's not necessary set both buffer, NULL is valid here.
|
||||
*/
|
||||
void BLF_draw_buffer_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void BLF_draw_buffer_ex(int fontid, const char *str, size_t str_len, struct ResultBLF *r_info)
|
||||
ATTR_NONNULL(2);
|
||||
void BLF_draw_buffer(int fontid, const char *str, size_t len) ATTR_NONNULL(2);
|
||||
void BLF_draw_buffer(int fontid, const char *str, size_t str_len) ATTR_NONNULL(2);
|
||||
|
||||
/* Add a path to the font dir paths. */
|
||||
void BLF_dir_add(const char *path) ATTR_NONNULL();
|
||||
|
@ -254,8 +256,9 @@ void BLF_default_dpi(int dpi);
|
|||
void BLF_default_set(int fontid);
|
||||
int BLF_default(void); /* get default font ID so we can pass it to other functions */
|
||||
/* Draw the string using the default font, size and dpi. */
|
||||
void BLF_draw_default(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
|
||||
void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL();
|
||||
void BLF_draw_default(float x, float y, float z, const char *str, size_t str_len) ATTR_NONNULL();
|
||||
void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t str_len)
|
||||
ATTR_NONNULL();
|
||||
/* Set size and DPI, and return default font ID. */
|
||||
int BLF_set_default(void);
|
||||
|
||||
|
|
|
@ -521,7 +521,7 @@ static void blf_draw_gl__end(FontBLF *font)
|
|||
}
|
||||
}
|
||||
|
||||
void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void BLF_draw_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
|
@ -530,27 +530,27 @@ void BLF_draw_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_in
|
|||
if (font) {
|
||||
blf_draw_gl__start(font);
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
blf_font_draw__wrap(font, str, len, r_info);
|
||||
blf_font_draw__wrap(font, str, str_len, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_draw(font, str, len, r_info);
|
||||
blf_font_draw(font, str, str_len, r_info);
|
||||
}
|
||||
blf_draw_gl__end(font);
|
||||
}
|
||||
}
|
||||
void BLF_draw(int fontid, const char *str, size_t len)
|
||||
void BLF_draw(int fontid, const char *str, const size_t str_len)
|
||||
{
|
||||
if (len == 0 || str[0] == '\0') {
|
||||
if (str_len == 0 || str[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
|
||||
/* Avoid bgl usage to corrupt BLF drawing. */
|
||||
GPU_bgl_end();
|
||||
|
||||
BLF_draw_ex(fontid, str, len, NULL);
|
||||
BLF_draw_ex(fontid, str, str_len, NULL);
|
||||
}
|
||||
|
||||
void BLF_draw_ascii_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void BLF_draw_ascii_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
|
@ -560,27 +560,27 @@ void BLF_draw_ascii_ex(int fontid, const char *str, size_t len, struct ResultBLF
|
|||
blf_draw_gl__start(font);
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
/* Use non-ASCII draw function for word-wrap. */
|
||||
blf_font_draw__wrap(font, str, len, r_info);
|
||||
blf_font_draw__wrap(font, str, str_len, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_draw_ascii(font, str, len, r_info);
|
||||
blf_font_draw_ascii(font, str, str_len, r_info);
|
||||
}
|
||||
blf_draw_gl__end(font);
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_draw_ascii(int fontid, const char *str, size_t len)
|
||||
void BLF_draw_ascii(int fontid, const char *str, const size_t str_len)
|
||||
{
|
||||
if (len == 0 || str[0] == '\0') {
|
||||
if (str_len == 0 || str[0] == '\0') {
|
||||
return;
|
||||
}
|
||||
|
||||
BLF_draw_ascii_ex(fontid, str, len, NULL);
|
||||
BLF_draw_ascii_ex(fontid, str, str_len, NULL);
|
||||
}
|
||||
|
||||
int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
|
||||
int BLF_draw_mono(int fontid, const char *str, const size_t str_len, int cwidth)
|
||||
{
|
||||
if (len == 0 || str[0] == '\0') {
|
||||
if (str_len == 0 || str[0] == '\0') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -589,7 +589,7 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
|
|||
|
||||
if (font) {
|
||||
blf_draw_gl__start(font);
|
||||
columns = blf_font_draw_mono(font, str, len, cwidth);
|
||||
columns = blf_font_draw_mono(font, str, str_len, cwidth);
|
||||
blf_draw_gl__end(font);
|
||||
}
|
||||
|
||||
|
@ -606,7 +606,7 @@ int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth)
|
|||
*/
|
||||
void BLF_boundbox_foreach_glyph_ex(int fontid,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
BLF_GlyphBoundsFn user_fn,
|
||||
void *user_data,
|
||||
struct ResultBLF *r_info)
|
||||
|
@ -621,25 +621,26 @@ void BLF_boundbox_foreach_glyph_ex(int fontid,
|
|||
BLI_assert(0);
|
||||
}
|
||||
else {
|
||||
blf_font_boundbox_foreach_glyph(font, str, len, user_fn, user_data, r_info);
|
||||
blf_font_boundbox_foreach_glyph(font, str, str_len, user_fn, user_data, r_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_boundbox_foreach_glyph(
|
||||
int fontid, const char *str, size_t len, BLF_GlyphBoundsFn user_fn, void *user_data)
|
||||
int fontid, const char *str, const size_t str_len, BLF_GlyphBoundsFn user_fn, void *user_data)
|
||||
{
|
||||
BLF_boundbox_foreach_glyph_ex(fontid, str, len, user_fn, user_data, NULL);
|
||||
BLF_boundbox_foreach_glyph_ex(fontid, str, str_len, user_fn, user_data, NULL);
|
||||
}
|
||||
|
||||
size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width, float *r_width)
|
||||
size_t BLF_width_to_strlen(
|
||||
int fontid, const char *str, const size_t str_len, float width, float *r_width)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
|
||||
size_t ret;
|
||||
ret = blf_font_width_to_strlen(font, str, len, width / xa, r_width);
|
||||
ret = blf_font_width_to_strlen(font, str, str_len, width / xa, r_width);
|
||||
if (r_width) {
|
||||
*r_width *= xa;
|
||||
}
|
||||
|
@ -652,14 +653,15 @@ size_t BLF_width_to_strlen(int fontid, const char *str, size_t len, float width,
|
|||
return 0;
|
||||
}
|
||||
|
||||
size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width, float *r_width)
|
||||
size_t BLF_width_to_rstrlen(
|
||||
int fontid, const char *str, const size_t str_len, float width, float *r_width)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
const float xa = (font->flags & BLF_ASPECT) ? font->aspect[0] : 1.0f;
|
||||
size_t ret;
|
||||
ret = blf_font_width_to_rstrlen(font, str, len, width / xa, r_width);
|
||||
ret = blf_font_width_to_rstrlen(font, str, str_len, width / xa, r_width);
|
||||
if (r_width) {
|
||||
*r_width *= xa;
|
||||
}
|
||||
|
@ -673,7 +675,7 @@ size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width
|
|||
}
|
||||
|
||||
void BLF_boundbox_ex(
|
||||
int fontid, const char *str, size_t len, rctf *r_box, struct ResultBLF *r_info)
|
||||
int fontid, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
|
@ -681,47 +683,48 @@ void BLF_boundbox_ex(
|
|||
|
||||
if (font) {
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
blf_font_boundbox__wrap(font, str, len, r_box, r_info);
|
||||
blf_font_boundbox__wrap(font, str, str_len, r_box, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_boundbox(font, str, len, r_box, r_info);
|
||||
blf_font_boundbox(font, str, str_len, r_box, r_info);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void BLF_boundbox(int fontid, const char *str, size_t len, rctf *r_box)
|
||||
void BLF_boundbox(int fontid, const char *str, const size_t str_len, rctf *r_box)
|
||||
{
|
||||
BLF_boundbox_ex(fontid, str, len, r_box, NULL);
|
||||
BLF_boundbox_ex(fontid, str, str_len, r_box, NULL);
|
||||
}
|
||||
|
||||
void BLF_width_and_height(int fontid, const char *str, size_t len, float *r_width, float *r_height)
|
||||
void BLF_width_and_height(
|
||||
int fontid, const char *str, const size_t str_len, float *r_width, float *r_height)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font) {
|
||||
blf_font_width_and_height(font, str, len, r_width, r_height, NULL);
|
||||
blf_font_width_and_height(font, str, str_len, r_width, r_height, NULL);
|
||||
}
|
||||
else {
|
||||
*r_width = *r_height = 0.0f;
|
||||
}
|
||||
}
|
||||
|
||||
float BLF_width_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
float BLF_width_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
BLF_RESULT_CHECK_INIT(r_info);
|
||||
|
||||
if (font) {
|
||||
return blf_font_width(font, str, len, r_info);
|
||||
return blf_font_width(font, str, str_len, r_info);
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float BLF_width(int fontid, const char *str, size_t len)
|
||||
float BLF_width(int fontid, const char *str, const size_t str_len)
|
||||
{
|
||||
return BLF_width_ex(fontid, str, len, NULL);
|
||||
return BLF_width_ex(fontid, str, str_len, NULL);
|
||||
}
|
||||
|
||||
float BLF_fixed_width(int fontid)
|
||||
|
@ -735,22 +738,22 @@ float BLF_fixed_width(int fontid)
|
|||
return 0.0f;
|
||||
}
|
||||
|
||||
float BLF_height_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
float BLF_height_ex(int fontid, const char *str, const size_t str_len, struct ResultBLF *r_info)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
BLF_RESULT_CHECK_INIT(r_info);
|
||||
|
||||
if (font) {
|
||||
return blf_font_height(font, str, len, r_info);
|
||||
return blf_font_height(font, str, str_len, r_info);
|
||||
}
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
|
||||
float BLF_height(int fontid, const char *str, size_t len)
|
||||
float BLF_height(int fontid, const char *str, const size_t str_len)
|
||||
{
|
||||
return BLF_height_ex(fontid, str, len, NULL);
|
||||
return BLF_height_ex(fontid, str, str_len, NULL);
|
||||
}
|
||||
|
||||
int BLF_height_max(int fontid)
|
||||
|
@ -894,24 +897,27 @@ void blf_draw_buffer__end(void)
|
|||
{
|
||||
}
|
||||
|
||||
void BLF_draw_buffer_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void BLF_draw_buffer_ex(int fontid,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
FontBLF *font = blf_get(fontid);
|
||||
|
||||
if (font && (font->buf_info.fbuf || font->buf_info.cbuf)) {
|
||||
blf_draw_buffer__start(font);
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
blf_font_draw_buffer__wrap(font, str, len, r_info);
|
||||
blf_font_draw_buffer__wrap(font, str, str_len, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_draw_buffer(font, str, len, r_info);
|
||||
blf_font_draw_buffer(font, str, str_len, r_info);
|
||||
}
|
||||
blf_draw_buffer__end();
|
||||
}
|
||||
}
|
||||
void BLF_draw_buffer(int fontid, const char *str, size_t len)
|
||||
void BLF_draw_buffer(int fontid, const char *str, const size_t str_len)
|
||||
{
|
||||
BLF_draw_buffer_ex(fontid, str, len, NULL);
|
||||
BLF_draw_buffer_ex(fontid, str, str_len, NULL);
|
||||
}
|
||||
|
||||
char *BLF_display_name_from_file(const char *filename)
|
||||
|
|
|
@ -68,23 +68,23 @@ int BLF_set_default(void)
|
|||
return global_font_default;
|
||||
}
|
||||
|
||||
void BLF_draw_default(float x, float y, float z, const char *str, size_t len)
|
||||
void BLF_draw_default(float x, float y, float z, const char *str, const size_t str_len)
|
||||
{
|
||||
ASSERT_DEFAULT_SET;
|
||||
|
||||
const uiStyle *style = UI_style_get();
|
||||
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
|
||||
BLF_position(global_font_default, x, y, z);
|
||||
BLF_draw(global_font_default, str, len);
|
||||
BLF_draw(global_font_default, str, str_len);
|
||||
}
|
||||
|
||||
/* same as above but call 'BLF_draw_ascii' */
|
||||
void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len)
|
||||
void BLF_draw_default_ascii(float x, float y, float z, const char *str, const size_t str_len)
|
||||
{
|
||||
ASSERT_DEFAULT_SET;
|
||||
|
||||
const uiStyle *style = UI_style_get();
|
||||
BLF_size(global_font_default, style->widgetlabel.points, global_font_dpi);
|
||||
BLF_position(global_font_default, x, y, z);
|
||||
BLF_draw_ascii(global_font_default, str, len); /* XXX, use real length */
|
||||
BLF_draw_ascii(global_font_default, str, str_len); /* XXX, use real length */
|
||||
}
|
||||
|
|
|
@ -365,7 +365,7 @@ BLI_INLINE void blf_kerning_step_fast(FontBLF *font,
|
|||
static void blf_font_draw_ex(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info,
|
||||
int pen_y)
|
||||
{
|
||||
|
@ -374,14 +374,14 @@ static void blf_font_draw_ex(FontBLF *font,
|
|||
int pen_x = 0;
|
||||
size_t i = 0;
|
||||
|
||||
if (len == 0) {
|
||||
if (str_len == 0) {
|
||||
/* early output, don't do any IMM OpenGL. */
|
||||
return;
|
||||
}
|
||||
|
||||
blf_batch_draw_begin(font);
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
while ((i < str_len) && str[i]) {
|
||||
g = blf_utf8_next_fast(font, gc, str, &i, &c);
|
||||
|
||||
if (UNLIKELY(c == BLI_UTF8_ERR)) {
|
||||
|
@ -407,16 +407,16 @@ static void blf_font_draw_ex(FontBLF *font,
|
|||
r_info->width = pen_x;
|
||||
}
|
||||
}
|
||||
void blf_font_draw(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void blf_font_draw(FontBLF *font, const char *str, const size_t str_len, struct ResultBLF *r_info)
|
||||
{
|
||||
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
|
||||
blf_font_draw_ex(font, gc, str, len, r_info, 0);
|
||||
blf_font_draw_ex(font, gc, str, str_len, r_info, 0);
|
||||
blf_glyph_cache_release(font);
|
||||
}
|
||||
|
||||
/* faster version of blf_font_draw, ascii only for view dimensions */
|
||||
static void blf_font_draw_ascii_ex(
|
||||
FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info, int pen_y)
|
||||
FontBLF *font, const char *str, size_t str_len, struct ResultBLF *r_info, int pen_y)
|
||||
{
|
||||
unsigned int c, c_prev = BLI_UTF8_ERR;
|
||||
GlyphBLF *g, *g_prev = NULL;
|
||||
|
@ -426,7 +426,7 @@ static void blf_font_draw_ascii_ex(
|
|||
|
||||
blf_batch_draw_begin(font);
|
||||
|
||||
while ((c = *(str++)) && len--) {
|
||||
while ((c = *(str++)) && str_len--) {
|
||||
BLI_assert(c < GLYPH_ASCII_TABLE_SIZE);
|
||||
g = gc->glyph_ascii_table[c];
|
||||
if (UNLIKELY(g == NULL)) {
|
||||
|
@ -456,13 +456,16 @@ static void blf_font_draw_ascii_ex(
|
|||
blf_glyph_cache_release(font);
|
||||
}
|
||||
|
||||
void blf_font_draw_ascii(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void blf_font_draw_ascii(FontBLF *font,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
blf_font_draw_ascii_ex(font, str, len, r_info, 0);
|
||||
blf_font_draw_ascii_ex(font, str, str_len, r_info, 0);
|
||||
}
|
||||
|
||||
/* use fixed column width, but an utf8 character may occupy multiple columns */
|
||||
int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
|
||||
int blf_font_draw_mono(FontBLF *font, const char *str, const size_t str_len, int cwidth)
|
||||
{
|
||||
unsigned int c;
|
||||
GlyphBLF *g;
|
||||
|
@ -474,7 +477,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
|
|||
|
||||
blf_batch_draw_begin(font);
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
while ((i < str_len) && str[i]) {
|
||||
g = blf_utf8_next_fast(font, gc, str, &i, &c);
|
||||
|
||||
if (UNLIKELY(c == BLI_UTF8_ERR)) {
|
||||
|
@ -512,7 +515,7 @@ int blf_font_draw_mono(FontBLF *font, const char *str, size_t len, int cwidth)
|
|||
static void blf_font_draw_buffer_ex(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info,
|
||||
int pen_y)
|
||||
{
|
||||
|
@ -531,7 +534,7 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
|
|||
|
||||
/* another buffer specific call for color conversion */
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
while ((i < str_len) && str[i]) {
|
||||
g = blf_utf8_next_fast(font, gc, str, &i, &c);
|
||||
|
||||
if (UNLIKELY(c == BLI_UTF8_ERR)) {
|
||||
|
@ -646,10 +649,13 @@ static void blf_font_draw_buffer_ex(FontBLF *font,
|
|||
}
|
||||
}
|
||||
|
||||
void blf_font_draw_buffer(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void blf_font_draw_buffer(FontBLF *font,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
|
||||
blf_font_draw_buffer_ex(font, gc, str, len, r_info, 0);
|
||||
blf_font_draw_buffer_ex(font, gc, str, str_len, r_info, 0);
|
||||
blf_glyph_cache_release(font);
|
||||
}
|
||||
|
||||
|
@ -685,7 +691,7 @@ static bool blf_font_width_to_strlen_glyph_process(FontBLF *font,
|
|||
}
|
||||
|
||||
size_t blf_font_width_to_strlen(
|
||||
FontBLF *font, const char *str, size_t len, float width, float *r_width)
|
||||
FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
|
||||
{
|
||||
unsigned int c, c_prev = BLI_UTF8_ERR;
|
||||
GlyphBLF *g, *g_prev;
|
||||
|
@ -695,7 +701,7 @@ size_t blf_font_width_to_strlen(
|
|||
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
|
||||
const int width_i = (int)width;
|
||||
|
||||
for (i_prev = i = 0, width_new = pen_x = 0, g_prev = NULL, c_prev = 0; (i < len) && str[i];
|
||||
for (i_prev = i = 0, width_new = pen_x = 0, g_prev = NULL, c_prev = 0; (i < str_len) && str[i];
|
||||
i_prev = i, width_new = pen_x, c_prev = c, g_prev = g) {
|
||||
g = blf_utf8_next_fast(font, gc, str, &i, &c);
|
||||
|
||||
|
@ -713,7 +719,7 @@ size_t blf_font_width_to_strlen(
|
|||
}
|
||||
|
||||
size_t blf_font_width_to_rstrlen(
|
||||
FontBLF *font, const char *str, size_t len, float width, float *r_width)
|
||||
FontBLF *font, const char *str, const size_t str_len, float width, float *r_width)
|
||||
{
|
||||
unsigned int c, c_prev = BLI_UTF8_ERR;
|
||||
GlyphBLF *g, *g_prev;
|
||||
|
@ -724,7 +730,7 @@ size_t blf_font_width_to_rstrlen(
|
|||
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
|
||||
const int width_i = (int)width;
|
||||
|
||||
i = BLI_strnlen(str, len);
|
||||
i = BLI_strnlen(str, str_len);
|
||||
s = BLI_str_find_prev_char_utf8(str, &str[i]);
|
||||
i = (size_t)((s != NULL) ? s - str : 0);
|
||||
s_prev = BLI_str_find_prev_char_utf8(str, s);
|
||||
|
@ -765,7 +771,7 @@ size_t blf_font_width_to_rstrlen(
|
|||
static void blf_font_boundbox_ex(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
rctf *box,
|
||||
struct ResultBLF *r_info,
|
||||
int pen_y)
|
||||
|
@ -781,7 +787,7 @@ static void blf_font_boundbox_ex(FontBLF *font,
|
|||
box->ymin = 32000.0f;
|
||||
box->ymax = -32000.0f;
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
while ((i < str_len) && str[i]) {
|
||||
g = blf_utf8_next_fast(font, gc, str, &i, &c);
|
||||
|
||||
if (UNLIKELY(c == BLI_UTF8_ERR)) {
|
||||
|
@ -829,16 +835,16 @@ static void blf_font_boundbox_ex(FontBLF *font,
|
|||
}
|
||||
}
|
||||
void blf_font_boundbox(
|
||||
FontBLF *font, const char *str, size_t len, rctf *r_box, struct ResultBLF *r_info)
|
||||
FontBLF *font, const char *str, const size_t str_len, rctf *r_box, struct ResultBLF *r_info)
|
||||
{
|
||||
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
|
||||
blf_font_boundbox_ex(font, gc, str, len, r_box, r_info, 0);
|
||||
blf_font_boundbox_ex(font, gc, str, str_len, r_box, r_info, 0);
|
||||
blf_glyph_cache_release(font);
|
||||
}
|
||||
|
||||
void blf_font_width_and_height(FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
float *r_width,
|
||||
float *r_height,
|
||||
struct ResultBLF *r_info)
|
||||
|
@ -856,16 +862,19 @@ void blf_font_width_and_height(FontBLF *font,
|
|||
}
|
||||
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
blf_font_boundbox__wrap(font, str, len, &box, r_info);
|
||||
blf_font_boundbox__wrap(font, str, str_len, &box, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_boundbox(font, str, len, &box, r_info);
|
||||
blf_font_boundbox(font, str, str_len, &box, r_info);
|
||||
}
|
||||
*r_width = (BLI_rctf_size_x(&box) * xa);
|
||||
*r_height = (BLI_rctf_size_y(&box) * ya);
|
||||
}
|
||||
|
||||
float blf_font_width(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
float blf_font_width(FontBLF *font,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
float xa;
|
||||
rctf box;
|
||||
|
@ -878,15 +887,18 @@ float blf_font_width(FontBLF *font, const char *str, size_t len, struct ResultBL
|
|||
}
|
||||
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
blf_font_boundbox__wrap(font, str, len, &box, r_info);
|
||||
blf_font_boundbox__wrap(font, str, str_len, &box, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_boundbox(font, str, len, &box, r_info);
|
||||
blf_font_boundbox(font, str, str_len, &box, r_info);
|
||||
}
|
||||
return BLI_rctf_size_x(&box) * xa;
|
||||
}
|
||||
|
||||
float blf_font_height(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
float blf_font_height(FontBLF *font,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
float ya;
|
||||
rctf box;
|
||||
|
@ -899,10 +911,10 @@ float blf_font_height(FontBLF *font, const char *str, size_t len, struct ResultB
|
|||
}
|
||||
|
||||
if (font->flags & BLF_WORD_WRAP) {
|
||||
blf_font_boundbox__wrap(font, str, len, &box, r_info);
|
||||
blf_font_boundbox__wrap(font, str, str_len, &box, r_info);
|
||||
}
|
||||
else {
|
||||
blf_font_boundbox(font, str, len, &box, r_info);
|
||||
blf_font_boundbox(font, str, str_len, &box, r_info);
|
||||
}
|
||||
return BLI_rctf_size_y(&box) * ya;
|
||||
}
|
||||
|
@ -930,7 +942,7 @@ float blf_font_fixed_width(FontBLF *font)
|
|||
static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
BLF_GlyphBoundsFn user_fn,
|
||||
void *user_data,
|
||||
struct ResultBLF *r_info,
|
||||
|
@ -942,12 +954,12 @@ static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
|
|||
size_t i = 0, i_curr;
|
||||
rcti gbox;
|
||||
|
||||
if (len == 0) {
|
||||
if (str_len == 0) {
|
||||
/* early output. */
|
||||
return;
|
||||
}
|
||||
|
||||
while ((i < len) && str[i]) {
|
||||
while ((i < str_len) && str[i]) {
|
||||
i_curr = i;
|
||||
g = blf_utf8_next_fast(font, gc, str, &i, &c);
|
||||
|
||||
|
@ -981,13 +993,13 @@ static void blf_font_boundbox_foreach_glyph_ex(FontBLF *font,
|
|||
}
|
||||
void blf_font_boundbox_foreach_glyph(FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
BLF_GlyphBoundsFn user_fn,
|
||||
void *user_data,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
GlyphCacheBLF *gc = blf_glyph_cache_acquire(font);
|
||||
blf_font_boundbox_foreach_glyph_ex(font, gc, str, len, user_fn, user_data, r_info, 0);
|
||||
blf_font_boundbox_foreach_glyph_ex(font, gc, str, str_len, user_fn, user_data, r_info, 0);
|
||||
blf_glyph_cache_release(font);
|
||||
}
|
||||
|
||||
|
@ -1008,12 +1020,12 @@ void blf_font_boundbox_foreach_glyph(FontBLF *font,
|
|||
*/
|
||||
static void blf_font_wrap_apply(FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info,
|
||||
void (*callback)(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
int pen_y,
|
||||
void *userdata),
|
||||
void *userdata)
|
||||
|
@ -1032,8 +1044,8 @@ static void blf_font_wrap_apply(FontBLF *font,
|
|||
size_t start, last[2];
|
||||
} wrap = {font->wrap_width != -1 ? font->wrap_width : INT_MAX, 0, {0, 0}};
|
||||
|
||||
// printf("%s wrapping (%d, %d) `%s`:\n", __func__, len, strlen(str), str);
|
||||
while ((i < len) && str[i]) {
|
||||
// printf("%s wrapping (%d, %d) `%s`:\n", __func__, str_len, strlen(str), str);
|
||||
while ((i < str_len) && str[i]) {
|
||||
|
||||
/* wrap vars */
|
||||
size_t i_curr = i;
|
||||
|
@ -1061,7 +1073,7 @@ static void blf_font_wrap_apply(FontBLF *font,
|
|||
if (UNLIKELY((pen_x_next >= wrap.wrap_width) && (wrap.start != wrap.last[0]))) {
|
||||
do_draw = true;
|
||||
}
|
||||
else if (UNLIKELY(((i < len) && str[i]) == 0)) {
|
||||
else if (UNLIKELY(((i < str_len) && str[i]) == 0)) {
|
||||
/* need check here for trailing newline, else we draw it */
|
||||
wrap.last[0] = i + ((g->c != '\n') ? 1 : 0);
|
||||
wrap.last[1] = i;
|
||||
|
@ -1112,54 +1124,61 @@ static void blf_font_wrap_apply(FontBLF *font,
|
|||
static void blf_font_draw__wrap_cb(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
int pen_y,
|
||||
void *UNUSED(userdata))
|
||||
{
|
||||
blf_font_draw_ex(font, gc, str, len, NULL, pen_y);
|
||||
blf_font_draw_ex(font, gc, str, str_len, NULL, pen_y);
|
||||
}
|
||||
void blf_font_draw__wrap(FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info)
|
||||
void blf_font_draw__wrap(FontBLF *font,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
blf_font_wrap_apply(font, str, len, r_info, blf_font_draw__wrap_cb, NULL);
|
||||
blf_font_wrap_apply(font, str, str_len, r_info, blf_font_draw__wrap_cb, NULL);
|
||||
}
|
||||
|
||||
/* blf_font_boundbox__wrap */
|
||||
static void blf_font_boundbox_wrap_cb(
|
||||
FontBLF *font, GlyphCacheBLF *gc, const char *str, size_t len, int pen_y, void *userdata)
|
||||
static void blf_font_boundbox_wrap_cb(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
const size_t str_len,
|
||||
int pen_y,
|
||||
void *userdata)
|
||||
{
|
||||
rctf *box = userdata;
|
||||
rctf box_single;
|
||||
|
||||
blf_font_boundbox_ex(font, gc, str, len, &box_single, NULL, pen_y);
|
||||
blf_font_boundbox_ex(font, gc, str, str_len, &box_single, NULL, pen_y);
|
||||
BLI_rctf_union(box, &box_single);
|
||||
}
|
||||
void blf_font_boundbox__wrap(
|
||||
FontBLF *font, const char *str, size_t len, rctf *box, struct ResultBLF *r_info)
|
||||
FontBLF *font, const char *str, const size_t str_len, rctf *box, struct ResultBLF *r_info)
|
||||
{
|
||||
box->xmin = 32000.0f;
|
||||
box->xmax = -32000.0f;
|
||||
box->ymin = 32000.0f;
|
||||
box->ymax = -32000.0f;
|
||||
|
||||
blf_font_wrap_apply(font, str, len, r_info, blf_font_boundbox_wrap_cb, box);
|
||||
blf_font_wrap_apply(font, str, str_len, r_info, blf_font_boundbox_wrap_cb, box);
|
||||
}
|
||||
|
||||
/* blf_font_draw_buffer__wrap */
|
||||
static void blf_font_draw_buffer__wrap_cb(FontBLF *font,
|
||||
GlyphCacheBLF *gc,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
int pen_y,
|
||||
void *UNUSED(userdata))
|
||||
{
|
||||
blf_font_draw_buffer_ex(font, gc, str, len, NULL, pen_y);
|
||||
blf_font_draw_buffer_ex(font, gc, str, str_len, NULL, pen_y);
|
||||
}
|
||||
void blf_font_draw_buffer__wrap(FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
const size_t str_len,
|
||||
struct ResultBLF *r_info)
|
||||
{
|
||||
blf_font_wrap_apply(font, str, len, r_info, blf_font_draw_buffer__wrap_cb, NULL);
|
||||
blf_font_wrap_apply(font, str, str_len, r_info, blf_font_draw_buffer__wrap_cb, NULL);
|
||||
}
|
||||
|
||||
/** \} */
|
||||
|
@ -1170,14 +1189,14 @@ void blf_font_draw_buffer__wrap(FontBLF *font,
|
|||
|
||||
int blf_font_count_missing_chars(FontBLF *font,
|
||||
const char *str,
|
||||
const size_t len,
|
||||
const size_t str_len,
|
||||
int *r_tot_chars)
|
||||
{
|
||||
int missing = 0;
|
||||
size_t i = 0;
|
||||
|
||||
*r_tot_chars = 0;
|
||||
while (i < len) {
|
||||
while (i < str_len) {
|
||||
unsigned int c;
|
||||
|
||||
if ((c = str[i]) < GLYPH_ASCII_TABLE_SIZE) {
|
||||
|
|
|
@ -53,46 +53,55 @@ struct FontBLF *blf_font_new_from_mem(const char *name, const unsigned char *mem
|
|||
void blf_font_attach_from_mem(struct FontBLF *font, const unsigned char *mem, int mem_size);
|
||||
|
||||
void blf_font_size(struct FontBLF *font, unsigned int size, unsigned int dpi);
|
||||
void blf_font_draw(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
|
||||
void blf_font_draw(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
void blf_font_draw__wrap(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
void blf_font_draw_ascii(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t len, int cwidth);
|
||||
int blf_font_draw_mono(struct FontBLF *font, const char *str, size_t str_len, int cwidth);
|
||||
void blf_font_draw_buffer(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
void blf_font_draw_buffer__wrap(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
size_t blf_font_width_to_strlen(
|
||||
struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
|
||||
struct FontBLF *font, const char *str, size_t str_len, float width, float *r_width);
|
||||
size_t blf_font_width_to_rstrlen(
|
||||
struct FontBLF *font, const char *str, size_t len, float width, float *r_width);
|
||||
struct FontBLF *font, const char *str, size_t str_len, float width, float *r_width);
|
||||
void blf_font_boundbox(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct rctf *r_box,
|
||||
struct ResultBLF *r_info);
|
||||
void blf_font_boundbox__wrap(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
struct rctf *r_box,
|
||||
struct ResultBLF *r_info);
|
||||
void blf_font_width_and_height(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
float *r_width,
|
||||
float *r_height,
|
||||
struct ResultBLF *r_info);
|
||||
float blf_font_width(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
|
||||
float blf_font_height(struct FontBLF *font, const char *str, size_t len, struct ResultBLF *r_info);
|
||||
float blf_font_width(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
float blf_font_height(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t str_len,
|
||||
struct ResultBLF *r_info);
|
||||
float blf_font_fixed_width(struct FontBLF *font);
|
||||
int blf_font_height_max(struct FontBLF *font);
|
||||
int blf_font_width_max(struct FontBLF *font);
|
||||
|
@ -103,7 +112,7 @@ char *blf_display_name(struct FontBLF *font);
|
|||
|
||||
void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
|
||||
const char *str,
|
||||
size_t len,
|
||||
size_t str_len,
|
||||
bool (*user_fn)(const char *str,
|
||||
const size_t str_step_ofs,
|
||||
const struct rcti *glyph_step_bounds,
|
||||
|
@ -116,7 +125,7 @@ void blf_font_boundbox_foreach_glyph(struct FontBLF *font,
|
|||
|
||||
int blf_font_count_missing_chars(struct FontBLF *font,
|
||||
const char *str,
|
||||
const size_t len,
|
||||
const size_t str_len,
|
||||
int *r_tot_chars);
|
||||
|
||||
void blf_font_free(struct FontBLF *font);
|
||||
|
|
Loading…
Reference in New Issue