1 #include <ft2build.h>
2 #include FT_FREETYPE_H
3 #include FT_GLYPH_H
4 
5 #include "common.h"
6 
7 /* TODO separate fonts and data stuff */
8 
9 typedef struct _Imlib_Font ImlibFont;
10 typedef struct _Imlib_Font_Glyph Imlib_Font_Glyph;
11 
12 typedef struct _Imlib_Object_List Imlib_Object_List;
13 typedef struct _Imlib_Hash Imlib_Hash;
14 typedef struct _Imlib_Hash_El Imlib_Hash_El;
15 
16 struct _Imlib_Object_List {
17    Imlib_Object_List  *next, *prev;
18    Imlib_Object_List  *last;
19 };
20 
21 struct _Imlib_Hash {
22    int                 population;
23    Imlib_Object_List  *buckets[256];
24 };
25 
26 struct _Imlib_Hash_El {
27    Imlib_Object_List   _list_data;
28    char               *key;
29    void               *data;
30 };
31 
32 struct _Imlib_Font {
33    Imlib_Object_List   _list_data;
34    char               *name;
35    char               *file;
36    int                 size;
37 
38    struct {
39       FT_Face             face;
40    } ft;
41 
42    Imlib_Hash         *glyphs;
43 
44    int                 usage;
45 
46    int                 references;
47 
48    /* using a double-linked list for the fallback chain */
49    struct _Imlib_Font *fallback_prev;
50    struct _Imlib_Font *fallback_next;
51 };
52 
53 struct _Imlib_Font_Glyph {
54    FT_Glyph            glyph;
55    FT_BitmapGlyph      glyph_out;
56 };
57 
58 /* functions */
59 
60 void                __imlib_font_init(void);
61 int                 __imlib_font_ascent_get(ImlibFont * fn);
62 int                 __imlib_font_descent_get(ImlibFont * fn);
63 int                 __imlib_font_max_ascent_get(ImlibFont * fn);
64 int                 __imlib_font_max_descent_get(ImlibFont * fn);
65 int                 __imlib_font_get_line_advance(ImlibFont * fn);
66 int                 __imlib_font_utf8_get_next(unsigned char *buf, int *iindex);
67 void                __imlib_font_add_font_path(const char *path);
68 void                __imlib_font_del_font_path(const char *path);
69 int                 __imlib_font_path_exists(const char *path);
70 char              **__imlib_font_list_font_path(int *num_ret);
71 char              **__imlib_font_list_fonts(int *num_ret);
72 
73 ImlibFont          *__imlib_font_load_joined(const char *name);
74 void                __imlib_font_free(ImlibFont * fn);
75 int                 __imlib_font_insert_into_fallback_chain_imp(ImlibFont * fn,
76                                                                 ImlibFont *
77                                                                 fallback);
78 void                __imlib_font_remove_from_fallback_chain_imp(ImlibFont * fn);
79 int                 __imlib_font_cache_get(void);
80 void                __imlib_font_cache_set(int size);
81 void                __imlib_font_flush(void);
82 void                __imlib_font_modify_cache_by(ImlibFont * fn, int dir);
83 void                __imlib_font_modify_cache_by(ImlibFont * fn, int dir);
84 void                __imlib_font_flush_last(void);
85 ImlibFont          *__imlib_font_find(const char *name, int size);
86 ImlibFont          *__imlib_font_find_glyph(ImlibFont * fn, int gl,
87                                             unsigned int *ret_index);
88 
89 void                __imlib_font_query_size(ImlibFont * fn, const char *text,
90                                             int *w, int *h);
91 int                 __imlib_font_query_inset(ImlibFont * fn, const char *text);
92 void                __imlib_font_query_advance(ImlibFont * fn, const char *text,
93                                                int *h_adv, int *v_adv);
94 int                 __imlib_font_query_char_coords(ImlibFont * fn,
95                                                    const char *text, int pos,
96                                                    int *cx, int *cy,
97                                                    int *cw, int *ch);
98 int                 __imlib_font_query_text_at_pos(ImlibFont * fn,
99                                                    const char *text,
100                                                    int x, int y,
101                                                    int *cx, int *cy,
102                                                    int *cw, int *ch);
103 
104 Imlib_Font_Glyph   *__imlib_font_cache_glyph_get(ImlibFont * fn, FT_UInt index);
105 void                __imlib_render_str(ImlibImage * im, ImlibFont * f,
106                                        int drx, int dry, const char *text,
107                                        DATA32 pixel, int dir, double angle,
108                                        int *retw, int *reth, int blur,
109                                        int *nextx, int *nexty, ImlibOp op,
110                                        int clx, int cly, int clw, int clh);
111 void                __imlib_font_draw(ImlibImage * dst, DATA32 col,
112                                       ImlibFont * fn, int x, int y,
113                                       const char *text, int *nextx, int *nexty,
114                                       int clx, int cly, int clw, int clh);
115 
116 /* data manipulation */
117 
118 void               *__imlib_object_list_prepend(void *in_list, void *in_item);
119 void               *__imlib_object_list_remove(void *in_list, void *in_item);
120 Imlib_Hash         *__imlib_hash_add(Imlib_Hash * hash, const char *key,
121                                      const void *data);
122 void               *__imlib_hash_find(Imlib_Hash * hash, const char *key);
123 void                __imlib_hash_free(Imlib_Hash * hash);
124 void                __imlib_hash_foreach(Imlib_Hash * hash,
125                                          int (*func)(Imlib_Hash * hash,
126                                                      const char *key,
127                                                      void *data, void *fdata),
128                                          const void *fdata);
129