MCPcopy Create free account
hub / github.com/NetHack/NetHack / curses_convert_glyph

Function curses_convert_glyph

win/curses/cursmisc.c:453–570  ·  view source on GitHub ↗

convert nethack's DECgraphics encoding into curses' ACS encoding */

Source from the content-addressed store, hash-verified

451
452/* convert nethack's DECgraphics encoding into curses' ACS encoding */
453int
454curses_convert_glyph(int ch, int glyph)
455{
456 /* The DEC line drawing characters use 0x5f through 0x7e instead
457 of the much more straightforward 0x60 through 0x7f, possibly
458 because 0x7f is effectively a control character (Rubout);
459 nethack ORs 0x80 to flag line drawing--that's stripped below */
460 static int decchars[33]; /* for chars 0x5f through 0x7f (95..127) */
461
462 ch &= 0xff; /* 0..255 only */
463 if (!(ch & 0x80))
464 return ch; /* no conversion needed */
465
466 /* this conversion routine is only called for SYMHANDLING(H_DEC) and
467 we decline to support special graphics symbols on the rogue level */
468 if (Is_rogue_level(&u.uz)) {
469 /* attempting to use line drawing characters will end up being
470 rendered as lowercase gibberish */
471 ch &= ~0x80;
472 return ch;
473 }
474
475 /*
476 * Curses has complete access to all characters that DECgraphics uses.
477 * However, their character value isn't consistent between terminals
478 * and implementations. For actual DEC terminals and faithful emulators,
479 * line-drawing characters are specified as lowercase letters (mostly)
480 * and a control code is sent to the terminal telling it to switch
481 * character sets (that's how the tty interface handles them).
482 * Curses remaps the characters instead.
483 */
484
485 /* one-time initialization; some ACS_x aren't compile-time constant */
486 if (!decchars[0]) {
487 /* [0] is non-breakable space; irrelevant to nethack */
488 decchars[0x5f - 0x5f] = ' '; /* NBSP */
489 decchars[0x60 - 0x5f] = ACS_DIAMOND; /* [1] solid diamond */
490 decchars[0x61 - 0x5f] = ACS_CKBOARD; /* [2] checkerboard */
491 /* several "line drawing" characters are two-letter glyphs
492 which could be substituted for invisible control codes;
493 nethack's DECgraphics doesn't use any of them so we're
494 satisfied with conversion to a simple letter;
495 [3] "HT" as one char, with small raised upper case H over
496 and/or preceding small lowered upper case T */
497 decchars[0x62 - 0x5f] = 'H'; /* "HT" (horizontal tab) */
498 decchars[0x63 - 0x5f] = 'F'; /* "FF" as one char (form feed) */
499 decchars[0x64 - 0x5f] = 'C'; /* "CR" as one (carriage return) */
500 decchars[0x65 - 0x5f] = 'L'; /* [6] "LF" as one (line feed) */
501 decchars[0x66 - 0x5f] = ACS_DEGREE; /* small raised circle */
502 /* [8] plus or minus sign, '+' with horizontal line below */
503 decchars[0x67 - 0x5f] = ACS_PLMINUS;
504 decchars[0x68 - 0x5f] = 'N'; /* [9] "NL" as one char (new line) */
505 decchars[0x69 - 0x5f] = 'V'; /* [10] "VT" as one (vertical tab) */
506 decchars[0x6a - 0x5f] = ACS_LRCORNER; /* lower right corner */
507 decchars[0x6b - 0x5f] = ACS_URCORNER; /* upper right corner, 7-ish */
508 decchars[0x6c - 0x5f] = ACS_ULCORNER; /* upper left corner */
509 decchars[0x6d - 0x5f] = ACS_LLCORNER; /* lower left corner, 'L' */
510 /* [15] center cross, like big '+' sign */

Callers 1

curses_print_glyphFunction · 0.85

Calls 1

glyph_to_cmapFunction · 0.85

Tested by

no test coverage detected