diff options
author | Campbell Barton <ideasman42@gmail.com> | 2015-09-18 13:10:26 +0300 |
---|---|---|
committer | Campbell Barton <ideasman42@gmail.com> | 2015-09-18 13:43:52 +0300 |
commit | f2341f829654c4dc97fcf9fd1f74a6526c4f50ff (patch) | |
tree | 7287c4bbe46c06394353e1f57d62a6dff8803876 /source/blender/blenfont/BLF_api.h | |
parent | e9dd060102f2ca84530ed000a063abbd53b99962 (diff) |
BLF: initial word-wrap support
- Adds support for word wrapping to Blender's BLF font library.
- Splits lines when width limit is reached or on explicit \n newlines.
Details:
- Word wrapping is used when `BLF_WORD_WRAP` flag is enabled.
- There is a single loop to handle line wrapping,
this runs callback, passing in a substring,
this way we can avoid code-duplication for all word-wrapped
versions of functions... OR... avoid having to add support
for word-wrapping directly into each function.
- The `ResultBLF` struct was added to be able to get the number
of wrapped lines, when calling otherwise unrelated functions
such as `BLF_draw/BLF_width/BLF_boundbox`,
which can be passed as the last argument to `BLF_*_ex()` functions.
- The `ResultBLF` struct is used to store the result of drawing
(currently only the number of lines wrapped, and the width).
Diffstat (limited to 'source/blender/blenfont/BLF_api.h')
-rw-r--r-- | source/blender/blenfont/BLF_api.h | 33 |
1 files changed, 28 insertions, 5 deletions
diff --git a/source/blender/blenfont/BLF_api.h b/source/blender/blenfont/BLF_api.h index d8dee7110a5..9527c4edcf0 100644 --- a/source/blender/blenfont/BLF_api.h +++ b/source/blender/blenfont/BLF_api.h @@ -36,6 +36,7 @@ struct rctf; struct ColorManagedDisplay; +struct ResultBLF; int BLF_init(int points, int dpi); void BLF_exit(void); @@ -79,9 +80,11 @@ void BLF_draw_default(float x, float y, float z, const char *str, size_t len) AT void BLF_draw_default_ascii(float x, float y, float z, const char *str, size_t len) ATTR_NONNULL(); /* Draw the string using the current font. */ -void BLF_draw(int fontid, const char *str, size_t len); -void BLF_draw_ascii(int fontid, const char *str, size_t len); -int BLF_draw_mono(int fontid, const char *str, size_t len, int cwidth); +void BLF_draw_ex(int fontid, const char *str, size_t 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) 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); /* 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); @@ -91,17 +94,20 @@ size_t BLF_width_to_rstrlen(int fontid, const char *str, size_t len, float width /* 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, 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(); /* 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) 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) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2); float BLF_height(int fontid, const char *str, size_t len) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(); /* Return dimensions of the font without any sample text. */ -float BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT; +int BLF_height_max(int fontid) ATTR_WARN_UNUSED_RESULT; float BLF_width_max(int fontid) ATTR_WARN_UNUSED_RESULT; float BLF_descender(int fontid) ATTR_WARN_UNUSED_RESULT; float BLF_ascender(int fontid) ATTR_WARN_UNUSED_RESULT; @@ -137,6 +143,7 @@ void BLF_disable_default(int option); void BLF_rotation(int fontid, float angle); void BLF_clipping(int fontid, float xmin, float ymin, float xmax, float ymax); void BLF_clipping_default(float xmin, float ymin, float xmax, float ymax); +void BLF_wordwrap(int fontid, int wrap_width); void BLF_blur(int fontid, int size); void BLF_enable(int fontid, int option); @@ -172,7 +179,8 @@ void BLF_buffer_col(int fontid, float r, float g, float b, float a); /* 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(int fontid, const char *str) ATTR_NONNULL(); +void BLF_draw_buffer_ex(int fontid, const char *str, size_t len, struct ResultBLF *r_info) ATTR_NONNULL(2); +void BLF_draw_buffer(int fontid, const char *str, size_t len) ATTR_NONNULL(2); /* Add a path to the font dir paths. */ void BLF_dir_add(const char *path) ATTR_NONNULL(); @@ -210,6 +218,7 @@ void BLF_state_print(int fontid); #define BLF_MATRIX (1 << 4) #define BLF_ASPECT (1 << 5) #define BLF_HINTING (1 << 6) +#define BLF_WORD_WRAP (1 << 7) #define BLF_DRAW_STR_DUMMY_MAX 1024 @@ -217,4 +226,18 @@ void BLF_state_print(int fontid); extern int blf_mono_font; extern int blf_mono_font_render; /* don't mess drawing with render threads. */ +/** + * Result of drawing/evaluating the string + */ +struct ResultBLF { + /** + * Number of lines drawn when #BLF_WORD_WRAP is enabled (both wrapped and `\n` newline). + */ + int lines; + /** + * The 'cursor' position on completion (ignoring character boundbox). + */ + int width; +}; + #endif /* __BLF_API_H__ */ |