handle fonts with multiple names
This commit is contained in:
parent
a3e7a770bc
commit
503dd08105
|
@ -42,33 +42,60 @@ _update_sizing(Evas_Object *term)
|
||||||
expecting_resize = 1;
|
expecting_resize = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char *
|
static int
|
||||||
_get_pretty_font_name(const char *full_name)
|
_parse_font_name(const char *full_name,
|
||||||
|
const char **name, const char **pretty_name)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
char buf[4096];
|
||||||
size_t style_len = 0;
|
size_t style_len = 0;
|
||||||
size_t font_len = 0;
|
size_t font_len = 0;
|
||||||
char *style = NULL;
|
char *style = NULL;
|
||||||
char *s;
|
char *s;
|
||||||
|
unsigned int len;
|
||||||
|
|
||||||
s = strchr(full_name, ':');
|
*pretty_name = NULL;
|
||||||
if (s == NULL)
|
*name = NULL;
|
||||||
|
|
||||||
|
font_len = strlen(full_name);
|
||||||
|
if (font_len >= sizeof(buf))
|
||||||
|
return -1;
|
||||||
|
style = strchr(full_name, ':');
|
||||||
|
if (style)
|
||||||
|
font_len = (size_t)(style - full_name);
|
||||||
|
|
||||||
|
s = strchr(full_name, ',');
|
||||||
|
if (s && style && s < style)
|
||||||
|
font_len = s - full_name;
|
||||||
|
|
||||||
|
#define STYLE_STR ":style="
|
||||||
|
if (style && strncmp(style, STYLE_STR, strlen(STYLE_STR)) == 0)
|
||||||
{
|
{
|
||||||
return eina_stringshare_add(full_name);
|
style += strlen(STYLE_STR);
|
||||||
}
|
s = strchr(style, ',');
|
||||||
font_len = s - full_name;
|
|
||||||
s++;
|
|
||||||
#define STYLE_STR "style="
|
|
||||||
if (strncmp(s, STYLE_STR, strlen(STYLE_STR)) == 0)
|
|
||||||
{
|
|
||||||
s += strlen(STYLE_STR);
|
|
||||||
style = s;
|
|
||||||
s = strchr(s, ',');
|
|
||||||
style_len = (s == NULL) ? strlen(style) : (size_t)(s - style);
|
style_len = (s == NULL) ? strlen(style) : (size_t)(s - style);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
s = buf;
|
||||||
|
memcpy(s, full_name, font_len);
|
||||||
|
s += font_len;
|
||||||
|
len = font_len;
|
||||||
|
if (style)
|
||||||
|
{
|
||||||
|
memcpy(s, STYLE_STR, strlen(STYLE_STR));
|
||||||
|
s += strlen(STYLE_STR);
|
||||||
|
len += strlen(STYLE_STR);
|
||||||
|
|
||||||
|
memcpy(s, style, style_len);
|
||||||
|
s += style_len;
|
||||||
|
len += style_len;
|
||||||
|
}
|
||||||
|
*s = '\0';
|
||||||
|
*name = eina_stringshare_add_length(buf, len);
|
||||||
#undef STYLE_STR
|
#undef STYLE_STR
|
||||||
|
|
||||||
/* unescape the dashes */
|
/* unescape the dashes */
|
||||||
s = buf;
|
s = buf;
|
||||||
|
len = 0;
|
||||||
while ( (size_t)(s - buf) < sizeof(buf) &&
|
while ( (size_t)(s - buf) < sizeof(buf) &&
|
||||||
font_len > 0 )
|
font_len > 0 )
|
||||||
{
|
{
|
||||||
|
@ -78,6 +105,7 @@ _get_pretty_font_name(const char *full_name)
|
||||||
}
|
}
|
||||||
full_name++;
|
full_name++;
|
||||||
font_len--;
|
font_len--;
|
||||||
|
len++;
|
||||||
}
|
}
|
||||||
/* copy style */
|
/* copy style */
|
||||||
if (style_len > 0 && ((sizeof(buf) - (s - buf)) > style_len + 3 ))
|
if (style_len > 0 && ((sizeof(buf) - (s - buf)) > style_len + 3 ))
|
||||||
|
@ -87,10 +115,13 @@ _get_pretty_font_name(const char *full_name)
|
||||||
memcpy(s, style, style_len);
|
memcpy(s, style, style_len);
|
||||||
s += style_len;
|
s += style_len;
|
||||||
*s++ = ')';
|
*s++ = ')';
|
||||||
|
|
||||||
|
len += 3 + style_len;
|
||||||
}
|
}
|
||||||
*s = '\0';
|
*s = '\0';
|
||||||
|
|
||||||
return eina_stringshare_add(buf);
|
*pretty_name = eina_stringshare_add_length(buf, len);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -431,8 +462,11 @@ options_font(Evas_Object *opbox, Evas_Object *term)
|
||||||
if (!eina_hash_find(fonthash, fname))
|
if (!eina_hash_find(fonthash, fname))
|
||||||
{
|
{
|
||||||
f = calloc(1, sizeof(Font));
|
f = calloc(1, sizeof(Font));
|
||||||
f->full_name = eina_stringshare_add(fname);
|
if (_parse_font_name(fname, &f->full_name, &f->pretty_name) <0)
|
||||||
f->pretty_name = _get_pretty_font_name(fname);
|
{
|
||||||
|
free(f);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
f->term = term;
|
f->term = term;
|
||||||
f->bitmap = EINA_FALSE;
|
f->bitmap = EINA_FALSE;
|
||||||
eina_hash_add(fonthash, eina_stringshare_add(fname), f);
|
eina_hash_add(fonthash, eina_stringshare_add(fname), f);
|
||||||
|
@ -446,7 +480,7 @@ options_font(Evas_Object *opbox, Evas_Object *term)
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
len = (s == NULL) ? strlen(fname) : (size_t)(s - fname);
|
len = (s == NULL) ? strlen(fname) : (size_t)(s - fname);
|
||||||
if (!strcmp(config->font.name, f->pretty_name) ||
|
if (!strcmp(config->font.name, f->full_name) ||
|
||||||
!strncmp(config->font.name, fname, len))
|
!strncmp(config->font.name, fname, len))
|
||||||
{
|
{
|
||||||
sel_it = it;
|
sel_it = it;
|
||||||
|
|
Loading…
Reference in New Issue