X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=EdkCompatibilityPkg%2FCompatibility%2FFrameworkHiiToUefiHiiThunk%2FFonts.c;h=27b5d95fbd798123938d432b94f9cbe3e8b39957;hb=98b16b9dad5c90b59d4b39f2af904cc4bfb3e6b8;hp=1d58dcd90849193c2cff1dd0e02ce2425d40e068;hpb=0368663fd609e2e008031a2025693f190d19b0c7;p=mirror_edk2.git diff --git a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c index 1d58dcd908..27b5d95fbd 100644 --- a/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c +++ b/EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c @@ -1,5 +1,4 @@ /**@file - This file contains the Glyph related function. Copyright (c) 2006 - 2008, Intel Corporation @@ -16,24 +15,38 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. #include "HiiDatabase.h" +EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}}; + +BOOLEAN mSysFontColorCached = FALSE; +EFI_GRAPHICS_OUTPUT_BLT_PIXEL mSysFGColor = {0}; -UINT8 mGlyphBuffer[EFI_GLYPH_WIDTH * 2 * EFI_GLYPH_HEIGHT]; /** - This function is only called by Graphics Console module and GraphicsLib. - EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib - complying to UEFI HII. + Translates a Unicode character into the corresponding font glyph. - This function will ASSERT and return EFI_UNSUPPORTED. - - @param This N.A. - @param Source N.A. - @param Index N.A. - @param GlyphBuffer N.A. - @param BitWidth N.A. - @param InternalStatus N.A. - - @return EFI_UNSUPPORTED N.A. + Notes: + This function is only called by Graphics Console module and GraphicsLib. + Wrap the Framework HII GetGlyph function to UEFI Font Protocol. + + EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib + complying to UEFI HII. + + @param This A pointer to the EFI_HII_PROTOCOL instance. + @param Source A pointer to a Unicode string. + @param Index On input, the offset into the string from which to fetch the character. On successful completion, the + index is updated to the first character past the character(s) making up the just extracted glyph. + @param GlyphBuffer Pointer to an array where the glyphs corresponding to the characters in the source may be stored. + GlyphBuffer is assumed to be wide enough to accept a wide glyph character. + @param BitWidth If EFI_SUCCESS was returned, the UINT16 pointed to by this value is filled with the length of the glyph in pixels. + It is unchanged if the call was unsuccessful. + @param InternalStatus To save the time required to read the string from the beginning on each glyph extraction + (for example, to ensure that the narrow versus wide glyph mode is correct), this value is + updated each time the function is called with the status that is local to the call. The cell pointed + to by this parameter must be initialized to zero prior to invoking the call the first time for any string. + + @retval EFI_SUCCESS It worked. + @retval EFI_NOT_FOUND A glyph for a character was not found. + **/ EFI_STATUS @@ -47,27 +60,98 @@ HiiGetGlyph ( IN OUT UINT32 *InternalStatus ) { - ASSERT (FALSE); - return EFI_UNSUPPORTED; + EFI_STATUS Status; + EFI_IMAGE_OUTPUT *Blt; + EFI_FONT_DISPLAY_INFO *FontInfo; + UINTN Xpos; + UINTN Ypos; + UINTN BaseLine; + + if (!mSysFontColorCached) { + // + // Cache the system font's foreground color. + // + Status = mHiiFontProtocol->GetFontInfo ( + mHiiFontProtocol, + NULL, + NULL, + &FontInfo, + NULL + ); + + if (!EFI_ERROR (Status)) { + ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0); + mSysFGColor = FontInfo->ForegroundColor; + FreePool (FontInfo); + + mSysFontColorCached = TRUE; + } + + } + + Blt = NULL; + Status = mHiiFontProtocol->GetGlyph ( + mHiiFontProtocol, + Source[*Index], + NULL, + &Blt, + &BaseLine + ); + + if (!EFI_ERROR (Status) && (Status != EFI_WARN_UNKNOWN_GLYPH)) { + // + // For simplicity, we only handle Narrow Glyph. + // + if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) { + + ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer)); + mNarrowGlyphBuffer.UnicodeWeight = *Source; + for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) { + for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) { + if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) { + mNarrowGlyphBuffer.GlyphCol1[Ypos] = (UINT8) (mNarrowGlyphBuffer.GlyphCol1[Ypos] | (1 << (EFI_GLYPH_WIDTH - 1 - Xpos))); + } + } + } + + *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer; + *BitWidth = EFI_GLYPH_WIDTH; + *Index += 1; + } else { + Status = EFI_NOT_FOUND; + } + + } + + if (EFI_ERROR (Status) || (Status == EFI_WARN_UNKNOWN_GLYPH)) { + if (Status == EFI_WARN_UNKNOWN_GLYPH) { + Status = EFI_NOT_FOUND; + } + *GlyphBuffer = NULL; + } + return Status; } /** + Translates a glyph into the format required for input to the Universal Graphics Adapter (UGA) Block Transfer (BLT) routines. + + Notes: This function is only called by Graphics Console module and GraphicsLib. EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib complying to UEFI HII. - This function will ASSERT and return EFI_UNSUPPORTED. - - @param This N.A. - @param GlyphBuffer N.A. - @param Foreground N.A. - @param Background N.A. - @param Count N.A. - @param Width N.A. - @param Height N.A. - @param BltBuffer N.A. - - @return EFI_UNSUPPORTED N.A. + @param This A pointer to the EFI_HII_PROTOCOL instance. + @param GlyphBuffer A pointer to the buffer that contains glyph data. + @param Foreground The foreground setting requested to be used for the generated BltBuffer data. Type EFI_UGA_PIXEL is defined in "Related Definitions" below. + @param Background The background setting requested to be used for the generated BltBuffer data. + @param Count The entry in the BltBuffer upon which to act. + @param Width The width in bits of the glyph being converted. + @param Height The height in bits of the glyph being converted + @param BltBuffer A pointer to the buffer that contains the data that is ready to be used by the UGA BLT routines. + + @retval EFI_SUCCESS It worked. + @retval EFI_NOT_FOUND A glyph for a character was not found. + **/ EFI_STATUS @@ -83,6 +167,21 @@ HiiGlyphToBlt ( IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer ) { - ASSERT (FALSE); - return EFI_UNSUPPORTED; + UINTN X; + UINTN Y; + + // + // Convert Monochrome bitmap of the Glyph to BltBuffer structure + // + for (Y = 0; Y < Height; Y++) { + for (X = 0; X < Width; X++) { + if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) { + BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground; + } else { + BltBuffer[Y * Width * Count + (Width - X - 1)] = Background; + } + } + } + + return EFI_SUCCESS; }