forked from rougier/freetype-gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
text-buffer.h
305 lines (252 loc) · 4.94 KB
/
text-buffer.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
/* Freetype GL - A C OpenGL Freetype engine
*
* Distributed under the OSI-approved BSD 2-Clause License. See accompanying
* file `LICENSE` for more details.
*/
#ifndef __TEXT_BUFFER_H__
#define __TEXT_BUFFER_H__
#ifdef __cplusplus
extern "C" {
#endif
#include "vertex-buffer.h"
#include "markup.h"
#ifdef __cplusplus
namespace ftgl {
#endif
/**
* Use LCD filtering
*/
#define LCD_FILTERING_ON 3
/**
* Do not use LCD filtering
*/
#define LCD_FILTERING_OFF 1
/**
* @file text-buffer.h
* @author Nicolas Rougier ([email protected])
*
* @defgroup text-buffer Text buffer
*
*
* <b>Example Usage</b>:
* @code
*
* int main( int arrgc, char *argv[] )
* {
*
* return 0;
* }
* @endcode
*
* @{
*/
/**
* Text buffer structure
*/
typedef struct text_buffer_t {
/**
* Vertex buffer
*/
vertex_buffer_t *buffer;
/**
* Base color for text
*/
vec4 base_color;
/**
* Pen origin
*/
vec2 origin;
/**
* Last pen y location
*/
float last_pen_y;
/**
* Total bounds
*/
vec4 bounds;
/**
* Index (in the vertex buffer) of the current line start
*/
size_t line_start;
/**
* Location of the start of the line
*/
float line_left;
/**
* Vector of line information
*/
vector_t * lines;
/**
* Current line ascender
*/
float line_ascender;
/**
* Current line decender
*/
float line_descender;
} text_buffer_t;
/**
* Glyph vertex structure
*/
typedef struct glyph_vertex_t {
/**
* Vertex x coordinates
*/
float x;
/**
* Vertex y coordinates
*/
float y;
/**
* Vertex z coordinates
*/
float z;
/**
* Texture first coordinate
*/
float u;
/**
* Texture second coordinate
*/
float v;
/**
* Color red component
*/
float r;
/**
* Color green component
*/
float g;
/**
* Color blue component
*/
float b;
/**
* Color alpha component
*/
float a;
/**
* Shift along x
*/
float shift;
/**
* Color gamma correction
*/
float gamma;
} glyph_vertex_t;
/**
* Line structure
*/
typedef struct line_info_t {
/**
* Index (in the vertex buffer) where this line starts
*/
size_t line_start;
/**
* bounds of this line
*/
vec4 bounds;
} line_info_t;
/**
* Align enumeration
*/
typedef enum Align
{
/**
* Align text to the left hand side
*/
ALIGN_LEFT,
/**
* Align text to the center
*/
ALIGN_CENTER,
/**
* Align text to the right hand side
*/
ALIGN_RIGHT
} Align;
/**
* Creates a new empty text buffer.
*
* @return a new empty text buffer.
*
*/
text_buffer_t *
text_buffer_new( );
/**
* Deletes texture buffer and its associated vertex buffer.
*
* @param self texture buffer to delete
*
*/
void
text_buffer_delete( text_buffer_t * self );
/**
* Print some text to the text buffer
*
* @param self a text buffer
* @param pen position of text start
* @param ... a series of markup_t *, char * ended by NULL
*
*/
void
text_buffer_printf( text_buffer_t * self, vec2 * pen, ... );
/**
* Add some text to the text buffer
*
* @param self a text buffer
* @param pen position of text start
* @param markup Markup to be used to add text
* @param text Text to be added
* @param length Length of text to be added
*/
void
text_buffer_add_text( text_buffer_t * self,
vec2 * pen, markup_t * markup,
const char * text, size_t length );
/**
* Add a char to the text buffer
*
* @param self a text buffer
* @param pen position of text start
* @param markup markup to be used to add text
* @param current charactr to be added
* @param previous previous character (if any)
*/
void
text_buffer_add_char( text_buffer_t * self,
vec2 * pen, markup_t * markup,
const char * current, const char * previous );
/**
* Align all the lines of text already added to the buffer
* This alignment will be relative to the overall bounds of the
* text which can be queried by text_buffer_get_bounds
*
* @param self a text buffer
* @param pen pen used in last call (must be unmodified)
* @param alignment desired alignment of text
*/
void
text_buffer_align( text_buffer_t * self, vec2 * pen,
enum Align alignment );
/**
* Get the rectangle surrounding the text
*
* @param self a text buffer
* @param pen pen used in last call (must be unmodified)
*/
vec4
text_buffer_get_bounds( text_buffer_t * self, vec2 * pen );
/**
* Clear text buffer
*
* @param self a text buffer
*/
void
text_buffer_clear( text_buffer_t * self );
/** @} */
#ifdef __cplusplus
}
}
#endif
#endif /* #define __TEXT_BUFFER_H__ */