3 #define E_TOK_STYLE ":style="
5 static Eina_Bool _font_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__);
6 static Eina_Hash *_e_font_available_hash_add(Eina_Hash *font_hash, const char *full_name);
7 static E_Font_Properties *_e_font_fontconfig_name_parse(Eina_Hash **font_hash, E_Font_Properties *efp, const char *font);
8 static char _fn_buf[1024];
13 /* all init stuff is in e_config */
20 /* e_config will do this */
34 /* setup edje fallback list */
35 blen = sizeof(buf) - 1;
38 l = e_config->font_fallbacks;
41 eff = eina_list_data_get(l);
42 len = strlen(eff->name);
45 strcpy(buf, eff->name);
48 EINA_LIST_FOREACH(eina_list_next(l), l, eff)
56 len = strlen(eff->name);
59 strcat(buf, eff->name);
63 edje_fontset_append_set(buf);
66 edje_fontset_append_set(NULL);
68 /* setup edje text classes */
69 EINA_LIST_FOREACH(e_config->font_defaults, l, efd)
71 edje_text_class_set(efd->text_class, efd->font, efd->size);
75 EINA_LIST_FOREACH(e_border_client_list(), l, bd)
77 e_border_frame_recalc(bd);
82 e_font_available_list(void)
84 Eina_List *evas_fonts;
87 const char *evas_font;
91 man = e_manager_current_get();
92 if (!man) return NULL;
93 con = e_container_current_get(man);
94 if (!con) con = e_container_number_get(man, 0);
95 if (!con) return NULL;
97 evas_fonts = evas_font_available_list(con->bg_evas);
100 EINA_LIST_FOREACH(evas_fonts, l, evas_font)
102 E_Font_Available *efa;
104 efa = E_NEW(E_Font_Available, 1);
105 efa->name = eina_stringshare_add(evas_font);
106 e_fonts = eina_list_append(e_fonts, efa);
109 evas_font_available_list_free(con->bg_evas, evas_fonts);
115 e_font_available_list_free(Eina_List *available)
117 E_Font_Available *efa;
119 EINA_LIST_FREE(available, efa)
121 if (efa->name) eina_stringshare_del(efa->name);
127 e_font_properties_free(E_Font_Properties *efp)
131 EINA_LIST_FREE(efp->styles, str)
133 if (str) eina_stringshare_del(str);
135 if (efp->name) eina_stringshare_del(efp->name);
140 _font_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
142 E_Font_Properties *efp;
145 e_font_properties_free(efp);
150 e_font_available_hash_free(Eina_Hash *hash)
152 eina_hash_foreach(hash, _font_hash_free_cb, NULL);
153 eina_hash_free(hash);
156 EAPI E_Font_Properties *
157 e_font_fontconfig_name_parse(const char *font)
159 if (!font) return NULL;
160 return _e_font_fontconfig_name_parse(NULL, NULL, font);
163 static E_Font_Properties *
164 _e_font_fontconfig_name_parse(Eina_Hash **font_hash, E_Font_Properties *efp, const char *font)
168 s1 = strchr(font, ':');
171 char *s2, *name, *style;
175 name = calloc(sizeof(char), len + 1);
176 strncpy(name, font, len);
178 /* Get subname (should be english) */
179 s2 = strchr(name, ',');
183 name = realloc(name, sizeof(char) * len + 1);
184 memset(name, 0, sizeof(char) * len + 1);
185 strncpy(name, font, len);
188 if (strncmp(s1, E_TOK_STYLE, strlen(E_TOK_STYLE)) == 0)
190 style = s1 + strlen(E_TOK_STYLE);
192 if (font_hash) efp = eina_hash_find(*font_hash, name);
195 efp = calloc(1, sizeof(E_Font_Properties));
196 efp->name = eina_stringshare_add(name);
199 if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
200 eina_hash_add(*font_hash, name, efp);
203 s2 = strchr(style, ',');
210 style = calloc(sizeof(char), len + 1);
211 strncpy(style, style_old, len);
212 efp->styles = eina_list_append(efp->styles, eina_stringshare_add(style));
216 efp->styles = eina_list_append(efp->styles, eina_stringshare_add(style));
222 if (font_hash) efp = eina_hash_find(*font_hash, font);
225 efp = calloc(1, sizeof(E_Font_Properties));
226 efp->name = eina_stringshare_add(font);
229 if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
230 eina_hash_add(*font_hash, font, efp);
238 _e_font_available_hash_add(Eina_Hash *font_hash, const char *full_name)
240 _e_font_fontconfig_name_parse(&font_hash, NULL, full_name);
245 e_font_available_list_parse(Eina_List *list)
247 Eina_Hash *font_hash;
253 /* Populate Default Font Families */
254 font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Regular");
255 font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Bold");
256 font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Oblique");
257 font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Bold Oblique");
259 font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Regular");
260 font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Bold");
261 font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Oblique");
262 font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Bold Oblique");
264 font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Regular");
265 font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Bold");
266 font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Oblique");
267 font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Bold Oblique");
269 EINA_LIST_FOREACH(list, next, key)
270 font_hash = _e_font_available_hash_add(font_hash, key);
276 e_font_fontconfig_name_get(const char *name, const char *style)
280 if (!name) return NULL;
281 if (!style || style[0] == 0) return eina_stringshare_add(name);
282 snprintf(buf, 256, "%s"E_TOK_STYLE "%s", name, style);
283 return eina_stringshare_add(buf);
287 e_font_fallback_clear(void)
289 E_Font_Fallback *eff;
291 EINA_LIST_FREE(e_config->font_fallbacks, eff)
293 if (eff->name) eina_stringshare_del(eff->name);
299 e_font_fallback_append(const char *font)
301 E_Font_Fallback *eff;
303 e_font_fallback_remove(font);
305 eff = E_NEW(E_Font_Fallback, 1);
306 eff->name = eina_stringshare_add(font);
307 e_config->font_fallbacks = eina_list_append(e_config->font_fallbacks, eff);
311 e_font_fallback_prepend(const char *font)
313 E_Font_Fallback *eff;
315 e_font_fallback_remove(font);
317 eff = E_NEW(E_Font_Fallback, 1);
318 eff->name = eina_stringshare_add(font);
319 e_config->font_fallbacks = eina_list_prepend(e_config->font_fallbacks, eff);
323 e_font_fallback_remove(const char *font)
326 E_Font_Fallback *eff;
328 EINA_LIST_FOREACH(e_config->font_fallbacks, next, eff)
330 if (!strcmp(eff->name, font))
332 e_config->font_fallbacks =
333 eina_list_remove_list(e_config->font_fallbacks, next);
334 if (eff->name) eina_stringshare_del(eff->name);
342 e_font_fallback_list(void)
344 return e_config->font_fallbacks;
348 e_font_default_set(const char *text_class, const char *font, Evas_Font_Size size)
353 /* search for the text class */
354 EINA_LIST_FOREACH(e_config->font_defaults, next, efd)
356 if (!strcmp(efd->text_class, text_class))
358 if (efd->font) eina_stringshare_del(efd->font);
359 efd->font = eina_stringshare_add(font);
361 /* move to the front of the list */
362 e_config->font_defaults =
363 eina_list_remove_list(e_config->font_defaults, next);
364 e_config->font_defaults =
365 eina_list_prepend(e_config->font_defaults, efd);
370 /* the text class doesn't exist */
371 efd = E_NEW(E_Font_Default, 1);
372 efd->text_class = eina_stringshare_add(text_class);
373 efd->font = eina_stringshare_add(font);
376 e_config->font_defaults = eina_list_prepend(e_config->font_defaults, efd);
380 * returns a pointer to the data, return null if nothing if found.
382 EAPI E_Font_Default *
383 e_font_default_get(const char *text_class)
385 E_Font_Default *efd = NULL, *defd = NULL;
388 /* search for the text class */
389 EINA_LIST_FOREACH(e_config->font_defaults, next, efd)
391 if (!strcmp(efd->text_class, text_class))
393 /* move to the front of the list */
394 e_config->font_defaults =
395 eina_list_remove_list(e_config->font_defaults, next);
396 e_config->font_defaults =
397 eina_list_prepend(e_config->font_defaults, efd);
400 if (!strcmp(efd->text_class, "default")) defd = efd;
402 if (!defd) defd = efd;
407 e_font_default_remove(const char *text_class)
412 /* search for the text class */
413 EINA_LIST_FOREACH(e_config->font_defaults, next, efd)
415 if (!strcmp(efd->text_class, text_class))
417 e_config->font_defaults =
418 eina_list_remove_list(e_config->font_defaults, next);
419 if (efd->text_class) eina_stringshare_del(efd->text_class);
420 if (efd->font) eina_stringshare_del(efd->font);
422 edje_text_class_del(text_class);
429 e_font_default_list(void)
431 return e_config->font_defaults;
434 /* return the default font name with fallbacks, font size is returned
435 * in size_ret. This function is needed when all hell breaks loose and
436 * we need a font name and size.
439 e_font_default_string_get(const char *text_class, Evas_Font_Size *size_ret)
443 E_Font_Fallback *eff;
447 efd = e_font_default_get(text_class);
450 if (size_ret) *size_ret = 0;
453 blen = sizeof(_fn_buf) - 1;
455 len = strlen(efd->font);
458 strcpy(_fn_buf, efd->font);
462 EINA_LIST_FOREACH(e_config->font_fallbacks, next, eff)
467 strcat(_fn_buf, ",");
470 len = strlen(eff->name);
473 strcat(_fn_buf, eff->name);
478 if (size_ret) *size_ret = efd->size;