]> git.xonotic.org Git - xonotic/darkplaces.git/blob - ft2.h
physics: fix and refactor unsticking
[xonotic/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 #include "utf8lib.h"
11
12 /* 
13  * From http://www.unicode.org/Public/UNIDATA/Blocks.txt
14  *
15  *   E000..F8FF; Private Use Area
16  *   F0000..FFFFF; Supplementary Private Use Area-A
17  *
18  * We use:
19  *   Range E000 - E0FF
20  *     Contains the non-FreeType2 version of characters.
21  */
22
23 typedef struct ft2_font_map_s ft2_font_map_t;
24 typedef struct font_incmap_s font_incmap_t;
25 typedef struct incmap_lookup_cache_s incmap_lookup_cache_t;
26 typedef struct ft2_attachment_s ft2_attachment_t;
27 #ifdef WIN64
28 #define ft2_oldstyle_map ((ft2_font_map_t*)-1LL)
29 #else
30 #define ft2_oldstyle_map ((ft2_font_map_t*)-1)
31 #endif
32
33 typedef float ft2_kernvec[2];
34 typedef struct ft2_kerning_s
35 {
36         ft2_kernvec kerning[256][256]; /* kerning[left char][right char] */
37 } ft2_kerning_t;
38
39 typedef struct ft2_font_s
40 {
41         char   name[64];
42         qbool  has_kerning;
43         // last requested size loaded using Font_SetSize
44         float  currentw;
45         float  currenth;
46         float  ascend;
47         float  descend;
48         qbool  image_font; // only fallbacks are freetype fonts
49
50         // TODO: clean this up and do not expose everything.
51
52         const unsigned char  *data; // FT2 needs it to stay
53         //fs_offset_t     datasize;
54         void                 *face;
55
56         // an unordered array of ordered linked lists of glyph maps for a specific size
57         ft2_font_map_t       *font_maps[MAX_FONT_SIZES];
58         int                   num_sizes;
59
60         // attachments
61         size_t                attachmentcount;
62         ft2_attachment_t     *attachments;
63
64         ft2_settings_t       *settings;
65
66         // fallback mechanism
67         struct ft2_font_s    *next;
68 } ft2_font_t;
69
70 void            Font_CloseLibrary(void);
71 void            Font_Init(void);
72 qbool           Font_OpenLibrary(void);
73 ft2_font_t*     Font_Alloc(void);
74 void            Font_UnloadFont(ft2_font_t *font);
75 // IndexForSize suggests to change the width and height if a font size is in a reasonable range
76 // for example, you render at a size of 12.4, and a font of size 12 has been loaded
77 // in such a case, *outw and *outh are set to 12, which is often a good alternative size
78 int             Font_IndexForSize(ft2_font_t *font, float size, float *outw, float *outh);
79 ft2_font_map_t *Font_MapForIndex(ft2_font_t *font, int index);
80 qbool           Font_LoadFont(const char *name, dp_font_t *dpfnt);
81 qbool           Font_GetKerningForSize(ft2_font_t *font, float w, float h, Uchar left, Uchar right, float *outx, float *outy);
82 qbool           Font_GetKerningForMap(ft2_font_t *font, int map_index, float w, float h, Uchar left, Uchar right, float *outx, float *outy);
83 float           Font_VirtualToRealSize(float sz);
84 float           Font_SnapTo(float val, float snapwidth);
85 // since this is used on a font_map_t, let's name it FontMap_*
86 ft2_font_map_t *FontMap_FindForChar(ft2_font_map_t *start, Uchar ch);
87 qbool           Font_GetMapForChar(ft2_font_t *font, int map_index, Uchar ch, ft2_font_map_t **outmap, int *outmapch);
88 #endif // DP_FREETYPE2_H__