aboutsummaryrefslogtreecommitdiffstats
path: root/src/gdisp/mcufont/mf_wordwrap.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/gdisp/mcufont/mf_wordwrap.h')
-rw-r--r--src/gdisp/mcufont/mf_wordwrap.h32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/gdisp/mcufont/mf_wordwrap.h b/src/gdisp/mcufont/mf_wordwrap.h
new file mode 100644
index 00000000..bf3dbcb7
--- /dev/null
+++ b/src/gdisp/mcufont/mf_wordwrap.h
@@ -0,0 +1,32 @@
+/* Word wrapping algorithm with UTF-8 support. More than just a basic greedy
+ * word-wrapper: it attempts to balance consecutive lines as pairs.
+ */
+
+#ifndef _MF_WORDWRAP_H_
+#define _MF_WORDWRAP_H_
+
+#include "mf_rlefont.h"
+#include <stdbool.h>
+
+/* Callback function for handling each line.
+ *
+ * line: Pointer to the beginning of the string for this line.
+ * count: Number of characters on the line.
+ * state: Free variable that was passed to wordwrap().
+ *
+ * Returns: true to continue, false to stop after this line.
+ */
+typedef bool (*mf_line_callback_t) (mf_str line, uint16_t count,
+ void *state);
+
+/* Word wrap a piece of text. Calls the callback function for each line.
+ *
+ * font: Font to use for metrics.
+ * width: Maximum line width in pixels.
+ * text: Pointer to the start of the text to process.
+ * state: Free variable for caller to use (can be NULL).
+ */
+MF_EXTERN void mf_wordwrap(const struct mf_font_s *font, int16_t width,
+ mf_str text, mf_line_callback_t callback, void *state);
+
+#endif