X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FFont.c;h=5ecd6bd4a1e4f0d32e9c857a8451c7d7660b5824;hp=eb8e651360a9615d210c21c68915466dd00356a7;hb=d2970bbc1d88dbde480e7eef57f3ddcedd39ad08;hpb=ac644614683362804223844048c5be1a2adfa6b7 diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c index eb8e651360..5ecd6bd4a1 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c @@ -1,7 +1,9 @@ /** @file +Implementation for EFI_HII_FONT_PROTOCOL. -Copyright (c) 2007, Intel Corporation -All rights reserved. This program and the accompanying materials + +Copyright (c) 2007 - 2016, Intel Corporation. All rights reserved.
+This program and the accompanying materials are licensed and made available under the terms and conditions of the BSD License which accompanies this distribution. The full text of the license may be found at http://opensource.org/licenses/bsd-license.php @@ -9,23 +11,12 @@ http://opensource.org/licenses/bsd-license.php THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. -Module Name: - - Font.c - -Abstract: - - Implementation for EFI_HII_FONT_PROTOCOL. - -Revision History - - **/ #include "HiiDatabase.h" -static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = { +EFI_GRAPHICS_OUTPUT_BLT_PIXEL mHiiEfiColors[16] = { // // B G R // @@ -51,6 +42,8 @@ static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = { /** Insert a character cell information to the list specified by GlyphInfoList. + This is a internal function. + @param CharValue Unicode character value, which identifies a glyph block. @param GlyphInfoList HII_GLYPH_INFO list head. @@ -61,7 +54,6 @@ static EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = { task. **/ -STATIC EFI_STATUS NewCell ( IN CHAR16 CharValue, @@ -84,6 +76,9 @@ NewCell ( // GlyphInfo->Signature = HII_GLYPH_INFO_SIGNATURE; GlyphInfo->CharId = CharValue; + if (Cell->AdvanceX == 0) { + Cell->AdvanceX = Cell->Width; + } CopyMem (&GlyphInfo->Cell, Cell, sizeof (EFI_HII_GLYPH_INFO)); InsertTailList (GlyphInfoList, &GlyphInfo->Entry); @@ -94,6 +89,8 @@ NewCell ( /** Get a character cell information from the list specified by GlyphInfoList. + This is a internal function. + @param CharValue Unicode character value, which identifies a glyph block. @param GlyphInfoList HII_GLYPH_INFO list head. @@ -105,7 +102,6 @@ NewCell ( not exist. **/ -STATIC EFI_STATUS GetCell ( IN CHAR16 CharValue, @@ -143,6 +139,8 @@ GetCell ( /** Convert the glyph for a single character into a bitmap. + This is a internal function. + @param Private HII database driver private data. @param Char Character to retrieve. @param StringInfo Points to the string font and color information @@ -158,7 +156,6 @@ GetCell ( @retval EFI_INVALID_PARAMETER Any input parameter is invalid. **/ -STATIC EFI_STATUS GetGlyphBuffer ( IN HII_DATABASE_PRIVATE_DATA *Private, @@ -227,7 +224,6 @@ GetGlyphBuffer ( } Cell->Width = EFI_GLYPH_WIDTH; Cell->Height = EFI_GLYPH_HEIGHT; - Cell->OffsetY = NARROW_BASELINE; Cell->AdvanceX = Cell->Width; CopyMem (*GlyphBuffer, Narrow.GlyphCol1, Cell->Height); if (Attributes != NULL) { @@ -249,7 +245,6 @@ GetGlyphBuffer ( } Cell->Width = EFI_GLYPH_WIDTH * 2; Cell->Height = EFI_GLYPH_HEIGHT; - Cell->OffsetY = WIDE_BASELINE; Cell->AdvanceX = Cell->Width; CopyMem (*GlyphBuffer, Wide.GlyphCol1, EFI_GLYPH_HEIGHT); CopyMem (*GlyphBuffer + EFI_GLYPH_HEIGHT, Wide.GlyphCol2, EFI_GLYPH_HEIGHT); @@ -266,20 +261,41 @@ GetGlyphBuffer ( return EFI_NOT_FOUND; } -STATIC +/** + Convert bitmap data of the glyph to blt structure. + + This is a internal function. + + @param GlyphBuffer Buffer points to bitmap data of glyph. + @param Foreground The color of the "on" pixels in the glyph in the + bitmap. + @param Background The color of the "off" pixels in the glyph in the + bitmap. + @param ImageWidth Width of the whole image in pixels. + @param RowWidth The width of the text on the line, in pixels. + @param RowHeight The height of the line, in pixels. + @param Transparent If TRUE, the Background color is ignored and all + "off" pixels in the character's drawn wil use the + pixel value from BltBuffer. + @param Origin On input, points to the origin of the to be + displayed character, on output, points to the + next glyph's origin. + +**/ VOID NarrowGlyphToBlt ( IN UINT8 *GlyphBuffer, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background, - IN UINTN ImageWidth, - IN UINTN ImageHeight, + IN UINT16 ImageWidth, + IN UINTN RowWidth, + IN UINTN RowHeight, IN BOOLEAN Transparent, IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin ) { - UINT8 X; - UINT8 Y; + UINT8 Xpos; + UINT8 Ypos; UINT8 Height; UINT8 Width; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer; @@ -288,71 +304,100 @@ NarrowGlyphToBlt ( Height = EFI_GLYPH_HEIGHT; Width = EFI_GLYPH_WIDTH; + + // + // Move position to the left-top corner of char. + // + Buffer = *Origin - EFI_GLYPH_HEIGHT * ImageWidth; - ASSERT (Width <= ImageWidth && Height <= ImageHeight); - - Buffer = *Origin; + // + // Char may be partially displayed when CLIP_X or CLIP_Y is not set. + // + if (RowHeight < Height) { + Height = (UINT8) RowHeight; + } + if (RowWidth < Width) { + Width = (UINT8) RowWidth; + } - for (Y = 0; Y < Height; Y++) { - for (X = 0; X < Width; X++) { - if ((GlyphBuffer[Y] & (1 << X)) != 0) { - Buffer[Y * ImageWidth + (Width - X - 1)] = Foreground; + for (Ypos = 0; Ypos < Height; Ypos++) { + for (Xpos = 0; Xpos < Width; Xpos++) { + if ((GlyphBuffer[Ypos] & (1 << (EFI_GLYPH_WIDTH - Xpos - 1))) != 0) { + Buffer[Ypos * ImageWidth + Xpos] = Foreground; } else { if (!Transparent) { - Buffer[Y * ImageWidth + (Width - X - 1)] = Background; + Buffer[Ypos * ImageWidth + Xpos] = Background; } } } } - *Origin = Buffer + Width; + *Origin = *Origin + EFI_GLYPH_WIDTH; } /** Convert bitmap data of the glyph to blt structure. + This is a internal function. + @param GlyphBuffer Buffer points to bitmap data of glyph. @param Foreground The color of the "on" pixels in the glyph in the bitmap. @param Background The color of the "off" pixels in the glyph in the bitmap. - @param Width Width of the character or character cell, in - pixels. - @param Height Height of the character or character cell, in - pixels. + @param ImageWidth Width of the whole image in pixels. + @param BaseLine BaseLine in the line. + @param RowWidth The width of the text on the line, in pixels. + @param RowHeight The height of the line, in pixels. @param Transparent If TRUE, the Background color is ignored and all "off" pixels in the character's drawn wil use the pixel value from BltBuffer. - @param BltBuffer Points to the blt buffer. + @param Cell Points to EFI_HII_GLYPH_INFO structure. + @param Attributes The attribute of incoming glyph in GlyphBuffer. + @param Origin On input, points to the origin of the to be + displayed character, on output, points to the + next glyph's origin. **/ -STATIC VOID GlyphToBlt ( IN UINT8 *GlyphBuffer, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background, - IN UINTN ImageWidth, - IN UINTN ImageHeight, + IN UINT16 ImageWidth, + IN UINT16 BaseLine, + IN UINTN RowWidth, + IN UINTN RowHeight, IN BOOLEAN Transparent, - IN EFI_HII_GLYPH_INFO Cell, + IN CONST EFI_HII_GLYPH_INFO *Cell, IN UINT8 Attributes, IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin ) { - UINT8 X; - UINT8 Y; - UINT8 Data; - UINT8 Index; - UINTN OffsetY; - EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; + UINT16 Xpos; + UINT16 Ypos; + UINT8 Data; + UINT16 Index; + UINT16 YposOffset; + UINTN OffsetY; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; - ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL); - ASSERT (Cell.Width <= ImageWidth && Cell.Height <= ImageHeight); + ASSERT (Origin != NULL && *Origin != NULL && Cell != NULL); - BltBuffer = *Origin; + // + // Only adjust origin position if char has no bitmap. + // + if (GlyphBuffer == NULL) { + *Origin = *Origin + Cell->AdvanceX; + return; + } + // + // Move position to the left-top corner of char. + // + BltBuffer = *Origin + Cell->OffsetX - (Cell->OffsetY + Cell->Height) * ImageWidth; + YposOffset = (UINT16) (BaseLine - (Cell->OffsetY + Cell->Height)); // // Since non-spacing key will be printed OR'd with the previous glyph, don't @@ -366,59 +411,61 @@ GlyphToBlt ( // The glyph's upper left hand corner pixel is the most significant bit of the // first bitmap byte. // - for (Y = 0; Y < Cell.Height; Y++) { - OffsetY = BITMAP_LEN_1_BIT (Cell.Width, Y); + for (Ypos = 0; Ypos < Cell->Height && ((UINTN) (Ypos + YposOffset) < RowHeight); Ypos++) { + OffsetY = BITMAP_LEN_1_BIT (Cell->Width, Ypos); // // All bits in these bytes are meaningful. // - for (X = 0; X < Cell.Width / 8; X++) { - Data = *(GlyphBuffer + OffsetY + X); - for (Index = 0; Index < 8; Index++) { - if ((Data & (1 << Index)) != 0) { - BltBuffer[Y * ImageWidth + X * 8 + (8 - Index - 1)] = Foreground; + for (Xpos = 0; Xpos < Cell->Width / 8; Xpos++) { + Data = *(GlyphBuffer + OffsetY + Xpos); + for (Index = 0; Index < 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) { + if ((Data & (1 << (8 - Index - 1))) != 0) { + BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground; } else { if (!Transparent) { - BltBuffer[Y * ImageWidth + X * 8 + (8 - Index - 1)] = Background; + BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Background; } } } } - if (Cell.Width % 8 != 0) { + if (Cell->Width % 8 != 0) { // // There are some padding bits in this byte. Ignore them. // - Data = *(GlyphBuffer + OffsetY + X); - for (Index = 0; Index < Cell.Width % 8; Index++) { + Data = *(GlyphBuffer + OffsetY + Xpos); + for (Index = 0; Index < Cell->Width % 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) { if ((Data & (1 << (8 - Index - 1))) != 0) { - BltBuffer[Y * ImageWidth + X * 8 + Index] = Foreground; + BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground; } else { if (!Transparent) { - BltBuffer[Y * ImageWidth + X * 8 + Index] = Background; + BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Background; } } } } // end of if (Width % 8...) - } // end of for (Y=0...) + } // end of for (Ypos=0...) - *Origin = BltBuffer + Cell.Width; + *Origin = *Origin + Cell->AdvanceX; } /** Convert bitmap data of the glyph to blt structure. + This is a internal function. + @param GlyphBuffer Buffer points to bitmap data of glyph. @param Foreground The color of the "on" pixels in the glyph in the bitmap. @param Background The color of the "off" pixels in the glyph in the bitmap. - @param Width Width of the character or character cell, in - pixels. - @param Height Height of the character or character cell, in - pixels. + @param ImageWidth Width of the whole image in pixels. + @param BaseLine BaseLine in the line. + @param RowWidth The width of the text on the line, in pixels. + @param RowHeight The height of the line, in pixels. @param Transparent If TRUE, the Background color is ignored and all "off" pixels in the character's drawn wil use the pixel value from BltBuffer. @@ -431,24 +478,24 @@ GlyphToBlt ( @return Points to the address of next origin node in BltBuffer. **/ -STATIC VOID GlyphToImage ( IN UINT8 *GlyphBuffer, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground, IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background, - IN UINTN ImageWidth, - IN UINTN ImageHeight, + IN UINT16 ImageWidth, + IN UINT16 BaseLine, + IN UINTN RowWidth, + IN UINTN RowHeight, IN BOOLEAN Transparent, - IN EFI_HII_GLYPH_INFO Cell, + IN CONST EFI_HII_GLYPH_INFO *Cell, IN UINT8 Attributes, IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin ) { EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer; - ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL); - ASSERT (Cell.Width <= ImageWidth && Cell.Height <= ImageHeight); + ASSERT (Origin != NULL && *Origin != NULL && Cell != NULL); Buffer = *Origin; @@ -457,13 +504,15 @@ GlyphToImage ( // This character is a non-spacing key, print it OR'd with the previous glyph. // without advancing cursor. // - Buffer -= Cell.Width; + Buffer -= Cell->AdvanceX; GlyphToBlt ( GlyphBuffer, Foreground, Background, ImageWidth, - ImageHeight, + BaseLine, + RowWidth, + RowHeight, Transparent, Cell, Attributes, @@ -480,7 +529,8 @@ GlyphToImage ( Foreground, Background, ImageWidth, - ImageHeight, + RowWidth, + RowHeight, Transparent, Origin ); @@ -490,7 +540,8 @@ GlyphToImage ( Foreground, Background, ImageWidth, - ImageHeight, + RowWidth, + RowHeight, Transparent, Origin ); @@ -504,21 +555,24 @@ GlyphToImage ( Foreground, Background, ImageWidth, - ImageHeight, + RowWidth, + RowHeight, Transparent, Origin ); } else if ((Attributes & PROPORTIONAL_GLYPH) == PROPORTIONAL_GLYPH) { // - // This character is proportional glyph, i.e. Cell.Width * Cell.Height pixels. + // This character is proportional glyph, i.e. Cell->Width * Cell->Height pixels. // GlyphToBlt ( GlyphBuffer, Foreground, Background, ImageWidth, - ImageHeight, + BaseLine, + RowWidth, + RowHeight, Transparent, Cell, Attributes, @@ -531,6 +585,8 @@ GlyphToImage ( /** Write the output parameters of FindGlyphBlock(). + This is a internal function. + @param BufferIn Buffer which stores the bitmap data of the found block. @param BufferLen Length of BufferIn. @@ -548,7 +604,6 @@ GlyphToImage ( task. **/ -STATIC EFI_STATUS WriteOutputParam ( IN UINT8 *BufferIn, @@ -559,7 +614,7 @@ WriteOutputParam ( OUT UINTN *GlyphBufferLen OPTIONAL ) { - if (BufferIn == NULL || BufferLen < 1 || InputCell == NULL) { + if (BufferIn == NULL || InputCell == NULL) { return EFI_INVALID_PARAMETER; } @@ -567,7 +622,7 @@ WriteOutputParam ( CopyMem (Cell, InputCell, sizeof (EFI_HII_GLYPH_INFO)); } - if (GlyphBuffer != NULL) { + if (GlyphBuffer != NULL && BufferLen > 0) { *GlyphBuffer = (UINT8 *) AllocateZeroPool (BufferLen); if (*GlyphBuffer == NULL) { return EFI_OUT_OF_RESOURCES; @@ -623,10 +678,14 @@ FindGlyphBlock ( UINT16 Index; EFI_HII_GLYPH_INFO DefaultCell; EFI_HII_GLYPH_INFO LocalCell; + INT16 MinOffsetY; + UINT16 BaseLine; ASSERT (FontPackage != NULL); ASSERT (FontPackage->Signature == HII_FONT_PACKAGE_SIGNATURE); - + BaseLine = 0; + MinOffsetY = 0; + if (CharValue == (CHAR16) (-1)) { // // Collect the cell information specified in font package fixed header. @@ -640,6 +699,11 @@ FindGlyphBlock ( if (EFI_ERROR (Status)) { return Status; } + CopyMem ( + &LocalCell, + (UINT8 *) FontPackage->FontPkgHdr + 3 * sizeof (UINT32), + sizeof (EFI_HII_GLYPH_INFO) + ); } BlockPtr = FontPackage->GlyphBlock; @@ -662,6 +726,17 @@ FindGlyphBlock ( if (EFI_ERROR (Status)) { return Status; } + CopyMem ( + &LocalCell, + BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), + sizeof (EFI_HII_GLYPH_INFO) + ); + if (BaseLine < LocalCell.Height + LocalCell.OffsetY) { + BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY); + } + if (MinOffsetY > LocalCell.OffsetY) { + MinOffsetY = LocalCell.OffsetY; + } } BlockPtr += sizeof (EFI_HII_GIBT_DEFAULTS_BLOCK); break; @@ -678,12 +753,12 @@ FindGlyphBlock ( break; case EFI_HII_GIBT_EXT1: - BlockPtr += *(BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)); + BlockPtr += *(UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)); break; case EFI_HII_GIBT_EXT2: CopyMem ( &Length16, - BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)), sizeof (UINT16) ); BlockPtr += Length16; @@ -691,7 +766,7 @@ FindGlyphBlock ( case EFI_HII_GIBT_EXT4: CopyMem ( &Length32, - BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8), + (UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)), sizeof (UINT32) ); BlockPtr += Length32; @@ -703,10 +778,18 @@ FindGlyphBlock ( BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (EFI_HII_GLYPH_INFO) ); + if (CharValue == (CHAR16) (-1)) { + if (BaseLine < LocalCell.Height + LocalCell.OffsetY) { + BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY); + } + if (MinOffsetY > LocalCell.OffsetY) { + MinOffsetY = LocalCell.OffsetY; + } + } BufferLen = BITMAP_LEN_1_BIT (LocalCell.Width, LocalCell.Height); if (CharCurrent == CharValue) { return WriteOutputParam ( - BlockPtr + sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8), + (UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8)), BufferLen, &LocalCell, GlyphBuffer, @@ -725,6 +808,15 @@ FindGlyphBlock ( CopyMem (&Glyphs.Count, BlockPtr, sizeof (UINT16)); BlockPtr += sizeof (UINT16); + if (CharValue == (CHAR16) (-1)) { + if (BaseLine < Glyphs.Cell.Height + Glyphs.Cell.OffsetY) { + BaseLine = (UINT16) (Glyphs.Cell.Height + Glyphs.Cell.OffsetY); + } + if (MinOffsetY > Glyphs.Cell.OffsetY) { + MinOffsetY = Glyphs.Cell.OffsetY; + } + } + BufferLen = BITMAP_LEN_1_BIT (Glyphs.Cell.Width, Glyphs.Cell.Height); for (Index = 0; Index < Glyphs.Count; Index++) { if (CharCurrent + Index == CharValue) { @@ -807,6 +899,8 @@ FindGlyphBlock ( } if (CharValue == (CHAR16) (-1)) { + FontPackage->BaseLine = BaseLine; + FontPackage->Height = (UINT16) (BaseLine - MinOffsetY); return EFI_SUCCESS; } @@ -817,6 +911,8 @@ FindGlyphBlock ( /** Copy a Font Name to a new created EFI_FONT_INFO structure. + This is a internal function. + @param FontName NULL-terminated string. @param FontInfo a new EFI_FONT_INFO which stores the FontName. It's caller's responsibility to free this buffer. @@ -826,7 +922,6 @@ FindGlyphBlock ( task. **/ -STATIC EFI_STATUS SaveFontName ( IN EFI_STRING FontName, @@ -834,16 +929,18 @@ SaveFontName ( ) { UINTN FontInfoLen; + UINTN NameSize; ASSERT (FontName != NULL && FontInfo != NULL); - FontInfoLen = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + StrSize (FontName); + NameSize = StrSize (FontName); + FontInfoLen = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + NameSize; *FontInfo = (EFI_FONT_INFO *) AllocateZeroPool (FontInfoLen); if (*FontInfo == NULL) { return EFI_OUT_OF_RESOURCES; } - StrCpy ((*FontInfo)->FontName, FontName); + StrCpyS ((*FontInfo)->FontName, NameSize / sizeof (CHAR16), FontName); return EFI_SUCCESS; } @@ -872,6 +969,7 @@ GetSystemFont ( { EFI_FONT_DISPLAY_INFO *Info; UINTN InfoSize; + UINTN NameSize; if (Private == NULL || Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE) { return EFI_INVALID_PARAMETER; @@ -883,18 +981,19 @@ GetSystemFont ( // // The standard font always has the name "sysdefault". // - InfoSize = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + StrSize (L"sysdefault"); + NameSize = StrSize (L"sysdefault"); + InfoSize = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize; Info = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (InfoSize); if (Info == NULL) { return EFI_OUT_OF_RESOURCES; } - Info->ForegroundColor = mEfiColors[Private->Attribute & 0x0f]; - Info->BackgroundColor = mEfiColors[Private->Attribute >> 4]; + Info->ForegroundColor = mHiiEfiColors[Private->Attribute & 0x0f]; + Info->BackgroundColor = mHiiEfiColors[Private->Attribute >> 4]; Info->FontInfoMask = EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_SYS_STYLE; Info->FontInfo.FontStyle = 0; Info->FontInfo.FontSize = EFI_GLYPH_HEIGHT; - StrCpy (Info->FontInfo.FontName, L"sysdefault"); + StrCpyS (Info->FontInfo.FontName, NameSize / sizeof (CHAR16), L"sysdefault"); *FontInfo = Info; if (FontInfoSize != NULL) { @@ -905,15 +1004,16 @@ GetSystemFont ( /** - Check whether EFI_FONT_DISPLAY_INFO points to system default font and color. + Check whether EFI_FONT_DISPLAY_INFO points to system default font and color or + returns the system default according to the optional inputs. + + This is a internal function. @param Private HII database driver private data. @param StringInfo Points to the string output information, including the color and font. - @param SystemInfo If not NULL, points to system default font and - color when incoming StringInfo does not match the - default. Points to NULL if matches. It's - caller's reponsibility to free this buffer. + @param SystemInfo If not NULL, points to system default font and color. + @param SystemInfoLen If not NULL, output the length of default system info. @@ -921,7 +1021,6 @@ GetSystemFont ( @retval FALSE No. **/ -STATIC BOOLEAN IsSystemFontInfo ( IN HII_DATABASE_PRIVATE_DATA *Private, @@ -933,6 +1032,7 @@ IsSystemFontInfo ( EFI_STATUS Status; EFI_FONT_DISPLAY_INFO *SystemDefault; UINTN DefaultLen; + BOOLEAN Flag; ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE); @@ -940,28 +1040,75 @@ IsSystemFontInfo ( return TRUE; } - // - // Check whether incoming string font and color matches system default. - // + SystemDefault = NULL; + DefaultLen = 0; + Status = GetSystemFont (Private, &SystemDefault, &DefaultLen); ASSERT_EFI_ERROR (Status); + ASSERT ((SystemDefault != NULL) && (DefaultLen != 0)); + // + // Record the system default info. + // if (SystemInfo != NULL) { *SystemInfo = SystemDefault; - } else { - SafeFreePool (SystemDefault); } if (SystemInfoLen != NULL) { *SystemInfoLen = DefaultLen; } - if (StringInfo == NULL || - (StringInfo != NULL && CompareMem (SystemDefault, StringInfo, DefaultLen) == 0)) { + if (StringInfo == NULL) { return TRUE; } - return FALSE; + Flag = FALSE; + // + // Check the FontInfoMask to see whether it is retrieving system info. + // + if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) == 0) { + if (StrCmp (StringInfo->FontInfo.FontName, SystemDefault->FontInfo.FontName) != 0) { + goto Exit; + } + } + if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == 0) { + if (StringInfo->FontInfo.FontSize != SystemDefault->FontInfo.FontSize) { + goto Exit; + } + } + if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == 0) { + if (StringInfo->FontInfo.FontStyle != SystemDefault->FontInfo.FontStyle) { + goto Exit; + } + } + if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == 0) { + if (CompareMem ( + &StringInfo->ForegroundColor, + &SystemDefault->ForegroundColor, + sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ) != 0) { + goto Exit; + } + } + if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == 0) { + if (CompareMem ( + &StringInfo->BackgroundColor, + &SystemDefault->BackgroundColor, + sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL) + ) != 0) { + goto Exit; + } + } + + Flag = TRUE; + +Exit: + if (SystemInfo == NULL) { + if (SystemDefault != NULL) { + FreePool (SystemDefault); + } + } + return Flag; } @@ -1277,77 +1424,80 @@ IsFontInfoExisted ( /** Check whether the unicode represents a line break or not. + This is a internal function. Please see Section 27.2.6 of the UEFI Specification + for a description of the supported string format. + @param Char Unicode character - @retval 0 Yes, it is a line break. - @retval 1 Yes, it is a hyphen that desires a line break - after this character. - @retval 2 Yes, it is a dash that desires a line break - before and after it. + @retval 0 Yes, it forces a line break. + @retval 1 Yes, it presents a line break opportunity + @retval 2 Yes, it requires a line break happen before and after it. @retval -1 No, it is not a link break. **/ -STATIC INT8 IsLineBreak ( IN CHAR16 Char ) { - UINT8 Byte1; - UINT8 Byte2; - - // - // In little endian, Byte1 is the low byte of Char, Byte2 is the high byte of Char. - // - Byte1 = *((UINT8 *) (&Char)); - Byte2 = *(((UINT8 *) (&Char) + 1)); - - if (Byte2 == 0x20) { - switch (Byte1) { - case 0x00: - case 0x01: - case 0x02: - case 0x03: - case 0x04: - case 0x05: - case 0x06: - case 0x08: - case 0x09: - case 0x0A: - case 0x0B: - case 0x28: - case 0x29: - case 0x5F: - return 0; - case 0x10: - case 0x12: - case 0x13: - return 1; - case 0x14: - // - // BUGBUG: Does it really require line break before it and after it? - // - return 2; - } - } else if (Byte2 == 0x00) { - switch (Byte1) { - case 0x20: - case 0x0C: - case 0x0D: - return 0; - } - } - switch (Char) { - case 0x1680: + // + // Mandatory line break characters, which force a line-break + // + case 0x000A: + case 0x000C: + case 0x000D: + case 0x2028: + case 0x2029: return 0; + // + // Space characters, which is taken as a line-break opportunity + // + case 0x0020: + case 0x1680: + case 0x2000: + case 0x2001: + case 0x2002: + case 0x2003: + case 0x2004: + case 0x2005: + case 0x2006: + case 0x2008: + case 0x2009: + case 0x200A: + case 0x205F: + // + // In-Word Break Opportunities + // + case 0x200B: + return 1; + // + // A space which is not a line-break opportunity + // + case 0x00A0: + case 0x202F: + // + // A hyphen which is not a line-break opportunity + // + case 0x2011: + return -1; + // + // Hyphen characters which describe line break opportunities after the character + // case 0x058A: + case 0x2010: + case 0x2012: + case 0x2013: case 0x0F0B: case 0x1361: case 0x17D5: return 1; + // + // A hyphen which describes line break opportunities before and after them, but not between a pair of them + // + case 0x2014: + return 2; } - return -1; } @@ -1372,7 +1522,10 @@ IsLineBreak ( will be allocated to hold the generated image and the pointer updated on exit. It is the caller's responsibility to free this buffer. - @param BltX,BLTY Specifies the offset from the left and top edge + @param BltX Specifies the offset from the left and top edge + of the image of the first character cell in the + image. + @param BltY Specifies the offset from the left and top edge of the image of the first character cell in the image. @param RowInfoArray If this is non-NULL on entry, then on exit, this @@ -1400,6 +1553,7 @@ IsLineBreak ( @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for RowInfoArray or Blt. @retval EFI_INVALID_PARAMETER The String or Blt was NULL. + @retval EFI_INVALID_PARAMETER Flags were invalid combination.. **/ EFI_STATUS @@ -1428,10 +1582,13 @@ HiiStringToImage ( EFI_HII_ROW_INFO *RowInfo; UINTN LineWidth; UINTN LineHeight; + UINTN LineOffset; + UINTN LastLineHeight; UINTN BaseLineOffset; UINT16 MaxRowNum; UINT16 RowIndex; UINTN Index; + UINTN NextIndex; UINTN Index1; EFI_FONT_DISPLAY_INFO *StringInfoOut; EFI_FONT_DISPLAY_INFO *SystemDefault; @@ -1439,6 +1596,7 @@ HiiStringToImage ( EFI_STRING StringIn; EFI_STRING StringIn2; UINT16 Height; + UINT16 BaseLine; EFI_FONT_INFO *FontInfo; BOOLEAN SysFontFlag; EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground; @@ -1448,6 +1606,10 @@ HiiStringToImage ( EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BufferPtr; UINTN RowInfoSize; BOOLEAN LineBreak; + UINTN StrLength; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *RowBufferPtr; + HII_GLOBAL_FONT_INFO *GlobalFont; + UINT32 PreInitBkgnd; // // Check incoming parameters. @@ -1470,30 +1632,55 @@ HiiStringToImage ( // // These two flags require that EFI_HII_OUT_FLAG_CLIP be also set. // - if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLEAN_X)) == EFI_HII_OUT_FLAG_CLEAN_X) { + if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_X) { return EFI_INVALID_PARAMETER; } - if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLEAN_Y)) == EFI_HII_OUT_FLAG_CLEAN_Y) { + if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) { return EFI_INVALID_PARAMETER; } // // This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X. // - if ((Flags & (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLEAN_X)) == (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLEAN_X)) { + if ((Flags & (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) == (EFI_HII_OUT_FLAG_WRAP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) { return EFI_INVALID_PARAMETER; } - GlyphBuf = (UINT8 **) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (UINT8 *)); + if (*Blt == NULL) { + // + // Create a new bitmap and draw the string onto this image. + // + Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT)); + if (Image == NULL) { + return EFI_OUT_OF_RESOURCES; + } + Image->Width = 800; + Image->Height = 600; + Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height *sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + if (Image->Image.Bitmap == NULL) { + FreePool (Image); + return EFI_OUT_OF_RESOURCES; + } + + // + // Other flags are not permitted when Blt is NULL. + // + Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK; + *Blt = Image; + } + + StrLength = StrLen(String); + GlyphBuf = (UINT8 **) AllocateZeroPool (StrLength * sizeof (UINT8 *)); ASSERT (GlyphBuf != NULL); - Cell = (EFI_HII_GLYPH_INFO *) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (EFI_HII_GLYPH_INFO)); + Cell = (EFI_HII_GLYPH_INFO *) AllocateZeroPool (StrLength * sizeof (EFI_HII_GLYPH_INFO)); ASSERT (Cell != NULL); - Attributes = (UINT8 *) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (UINT8)); + Attributes = (UINT8 *) AllocateZeroPool (StrLength * sizeof (UINT8)); ASSERT (Attributes != NULL); RowInfo = NULL; Status = EFI_SUCCESS; StringIn2 = NULL; SystemDefault = NULL; + StringIn = NULL; // // Calculate the string output information, including specified color and font . @@ -1506,12 +1693,18 @@ HiiStringToImage ( SysFontFlag = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL); if (SysFontFlag) { + ASSERT (SystemDefault != NULL); FontInfo = NULL; Height = SystemDefault->FontInfo.FontSize; + BaseLine = SystemDefault->FontInfo.FontSize; Foreground = SystemDefault->ForegroundColor; Background = SystemDefault->BackgroundColor; } else { + // + // StringInfo must not be NULL if it is not system info. + // + ASSERT (StringInfo != NULL); Status = HiiGetFontInfo (This, &FontHandle, (EFI_FONT_DISPLAY_INFO *) StringInfo, &StringInfoOut, NULL); if (Status == EFI_NOT_FOUND) { // @@ -1521,23 +1714,35 @@ HiiStringToImage ( SysFontFlag = TRUE; FontInfo = NULL; Height = SystemDefault->FontInfo.FontSize; + BaseLine = SystemDefault->FontInfo.FontSize; Foreground = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->ForegroundColor; Background = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->BackgroundColor; - } else { + } else if (Status == EFI_SUCCESS) { FontInfo = &StringInfoOut->FontInfo; - Height = StringInfoOut->FontInfo.FontSize; + IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont); + Height = GlobalFont->FontPackage->Height; + BaseLine = GlobalFont->FontPackage->BaseLine; Foreground = StringInfoOut->ForegroundColor; Background = StringInfoOut->BackgroundColor; + } else { + goto Exit; } } - + + // + // Use the maxinum height of font as the base line. + // And, use the maxinum height as line height. + // + LineHeight = Height; + LastLineHeight = Height; + BaseLineOffset = Height - BaseLine; + // // Parse the string to be displayed to drop some ignored characters. // StringPtr = String; - StringIn = NULL; // // Ignore line-break characters only. Hyphens or dash character will be displayed @@ -1571,14 +1776,20 @@ HiiStringToImage ( } Index = 0; StringTmp = StringIn2; - - while (*StringPtr != 0 && Index < MAX_STRING_LENGTH) { + StrLength = StrLen(StringPtr); + while (*StringPtr != 0 && Index < StrLength) { + if (IsLineBreak (*StringPtr) == 0) { + *StringTmp++ = *StringPtr++; + Index++; + continue; + } + Status = GetGlyphBuffer (Private, *StringPtr, FontInfo, &GlyphBuf[Index], &Cell[Index], &Attributes[Index]); if (Status == EFI_NOT_FOUND) { if ((Flags & EFI_HII_IGNORE_IF_NO_GLYPH) == EFI_HII_IGNORE_IF_NO_GLYPH) { - SafeFreePool (GlyphBuf[Index]); GlyphBuf[Index] = NULL; - StringPtr++; + ZeroMem (&Cell[Index], sizeof (Cell[Index])); + Status = EFI_SUCCESS; } else { // // Unicode 0xFFFD must exist in current hii database if this flag is not set. @@ -1593,17 +1804,16 @@ HiiStringToImage ( ); if (EFI_ERROR (Status)) { Status = EFI_INVALID_PARAMETER; - goto Exit; } - *StringTmp++ = *StringPtr++; - Index++; } - } else if (EFI_ERROR (Status)) { + } + + if (EFI_ERROR (Status)) { goto Exit; - } else { - *StringTmp++ = *StringPtr++; - Index++; } + + *StringTmp++ = *StringPtr++; + Index++; } *StringTmp = 0; StringPtr = StringIn2; @@ -1614,181 +1824,269 @@ HiiStringToImage ( // to an existing image (bitmap or screen depending on flags) pointed by "*Blt". // Otherwise render this string to a new allocated image and output it. // - if (*Blt != NULL) { - Image = *Blt; - BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX; - MaxRowNum = (UINT16) (Image->Height / Height); - if (Image->Height % Height != 0) { - MaxRowNum++; - } - - RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO)); - if (RowInfo == NULL) { - Status = EFI_OUT_OF_RESOURCES; - goto Exit; - } - + Image = *Blt; + BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX; + if (Image->Height < BltY) { // - // Format the glyph buffer according to flags. + // the top edge of the image should be in Image resolution scope. // + Status = EFI_INVALID_PARAMETER; + goto Exit; + } + MaxRowNum = (UINT16) ((Image->Height - BltY) / Height); + if ((Image->Height - BltY) % Height != 0) { + LastLineHeight = (Image->Height - BltY) % Height; + MaxRowNum++; + } - Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE); - if ((Flags & EFI_HII_OUT_FLAG_CLEAN_Y) == EFI_HII_OUT_FLAG_CLEAN_Y) { - // - // Don't draw at all if there is only one row and - // the row's bottom-most on pixel cannot fit. - // - if (MaxRowNum == 1 && SysFontFlag) { - Status = EFI_SUCCESS; - goto Exit; - } - } + RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO)); + if (RowInfo == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } - for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) { - LineWidth = 0; - LineHeight = 0; - BaseLineOffset = 0; - LineBreak = FALSE; + // + // Format the glyph buffer according to flags. + // + Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE); - // - // Calculate how many characters there are in a row. - // - RowInfo[RowIndex].StartIndex = Index; + for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) { + LineWidth = 0; + LineBreak = FALSE; - while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) { - LineWidth += (UINTN) Cell[Index].AdvanceX; - if (LineHeight < Cell[Index].Height) { - LineHeight = (UINTN) Cell[Index].Height; - } - BaseLineOffset += (UINTN) Cell[Index].OffsetY; + // + // Clip the final row if the row's bottom-most on pixel cannot fit when + // EFI_HII_OUT_FLAG_CLEAN_Y is set. + // + if (RowIndex == MaxRowNum - 1) { + if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y && LastLineHeight < LineHeight ) { + // + // Don't draw at all if the row's bottom-most on pixel cannot fit. + // + break; + } + LineHeight = LastLineHeight; + } - if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0 && - (Flags & EFI_HII_OUT_FLAG_WRAP) == 0 && - IsLineBreak (StringPtr[Index]) > 0) { - // - // It is a line break that ends this row. - // - Index++; - break; - } + // + // Calculate how many characters there are in a row. + // + RowInfo[RowIndex].StartIndex = Index; + while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) { + if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0 && + IsLineBreak (StringPtr[Index]) == 0) { + // + // It forces a line break that ends this row. + // Index++; + LineBreak = TRUE; + break; } // - // If this character is the last character of a row, we need not - // draw its (AdvanceX - Width) for next character. + // If the glyph of the character is existing, then accumulate the actual printed width // - Index--; - if (!SysFontFlag) { - LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width); - } + LineWidth += (UINTN) Cell[Index].AdvanceX; + + Index++; + } + // + // Record index of next char. + // + NextIndex = Index; + // + // Return to the previous char. + // + Index--; + if (LineBreak && Index > 0 ) { // - // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break - // opportunity prior to a character whose right-most extent would exceed Width. - // Search the right-most line-break opportunity here. + // Return the previous non line break char. // - if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP) { - if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) { - for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) { - if (IsLineBreak (StringPtr[Index1]) > 0) { - LineBreak = TRUE; - RowInfo[RowIndex].EndIndex = Index1 - 1; - break; - } - } - } - // - // If no line-break opportunity can be found, then the text will - // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set. - // - if (!LineBreak) { - Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP); - Flags |= EFI_HII_OUT_FLAG_CLEAN_X; - } - } + Index --; + } + + // + // If this character is the last character of a row, we need not + // draw its (AdvanceX - Width - OffsetX) for next character. + // + LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX); + // + // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set. + // + if (LineWidth + BltX <= Image->Width || + (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) { + // + // Record right-most character in RowInfo even if it is partially displayed. + // + RowInfo[RowIndex].EndIndex = Index; + RowInfo[RowIndex].LineWidth = LineWidth; + RowInfo[RowIndex].LineHeight = LineHeight; + RowInfo[RowIndex].BaselineOffset = BaseLineOffset; + } else { // - // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set. + // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character + // if its right-most on pixel cannot fit. // - if (LineWidth + BltX <= Image->Width || - (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLEAN_X) == 0)) { + if (Index > RowInfo[RowIndex].StartIndex) { // - // Record right-most character in RowInfo even if it is partially displayed. + // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX). // - RowInfo[RowIndex].EndIndex = Index; + LineWidth -= (UINTN) (Cell[Index].Width + Cell[Index].OffsetX); + LineWidth -= (UINTN) (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX); + RowInfo[RowIndex].EndIndex = Index - 1; RowInfo[RowIndex].LineWidth = LineWidth; RowInfo[RowIndex].LineHeight = LineHeight; RowInfo[RowIndex].BaselineOffset = BaseLineOffset; } else { // - // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character - // if its right-most on pixel cannot fit. + // There is no enough column to draw any character, so set current line width to zero. + // And go to draw Next line if LineBreak is set. // - if (Index > 0) { - RowInfo[RowIndex].EndIndex = Index - 1; - RowInfo[RowIndex].LineWidth = LineWidth - Cell[Index].AdvanceX; - RowInfo[RowIndex].BaselineOffset = BaseLineOffset - Cell[Index].OffsetY; - if (LineHeight > Cell[Index - 1].Height) { - LineHeight = Cell[Index - 1].Height; + RowInfo[RowIndex].LineWidth = 0; + goto NextLine; + } + } + + // + // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break + // opportunity prior to a character whose right-most extent would exceed Width. + // Search the right-most line-break opportunity here. + // + if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP && + (RowInfo[RowIndex].LineWidth + BltX > Image->Width || StringPtr[NextIndex] != 0) && + !LineBreak) { + if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) { + LineWidth = RowInfo[RowIndex].LineWidth; + for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) { + if (Index1 == RowInfo[RowIndex].EndIndex) { + LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX); + } else { + LineWidth -= Cell[Index1].AdvanceX; + } + if (IsLineBreak (StringPtr[Index1]) > 0) { + LineBreak = TRUE; + if (Index1 > RowInfo[RowIndex].StartIndex) { + RowInfo[RowIndex].EndIndex = Index1 - 1; + } + // + // relocate to the character after the right-most line break opportunity of this line + // + NextIndex = Index1 + 1; + break; } - RowInfo[RowIndex].LineHeight = LineHeight; - } else { // - // There is only one column and it can not be drawn so that return directly. + // If don't find a line break opportunity from EndIndex to StartIndex, + // then jump out. // - Status = EFI_SUCCESS; - goto Exit; + if (Index1 == RowInfo[RowIndex].StartIndex) + break; } - } + // + // Update LineWidth to the real width + // + if (IsLineBreak (StringPtr[Index1]) > 0) { + if (Index1 == RowInfo[RowIndex].StartIndex) { + LineWidth = 0; + } else { + LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX); + } + RowInfo[RowIndex].LineWidth = LineWidth; + } + } // - // Clip the final row if the row's bottom-most on pixel cannot fit when - // EFI_HII_OUT_FLAG_CLEAN_Y is set. + // If no line-break opportunity can be found, then the text will + // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set. // - if (RowIndex == MaxRowNum - 1 && Image->Height < LineHeight) { - LineHeight = Image->Height; - if ((Flags & EFI_HII_OUT_FLAG_CLEAN_Y) == EFI_HII_OUT_FLAG_CLEAN_Y) { - // - // Don't draw at all if the row's bottom-most on pixel cannot fit. - // - break; + if (!LineBreak) { + LineWidth = RowInfo[RowIndex].LineWidth; + Index1 = RowInfo[RowIndex].EndIndex; + if (LineWidth + BltX > Image->Width) { + if (Index1 > RowInfo[RowIndex].StartIndex) { + // + // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX). + // + LineWidth -= (UINTN) (Cell[Index1].Width + Cell[Index1].OffsetX); + LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX); + RowInfo[RowIndex].EndIndex = Index1 - 1; + RowInfo[RowIndex].LineWidth = LineWidth; + } else { + // + // There is no enough column to draw any character, so set current line width to zero. + // And go to draw Next line if LineBreak is set. + // + RowInfo[RowIndex].LineWidth = 0; + goto NextLine; + } } } + } + + // + // LineWidth can't exceed Image width. + // + if (RowInfo[RowIndex].LineWidth + BltX > Image->Width) { + RowInfo[RowIndex].LineWidth = Image->Width - BltX; + } - // - // Draw it to screen or existing bitmap depending on whether - // EFI_HII_DIRECT_TO_SCREEN is set. - // - if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) { + // + // Draw it to screen or existing bitmap depending on whether + // EFI_HII_DIRECT_TO_SCREEN is set. + // + LineOffset = 0; + if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) { + BltBuffer = NULL; + if (RowInfo[RowIndex].LineWidth != 0) { BltBuffer = AllocateZeroPool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); if (BltBuffer == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Exit; } - BufferPtr = BltBuffer; - for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) { + // + // Initialize the background color. + // + PreInitBkgnd = Background.Blue | Background.Green << 8 | Background.Red << 16; + SetMem32 (BltBuffer,RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL),PreInitBkgnd); + // + // Set BufferPtr to Origin by adding baseline to the starting position. + // + BufferPtr = BltBuffer + BaseLine * RowInfo[RowIndex].LineWidth; + } + for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) { + if (RowInfo[RowIndex].LineWidth > 0 && RowInfo[RowIndex].LineWidth > LineOffset) { + // + // Only BLT these character which have corrsponding glyph in font basebase. + // GlyphToImage ( GlyphBuf[Index1], Foreground, Background, - RowInfo[RowIndex].LineWidth, + (UINT16) RowInfo[RowIndex].LineWidth, + BaseLine, + RowInfo[RowIndex].LineWidth - LineOffset, RowInfo[RowIndex].LineHeight, Transparent, - Cell[Index1], + &Cell[Index1], Attributes[Index1], &BufferPtr - ); - if (ColumnInfoArray != NULL) { - if (Index1 == RowInfo[RowIndex].StartIndex) { - *ColumnInfoArray = 0; - } else { - *ColumnInfoArray = Cell[Index1 -1].AdvanceX; - } - ColumnInfoArray++; + ); + } + if (ColumnInfoArray != NULL) { + if ((GlyphBuf[Index1] == NULL && Cell[Index1].AdvanceX == 0) + || RowInfo[RowIndex].LineWidth == 0) { + *ColumnInfoArray = (UINTN) ~0; + } else { + *ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX; } + ColumnInfoArray++; } + LineOffset += Cell[Index1].AdvanceX; + } + + if (BltBuffer != NULL) { Status = Image->Image.Screen->Blt ( Image->Image.Screen, BltBuffer, @@ -1802,115 +2100,132 @@ HiiStringToImage ( 0 ); if (EFI_ERROR (Status)) { - SafeFreePool (BltBuffer); + FreePool (BltBuffer); goto Exit; } - - SafeFreePool (BltBuffer); - - } else { - for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) { + + FreePool (BltBuffer); + } + } else { + // + // Save the starting position for calculate the starting postition of next row. + // + RowBufferPtr = BufferPtr; + // + // Set BufferPtr to Origin by adding baseline to the starting position. + // + BufferPtr = BufferPtr + BaseLine * Image->Width; + for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) { + if (RowInfo[RowIndex].LineWidth > 0 && RowInfo[RowIndex].LineWidth > LineOffset) { + // + // Only BLT these character which have corrsponding glyph in font basebase. + // GlyphToImage ( GlyphBuf[Index1], Foreground, Background, Image->Width, - Image->Height, + BaseLine, + RowInfo[RowIndex].LineWidth - LineOffset, + RowInfo[RowIndex].LineHeight, Transparent, - Cell[Index1], + &Cell[Index1], Attributes[Index1], &BufferPtr - ); - if (ColumnInfoArray != NULL) { - if (Index1 == RowInfo[RowIndex].StartIndex) { - *ColumnInfoArray = 0; - } else { - *ColumnInfoArray = Cell[Index1 -1].AdvanceX; - } - ColumnInfoArray++; + ); + } + if (ColumnInfoArray != NULL) { + if ((GlyphBuf[Index1] == NULL && Cell[Index1].AdvanceX == 0) + || RowInfo[RowIndex].LineWidth == 0) { + *ColumnInfoArray = (UINTN) ~0; + } else { + *ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX; } + ColumnInfoArray++; } - // - // Jump to next row - // - BufferPtr += BltX + Image->Width * (LineHeight - 1); + LineOffset += Cell[Index1].AdvanceX; } - Index++; - RowIndex++; - + // + // Jump to starting position of next row. + // + if (RowIndex == 0) { + BufferPtr = RowBufferPtr - BltX + LineHeight * Image->Width; + } else { + BufferPtr = RowBufferPtr + LineHeight * Image->Width; + } } +NextLine: // - // Write output parameters. + // Recalculate the start point of Y axis to draw multi-lines with the order of top-to-down // - RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO); - if (RowInfoArray != NULL) { + BltY += RowInfo[RowIndex].LineHeight; + + RowIndex++; + Index = NextIndex; + + if (!LineBreak) { + // + // If there is not a mandatory line break or line break opportunity, only render one line to image + // + break; + } + } + + // + // Write output parameters. + // + RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO); + if (RowInfoArray != NULL) { + if (RowInfoSize > 0) { *RowInfoArray = AllocateZeroPool (RowInfoSize); if (*RowInfoArray == NULL) { Status = EFI_OUT_OF_RESOURCES; goto Exit; } CopyMem (*RowInfoArray, RowInfo, RowInfoSize); + } else { + *RowInfoArray = NULL; } - if (RowInfoArraySize != NULL) { - *RowInfoArraySize = RowIndex; - } - - } else { - // - // Create a new bitmap and draw the string onto this image. - // - Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT)); - if (Image == NULL) { - return EFI_OUT_OF_RESOURCES; - } - Image->Width = 800; - Image->Height = 600; - Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height *sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - if (Image->Image.Bitmap == NULL) { - SafeFreePool (Image); - return EFI_OUT_OF_RESOURCES; - } - - // - // Other flags are not permitted when Blt is NULL. - // - Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK; - Status = HiiStringToImage ( - This, - Flags, - String, - StringInfo, - &Image, - BltX, - BltY, - RowInfoArray, - RowInfoArraySize, - ColumnInfoArray - ); - if (EFI_ERROR (Status)) { - return Status; - } - - *Blt = Image; + } + if (RowInfoArraySize != NULL) { + *RowInfoArraySize = RowIndex; } Status = EFI_SUCCESS; Exit: - for (Index = 0; Index < MAX_STRING_LENGTH; Index++) { - SafeFreePool (GlyphBuf[Index]); + for (Index = 0; Index < StrLength; Index++) { + if (GlyphBuf[Index] != NULL) { + FreePool (GlyphBuf[Index]); + } + } + if (StringIn != NULL) { + FreePool (StringIn); + } + if (StringIn2 != NULL) { + FreePool (StringIn2); + } + if (StringInfoOut != NULL) { + FreePool (StringInfoOut); + } + if (RowInfo != NULL) { + FreePool (RowInfo); + } + if (SystemDefault != NULL) { + FreePool (SystemDefault); + } + if (GlyphBuf != NULL) { + FreePool (GlyphBuf); + } + if (Cell != NULL) { + FreePool (Cell); + } + if (Attributes != NULL) { + FreePool (Attributes); } - SafeFreePool (StringIn); - SafeFreePool (StringIn2); - SafeFreePool (StringInfoOut); - SafeFreePool (RowInfo); - SafeFreePool (SystemDefault); - SafeFreePool (GlyphBuf); - SafeFreePool (Cell); - SafeFreePool (Attributes); return Status; } @@ -1941,7 +2256,10 @@ Exit: will be allocated to hold the generated image and the pointer updated on exit. It is the caller's responsibility to free this buffer. - @param BltX,BLTY Specifies the offset from the left and top edge + @param BltX Specifies the offset from the left and top edge + of the image of the first character cell in the + image. + @param BltY Specifies the offset from the left and top edge of the image of the first character cell in the image. @param RowInfoArray If this is non-NULL on entry, then on exit, this @@ -1968,7 +2286,10 @@ Exit: @retval EFI_SUCCESS The string was successfully rendered. @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for RowInfoArray or Blt. - @retval EFI_INVALID_PARAMETER The PackageList was NULL. + @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL. + @retval EFI_INVALID_PARAMETER Flags were invalid combination. + @retval EFI_NOT_FOUND The specified PackageList is not in the Database or the stringid is not + in the specified PackageList. **/ EFI_STATUS @@ -1990,8 +2311,18 @@ HiiStringIdToImage ( { EFI_STATUS Status; HII_DATABASE_PRIVATE_DATA *Private; + EFI_HII_STRING_PROTOCOL *HiiString; EFI_STRING String; UINTN StringSize; + UINTN FontLen; + UINTN NameSize; + EFI_FONT_INFO *StringFontInfo; + EFI_FONT_DISPLAY_INFO *NewStringInfo; + CHAR8 TempSupportedLanguages; + CHAR8 *SupportedLanguages; + UINTN SupportedLanguagesSize; + CHAR8 *CurrentLanguage; + CHAR8 *BestLanguage; if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) { return EFI_INVALID_PARAMETER; @@ -2001,51 +2332,140 @@ HiiStringIdToImage ( return EFI_NOT_FOUND; } - Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This); + // + // Initialize string pointers to be NULL + // + SupportedLanguages = NULL; + CurrentLanguage = NULL; + BestLanguage = NULL; + String = NULL; + StringFontInfo = NULL; + NewStringInfo = NULL; // // Get the string to be displayed. // + Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This); + HiiString = &Private->HiiString; + + // + // Get the size of supported language. + // + SupportedLanguagesSize = 0; + Status = HiiString->GetLanguages ( + HiiString, + PackageList, + &TempSupportedLanguages, + &SupportedLanguagesSize + ); + if (Status != EFI_BUFFER_TOO_SMALL) { + return Status; + } + SupportedLanguages = AllocatePool (SupportedLanguagesSize); + if (SupportedLanguages == NULL) { + return EFI_OUT_OF_RESOURCES; + } + + Status = HiiString->GetLanguages ( + HiiString, + PackageList, + SupportedLanguages, + &SupportedLanguagesSize + ); + if (EFI_ERROR (Status)) { + goto Exit; + } + + if (Language == NULL) { + Language = ""; + } + GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLanguage, NULL); + BestLanguage = GetBestLanguage ( + SupportedLanguages, + FALSE, + Language, + (CurrentLanguage == NULL) ? CurrentLanguage : "", + (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang), + NULL + ); + if (BestLanguage == NULL) { + Status = EFI_NOT_FOUND; + goto Exit; + } + StringSize = MAX_STRING_LENGTH; String = (EFI_STRING) AllocateZeroPool (StringSize); if (String == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = EFI_OUT_OF_RESOURCES; + goto Exit; } - Status = Private->HiiString.GetString ( - &Private->HiiString, - Language, - PackageList, - StringId, - String, - &StringSize, - NULL - ); + Status = HiiString->GetString ( + HiiString, + BestLanguage, + PackageList, + StringId, + String, + &StringSize, + &StringFontInfo + ); if (Status == EFI_BUFFER_TOO_SMALL) { - SafeFreePool (String); + FreePool (String); String = (EFI_STRING) AllocateZeroPool (StringSize); if (String == NULL) { - return EFI_OUT_OF_RESOURCES; + Status = EFI_OUT_OF_RESOURCES; + goto Exit; } - Status = Private->HiiString.GetString ( - &Private->HiiString, - Language, - PackageList, - StringId, - String, - &StringSize, - NULL - ); - + Status = HiiString->GetString ( + HiiString, + BestLanguage, + PackageList, + StringId, + String, + &StringSize, + NULL + ); } if (EFI_ERROR (Status)) { - SafeFreePool (String); - return Status; + goto Exit; + } + + // + // When StringInfo specifies that string will be output in the system default font and color, + // use particular stringfontinfo described in string package instead if exists. + // StringFontInfo equals NULL means system default font attaches with the string block. + // + if (StringFontInfo != NULL && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, NULL, NULL)) { + NameSize = StrSize (StringFontInfo->FontName); + FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize; + NewStringInfo = AllocateZeroPool (FontLen); + if (NewStringInfo == NULL) { + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } + NewStringInfo->FontInfoMask = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR; + NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle; + NewStringInfo->FontInfo.FontSize = StringFontInfo->FontSize; + StrCpyS (NewStringInfo->FontInfo.FontName, NameSize / sizeof (CHAR16), StringFontInfo->FontName); + + Status = HiiStringToImage ( + This, + Flags, + String, + NewStringInfo, + Blt, + BltX, + BltY, + RowInfoArray, + RowInfoArraySize, + ColumnInfoArray + ); + goto Exit; } - return HiiStringToImage ( + Status = HiiStringToImage ( This, Flags, String, @@ -2058,6 +2478,27 @@ HiiStringIdToImage ( ColumnInfoArray ); +Exit: + if (SupportedLanguages != NULL) { + FreePool (SupportedLanguages); + } + if (CurrentLanguage != NULL) { + FreePool (CurrentLanguage); + } + if (BestLanguage != NULL) { + FreePool (BestLanguage); + } + if (String != NULL) { + FreePool (String); + } + if (StringFontInfo != NULL) { + FreePool (StringFontInfo); + } + if (NewStringInfo != NULL) { + FreePool (NewStringInfo); + } + + return Status; } @@ -2108,6 +2549,7 @@ HiiGetGlyph ( EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground; EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer; + UINT16 BaseLine; if (This == NULL || Blt == NULL || *Blt != NULL) { return EFI_INVALID_PARAMETER; @@ -2146,10 +2588,12 @@ HiiGetGlyph ( if (EFI_ERROR (Status)) { goto Exit; } + ASSERT (StringInfoOut != NULL); FontInfo = &StringInfoOut->FontInfo; Foreground = StringInfoOut->ForegroundColor; Background = StringInfoOut->BackgroundColor; } else { + ASSERT (SystemDefault != NULL); Foreground = SystemDefault->ForegroundColor; Background = SystemDefault->BackgroundColor; } @@ -2167,25 +2611,36 @@ HiiGetGlyph ( Image->Width = Cell.Width; Image->Height = Cell.Height; - Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); - if (Image->Image.Bitmap == NULL) { - SafeFreePool (Image); - Status = EFI_OUT_OF_RESOURCES; - goto Exit; - } + if (Image->Width * Image->Height > 0) { + Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)); + if (Image->Image.Bitmap == NULL) { + FreePool (Image); + Status = EFI_OUT_OF_RESOURCES; + goto Exit; + } - BltBuffer = Image->Image.Bitmap; - GlyphToImage ( - GlyphBuffer, - Foreground, - Background, - Image->Width, - Image->Height, - FALSE, - Cell, - Attributes, - &BltBuffer - ); + // + // Set BaseLine to the char height. + // + BaseLine = (UINT16) (Cell.Height + Cell.OffsetY); + // + // Set BltBuffer to the position of Origin. + // + BltBuffer = Image->Image.Bitmap + (Cell.Height + Cell.OffsetY) * Image->Width - Cell.OffsetX; + GlyphToImage ( + GlyphBuffer, + Foreground, + Background, + Image->Width, + BaseLine, + Cell.Width + Cell.OffsetX, + BaseLine - Cell.OffsetY, + FALSE, + &Cell, + Attributes, + &BltBuffer + ); + } *Blt = Image; if (Baseline != NULL) { @@ -2210,10 +2665,18 @@ Exit: } } - SafeFreePool (SystemDefault); - SafeFreePool (StringInfoOut); - SafeFreePool (String); - SafeFreePool (GlyphBuffer); + if (SystemDefault != NULL) { + FreePool (SystemDefault); + } + if (StringInfoOut != NULL) { + FreePool (StringInfoOut); + } + if (String != NULL) { + FreePool (String); + } + if (GlyphBuffer != NULL) { + FreePool (GlyphBuffer); + } return Status; } @@ -2230,19 +2693,22 @@ Exit: with the first font. On return, points to the returned font handle or points to NULL if there are no more matching fonts. - @param StringInfoIn Upon entry, points to the font to return - information about. - @param StringInfoOut Upon return, contains the matching font's - information. If NULL, then no information is - returned. It's caller's responsibility to free - this buffer. + @param StringInfoIn Upon entry, points to the font to return information + about. If NULL, then the information about the system + default font will be returned. + @param StringInfoOut Upon return, contains the matching font's information. + If NULL, then no information is returned. This buffer + is allocated with a call to the Boot Service AllocatePool(). + It is the caller's responsibility to call the Boot + Service FreePool() when the caller no longer requires + the contents of StringInfoOut. @param String Points to the string which will be tested to determine if all characters are available. If NULL, then any font is acceptable. @retval EFI_SUCCESS Matching font returned successfully. @retval EFI_NOT_FOUND No matching font was found. - @retval EFI_INVALID_PARAMETER StringInfoIn is NULL. + @retval EFI_INVALID_PARAMETER StringInfoIn->FontInfoMask is an invalid combination. @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the request. @@ -2252,7 +2718,7 @@ EFIAPI HiiGetFontInfo ( IN CONST EFI_HII_FONT_PROTOCOL *This, IN OUT EFI_FONT_HANDLE *FontHandle, - IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn, + IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn, OPTIONAL OUT EFI_FONT_DISPLAY_INFO **StringInfoOut, IN CONST EFI_STRING String OPTIONAL ) @@ -2267,51 +2733,76 @@ HiiGetFontInfo ( EFI_STRING StringIn; EFI_FONT_HANDLE LocalFontHandle; - if (This == NULL || StringInfoIn == NULL) { - return EFI_INVALID_PARAMETER; - } - - // - // Check the font information mask to make sure it is valid. - // - if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) == - (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) || - ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == - (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) || - ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == - (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) || - ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) == - (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) || - ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)) == - (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) { + if (This == NULL) { return EFI_INVALID_PARAMETER; } + StringInfoOutLen = 0; FontInfo = NULL; + SystemDefault = NULL; LocalFontHandle = NULL; if (FontHandle != NULL) { LocalFontHandle = *FontHandle; } + Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This); + + // + // Already searched to the end of the whole list, return directly. + // + if (LocalFontHandle == &Private->FontInfoList) { + LocalFontHandle = NULL; + Status = EFI_NOT_FOUND; + goto Exit; + } + // // Get default system display info, if StringInfoIn points to // system display info, return it directly. // - Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This); - if (IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, &SystemDefault, &StringInfoOutLen)) { - if (StringInfoOut != NULL) { - *StringInfoOut = AllocateCopyPool (StringInfoOutLen, (EFI_FONT_DISPLAY_INFO *) StringInfoIn); - if (*StringInfoOut == NULL) { - Status = EFI_OUT_OF_RESOURCES; - LocalFontHandle = NULL; - goto Exit; + // + // System font is the first node. When handle is not NULL, system font can not + // be found any more. + // + if (LocalFontHandle == NULL) { + if (StringInfoOut != NULL) { + *StringInfoOut = AllocateCopyPool (StringInfoOutLen, SystemDefault); + if (*StringInfoOut == NULL) { + Status = EFI_OUT_OF_RESOURCES; + LocalFontHandle = NULL; + goto Exit; + } } - } - LocalFontHandle = Private->FontInfoList.ForwardLink; - Status = EFI_SUCCESS; - goto Exit; + LocalFontHandle = Private->FontInfoList.ForwardLink; + Status = EFI_SUCCESS; + goto Exit; + } else { + LocalFontHandle = NULL; + Status = EFI_NOT_FOUND; + goto Exit; + } + } + + // + // StringInfoIn must not be NULL if it is not system default font info. + // + ASSERT (StringInfoIn != NULL); + // + // Check the font information mask to make sure it is valid. + // + if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) == + (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) || + ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == + (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) || + ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == + (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) || + ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) == + (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) || + ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)) == + (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) { + return EFI_INVALID_PARAMETER; } // @@ -2331,22 +2822,26 @@ HiiGetFontInfo ( if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_SIZE) == EFI_FONT_INFO_SYS_SIZE) { InfoOut.FontInfo.FontSize = SystemDefault->FontInfo.FontSize; - } else if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) { + } + if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) { InfoOut.FontInfo.FontStyle = SystemDefault->FontInfo.FontStyle; - } else if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) { + } + if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) { InfoOut.ForegroundColor = SystemDefault->ForegroundColor; - } else if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) { + } + if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) { InfoOut.BackgroundColor = SystemDefault->BackgroundColor; } - + + ASSERT (FontInfo != NULL); FontInfo->FontSize = InfoOut.FontInfo.FontSize; FontInfo->FontStyle = InfoOut.FontInfo.FontStyle; if (IsFontInfoExisted (Private, FontInfo, &InfoOut.FontInfoMask, LocalFontHandle, &GlobalFont)) { + // + // Test to guarantee all characters are available in the found font. + // if (String != NULL) { - // - // Test to guarantee all characters are available in the found font. - // StringIn = String; while (*StringIn != 0) { Status = FindGlyphBlock (GlobalFont->FontPackage, *StringIn, NULL, NULL, NULL); @@ -2356,29 +2851,27 @@ HiiGetFontInfo ( } StringIn++; } - - // - // Write to output parameter - // - if (StringInfoOut != NULL) { - StringInfoOutLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (EFI_FONT_INFO) + GlobalFont->FontInfoSize; - *StringInfoOut = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (StringInfoOutLen); - if (*StringInfoOut == NULL) { - Status = EFI_OUT_OF_RESOURCES; - LocalFontHandle = NULL; - goto Exit; - } - CopyMem (*StringInfoOut, &InfoOut, sizeof (EFI_FONT_DISPLAY_INFO)); - CopyMem (&(*StringInfoOut)->FontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize); + } + // + // Write to output parameter + // + if (StringInfoOut != NULL) { + StringInfoOutLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (EFI_FONT_INFO) + GlobalFont->FontInfoSize; + *StringInfoOut = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (StringInfoOutLen); + if (*StringInfoOut == NULL) { + Status = EFI_OUT_OF_RESOURCES; + LocalFontHandle = NULL; + goto Exit; } - LocalFontHandle = GlobalFont->Entry.ForwardLink; - - Status = EFI_SUCCESS; - goto Exit; + + CopyMem (*StringInfoOut, &InfoOut, sizeof (EFI_FONT_DISPLAY_INFO)); + CopyMem (&(*StringInfoOut)->FontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize); } - } else { - LocalFontHandle = NULL; - } + + LocalFontHandle = GlobalFont->Entry.ForwardLink; + Status = EFI_SUCCESS; + goto Exit; + } Status = EFI_NOT_FOUND; @@ -2388,8 +2881,13 @@ Exit: *FontHandle = LocalFontHandle; } - SafeFreePool (SystemDefault); - SafeFreePool (FontInfo); + if (SystemDefault != NULL) { + FreePool (SystemDefault); + } + if (FontInfo != NULL) { + FreePool (FontInfo); + } return Status; } +