aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGerd Moellmann2000-03-03 13:49:32 +0000
committerGerd Moellmann2000-03-03 13:49:32 +0000
commite2ef8ee6d5320044decd2be0855216e546dd532e (patch)
tree5846e64483e5dee7016329dd648031ad0cfe3cf9
parente5b99cff112763293a7593f32381c36ec1c96fef (diff)
downloademacs-e2ef8ee6d5320044decd2be0855216e546dd532e.tar.gz
emacs-e2ef8ee6d5320044decd2be0855216e546dd532e.zip
(PER_CHAR_METRIC): Removed.
(x_per_char_metric_1, x_default_char): New functions. (x_per_char_metric): If font's default char is invalid, return metrics of a suitably chosen usable default char. (x_draw_glyph_string_foreground): If font has an invalid default char, replace occurrences of that char with a suitably chosen usable default char.
-rw-r--r--src/xterm.c112
1 files changed, 83 insertions, 29 deletions
diff --git a/src/xterm.c b/src/xterm.c
index 22394aba204..1ed9c9db617 100644
--- a/src/xterm.c
+++ b/src/xterm.c
@@ -1097,6 +1097,7 @@ static struct face *x_get_glyph_face_and_encoding P_ ((struct frame *,
1097 XChar2b *)); 1097 XChar2b *));
1098static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int, 1098static struct face *x_get_char_face_and_encoding P_ ((struct frame *, int,
1099 int, XChar2b *, int)); 1099 int, XChar2b *, int));
1100static XCharStruct *x_per_char_metric_1 P_ ((XFontStruct *, XChar2b *));
1100static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *)); 1101static XCharStruct *x_per_char_metric P_ ((XFontStruct *, XChar2b *));
1101static void x_encode_char P_ ((int, XChar2b *, struct font_info *)); 1102static void x_encode_char P_ ((int, XChar2b *, struct font_info *));
1102static void x_append_glyph P_ ((struct it *)); 1103static void x_append_glyph P_ ((struct it *));
@@ -1105,27 +1106,14 @@ static void x_append_stretch_glyph P_ ((struct it *it, Lisp_Object,
1105 int, int, double)); 1106 int, int, double));
1106static void x_produce_glyphs P_ ((struct it *)); 1107static void x_produce_glyphs P_ ((struct it *));
1107static void x_produce_image_glyph P_ ((struct it *it)); 1108static void x_produce_image_glyph P_ ((struct it *it));
1108 1109static XCharStruct *x_default_char P_ ((XFontStruct *, XChar2b *));
1109
1110/* Return a pointer to per-char metric information in FONT of a
1111 character pointed by B which is a pointer to an XChar2b. */
1112
1113#define PER_CHAR_METRIC(font, b) \
1114 ((font)->per_char \
1115 ? ((font)->per_char + (b)->byte2 - (font)->min_char_or_byte2 \
1116 + (((font)->min_byte1 || (font)->max_byte1) \
1117 ? (((b)->byte1 - (font)->min_byte1) \
1118 * ((font)->max_char_or_byte2 - (font)->min_char_or_byte2 + 1)) \
1119 : 0)) \
1120 : &((font)->max_bounds))
1121 1110
1122 1111
1123/* Get metrics of character CHAR2B in FONT. Value is always non-null. 1112/* Get metrics of character CHAR2B in FONT. Value is null if CHAR2B
1124 If CHAR2B is not contained in FONT, the font's default character 1113 is not contained in the font. */
1125 metric is returned. */
1126 1114
1127static INLINE XCharStruct * 1115static INLINE XCharStruct *
1128x_per_char_metric (font, char2b) 1116x_per_char_metric_1 (font, char2b)
1129 XFontStruct *font; 1117 XFontStruct *font;
1130 XChar2b *char2b; 1118 XChar2b *char2b;
1131{ 1119{
@@ -1186,27 +1174,82 @@ x_per_char_metric (font, char2b)
1186 pcm = &font->max_bounds; 1174 pcm = &font->max_bounds;
1187 } 1175 }
1188 1176
1177 if (pcm && pcm->width == 0)
1178 pcm = NULL;
1179
1180 return pcm;
1181}
1182
1183
1184/* Return in *DEFAULT_CHAR the default char to use for characters not
1185 contained in FONT. This is either FONT->default_char if that is
1186 valid, or some suitable other character if FONT->default_char is
1187 invalid. Value is a pointer to the XCharStruct of
1188 FONT->default_char or null if FONT->default_char is invalid. */
1189
1190static INLINE XCharStruct *
1191x_default_char (font, default_char)
1192 XFontStruct *font;
1193 XChar2b *default_char;
1194{
1195 XCharStruct *pcm;
1196
1197 /* FONT->default_char is a 16-bit character code with byte1 in the
1198 most significant byte and byte2 in the least significant
1199 byte. */
1200 default_char->byte1 = (font->default_char >> BITS_PER_CHAR) & 0xff;
1201 default_char->byte2 = font->default_char & 0xff;
1202 pcm = x_per_char_metric_1 (font, default_char);
1203
1204 /* If FONT->default_char is invalid, choose a better one. */
1205 if (pcm == NULL)
1206 {
1207 if (font->per_char)
1208 {
1209 if (font->min_byte1 == 0 && font->max_byte1 == 0)
1210 {
1211 default_char->byte1 = 0;
1212 default_char->byte2 = font->min_char_or_byte2;
1213 }
1214 else
1215 {
1216 default_char->byte1 = font->min_byte1;
1217 default_char->byte2 = font->min_char_or_byte2;
1218 }
1219 }
1220 else
1221 default_char->byte2 = font->min_char_or_byte2;
1222 }
1223
1224 return pcm;
1225}
1226
1189 1227
1190 if (pcm == NULL || pcm->width == 0) 1228/* Get metrics of character CHAR2B in FONT. Value is always non-null.
1229 If CHAR2B is not contained in FONT, a default character metric is
1230 returned. */
1231
1232static INLINE XCharStruct *
1233x_per_char_metric (font, char2b)
1234 XFontStruct *font;
1235 XChar2b *char2b;
1236{
1237 XCharStruct *pcm = x_per_char_metric_1 (font, char2b);
1238
1239 if (pcm == NULL)
1191 { 1240 {
1192 /* Character not contained in the font. FONT->default_char 1241 /* Character not contained in the font. FONT->default_char
1193 gives the character that will be printed. FONT->default_char 1242 gives the character that will be printed. FONT->default_char
1194 is a 16-bit character code with byte1 in the most significant 1243 is a 16-bit character code with byte1 in the most significant
1195 byte and byte2 in the least significant byte. */ 1244 byte and byte2 in the least significant byte. */
1196 XChar2b default_char; 1245 XChar2b default_char;
1197 default_char.byte1 = (font->default_char >> BITS_PER_CHAR) & 0xff; 1246
1198 default_char.byte2 = font->default_char & 0xff; 1247 pcm = x_default_char (font, &default_char);
1199 1248 if (pcm == NULL)
1200 /* Avoid an endless recursion if FONT->default_char itself 1249 pcm = x_per_char_metric_1 (font, &default_char);
1201 hasn't per char metrics. handa@etl.go.jp reports that some
1202 fonts have this problem. */
1203 if (default_char.byte1 != char2b->byte1
1204 || default_char.byte2 != char2b->byte2)
1205 pcm = x_per_char_metric (font, &default_char);
1206 else
1207 pcm = &font->max_bounds;
1208 } 1250 }
1209 1251
1252 xassert (pcm != NULL);
1210 return pcm; 1253 return pcm;
1211} 1254}
1212 1255
@@ -3049,10 +3092,21 @@ x_draw_glyph_string_foreground (s)
3049 { 3092 {
3050 char *char1b = (char *) s->char2b; 3093 char *char1b = (char *) s->char2b;
3051 int boff = s->font_info->baseline_offset; 3094 int boff = s->font_info->baseline_offset;
3095 XChar2b default_char;
3052 3096
3053 if (s->font_info->vertical_centering) 3097 if (s->font_info->vertical_centering)
3054 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff; 3098 boff = VCENTER_BASELINE_OFFSET (s->font, s->f) - boff;
3055 3099
3100 /* If S->font has an invalid default char, X might output some
3101 characters with zero width which is highly undesirable.
3102 Choose another default char in this case, and replace all
3103 occurrences of invalid characters in the string with that
3104 char. */
3105 if (!x_default_char (s->font, &default_char))
3106 for (i = 0; i < s->nchars; ++i)
3107 if (!x_per_char_metric_1 (s->font, s->char2b + i))
3108 s->char2b[i] = default_char;
3109
3056 /* If we can use 8-bit functions, condense S->char2b. */ 3110 /* If we can use 8-bit functions, condense S->char2b. */
3057 if (!s->two_byte_p) 3111 if (!s->two_byte_p)
3058 for (i = 0; i < s->nchars; ++i) 3112 for (i = 0; i < s->nchars; ++i)