1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
|
/*++
Copyright (c) 2004, Intel Corporation
All rights reserved. This program and the accompanying materials
are licensed and made available under the terms and conditions of the BSD License
which accompanies this distribution. The full text of the license may be found at
http://opensource.org/licenses/bsd-license.php
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
Module Name:
BoxDraw.c
Abstract:
Lib functions to support Box Draw Unicode code pages.
Revision History
--*/
#include "Tiano.h"
#include "EfiDriverLib.h"
typedef struct {
CHAR16 Unicode;
CHAR8 PcAnsi;
CHAR8 Ascii;
} UNICODE_TO_CHAR;
//
// This list is used to define the valid extend chars.
// It also provides a mapping from Unicode to PCANSI or
// ASCII. The ASCII mapping we just made up.
//
//
static UNICODE_TO_CHAR UnicodeToPcAnsiOrAscii[] = {
{BOXDRAW_HORIZONTAL, 0xc4, L'-'},
{BOXDRAW_VERTICAL, 0xb3, L'|'},
{BOXDRAW_DOWN_RIGHT, 0xda, L'/'},
{BOXDRAW_DOWN_LEFT, 0xbf, L'\\'},
{BOXDRAW_UP_RIGHT, 0xc0, L'\\'},
{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N_DOUBLE_HORIZONTAL, 0xd2, L'+'},
{BOXDRAW_DOUBLE_DOWN_HORIZONTAL, 0xcb, L'+'},
{BOXDRAW_UP_HORIZONTAL_DOUBLE, 0xcf, L'+'},
{BOXDRAW_UP_DOUBLE_HORIZONTAL, 0xd0, L'+'},
{BOXDRAW_DOUBLE_UP_HORIZONTAL, 0xca, L'+'},
{BOXDRAW_VERTICAL_HORIZONTAL_DOUBLE, 0xd8, L'+'},
{BOXDRAW_VERTICAL_DOUBLE_HORIZONTAL, 0xd7, L'+'},
{BOXDRAW_DOUBLE_VERTICAL_HORIZONTAL, 0xce, L'+'},
{BLOCKELEMENT_FULL_BLOCK, 0xdb, L'*'},
{BLOCKELEMENT_LIGHT_SHADE, 0xb0, L'+'},
{GEOMETRICSHAPE_UP_TRIANGLE, 0x1e, L'^'},
{GEOMETRICSHAPE_RIGHT_TRIANGLE, 0x10, L'>'},
{GEOMETRICSHAPE_DOWN_TRIANGLE, 0x1f, L'v'},
{GEOMETRICSHAPE_LEFT_TRIANGLE, 0x11, L'<'},
{ARROW_LEFT, 0x3c, L'<'},
{ARROW_UP, 0x18, L'^'},
{ARROW_RIGHT, 0x3e, L'>'},
{ARROW_DOWN, 0x19, L'v'},
{0x0000, 0x00, L'\0'},
};
BOOLEAN
LibIsValidTextGraphics (
IN CHAR16 Graphic,
OUT CHAR8 *PcAnsi, OPTIONAL
OUT CHAR8 *Ascii OPTIONAL
)
/*++
Routine Description:
Detects if a Unicode char is for Box Drawing text graphics.
Arguments:
Grphic - Unicode char to test.
PcAnsi - Optional pointer to return PCANSI equivalent of Graphic.
Asci - Optional pointer to return Ascii equivalent of Graphic.
Returns:
TRUE if Gpaphic is a supported Unicode Box Drawing character.
--*/
{
UNICODE_TO_CHAR *Table;
if ((((Graphic & 0xff00) != 0x2500) && ((Graphic & 0xff00) != 0x2100))) {
//
// Unicode drawing code charts are all in the 0x25xx range,
// arrows are 0x21xx
//
return FALSE;
}
for (Table = UnicodeToPcAnsiOrAscii; Table->Unicode != 0x0000; Table++) {
if (Graphic == Table->Unicode) {
if (PcAnsi != NULL) {
*PcAnsi = Table->PcAnsi;
}
if (Ascii != NULL) {
*Ascii = Table->Ascii;
}
return TRUE;
}
}
return FALSE;
}
BOOLEAN
IsValidAscii (
IN CHAR16 Ascii
)
/*++
Routine Description:
Is it valid ascii char?
Arguments:
Ascii - The char to check
Returns:
TRUE - Is a ascii char
FALSE - Not a ascii char
--*/
{
if ((Ascii >= 0x20) && (Ascii <= 0x7f)) {
return TRUE;
}
return FALSE;
}
BOOLEAN
IsValidEfiCntlChar (
IN CHAR16 CharC
)
/*++
Routine Description:
Is it valid EFI control char?
Arguments:
Ascii - The char to check
Returns:
TRUE - Is a valid EFI control char
FALSE - Not a valid EFI control char
--*/
{
if (CharC == CHAR_NULL || CharC == CHAR_BACKSPACE || CharC == CHAR_LINEFEED || CharC == CHAR_CARRIAGE_RETURN) {
return TRUE;
}
return FALSE;
}
|