Skip to content

Commit

Permalink
rewrite render text
Browse files Browse the repository at this point in the history
Signed-off-by: Sergey Isakov <[email protected]>
  • Loading branch information
SergeySlice committed Mar 23, 2020
1 parent 8b8b845 commit a3f3053
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 8 deletions.
5 changes: 5 additions & 0 deletions rEFIt_UEFI/libeg/XImage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,11 @@ void XImage::Fill(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color)
PixelData[y * Width + x] = Color;
}

void XImage::Fill(const EG_PIXEL* Color)
{
Fill((const EFI_GRAPHICS_OUTPUT_BLT_PIXEL&)Color);
}


void XImage::FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect)
{
Expand Down
1 change: 1 addition & 0 deletions rEFIt_UEFI/libeg/XImage.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class XImage


void Fill(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color = { 0, 0, 0, 0 });
void Fill(const EG_PIXEL* Color);
void FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect);
void CopyScaled(const XImage& Image, float scale);
void Compose(INTN PosX, INTN PosY, const XImage& TopImage, bool Lowest); //instead of compose we often can Back.Draw(...) + Top.Draw(...)
Expand Down
1 change: 0 additions & 1 deletion rEFIt_UEFI/libeg/libeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,6 @@ VOID egFillImageArea(IN OUT EG_IMAGE *CompImage,
VOID egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN INTN PosX, IN INTN PosY);
VOID PrepareFont(VOID);
VOID egMeasureText(IN CONST CHAR16 *Text, OUT INTN *Width, OUT INTN *Height);
INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType);

VOID egClearScreen(IN EG_PIXEL *Color);
//VOID egDrawImage(IN EG_IMAGE *Image, IN INTN ScreenPosX, IN INTN ScreenPosY);
Expand Down
4 changes: 3 additions & 1 deletion rEFIt_UEFI/libeg/libegint.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,12 +183,14 @@ EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN BOOLEAN W

#if USE_XTHEME
INTN renderSVGtext(XImage& TextBufferXY, INTN posX, INTN posY, INTN textType, XStringW string, UINTN Cursor);
INTN egRenderText(IN XStringW& Text, IN XImage& CompImage,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType);
#else
INTN renderSVGtext(EG_IMAGE* TextBufferXY, INTN posX, INTN posY, INTN textType, CONST CHAR16* text, UINTN Cursor);
INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage, IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType);
#endif



#endif /* __LIBEG_LIBEGINT_H__ */

/* EOF */
21 changes: 18 additions & 3 deletions rEFIt_UEFI/libeg/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,13 @@ INTN GetEmpty(EG_PIXEL *Ptr, EG_PIXEL *FirstPixel, INTN MaxWidth, INTN Step, INT
return m;
}

#if USE_XTHEME
INTN egRenderText(IN XStringW& Text, IN XImage& CompImage,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType)
#else
INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType)
#endif
{
EG_PIXEL *BufferPtr;
EG_PIXEL *FontPixelData;
Expand All @@ -276,14 +281,15 @@ INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
UINTN Cho = 0, Jong = 0, Joong = 0;
UINTN LeftSpace, RightSpace;
INTN RealWidth = 0;
INTN ScaledWidth = (INTN)(GlobalConfig.CharWidth * GlobalConfig.Scale);


#if USE_XTHEME
INTN ScaledWidth = (INTN)(ThemeX.CharWidth * ThemeX.Scale);
if (ThemeX.TypeSVG) {
XImage TextImage(CompImage);
return renderSVGtext(TextImage, PosX, PosY, textType, XStringW().takeValueFrom(Text), Cursor);
return renderSVGtext(CompImage, PosX, PosY, textType, Text, Cursor);
}
#else
INTN ScaledWidth = (INTN)(GlobalConfig.CharWidth * GlobalConfig.Scale);
if (GlobalConfig.TypeSVG) {
return renderSVGtext(CompImage, PosX, PosY, textType, Text, Cursor);
}
Expand All @@ -299,8 +305,13 @@ INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,

// DBG("TextLength =%d PosX=%d PosY=%d\n", TextLength, PosX, PosY);
// render it
#if USE_XTHEME
BufferPtr = (EG_PIXEL*)CompImage.GetPixelPtr(0,0);
BufferLineOffset = CompImage.GetWidth();
#else
BufferPtr = CompImage->PixelData;
BufferLineOffset = CompImage->Width;
#endif
BufferLineWidth = BufferLineOffset - PosX; // remove indent from drawing width
BufferPtr += PosX + PosY * BufferLineOffset;
FirstPixelBuf = BufferPtr;
Expand All @@ -315,7 +326,11 @@ INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
RealWidth = ScaledWidth;
// DBG("FontWidth=%d, CharWidth=%d\n", FontWidth, RealWidth);
for (i = 0; i < TextLength; i++) {
#if USE_XTHEME
c = Text.data()[i];
#else
c = Text[i];
#endif
if (gLanguage != korean) {
c1 = (((c >= GlobalConfig.Codepage) ? (c - (GlobalConfig.Codepage - AsciiPageSize)) : c) & 0xff); //International letters
c = c1;
Expand Down
5 changes: 5 additions & 0 deletions rEFIt_UEFI/refit/icns.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,8 +279,13 @@ EG_IMAGE * BuiltinIcon(IN UINTN Id)
// icon name is shutdown from historic reasons, but function is now exit
UnicodeSPrint(Text, 30, L"exit");
}
#if USE_XTHEME
#else
egRenderText(Text, TextBuffer, 0, 0, 0xFFFF, 1);
BuiltinIconTable[Id].Image = TextBuffer;
#endif


DebugLog(1, " [!] Icon %d: Text <%s> rendered\n", Id, Text);
FreePool(Text);
}
Expand Down
90 changes: 87 additions & 3 deletions rEFIt_UEFI/refit/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ INTN OldChosenDsdt;
UINTN OldChosenAudio;
UINT8 DefaultAudioVolume = 70;
//INTN NewChosenTheme;
INTN TextStyle;
INTN TextStyle; //why global?

BOOLEAN mGuiReady = FALSE;

Expand Down Expand Up @@ -2507,7 +2507,27 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INT
} else {
TextStyle = 2;
}

#if USE_XTHEME
if (ThemeX.TypeSVG) {
if (!textFace[TextStyle].valid) {
if (textFace[0].valid) {
TextStyle = 0;
} else if (textFace[2].valid) {
TextStyle = 2;
} else if (textFace[1].valid) {
TextStyle = 1;
} else {
DBG("no valid text style\n");
textFace[TextStyle].size = TextHeight - 4;
}
}
if (textFace[TextStyle].valid) {
// TextHeight = (int)((textFace[TextStyle].size + 4) * GlobalConfig.Scale);
//clovy - row height / text size factor
TextHeight = (int)((textFace[TextStyle].size * RowHeightFromTextHeight) * ThemeX.Scale);
}
}
#else
if (GlobalConfig.TypeSVG) {
if (!textFace[TextStyle].valid) {
if (textFace[0].valid) {
Expand All @@ -2527,6 +2547,7 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INT
TextHeight = (int)((textFace[TextStyle].size * RowHeightFromTextHeight) * GlobalConfig.Scale);
}
}
#endif

//no default - no timeout!
if ((*DefaultEntryIndex != -1) && (TimeoutSeconds > 0)) {
Expand Down Expand Up @@ -3079,6 +3100,69 @@ VOID REFIT_MENU_SCREEN::TextMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT
/**
* Draw text with specific coordinates.
*/


#if USE_XTHEME
INTN DrawTextXY(IN XStringW& Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign)
{
INTN TextWidth = 0;
INTN XText = 0;
INTN Height;
INTN TextXYStyle = 1;
// EG_IMAGE *TextBufferXY = NULL;
XImage TextBufferXY(0,0);

if (Text.isEmpty()) {
return 0;
}
if (!textFace[1].valid) {
if (textFace[2].valid) {
TextXYStyle = 2;
} else {
TextXYStyle = 0;
}
}

egMeasureText(Text.data(), &TextWidth, NULL);

if (XAlign == X_IS_LEFT) {
TextWidth = UGAWidth - XPos - 1;
XText = XPos;
}

if (ThemeX.TypeSVG) {
TextWidth += TextHeight * 2; //give more place for buffer
if (!textFace[TextXYStyle].valid) {
DBG("no vaid text face for message!\n");
Height = TextHeight;
} else {
Height = (int)(textFace[TextXYStyle].size * RowHeightFromTextHeight * ThemeX.Scale);
}
} else {
Height = TextHeight;
}

// TextBufferXY = egCreateFilledImage(TextWidth, Height, TRUE, &MenuBackgroundPixel);
TextBufferXY.setSizeInPixels(TextWidth, Height);
TextBufferXY.Fill(&MenuBackgroundPixel);

// render the text
TextWidth = egRenderText(Text, TextBufferXY, 0, 0, 0xFFFF, TextXYStyle);

if (XAlign != X_IS_LEFT) {
// shift 64 is prohibited
XText = XPos - (TextWidth >> XAlign); //X_IS_CENTER = 1
}
// DBG("draw text %s\n", Text);
// DBG("pos=%d width=%d xtext=%d Height=%d Y=%d\n", XPos, TextWidth, XText, Height, YPos);
// BltImageAlpha(TextBufferXY, XText, YPos, &MenuBackgroundPixel, 16);
// egFreeImage(TextBufferXY);
TextBufferXY.Draw(XText, YPos, 1.f);
return TextWidth;
}
#else


INTN DrawTextXY(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign)
{
INTN TextWidth = 0;
Expand Down Expand Up @@ -3133,7 +3217,7 @@ INTN DrawTextXY(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAli

return TextWidth;
}

#endif
/**
* Helper function to draw text for Boot Camp Style.
* @author: Needy
Expand Down

0 comments on commit a3f3053

Please sign in to comment.