2 # include "elementary_config.h"
9 #include <Elementary.h>
13 _elm_font_properties_get(Eina_Hash **font_hash,
16 Elm_Font_Properties *efp = NULL;
19 s1 = strchr(font, ':');
22 char *s2, *name, *style;
26 name = calloc(sizeof(char), len + 1);
27 if (!name) return NULL;
28 strncpy(name, font, len);
30 /* get subname (should be english) */
31 s2 = strchr(name, ',');
35 name = realloc(name, sizeof(char) * len + 1);
38 memset(name, 0, sizeof(char) * len + 1);
39 strncpy(name, font, len);
43 if (!strncmp(s1, ELM_FONT_TOKEN_STYLE, strlen(ELM_FONT_TOKEN_STYLE)))
45 style = s1 + strlen(ELM_FONT_TOKEN_STYLE);
47 if (font_hash) efp = eina_hash_find(*font_hash, name);
50 efp = calloc(1, sizeof(Elm_Font_Properties));
53 efp->name = eina_stringshare_add(name);
54 if ((font_hash && !*font_hash))
56 *font_hash = eina_hash_string_superfast_new(NULL);
57 eina_hash_add(*font_hash, name, efp);
61 s2 = strchr(style, ',');
68 style = calloc(sizeof(char), len + 1);
71 strncpy(style, style_old, len);
72 efp->styles = eina_list_append(efp->styles,
73 eina_stringshare_add(style));
78 efp->styles = eina_list_append(efp->styles,
79 eina_stringshare_add(style));
85 if (font_hash) efp = eina_hash_find(*font_hash, font);
88 efp = calloc(1, sizeof(Elm_Font_Properties));
91 efp->name = eina_stringshare_add(font);
92 if (font_hash && !*font_hash)
94 *font_hash = eina_hash_string_superfast_new(NULL);
95 eina_hash_add(*font_hash, font, efp);
104 _elm_font_available_hash_add(Eina_Hash *font_hash,
105 const char *full_name)
107 _elm_font_properties_get(&font_hash, full_name);
112 _elm_font_properties_free(Elm_Font_Properties *efp)
116 EINA_LIST_FREE(efp->styles, str)
117 if (str) eina_stringshare_del(str);
119 if (efp->name) eina_stringshare_del(efp->name);
124 _font_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
126 Elm_Font_Properties *efp;
129 _elm_font_properties_free(efp);
134 _elm_font_available_hash_del(Eina_Hash *hash)
138 eina_hash_foreach(hash, _font_hash_free_cb, NULL);
139 eina_hash_free(hash);
142 EAPI Elm_Font_Properties *
143 elm_font_properties_get(const char *font)
145 EINA_SAFETY_ON_NULL_RETURN_VAL(font, NULL);
146 return _elm_font_properties_get(NULL, font);
150 elm_font_properties_free(Elm_Font_Properties *efp)
154 EINA_SAFETY_ON_NULL_RETURN(efp);
155 EINA_LIST_FREE(efp->styles, str)
156 if (str) eina_stringshare_del(str);
157 if (efp->name) eina_stringshare_del(efp->name);
162 elm_font_fontconfig_name_get(const char *name,
167 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
168 if (!style || style[0] == 0) return (char *) eina_stringshare_add(name);
169 snprintf(buf, 256, "%s" ELM_FONT_TOKEN_STYLE "%s", name, style);
170 return (char *) eina_stringshare_add(buf);
174 elm_font_fontconfig_name_free(char *name)
176 eina_stringshare_del(name);
180 elm_font_available_hash_add(Eina_List *list)
182 Eina_Hash *font_hash;
188 /* populate with default font families */
189 //FIXME: Need to check whether fonts are being added multiple times.
190 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Regular");
191 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold");
192 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Oblique");
193 font_hash = _elm_font_available_hash_add(font_hash,
194 "Sans:style=Bold Oblique");
196 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Regular");
197 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold");
198 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Oblique");
199 font_hash = _elm_font_available_hash_add(font_hash,
200 "Serif:style=Bold Oblique");
202 font_hash = _elm_font_available_hash_add(font_hash,
203 "Monospace:style=Regular");
204 font_hash = _elm_font_available_hash_add(font_hash,
205 "Monospace:style=Bold");
206 font_hash = _elm_font_available_hash_add(font_hash,
207 "Monospace:style=Oblique");
208 font_hash = _elm_font_available_hash_add(font_hash,
209 "Monospace:style=Bold Oblique");
211 EINA_LIST_FOREACH(list, l, key)
212 if (key) _elm_font_available_hash_add(font_hash, key);
218 elm_font_available_hash_del(Eina_Hash *hash)
220 _elm_font_available_hash_del(hash);