2 # include "elementary_config.h"
9 #include <Elementary.h>
13 _elm_font_properties_get(Eina_Hash **font_hash,
16 Elm_Font_Properties *efp = NULL;
17 char *token = strchr(font, ':');
20 !strncmp(token, ELM_FONT_TOKEN_STYLE, strlen(ELM_FONT_TOKEN_STYLE)))
22 char *name, *subname, *style, *substyle;
27 name = calloc(sizeof(char), len + 1);
28 if (!name) return NULL;
29 strncpy(name, font, len);
31 /* remove subnames from the font name (should be english) */
32 subname = strchr(name, ',');
36 name = realloc(name, sizeof(char) * len + 1);
39 memset(name, 0, sizeof(char) * len + 1);
40 strncpy(name, font, len);
46 efp = eina_hash_find(*font_hash, name);
49 efp = calloc(1, sizeof(Elm_Font_Properties));
56 efp->name = eina_stringshare_add(name);
60 *font_hash = eina_hash_string_superfast_new(NULL);
61 eina_hash_add(*font_hash, name, efp);
67 style = token + strlen(ELM_FONT_TOKEN_STYLE);
68 substyle = strchr(style, ',');
70 //TODO: Seems to need to add all styles. not only one.
73 char *style_old = style;
75 len = substyle - style;
76 style = calloc(sizeof(char), len + 1);
79 strncpy(style, style_old, len);
80 efp->styles = eina_list_append(efp->styles,
81 eina_stringshare_add(style));
86 efp->styles = eina_list_append(efp->styles,
87 eina_stringshare_add(style));
89 else if ((font_hash) && (!eina_hash_find(*font_hash, font)))
91 efp = calloc(1, sizeof(Elm_Font_Properties));
92 if (!efp) return NULL;
94 efp->name = eina_stringshare_add(font);
95 if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
96 eina_hash_add(*font_hash, font, efp);
103 _elm_font_available_hash_add(Eina_Hash *font_hash,
104 const char *full_name)
106 _elm_font_properties_get(&font_hash, full_name);
111 _elm_font_properties_free(Elm_Font_Properties *efp)
115 EINA_LIST_FREE(efp->styles, str)
116 if (str) eina_stringshare_del(str);
118 if (efp->name) eina_stringshare_del(efp->name);
123 _font_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
125 Elm_Font_Properties *efp;
128 _elm_font_properties_free(efp);
133 _elm_font_available_hash_del(Eina_Hash *hash)
137 eina_hash_foreach(hash, _font_hash_free_cb, NULL);
138 eina_hash_free(hash);
141 EAPI Elm_Font_Properties *
142 elm_font_properties_get(const char *font)
144 EINA_SAFETY_ON_NULL_RETURN_VAL(font, NULL);
145 return _elm_font_properties_get(NULL, font);
149 elm_font_properties_free(Elm_Font_Properties *efp)
153 EINA_SAFETY_ON_NULL_RETURN(efp);
154 EINA_LIST_FREE(efp->styles, str)
155 if (str) eina_stringshare_del(str);
156 if (efp->name) eina_stringshare_del(efp->name);
161 elm_font_fontconfig_name_get(const char *name,
166 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
167 if (!style || style[0] == 0) return (char *) eina_stringshare_add(name);
168 snprintf(buf, 256, "%s" ELM_FONT_TOKEN_STYLE "%s", name, style);
169 return (char *) eina_stringshare_add(buf);
173 elm_font_fontconfig_name_free(char *name)
175 eina_stringshare_del(name);
179 elm_font_available_hash_add(Eina_List *list)
181 Eina_Hash *font_hash;
187 /* populate with default font families */
188 //FIXME: Need to check whether fonts are being added multiple times.
189 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Regular");
190 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold");
191 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Oblique");
192 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold Oblique");
193 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Regular");
194 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold");
195 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Oblique");
196 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold Oblique");
197 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Regular");
198 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Bold");
199 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Oblique");
200 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Bold Oblique");
202 EINA_LIST_FOREACH(list, l, key)
203 if (key) _elm_font_available_hash_add(font_hash, key);
209 elm_font_available_hash_del(Eina_Hash *hash)
211 _elm_font_available_hash_del(hash);