我们可以通过EFI_HII_FONT_PROTOCOL【参考1】 中的 GetGlyph来取得一些字符的字形定义。

gly1

GetGlyph 的原型可以在 \MdePkg\Include\Protocol\HiiFont.h 中找到:

/**

  Convert the glyph for a single character into a bitmap.

  @param This       A pointer to the EFI_HII_FONT_PROTOCOL instance.

  @param Char       The character to retrieve.

  @param StringInfo Points to the string font and color
                    information or NULL if the string should use
                    the default system font and color.

  @param Blt        This must point to a NULL on entry. A buffer will
                    be allocated to hold the output and the pointer
                    updated on exit. It is the caller's responsibility
                    to free this buffer.

  @param Baseline   The number of pixels from the bottom of the bitmap
                    to the baseline.


  @retval EFI_SUCCESS             The glyph bitmap created.

  @retval EFI_OUT_OF_RESOURCES    Unable to allocate the output buffer Blt.

  @retval EFI_WARN_UNKNOWN_GLYPH  The glyph was unknown and was
                                  replaced with the glyph for
                                  Unicode character code 0xFFFD.

  @retval EFI_INVALID_PARAMETER   Blt is NULL, or Width is NULL, or
                                  Height is NULL


**/
typedef
EFI_STATUS
(EFIAPI *EFI_HII_GET_GLYPH)(
  IN CONST  EFI_HII_FONT_PROTOCOL *This,
  IN CONST  CHAR16                Char,
  IN CONST  EFI_FONT_DISPLAY_INFO *StringInfo,
  OUT       EFI_IMAGE_OUTPUT      **Blt,
  OUT       UINTN                 *Baseline OPTIONAL
);

 

其中 Char 是你要取对应字形的文字(特别注意是单个的CHAR16),StringInfo 为 NULL时取得的是系统默认的字体,输出结果在 Blt 中。最后一项含义我不清楚……
再看一下输出结果是 EFI_IMAGE_OUTPUT。它的定义在 \MdePkg\Include\Protocol\HiiImage.h中。其中含有一个Union的定义,在我们这里使用时,会按照 EFI_GRAPHICS_OUTPUT_BLT_PIXEL 给出。

最后写一个简单的测试程序如下,功能是取得“z”字符的字形。

#include  <Uefi.h>
#include  <Library/UefiLib.h>
#include  <Library/ShellCEntryLib.h>

#include <Protocol/HiiFont.h>

extern EFI_BOOT_SERVICES         *gBS;
 
int
EFIAPI
main (
  IN int Argc,
  IN CHAR16 **Argv
  )
{
    EFI_STATUS	Status = 0;
	UINTN		BaseLine;
	UINTN		i,j;	
    EFI_HII_FONT_PROTOCOL	*HiiFont = 0;
	EFI_IMAGE_OUTPUT		*Blt=NULL;
	CHAR8		*c,*p;
	
	Status = gBS->LocateProtocol (&gEfiHiiFontProtocolGuid, NULL, (VOID **) &HiiFont);
	if (Status!=EFI_SUCCESS) {
		Print(L"Error when LocateProtocol gEfiHiiFontProtocolGuid. Code[%r]\n",Status);
		return EFI_SUCCESS;
	}
   Status = HiiFont->GetGlyph (
				HiiFont,	//Protocol instance
				L'Z',		//Show char 'Z'
				NULL,		//Use the defualt system font and color
				&Blt,		//GLYPH information
				&BaseLine); //I don't know
				
	Print(L"This is [%d]x[%d]\n",Blt->Width,Blt->Height);
	
	c=(CHAR8*) Blt->Image.Bitmap;			
	for (j=0;j<Blt->Height;j++)
		{
			p=c;
			for (i=0;i<Blt->Width;i++)
				{
					Print(L"%2X",(*c)&0xFF);
					c=c+4;
				}
			Print(L"   ");	
			c=p+1;	
			for (i=0;i<Blt->Width;i++)
				{
					Print(L"%2X",(*c)&0xFF);
					c=c+4;
				}
			Print(L"   ");					
			c=p+2;	
			for (i=0;i<Blt->Width;i++)
				{
					Print(L"%2X",(*c)&0xFF);
					c=c+4;
				}
			c=p+(Blt->Width*4);
			Print(L"\n");	
		}	
		
	c=(CHAR8*) Blt->Image.Bitmap;			
	for (j=0;j<Blt->Height;j++)
		{
			for (i=0;i<Blt->Width;i++)
				{
					if (*c!=0) {
						Print(L"*");
					}
					else
					  {
						Print(L" ");
					  }	
					c=c+4;
				}
			Print(L"\n");	
		}			
		
	return EFI_SUCCESS;
}

 

运行结果,首先输出的是 R G B 数组,隐隐约约能看到其中有一个形状

gly2

程序后面有一个判断,直接输出星号和空格,结果如下,这样就看到非常清楚了。

gly3

完整的代码下载
GetGlyph

唯一的问题是:我还不知道取得这个东西能有什么用途.......

参考:
1.UEFI spec 2.4 P1711

Leave a Reply

电子邮件地址不会被公开。 必填项已用*标注

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>