]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
Roll back changes to apply GetBestLanguage() in HiiDataBase. Exact language match...
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Font.c
index 82f47163b7dd468d707ab9452edc127735ffcbd6..4bb72c81d417cc2cf094b2100d32965049a03e02 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
@@ -1344,15 +1344,14 @@ IsFontInfoExisted (
 /**\r
   Check whether the unicode represents a line break or not.\r
 \r
-  This is a internal function.\r
+  This is a internal function. Please see Section 27.2.6 of the UEFI Specification\r
+  for a description of the supported string format.\r
 \r
   @param  Char                    Unicode character\r
 \r
-  @retval 0                       Yes, it is a line break.\r
-  @retval 1                       Yes, it is a hyphen that desires a line break\r
-                                  after this character.\r
-  @retval 2                       Yes, it is a dash that desires a line break\r
-                                  before and after it.\r
+  @retval 0                       Yes, it forces a line break.\r
+  @retval 1                       Yes, it presents a line break opportunity\r
+  @retval 2                       Yes, it requires a line break happen before and after it.\r
   @retval -1                      No, it is not a link break.\r
 \r
 **/\r
@@ -1361,61 +1360,63 @@ IsLineBreak (
   IN  CHAR16    Char\r
   )\r
 {\r
-  UINT8         Byte1;\r
-  UINT8         Byte2;\r
-\r
-  //\r
-  // In little endian, Byte1 is the low byte of Char, Byte2 is the high byte of Char.\r
-  //\r
-  Byte1 = *((UINT8 *) (&Char));\r
-  Byte2 = *(((UINT8 *) (&Char) + 1));\r
-\r
-  if (Byte2 == 0x20) {\r
-    switch (Byte1) {\r
-    case 0x00:\r
-    case 0x01:\r
-    case 0x02:\r
-    case 0x03:\r
-    case 0x04:\r
-    case 0x05:\r
-    case 0x06:\r
-    case 0x08:\r
-    case 0x09:\r
-    case 0x0A:\r
-    case 0x0B:\r
-    case 0x28:\r
-    case 0x29:\r
-    case 0x5F:\r
-      return 0;\r
-    case 0x10:\r
-    case 0x12:\r
-    case 0x13:\r
-      return 1;\r
-    case 0x14:\r
-      //\r
-      // BUGBUG: Does it really require line break before it and after it?\r
-      //\r
-      return 2;\r
-    }\r
-  } else if (Byte2 == 0x00) {\r
-    switch (Byte1) {\r
-    case 0x20:\r
-    case 0x0C:\r
-    case 0x0D:\r
-      return 0;\r
-    }\r
-  }\r
-\r
   switch (Char) {\r
-    case 0x1680:\r
+    //\r
+    // Mandatory line break characters, which force a line-break\r
+    //\r
+    case 0x000C:\r
+    case 0x000D:\r
+    case 0x2028:\r
+    case 0x2029:\r
       return 0;\r
+    //\r
+    // Space characters, which is taken as a line-break opportunity\r
+    //\r
+    case 0x0020:\r
+    case 0x1680:\r
+    case 0x2000:\r
+    case 0x2001:\r
+    case 0x2002:\r
+    case 0x2003:\r
+    case 0x2004:\r
+    case 0x2005:\r
+    case 0x2006:\r
+    case 0x2008:\r
+    case 0x2009:\r
+    case 0x200A:\r
+    case 0x205F:\r
+    //\r
+    // In-Word Break Opportunities\r
+    //\r
+    case 0x200B:\r
+      return 1;\r
+    //\r
+    // A space which is not a line-break opportunity\r
+    //\r
+    case 0x00A0:\r
+    case 0x202F:\r
+    //\r
+    // A hyphen which is not a line-break opportunity\r
+    //\r
+    case 0x2011:\r
+      return -1;\r
+    //\r
+    // Hyphen characters which describe line break opportunities after the character\r
+    //\r
     case 0x058A:\r
+    case 0x2010:\r
+    case 0x2012:\r
+    case 0x2013:\r
     case 0x0F0B:\r
     case 0x1361:\r
     case 0x17D5:\r
       return 1;\r
+    //\r
+    // A hyphen which describes line break opportunities before and after them, but not between a pair of them\r
+    //\r
+    case 0x2014:\r
+      return 2;\r
   }\r
-\r
   return -1;\r
 }\r
 \r
@@ -1520,6 +1521,7 @@ HiiStringToImage (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL       *BufferPtr;\r
   UINTN                               RowInfoSize;\r
   BOOLEAN                             LineBreak;\r
+  UINTN                               StrLength;\r
 \r
   //\r
   // Check incoming parameters.\r
@@ -1555,11 +1557,35 @@ HiiStringToImage (
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
-  GlyphBuf = (UINT8 **) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (UINT8 *));\r
+  if (*Blt == NULL) {\r
+    //\r
+    // Create a new bitmap and draw the string onto this image.\r
+    //\r
+    Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
+    if (Image == NULL) {\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+    Image->Width  = 800;\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
+      FreePool (Image);\r
+      return EFI_OUT_OF_RESOURCES;\r
+    }\r
+\r
+    //\r
+    // Other flags are not permitted when Blt is NULL.\r
+    //\r
+    Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK;\r
+    *Blt = Image;\r
+  }\r
+\r
+  StrLength = StrLen(String);\r
+  GlyphBuf = (UINT8 **) AllocateZeroPool (StrLength * sizeof (UINT8 *));\r
   ASSERT (GlyphBuf != NULL);\r
-  Cell = (EFI_HII_GLYPH_INFO *) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (EFI_HII_GLYPH_INFO));\r
+  Cell = (EFI_HII_GLYPH_INFO *) AllocateZeroPool (StrLength * sizeof (EFI_HII_GLYPH_INFO));\r
   ASSERT (Cell != NULL);\r
-  Attributes = (UINT8 *) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (UINT8));\r
+  Attributes = (UINT8 *) AllocateZeroPool (StrLength * sizeof (UINT8));\r
   ASSERT (Attributes != NULL);\r
 \r
   RowInfo       = NULL;\r
@@ -1585,6 +1611,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
@@ -1645,16 +1675,14 @@ HiiStringToImage (
   }\r
   Index     = 0;\r
   StringTmp = StringIn2;\r
-\r
-  while (*StringPtr != 0 && Index < MAX_STRING_LENGTH) {\r
+  StrLength = StrLen(StringPtr);\r
+  while (*StringPtr != 0 && Index < StrLength) {\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
-        if (GlyphBuf[Index] != NULL) {\r
-          FreePool (GlyphBuf[Index]);\r
-        }\r
         GlyphBuf[Index] = NULL;\r
-        StringPtr++;\r
+        *StringTmp++ = *StringPtr++;\r
+        Index++;\r
       } else {\r
         //\r
         // Unicode 0xFFFD must exist in current hii database if this flag is not set.\r
@@ -1690,160 +1718,172 @@ HiiStringToImage (
   // to an existing image (bitmap or screen depending on flags) pointed by "*Blt".\r
   // Otherwise render this string to a new allocated image and output it.\r
   //\r
-  if (*Blt != NULL) {\r
-    Image     = *Blt;\r
-    BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX;\r
-    MaxRowNum = (UINT16) (Image->Height / Height);\r
-    if (Image->Height % Height != 0) {\r
-      MaxRowNum++;\r
-    }\r
+  Image     = *Blt;\r
+  BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX;\r
+  MaxRowNum = (UINT16) (Image->Height / Height);\r
+  if (Image->Height % Height != 0) {\r
+    MaxRowNum++;\r
+  }\r
 \r
-    RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO));\r
-    if (RowInfo == NULL) {\r
-      Status = EFI_OUT_OF_RESOURCES;\r
+  RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO));\r
+  if (RowInfo == NULL) {\r
+    Status = EFI_OUT_OF_RESOURCES;\r
+    goto Exit;\r
+  }\r
+\r
+  //\r
+  // Format the glyph buffer according to flags.\r
+  //\r
+\r
+  Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE);\r
+  if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
+    //\r
+    // Don't draw at all if there is only one row and\r
+    // the row's bottom-most on pixel cannot fit.\r
+    //\r
+    if (MaxRowNum == 1 && SysFontFlag) {\r
+      Status = EFI_SUCCESS;\r
       goto Exit;\r
     }\r
+  }\r
+\r
+  for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) {\r
+    LineWidth      = 0;\r
+    LineHeight     = 0;\r
+    BaseLineOffset = 0;\r
+    LineBreak      = FALSE;\r
 \r
     //\r
-    // Format the glyph buffer according to flags.\r
+    // Calculate how many characters there are in a row.\r
     //\r
+    RowInfo[RowIndex].StartIndex = Index;\r
 \r
-    Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE);\r
-    if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
-      //\r
-      // Don't draw at all if there is only one row and\r
-      // the row's bottom-most on pixel cannot fit.\r
-      //\r
-      if (MaxRowNum == 1 && SysFontFlag) {\r
-        Status = EFI_SUCCESS;\r
-        goto Exit;\r
+    while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) {\r
+      if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0 &&\r
+          (Flags & EFI_HII_OUT_FLAG_WRAP) == 0 &&\r
+           IsLineBreak (StringPtr[Index]) == 0) {\r
+        //\r
+        // It forces a line break that ends this row.\r
+        //\r
+        Index++;\r
+        break;\r
       }\r
-    }\r
-\r
-    for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) {\r
-      LineWidth      = 0;\r
-      LineHeight     = 0;\r
-      BaseLineOffset = 0;\r
-      LineBreak      = FALSE;\r
 \r
       //\r
-      // Calculate how many characters there are in a row.\r
+      // If the glyph of the character is existing, then accumulate the actual printed width\r
       //\r
-      RowInfo[RowIndex].StartIndex = Index;\r
-\r
-      while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) {\r
+      if (GlyphBuf[Index] != NULL) {\r
         LineWidth += (UINTN) Cell[Index].AdvanceX;\r
         if (LineHeight < Cell[Index].Height) {\r
           LineHeight = (UINTN) Cell[Index].Height;\r
         }\r
+      }\r
 \r
-        if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0 &&\r
-            (Flags & EFI_HII_OUT_FLAG_WRAP) == 0 &&\r
-             IsLineBreak (StringPtr[Index]) > 0) {\r
-          //\r
-          // It is a line break that ends this row.\r
-          //\r
-          Index++;\r
-          break;\r
-        }\r
+      Index++;\r
+    }\r
 \r
-        Index++;\r
-      }\r
+    //\r
+    // If this character is the last character of a row, we need not\r
+    // draw its (AdvanceX - Width) for next character.\r
+    //\r
+    Index--;\r
+    if (!SysFontFlag) {\r
+      LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width);\r
+    }\r
 \r
+    //\r
+    // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.\r
+    //\r
+    if (LineWidth + BltX <= Image->Width ||\r
+      (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) {\r
       //\r
-      // If this character is the last character of a row, we need not\r
-      // draw its (AdvanceX - Width) for next character.\r
+      // Record right-most character in RowInfo even if it is partially displayed.\r
       //\r
-      Index--;\r
-      if (!SysFontFlag) {\r
-        LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width);\r
-      }\r
-\r
+      RowInfo[RowIndex].EndIndex       = Index;\r
+      RowInfo[RowIndex].LineWidth      = LineWidth;\r
+      RowInfo[RowIndex].LineHeight     = LineHeight;\r
+      RowInfo[RowIndex].BaselineOffset = BaseLineOffset;\r
+    } else {\r
       //\r
-      // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break\r
-      // opportunity prior to a character whose right-most extent would exceed Width.\r
-      // Search the right-most line-break opportunity here.\r
+      // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character\r
+      // if its right-most on pixel cannot fit.\r
       //\r
-      if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP) {\r
-        if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {\r
-          for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {\r
-            if (IsLineBreak (StringPtr[Index1]) > 0) {\r
-              LineBreak = TRUE;\r
-              RowInfo[RowIndex].EndIndex = Index1 - 1;\r
-              break;\r
-            }\r
-          }\r
+      if (Index > 0) {\r
+        RowInfo[RowIndex].EndIndex       = Index - 1;\r
+        RowInfo[RowIndex].LineWidth      = LineWidth - Cell[Index].AdvanceX;\r
+        RowInfo[RowIndex].BaselineOffset = BaseLineOffset;\r
+        if (LineHeight > Cell[Index - 1].Height) {\r
+          LineHeight = Cell[Index - 1].Height;\r
         }\r
+        RowInfo[RowIndex].LineHeight     = LineHeight;\r
+      } else {\r
         //\r
-        // If no line-break opportunity can be found, then the text will\r
-        // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.\r
+        // There is only one column and it can not be drawn so that return directly.\r
         //\r
-        if (!LineBreak) {\r
-          Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP);\r
-          Flags |= EFI_HII_OUT_FLAG_CLIP_CLEAN_X;\r
-        }\r
+        Status = EFI_SUCCESS;\r
+        goto Exit;\r
       }\r
+    }\r
 \r
+    //\r
+    // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break\r
+    // opportunity prior to a character whose right-most extent would exceed Width.\r
+    // Search the right-most line-break opportunity here.\r
+    //\r
+    if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP) {\r
+      if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {\r
+        for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {\r
+          if (IsLineBreak (StringPtr[Index1]) > 0) {\r
+            LineBreak = TRUE;\r
+            RowInfo[RowIndex].EndIndex = Index1 - 1;\r
+            //\r
+            // relocate to the character after the right-most line break opportunity of this line\r
+            //\r
+            Index = Index1 + 1;\r
+            break;\r
+          }\r
+        }\r
+      }\r
       //\r
-      // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.\r
+      // If no line-break opportunity can be found, then the text will\r
+      // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.\r
       //\r
-      if (LineWidth + BltX <= Image->Width ||\r
-        (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) {\r
-        //\r
-        // Record right-most character in RowInfo even if it is partially displayed.\r
-        //\r
-        RowInfo[RowIndex].EndIndex       = Index;\r
-        RowInfo[RowIndex].LineWidth      = LineWidth;\r
-        RowInfo[RowIndex].LineHeight     = LineHeight;\r
-        RowInfo[RowIndex].BaselineOffset = BaseLineOffset;\r
-      } else {\r
+      if (!LineBreak) {\r
+        Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP);\r
+        Flags |= EFI_HII_OUT_FLAG_CLIP_CLEAN_X;\r
+      }\r
+    }\r
+\r
+    //\r
+    // Clip the final row if the row's bottom-most on pixel cannot fit when\r
+    // EFI_HII_OUT_FLAG_CLEAN_Y is set.\r
+    //\r
+    if (RowIndex == MaxRowNum - 1 && Image->Height < LineHeight) {\r
+      LineHeight = Image->Height;\r
+      if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
         //\r
-        // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character\r
-        // if its right-most on pixel cannot fit.\r
+        // Don't draw at all if the row's bottom-most on pixel cannot fit.\r
         //\r
-        if (Index > 0) {\r
-          RowInfo[RowIndex].EndIndex       = Index - 1;\r
-          RowInfo[RowIndex].LineWidth      = LineWidth - Cell[Index].AdvanceX;\r
-          RowInfo[RowIndex].BaselineOffset = BaseLineOffset;\r
-          if (LineHeight > Cell[Index - 1].Height) {\r
-            LineHeight = Cell[Index - 1].Height;\r
-          }\r
-          RowInfo[RowIndex].LineHeight     = LineHeight;\r
-        } else {\r
-          //\r
-          // There is only one column and it can not be drawn so that return directly.\r
-          //\r
-          Status = EFI_SUCCESS;\r
-          goto Exit;\r
-        }\r
+        break;\r
       }\r
+    }\r
 \r
-      //\r
-      // Clip the final row if the row's bottom-most on pixel cannot fit when\r
-      // EFI_HII_OUT_FLAG_CLEAN_Y is set.\r
-      //\r
-      if (RowIndex == MaxRowNum - 1 && Image->Height < LineHeight) {\r
-        LineHeight = Image->Height;\r
-        if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {\r
+    //\r
+    // Draw it to screen or existing bitmap depending on whether\r
+    // EFI_HII_DIRECT_TO_SCREEN is set.\r
+    //\r
+    if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r
+      BltBuffer = AllocateZeroPool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
+      if (BltBuffer == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+      BufferPtr = BltBuffer;\r
+      for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
+        if (GlyphBuf[Index1] != NULL) {\r
           //\r
-          // Don't draw at all if the row's bottom-most on pixel cannot fit.\r
+          // Only BLT these character which have corrsponding glyph in font basebase.\r
           //\r
-          break;\r
-        }\r
-      }\r
-\r
-      //\r
-      // Draw it to screen or existing bitmap depending on whether\r
-      // EFI_HII_DIRECT_TO_SCREEN is set.\r
-      //\r
-      if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {\r
-        BltBuffer = AllocateZeroPool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));\r
-        if (BltBuffer == NULL) {\r
-          Status = EFI_OUT_OF_RESOURCES;\r
-          goto Exit;\r
-        }\r
-        BufferPtr = BltBuffer;\r
-        for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
           GlyphToImage (\r
             GlyphBuf[Index1],\r
             Foreground,\r
@@ -1854,37 +1894,50 @@ HiiStringToImage (
             &Cell[Index1],\r
             Attributes[Index1],\r
             &BufferPtr\r
-            );\r
-          if (ColumnInfoArray != NULL) {\r
-            if (Index1 == RowInfo[RowIndex].StartIndex) {\r
-              *ColumnInfoArray = 0;\r
-            } else {\r
-              *ColumnInfoArray = Cell[Index1 -1].AdvanceX;\r
-            }\r
-            ColumnInfoArray++;\r
-          }\r
+          );\r
         }\r
-        Status = Image->Image.Screen->Blt (\r
-                                        Image->Image.Screen,\r
-                                        BltBuffer,\r
-                                        EfiBltBufferToVideo,\r
-                                        0,\r
-                                        0,\r
-                                        BltX,\r
-                                        BltY,\r
-                                        RowInfo[RowIndex].LineWidth,\r
-                                        RowInfo[RowIndex].LineHeight,\r
-                                        0\r
-                                        );\r
-        if (EFI_ERROR (Status)) {\r
-          FreePool (BltBuffer);\r
-          goto Exit;\r
+        if (ColumnInfoArray != NULL) {\r
+          if (GlyphBuf[Index1] == NULL) {\r
+            *ColumnInfoArray = 0;\r
+          } else {\r
+            *ColumnInfoArray = Cell[Index1 -1].AdvanceX;\r
+          }\r
+          ColumnInfoArray++;\r
         }\r
+      }\r
+      //\r
+      // Recalculate the start point of X/Y axis to draw multi-lines with the order of top-to-down\r
+      //\r
+      if (RowIndex != 0) {\r
+        BltX = 0;\r
+        BltY += RowInfo[RowIndex].LineHeight;\r
+      }\r
 \r
+      Status = Image->Image.Screen->Blt (\r
+                                      Image->Image.Screen,\r
+                                      BltBuffer,\r
+                                      EfiBltBufferToVideo,\r
+                                      0,\r
+                                      0,\r
+                                      BltX,\r
+                                      BltY,\r
+                                      RowInfo[RowIndex].LineWidth,\r
+                                      RowInfo[RowIndex].LineHeight,\r
+                                      0\r
+                                      );\r
+      if (EFI_ERROR (Status)) {\r
         FreePool (BltBuffer);\r
+        goto Exit;\r
+      }\r
 \r
-      } else {\r
-        for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
+      FreePool (BltBuffer);\r
+\r
+    } else {\r
+      for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
+        if (GlyphBuf[Index1] != NULL) {\r
+          //\r
+          // Only BLT these character which have corrsponding glyph in font basebase.\r
+          //\r
           GlyphToImage (\r
             GlyphBuf[Index1],\r
             Foreground,\r
@@ -1895,87 +1948,55 @@ HiiStringToImage (
             &Cell[Index1],\r
             Attributes[Index1],\r
             &BufferPtr\r
-            );\r
-          if (ColumnInfoArray != NULL) {\r
-            if (Index1 == RowInfo[RowIndex].StartIndex) {\r
-              *ColumnInfoArray = 0;\r
-            } else {\r
-              *ColumnInfoArray = Cell[Index1 -1].AdvanceX;\r
-            }\r
-            ColumnInfoArray++;\r
+          );\r
+        }\r
+        if (ColumnInfoArray != NULL) {\r
+          if (GlyphBuf[Index1] == NULL) {\r
+            *ColumnInfoArray = 0;\r
+          } else {\r
+            *ColumnInfoArray = Cell[Index1 -1].AdvanceX;\r
           }\r
+          ColumnInfoArray++;\r
         }\r
-        //\r
-        // Jump to next row\r
-        //\r
-        BufferPtr += BltX + Image->Width * (LineHeight - 1);\r
       }\r
-\r
-      Index++;\r
-      RowIndex++;\r
-\r
+      //\r
+      // Jump to next row\r
+      //\r
+      BufferPtr += BltX + Image->Width * (LineHeight - 1);\r
     }\r
 \r
-    //\r
-    // Write output parameters.\r
-    //\r
-    RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO);\r
-    if (RowInfoArray != NULL) {\r
-      *RowInfoArray = AllocateZeroPool (RowInfoSize);\r
-      if (*RowInfoArray == NULL) {\r
-        Status = EFI_OUT_OF_RESOURCES;\r
-        goto Exit;\r
-      }\r
-      CopyMem (*RowInfoArray, RowInfo, RowInfoSize);\r
-    }\r
-    if (RowInfoArraySize != NULL) {\r
-      *RowInfoArraySize = RowIndex;\r
-    }\r
+    Index++;\r
+    RowIndex++;\r
 \r
-  } else {\r
-    //\r
-    // Create a new bitmap and draw the string onto this image.\r
-    //\r
-    Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));\r
-    if (Image == NULL) {\r
-      return EFI_OUT_OF_RESOURCES;\r
-    }\r
-    Image->Width  = 800;\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
-      FreePool (Image);\r
-      return EFI_OUT_OF_RESOURCES;\r
+    if (Flags & EFI_HII_IGNORE_LINE_BREAK) {\r
+      //\r
+      // If setting IGNORE_LINE_BREAK attribute, only render one line to image\r
+      //\r
+      break;\r
     }\r
+  }\r
 \r
-    //\r
-    // Other flags are not permitted when Blt is NULL.\r
-    //\r
-    Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK;\r
-    Status = HiiStringToImage (\r
-               This,\r
-               Flags,\r
-               String,\r
-               StringInfo,\r
-               &Image,\r
-               BltX,\r
-               BltY,\r
-               RowInfoArray,\r
-               RowInfoArraySize,\r
-               ColumnInfoArray\r
-               );\r
-    if (EFI_ERROR (Status)) {\r
-      return Status;\r
+  //\r
+  // Write output parameters.\r
+  //\r
+  RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO);\r
+  if (RowInfoArray != NULL) {\r
+    *RowInfoArray = AllocateZeroPool (RowInfoSize);\r
+    if (*RowInfoArray == NULL) {\r
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
     }\r
-\r
-    *Blt = Image;\r
+    CopyMem (*RowInfoArray, RowInfo, RowInfoSize);\r
+  }\r
+  if (RowInfoArraySize != NULL) {\r
+    *RowInfoArraySize = RowIndex;\r
   }\r
 \r
   Status = EFI_SUCCESS;\r
 \r
 Exit:\r
 \r
-  for (Index = 0; Index < MAX_STRING_LENGTH; Index++) {\r
+  for (Index = 0; Index < StrLength; Index++) {\r
     if (GlyphBuf[Index] != NULL) {\r
       FreePool (GlyphBuf[Index]);\r
     }\r
@@ -2089,12 +2110,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
@@ -2105,57 +2131,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
     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
@@ -2204,6 +2277,15 @@ HiiStringIdToImage (
            );\r
 \r
 Exit:\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
@@ -2484,7 +2566,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