summaryrefslogtreecommitdiff
path: root/src/lib/font.h
blob: 7d58a8ce2f603198ddeb654af9728cd2e55b681d (plain)
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
#include <ft2build.h>
#include FT_FREETYPE_H
#include FT_GLYPH_H

/* TODO separate fonts and data stuff */

typedef struct _Imlib_Font 		ImlibFont;
typedef struct _Imlib_Font_Glyph 	Imlib_Font_Glyph;

typedef struct _Imlib_Object_List 	Imlib_Object_List;
typedef struct _Imlib_Hash 		Imlib_Hash;
typedef struct _Imlib_Hash_El 		Imlib_Hash_El;

struct _Imlib_Object_List
{
   Imlib_Object_List  *next, *prev;
   Imlib_Object_List  *last;
};

struct _Imlib_Hash
{
   int                 population;
   Imlib_Object_List  *buckets[256];
};

struct _Imlib_Hash_El
{
   Imlib_Object_List   _list_data;
   char               *key;
   void               *data;
};

struct _Imlib_Font
{
   Imlib_Object_List   _list_data;
   char               *name;
   char               *file;
   int                 size;

   struct
   {
      FT_Face             face;
   }
   ft;

   Imlib_Hash         *glyphs;

   int                 usage;

   int                 references;

   /* using a double-linked list for the fallback chain */
   struct _Imlib_Font	*fallback_prev;
   struct _Imlib_Font	*fallback_next;
};

struct _Imlib_Font_Glyph
{
   FT_Glyph            glyph;
   FT_BitmapGlyph      glyph_out;
};

/* functions */

void                imlib_font_init(void);
int                 imlib_font_ascent_get(ImlibFont * fn);
int                 imlib_font_descent_get(ImlibFont * fn);
int                 imlib_font_max_ascent_get(ImlibFont * fn);
int                 imlib_font_max_descent_get(ImlibFont * fn);
int                 imlib_font_get_line_advance(ImlibFont * fn);
int                 imlib_font_utf8_get_next(unsigned char *buf, int *iindex);
void                imlib_font_add_font_path(const char *path);
void                imlib_font_del_font_path(const char *path);
int                 imlib_font_path_exists(const char *path);
char              **imlib_font_list_font_path(int *num_ret);
char              **imlib_font_list_fonts(int *num_ret);

ImlibFont          *imlib_font_load_joined(const char *name);
void                imlib_font_free(ImlibFont * fn);
int                 imlib_font_insert_into_fallback_chain_imp(ImlibFont * fn,
                                                              ImlibFont * fallback);
void                imlib_font_remove_from_fallback_chain_imp(ImlibFont * fn);
int                 imlib_font_cache_get(void);
void                imlib_font_cache_set(int size);
void                imlib_font_flush(void);
void                imlib_font_modify_cache_by(ImlibFont * fn, int dir);
void                imlib_font_modify_cache_by(ImlibFont * fn, int dir);
void                imlib_font_flush_last(void);
ImlibFont          *imlib_font_find(const char *name, int size);
ImlibFont          *imlib_font_find_glyph(ImlibFont * fn, int gl, unsigned int *ret_index);

void                imlib_font_query_size(ImlibFont * fn, const char *text,
					  int *w, int *h);
int                 imlib_font_query_inset(ImlibFont * fn, const char *text);
void                imlib_font_query_advance(ImlibFont * fn, const char *text,
					     int *h_adv, int *v_adv);
int                 imlib_font_query_char_coords(ImlibFont * fn,
						 const char *text, int pos,
						 int *cx, int *cy, int *cw,
						 int *ch);
int                 imlib_font_query_text_at_pos(ImlibFont * fn,
						 const char *text, int x, int y,
						 int *cx, int *cy, int *cw,
						 int *ch);

Imlib_Font_Glyph   *imlib_font_cache_glyph_get(ImlibFont * fn, FT_UInt index);
void                imlib_render_str(ImlibImage * im, ImlibFont * f, int drx,
				     int dry, const char *text, DATA8 r,
				     DATA8 g, DATA8 b, DATA8 a, char dir,
				     double angle, int *retw, int *reth,
				     int blur, int *nextx, int *nexty,
				     ImlibOp op, int clx, int cly, int clw,
				     int clh);
void                imlib_font_draw(ImlibImage * dst, DATA32 col,
				    ImlibFont * fn, int x, int y,
				    const char *text, int *nextx, int *nexty,
				    int clx, int cly, int clw, int clh);

/* data manipulation */

void               *imlib_object_list_prepend(void *in_list, void *in_item);
void               *imlib_object_list_remove(void *in_list, void *in_item);
Imlib_Hash         *imlib_hash_add(Imlib_Hash * hash, const char *key,
				   const void *data);
void               *imlib_hash_find(Imlib_Hash * hash, const char *key);
void                imlib_hash_free(Imlib_Hash * hash);
void                imlib_hash_foreach(Imlib_Hash * hash,
				       int (*func) (Imlib_Hash * hash,
						    const char *key, void *data,
						    void *fdata),
				       const void *fdata);