summaryrefslogtreecommitdiff
path: root/src/bin/options_font.c
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2014-05-25 22:38:23 +0200
committerBoris Faure <billiob@gmail.com>2014-05-25 22:38:23 +0200
commit503dd081059b60240316a538ae3ada0195577bf1 (patch)
tree169e6a2d36a58b34a2cb39e3db56d4b7edef2606 /src/bin/options_font.c
parenta3e7a770bc514e6660de8950dbbd083926110791 (diff)
handle fonts with multiple names
Diffstat (limited to 'src/bin/options_font.c')
-rw-r--r--src/bin/options_font.c66
1 files changed, 50 insertions, 16 deletions
diff --git a/src/bin/options_font.c b/src/bin/options_font.c
index 45b6f3e..98c15ff 100644
--- a/src/bin/options_font.c
+++ b/src/bin/options_font.c
@@ -42,33 +42,60 @@ _update_sizing(Evas_Object *term)
42 expecting_resize = 1; 42 expecting_resize = 1;
43} 43}
44 44
45static const char * 45static int
46_get_pretty_font_name(const char *full_name) 46_parse_font_name(const char *full_name,
47 const char **name, const char **pretty_name)
47{ 48{
48 char buf[4096]; 49 char buf[4096];
49 size_t style_len = 0; 50 size_t style_len = 0;
50 size_t font_len = 0; 51 size_t font_len = 0;
51 char *style = NULL; 52 char *style = NULL;
52 char *s; 53 char *s;
54 unsigned int len;
55
56 *pretty_name = NULL;
57 *name = NULL;
58
59 font_len = strlen(full_name);
60 if (font_len >= sizeof(buf))
61 return -1;
62 style = strchr(full_name, ':');
63 if (style)
64 font_len = (size_t)(style - full_name);
65
66 s = strchr(full_name, ',');
67 if (s && style && s < style)
68 font_len = s - full_name;
53 69
54 s = strchr(full_name, ':'); 70#define STYLE_STR ":style="
55 if (s == NULL) 71 if (style && strncmp(style, STYLE_STR, strlen(STYLE_STR)) == 0)
56 { 72 {
57 return eina_stringshare_add(full_name); 73 style += strlen(STYLE_STR);
74 s = strchr(style, ',');
75 style_len = (s == NULL) ? strlen(style) : (size_t)(s - style);
58 } 76 }
59 font_len = s - full_name; 77
60 s++; 78 s = buf;
61#define STYLE_STR "style=" 79 memcpy(s, full_name, font_len);
62 if (strncmp(s, STYLE_STR, strlen(STYLE_STR)) == 0) 80 s += font_len;
81 len = font_len;
82 if (style)
63 { 83 {
84 memcpy(s, STYLE_STR, strlen(STYLE_STR));
64 s += strlen(STYLE_STR); 85 s += strlen(STYLE_STR);
65 style = s; 86 len += strlen(STYLE_STR);
66 s = strchr(s, ','); 87
67 style_len = (s == NULL) ? strlen(style) : (size_t)(s - style); 88 memcpy(s, style, style_len);
89 s += style_len;
90 len += style_len;
68 } 91 }
92 *s = '\0';
93 *name = eina_stringshare_add_length(buf, len);
69#undef STYLE_STR 94#undef STYLE_STR
95
70 /* unescape the dashes */ 96 /* unescape the dashes */
71 s = buf; 97 s = buf;
98 len = 0;
72 while ( (size_t)(s - buf) < sizeof(buf) && 99 while ( (size_t)(s - buf) < sizeof(buf) &&
73 font_len > 0 ) 100 font_len > 0 )
74 { 101 {
@@ -78,6 +105,7 @@ _get_pretty_font_name(const char *full_name)
78 } 105 }
79 full_name++; 106 full_name++;
80 font_len--; 107 font_len--;
108 len++;
81 } 109 }
82 /* copy style */ 110 /* copy style */
83 if (style_len > 0 && ((sizeof(buf) - (s - buf)) > style_len + 3 )) 111 if (style_len > 0 && ((sizeof(buf) - (s - buf)) > style_len + 3 ))
@@ -87,10 +115,13 @@ _get_pretty_font_name(const char *full_name)
87 memcpy(s, style, style_len); 115 memcpy(s, style, style_len);
88 s += style_len; 116 s += style_len;
89 *s++ = ')'; 117 *s++ = ')';
118
119 len += 3 + style_len;
90 } 120 }
91 *s = '\0'; 121 *s = '\0';
92 122
93 return eina_stringshare_add(buf); 123 *pretty_name = eina_stringshare_add_length(buf, len);
124 return 0;
94} 125}
95 126
96static void 127static void
@@ -431,8 +462,11 @@ options_font(Evas_Object *opbox, Evas_Object *term)
431 if (!eina_hash_find(fonthash, fname)) 462 if (!eina_hash_find(fonthash, fname))
432 { 463 {
433 f = calloc(1, sizeof(Font)); 464 f = calloc(1, sizeof(Font));
434 f->full_name = eina_stringshare_add(fname); 465 if (_parse_font_name(fname, &f->full_name, &f->pretty_name) <0)
435 f->pretty_name = _get_pretty_font_name(fname); 466 {
467 free(f);
468 continue;
469 }
436 f->term = term; 470 f->term = term;
437 f->bitmap = EINA_FALSE; 471 f->bitmap = EINA_FALSE;
438 eina_hash_add(fonthash, eina_stringshare_add(fname), f); 472 eina_hash_add(fonthash, eina_stringshare_add(fname), f);
@@ -446,7 +480,7 @@ options_font(Evas_Object *opbox, Evas_Object *term)
446 size_t len; 480 size_t len;
447 481
448 len = (s == NULL) ? strlen(fname) : (size_t)(s - fname); 482 len = (s == NULL) ? strlen(fname) : (size_t)(s - fname);
449 if (!strcmp(config->font.name, f->pretty_name) || 483 if (!strcmp(config->font.name, f->full_name) ||
450 !strncmp(config->font.name, fname, len)) 484 !strncmp(config->font.name, fname, len))
451 { 485 {
452 sel_it = it; 486 sel_it = it;