Skip to content

Commit bb9a151

Browse files
Nicolas Pitregregkh
authored andcommitted
vt: move glyph determination to a separate function
No logical changes. Make it easier for enhancements to come. Signed-off-by: Nicolas Pitre <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 68e7a42 commit bb9a151

File tree

1 file changed

+38
-33
lines changed

1 file changed

+38
-33
lines changed

drivers/tty/vt/vt.c

Lines changed: 38 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2925,6 +2925,7 @@ static void vc_con_rewind(struct vc_data *vc)
29252925

29262926
#define UCS_ZWS 0x200b /* Zero Width Space */
29272927
#define UCS_VS16 0xfe0f /* Variation Selector 16 */
2928+
#define UCS_REPLACEMENT 0xfffd /* Replacement Character */
29282929

29292930
static int vc_process_ucs(struct vc_data *vc, int *c, int *tc)
29302931
{
@@ -2984,12 +2985,38 @@ static int vc_process_ucs(struct vc_data *vc, int *c, int *tc)
29842985
return 0;
29852986
}
29862987

2988+
static int vc_get_glyph(struct vc_data *vc, int tc)
2989+
{
2990+
int glyph = conv_uni_to_pc(vc, tc);
2991+
u16 charmask = vc->vc_hi_font_mask ? 0x1ff : 0xff;
2992+
2993+
if (!(glyph & ~charmask))
2994+
return glyph;
2995+
2996+
if (glyph == -1)
2997+
return -1; /* nothing to display */
2998+
2999+
/* Glyph not found */
3000+
if ((!vc->vc_utf || vc->vc_disp_ctrl || tc < 128) && !(tc & ~charmask)) {
3001+
/*
3002+
* In legacy mode use the glyph we get by a 1:1 mapping.
3003+
* This would make absolutely no sense with Unicode in mind, but do this for
3004+
* ASCII characters since a font may lack Unicode mapping info and we don't
3005+
* want to end up with having question marks only.
3006+
*/
3007+
return tc;
3008+
}
3009+
3010+
/* Display U+FFFD (Unicode Replacement Character). */
3011+
return conv_uni_to_pc(vc, UCS_REPLACEMENT);
3012+
}
3013+
29873014
static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
29883015
struct vc_draw_region *draw)
29893016
{
29903017
int next_c;
29913018
unsigned char vc_attr = vc->vc_attr;
2992-
u16 himask = vc->vc_hi_font_mask, charmask = himask ? 0x1ff : 0xff;
3019+
u16 himask = vc->vc_hi_font_mask;
29933020
u8 width = 1;
29943021
bool inverse = false;
29953022

@@ -3000,39 +3027,17 @@ static int vc_con_write_normal(struct vc_data *vc, int tc, int c,
30003027
}
30013028

30023029
/* Now try to find out how to display it */
3003-
tc = conv_uni_to_pc(vc, tc);
3004-
if (tc & ~charmask) {
3005-
if (tc == -1)
3006-
return -1; /* nothing to display */
3030+
tc = vc_get_glyph(vc, tc);
3031+
if (tc == -1)
3032+
return -1; /* nothing to display */
3033+
if (tc < 0) {
3034+
inverse = true;
3035+
tc = conv_uni_to_pc(vc, '?');
3036+
if (tc < 0)
3037+
tc = '?';
30073038

3008-
/* Glyph not found */
3009-
if ((!vc->vc_utf || vc->vc_disp_ctrl || c < 128) &&
3010-
!(c & ~charmask)) {
3011-
/*
3012-
* In legacy mode use the glyph we get by a 1:1
3013-
* mapping.
3014-
* This would make absolutely no sense with Unicode in
3015-
* mind, but do this for ASCII characters since a font
3016-
* may lack Unicode mapping info and we don't want to
3017-
* end up with having question marks only.
3018-
*/
3019-
tc = c;
3020-
} else {
3021-
/*
3022-
* Display U+FFFD. If it's not found, display an inverse
3023-
* question mark.
3024-
*/
3025-
tc = conv_uni_to_pc(vc, 0xfffd);
3026-
if (tc < 0) {
3027-
inverse = true;
3028-
tc = conv_uni_to_pc(vc, '?');
3029-
if (tc < 0)
3030-
tc = '?';
3031-
3032-
vc_attr = vc_invert_attr(vc);
3033-
con_flush(vc, draw);
3034-
}
3035-
}
3039+
vc_attr = vc_invert_attr(vc);
3040+
con_flush(vc, draw);
30363041
}
30373042

30383043
next_c = c;

0 commit comments

Comments
 (0)