]> icculus.org git repositories - divverent/darkplaces.git/blob - ft2.h
adding font attachments, supporting type-1 fonts with .afm kerning info
[divverent/darkplaces.git] / ft2.h
1 /* Header for FreeType 2 and UTF-8 encoding support for
2  * DarkPlaces
3  */
4
5 #ifndef DP_FREETYPE2_H__
6 #define DP_FREETYPE2_H__
7
8 #include <sys/types.h>
9
10 // types for unicode strings
11 // let them be 32 bit for now
12 // normally, whcar_t is 16 or 32 bit, 16 on linux I think, 32 on haiku and maybe windows
13 #ifdef _MSC_VER
14 #include <stdint.h>
15 typedef __int32 U_int32;
16 #else
17 typedef int32_t U_int32;
18 #endif
19
20 // Uchar, a wide character
21 typedef U_int32 Uchar;
22
23 size_t u8_strlen(const char*);
24 Uchar  u8_getchar(const char*, const char**);
25 int    u8_fromchar(Uchar, char*, size_t);
26 size_t u8_wcstombs(char*, const Uchar*, size_t);
27
28 /* 
29  * From http://www.unicode.org/Public/UNIDATA/Blocks.txt
30  *
31  *   E000..F8FF; Private Use Area
32  *   F0000..FFFFF; Supplementary Private Use Area-A
33  *
34  * TODO:
35  *   Range E000 - E0FF
36  *     Contains the non-FreeType2 version of characters.
37  */
38
39 typedef struct ft2_font_map_s ft2_font_map_t;
40 typedef struct ft2_attachment_s ft2_attachment_t;
41
42 typedef float ft2_kernvec[2];
43 typedef struct ft2_kerning_s
44 {
45         ft2_kernvec kerning[256][256]; /* kerning[left char][right char] */
46 } ft2_kerning_t;
47
48 typedef struct ft2_font_s
49 {
50         char            name[64];
51         int             size;
52         int             glyphSize;
53
54         qboolean        has_kerning;
55
56         // TODO: clean this up and do not expose everything.
57         
58         unsigned char  *data;
59         fs_offset_t     datasize;
60         void           *face;
61
62         // an ordered linked list of glyph maps
63         ft2_font_map_t *font_map;
64         // contains the kerning information for the first 256 characters
65         // for the other characters, we will lookup the kerning information
66         ft2_kerning_t   kerning;
67         // size factor to convert from freetype units
68         double          sfx, sfy;
69
70         // attachments
71         size_t            attachmentcount;
72         ft2_attachment_t *attachments;
73 } ft2_font_t;
74
75 void        Font_CloseLibrary(void);
76 void        Font_Init(void);
77 qboolean    Font_OpenLibrary(void);
78 ft2_font_t* Font_Alloc(void);
79 void        Font_UnloadFont(ft2_font_t *font);
80 qboolean    Font_LoadFont(const char *name, int size, ft2_font_t *font);
81 qboolean    Font_GetKerning(ft2_font_t *font, Uchar left, Uchar right, float *outx, float *outy);
82 /*
83 float Font_DrawString_Font(
84         float startx, float starty,
85         const char *text, size_t maxlen,
86         float width, float height,
87         float basered, float basegreen, float baseblue, float basealpha,
88         int flags, int *outcolor, qboolean ignorecolorcodes,
89         ft2_font_t *font);
90 float Font_DrawString(
91         float startx, float starty,
92         const char *text, size_t maxlen,
93         float width, float height,
94         float basered, float basegreen, float baseblue, float basealpha,
95         int flags, int *outcolor, qboolean ignorecolorcodes);
96 */
97 #endif // DP_FREETYPE2_H__