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));
50 if (!efp) return NULL;
52 efp->name = eina_stringshare_add(name);
56 *font_hash = eina_hash_string_superfast_new(NULL);
57 eina_hash_add(*font_hash, name, efp);
63 style = token + strlen(ELM_FONT_TOKEN_STYLE);
64 substyle = strchr(style, ',');
66 //TODO: Seems to need to add all styles. not only one.
69 char *style_old = style;
71 len = substyle - style;
72 style = calloc(sizeof(char), len + 1);
75 strncpy(style, style_old, len);
76 efp->styles = eina_list_append(efp->styles,
77 eina_stringshare_add(style));
82 efp->styles = eina_list_append(efp->styles,
83 eina_stringshare_add(style));
85 else if ((font_hash) && (!eina_hash_find(*font_hash, font)))
87 efp = calloc(1, sizeof(Elm_Font_Properties));
88 if (!efp) return NULL;
90 efp->name = eina_stringshare_add(font);
91 if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
92 eina_hash_add(*font_hash, font, efp);
99 _elm_font_available_hash_add(Eina_Hash *font_hash,
100 const char *full_name)
102 _elm_font_properties_get(&font_hash, full_name);
107 _elm_font_properties_free(Elm_Font_Properties *efp)
111 EINA_LIST_FREE(efp->styles, str)
112 if (str) eina_stringshare_del(str);
114 if (efp->name) eina_stringshare_del(efp->name);
119 _font_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
121 Elm_Font_Properties *efp;
124 _elm_font_properties_free(efp);
129 _elm_font_available_hash_del(Eina_Hash *hash)
133 eina_hash_foreach(hash, _font_hash_free_cb, NULL);
134 eina_hash_free(hash);
137 EAPI Elm_Font_Properties *
138 elm_font_properties_get(const char *font)
140 EINA_SAFETY_ON_NULL_RETURN_VAL(font, NULL);
141 return _elm_font_properties_get(NULL, font);
145 elm_font_properties_free(Elm_Font_Properties *efp)
149 EINA_SAFETY_ON_NULL_RETURN(efp);
150 EINA_LIST_FREE(efp->styles, str)
151 if (str) eina_stringshare_del(str);
152 if (efp->name) eina_stringshare_del(efp->name);
157 elm_font_fontconfig_name_get(const char *name,
162 EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
163 if (!style || style[0] == 0) return (char *) eina_stringshare_add(name);
164 snprintf(buf, 256, "%s" ELM_FONT_TOKEN_STYLE "%s", name, style);
165 return (char *) eina_stringshare_add(buf);
169 elm_font_fontconfig_name_free(char *name)
171 eina_stringshare_del(name);
175 elm_font_available_hash_add(Eina_List *list)
177 Eina_Hash *font_hash;
183 /* populate with default font families */
184 //FIXME: Need to check whether fonts are being added multiple times.
185 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Regular");
186 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold");
187 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Oblique");
188 font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold Oblique");
189 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Regular");
190 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold");
191 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Oblique");
192 font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold Oblique");
193 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Regular");
194 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Bold");
195 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Oblique");
196 font_hash = _elm_font_available_hash_add(font_hash, "Monospace:style=Bold Oblique");
198 EINA_LIST_FOREACH(list, l, key)
199 if (key) _elm_font_available_hash_add(font_hash, key);
205 elm_font_available_hash_del(Eina_Hash *hash)
207 _elm_font_available_hash_del(hash);