Commit 9c583b67 authored by Morten Welinder's avatar Morten Welinder

Improve fontset handling.

parent 0d4ed782
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com>
* src/gnumeric-util.c (font_get_italic_name): Plug leak.
(font_change_component): Constify. Handle fontsets.
1999-06-14 Morten Welinder <terra@diku.dk> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_floor): Add significance argument. * src/fn-math.c (gnumeric_floor): Add significance argument.
......
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com>
* src/gnumeric-util.c (font_get_italic_name): Plug leak.
(font_change_component): Constify. Handle fontsets.
1999-06-14 Morten Welinder <terra@diku.dk> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_floor): Add significance argument. * src/fn-math.c (gnumeric_floor): Add significance argument.
......
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com>
* src/gnumeric-util.c (font_get_italic_name): Plug leak.
(font_change_component): Constify. Handle fontsets.
1999-06-14 Morten Welinder <terra@diku.dk> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_floor): Add significance argument. * src/fn-math.c (gnumeric_floor): Add significance argument.
......
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com>
* src/gnumeric-util.c (font_get_italic_name): Plug leak.
(font_change_component): Constify. Handle fontsets.
1999-06-14 Morten Welinder <terra@diku.dk> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/fn-math.c (gnumeric_floor): Add significance argument. * src/fn-math.c (gnumeric_floor): Add significance argument.
......
...@@ -120,49 +120,65 @@ range_contains (Range *range, int col, int row) ...@@ -120,49 +120,65 @@ range_contains (Range *range, int col, int row)
return FALSE; return FALSE;
} }
char *
font_change_component (const char *fontname, int idx, char *newvalue) static char *
font_change_component_1 (const char *fontname, int idx,
const char *newvalue, char const **end)
{ {
/* FIXME: don't work well for a comma-sepated fontset name */ char *res, *dst;
char *components [15*10]; int hyphens = 0;
char *new = g_strdup (fontname), *res;
char *p = new; dst = res = (char *)g_malloc (strlen (fontname) + strlen (newvalue) + 1);
int n = 0, i, len; while (*fontname && *fontname != ',') {
if (hyphens != idx)
/* split the font name */ *dst++ = *fontname;
for (;*p; p++){ if (*fontname++ == '-') {
if (*p == '-'){ if (hyphens == idx)
*p = 0; *dst++ = '-';
p++; if (++hyphens == idx) {
components [n++] = p; strcpy (dst, newvalue);
if (n >= sizeof(components)/sizeof(components[0])) dst += strlen (newvalue);
break;
} }
} }
}
*end = fontname;
*dst = 0;
return res;
}
char *
font_change_component (const char *fontname, int idx, const char *newvalue)
{
char *res = 0;
int reslen = 0;
while (*fontname) {
const char *end;
char *new;
int newlen;
/* Change the value */ new = font_change_component_1 (fontname, idx + 1, newvalue, &end);
components [idx] = newvalue; newlen = strlen (new);
/* reassemble */ res = (char *)g_realloc (res, reslen + newlen + 2);
len = 1; strcpy (res + reslen, new);
for (i = 0; i < n; i++){ g_free (new);
len += strlen (components [i]) + 1; reslen += newlen;
fontname = end;
if (*fontname == ',') {
res[reslen++] = ',';
fontname++;
} }
len++;
res = g_malloc (len);
res [0] = '-';
res [1] = 0;
for (i = 0; i < n; i++){
strcat (res, components [i]);
if (i + 1 != n)
strcat (res, "-");
} }
g_free (new); if (reslen) {
res[reslen] = 0;
return res; return res;
} else
return g_strdup ("");
} }
char * char *
font_get_bold_name (const char *fontname) font_get_bold_name (const char *fontname)
{ {
...@@ -182,6 +198,7 @@ font_get_italic_name (const char *fontname) ...@@ -182,6 +198,7 @@ font_get_italic_name (const char *fontname)
f = font_change_component (fontname, 3, "o"); f = font_change_component (fontname, 3, "o");
if (style_font_new (f, 1) == NULL) { if (style_font_new (f, 1) == NULL) {
g_free (f);
f = font_change_component (fontname, 3, "i"); f = font_change_component (fontname, 3, "i");
} }
......
...@@ -14,7 +14,7 @@ void gtk_radio_button_select (GSList *group, int n); ...@@ -14,7 +14,7 @@ void gtk_radio_button_select (GSList *group, int n);
char *font_get_bold_name (const char *fontname); char *font_get_bold_name (const char *fontname);
char *font_get_italic_name (const char *fontname); char *font_get_italic_name (const char *fontname);
char *font_change_component (const char *fontname, int idx, char *value); char *font_change_component (const char *fontname, int idx, const char *value);
/* /*
* Use this on menus that are popped up * Use this on menus that are popped up
......
...@@ -120,49 +120,65 @@ range_contains (Range *range, int col, int row) ...@@ -120,49 +120,65 @@ range_contains (Range *range, int col, int row)
return FALSE; return FALSE;
} }
char *
font_change_component (const char *fontname, int idx, char *newvalue) static char *
font_change_component_1 (const char *fontname, int idx,
const char *newvalue, char const **end)
{ {
/* FIXME: don't work well for a comma-sepated fontset name */ char *res, *dst;
char *components [15*10]; int hyphens = 0;
char *new = g_strdup (fontname), *res;
char *p = new; dst = res = (char *)g_malloc (strlen (fontname) + strlen (newvalue) + 1);
int n = 0, i, len; while (*fontname && *fontname != ',') {
if (hyphens != idx)
/* split the font name */ *dst++ = *fontname;
for (;*p; p++){ if (*fontname++ == '-') {
if (*p == '-'){ if (hyphens == idx)
*p = 0; *dst++ = '-';
p++; if (++hyphens == idx) {
components [n++] = p; strcpy (dst, newvalue);
if (n >= sizeof(components)/sizeof(components[0])) dst += strlen (newvalue);
break;
} }
} }
}
*end = fontname;
*dst = 0;
return res;
}
char *
font_change_component (const char *fontname, int idx, const char *newvalue)
{
char *res = 0;
int reslen = 0;
while (*fontname) {
const char *end;
char *new;
int newlen;
/* Change the value */ new = font_change_component_1 (fontname, idx + 1, newvalue, &end);
components [idx] = newvalue; newlen = strlen (new);
/* reassemble */ res = (char *)g_realloc (res, reslen + newlen + 2);
len = 1; strcpy (res + reslen, new);
for (i = 0; i < n; i++){ g_free (new);
len += strlen (components [i]) + 1; reslen += newlen;
fontname = end;
if (*fontname == ',') {
res[reslen++] = ',';
fontname++;
} }
len++;
res = g_malloc (len);
res [0] = '-';
res [1] = 0;
for (i = 0; i < n; i++){
strcat (res, components [i]);
if (i + 1 != n)
strcat (res, "-");
} }
g_free (new); if (reslen) {
res[reslen] = 0;
return res; return res;
} else
return g_strdup ("");
} }
char * char *
font_get_bold_name (const char *fontname) font_get_bold_name (const char *fontname)
{ {
...@@ -182,6 +198,7 @@ font_get_italic_name (const char *fontname) ...@@ -182,6 +198,7 @@ font_get_italic_name (const char *fontname)
f = font_change_component (fontname, 3, "o"); f = font_change_component (fontname, 3, "o");
if (style_font_new (f, 1) == NULL) { if (style_font_new (f, 1) == NULL) {
g_free (f);
f = font_change_component (fontname, 3, "i"); f = font_change_component (fontname, 3, "i");
} }
......
...@@ -14,7 +14,7 @@ void gtk_radio_button_select (GSList *group, int n); ...@@ -14,7 +14,7 @@ void gtk_radio_button_select (GSList *group, int n);
char *font_get_bold_name (const char *fontname); char *font_get_bold_name (const char *fontname);
char *font_get_italic_name (const char *fontname); char *font_get_italic_name (const char *fontname);
char *font_change_component (const char *fontname, int idx, char *value); char *font_change_component (const char *fontname, int idx, const char *value);
/* /*
* Use this on menus that are popped up * Use this on menus that are popped up
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment