/**@file\r
-\r
This file contains the Glyph related function.\r
\r
Copyright (c) 2006 - 2008, Intel Corporation\r
\r
#include "HiiDatabase.h"\r
\r
+EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}};\r
+\r
+BOOLEAN mSysFontColorCached = FALSE;\r
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL mSysFGColor = {0};\r
+\r
+\r
+/**\r
+ Translates a Unicode character into the corresponding font glyph.\r
+ \r
+ Notes:\r
+ This function is only called by Graphics Console module and GraphicsLib. \r
+ Wrap the Framework HII GetGlyph function to UEFI Font Protocol.\r
+ \r
+ EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib \r
+ complying to UEFI HII.\r
+ \r
+ @param This A pointer to the EFI_HII_PROTOCOL instance.\r
+ @param Source A pointer to a Unicode string.\r
+ @param Index On input, the offset into the string from which to fetch the character. On successful completion, the \r
+ index is updated to the first character past the character(s) making up the just extracted glyph. \r
+ @param GlyphBuffer Pointer to an array where the glyphs corresponding to the characters in the source may be stored. \r
+ GlyphBuffer is assumed to be wide enough to accept a wide glyph character.\r
+ @param BitWidth If EFI_SUCCESS was returned, the UINT16 pointed to by this value is filled with the length of the glyph in pixels. \r
+ It is unchanged if the call was unsuccessful.\r
+ @param InternalStatus To save the time required to read the string from the beginning on each glyph extraction \r
+ (for example, to ensure that the narrow versus wide glyph mode is correct), this value is \r
+ updated each time the function is called with the status that is local to the call. The cell pointed \r
+ to by this parameter must be initialized to zero prior to invoking the call the first time for any string.\r
+\r
+ @retval EFI_SUCCESS It worked.\r
+ @retval EFI_NOT_FOUND A glyph for a character was not found.\r
+ \r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
HiiGetGlyph (\r
OUT UINT16 *BitWidth,\r
IN OUT UINT32 *InternalStatus\r
)\r
-/*++\r
+{\r
+ EFI_STATUS Status;\r
+ EFI_IMAGE_OUTPUT *Blt;\r
+ EFI_FONT_DISPLAY_INFO *FontInfo;\r
+ UINTN Xpos;\r
+ UINTN Ypos;\r
+ UINTN BaseLine;\r
\r
-Routine Description:\r
- Translates a Unicode character into the corresponding font glyph.\r
- If the Source was pointing to a non-spacing character, the next Source[*Index]\r
- character will be parsed and OR'd to the GlyphBuffer until a spacing character\r
- is found in the Source. Since non-spacing characters are considered to be the\r
- same pixel width as a regular character their BitWidth will be reflected correctly\r
- however due to their special attribute, they are considered to be zero advancing width.\r
- This basically means that the cursor would not advance, thus the character that follows\r
- it would overlay the non-spacing character. The Index is modified to reflect both the\r
- incoming array entry into the Source string but also the outgoing array entry after having\r
- parsed the equivalent of a single Glyph's worth of data.\r
+ if (!mSysFontColorCached) {\r
+ //\r
+ // Cache the system font's foreground color.\r
+ //\r
+ Status = mHiiFontProtocol->GetFontInfo (\r
+ mHiiFontProtocol,\r
+ NULL,\r
+ NULL,\r
+ &FontInfo,\r
+ NULL\r
+ );\r
\r
-Arguments:\r
+ if (!EFI_ERROR (Status)) {\r
+ ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0);\r
+ mSysFGColor = FontInfo->ForegroundColor;\r
+ FreePool (FontInfo);\r
\r
-Returns:\r
+ mSysFontColorCached = TRUE;\r
+ }\r
+ \r
+ }\r
\r
---*/\r
-{\r
- ASSERT (FALSE);\r
- return EFI_SUCCESS;\r
+ Blt = NULL;\r
+ Status = mHiiFontProtocol->GetGlyph (\r
+ mHiiFontProtocol,\r
+ Source[*Index],\r
+ NULL,\r
+ &Blt,\r
+ &BaseLine\r
+ );\r
+\r
+ if (!EFI_ERROR (Status) && (Status != EFI_WARN_UNKNOWN_GLYPH)) {\r
+ //\r
+ // For simplicity, we only handle Narrow Glyph.\r
+ //\r
+ if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) {\r
+\r
+ ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer));\r
+ mNarrowGlyphBuffer.UnicodeWeight = *Source;\r
+ for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) {\r
+ for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) {\r
+ if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) {\r
+ mNarrowGlyphBuffer.GlyphCol1[Ypos] = (UINT8) (mNarrowGlyphBuffer.GlyphCol1[Ypos] | (1 << (EFI_GLYPH_WIDTH - 1 - Xpos)));\r
+ }\r
+ }\r
+ }\r
+\r
+ *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer;\r
+ *BitWidth = EFI_GLYPH_WIDTH;\r
+ *Index += 1;\r
+ } else {\r
+ Status = EFI_NOT_FOUND;\r
+ }\r
+\r
+ }\r
+\r
+ if (EFI_ERROR (Status) || (Status == EFI_WARN_UNKNOWN_GLYPH)) {\r
+ if (Status == EFI_WARN_UNKNOWN_GLYPH) {\r
+ Status = EFI_NOT_FOUND;\r
+ }\r
+ *GlyphBuffer = NULL;\r
+ }\r
+ return Status;\r
}\r
\r
+/**\r
+ Translates a glyph into the format required for input to the Universal Graphics Adapter (UGA) Block Transfer (BLT) routines.\r
+ \r
+ Notes:\r
+ This function is only called by Graphics Console module and GraphicsLib. \r
+ EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib \r
+ complying to UEFI HII.\r
+ \r
+ @param This A pointer to the EFI_HII_PROTOCOL instance.\r
+ @param GlyphBuffer A pointer to the buffer that contains glyph data. \r
+ @param Foreground The foreground setting requested to be used for the generated BltBuffer data. Type EFI_UGA_PIXEL is defined in "Related Definitions" below.\r
+ @param Background The background setting requested to be used for the generated BltBuffer data. \r
+ @param Count The entry in the BltBuffer upon which to act.\r
+ @param Width The width in bits of the glyph being converted.\r
+ @param Height The height in bits of the glyph being converted\r
+ @param BltBuffer A pointer to the buffer that contains the data that is ready to be used by the UGA BLT routines. \r
+\r
+ @retval EFI_SUCCESS It worked.\r
+ @retval EFI_NOT_FOUND A glyph for a character was not found.\r
+ \r
+\r
+**/\r
EFI_STATUS\r
EFIAPI\r
HiiGlyphToBlt (\r
IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer\r
)\r
{\r
- ASSERT (FALSE);\r
+ UINTN X;\r
+ UINTN Y;\r
+\r
+ //\r
+ // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r
+ //\r
+ for (Y = 0; Y < Height; Y++) {\r
+ for (X = 0; X < Width; X++) {\r
+ if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {\r
+ BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;\r
+ } else {\r
+ BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;\r
+ }\r
+ }\r
+ }\r
+\r
return EFI_SUCCESS;\r
}\r