version 2.8
mf_wordwrap.h
1 /*
2  * This file is subject to the terms of the GFX License. If a copy of
3  * the license was not distributed with this file, you can obtain one at:
4  *
5  * http://ugfx.org/license.html
6  */
7 
8 /* Word wrapping algorithm with UTF-8 support. More than just a basic greedy
9  * word-wrapper: it attempts to balance consecutive lines as pairs.
10  */
11 
12 #ifndef _MF_WORDWRAP_H_
13 #define _MF_WORDWRAP_H_
14 
15 #include "mf_rlefont.h"
16 #include <stdbool.h>
17 
18 /* Callback function for handling each line.
19  *
20  * line: Pointer to the beginning of the string for this line.
21  * count: Number of characters on the line.
22  * state: Free variable that was passed to wordwrap().
23  *
24  * Returns: true to continue, false to stop after this line.
25  */
26 typedef bool (*mf_line_callback_t) (mf_str line, uint16_t count,
27  void *state);
28 
29 /* Word wrap a piece of text. Calls the callback function for each line.
30  *
31  * font: Font to use for metrics.
32  * width: Maximum line width in pixels.
33  * text: Pointer to the start of the text to process.
34  * state: Free variable for caller to use (can be NULL).
35  */
36 MF_EXTERN void mf_wordwrap(const struct mf_font_s *font, int16_t width,
37  mf_str text, mf_line_callback_t callback, void *state);
38 
39 #endif