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