rewrite render text

Signed-off-by: Sergey Isakov <isakov-sl@bk.ru>
This commit is contained in:
Sergey Isakov 2020-03-23 22:10:16 +03:00
parent 8b8b8452b6
commit a3f3053c30
7 changed files with 119 additions and 8 deletions

View File

@ -204,6 +204,11 @@ void XImage::Fill(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color)
PixelData[y * Width + x] = 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) void XImage::FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect)
{ {

View File

@ -80,6 +80,7 @@ public:
void Fill(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color = { 0, 0, 0, 0 }); 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 FillArea(const EFI_GRAPHICS_OUTPUT_BLT_PIXEL& Color, EG_RECT& Rect);
void CopyScaled(const XImage& Image, float scale); 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(...) void Compose(INTN PosX, INTN PosY, const XImage& TopImage, bool Lowest); //instead of compose we often can Back.Draw(...) + Top.Draw(...)

View File

@ -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 egComposeImage(IN OUT EG_IMAGE *CompImage, IN EG_IMAGE *TopImage, IN INTN PosX, IN INTN PosY);
VOID PrepareFont(VOID); VOID PrepareFont(VOID);
VOID egMeasureText(IN CONST CHAR16 *Text, OUT INTN *Width, OUT INTN *Height); 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 egClearScreen(IN EG_PIXEL *Color);
//VOID egDrawImage(IN EG_IMAGE *Image, IN INTN ScreenPosX, IN INTN ScreenPosY); //VOID egDrawImage(IN EG_IMAGE *Image, IN INTN ScreenPosX, IN INTN ScreenPosY);

View File

@ -183,12 +183,14 @@ EG_IMAGE * egDecodePNG(IN UINT8 *FileData, IN UINTN FileDataLength, IN BOOLEAN W
#if USE_XTHEME #if USE_XTHEME
INTN renderSVGtext(XImage& TextBufferXY, INTN posX, INTN posY, INTN textType, XStringW string, UINTN Cursor); 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 #else
INTN renderSVGtext(EG_IMAGE* TextBufferXY, INTN posX, INTN posY, INTN textType, CONST CHAR16* text, UINTN Cursor); 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
#endif /* __LIBEG_LIBEGINT_H__ */ #endif /* __LIBEG_LIBEGINT_H__ */
/* EOF */ /* EOF */

View File

@ -262,8 +262,13 @@ INTN GetEmpty(EG_PIXEL *Ptr, EG_PIXEL *FirstPixel, INTN MaxWidth, INTN Step, INT
return m; 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, INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType) IN INTN PosX, IN INTN PosY, IN INTN Cursor, INTN textType)
#endif
{ {
EG_PIXEL *BufferPtr; EG_PIXEL *BufferPtr;
EG_PIXEL *FontPixelData; EG_PIXEL *FontPixelData;
@ -276,14 +281,15 @@ INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
UINTN Cho = 0, Jong = 0, Joong = 0; UINTN Cho = 0, Jong = 0, Joong = 0;
UINTN LeftSpace, RightSpace; UINTN LeftSpace, RightSpace;
INTN RealWidth = 0; INTN RealWidth = 0;
INTN ScaledWidth = (INTN)(GlobalConfig.CharWidth * GlobalConfig.Scale);
#if USE_XTHEME #if USE_XTHEME
INTN ScaledWidth = (INTN)(ThemeX.CharWidth * ThemeX.Scale);
if (ThemeX.TypeSVG) { if (ThemeX.TypeSVG) {
XImage TextImage(CompImage); return renderSVGtext(CompImage, PosX, PosY, textType, Text, Cursor);
return renderSVGtext(TextImage, PosX, PosY, textType, XStringW().takeValueFrom(Text), Cursor);
} }
#else #else
INTN ScaledWidth = (INTN)(GlobalConfig.CharWidth * GlobalConfig.Scale);
if (GlobalConfig.TypeSVG) { if (GlobalConfig.TypeSVG) {
return renderSVGtext(CompImage, PosX, PosY, textType, Text, Cursor); return renderSVGtext(CompImage, PosX, PosY, textType, Text, Cursor);
} }
@ -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); // DBG("TextLength =%d PosX=%d PosY=%d\n", TextLength, PosX, PosY);
// render it // render it
#if USE_XTHEME
BufferPtr = (EG_PIXEL*)CompImage.GetPixelPtr(0,0);
BufferLineOffset = CompImage.GetWidth();
#else
BufferPtr = CompImage->PixelData; BufferPtr = CompImage->PixelData;
BufferLineOffset = CompImage->Width; BufferLineOffset = CompImage->Width;
#endif
BufferLineWidth = BufferLineOffset - PosX; // remove indent from drawing width BufferLineWidth = BufferLineOffset - PosX; // remove indent from drawing width
BufferPtr += PosX + PosY * BufferLineOffset; BufferPtr += PosX + PosY * BufferLineOffset;
FirstPixelBuf = BufferPtr; FirstPixelBuf = BufferPtr;
@ -315,7 +326,11 @@ INTN egRenderText(IN CONST CHAR16 *Text, IN OUT EG_IMAGE *CompImage,
RealWidth = ScaledWidth; RealWidth = ScaledWidth;
// DBG("FontWidth=%d, CharWidth=%d\n", FontWidth, RealWidth); // DBG("FontWidth=%d, CharWidth=%d\n", FontWidth, RealWidth);
for (i = 0; i < TextLength; i++) { for (i = 0; i < TextLength; i++) {
#if USE_XTHEME
c = Text.data()[i];
#else
c = Text[i]; c = Text[i];
#endif
if (gLanguage != korean) { if (gLanguage != korean) {
c1 = (((c >= GlobalConfig.Codepage) ? (c - (GlobalConfig.Codepage - AsciiPageSize)) : c) & 0xff); //International letters c1 = (((c >= GlobalConfig.Codepage) ? (c - (GlobalConfig.Codepage - AsciiPageSize)) : c) & 0xff); //International letters
c = c1; c = c1;

View File

@ -279,8 +279,13 @@ EG_IMAGE * BuiltinIcon(IN UINTN Id)
// icon name is shutdown from historic reasons, but function is now exit // icon name is shutdown from historic reasons, but function is now exit
UnicodeSPrint(Text, 30, L"exit"); UnicodeSPrint(Text, 30, L"exit");
} }
#if USE_XTHEME
#else
egRenderText(Text, TextBuffer, 0, 0, 0xFFFF, 1); egRenderText(Text, TextBuffer, 0, 0, 0xFFFF, 1);
BuiltinIconTable[Id].Image = TextBuffer; BuiltinIconTable[Id].Image = TextBuffer;
#endif
DebugLog(1, " [!] Icon %d: Text <%s> rendered\n", Id, Text); DebugLog(1, " [!] Icon %d: Text <%s> rendered\n", Id, Text);
FreePool(Text); FreePool(Text);
} }

View File

@ -204,7 +204,7 @@ INTN OldChosenDsdt;
UINTN OldChosenAudio; UINTN OldChosenAudio;
UINT8 DefaultAudioVolume = 70; UINT8 DefaultAudioVolume = 70;
//INTN NewChosenTheme; //INTN NewChosenTheme;
INTN TextStyle; INTN TextStyle; //why global?
BOOLEAN mGuiReady = FALSE; BOOLEAN mGuiReady = FALSE;
@ -2507,7 +2507,27 @@ UINTN REFIT_MENU_SCREEN::RunGenericMenu(IN MENU_STYLE_FUNC StyleFunc, IN OUT INT
} else { } else {
TextStyle = 2; 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 (GlobalConfig.TypeSVG) {
if (!textFace[TextStyle].valid) { if (!textFace[TextStyle].valid) {
if (textFace[0].valid) { if (textFace[0].valid) {
@ -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); TextHeight = (int)((textFace[TextStyle].size * RowHeightFromTextHeight) * GlobalConfig.Scale);
} }
} }
#endif
//no default - no timeout! //no default - no timeout!
if ((*DefaultEntryIndex != -1) && (TimeoutSeconds > 0)) { if ((*DefaultEntryIndex != -1) && (TimeoutSeconds > 0)) {
@ -3079,6 +3100,69 @@ VOID REFIT_MENU_SCREEN::TextMenuStyle(IN UINTN Function, IN CONST CHAR16 *ParamT
/** /**
* Draw text with specific coordinates. * 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 DrawTextXY(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAlign)
{ {
INTN TextWidth = 0; INTN TextWidth = 0;
@ -3133,7 +3217,7 @@ INTN DrawTextXY(IN CONST CHAR16 *Text, IN INTN XPos, IN INTN YPos, IN UINT8 XAli
return TextWidth; return TextWidth;
} }
#endif
/** /**
* Helper function to draw text for Boot Camp Style. * Helper function to draw text for Boot Camp Style.
* @author: Needy * @author: Needy