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>
* 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>
* 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>
* 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>
* src/fn-math.c (gnumeric_floor): Add significance argument.
......
......@@ -120,49 +120,65 @@ range_contains (Range *range, int col, int row)
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 *components [15*10];
char *new = g_strdup (fontname), *res;
char *p = new;
int n = 0, i, len;
/* split the font name */
for (;*p; p++){
if (*p == '-'){
*p = 0;
p++;
components [n++] = p;
if (n >= sizeof(components)/sizeof(components[0]))
break;
char *res, *dst;
int hyphens = 0;
dst = res = (char *)g_malloc (strlen (fontname) + strlen (newvalue) + 1);
while (*fontname && *fontname != ',') {
if (hyphens != idx)
*dst++ = *fontname;
if (*fontname++ == '-') {
if (hyphens == idx)
*dst++ = '-';
if (++hyphens == idx) {
strcpy (dst, newvalue);
dst += strlen (newvalue);
}
}
}
*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 */
components [idx] = newvalue;
new = font_change_component_1 (fontname, idx + 1, newvalue, &end);
newlen = strlen (new);
/* reassemble */
len = 1;
for (i = 0; i < n; i++){
len += strlen (components [i]) + 1;
res = (char *)g_realloc (res, reslen + newlen + 2);
strcpy (res + reslen, new);
g_free (new);
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;
} else
return g_strdup ("");
}
char *
font_get_bold_name (const char *fontname)
{
......@@ -182,6 +198,7 @@ font_get_italic_name (const char *fontname)
f = font_change_component (fontname, 3, "o");
if (style_font_new (f, 1) == NULL) {
g_free (f);
f = font_change_component (fontname, 3, "i");
}
......
......@@ -14,7 +14,7 @@ void gtk_radio_button_select (GSList *group, int n);
char *font_get_bold_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
......
......@@ -120,49 +120,65 @@ range_contains (Range *range, int col, int row)
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 *components [15*10];
char *new = g_strdup (fontname), *res;
char *p = new;
int n = 0, i, len;
/* split the font name */
for (;*p; p++){
if (*p == '-'){
*p = 0;
p++;
components [n++] = p;
if (n >= sizeof(components)/sizeof(components[0]))
break;
char *res, *dst;
int hyphens = 0;
dst = res = (char *)g_malloc (strlen (fontname) + strlen (newvalue) + 1);
while (*fontname && *fontname != ',') {
if (hyphens != idx)
*dst++ = *fontname;
if (*fontname++ == '-') {
if (hyphens == idx)
*dst++ = '-';
if (++hyphens == idx) {
strcpy (dst, newvalue);
dst += strlen (newvalue);
}
}
}
*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 */
components [idx] = newvalue;
new = font_change_component_1 (fontname, idx + 1, newvalue, &end);
newlen = strlen (new);
/* reassemble */
len = 1;
for (i = 0; i < n; i++){
len += strlen (components [i]) + 1;
res = (char *)g_realloc (res, reslen + newlen + 2);
strcpy (res + reslen, new);
g_free (new);
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;
} else
return g_strdup ("");
}
char *
font_get_bold_name (const char *fontname)
{
......@@ -182,6 +198,7 @@ font_get_italic_name (const char *fontname)
f = font_change_component (fontname, 3, "o");
if (style_font_new (f, 1) == NULL) {
g_free (f);
f = font_change_component (fontname, 3, "i");
}
......
......@@ -14,7 +14,7 @@ void gtk_radio_button_select (GSList *group, int n);
char *font_get_bold_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
......
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