diff options
| author | Richard M. Stallman | 1993-08-08 22:38:31 +0000 |
|---|---|---|
| committer | Richard M. Stallman | 1993-08-08 22:38:31 +0000 |
| commit | 2224a5fc74ae074978f60dadf46aa9a38846c619 (patch) | |
| tree | 83959d3968012cecd431cfac4a902b92f7c37ebc /src | |
| parent | 7a094f24488c2004903f1b2db0c5ee072f02e49f (diff) | |
| download | emacs-2224a5fc74ae074978f60dadf46aa9a38846c619.tar.gz emacs-2224a5fc74ae074978f60dadf46aa9a38846c619.zip | |
(struct font_info): New structure.
(x_font_table): Use struct font_info as elements.
(x_new_font): Corresponding changes.
Use XListFonts, not XListFontsWithInfo.
Use XFreeFontNames, not XFreeFontInfo.
Compare fonts by name, not by fid.
If already_loaded is 0, that counts as "yes".
Diffstat (limited to 'src')
| -rw-r--r-- | src/xterm.c | 43 |
1 files changed, 25 insertions, 18 deletions
diff --git a/src/xterm.c b/src/xterm.c index 535031e8dd6..30f34032d9b 100644 --- a/src/xterm.c +++ b/src/xterm.c | |||
| @@ -3998,8 +3998,14 @@ x_trace_wire () | |||
| 3998 | 3998 | ||
| 3999 | #ifdef HAVE_X11 | 3999 | #ifdef HAVE_X11 |
| 4000 | 4000 | ||
| 4001 | struct font_info | ||
| 4002 | { | ||
| 4003 | XFontStruct *font; | ||
| 4004 | char *name; | ||
| 4005 | }; | ||
| 4006 | |||
| 4001 | /* A table of all the fonts we have already loaded. */ | 4007 | /* A table of all the fonts we have already loaded. */ |
| 4002 | static XFontStruct **x_font_table; | 4008 | static struct font_info *x_font_table; |
| 4003 | 4009 | ||
| 4004 | /* The current capacity of x_font_table. */ | 4010 | /* The current capacity of x_font_table. */ |
| 4005 | static int x_font_table_size; | 4011 | static int x_font_table_size; |
| @@ -4022,9 +4028,8 @@ x_new_font (f, fontname) | |||
| 4022 | /* Get a list of all the fonts that match this name. Once we | 4028 | /* Get a list of all the fonts that match this name. Once we |
| 4023 | have a list of matching fonts, we compare them against the fonts | 4029 | have a list of matching fonts, we compare them against the fonts |
| 4024 | we already have by comparing font ids. */ | 4030 | we already have by comparing font ids. */ |
| 4025 | font_names = (char **) XListFontsWithInfo (x_current_display, fontname, | 4031 | font_names = (char **) XListFonts (x_current_display, fontname, |
| 4026 | 1024, &n_matching_fonts, | 4032 | 1024, &n_matching_fonts); |
| 4027 | &font_info); | ||
| 4028 | /* Apparently it doesn't set n_matching_fonts to zero when it can't | 4033 | /* Apparently it doesn't set n_matching_fonts to zero when it can't |
| 4029 | find any matches; font_names == 0 is the only clue. */ | 4034 | find any matches; font_names == 0 is the only clue. */ |
| 4030 | if (! font_names) | 4035 | if (! font_names) |
| @@ -4042,7 +4047,7 @@ x_new_font (f, fontname) | |||
| 4042 | 4047 | ||
| 4043 | for (i = 0; i < n_fonts; i++) | 4048 | for (i = 0; i < n_fonts; i++) |
| 4044 | for (j = 0; j < n_matching_fonts; j++) | 4049 | for (j = 0; j < n_matching_fonts; j++) |
| 4045 | if (x_font_table[i]->fid == font_info[j].fid) | 4050 | if (!strcmp (x_font_table[i].name, font_names[j])) |
| 4046 | { | 4051 | { |
| 4047 | already_loaded = i; | 4052 | already_loaded = i; |
| 4048 | fontname = font_names[j]; | 4053 | fontname = font_names[j]; |
| @@ -4052,8 +4057,8 @@ x_new_font (f, fontname) | |||
| 4052 | found_font: | 4057 | found_font: |
| 4053 | 4058 | ||
| 4054 | /* If we have, just return it from the table. */ | 4059 | /* If we have, just return it from the table. */ |
| 4055 | if (already_loaded > 0) | 4060 | if (already_loaded >= 0) |
| 4056 | f->display.x->font = x_font_table[already_loaded]; | 4061 | f->display.x->font = x_font_table[already_loaded].font; |
| 4057 | 4062 | ||
| 4058 | /* Otherwise, load the font and add it to the table. */ | 4063 | /* Otherwise, load the font and add it to the table. */ |
| 4059 | else | 4064 | else |
| @@ -4078,9 +4083,9 @@ x_new_font (f, fontname) | |||
| 4078 | font = (XFontStruct *) XLoadQueryFont (x_current_display, fontname); | 4083 | font = (XFontStruct *) XLoadQueryFont (x_current_display, fontname); |
| 4079 | if (! font) | 4084 | if (! font) |
| 4080 | { | 4085 | { |
| 4081 | /* Free the information from XListFontsWithInfo. */ | 4086 | /* Free the information from XListFonts. */ |
| 4082 | if (n_matching_fonts) | 4087 | if (n_matching_fonts) |
| 4083 | XFreeFontInfo (font_names, font_info, n_matching_fonts); | 4088 | XFreeFontNames (font_names); |
| 4084 | return Qnil; | 4089 | return Qnil; |
| 4085 | } | 4090 | } |
| 4086 | 4091 | ||
| @@ -4089,22 +4094,24 @@ x_new_font (f, fontname) | |||
| 4089 | { | 4094 | { |
| 4090 | x_font_table_size = 16; | 4095 | x_font_table_size = 16; |
| 4091 | x_font_table | 4096 | x_font_table |
| 4092 | = (XFontStruct **) xmalloc (x_font_table_size | 4097 | = (struct font_info *) xmalloc (x_font_table_size |
| 4093 | * sizeof (x_font_table[0])); | 4098 | * sizeof (x_font_table[0])); |
| 4094 | } | 4099 | } |
| 4095 | /* Do we need to grow the table? */ | 4100 | /* Do we need to grow the table? */ |
| 4096 | else if (n_fonts >= x_font_table_size) | 4101 | else if (n_fonts >= x_font_table_size) |
| 4097 | { | 4102 | { |
| 4098 | x_font_table_size *= 2; | 4103 | x_font_table_size *= 2; |
| 4099 | x_font_table | 4104 | x_font_table |
| 4100 | = (XFontStruct **) xrealloc (x_font_table, | 4105 | = (struct font_info *) xrealloc (x_font_table, |
| 4101 | (x_font_table_size | 4106 | (x_font_table_size |
| 4102 | * sizeof (x_font_table[0]))); | 4107 | * sizeof (x_font_table[0]))); |
| 4103 | } | 4108 | } |
| 4104 | 4109 | ||
| 4105 | f->display.x->font = x_font_table[n_fonts++] = font; | 4110 | x_font_table[n_fonts].name = (char *) xmalloc (strlen (fontname)); |
| 4111 | bcopy (fontname, x_font_table[n_fonts].name, strlen (fontname) + 1); | ||
| 4112 | f->display.x->font = x_font_table[n_fonts++].font = font; | ||
| 4106 | } | 4113 | } |
| 4107 | 4114 | ||
| 4108 | /* Now make the frame display the given font. */ | 4115 | /* Now make the frame display the given font. */ |
| 4109 | if (FRAME_X_WINDOW (f) != 0) | 4116 | if (FRAME_X_WINDOW (f) != 0) |
| 4110 | { | 4117 | { |
| @@ -4122,9 +4129,9 @@ x_new_font (f, fontname) | |||
| 4122 | Lisp_Object lispy_name = build_string (fontname); | 4129 | Lisp_Object lispy_name = build_string (fontname); |
| 4123 | 4130 | ||
| 4124 | 4131 | ||
| 4125 | /* Free the information from XListFontsWithInfo. The data | 4132 | /* Free the information from XListFonts. The data |
| 4126 | we actually retain comes from XLoadQueryFont. */ | 4133 | we actually retain comes from XLoadQueryFont. */ |
| 4127 | XFreeFontInfo (font_names, font_info, n_matching_fonts); | 4134 | XFreeFontNames (font_names); |
| 4128 | 4135 | ||
| 4129 | return lispy_name; | 4136 | return lispy_name; |
| 4130 | } | 4137 | } |