From e621f88d259b8871ea62d2a7753d7475352cb774 Mon Sep 17 00:00:00 2001 From: Konstantin Aladyshev Date: Tue, 9 Nov 2021 13:01:09 +0300 Subject: Add lesson 53 Signed-off-by: Konstantin Aladyshev --- .../HIIAddRussianFont/HIIAddRussianFont.c | 93 ++++++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 UefiLessonsPkg/HIIAddRussianFont/HIIAddRussianFont.c (limited to 'UefiLessonsPkg/HIIAddRussianFont/HIIAddRussianFont.c') diff --git a/UefiLessonsPkg/HIIAddRussianFont/HIIAddRussianFont.c b/UefiLessonsPkg/HIIAddRussianFont/HIIAddRussianFont.c new file mode 100644 index 0000000..6ddab88 --- /dev/null +++ b/UefiLessonsPkg/HIIAddRussianFont/HIIAddRussianFont.c @@ -0,0 +1,93 @@ +/* + * Copyright (c) 2021, Konstantin Aladyshev + * + * SPDX-License-Identifier: MIT + */ + +#include +#include + +#include +#include +#include + + +extern EFI_WIDE_GLYPH gSimpleFontWideGlyphData[]; +extern UINT32 gSimpleFontWideBytes; +extern EFI_NARROW_GLYPH gSimpleFontNarrowGlyphData[]; +extern UINT32 gSimpleFontNarrowBytes; + + +UINT8* CreateSimpleFontPkg(EFI_WIDE_GLYPH* WideGlyph, + UINT32 WideGlyphSizeInBytes, + EFI_NARROW_GLYPH* NarrowGlyph, + UINT32 NarrowGlyphSizeInBytes) +{ + UINT32 PackageLen = sizeof(EFI_HII_SIMPLE_FONT_PACKAGE_HDR) + WideGlyphSizeInBytes + NarrowGlyphSizeInBytes + 4; + UINT8* FontPackage = (UINT8*)AllocateZeroPool (PackageLen); + *(UINT32*)FontPackage = PackageLen; + + EFI_HII_SIMPLE_FONT_PACKAGE_HDR *SimpleFont; + SimpleFont = (EFI_HII_SIMPLE_FONT_PACKAGE_HDR*)(FontPackage + 4); + SimpleFont->Header.Length = (UINT32)(PackageLen - 4); + SimpleFont->Header.Type = EFI_HII_PACKAGE_SIMPLE_FONTS; + SimpleFont->NumberOfNarrowGlyphs = (UINT16)(NarrowGlyphSizeInBytes / sizeof(EFI_NARROW_GLYPH)); + SimpleFont->NumberOfWideGlyphs = (UINT16)(WideGlyphSizeInBytes / sizeof(EFI_WIDE_GLYPH)); + + UINT8* Location = (UINT8*)(&SimpleFont->NumberOfWideGlyphs + 1); + CopyMem(Location, NarrowGlyph, NarrowGlyphSizeInBytes); + CopyMem(Location + NarrowGlyphSizeInBytes, WideGlyph, WideGlyphSizeInBytes); + + return FontPackage; +} + + +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + Print(L"Привет!\n"); + + UINT8* FontPackage = CreateSimpleFontPkg(gSimpleFontWideGlyphData, + gSimpleFontWideBytes, + gSimpleFontNarrowGlyphData, + gSimpleFontNarrowBytes); + + EFI_HII_HANDLE Handle = HiiAddPackages(&gHIIAddRussianFontGuid, + NULL, + FontPackage, + HIIAddRussianFontStrings, + NULL); + + FreePool(FontPackage); + + if (Handle == NULL) + { + Print(L"Error! Can't perform HiiAddPackages\n"); + return EFI_INVALID_PARAMETER; + } + + Print(L"en-US ID=1: %s\n", HiiGetString(Handle, 1, "en-US")); + Print(L"en-US ID=2: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_HELLO), "en-US")); + Print(L"en-US ID=3: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_BYE), "en-US")); + Print(L"en-US ID=4: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_ALPHABET_UPPERCASE), "en-US")); + Print(L"en-US ID=5: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_ALPHABET_LOWERCASE), "en-US")); + Print(L"fr-FR ID=1: %s\n", HiiGetString(Handle, 1, "fr-FR")); + Print(L"fr-FR ID=2: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_HELLO), "fr-FR")); + Print(L"fr-FR ID=3: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_BYE), "fr-FR")); + Print(L"fr-FR ID=4: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_ALPHABET_UPPERCASE), "fr-FR")); + Print(L"fr-FR ID=5: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_ALPHABET_LOWERCASE), "fr-FR")); + Print(L"ru-RU ID=1: %s\n", HiiGetString(Handle, 1, "ru-RU")); + Print(L"ru-RU ID=2: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_HELLO), "ru-RU")); + Print(L"ru-RU ID=3: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_BYE), "ru-RU")); + Print(L"ru-RU ID=4: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_ALPHABET_UPPERCASE), "ru-RU")); + Print(L"ru-RU ID=5: %s\n", HiiGetString(Handle, STRING_TOKEN(STR_ALPHABET_LOWERCASE), "ru-RU")); + + Print(L"Привет!\n"); + + return EFI_SUCCESS; +} + -- cgit v1.2.3-18-g5258