X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=blobdiff_plain;f=MdeModulePkg%2FUniversal%2FHiiDatabaseDxe%2FFont.c;h=5ecd6bd4a1e4f0d32e9c857a8451c7d7660b5824;hp=4d2fcc081b5cf4ee5a0c5f6d536b24cba5b48b93;hb=d2970bbc1d88dbde480e7eef57f3ddcedd39ad08;hpb=fbf82a2cf22e0073b3a221629562184b129925ac diff --git a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c index 4d2fcc081b..5ecd6bd4a1 100644 --- a/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c +++ b/MdeModulePkg/Universal/HiiDatabaseDxe/Font.c @@ -2,7 +2,7 @@ Implementation for EFI_HII_FONT_PROTOCOL. -Copyright (c) 2007 - 2011, Intel Corporation. All rights reserved.
+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 @@ -704,10 +704,6 @@ FindGlyphBlock ( (UINT8 *) FontPackage->FontPkgHdr + 3 * sizeof (UINT32), sizeof (EFI_HII_GLYPH_INFO) ); - BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY); - if (MinOffsetY > LocalCell.OffsetY) { - MinOffsetY = LocalCell.OffsetY; - } } BlockPtr = FontPackage->GlyphBlock; @@ -757,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; @@ -770,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; @@ -793,7 +789,7 @@ FindGlyphBlock ( 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, @@ -933,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; } @@ -971,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; @@ -982,7 +981,8 @@ 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; @@ -993,7 +993,7 @@ GetSystemFont ( 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) { @@ -1040,8 +1040,12 @@ IsSystemFontInfo ( return TRUE; } + SystemDefault = NULL; + DefaultLen = 0; + Status = GetSystemFont (Private, &SystemDefault, &DefaultLen); ASSERT_EFI_ERROR (Status); + ASSERT ((SystemDefault != NULL) && (DefaultLen != 0)); // // Record the system default info. @@ -1440,6 +1444,7 @@ IsLineBreak ( // // Mandatory line break characters, which force a line-break // + case 0x000A: case 0x000C: case 0x000D: case 0x2028: @@ -1604,6 +1609,7 @@ HiiStringToImage ( UINTN StrLength; EFI_GRAPHICS_OUTPUT_BLT_PIXEL *RowBufferPtr; HII_GLOBAL_FONT_INFO *GlobalFont; + UINT32 PreInitBkgnd; // // Check incoming parameters. @@ -1687,6 +1693,7 @@ 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; @@ -1819,7 +1826,13 @@ HiiStringToImage ( // Image = *Blt; BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX; - ASSERT (Image->Height >= BltY); + if (Image->Height < BltY) { + // + // 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; @@ -2033,6 +2046,11 @@ HiiStringToImage ( goto Exit; } // + // 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; @@ -2140,9 +2158,8 @@ HiiStringToImage ( NextLine: // - // Recalculate the start point of X/Y axis to draw multi-lines with the order of top-to-down + // Recalculate the start point of Y axis to draw multi-lines with the order of top-to-down // - BltX = 0; BltY += RowInfo[RowIndex].LineHeight; RowIndex++; @@ -2298,6 +2315,7 @@ HiiStringIdToImage ( EFI_STRING String; UINTN StringSize; UINTN FontLen; + UINTN NameSize; EFI_FONT_INFO *StringFontInfo; EFI_FONT_DISPLAY_INFO *NewStringInfo; CHAR8 TempSupportedLanguages; @@ -2362,7 +2380,7 @@ HiiStringIdToImage ( if (Language == NULL) { Language = ""; } - CurrentLanguage = GetEfiGlobalVariable (L"PlatformLang"); + GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLanguage, NULL); BestLanguage = GetBestLanguage ( SupportedLanguages, FALSE, @@ -2420,7 +2438,8 @@ HiiStringIdToImage ( // StringFontInfo equals NULL means system default font attaches with the string block. // if (StringFontInfo != NULL && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, NULL, NULL)) { - FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + StrSize (StringFontInfo->FontName); + NameSize = StrSize (StringFontInfo->FontName); + FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize; NewStringInfo = AllocateZeroPool (FontLen); if (NewStringInfo == NULL) { Status = EFI_OUT_OF_RESOURCES; @@ -2429,7 +2448,7 @@ HiiStringIdToImage ( NewStringInfo->FontInfoMask = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR; NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle; NewStringInfo->FontInfo.FontSize = StringFontInfo->FontSize; - StrCpy (NewStringInfo->FontInfo.FontName, StringFontInfo->FontName); + StrCpyS (NewStringInfo->FontInfo.FontName, NameSize / sizeof (CHAR16), StringFontInfo->FontName); Status = HiiStringToImage ( This, @@ -2574,6 +2593,7 @@ HiiGetGlyph ( Foreground = StringInfoOut->ForegroundColor; Background = StringInfoOut->BackgroundColor; } else { + ASSERT (SystemDefault != NULL); Foreground = SystemDefault->ForegroundColor; Background = SystemDefault->BackgroundColor; } @@ -2673,14 +2693,15 @@ 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. - 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. 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. @@ -2716,6 +2737,7 @@ HiiGetFontInfo ( return EFI_INVALID_PARAMETER; } + StringInfoOutLen = 0; FontInfo = NULL; SystemDefault = NULL; LocalFontHandle = NULL;