Implementation for EFI_HII_FONT_PROTOCOL.\r
\r
\r
-Copyright (c) 2007 - 2008, Intel Corporation\r
+Copyright (c) 2007 - 2009, Intel Corporation\r
All rights reserved. This program and the accompanying materials\r
are licensed and made available under the terms and conditions of the BSD License\r
which accompanies this distribution. The full text of the license may be found at\r
\r
#include "HiiDatabase.h"\r
\r
-EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[16] = {\r
+EFI_GRAPHICS_OUTPUT_BLT_PIXEL mHiiEfiColors[16] = {\r
//\r
// B G R\r
//\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
- Info->ForegroundColor = mEfiColors[Private->Attribute & 0x0f];\r
- Info->BackgroundColor = mEfiColors[Private->Attribute >> 4];\r
+ Info->ForegroundColor = mHiiEfiColors[Private->Attribute & 0x0f];\r
+ Info->BackgroundColor = mHiiEfiColors[Private->Attribute >> 4];\r
Info->FontInfoMask = EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_SYS_STYLE;\r
Info->FontInfo.FontStyle = 0;\r
Info->FontInfo.FontSize = EFI_GLYPH_HEIGHT;\r
\r
Exit:\r
if (SystemInfo == NULL) {\r
- SafeFreePool (SystemDefault); \r
+ if (SystemDefault != NULL) {\r
+ FreePool (SystemDefault);\r
+ }\r
}\r
return Flag;\r
}\r
Status = EFI_SUCCESS;\r
StringIn2 = NULL;\r
SystemDefault = NULL;\r
+ StringIn = NULL;\r
\r
//\r
// Calculate the string output information, including specified color and font .\r
Background = SystemDefault->BackgroundColor;\r
\r
} else {\r
+ //\r
+ // StringInfo must not be NULL if it is not system info.\r
+ //\r
+ ASSERT (StringInfo != NULL);\r
Status = HiiGetFontInfo (This, &FontHandle, (EFI_FONT_DISPLAY_INFO *) StringInfo, &StringInfoOut, NULL);\r
if (Status == EFI_NOT_FOUND) {\r
//\r
Foreground = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->ForegroundColor;\r
Background = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->BackgroundColor;\r
\r
- } else {\r
+ } else if (Status == EFI_SUCCESS) {\r
FontInfo = &StringInfoOut->FontInfo;\r
Height = StringInfoOut->FontInfo.FontSize;\r
Foreground = StringInfoOut->ForegroundColor;\r
Background = StringInfoOut->BackgroundColor;\r
+ } else {\r
+ goto Exit;\r
}\r
}\r
\r
//\r
\r
StringPtr = String;\r
- StringIn = NULL;\r
\r
//\r
// Ignore line-break characters only. Hyphens or dash character will be displayed\r
Status = GetGlyphBuffer (Private, *StringPtr, FontInfo, &GlyphBuf[Index], &Cell[Index], &Attributes[Index]);\r
if (Status == EFI_NOT_FOUND) {\r
if ((Flags & EFI_HII_IGNORE_IF_NO_GLYPH) == EFI_HII_IGNORE_IF_NO_GLYPH) {\r
- SafeFreePool (GlyphBuf[Index]);\r
+ if (GlyphBuf[Index] != NULL) {\r
+ FreePool (GlyphBuf[Index]);\r
+ }\r
GlyphBuf[Index] = NULL;\r
StringPtr++;\r
} else {\r
0\r
);\r
if (EFI_ERROR (Status)) {\r
- SafeFreePool (BltBuffer);\r
+ FreePool (BltBuffer);\r
goto Exit;\r
}\r
\r
- SafeFreePool (BltBuffer);\r
+ FreePool (BltBuffer);\r
\r
} else {\r
for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
Image->Height = 600;\r
Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height *sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
if (Image->Image.Bitmap == NULL) {\r
- SafeFreePool (Image);\r
+ FreePool (Image);\r
return EFI_OUT_OF_RESOURCES;\r
}\r
\r
Exit:\r
\r
for (Index = 0; Index < MAX_STRING_LENGTH; Index++) {\r
- SafeFreePool (GlyphBuf[Index]);\r
+ if (GlyphBuf[Index] != NULL) {\r
+ FreePool (GlyphBuf[Index]);\r
+ }\r
+ }\r
+ if (StringIn != NULL) {\r
+ FreePool (StringIn);\r
+ }\r
+ if (StringIn2 != NULL) {\r
+ FreePool (StringIn2);\r
+ }\r
+ if (StringInfoOut != NULL) {\r
+ FreePool (StringInfoOut);\r
+ }\r
+ if (RowInfo != NULL) {\r
+ FreePool (RowInfo);\r
+ }\r
+ if (SystemDefault != NULL) {\r
+ FreePool (SystemDefault);\r
+ }\r
+ if (GlyphBuf != NULL) {\r
+ FreePool (GlyphBuf);\r
+ }\r
+ if (Cell != NULL) {\r
+ FreePool (Cell);\r
+ }\r
+ if (Attributes != NULL) {\r
+ FreePool (Attributes);\r
}\r
- SafeFreePool (StringIn);\r
- SafeFreePool (StringIn2);\r
- SafeFreePool (StringInfoOut);\r
- SafeFreePool (RowInfo);\r
- SafeFreePool (SystemDefault);\r
- SafeFreePool (GlyphBuf);\r
- SafeFreePool (Cell);\r
- SafeFreePool (Attributes);\r
\r
return Status;\r
}\r
{\r
EFI_STATUS Status;\r
HII_DATABASE_PRIVATE_DATA *Private;\r
+ EFI_HII_STRING_PROTOCOL *HiiString;\r
EFI_STRING String;\r
UINTN StringSize;\r
UINTN FontLen;\r
EFI_FONT_INFO *StringFontInfo;\r
EFI_FONT_DISPLAY_INFO *NewStringInfo;\r
- CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];\r
+ CHAR8 TempSupportedLanguages;\r
+ CHAR8 *SupportedLanguages;\r
+ UINTN SupportedLanguagesSize;\r
+ CHAR8 *CurrentLanguage;\r
+ CHAR8 *BestLanguage;\r
\r
if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {\r
return EFI_INVALID_PARAMETER;\r
}\r
\r
//\r
- // When Language points to NULL, current system language is used.\r
+ // Initialize string pointers to be NULL\r
//\r
- if (Language != NULL) {\r
- AsciiStrCpy (CurrentLang, (CHAR8 *) Language);\r
- } else {\r
- GetCurrentLanguage (CurrentLang);\r
- }\r
+ SupportedLanguages = NULL;\r
+ CurrentLanguage = NULL;\r
+ BestLanguage = NULL;\r
+ String = NULL;\r
+ StringInfo = NULL;\r
+ StringFontInfo = NULL;\r
+ NewStringInfo = NULL;\r
\r
//\r
// Get the string to be displayed.\r
//\r
+ Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
+ HiiString = &Private->HiiString;\r
\r
+ //\r
+ // Get the size of supported language.\r
+ //\r
+ SupportedLanguagesSize = 0;\r
+ Status = HiiString->GetLanguages (\r
+ HiiString,\r
+ PackageList,\r
+ &TempSupportedLanguages,\r
+ &SupportedLanguagesSize\r
+ );\r
+ if (Status != EFI_BUFFER_TOO_SMALL) {\r
+ return Status;\r
+ }\r
+\r
+ SupportedLanguages = AllocatePool (SupportedLanguagesSize);\r
+ if (SupportedLanguages == NULL) {\r
+ return EFI_OUT_OF_RESOURCES;\r
+ }\r
+\r
+ Status = HiiString->GetLanguages (\r
+ HiiString,\r
+ PackageList,\r
+ SupportedLanguages,\r
+ &SupportedLanguagesSize\r
+ );\r
+ if (EFI_ERROR (Status)) {\r
+ goto Exit;\r
+ }\r
+ \r
+ if (Language == NULL) {\r
+ Language = "";\r
+ }\r
+ CurrentLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
+ BestLanguage = GetBestLanguage (\r
+ SupportedLanguages,\r
+ FALSE,\r
+ Language,\r
+ (CurrentLanguage == NULL) ? CurrentLanguage : "",\r
+ (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),\r
+ NULL\r
+ );\r
+ if (BestLanguage == NULL) {\r
+ Status = EFI_NOT_FOUND;\r
+ goto Exit;\r
+ }\r
+ \r
StringSize = MAX_STRING_LENGTH;\r
String = (EFI_STRING) AllocateZeroPool (StringSize);\r
if (String == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Exit;\r
}\r
\r
- Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);\r
- StringFontInfo = NULL;\r
- NewStringInfo = NULL;\r
- \r
- Status = Private->HiiString.GetString (\r
- &Private->HiiString,\r
- CurrentLang,\r
- PackageList,\r
- StringId,\r
- String,\r
- &StringSize,\r
- &StringFontInfo\r
- );\r
+ Status = HiiString->GetString (\r
+ HiiString,\r
+ BestLanguage,\r
+ PackageList,\r
+ StringId,\r
+ String,\r
+ &StringSize,\r
+ &StringFontInfo\r
+ );\r
if (Status == EFI_BUFFER_TOO_SMALL) {\r
- SafeFreePool (String);\r
+ FreePool (String);\r
String = (EFI_STRING) AllocateZeroPool (StringSize);\r
if (String == NULL) {\r
- return EFI_OUT_OF_RESOURCES;\r
+ Status = EFI_OUT_OF_RESOURCES;\r
+ goto Exit;\r
}\r
- Status = Private->HiiString.GetString (\r
- &Private->HiiString,\r
- Language,\r
- PackageList,\r
- StringId,\r
- String,\r
- &StringSize,\r
- NULL\r
- );\r
-\r
+ Status = HiiString->GetString (\r
+ HiiString,\r
+ BestLanguage,\r
+ PackageList,\r
+ StringId,\r
+ String,\r
+ &StringSize,\r
+ NULL\r
+ );\r
}\r
\r
if (EFI_ERROR (Status)) {\r
- goto Exit;\r
+ goto Exit;\r
}\r
\r
//\r
);\r
\r
Exit:\r
- SafeFreePool (String);\r
- SafeFreePool (StringFontInfo);\r
- SafeFreePool (NewStringInfo);\r
+ if (SupportedLanguages != NULL) {\r
+ FreePool (SupportedLanguages);\r
+ }\r
+ if (CurrentLanguage != NULL) {\r
+ FreePool (CurrentLanguage);\r
+ }\r
+ if (BestLanguage != NULL) {\r
+ FreePool (BestLanguage);\r
+ }\r
+ if (String != NULL) {\r
+ FreePool (String);\r
+ }\r
+ if (StringFontInfo != NULL) {\r
+ FreePool (StringFontInfo);\r
+ }\r
+ if (NewStringInfo != NULL) {\r
+ FreePool (NewStringInfo);\r
+ }\r
\r
return Status;\r
}\r
\r
Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
if (Image->Image.Bitmap == NULL) {\r
- SafeFreePool (Image);\r
+ FreePool (Image);\r
Status = EFI_OUT_OF_RESOURCES;\r
goto Exit;\r
}\r
}\r
}\r
\r
- SafeFreePool (SystemDefault);\r
- SafeFreePool (StringInfoOut);\r
- SafeFreePool (String);\r
- SafeFreePool (GlyphBuffer);\r
+ if (SystemDefault != NULL) {\r
+ FreePool (SystemDefault);\r
+ }\r
+ if (StringInfoOut != NULL) {\r
+ FreePool (StringInfoOut);\r
+ }\r
+ if (String != NULL) {\r
+ FreePool (String);\r
+ }\r
+ if (GlyphBuffer != NULL) {\r
+ FreePool (GlyphBuffer);\r
+ }\r
\r
return Status;\r
}\r
goto Exit;\r
}\r
}\r
-\r
+ \r
+ //\r
+ // StringInfoIn must not be NULL if it is not system default font info.\r
+ //\r
+ ASSERT (StringInfoIn != NULL);\r
//\r
// Check the font information mask to make sure it is valid.\r
//\r
*FontHandle = LocalFontHandle;\r
}\r
\r
- SafeFreePool (SystemDefault);\r
- SafeFreePool (FontInfo);\r
+ if (SystemDefault != NULL) {\r
+ FreePool (SystemDefault);\r
+ }\r
+ if (FontInfo != NULL) {\r
+ FreePool (FontInfo);\r
+ }\r
return Status;\r
}\r
\r