Re: SIMPLE_FONT package in OptionROM code
Konstantin Aladyshev
Hi Felix!
toggle quoted message
Show quoted text
Thanks for the response! I was able to solve my problem using the `GetGlyph` function from the `gEfiHiiFontProtocolGuid` protocol. This function can return a `Blt` of the glyph. Here is the example app that I've used to test how 'T' glyph is displayed on different UEFI firmwares: ```cpp EFI_STATUS EFIAPI UefiMain ( IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable ) { EFI_HII_FONT_PROTOCOL *gHiiFont = NULL; EFI_STATUS Status = gBS->LocateProtocol(&gEfiHiiFontProtocolGuid, NULL, (VOID **)&gHiiFont); if (EFI_ERROR(Status)) { Print(L"Error! Can't get gEfiHiiFontProtocolGuid\n"); return Status; } EFI_IMAGE_OUTPUT* Blt = NULL; UINTN Baseline; Status = gHiiFont->GetGlyph(gHiiFont, L'T', NULL, &Blt, &Baseline); if (EFI_ERROR(Status)) { Print(L"Error! GetGlyph returned %r\n", Status); return Status; } for (UINT8 i = 0; i < (Blt->Height); i++) { for (UINT8 j = 0; j < (Blt->Width); j++) { Print(L"%02x", Blt->Image.Bitmap[i*(Blt->Width) + j].Blue); Print(L"%02x", Blt->Image.Bitmap[i*(Blt->Width) + j].Green); Print(L"%02x", Blt->Image.Bitmap[i*(Blt->Width) + j].Red); Print(L" "); } Print(L"\n"); } return EFI_SUCCESS; } ``` This output either something like ``` 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 989898 989898 989898 989898 989898 989898 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 989898 989898 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 ``` or ``` 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 989898 989898 989898 989898 989898 989898 989898 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 989898 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 000000 ``` Therefore `IsBoldFont` function can be written like this: ```cpp BOOLEAN IsBoldFont() { EFI_HII_FONT_PROTOCOL *gHiiFont = NULL; EFI_STATUS Status = gBS->LocateProtocol(&gEfiHiiFontProtocolGuid, NULL, (VOID **)&gHiiFont); if (EFI_ERROR(Status)) { return FALSE; } EFI_IMAGE_OUTPUT* Blt = NULL; UINTN Baseline; Status = gHiiFont->GetGlyph(gHiiFont, L'T', NULL, &Blt, &Baseline); if (EFI_ERROR(Status)) { return FALSE; } UINTN Pixels = 0; for (UINT8 i = 0; i < (Blt->Width); i++) { if ((Blt->Image.Bitmap[10*(Blt->Width) + i].Blue != 0x00) || (Blt->Image.Bitmap[10*(Blt->Width) + i].Green != 0x00) || (Blt->Image.Bitmap[10*(Blt->Width) + i].Red != 0x00)) { Pixels++; } } if (Pixels > 1) { return TRUE; } return FALSE; } ``` Based on its output I populate either bold or standard font. _________________________ Conclusion: I understand that all of this is probably not an UEFI way. Doing things the right way I just need to supply strings in `UNI` in english and my local language, and hope for the local language support in the firmware. But what's fun about that?) Maybe I'll fallback to this, but right now I've tested my solution and it performs well on all available to me motherboards. On Wed, Jan 25, 2023 at 2:38 AM Felix Polyudov <Felixp@...> wrote:
There is no standard way to query platform glyph styles. |
|