Mercurial > hg > forks > bilotrip-mj12
comparison src/texture-font.h @ 0:785057719d9b
Import.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 05 Aug 2013 12:25:43 +0300 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:785057719d9b |
---|---|
1 /* ============================================================================ | |
2 * Freetype GL - A C OpenGL Freetype engine | |
3 * Platform: Any | |
4 * WWW: http://code.google.com/p/freetype-gl/ | |
5 * ---------------------------------------------------------------------------- | |
6 * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved. | |
7 * | |
8 * Redistribution and use in source and binary forms, with or without | |
9 * modification, are permitted provided that the following conditions are met: | |
10 * | |
11 * 1. Redistributions of source code must retain the above copyright notice, | |
12 * this list of conditions and the following disclaimer. | |
13 * | |
14 * 2. Redistributions in binary form must reproduce the above copyright | |
15 * notice, this list of conditions and the following disclaimer in the | |
16 * documentation and/or other materials provided with the distribution. | |
17 * | |
18 * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR | |
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF | |
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO | |
21 * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, | |
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | |
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | |
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
28 * | |
29 * The views and conclusions contained in the software and documentation are | |
30 * those of the authors and should not be interpreted as representing official | |
31 * policies, either expressed or implied, of Nicolas P. Rougier. | |
32 * ============================================================================ | |
33 */ | |
34 #ifndef __TEXTURE_FONT_H__ | |
35 #define __TEXTURE_FONT_H__ | |
36 | |
37 #include <stdlib.h> | |
38 | |
39 #ifdef __cplusplus | |
40 extern "C" { | |
41 #endif | |
42 | |
43 #include "vector.h" | |
44 #include "texture-atlas.h" | |
45 | |
46 /** | |
47 * @file texture-font.h | |
48 * @author Nicolas Rougier (Nicolas.Rougier@inria.fr) | |
49 * | |
50 * @defgroup texture-font Texture font | |
51 * | |
52 * Texture font. | |
53 * | |
54 * Example Usage: | |
55 * @code | |
56 * #include "texture-font.h" | |
57 * | |
58 * int main( int arrgc, char *argv[] ) | |
59 * { | |
60 * return 0; | |
61 * } | |
62 * @endcode | |
63 * | |
64 * @{ | |
65 */ | |
66 | |
67 | |
68 | |
69 /** | |
70 * A structure that hold a kerning value relatively to a charcode. | |
71 * | |
72 * This structure cannot be used alone since the (necessary) right charcode is | |
73 * implicitely held by the owner of this structure. | |
74 */ | |
75 typedef struct | |
76 { | |
77 /** | |
78 * Left character code in the kern pair. | |
79 */ | |
80 wchar_t charcode; | |
81 | |
82 /** | |
83 * Kerning value (in fractional pixels). | |
84 */ | |
85 float kerning; | |
86 | |
87 } kerning_t; | |
88 | |
89 | |
90 | |
91 | |
92 /* | |
93 * Glyph metrics: | |
94 * -------------- | |
95 * | |
96 * xmin xmax | |
97 * | | | |
98 * |<-------- width -------->| | |
99 * | | | |
100 * | +-------------------------+----------------- ymax | |
101 * | | ggggggggg ggggg | ^ ^ | |
102 * | | g:::::::::ggg::::g | | | | |
103 * | | g:::::::::::::::::g | | | | |
104 * | | g::::::ggggg::::::gg | | | | |
105 * | | g:::::g g:::::g | | | | |
106 * offset_x -|-------->| g:::::g g:::::g | offset_y | | |
107 * | | g:::::g g:::::g | | | | |
108 * | | g::::::g g:::::g | | | | |
109 * | | g:::::::ggggg:::::g | | | | |
110 * | | g::::::::::::::::g | | height | |
111 * | | gg::::::::::::::g | | | | |
112 * baseline ---*---------|---- gggggggg::::::g-----*-------- | | |
113 * / | | g:::::g | | | |
114 * origin | | gggggg g:::::g | | | |
115 * | | g:::::gg gg:::::g | | | |
116 * | | g::::::ggg:::::::g | | | |
117 * | | gg:::::::::::::g | | | |
118 * | | ggg::::::ggg | | | |
119 * | | gggggg | v | |
120 * | +-------------------------+----------------- ymin | |
121 * | | | |
122 * |------------- advance_x ---------->| | |
123 */ | |
124 | |
125 /** | |
126 * A structure that describe a glyph. | |
127 */ | |
128 typedef struct | |
129 { | |
130 /** | |
131 * Wide character this glyph represents | |
132 */ | |
133 wchar_t charcode; | |
134 | |
135 /** | |
136 * Glyph id (used for display lists) | |
137 */ | |
138 unsigned int id; | |
139 | |
140 /** | |
141 * Glyph's width in pixels. | |
142 */ | |
143 size_t width; | |
144 | |
145 /** | |
146 * Glyph's height in pixels. | |
147 */ | |
148 size_t height; | |
149 | |
150 /** | |
151 * Glyph's left bearing expressed in integer pixels. | |
152 */ | |
153 int offset_x; | |
154 | |
155 /** | |
156 * Glyphs's top bearing expressed in integer pixels. | |
157 * | |
158 * Remember that this is the distance from the baseline to the top-most | |
159 * glyph scanline, upwards y coordinates being positive. | |
160 */ | |
161 int offset_y; | |
162 | |
163 /** | |
164 * For horizontal text layouts, this is the horizontal distance (in | |
165 * fractional pixels) used to increment the pen position when the glyph is | |
166 * drawn as part of a string of text. | |
167 */ | |
168 float advance_x; | |
169 | |
170 /** | |
171 * For vertical text layouts, this is the vertical distance (in fractional | |
172 * pixels) used to increment the pen position when the glyph is drawn as | |
173 * part of a string of text. | |
174 */ | |
175 float advance_y; | |
176 | |
177 /** | |
178 * First normalized texture coordinate (x) of top-left corner | |
179 */ | |
180 float s0; | |
181 | |
182 /** | |
183 * Second normalized texture coordinate (y) of top-left corner | |
184 */ | |
185 float t0; | |
186 | |
187 /** | |
188 * First normalized texture coordinate (x) of bottom-right corner | |
189 */ | |
190 float s1; | |
191 | |
192 /** | |
193 * Second normalized texture coordinate (y) of bottom-right corner | |
194 */ | |
195 float t1; | |
196 | |
197 /** | |
198 * A vector of kerning pairs relative to this glyph. | |
199 */ | |
200 vector_t * kerning; | |
201 | |
202 /** | |
203 * Glyph outline type (0 = None, 1 = line, 2 = inner, 3 = outer) | |
204 */ | |
205 int outline_type; | |
206 | |
207 /** | |
208 * Glyph outline thickness | |
209 */ | |
210 float outline_thickness; | |
211 | |
212 } texture_glyph_t; | |
213 | |
214 | |
215 | |
216 /** | |
217 * Texture font structure. | |
218 */ | |
219 typedef struct | |
220 { | |
221 /** | |
222 * Vector of glyphs contained in this font. | |
223 */ | |
224 vector_t * glyphs; | |
225 | |
226 /** | |
227 * Atlas structure to store glyphs data. | |
228 */ | |
229 texture_atlas_t * atlas; | |
230 | |
231 /** | |
232 * Font filename | |
233 */ | |
234 char * filename; | |
235 | |
236 /** | |
237 * Font size | |
238 */ | |
239 float size; | |
240 | |
241 /** | |
242 * Whether to use autohint when rendering font | |
243 */ | |
244 int hinting; | |
245 | |
246 /** | |
247 * Outline type (0 = None, 1 = line, 2 = inner, 3 = outer) | |
248 */ | |
249 int outline_type; | |
250 | |
251 /** | |
252 * Outline thickness | |
253 */ | |
254 float outline_thickness; | |
255 | |
256 /** | |
257 * Whether to use our own lcd filter. | |
258 */ | |
259 int filtering; | |
260 | |
261 /** | |
262 * Whether to use kerning if available | |
263 */ | |
264 int kerning; | |
265 | |
266 /** | |
267 * LCD filter weights | |
268 */ | |
269 unsigned char lcd_weights[5]; | |
270 | |
271 /** | |
272 * This field is simply used to compute a default line spacing (i.e., the | |
273 * baseline-to-baseline distance) when writing text with this font. Note | |
274 * that it usually is larger than the sum of the ascender and descender | |
275 * taken as absolute values. There is also no guarantee that no glyphs | |
276 * extend above or below subsequent baselines when using this distance. | |
277 */ | |
278 float height; | |
279 | |
280 /** | |
281 * This field is the distance that must be placed between two lines of | |
282 * text. The baseline-to-baseline distance should be computed as: | |
283 * ascender - descender + linegap | |
284 */ | |
285 float linegap; | |
286 | |
287 /** | |
288 * The ascender is the vertical distance from the horizontal baseline to | |
289 * the highest 'character' coordinate in a font face. Unfortunately, font | |
290 * formats define the ascender differently. For some, it represents the | |
291 * ascent of all capital latin characters (without accents), for others it | |
292 * is the ascent of the highest accented character, and finally, other | |
293 * formats define it as being equal to bbox.yMax. | |
294 */ | |
295 float ascender; | |
296 | |
297 /** | |
298 * The descender is the vertical distance from the horizontal baseline to | |
299 * the lowest 'character' coordinate in a font face. Unfortunately, font | |
300 * formats define the descender differently. For some, it represents the | |
301 * descent of all capital latin characters (without accents), for others it | |
302 * is the ascent of the lowest accented character, and finally, other | |
303 * formats define it as being equal to bbox.yMin. This field is negative | |
304 * for values below the baseline. | |
305 */ | |
306 float descender; | |
307 | |
308 /** | |
309 * The position of the underline line for this face. It is the center of | |
310 * the underlining stem. Only relevant for scalable formats. | |
311 */ | |
312 float underline_position; | |
313 | |
314 /** | |
315 * The thickness of the underline for this face. Only relevant for scalable | |
316 * formats. | |
317 */ | |
318 float underline_thickness; | |
319 | |
320 } texture_font_t; | |
321 | |
322 | |
323 | |
324 /** | |
325 * This function creates a new texture font from given filename and size. The | |
326 * texture atlas is used to store glyph on demand. Note the depth of the atlas | |
327 * will determine if the font is rendered as alpha channel only (depth = 1) or | |
328 * RGB (depth = 3) that correspond to subpixel rendering (if available on your | |
329 * freetype implementation). | |
330 * | |
331 * @param atlas A texture atlas | |
332 * @param filename A font filename | |
333 * @param size Size of font to be created (in points) | |
334 * | |
335 * @return A new empty font (no glyph inside yet) | |
336 * | |
337 */ | |
338 texture_font_t * | |
339 texture_font_new( texture_atlas_t * atlas, | |
340 const char * filename, | |
341 const float size ); | |
342 | |
343 | |
344 /** | |
345 * Delete a texture font. Note that this does not delete the glyph from the | |
346 * texture atlas. | |
347 * | |
348 * @param self a valid texture font | |
349 */ | |
350 void | |
351 texture_font_delete( texture_font_t * self ); | |
352 | |
353 | |
354 /** | |
355 * Request a new glyph from the font. If it has not been created yet, it will | |
356 * be. | |
357 * | |
358 * @param self A valid texture font | |
359 * @param charcode Character codepoint to be loaded. | |
360 * | |
361 * @return A pointer on the new glyph or 0 if the texture atlas is not big | |
362 * enough | |
363 * | |
364 */ | |
365 texture_glyph_t * | |
366 texture_font_get_glyph( texture_font_t * self, | |
367 wchar_t charcode ); | |
368 | |
369 | |
370 /** | |
371 * Request the loading of several glyphs at once. | |
372 * | |
373 * @param self a valid texture font | |
374 * @param charcodes character codepoints to be loaded. | |
375 * | |
376 * @return Number of missed glyph if the texture is not big enough to hold | |
377 * every glyphs. | |
378 */ | |
379 size_t | |
380 texture_font_load_glyphs( texture_font_t * self, | |
381 const wchar_t * charcodes ); | |
382 | |
383 /** | |
384 * Get the kerning between two horizontal glyphs. | |
385 * | |
386 * @param self a valid texture glyph | |
387 * @param charcode codepoint of the peceding glyph | |
388 * | |
389 * @return x kerning value | |
390 */ | |
391 float | |
392 texture_glyph_get_kerning( const texture_glyph_t * self, | |
393 const wchar_t charcode ); | |
394 | |
395 | |
396 /** | |
397 * Creates a new empty glyph | |
398 * | |
399 * @return a new empty glyph (not valid) | |
400 */ | |
401 texture_glyph_t * | |
402 texture_glyph_new( void ); | |
403 | |
404 /** @} */ | |
405 | |
406 | |
407 #ifdef __cplusplus | |
408 } | |
409 #endif | |
410 | |
411 #endif /* __TEXTURE_FONT_H__ */ | |
412 |