move around - flatter.
[profile/ivi/evas.git] / src / lib / imaging / evas_imaging.c
1 #ifdef HAVE_CONFIG_H
2 # include "config.h"  /* so that EAPI in Eet.h is correctly defined */
3 #endif
4
5 #ifdef BUILD_FONT_LOADER_EET
6 #include <Eet.h>
7 #endif
8
9 #include "evas_common.h"
10 #include "evas_private.h"
11
12 EAPI Evas_Imaging_Image *
13 evas_imaging_image_load(const char *file, const char *key)
14 {
15    Evas_Imaging_Image *im;
16    RGBA_Image *image;
17
18    if (!file) file = "";
19    if (!key) key = "";
20    evas_common_cpu_init();
21    evas_common_image_init();
22    image = evas_common_load_image_from_file(file, key, NULL);
23    if (!image) return NULL;
24    im = calloc(1, sizeof(Evas_Imaging_Image));
25    if (!im)
26      {
27         evas_cache_image_drop(&image->cache_entry);
28         return NULL;
29      }
30    im->image = image;
31    return im;
32 }
33
34 EAPI void
35 evas_imaging_image_free(Evas_Imaging_Image *im)
36 {
37    if (!im) return;
38    evas_cache_image_drop(&im->image->cache_entry);
39    free(im);
40 }
41
42 EAPI void
43 evas_imaging_image_size_get(const Evas_Imaging_Image *im, int *w, int *h)
44 {
45    if (!im) return;
46    if (w) *w = im->image->cache_entry.w;
47    if (h) *h = im->image->cache_entry.h;
48 }
49
50 EAPI Evas_Bool
51 evas_imaging_image_alpha_get(const Evas_Imaging_Image *im)
52 {
53    if (!im) return 0;
54    if (im->image->cache_entry.flags.alpha) return 1;
55    return 0;
56 }
57
58 EAPI void
59 evas_imaging_image_cache_set(int bytes)
60 {
61    evas_common_image_set_cache(bytes);
62 }
63
64 EAPI int
65 evas_imaging_image_cache_get(void)
66 {
67    return evas_common_image_get_cache();
68 }
69
70 static Evas_Font_Hinting_Flags _evas_hinting = EVAS_FONT_HINTING_BYTECODE;
71
72 EAPI void
73 evas_imaging_font_hinting_set(Evas_Font_Hinting_Flags hinting)
74 {
75    _evas_hinting = hinting;
76 }
77
78 EAPI Evas_Font_Hinting_Flags
79 evas_imaging_font_hinting_get(void)
80 {
81    return _evas_hinting;
82 }
83
84 EAPI Evas_Bool
85 evas_imaging_font_hinting_can_hint(Evas_Font_Hinting_Flags hinting)
86 {
87    return evas_common_hinting_available(hinting);
88 }
89
90 EAPI Evas_Imaging_Font *
91 evas_imaging_font_load(const char *file, const char *key, int size)
92 {
93    Evas_Imaging_Font *fn;
94    RGBA_Font *font;
95
96    evas_common_cpu_init();
97    evas_common_font_init();
98    if (!file) file = "";
99    if ((key) && (key[0] == 0)) key = NULL;
100 #ifdef BUILD_FONT_LOADER_EET
101    if (key)
102      {
103         char *tmp;
104
105         tmp = evas_file_path_join(file, key);
106         if (tmp)
107           {
108              font = evas_common_font_hinting_load(tmp, size, _evas_hinting);
109              if (!font)
110                {
111                   Eet_File *ef;
112
113                   ef = eet_open((char *)file, EET_FILE_MODE_READ);
114                   if (ef)
115                     {
116                        void *fdata;
117                        int fsize = 0;
118
119                        fdata = eet_read(ef, (char *)key, &fsize);
120                        if ((fdata) && (fsize > 0))
121                          {
122                             font = evas_common_font_memory_hinting_load(tmp, size, fdata, fsize, _evas_hinting);
123                             free(fdata);
124                          }
125                        eet_close(ef);
126                     }
127                }
128              free(tmp);
129           }
130      }
131    else
132 #endif
133      {
134         font = evas_common_font_hinting_load((char *)file, size, _evas_hinting);
135      }
136    fn = calloc(1, sizeof(RGBA_Font));
137    if (!fn) return NULL;
138    fn->font = font;
139    return fn;
140 }
141
142 EAPI void
143 evas_imaging_font_free(Evas_Imaging_Font *fn)
144 {
145    evas_common_font_free(fn->font);
146    free(fn);
147 }
148
149 EAPI int
150 evas_imaging_font_ascent_get(const Evas_Imaging_Font *fn)
151 {
152    return evas_common_font_ascent_get(fn->font);
153 }
154
155 EAPI int
156 evas_imaging_font_descent_get(const Evas_Imaging_Font *fn)
157 {
158    return evas_common_font_descent_get(fn->font);
159 }
160
161 EAPI int
162 evas_imaging_font_max_ascent_get(const Evas_Imaging_Font *fn)
163 {
164    return evas_common_font_max_ascent_get(fn->font);
165 }
166
167 EAPI int
168 evas_imaging_font_max_descent_get(const Evas_Imaging_Font *fn)
169 {
170    return evas_common_font_max_descent_get(fn->font);
171 }
172
173 EAPI int
174 evas_imaging_font_line_advance_get(const Evas_Imaging_Font *fn)
175 {
176    return evas_common_font_get_line_advance(fn->font);
177 }
178
179 EAPI void
180 evas_imaging_font_string_advance_get(const Evas_Imaging_Font *fn, char *str, int *x, int *y)
181 {
182    evas_common_font_query_advance(fn->font, str, x, y);
183 }
184
185 EAPI void
186 evas_imaging_font_string_size_query(const Evas_Imaging_Font *fn, char *str, int *w, int *h)
187 {
188    evas_common_font_query_size(fn->font, str, w, h);
189 }
190
191 EAPI int
192 evas_imaging_font_string_inset_get(const Evas_Imaging_Font *fn, char *str)
193 {
194    return evas_common_font_query_inset(fn->font, str);
195 }
196
197 EAPI int
198 evas_imaging_font_string_char_coords_get(const Evas_Imaging_Font *fn, char *str, int pos, int *cx, int *cy, int *cw, int *ch)
199 {
200    return evas_common_font_query_char_coords(fn->font, str, pos, cx, cy, cw, ch);
201 }
202
203 EAPI int
204 evas_imaging_font_string_char_at_coords_get(const Evas_Imaging_Font *fn, char *str, int x, int y, int *cx, int *cy, int *cw, int *ch)
205 {
206    return evas_common_font_query_text_at_pos(fn->font, str, x, y, cx, cy, cw, ch);
207 }
208
209 EAPI void
210 evas_imaging_font_cache_set(int bytes)
211 {
212    evas_common_font_cache_set(bytes);
213 }
214
215 EAPI int
216 evas_imaging_font_cache_get(void)
217 {
218    return evas_common_font_cache_get();
219 }
220