Mirai's Miscellaneous Misadventures

M39 / include / mimimi / text.h

1// copyright 2023 zamfofex
2// license: AGPLv3 or later
3
4#ifndef MIMIMI_TEXT_H
5#define MIMIMI_TEXT_H
6
7struct mimimi_allocator;
8struct mimimi_font;
9struct mimimi_image;
10
11// Note: Pointers to 'char' are in the execution encoding.
12// Note: Pointers to 'unsigned char' are in UTF-8.
13// Note: 'unsigned long int' values represent code points.
14// Note: All counts regard bytes.
15// Note: Where relevant and otherwise unspecified, the default direction will be LTR.
16// Note: The word "grapheme" refers to default extended grapheme clusters.
17
18// Converts from the execution encoding to UTF-8.
19// Note: Skips characters outside the basic execution character set (as defined by C99, C11, C17, and C23).
20// Note: The returned value needs to be dealocated appropriately.
21unsigned char *mimimi_utf8(char *text, struct mimimi_allocator *allocator);
22
23// Returns the value of the first Unicode code point in the text.
24unsigned long int mimimi_code_point(unsigned char *text);
25
26// Counts the number of bytes in a type of text segment.
27// Note: If the string starts at a delimiter, these return zero.
28int mimimi_count_code_point(unsigned char *text);
29int mimimi_count_grapheme(unsigned char *text);
30int mimimi_count_word(unsigned char *text);
31int mimimi_count_paragraph(unsigned char *text);
32int mimimi_count_text(unsigned char *text);
33
34// Skips a type of text segment and its delimiter (if any).
35// Note: If the string starts at a delimiter, these skip to the start of the next segment of their type.
36unsigned char *mimimi_skip_code_point(unsigned char *text);
37unsigned char *mimimi_skip_grapheme(unsigned char *text);
38unsigned char *mimimi_skip_word(unsigned char *text);
39unsigned char *mimimi_skip_paragraph(unsigned char *text);
40
41int mimimi_count_line(unsigned char *text, int width, struct mimimi_font *font);
42unsigned char *mimimi_skip_line(unsigned char *text, int width, struct mimimi_font *font);
43int mimimi_measure_line(unsigned char *paragraph, unsigned char *text, int count, struct mimimi_font *font);
44
45int mimimi_draw_segment(struct mimimi_image *image, int x, int y, unsigned char *paragraph, unsigned char *line, int line_count, unsigned char *text, int count, struct mimimi_font *font, unsigned char color);
46int mimimi_draw_line(struct mimimi_image *image, int x, int y, unsigned char *paragraph, unsigned char *text, int count, struct mimimi_font *font, unsigned char color);
47int mimimi_draw_text(struct mimimi_image *image, int x, int y, int width, int height, unsigned char *text, struct mimimi_font *font, unsigned char color);
48
49#endif