Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

173 lines
4.8 KiB

  1. /*++
  2. Copyright (c) 1998 Intel Corporation
  3. Module Name:
  4. BoxDraw.c
  5. Abstract:
  6. Lib functions to support Box Draw Unicode code pages.
  7. Revision History
  8. --*/
  9. #include "lib.h"
  10. typedef struct {
  11. CHAR16 Unicode;
  12. CHAR8 PcAnsi;
  13. CHAR8 Ascii;
  14. } UNICODE_TO_CHAR;
  15. /*
  16. * This list is used to define the valid extend chars.
  17. * It also provides a mapping from Unicode to PCANSI or
  18. * ASCII. The ASCII mapping we just made up.
  19. *
  20. */
  21. STATIC UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
  22. BOXDRAW_HORIZONTAL, 0xc4, L'-',
  23. BOXDRAW_VERTICAL, 0xb3, L'|',
  24. BOXDRAW_DOWN_RIGHT, 0xda, L'/',
  25. BOXDRAW_DOWN_LEFT, 0xbf, L'\\',
  26. BOXDRAW_UP_RIGHT, 0xc0, L'\\',
  27. BOXDRAW_UP_LEFT, 0xd9, L'/',
  28. BOXDRAW_VERTICAL_RIGHT, 0xc3, L'|',
  29. BOXDRAW_VERTICAL_LEFT, 0xb4, L'|',
  30. BOXDRAW_DOWN_HORIZONTAL, 0xc2, L'+',
  31. BOXDRAW_UP_HORIZONTAL, 0xc1, L'+',
  32. BOXDRAW_VERTICAL_HORIZONTAL, 0xc5, L'+',
  33. BOXDRAW_DOUBLE_HORIZONTAL, 0xcd, L'-',
  34. BOXDRAW_DOUBLE_VERTICAL, 0xba, L'|',
  35. BOXDRAW_DOWN_RIGHT_DOUBLE, 0xd5, L'/',
  36. BOXDRAW_DOWN_DOUBLE_RIGHT, 0xd6, L'/',
  37. BOXDRAW_DOUBLE_DOWN_RIGHT, 0xc9, L'/',
  38. BOXDRAW_DOWN_LEFT_DOUBLE, 0xb8, L'\\',
  39. BOXDRAW_DOWN_DOUBLE_LEFT, 0xb7, L'\\',
  40. BOXDRAW_DOUBLE_DOWN_LEFT, 0xbb, L'\\',
  41. BOXDRAW_UP_RIGHT_DOUBLE, 0xd4, L'\\',
  42. BOXDRAW_UP_DOUBLE_RIGHT, 0xd3, L'\\',
  43. BOXDRAW_DOUBLE_UP_RIGHT, 0xc8, L'\\',
  44. BOXDRAW_UP_LEFT_DOUBLE, 0xbe, L'/',
  45. BOXDRAW_UP_DOUBLE_LEFT, 0xbd, L'/',
  46. BOXDRAW_DOUBLE_UP_LEFT, 0xbc, L'/',
  47. BOXDRAW_VERTICAL_RIGHT_DOUBLE, 0xc6, L'|',
  48. BOXDRAW_VERTICAL_DOUBLE_RIGHT, 0xc7, L'|',
  49. BOXDRAW_DOUBLE_VERTICAL_RIGHT, 0xcc, L'|',
  50. BOXDRAW_VERTICAL_LEFT_DOUBLE, 0xb5, L'|',
  51. BOXDRAW_VERTICAL_DOUBLE_LEFT, 0xb6, L'|',
  52. BOXDRAW_DOUBLE_VERTICAL_LEFT, 0xb9, L'|',
  53. BOXDRAW_DOWN_HORIZONTAL_DOUBLE, 0xd1, L'+',
  54. BOXDRAW_DOWN_DOUBLE_HORIZONTAL, 0xd2, L'+',
  55. BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+',
  56. BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+',
  57. BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+',
  58. BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+',
  59. BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+',
  60. BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+',
  61. BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+',
  62. BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*',
  63. BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+',
  64. GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^',
  65. GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>',
  66. GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v',
  67. GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<',
  68. /* BugBug: Left Arrow is an ESC. We can not make it print
  69. on a PCANSI terminal. If we can make left arrow
  70. come out on PC ANSI we can add it back.
  71. ARROW_LEFT, 0x1b, L'<',
  72. */
  73. ARROW_UP, 0x18, L'^',
  74. /* BugBut: Took out left arrow so right has to go too.
  75. ARROW_RIGHT, 0x1a, L'>',
  76. */
  77. ARROW_DOWN, 0x19, L'v',
  78. 0x0000, 0x00
  79. };
  80. BOOLEAN
  81. LibIsValidTextGraphics (
  82. IN CHAR16 Graphic,
  83. OUT CHAR8 *PcAnsi, OPTIONAL
  84. OUT CHAR8 *Ascii OPTIONAL
  85. )
  86. /*++
  87. Routine Description:
  88. Detects if a Unicode char is for Box Drawing text graphics.
  89. Arguments:
  90. Grphic - Unicode char to test.
  91. PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
  92. Asci - Optional pointer to return Ascii equivalent of Graphic.
  93. Returns:
  94. TRUE if Gpaphic is a supported Unicode Box Drawing character.
  95. --*/{
  96. UNICODE_TO_CHAR *Table;
  97. if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {
  98. /*
  99. * Unicode drawing code charts are all in the 0x25xx range,
  100. * arrows are 0x21xx
  101. */
  102. return FALSE;
  103. }
  104. for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {
  105. if (Graphic == Table->Unicode) {
  106. if (PcAnsi) {
  107. *PcAnsi = Table->PcAnsi;
  108. }
  109. if (Ascii) {
  110. *Ascii = Table->Ascii;
  111. }
  112. return TRUE;
  113. }
  114. }
  115. return FALSE;
  116. }
  117. BOOLEAN
  118. IsValidAscii (
  119. IN CHAR16 Ascii
  120. )
  121. {
  122. if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {
  123. return TRUE;
  124. }
  125. return FALSE;
  126. }
  127. BOOLEAN
  128. IsValidEfiCntlChar (
  129. IN CHAR16 c
  130. )
  131. {
  132. if (c == CHAR_NULL || c == CHAR_BACKSPACE || c == CHAR_LINEFEED || c == CHAR_CARRIAGE_RETURN) {
  133. return TRUE;
  134. }
  135. return FALSE;
  136. }