Skip to content

Commit e5bf2ba

Browse files
tonpervathpela
authored andcommitted
Use ASCII as fallback if Unicode Box Drawing characters fail
Many ASRock boards will not render MokManager correctly if the Unicode Box Drawing characters are used. Signed-off-by: Tony Persson <tony@tonypersson.se>
1 parent b437584 commit e5bf2ba

File tree

1 file changed

+39
-8
lines changed

1 file changed

+39
-8
lines changed

lib/console.c

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,30 @@ console_print_at(UINTN col, UINTN row, const CHAR16 *fmt, ...)
122122
return ret;
123123
}
124124

125+
static struct {
126+
CHAR16 up_left;
127+
CHAR16 up_right;
128+
CHAR16 down_left;
129+
CHAR16 down_right;
130+
CHAR16 horizontal;
131+
CHAR16 vertical;
132+
} boxdraw[2] = {
133+
{
134+
BOXDRAW_UP_LEFT,
135+
BOXDRAW_UP_RIGHT,
136+
BOXDRAW_DOWN_LEFT,
137+
BOXDRAW_DOWN_RIGHT,
138+
BOXDRAW_HORIZONTAL,
139+
BOXDRAW_VERTICAL
140+
}, {
141+
'+',
142+
'+',
143+
'+',
144+
'+',
145+
'-',
146+
'|'
147+
}
148+
};
125149

126150
void
127151
console_print_box_at(CHAR16 *str_arr[], int highlight,
@@ -133,6 +157,7 @@ console_print_box_at(CHAR16 *str_arr[], int highlight,
133157
SIMPLE_TEXT_OUTPUT_INTERFACE *co = ST->ConOut;
134158
UINTN rows, cols;
135159
CHAR16 *Line;
160+
bool char_set;
136161

137162
if (lines == 0)
138163
return;
@@ -181,10 +206,16 @@ console_print_box_at(CHAR16 *str_arr[], int highlight,
181206
return;
182207
}
183208

184-
SetMem16 (Line, size_cols * 2, BOXDRAW_HORIZONTAL);
209+
/* test if boxdraw characters work */
210+
co->SetCursorPosition(co, start_col, start_row);
211+
Line[0] = boxdraw[0].up_left;
212+
Line[1] = L'\0';
213+
char_set = co->OutputString(co, Line) == 0 ? 0 : 1;
214+
215+
SetMem16 (Line, size_cols * 2, boxdraw[char_set].horizontal);
185216

186-
Line[0] = BOXDRAW_DOWN_RIGHT;
187-
Line[size_cols - 1] = BOXDRAW_DOWN_LEFT;
217+
Line[0] = boxdraw[char_set].down_right;
218+
Line[size_cols - 1] = boxdraw[char_set].down_left;
188219
Line[size_cols] = L'\0';
189220
co->SetCursorPosition(co, start_col, start_row);
190221
co->OutputString(co, Line);
@@ -204,8 +235,8 @@ console_print_box_at(CHAR16 *str_arr[], int highlight,
204235
int line = i - start;
205236

206237
SetMem16 (Line, size_cols*2, L' ');
207-
Line[0] = BOXDRAW_VERTICAL;
208-
Line[size_cols - 1] = BOXDRAW_VERTICAL;
238+
Line[0] = boxdraw[char_set].vertical;
239+
Line[size_cols - 1] = boxdraw[char_set].vertical;
209240
Line[size_cols] = L'\0';
210241
if (line >= 0 && line < lines) {
211242
CHAR16 *s = str_arr[line];
@@ -227,9 +258,9 @@ console_print_box_at(CHAR16 *str_arr[], int highlight,
227258
EFI_BACKGROUND_BLUE);
228259

229260
}
230-
SetMem16 (Line, size_cols * 2, BOXDRAW_HORIZONTAL);
231-
Line[0] = BOXDRAW_UP_RIGHT;
232-
Line[size_cols - 1] = BOXDRAW_UP_LEFT;
261+
SetMem16 (Line, size_cols * 2, boxdraw[char_set].horizontal);
262+
Line[0] = boxdraw[char_set].up_right;
263+
Line[size_cols - 1] = boxdraw[char_set].up_left;
233264
Line[size_cols] = L'\0';
234265
co->SetCursorPosition(co, start_col, i);
235266
co->OutputString(co, Line);

0 commit comments

Comments
 (0)