comparison libcore/core/font.h @ 121:789b23e01f52

misc: reorganize hierarchy, closes #2490
author David Demelier <markand@malikania.fr>
date Mon, 05 Oct 2020 13:25:06 +0200
parents src/core/font.h@ed72843a7194
children 28d9bb62fcb1
comparison
equal deleted inserted replaced
120:b3429b26d60d 121:789b23e01f52
1 /*
2 * font.h -- basic font management
3 *
4 * Copyright (c) 2020 David Demelier <markand@malikania.fr>
5 *
6 * Permission to use, copy, modify, and/or distribute this software for any
7 * purpose with or without fee is hereby granted, provided that the above
8 * copyright notice and this permission notice appear in all copies.
9 *
10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17 */
18
19 #ifndef MOLKO_FONT_H
20 #define MOLKO_FONT_H
21
22 /**
23 * \file font.h
24 * \brief Basic font management.
25 * \ingroup drawing
26 */
27
28 #include <stdbool.h>
29 #include <stddef.h>
30
31 struct texture;
32
33 /**
34 * \brief Font style for rendering.
35 */
36 enum font_style {
37 FONT_STYLE_ANTIALIASED, /*!< Pretty antialiasing looking. */
38 FONT_STYLE_NONE /*!< No antialiasing. */
39 };
40
41 /**
42 * \brief Font object.
43 */
44 struct font {
45 enum font_style style; /*!< (RW) Style for rendering. */
46 unsigned long color; /*!< (RW) Color for rendering. */
47 void *handle; /*!< (RO) Native handle. */
48 };
49
50 /**
51 * Open font from path file.
52 *
53 * \pre font != NULL
54 * \pre path != NULL
55 * \param font the font to initialize
56 * \param path the path to the font
57 * \param size the desired size
58 * \return False on errors.
59 */
60 bool
61 font_open(struct font *font, const char *path, unsigned int size);
62
63 /**
64 * Open font from memory buffer.
65 *
66 * \pre font != NULL
67 * \pre buffer != NULL
68 * \param font the font to initialize
69 * \param buffer the memory buffer
70 * \param buflen the memory buffer length
71 * \param size the desired size
72 * \warning The buffer must remain valid until font is closed
73 * \return False on errors.
74 */
75 bool
76 font_openmem(struct font *font, const void *buffer, size_t buflen, unsigned int size);
77
78 /**
79 * Tells if the font was properly opened.
80 *
81 * \pre font != NULL
82 * \param font the font to check
83 * \return True if the native handle was opened.
84 */
85 bool
86 font_ok(const struct font *font);
87
88 /**
89 * Render some text into the texture.
90 *
91 * This function use the current color/style and other properties in the font
92 * to render the texture.
93 *
94 * \pre font != NULL
95 * \pre tex != NULL
96 * \param font the font to use
97 * \param tex the texture to generate
98 * \param text the UTF-8 text
99 * \return False on errors.
100 */
101 bool
102 font_render(struct font *font, struct texture *tex, const char *text);
103
104 /**
105 * Get the maximum height for all glyphs.
106 *
107 * \pre font != NULL
108 * \param font the font handle
109 * \return the height in pixels
110 */
111 unsigned int
112 font_height(const struct font *font);
113
114 /**
115 * Close the font.
116 *
117 * \pre font != NULL
118 * \param font the font handle
119 */
120 void
121 font_finish(struct font *font);
122
123 #endif /* !MOLKO_FONT_H */