2010-11-18 02:01:24 -08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "elementary_config.h"
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_EVIL
|
|
|
|
# include <Evil.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <Elementary.h>
|
|
|
|
#include "elm_priv.h"
|
|
|
|
|
|
|
|
Elm_Font_Properties *
|
|
|
|
_elm_font_properties_get(Eina_Hash **font_hash,
|
|
|
|
const char *font)
|
|
|
|
{
|
|
|
|
Elm_Font_Properties *efp = NULL;
|
2012-05-02 17:34:26 -07:00
|
|
|
char *token = strchr(font, ':');
|
2010-11-18 02:01:24 -08:00
|
|
|
|
2012-05-02 17:34:26 -07:00
|
|
|
if (token &&
|
|
|
|
!strncmp(token, ELM_FONT_TOKEN_STYLE, strlen(ELM_FONT_TOKEN_STYLE)))
|
2010-11-18 02:01:24 -08:00
|
|
|
{
|
2012-05-02 17:34:26 -07:00
|
|
|
char *name, *subname, *style, *substyle;
|
2010-11-18 02:01:24 -08:00
|
|
|
int len;
|
|
|
|
|
2012-05-02 17:34:26 -07:00
|
|
|
/* get font name */
|
|
|
|
len = token - font;
|
2010-11-18 02:01:24 -08:00
|
|
|
name = calloc(sizeof(char), len + 1);
|
2012-02-20 17:39:52 -08:00
|
|
|
if (!name) return NULL;
|
2010-11-18 02:01:24 -08:00
|
|
|
strncpy(name, font, len);
|
|
|
|
|
2012-05-02 17:34:26 -07:00
|
|
|
/* remove subnames from the font name (should be english) */
|
|
|
|
subname = strchr(name, ',');
|
|
|
|
if (subname)
|
2010-11-18 02:01:24 -08:00
|
|
|
{
|
2012-05-02 17:34:26 -07:00
|
|
|
len = subname - name;
|
2010-11-18 02:01:24 -08:00
|
|
|
name = realloc(name, sizeof(char) * len + 1);
|
2012-02-20 17:53:40 -08:00
|
|
|
if (name)
|
2012-02-20 17:39:52 -08:00
|
|
|
{
|
|
|
|
memset(name, 0, sizeof(char) * len + 1);
|
|
|
|
strncpy(name, font, len);
|
|
|
|
}
|
2010-11-18 02:01:24 -08:00
|
|
|
}
|
|
|
|
|
2012-05-02 17:34:26 -07:00
|
|
|
/* add a font name */
|
|
|
|
if (font_hash)
|
|
|
|
{
|
|
|
|
efp = eina_hash_find(*font_hash, name);
|
|
|
|
if (!efp)
|
2010-11-18 02:01:24 -08:00
|
|
|
{
|
2012-05-02 17:34:26 -07:00
|
|
|
efp = calloc(1, sizeof(Elm_Font_Properties));
|
|
|
|
if (!efp) return NULL;
|
|
|
|
|
|
|
|
efp->name = eina_stringshare_add(name);
|
|
|
|
if (!*font_hash)
|
|
|
|
*font_hash = eina_hash_string_superfast_new(NULL);
|
|
|
|
eina_hash_add(*font_hash, name, efp);
|
2010-11-18 02:01:24 -08:00
|
|
|
}
|
2012-05-02 17:34:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
free(name);
|
|
|
|
|
|
|
|
style = token + strlen(ELM_FONT_TOKEN_STYLE);
|
|
|
|
substyle = strchr(style, ',');
|
|
|
|
|
|
|
|
//TODO: Seems to need to add all styles. not only one.
|
|
|
|
if (substyle)
|
|
|
|
{
|
|
|
|
char *style_old = style;
|
|
|
|
|
|
|
|
len = substyle - style;
|
|
|
|
style = calloc(sizeof(char), len + 1);
|
|
|
|
if (style)
|
2010-11-18 02:01:24 -08:00
|
|
|
{
|
2012-05-02 17:34:26 -07:00
|
|
|
strncpy(style, style_old, len);
|
|
|
|
efp->styles = eina_list_append(efp->styles,
|
|
|
|
eina_stringshare_add(style));
|
|
|
|
free(style);
|
2010-11-18 02:01:24 -08:00
|
|
|
}
|
|
|
|
}
|
2012-05-02 17:34:26 -07:00
|
|
|
else
|
|
|
|
efp->styles = eina_list_append(efp->styles,
|
|
|
|
eina_stringshare_add(style));
|
2010-11-18 02:01:24 -08:00
|
|
|
}
|
2012-05-02 17:34:26 -07:00
|
|
|
else if ((font_hash) && (!eina_hash_find(*font_hash, font)))
|
2010-11-18 02:01:24 -08:00
|
|
|
{
|
2012-05-02 17:34:26 -07:00
|
|
|
efp = calloc(1, sizeof(Elm_Font_Properties));
|
|
|
|
if (!efp) return NULL;
|
2012-05-02 03:29:58 -07:00
|
|
|
|
2012-05-02 17:34:26 -07:00
|
|
|
efp->name = eina_stringshare_add(font);
|
|
|
|
if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
|
|
|
|
eina_hash_add(*font_hash, font, efp);
|
2010-11-18 02:01:24 -08:00
|
|
|
}
|
2012-05-02 17:34:26 -07:00
|
|
|
|
2010-11-18 02:01:24 -08:00
|
|
|
return efp;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Hash *
|
|
|
|
_elm_font_available_hash_add(Eina_Hash *font_hash,
|
|
|
|
const char *full_name)
|
|
|
|
{
|
|
|
|
_elm_font_properties_get(&font_hash, full_name);
|
|
|
|
return font_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
_elm_font_properties_free(Elm_Font_Properties *efp)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
EINA_LIST_FREE(efp->styles, str)
|
|
|
|
if (str) eina_stringshare_del(str);
|
|
|
|
|
|
|
|
if (efp->name) eina_stringshare_del(efp->name);
|
|
|
|
free(efp);
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_font_hash_free_cb(const Eina_Hash *hash __UNUSED__, const void *key __UNUSED__, void *data, void *fdata __UNUSED__)
|
|
|
|
{
|
|
|
|
Elm_Font_Properties *efp;
|
|
|
|
|
|
|
|
efp = data;
|
|
|
|
_elm_font_properties_free(efp);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
_elm_font_available_hash_del(Eina_Hash *hash)
|
|
|
|
{
|
2012-02-20 17:39:52 -08:00
|
|
|
if (!hash) return;
|
2011-05-02 03:16:18 -07:00
|
|
|
|
2010-11-18 02:01:24 -08:00
|
|
|
eina_hash_foreach(hash, _font_hash_free_cb, NULL);
|
2012-02-20 17:39:52 -08:00
|
|
|
eina_hash_free(hash);
|
2010-11-18 02:01:24 -08:00
|
|
|
}
|
2012-03-06 01:49:24 -08:00
|
|
|
|
|
|
|
EAPI Elm_Font_Properties *
|
|
|
|
elm_font_properties_get(const char *font)
|
|
|
|
{
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(font, NULL);
|
|
|
|
return _elm_font_properties_get(NULL, font);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_font_properties_free(Elm_Font_Properties *efp)
|
|
|
|
{
|
|
|
|
const char *str;
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN(efp);
|
|
|
|
EINA_LIST_FREE(efp->styles, str)
|
|
|
|
if (str) eina_stringshare_del(str);
|
|
|
|
if (efp->name) eina_stringshare_del(efp->name);
|
|
|
|
free(efp);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI char *
|
|
|
|
elm_font_fontconfig_name_get(const char *name,
|
|
|
|
const char *style)
|
|
|
|
{
|
|
|
|
char buf[256];
|
|
|
|
|
|
|
|
EINA_SAFETY_ON_NULL_RETURN_VAL(name, NULL);
|
|
|
|
if (!style || style[0] == 0) return (char *) eina_stringshare_add(name);
|
|
|
|
snprintf(buf, 256, "%s" ELM_FONT_TOKEN_STYLE "%s", name, style);
|
|
|
|
return (char *) eina_stringshare_add(buf);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_font_fontconfig_name_free(char *name)
|
|
|
|
{
|
|
|
|
eina_stringshare_del(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI Eina_Hash *
|
|
|
|
elm_font_available_hash_add(Eina_List *list)
|
|
|
|
{
|
|
|
|
Eina_Hash *font_hash;
|
|
|
|
Eina_List *l;
|
|
|
|
void *key;
|
|
|
|
|
|
|
|
font_hash = NULL;
|
|
|
|
|
|
|
|
/* populate with default font families */
|
|
|
|
//FIXME: Need to check whether fonts are being added multiple times.
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Regular");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Bold");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash, "Sans:style=Oblique");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash,
|
|
|
|
"Sans:style=Bold Oblique");
|
|
|
|
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Regular");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Bold");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash, "Serif:style=Oblique");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash,
|
|
|
|
"Serif:style=Bold Oblique");
|
|
|
|
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash,
|
|
|
|
"Monospace:style=Regular");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash,
|
|
|
|
"Monospace:style=Bold");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash,
|
|
|
|
"Monospace:style=Oblique");
|
|
|
|
font_hash = _elm_font_available_hash_add(font_hash,
|
|
|
|
"Monospace:style=Bold Oblique");
|
|
|
|
|
|
|
|
EINA_LIST_FOREACH(list, l, key)
|
|
|
|
if (key) _elm_font_available_hash_add(font_hash, key);
|
|
|
|
|
|
|
|
return font_hash;
|
|
|
|
}
|
|
|
|
|
|
|
|
EAPI void
|
|
|
|
elm_font_available_hash_del(Eina_Hash *hash)
|
|
|
|
{
|
|
|
|
_elm_font_available_hash_del(hash);
|
|
|
|
}
|