-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathSDL_textengine.h
181 lines (152 loc) · 6.89 KB
/
SDL_textengine.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
/*
SDL_ttf: A companion library to SDL for working with TrueType (tm) fonts
Copyright (C) 2001-2025 Sam Lantinga <slouken@libsdl.org>
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.
*/
/**
* \file SDL_textengine.h
*
* Definitions for implementations of the TTF_TextEngine interface.
*/
#ifndef SDL_TTF_TEXTENGINE_H_
#define SDL_TTF_TEXTENGINE_H_
#include <SDL3/SDL.h>
#include <SDL3_ttf/SDL_ttf.h>
#include <SDL3/SDL_begin_code.h>
/* Set up for C function definitions, even when using C++ */
#ifdef __cplusplus
extern "C" {
#endif
/**
* A font atlas draw command.
*
* \since This enum is available since SDL_ttf 3.0.0.
*/
typedef enum TTF_DrawCommand
{
TTF_DRAW_COMMAND_NOOP,
TTF_DRAW_COMMAND_FILL,
TTF_DRAW_COMMAND_COPY
} TTF_DrawCommand;
/**
* A filled rectangle draw operation.
*
* \since This struct is available since SDL_ttf 3.0.0.
*
* \sa TTF_DrawOperation
*/
typedef struct TTF_FillOperation
{
TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_FILL */
SDL_Rect rect; /**< The rectangle to fill, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */
} TTF_FillOperation;
/**
* A texture copy draw operation.
*
* \since This struct is available since SDL_ttf 3.0.0.
*
* \sa TTF_DrawOperation
*/
typedef struct TTF_CopyOperation
{
TTF_DrawCommand cmd; /**< TTF_DRAW_COMMAND_COPY */
int text_offset; /**< The offset in the text corresponding to this glyph.
There may be multiple glyphs with the same text offset
and the next text offset might be several Unicode codepoints
later. In this case the glyphs and codepoints are grouped
together and the group bounding box is the union of the dst
rectangles for the corresponding glyphs. */
TTF_Font *glyph_font; /**< The font containing the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */
Uint32 glyph_index; /**< The glyph index of the glyph to be drawn, can be passed to TTF_GetGlyphImageForIndex() */
SDL_Rect src; /**< The area within the glyph to be drawn */
SDL_Rect dst; /**< The drawing coordinates of the glyph, in pixels. The x coordinate is relative to the left side of the text area, going right, and the y coordinate is relative to the top side of the text area, going down. */
void *reserved;
} TTF_CopyOperation;
/**
* A text engine draw operation.
*
* \since This struct is available since SDL_ttf 3.0.0.
*/
typedef union TTF_DrawOperation
{
TTF_DrawCommand cmd;
TTF_FillOperation fill;
TTF_CopyOperation copy;
} TTF_DrawOperation;
/* Private data in TTF_Text, to assist in text measurement and layout */
typedef struct TTF_TextLayout TTF_TextLayout;
/* Private data in TTF_Text, available to implementations */
struct TTF_TextData
{
TTF_Font *font; /**< The font used by this text, read-only. */
SDL_FColor color; /**< The color of the text, read-only. */
bool needs_layout_update; /**< True if the layout needs to be updated */
TTF_TextLayout *layout; /**< Cached layout information, read-only. */
int x; /**< The x offset of the upper left corner of this text, in pixels, read-only. */
int y; /**< The y offset of the upper left corner of this text, in pixels, read-only. */
int w; /**< The width of this text, in pixels, read-only. */
int h; /**< The height of this text, in pixels, read-only. */
int num_ops; /**< The number of drawing operations to render this text, read-only. */
TTF_DrawOperation *ops; /**< The drawing operations used to render this text, read-only. */
int num_clusters; /**< The number of substrings representing clusters of glyphs in the string, read-only */
TTF_SubString *clusters; /**< Substrings representing clusters of glyphs in the string, read-only */
SDL_PropertiesID props; /**< Custom properties associated with this text, read-only. This field is created as-needed using TTF_GetTextProperties() and the properties may be then set and read normally */
bool needs_engine_update; /**< True if the engine text needs to be updated */
TTF_TextEngine *engine; /**< The engine used to render this text, read-only. */
void *engine_text; /**< The implementation-specific representation of this text */
};
/**
* A text engine interface.
*
* This structure should be initialized using SDL_INIT_INTERFACE()
*
* \since This struct is available since SDL_ttf 3.0.0.
*
* \sa SDL_INIT_INTERFACE
*/
struct TTF_TextEngine
{
Uint32 version; /**< The version of this interface */
void *userdata; /**< User data pointer passed to callbacks */
/* Create a text representation from draw instructions.
*
* All fields of `text` except `internal->engine_text` will already be filled out.
*
* This function should set the `internal->engine_text` field to a non-NULL value.
*
* \param userdata the userdata pointer in this interface.
* \param text the text object being created.
*/
bool (SDLCALL *CreateText)(void *userdata, TTF_Text *text);
/**
* Destroy a text representation.
*/
void (SDLCALL *DestroyText)(void *userdata, TTF_Text *text);
};
/* Check the size of TTF_TextEngine
*
* If this assert fails, either the compiler is padding to an unexpected size,
* or the interface has been updated and this should be updated to match and
* the code using this interface should be updated to handle the old version.
*/
SDL_COMPILE_TIME_ASSERT(TTF_TextEngine_SIZE,
(sizeof(void *) == 4 && sizeof(TTF_TextEngine) == 16) ||
(sizeof(void *) == 8 && sizeof(TTF_TextEngine) == 32));
/* Ends C function definitions when using C++ */
#ifdef __cplusplus
}
#endif
#include <SDL3/SDL_close_code.h>
#endif /* SDL_TTF_TEXTENGINE_H_ */