annotate libcore/core/font.h @ 162:629f55f3961e

core: rework states
author David Demelier <markand@malikania.fr>
date Sun, 18 Oct 2020 12:01:59 +0200
parents e05a792f6910
children eb0a7ab71023
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
1 /*
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
2 * font.h -- basic font management
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
3 *
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
5 *
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
6 * Permission to use, copy, modify, and/or distribute this software for any
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
7 * purpose with or without fee is hereby granted, provided that the above
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
8 * copyright notice and this permission notice appear in all copies.
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
9 *
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
17 */
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
18
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
19 #ifndef MOLKO_FONT_H
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
20 #define MOLKO_FONT_H
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
21
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
22 /**
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
23 * \file font.h
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
24 * \brief Basic font management.
72
6203e1ac9b18 doc: improve doxygen documentation a lot
David Demelier <markand@malikania.fr>
parents: 59
diff changeset
25 * \ingroup drawing
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
26 */
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
27
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
28 #include <stdbool.h>
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
29 #include <stddef.h>
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
30
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
31 struct texture;
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
32
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
33 /**
79
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
34 * \brief Font style for rendering.
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
35 */
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
36 enum font_style {
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
37 FONT_STYLE_ANTIALIASED, /*!< Pretty antialiasing looking. */
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
38 FONT_STYLE_NONE /*!< No antialiasing. */
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
39 };
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
40
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
41 /**
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
42 * \brief Font object.
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
43 */
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
44 struct font {
147
b386d25832c8 doc: use new nomenclature, closes #2497
David Demelier <markand@malikania.fr>
parents: 144
diff changeset
45 enum font_style style; /*!< (+) Style for rendering. */
b386d25832c8 doc: use new nomenclature, closes #2497
David Demelier <markand@malikania.fr>
parents: 144
diff changeset
46 unsigned long color; /*!< (+) Color for rendering. */
b386d25832c8 doc: use new nomenclature, closes #2497
David Demelier <markand@malikania.fr>
parents: 144
diff changeset
47 void *handle; /*!< (*) Native handle. */
79
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
48 };
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
49
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
50 /**
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
51 * Open font from path file.
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
52 *
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
53 * \pre font != NULL
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
54 * \pre path != NULL
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
55 * \param font the font to initialize
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
56 * \param path the path to the font
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
57 * \param size the desired size
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
58 * \return False on errors.
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
59 */
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
60 bool
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
61 font_open(struct font *font, const char *path, unsigned int size);
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
62
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
63 /**
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
64 * Open font from memory buffer.
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
65 *
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
66 * \pre font != NULL
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
67 * \pre buffer != NULL
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
68 * \param font the font to initialize
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
69 * \param buffer the memory buffer
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
70 * \param buflen the memory buffer length
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
71 * \param size the desired size
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
72 * \warning The buffer must remain valid until font is closed
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
73 * \return False on errors.
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
74 */
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
75 bool
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
76 font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size);
79
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
77
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
78 /**
154
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
79 * Convenient shortcut to shallow copy src into dst.
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
80 *
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
81 * Use this function when you want your own local font to update its attributes
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
82 * without changing the calling site.
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
83 *
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
84 * This is a shortcut to `memcpy(dst, src, sizeof (*src))`.
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
85 *
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
86 * \pre dst != NULL
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
87 * \param dst the destination font
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
88 * \param src the source font (may be NULL)
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
89 * \note Internal handle points to the same pointer, do not use \ref font_finish
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
90 * on the destination.
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
91 */
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
92 void
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
93 font_shallow(struct font *dst, const struct font *src);
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
94
2252f9efac9a ui: remove style from debug_report, closes #2499
David Demelier <markand@malikania.fr>
parents: 147
diff changeset
95 /**
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
96 * Tells if the font was properly opened.
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
97 *
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
98 * \pre font != NULL
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
99 * \param font the font to check
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
100 * \return True if the native handle was opened.
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
101 */
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
102 bool
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
103 font_ok(const struct font *font);
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
104
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
105 /**
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
106 * Render some text into the texture.
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
107 *
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
108 * This function use the current color/style and other properties in the font
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
109 * to render the texture.
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
110 *
144
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
111 * \pre font_ok(font)
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
112 * \pre tex != NULL
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
113 * \param font the font to use
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
114 * \param tex the texture to generate
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
115 * \param text the UTF-8 text
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
116 * \return False on errors.
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
117 */
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
118 bool
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
119 font_render(struct font *font, struct texture *tex, const char *text);
79
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
120
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
121 /**
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
122 * Get the maximum height for all glyphs.
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
123 *
144
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
124 * \pre font_ok(font)
79
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
125 * \param font the font handle
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
126 * \return the height in pixels
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
127 */
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
128 unsigned int
8f95462ac5f8 core: create a debugging API, closes #2469 @2h
David Demelier <markand@malikania.fr>
parents: 72
diff changeset
129 font_height(const struct font *font);
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
130
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
131 /**
144
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
132 * Compute the text size required with this font.
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
133 *
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
134 * \pre font_ok(font)
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
135 * \pre text != NULL
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
136 * \param font the font object
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
137 * \param text the UTF-8 text
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
138 * \param w pointer to width (may be NULL)
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
139 * \param h pointer to height (may be NULL)
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
140 * \return false in case of error and pointers to w and h are left unmodified
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
141 */
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
142 bool
159
e05a792f6910 ui: make message less clever and provide spacing field
David Demelier <markand@malikania.fr>
parents: 154
diff changeset
143 font_query(const struct font *font, const char *text, unsigned int *w, unsigned int *h);
144
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
144
28d9bb62fcb1 core: add font_box function, closes #2495
David Demelier <markand@malikania.fr>
parents: 121
diff changeset
145 /**
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
146 * Close the font.
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
147 *
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
148 * \pre font != NULL
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
149 * \param font the font handle
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
150 */
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
151 void
94
ed72843a7194 core: simplify font/texture interfaces
David Demelier <markand@malikania.fr>
parents: 79
diff changeset
152 font_finish(struct font *font);
10
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
153
c91c3272101b core: implement fonts, closes #2444
David Demelier <markand@malikania.fr>
parents:
diff changeset
154 #endif /* !MOLKO_FONT_H */