enlightenment/src/bin/e_font.c

479 lines
12 KiB
C
Raw Normal View History

#include "e.h"
#define E_TOK_STYLE ":style="
static Eina_Bool _font_hash_free_cb(const Eina_Hash *hash EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED);
2012-07-25 23:49:35 -07:00
static Eina_Hash *_e_font_available_hash_add(Eina_Hash *font_hash, const char *full_name);
static E_Font_Properties *_e_font_fontconfig_name_parse(Eina_Hash **font_hash, E_Font_Properties *efp, const char *font);
static char _fn_buf[1024];
EINTERN int
e_font_init(void)
{
2005-04-21 21:25:51 -07:00
/* all init stuff is in e_config */
return 1;
}
EINTERN int
e_font_shutdown(void)
{
/* e_config will do this */
return 1;
}
E_API void
e_font_apply(void)
{
char buf[1024];
const Eina_List *l;
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
E_Client *ec;
E_Font_Default *efd;
E_Font_Fallback *eff;
int blen, len;
/* setup edje fallback list */
blen = sizeof(buf) - 1;
buf[0] = 0;
buf[blen] = 0;
l = e_config->font_fallbacks;
if (l)
{
2012-07-25 23:49:35 -07:00
eff = eina_list_data_get(l);
len = strlen(eff->name);
if (len < blen)
{
strcpy(buf, eff->name);
blen -= len;
}
EINA_LIST_FOREACH(eina_list_next(l), l, eff)
{
len = 1;
if (len < blen)
{
strcat(buf, ",");
blen -= len;
}
len = strlen(eff->name);
if (len < blen)
{
strcat(buf, eff->name);
blen -= len;
}
}
edje_fontset_append_set(buf);
}
else
edje_fontset_append_set(NULL);
/* setup edje text classes */
EINA_LIST_FOREACH(e_config->font_defaults, l, efd)
{
2012-07-25 23:49:35 -07:00
edje_text_class_set(efd->text_class, efd->font, efd->size);
}
compositor rewrite / charlie-foxtrot situation huge fustercluck commit because there wasn't really a way to separate out the changes. better to just rip it all out at once. * compositor and window management completely rewritten. this was the goal for E19, but it pretty much required everything existing to be scrapped since it wasn't optimized, streamlined, or sensible. now instead of having the compositor strapped to the window manager like an outboard motor, it's housed more like an automobile engine. ** various comp structs have been merged into other places (eg. E_Comp_Zone is now just part of E_Zone where applicable), leading to a large deduplication of attributes ** awful E_Comp_Win is totally dead, having been replaced with e_comp_object smart objects which work just like normal canvas objects ** protocol-specific window management and compositor functionality is now kept exclusively in backend files ** e_pixmap api provides generic client finding and rendering api ** screen/xinerama screens are now provided directly by compositor on startup and re-set on change ** e_comp_render_update finally replaced with eina_tiler ** wayland compositor no longer creates X windows ** compositor e_layout removed entirely * e_container is gone. this was made unnecessary in E18, but I kept it to avoid having too much code churn in one release. its sole purpose was to catch some events and handle window stacking, both of which are now just done by the compositor infra * e_manager is just for screensaver and keybind stuff now, possibly remove later? * e_border is gone along with a lot of its api. e_client has replaced it, and e_client has been rewritten completely; some parts may be similar, but the design now relies upon having a functional compositor ** window configuration/focus functions are all removed. all windows are now managed solely with evas_object_X functions on the "frame" member of a client, just as any other canvas object can be managed. *** do NOT set interceptors on a client's comp_object. seriously. * startup order rewritten: compositor now starts much earlier, other things just use attrs and members of the compositor * ecore_x_pointer_xy_get usage replaced with ecore_evas_pointer_xy_get * e_popup is totally gone, existing usage replaced by e_comp_object_util_add where applicable, otherwise just placed normally on the canvas * deskmirror is (more) broken for now * illume is totally fucked * Ecore_X_Window replaced with Ecore_Window in most cases * edge binding XWindows replaced with regular canvas objects * some E_Win functionality has changed such that delete callbacks are now correctly called in ALL cases. various dialogs have been updated to not crash as a result comp files and descriptions: e_comp.c - overall compositor functions, rendering/update loop, shape cutting e_comp_x.c - X window management and compositor functionality e_comp_wl.c - Wayland surface management and compositor functionality e_comp_canvas.c - general compositor canvas functions and utilities e_comp_object.c - E_Client->frame member for managing clients as Evas_Objects, utility functions for adding objects to the compositor rendering systems additional authors: ivan.briano@intel.com feature: new compositor removal: e_border, e_container, e_popup
2014-01-14 17:19:12 -08:00
/* Update clients */
if (!e_comp) return;
EINA_LIST_FOREACH(e_comp->clients, l, ec)
e_client_frame_recalc(ec);
}
E_API Eina_List *
e_font_available_list(void)
{
Eina_List *evas_fonts;
Eina_List *e_fonts;
Eina_List *l;
const char *evas_font;
2015-03-18 14:25:20 -07:00
evas_fonts = evas_font_available_list(e_comp->evas);
e_fonts = NULL;
EINA_LIST_FOREACH(evas_fonts, l, evas_font)
2005-05-19 20:09:44 -07:00
{
2012-07-25 23:49:35 -07:00
E_Font_Available *efa;
2012-06-20 23:19:43 -07:00
2012-07-25 23:49:35 -07:00
efa = E_NEW(E_Font_Available, 1);
efa->name = eina_stringshare_add(evas_font);
e_fonts = eina_list_append(e_fonts, efa);
}
2015-03-18 14:25:20 -07:00
evas_font_available_list_free(e_comp->evas, evas_fonts);
return e_fonts;
}
E_API void
e_font_available_list_free(Eina_List *available)
{
2005-04-21 21:25:51 -07:00
E_Font_Available *efa;
EINA_LIST_FREE(available, efa)
2012-06-20 23:19:43 -07:00
{
2012-07-25 23:49:35 -07:00
if (efa->name) eina_stringshare_del(efa->name);
E_FREE(efa);
}
}
E_API void
e_font_properties_free(E_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 EINA_UNUSED, const void *key EINA_UNUSED, void *data, void *fdata EINA_UNUSED)
{
E_Font_Properties *efp;
efp = data;
e_font_properties_free(efp);
return 1;
}
E_API void
e_font_available_hash_free(Eina_Hash *hash)
{
eina_hash_foreach(hash, _font_hash_free_cb, NULL);
eina_hash_free(hash);
}
E_API E_Font_Properties *
e_font_fontconfig_name_parse(const char *font)
{
if (!font) return NULL;
return _e_font_fontconfig_name_parse(NULL, NULL, font);
}
static E_Font_Properties *
_e_font_fontconfig_name_parse(Eina_Hash **font_hash, E_Font_Properties *efp, const char *font)
{
char *s1;
s1 = strchr(font, ':');
if (s1)
{
char *s2, *name, *style, *temp;
int len;
len = s1 - font;
name = calloc(sizeof(char), len + 1);
strncpy(name, font, len);
/* Get subname (should be english) */
s2 = strchr(name, ',');
if (s2)
{
len = s2 - name;
temp = name;
name = realloc(name, sizeof(char) * len + 1);
if (!name)
{
free(temp);
return NULL;
}
memset(name, 0, sizeof(char) * len + 1);
strncpy(name, font, len);
}
if (strncmp(s1, E_TOK_STYLE, strlen(E_TOK_STYLE)) == 0)
{
style = s1 + strlen(E_TOK_STYLE);
if (font_hash) efp = eina_hash_find(*font_hash, name);
if (!efp)
{
efp = calloc(1, sizeof(E_Font_Properties));
efp->name = eina_stringshare_add(name);
2012-06-20 23:19:43 -07:00
if (font_hash)
2012-07-25 23:49:35 -07:00
{
if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
eina_hash_add(*font_hash, name, efp);
}
}
s2 = strchr(style, ',');
if (s2)
{
char *style_old;
len = s2 - style;
style_old = style;
style = calloc(sizeof(char), len + 1);
strncpy(style, style_old, len);
efp->styles = eina_list_append(efp->styles, eina_stringshare_add(style));
free(style);
}
else
efp->styles = eina_list_append(efp->styles, eina_stringshare_add(style));
}
free(name);
}
2012-06-20 23:19:43 -07:00
else
{
if (font_hash) efp = eina_hash_find(*font_hash, font);
if (!efp)
{
efp = calloc(1, sizeof(E_Font_Properties));
efp->name = eina_stringshare_add(font);
if (font_hash)
2012-07-25 23:49:35 -07:00
{
if (!*font_hash) *font_hash = eina_hash_string_superfast_new(NULL);
eina_hash_add(*font_hash, font, efp);
}
}
}
return efp;
}
static Eina_Hash *
_e_font_available_hash_add(Eina_Hash *font_hash, const char *full_name)
{
_e_font_fontconfig_name_parse(&font_hash, NULL, full_name);
return font_hash;
}
E_API Eina_Hash *
e_font_available_list_parse(Eina_List *list)
{
Eina_Hash *font_hash;
Eina_List *next;
void *key;
font_hash = NULL;
/* Populate Default Font Families */
font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Regular");
font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Bold");
font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Oblique");
font_hash = _e_font_available_hash_add(font_hash, "Sans:style=Bold Oblique");
font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Regular");
font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Bold");
font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Oblique");
font_hash = _e_font_available_hash_add(font_hash, "Serif:style=Bold Oblique");
font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Regular");
font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Bold");
font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Oblique");
font_hash = _e_font_available_hash_add(font_hash, "Monospace:style=Bold Oblique");
EINA_LIST_FOREACH(list, next, key)
font_hash = _e_font_available_hash_add(font_hash, key);
return font_hash;
}
E_API const char *
e_font_fontconfig_name_get(const char *name, const char *style)
{
char buf[256];
if (!name) return NULL;
if (!style || style[0] == 0) return eina_stringshare_add(name);
2012-07-25 23:49:35 -07:00
snprintf(buf, 256, "%s"E_TOK_STYLE "%s", name, style);
return eina_stringshare_add(buf);
}
E_API void
e_font_fallback_clear(void)
{
2005-04-21 21:25:51 -07:00
E_Font_Fallback *eff;
EINA_LIST_FREE(e_config->font_fallbacks, eff)
2012-06-20 23:19:43 -07:00
{
2012-07-25 23:49:35 -07:00
if (eff->name) eina_stringshare_del(eff->name);
E_FREE(eff);
}
}
E_API void
e_font_fallback_append(const char *font)
{
E_Font_Fallback *eff;
2008-03-12 03:05:19 -07:00
e_font_fallback_remove(font);
eff = E_NEW(E_Font_Fallback, 1);
eff->name = eina_stringshare_add(font);
e_config->font_fallbacks = eina_list_append(e_config->font_fallbacks, eff);
}
E_API void
e_font_fallback_prepend(const char *font)
{
E_Font_Fallback *eff;
2008-03-12 03:05:19 -07:00
e_font_fallback_remove(font);
eff = E_NEW(E_Font_Fallback, 1);
eff->name = eina_stringshare_add(font);
e_config->font_fallbacks = eina_list_prepend(e_config->font_fallbacks, eff);
}
E_API void
e_font_fallback_remove(const char *font)
{
Eina_List *next;
E_Font_Fallback *eff;
2005-04-21 21:25:51 -07:00
EINA_LIST_FOREACH(e_config->font_fallbacks, next, eff)
{
if (!e_util_strcmp(eff->name, font))
2012-07-25 23:49:35 -07:00
{
e_config->font_fallbacks =
eina_list_remove_list(e_config->font_fallbacks, next);
2012-07-25 23:49:35 -07:00
if (eff->name) eina_stringshare_del(eff->name);
E_FREE(eff);
break;
}
}
}
E_API Eina_List *
e_font_fallback_list(void)
{
2005-04-21 21:25:51 -07:00
return e_config->font_fallbacks;
}
E_API void
e_font_default_set(const char *text_class, const char *font, Evas_Font_Size size)
{
E_Font_Default *efd;
Eina_List *next;
/* search for the text class */
EINA_LIST_FOREACH(e_config->font_defaults, next, efd)
{
2012-07-25 23:49:35 -07:00
if (!strcmp(efd->text_class, text_class))
{
if (efd->font) eina_stringshare_del(efd->font);
efd->font = eina_stringshare_add(font);
efd->size = size;
/* move to the front of the list */
e_config->font_defaults =
eina_list_remove_list(e_config->font_defaults, next);
2012-07-25 23:49:35 -07:00
e_config->font_defaults =
eina_list_prepend(e_config->font_defaults, efd);
2012-07-25 23:49:35 -07:00
return;
}
}
Fix common misspellings Some misspellings were manually reverted since in E there are tons of .po with phrases in other languages. Other than that all the changes in the following files were reverted: * src/modules/illume/dicts/English_(US).dic * src/modules/illume-keyboard/dicts/English_(US).dic Following misspellings were fixed: acquited->acquitted adres->address adress->address alreayd->already aquire->acquire arbitarily->arbitrarily cant->can't Capetown->Cape carefull->careful causalities->casualties Celcius->Celsius certian->certain commandoes->commandos considerd->considered conveyer->conveyor dependant->dependent didnt->didn't discontentment->discontent doesnt->doesn't everytime->every exemple->example existance->existence existant->existent existince->existence Farenheit->Fahrenheit forbad->forbade funguses->fungi guage->gauge guerilla->guerrilla guerillas->guerrillas happend->happened hasnt->hasn't heros->heroes inbetween->between independant->independent inital->initial intrusted->entrusted irregardless->regardless isnt->isn't knifes->knives layed->laid loosing->losing marrage->marriage midwifes->midwives miniscule->minuscule monickers->monikers mroe->more noone->no one occured->occurred omre->more paralell->parallel payed->paid planed->planned quitted->quit quizes->quizzes seperated->separated seperate->separate shoudl->should similiar->similar simplier->simpler specifiying->specifying teh->the toke->took torpedos->torpedoes Tuscon->Tucson unecessary->unnecessary useage->usage usefull->useful useing->using waht->what wanna->want whith->with wich->which withing->within SVN revision: 52006
2010-09-08 16:59:07 -07:00
/* the text class doesn't exist */
efd = E_NEW(E_Font_Default, 1);
efd->text_class = eina_stringshare_add(text_class);
efd->font = eina_stringshare_add(font);
efd->size = size;
e_config->font_defaults = eina_list_prepend(e_config->font_defaults, efd);
}
/*
* returns a pointer to the data, return null if nothing if found.
*/
E_API E_Font_Default *
e_font_default_get(const char *text_class)
{
2005-04-29 03:48:07 -07:00
E_Font_Default *efd = NULL, *defd = NULL;
Eina_List *next;
/* search for the text class */
EINA_LIST_FOREACH(e_config->font_defaults, next, efd)
{
2012-07-25 23:49:35 -07:00
if (!strcmp(efd->text_class, text_class))
{
/* move to the front of the list */
e_config->font_defaults =
eina_list_remove_list(e_config->font_defaults, next);
2012-07-25 23:49:35 -07:00
e_config->font_defaults =
eina_list_prepend(e_config->font_defaults, efd);
2012-07-25 23:49:35 -07:00
return efd;
}
if (!strcmp(efd->text_class, "default")) defd = efd;
}
2012-07-25 23:49:35 -07:00
if (!defd) defd = efd;
return defd;
}
E_API void
e_font_default_remove(const char *text_class)
{
E_Font_Default *efd;
Eina_List *next;
/* search for the text class */
EINA_LIST_FOREACH(e_config->font_defaults, next, efd)
{
if (!e_util_strcmp(efd->text_class, text_class))
2012-07-25 23:49:35 -07:00
{
e_config->font_defaults =
eina_list_remove_list(e_config->font_defaults, next);
2012-07-25 23:49:35 -07:00
if (efd->text_class) eina_stringshare_del(efd->text_class);
if (efd->font) eina_stringshare_del(efd->font);
E_FREE(efd);
edje_text_class_del(text_class);
return;
}
}
}
E_API Eina_List *
e_font_default_list(void)
{
2005-04-21 21:25:51 -07:00
return e_config->font_defaults;
}
/* return the default font name with fallbacks, font size is returned
* in size_ret. This function is needed when all hell breaks loose and
* we need a font name and size.
*/
E_API const char *
e_font_default_string_get(const char *text_class, Evas_Font_Size *size_ret)
{
E_Font_Default *efd;
Eina_List *next;
E_Font_Fallback *eff;
int blen, len;
_fn_buf[0] = 0;
efd = e_font_default_get(text_class);
if (!efd)
{
2012-07-25 23:49:35 -07:00
if (size_ret) *size_ret = 0;
return "";
}
blen = sizeof(_fn_buf) - 1;
len = strlen(efd->font);
if (len < blen)
{
2012-07-25 23:49:35 -07:00
strcpy(_fn_buf, efd->font);
blen -= len;
}
EINA_LIST_FOREACH(e_config->font_fallbacks, next, eff)
{
2012-07-25 23:49:35 -07:00
len = 1;
if (len < blen)
{
strcat(_fn_buf, ",");
blen -= len;
}
len = strlen(eff->name);
if (len < blen)
{
strcat(_fn_buf, eff->name);
blen -= len;
}
}
if (size_ret) *size_ret = efd->size;
return _fn_buf;
}
2012-07-25 23:49:35 -07:00