Commit 6bb20b43 authored by Morten Welinder's avatar Morten Welinder

More font work.

parent e36a679f
1999-06-15 Morten Welinder <terra@diku.dk>
* src/style.c (font_init): Rework. (Work in progress. Things
should work ok, but will become even better.)
(style_font_new_simple): Revert to loading a font, not a fontset.
* src/gnumeric-util.c (font_get_italic_name): Plug leak and unref
the StyleFont.
(font_get_bold_name, font_get_italic_name): New parameter units.
All callers changed.
1999-06-15 Tomas Ogren <stric@ing.umu.se> 1999-06-15 Tomas Ogren <stric@ing.umu.se>
* configure.in: Added sv * configure.in: Added sv
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/style.c (style_font_new_simple): Add negative caching. * src/style.c (style_font_new_simple): Add negative caching.
(DEFAULT_FONT): Don't have a complete wildcard here -- that might (DEFAULT_FONT): Don't have a complete wildcard here -- that might
......
1999-06-15 Morten Welinder <terra@diku.dk>
* src/style.c (font_init): Rework. (Work in progress. Things
should work ok, but will become even better.)
(style_font_new_simple): Revert to loading a font, not a fontset.
* src/gnumeric-util.c (font_get_italic_name): Plug leak and unref
the StyleFont.
(font_get_bold_name, font_get_italic_name): New parameter units.
All callers changed.
1999-06-15 Tomas Ogren <stric@ing.umu.se> 1999-06-15 Tomas Ogren <stric@ing.umu.se>
* configure.in: Added sv * configure.in: Added sv
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/style.c (style_font_new_simple): Add negative caching. * src/style.c (style_font_new_simple): Add negative caching.
(DEFAULT_FONT): Don't have a complete wildcard here -- that might (DEFAULT_FONT): Don't have a complete wildcard here -- that might
......
1999-06-15 Morten Welinder <terra@diku.dk>
* src/style.c (font_init): Rework. (Work in progress. Things
should work ok, but will become even better.)
(style_font_new_simple): Revert to loading a font, not a fontset.
* src/gnumeric-util.c (font_get_italic_name): Plug leak and unref
the StyleFont.
(font_get_bold_name, font_get_italic_name): New parameter units.
All callers changed.
1999-06-15 Tomas Ogren <stric@ing.umu.se> 1999-06-15 Tomas Ogren <stric@ing.umu.se>
* configure.in: Added sv * configure.in: Added sv
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/style.c (style_font_new_simple): Add negative caching. * src/style.c (style_font_new_simple): Add negative caching.
(DEFAULT_FONT): Don't have a complete wildcard here -- that might (DEFAULT_FONT): Don't have a complete wildcard here -- that might
......
1999-06-15 Morten Welinder <terra@diku.dk>
* src/style.c (font_init): Rework. (Work in progress. Things
should work ok, but will become even better.)
(style_font_new_simple): Revert to loading a font, not a fontset.
* src/gnumeric-util.c (font_get_italic_name): Plug leak and unref
the StyleFont.
(font_get_bold_name, font_get_italic_name): New parameter units.
All callers changed.
1999-06-15 Tomas Ogren <stric@ing.umu.se> 1999-06-15 Tomas Ogren <stric@ing.umu.se>
* configure.in: Added sv * configure.in: Added sv
Mon Jun 14 18:24:40 1999 Morten Welinder <welinder@rentec.com> 1999-06-14 Morten Welinder <terra@diku.dk>
* src/style.c (style_font_new_simple): Add negative caching. * src/style.c (style_font_new_simple): Add negative caching.
(DEFAULT_FONT): Don't have a complete wildcard here -- that might (DEFAULT_FONT): Don't have a complete wildcard here -- that might
......
Tue Jun 15 18:12:19 1999 Morten Welinder <welinder@rentec.com>
* ms-excel-read.c (biff_font_data_get_style_font): Supply correct
size when initialising.
(biff_nasty_font_check_function): Revert last change. Extra
parameter ptsize.
1999-06-15 Jody Goldberg <jgoldberg@home.com> 1999-06-15 Jody Goldberg <jgoldberg@home.com>
* ms-formula-read.c (formula_func_data): Repopulate using xlcall.h and * ms-formula-read.c (formula_func_data): Repopulate using xlcall.h and
......
...@@ -425,10 +425,14 @@ biff_boundsheet_data_destroy (gpointer key, BIFF_BOUNDSHEET_DATA *d, gpointer us ...@@ -425,10 +425,14 @@ biff_boundsheet_data_destroy (gpointer key, BIFF_BOUNDSHEET_DATA *d, gpointer us
* Ug! FIXME * Ug! FIXME
**/ **/
static char * static char *
biff_nasty_font_check_function (char *name1, char *name2) biff_nasty_font_check_function (char *name1, char *name2, int ptsize)
{ {
if (gdk_fontset_load(name1)) StyleFont *font;
font = style_font_new_simple (name1, ptsize);
if (font)
{ {
style_font_unref (font);
if (name2) if (name2)
g_free(name2) ; g_free(name2) ;
return name1 ; return name1 ;
...@@ -444,16 +448,18 @@ biff_nasty_font_check_function (char *name1, char *name2) ...@@ -444,16 +448,18 @@ biff_nasty_font_check_function (char *name1, char *name2)
static StyleFont* static StyleFont*
biff_font_data_get_style_font (BIFF_FONT_DATA *fd) biff_font_data_get_style_font (BIFF_FONT_DATA *fd)
{ {
char font_size[4*sizeof(int)]; /* I know it may seem excessive. Time will say. */
int i; int i;
char *fname1, *fname2 ; char *fname1, *fname2 ;
StyleFont *ans ; StyleFont *ans ;
int ptsize;
ptsize = MAX (4, fd->height / 20);
if (!fd->fontname) { if (!fd->fontname) {
#if EXCEL_DEBUG > 0 #if EXCEL_DEBUG > 0
printf ("Curious no font name on %d\n", fd->index); printf ("Curious no font name on %d\n", fd->index);
#endif #endif
return style_font_new (gnumeric_default_font->font_name, 1); return style_font_new (gnumeric_default_font->font_name, ptsize);
} }
/* /*
...@@ -469,36 +475,27 @@ biff_font_data_get_style_font (BIFF_FONT_DATA *fd) ...@@ -469,36 +475,27 @@ biff_font_data_get_style_font (BIFF_FONT_DATA *fd)
fname1 = g_strdup (gnumeric_default_font->font_name); fname1 = g_strdup (gnumeric_default_font->font_name);
fname2 = font_change_component (gnumeric_default_font->font_name, 1, fd->fontname); fname2 = font_change_component (gnumeric_default_font->font_name, 1, fd->fontname);
fname1 = biff_nasty_font_check_function (fname2, fname1); fname1 = biff_nasty_font_check_function (fname2, fname1, ptsize);
/* printf ("FoNt [-]: %s\n", fname1) ; */ /* printf ("FoNt [-]: %s\n", fname1) ; */
if (fd->italic) { if (fd->italic) {
fname2 = font_get_italic_name (fname1); fname2 = font_get_italic_name (fname1, ptsize);
/* printf ("FoNt [i]: %s\n", fname2) ; */ /* printf ("FoNt [i]: %s\n", fname2) ; */
} }
else else
fname2 = g_strdup (fname1) ; fname2 = g_strdup (fname1) ;
fname1 = biff_nasty_font_check_function (fname2, fname1) ; fname1 = biff_nasty_font_check_function (fname2, fname1, ptsize) ;
if (fd->boldness >= 0x2bc) { if (fd->boldness >= 0x2bc) {
fname2 = font_get_bold_name (fname1) ; fname2 = font_get_bold_name (fname1, ptsize) ;
/* printf ("FoNt [b]: %s\n", fname1) ; */ /* printf ("FoNt [b]: %s\n", fname1) ; */
} }
else else
fname2 = g_strdup (fname1) ; fname2 = g_strdup (fname1) ;
fname1 = biff_nasty_font_check_function (fname2, fname1) ; fname1 = biff_nasty_font_check_function (fname2, fname1, ptsize) ;
/* What about underlining? */ /* What about underlining? */
g_snprintf (font_size, 16, "%d", fd->height / 2); ans = style_font_new (fname1, ptsize) ;
{
char *tmp;
tmp = font_change_component (fname1, 7, font_size);
fname2 = font_change_component (tmp, 6, "*");
g_free (tmp);
}
fname1 = biff_nasty_font_check_function (fname2, fname1) ;
ans = style_font_new (fname1, 1) ;
g_free (fname1) ; g_free (fname1) ;
if (fd->italic) if (fd->italic)
......
...@@ -186,7 +186,7 @@ font_change_component (const char *fontname, int idx, const char *newvalue) ...@@ -186,7 +186,7 @@ font_change_component (const char *fontname, int idx, const char *newvalue)
char * char *
font_get_bold_name (const char *fontname) font_get_bold_name (const char *fontname, int units)
{ {
char *f; char *f;
...@@ -198,15 +198,18 @@ font_get_bold_name (const char *fontname) ...@@ -198,15 +198,18 @@ font_get_bold_name (const char *fontname)
} }
char * char *
font_get_italic_name (const char *fontname) font_get_italic_name (const char *fontname, int units)
{ {
char *f; char *f;
StyleFont *sf;
f = font_change_component (fontname, 3, "o"); f = font_change_component (fontname, 3, "o");
if (style_font_new (f, 1) == NULL) { sf = style_font_new_simple (f, units);
if (sf == NULL) {
g_free (f); g_free (f);
f = font_change_component (fontname, 3, "i"); f = font_change_component (fontname, 3, "i");
} } else
style_font_unref (sf);
return f; return f;
} }
......
...@@ -12,8 +12,8 @@ int run_popup_menu (GdkEvent *event, int button, char **strings); ...@@ -12,8 +12,8 @@ int run_popup_menu (GdkEvent *event, int button, char **strings);
int gtk_radio_group_get_selected (GSList *radio_group); int gtk_radio_group_get_selected (GSList *radio_group);
void gtk_radio_button_select (GSList *group, int n); 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, int units);
char *font_get_italic_name (const char *fontname); char *font_get_italic_name (const char *fontname, int units);
char *font_change_component (const char *fontname, int idx, const char *value); char *font_change_component (const char *fontname, int idx, const char *value);
/* /*
......
...@@ -186,7 +186,7 @@ font_change_component (const char *fontname, int idx, const char *newvalue) ...@@ -186,7 +186,7 @@ font_change_component (const char *fontname, int idx, const char *newvalue)
char * char *
font_get_bold_name (const char *fontname) font_get_bold_name (const char *fontname, int units)
{ {
char *f; char *f;
...@@ -198,15 +198,18 @@ font_get_bold_name (const char *fontname) ...@@ -198,15 +198,18 @@ font_get_bold_name (const char *fontname)
} }
char * char *
font_get_italic_name (const char *fontname) font_get_italic_name (const char *fontname, int units)
{ {
char *f; char *f;
StyleFont *sf;
f = font_change_component (fontname, 3, "o"); f = font_change_component (fontname, 3, "o");
if (style_font_new (f, 1) == NULL) { sf = style_font_new_simple (f, units);
if (sf == NULL) {
g_free (f); g_free (f);
f = font_change_component (fontname, 3, "i"); f = font_change_component (fontname, 3, "i");
} } else
style_font_unref (sf);
return f; return f;
} }
......
...@@ -12,8 +12,8 @@ int run_popup_menu (GdkEvent *event, int button, char **strings); ...@@ -12,8 +12,8 @@ int run_popup_menu (GdkEvent *event, int button, char **strings);
int gtk_radio_group_get_selected (GSList *radio_group); int gtk_radio_group_get_selected (GSList *radio_group);
void gtk_radio_button_select (GSList *group, int n); 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, int units);
char *font_get_italic_name (const char *fontname); char *font_get_italic_name (const char *fontname, int units);
char *font_change_component (const char *fontname, int idx, const char *value); char *font_change_component (const char *fontname, int idx, const char *value);
/* /*
......
...@@ -11,18 +11,12 @@ ...@@ -11,18 +11,12 @@
#include "gnumeric.h" #include "gnumeric.h"
#include "format.h" #include "format.h"
#include "color.h" #include "color.h"
#include "gnumeric-util.h"
#define DEFAULT_FONT \ #define DEBUG_FONTS
"-adobe-helvetica-medium-r-normal--*-120-*-*-*-*-iso8859-*," \
"-*-*-medium-r-normal--12-*-*-*-*-*-iso8859-*," \ #define DEFAULT_FONT "-adobe-helvetica-medium-r-normal--*-*-*-*-*-*-iso8859-*"
"-*-*-regular-r-normal--12-*-*-*-*-*-iso8859-*" #define DEFAULT_FONT_SIZE 12
#define DEFAULT_BOLD_FONT \
"-adobe-helvetica-bold-r-normal--*-120-*-*-*-*-iso8859-*," \
"-*-*-bold-r-normal--12-*-*-*-*-*-iso8859-*"
#define DEFAULT_ITALIC_FONT \
"-adobe-helvetica-medium-o-normal--*-120-*-*-*-*-iso8859-*," \
"-*-*-medium-o-normal--12-*-*-*-*-*-iso8859-*"
#define DEFAULT_SIZE 12
static GHashTable *style_format_hash; static GHashTable *style_format_hash;
static GHashTable *style_font_hash; static GHashTable *style_font_hash;
...@@ -34,6 +28,9 @@ StyleFont *gnumeric_default_font; ...@@ -34,6 +28,9 @@ StyleFont *gnumeric_default_font;
StyleFont *gnumeric_default_bold_font; StyleFont *gnumeric_default_bold_font;
StyleFont *gnumeric_default_italic_font; StyleFont *gnumeric_default_italic_font;
static StyleFont *standard_fonts[2][2]; /* [bold-p][italic-p] */
static char *standard_font_names[2][2]; /* [bold-p][italic-p] */
StyleFormat * StyleFormat *
style_format_new (const char *name) style_format_new (const char *name)
{ {
...@@ -105,6 +102,26 @@ font_compute_hints (StyleFont *font) ...@@ -105,6 +102,26 @@ font_compute_hints (StyleFont *font)
} }
} }
#ifdef DEBUG_FONTS
#include <X11/Xlib.h>
#include "gdk/gdkprivate.h" /* Sorry */
static const char *
my_gdk_actual_font_name (GdkFont *font)
{
GdkFontPrivate *private;
Atom atom, font_atom;
private = (GdkFontPrivate *)font;
font_atom = XInternAtom (private->xdisplay, "FONT", True);
if (font_atom != None) {
if (XGetFontProperty (private->xfont, font_atom, &atom) == True)
return XGetAtomName (private->xdisplay, atom);
}
return NULL;
}
#endif
StyleFont * StyleFont *
style_font_new_simple (const char *font_name, int units) style_font_new_simple (const char *font_name, int units)
{ {
...@@ -112,29 +129,46 @@ style_font_new_simple (const char *font_name, int units) ...@@ -112,29 +129,46 @@ style_font_new_simple (const char *font_name, int units)
StyleFont key; StyleFont key;
g_return_val_if_fail (font_name != NULL, NULL); g_return_val_if_fail (font_name != NULL, NULL);
g_return_val_if_fail (units != 0, NULL); g_return_val_if_fail (units > 0, NULL);
key.font_name = (char *)font_name; /* We will not change the name. */ /* This cast does not mean we will change the name. */
key.font_name = (char *)font_name;
key.units = units; key.units = units;
font = (StyleFont *) g_hash_table_lookup (style_font_hash, &key); font = (StyleFont *) g_hash_table_lookup (style_font_hash, &key);
if (!font){ if (!font){
GdkFont *gdk_font; GdkFont *gdk_font;
char *font_name_copy; char *font_name_copy, *font_name_with_size;
char sizetxt[4 * sizeof (int)];
if (g_hash_table_lookup (style_font_negative_hash, &key)) if (g_hash_table_lookup (style_font_negative_hash, &key))
return NULL; return NULL;
font_name_copy = g_strdup (font_name); font_name_copy = g_strdup (font_name);
gdk_font = gdk_fontset_load (font_name_copy); sprintf (sizetxt, "%d", units);
font_name_with_size =
font_change_component (font_name, 6, sizetxt);
gdk_font = gdk_font_load (font_name_copy);
#ifdef DEBUG_FONTS
printf ("Font \"%s\"\n", font_name_with_size);
#endif
g_free (font_name_with_size);
if (!gdk_font) { if (!gdk_font) {
key.font_name = font_name_copy; key.font_name = font_name_copy;
g_hash_table_insert (style_font_negative_hash, g_hash_table_insert (style_font_negative_hash,
&key, &key); &key, &key);
#ifdef DEBUG_FONTS
printf ("was not resolved.\n\n");
#endif
return NULL; return NULL;
} }
#ifdef DEBUG_FONTS
printf ("was resolved as \"%s\".\n\n",
my_gdk_actual_font_name (gdk_font));
#endif
font = g_new0 (StyleFont, 1); font = g_new0 (StyleFont, 1);
font->font_name = font_name_copy; font->font_name = font_name_copy;
font->units = units; font->units = units;
...@@ -309,7 +343,7 @@ style_new (void) ...@@ -309,7 +343,7 @@ style_new (void)
style->valid_flags = STYLE_ALL; style->valid_flags = STYLE_ALL;
style->format = style_format_new ("General"); style->format = style_format_new ("General");
style->font = style_font_new (DEFAULT_FONT, DEFAULT_SIZE); style->font = style_font_new (DEFAULT_FONT, DEFAULT_FONT_SIZE);
style->border = style_border_new_plain (); style->border = style_border_new_plain ();
style->fore_color = style_color_new (0, 0, 0); style->fore_color = style_color_new (0, 0, 0);
style->back_color = style_color_new (0xffff, 0xffff, 0xffff); style->back_color = style_color_new (0xffff, 0xffff, 0xffff);
...@@ -529,12 +563,32 @@ style_merge_to (Style *target, Style *source) ...@@ -529,12 +563,32 @@ style_merge_to (Style *target, Style *source)
static void static void
font_init (void) font_init (void)
{ {
gnumeric_default_font = style_font_new_simple (DEFAULT_FONT, DEFAULT_SIZE); int boldp, italicp;
for (boldp = 0; boldp <= 1; boldp++) {
for (italicp = 0; italicp <= 1; italicp++) {
char *name;
int size = DEFAULT_FONT_SIZE;
if (!gnumeric_default_font) name = g_strdup (DEFAULT_FONT);
gnumeric_default_font = style_font_new_simple ("fixed", DEFAULT_SIZE);
if (!gnumeric_default_font) { if (boldp) {
char *tmp;
tmp = font_get_bold_name (name, size);
g_free (name);
name = tmp;
}
if (italicp) {
char *tmp;
tmp = font_get_italic_name (name, size);
g_free (name);
name = tmp;
}
standard_fonts[boldp][italicp] =
style_font_new_simple (name, size);
if (!standard_fonts[boldp][italicp]) {
fprintf (stderr, fprintf (stderr,
"Gnumeric failed to find a suitable default font.\n" "Gnumeric failed to find a suitable default font.\n"
"Please file a proper bug report (see http://bugs.gnome.org)\n" "Please file a proper bug report (see http://bugs.gnome.org)\n"
...@@ -542,13 +596,20 @@ font_init (void) ...@@ -542,13 +596,20 @@ font_init (void)
"\n" "\n"
"1. Values of LC_ALL and LANG environment variables.\n" "1. Values of LC_ALL and LANG environment variables.\n"
"2. A list of the fonts on your system (from the xlsfonts program).\n" "2. A list of the fonts on your system (from the xlsfonts program).\n"
"3. The values here: boldp=%d, italicp=%d\n"
"\n" "\n"
"Thanks -- the Gnumeric Team\n"); "Thanks -- the Gnumeric Team\n",
boldp, italicp);
exit (1); exit (1);
} }
gnumeric_default_bold_font = style_font_new (DEFAULT_BOLD_FONT, DEFAULT_SIZE); standard_font_names[boldp][italicp] = name;
gnumeric_default_italic_font = style_font_new (DEFAULT_ITALIC_FONT, DEFAULT_SIZE); }
}
gnumeric_default_font = standard_fonts[0][0];
gnumeric_default_bold_font = standard_fonts[1][0];
gnumeric_default_italic_font = standard_fonts[0][1];
} }
void void
......
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