- added libdrawtext
[demo_prior] / libs / drawtext / src / drawtext_impl.h
1 /*
2 libdrawtext - a simple library for fast text rendering in OpenGL
3 Copyright (C) 2011-2016  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #ifndef DRAWTEXT_IMPL_H_
19 #define DRAWTEXT_IMPL_H_
20
21 #include "drawtext.h"
22
23 struct glyph {
24         int code;
25         float x, y, width, height;
26         /* normalized coords [0, 1] */
27         float nx, ny, nwidth, nheight;
28         float orig_x, orig_y;
29         float advance;
30         struct glyph *next;
31 };
32
33 struct dtx_glyphmap {
34         int ptsize;
35
36         int xsz, ysz;
37         unsigned int xsz_shift;
38         unsigned char *pixels;
39         unsigned int tex;
40         int tex_valid;
41         void *udata;
42
43         int cstart, cend;       /* character range */
44         int crange;
45
46         float line_advance;
47         float baseline;
48
49         struct glyph *glyphs;
50         struct dtx_glyphmap *next;
51 };
52
53 struct dtx_font {
54         /* freetype FT_Face */
55         void *face;
56
57         /* list of glyphmaps */
58         struct dtx_glyphmap *gmaps;
59
60         /* last returned glyphmap (cache) */
61         struct dtx_glyphmap *last_gmap;
62 };
63
64 #ifndef COMMON
65 #define COMMON extern
66 #endif
67
68 COMMON struct dtx_font *dtx_font;
69 COMMON int dtx_font_sz;
70 COMMON int dtx_buf_mode;        /* DTX_NBF is 0 */
71 COMMON float dtx_cur_color[4];
72 COMMON int dtx_cur_color_int[4];
73 COMMON float dtx_cur_offset[2];
74
75 #define fperror(str) \
76         fprintf(stderr, "%s: %s: %s\n", __func__, (str), strerror(errno))
77
78 #ifdef _MSC_VER
79 #define __func__        __FUNCTION__
80 #endif
81
82 /* returns zero if it should NOT be printed and modifies xpos/ypos */
83 /* implemented in font.c */
84 struct dtx_glyphmap *dtx_proc_char(int code, float *xpos, float *ypos);
85
86 COMMON const char *(*dtx_drawchar)(const char*, float*, float*, int*);
87 COMMON void (*dtx_drawflush)(void);
88
89 int dtx_gl_setopt(enum dtx_option opt, int val);
90 int dtx_gl_getopt(enum dtx_option opt, int *ret);
91 int dtx_rast_setopt(enum dtx_option opt, int val);
92 int dtx_rast_getopt(enum dtx_option opt, int *ret);
93
94 #endif  /* DRAWTEXT_IMPL_H_ */