Skip to content

Commit f764a27

Browse files
committed
Correct proportional font
1 parent 59314b6 commit f764a27

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

rEFIt_UEFI/libeg/XTheme.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ class XTheme
137137
//fonts
138138
void LoadFontImage(IN BOOLEAN UseEmbedded, IN INTN Rows, IN INTN Cols);
139139
void PrepareFont();
140-
INTN GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& FirstPixel, INTN Start, INTN Step);
140+
INTN GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& FirstPixel, INTN MaxWidth, INTN Start, INTN Step);
141141
INTN RenderText(IN const XStringW& Text, OUT XImage* CompImage_ptr,
142142
IN INTN PosX, IN INTN PosY, IN UINTN Cursor, INTN textType, float textScale = 0.f);
143143
//overload for UTF8 text

rEFIt_UEFI/libeg/text.cpp

+9-9
Original file line numberDiff line numberDiff line change
@@ -219,14 +219,14 @@ inline bool SamePix(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Ptr, const EFI_GRAPHICS
219219
//used for proportional fonts in raster themes
220220
//search empty column from begin Step=1 or from end Step=-1 in the input buffer
221221
// empty means similar to FirstPixel
222-
INTN XTheme::GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& FirstPixel, INTN Start, INTN Step)
222+
INTN XTheme::GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& FirstPixel, INTN MaxWidth, INTN Start, INTN Step)
223223
{
224224
INTN m, i;
225225
// INTN Shift = (Step > 0)?0:1;
226-
m = FontWidth;
226+
m = MaxWidth;
227227
if (Step == 1) {
228228
for (INTN j = 0; j < FontHeight; j++) {
229-
for (i = 0; i < FontWidth; i++) {
229+
for (i = 0; i < MaxWidth; i++) {
230230
if (!SamePix(Buffer.GetPixel(Start + i,j), FirstPixel)) { //found not empty pixel
231231
break;
232232
}
@@ -235,14 +235,14 @@ INTN XTheme::GetEmpty(const XImage& Buffer, const EFI_GRAPHICS_OUTPUT_BLT_PIXEL&
235235
if (m == 0) break;
236236
}
237237
} else { // go back
238-
m = 0;
239238
for (INTN j = 0; j < FontHeight; j++) {
240-
for (i = FontWidth - 1; i >= 0; --i) {
241-
if (!SamePix(Buffer.GetPixel(Start + i,j), FirstPixel)) { //found not empty pixel
239+
for (i = 1; i <= MaxWidth; i++) {
240+
if (!SamePix(Buffer.GetPixel(Start - i,j), FirstPixel)) { //found not empty pixel
242241
break;
243242
}
244243
}
245-
m = MAX(m, i); //for each line to find minimum
244+
m = MIN(m, i); //for each line to find minimum
245+
if (m == 0) break;
246246
}
247247
}
248248
return m;
@@ -319,13 +319,13 @@ INTN XTheme::RenderText(IN const XStringW& Text, OUT XImage* CompImage_ptr,
319319
if (c0 <= 0x20) { // space before or at buffer edge
320320
LeftSpace = 2;
321321
} else {
322-
LeftSpace = GetEmpty(CompImage, FirstPixel, PosX, -1);
322+
LeftSpace = GetEmpty(CompImage, FirstPixel, RealWidth, PosX, -1);
323323
}
324324
if (c <= 0x20) { //new space will be half font width
325325
RightSpace = 1;
326326
RealWidth = (CharScaledWidth >> 1) + 1;
327327
} else {
328-
RightSpace = GetEmpty(FontImage, FontPixel, c * FontWidth, 1); //not scaled yet
328+
RightSpace = GetEmpty(FontImage, FontPixel, FontWidth, c * FontWidth, 1); //not scaled yet
329329
if (RightSpace >= FontWidth) {
330330
RightSpace = 0; //empty place for invisible characters
331331
}

0 commit comments

Comments
 (0)