]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
rename array name to avoid naming collision.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Font.c
index a9d9571f836a0501118a8898bed7e0216ece1748..b899cec3605888834a6ebfe716619e7565756a7f 100644 (file)
@@ -2,7 +2,7 @@
 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
@@ -16,7 +16,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
 \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
@@ -912,8 +912,8 @@ GetSystemFont (
     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
@@ -1024,7 +1024,9 @@ IsSystemFontInfo (
 \r
 Exit:\r
   if (SystemInfo == NULL) {\r
-    SafeFreePool (SystemDefault);    \r
+    if (SystemDefault != NULL) {\r
+      FreePool (SystemDefault);\r
+    }\r
   }\r
   return Flag;\r
 }\r
@@ -1564,6 +1566,7 @@ HiiStringToImage (
   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
@@ -1582,6 +1585,10 @@ HiiStringToImage (
     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
@@ -1594,11 +1601,13 @@ HiiStringToImage (
       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
@@ -1607,7 +1616,6 @@ HiiStringToImage (
   //\r
 \r
   StringPtr = String;\r
-  StringIn  = NULL;\r
 \r
   //\r
   // Ignore line-break characters only. Hyphens or dash character will be displayed\r
@@ -1646,7 +1654,9 @@ HiiStringToImage (
     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
@@ -1871,11 +1881,11 @@ HiiStringToImage (
                                         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
@@ -1938,7 +1948,7 @@ HiiStringToImage (
     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
@@ -1970,16 +1980,34 @@ HiiStringToImage (
 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
@@ -2065,12 +2093,17 @@ HiiStringIdToImage (
 {\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
@@ -2081,57 +2114,104 @@ HiiStringIdToImage (
   }\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
@@ -2180,9 +2260,24 @@ HiiStringIdToImage (
            );\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
@@ -2296,7 +2391,7 @@ HiiGetGlyph (
 \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
@@ -2337,10 +2432,18 @@ Exit:
     }\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
@@ -2446,7 +2549,11 @@ HiiGetFontInfo (
       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
@@ -2539,8 +2646,12 @@ Exit:
     *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