version 2.8
mf_justify.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 /* Text alignment and justification algorithm. Supports left, right, center
9  * alignment and justify. Supports tab stops and kerning.
10  */
11 
12 #ifndef _MF_JUSTIFY_H_
13 #define _MF_JUSTIFY_H_
14 
15 #include "mf_rlefont.h"
16 #include <stdbool.h>
17 
18 enum mf_align_t
19 {
20  MF_ALIGN_LEFT = 0,
21  MF_ALIGN_CENTER,
22  MF_ALIGN_RIGHT
23 };
24 
25 /* Callback for rendering a single character.
26  * x0: Left edge of the target position of character.
27  * y0: Upper edge of the target position of character.
28  * character: Character to render.
29  * state: Free state variable for use by the callback.
30  * Returns the width of the character.
31  */
32 typedef uint8_t (*mf_character_callback_t) (int16_t x0, int16_t y0,
33  mf_char character, void *state);
34 
35 /* Get width of a string in pixels.
36  *
37  * font: Pointer to the font definition.
38  * text: Pointer to start of the text to measure.
39  * count: Number of characters on the line or 0 to read until end of string.
40  * kern: True to consider kerning (slower).
41  */
42 MF_EXTERN int16_t mf_get_string_width(const struct mf_font_s *font,
43  mf_str text, uint16_t count, bool kern);
44 
45 /* Render a single line of aligned text.
46  *
47  * font: Pointer to the font definition.
48  * x0: Depending on aligned, either left, center or right edge of target.
49  * y0: Upper edge of the target area.
50  * align: Type of alignment.
51  * text: Pointer to start of the text to render.
52  * count: Number of characters on the line or 0 to read until end of string.
53  * callback: Callback to call for each character.
54  * state: Free variable for use in the callback.
55  */
56 MF_EXTERN void mf_render_aligned(const struct mf_font_s *font,
57  int16_t x0, int16_t y0,
58  enum mf_align_t align,
59  mf_str text, uint16_t count,
60  mf_character_callback_t callback,
61  void *state);
62 
63 /* Render a single line of justified text.
64  *
65  * font: Pointer to the font definition.
66  * x0: Left edge of the target area.
67  * y0: Upper edge of the target area.
68  * width: Width of the target area.
69  * text: Pointer to start of the text to render.
70  * count: Number of characters on the line or 0 to read until end of string.
71  * callback: Callback to call for each character.
72  * state: Free variable for use in the callback.
73  */
74 MF_EXTERN void mf_render_justified(const struct mf_font_s *font,
75  int16_t x0, int16_t y0, int16_t width,
76  mf_str text, uint16_t count,
77  mf_character_callback_t callback,
78  void *state);
79 
80 
81 #endif