]> git.proxmox.com Git - mirror_edk2.git/blobdiff - MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
Fixed build failed.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Font.c
index 2fd355029d33f6c9067e651a8da9d8f5c5e41c50..f6f784e733c202f367479f8f19a88ec8dbbf8fd8 100644 (file)
@@ -2,8 +2,8 @@
 Implementation for EFI_HII_FONT_PROTOCOL.\r
 \r
 \r
-Copyright (c) 2007 - 2009, Intel Corporation\r
-All rights reserved. This program and the accompanying materials\r
+Copyright (c) 2007 - 2012, Intel Corporation. All rights reserved.<BR>\r
+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
 http://opensource.org/licenses/bsd-license.php\r
@@ -76,6 +76,9 @@ NewCell (
   //\r
   GlyphInfo->Signature = HII_GLYPH_INFO_SIGNATURE;\r
   GlyphInfo->CharId    = CharValue;\r
+  if (Cell->AdvanceX == 0) {\r
+    Cell->AdvanceX = Cell->Width;\r
+  }\r
   CopyMem (&GlyphInfo->Cell, Cell, sizeof (EFI_HII_GLYPH_INFO));\r
   InsertTailList (GlyphInfoList, &GlyphInfo->Entry);\r
 \r
@@ -221,7 +224,6 @@ GetGlyphBuffer (
             }\r
             Cell->Width    = EFI_GLYPH_WIDTH;\r
             Cell->Height   = EFI_GLYPH_HEIGHT;\r
-            Cell->OffsetY  = NARROW_BASELINE;\r
             Cell->AdvanceX = Cell->Width;\r
             CopyMem (*GlyphBuffer, Narrow.GlyphCol1, Cell->Height);\r
             if (Attributes != NULL) {\r
@@ -243,7 +245,6 @@ GetGlyphBuffer (
             }\r
             Cell->Width    = EFI_GLYPH_WIDTH * 2;\r
             Cell->Height   = EFI_GLYPH_HEIGHT;\r
-            Cell->OffsetY  = WIDE_BASELINE;\r
             Cell->AdvanceX = Cell->Width;\r
             CopyMem (*GlyphBuffer, Wide.GlyphCol1, EFI_GLYPH_HEIGHT);\r
             CopyMem (*GlyphBuffer + EFI_GLYPH_HEIGHT, Wide.GlyphCol2, EFI_GLYPH_HEIGHT);\r
@@ -270,16 +271,15 @@ GetGlyphBuffer (
                          bitmap.\r
   @param  Background     The color of the "off" pixels in the glyph in the\r
                          bitmap.\r
-  @param  ImageWidth     Width of the character or character cell, in\r
-                         pixels.\r
-  @param  ImageHeight    Height of the character or character cell, in\r
-                         pixels.\r
-  @param  Transparent             If TRUE, the Background color is ignored and all\r
-                                  "off" pixels in the character's drawn wil use the\r
-                                  pixel value from BltBuffer.\r
-  @param  Origin                  On input, points to the origin of the to be\r
-                                  displayed character, on output, points to the\r
-                                  next glyph's origin.\r
+  @param  ImageWidth     Width of the whole image in pixels.\r
+  @param  RowWidth       The width of the text on the line, in pixels.\r
+  @param  RowHeight      The height of the line, in pixels.\r
+  @param  Transparent    If TRUE, the Background color is ignored and all\r
+                         "off" pixels in the character's drawn wil use the\r
+                         pixel value from BltBuffer.\r
+  @param  Origin         On input, points to the origin of the to be\r
+                         displayed character, on output, points to the\r
+                         next glyph's origin.\r
 \r
 **/\r
 VOID\r
@@ -287,8 +287,9 @@ NarrowGlyphToBlt (
   IN     UINT8                         *GlyphBuffer,\r
   IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,\r
   IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,\r
-  IN     UINTN                         ImageWidth,\r
-  IN     UINTN                         ImageHeight,\r
+  IN     UINT16                        ImageWidth,\r
+  IN     UINTN                         RowWidth,\r
+  IN     UINTN                         RowHeight,\r
   IN     BOOLEAN                       Transparent,\r
   IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin\r
   )\r
@@ -303,24 +304,35 @@ NarrowGlyphToBlt (
 \r
   Height = EFI_GLYPH_HEIGHT;\r
   Width  = EFI_GLYPH_WIDTH;\r
+  \r
+  //\r
+  // Move position to the left-top corner of char.\r
+  //\r
+  Buffer = *Origin - EFI_GLYPH_HEIGHT * ImageWidth;\r
 \r
-  ASSERT (Width <= ImageWidth && Height <= ImageHeight);\r
-\r
-  Buffer = *Origin;\r
+  //\r
+  // Char may be partially displayed when CLIP_X or CLIP_Y is not set. \r
+  //\r
+  if (RowHeight < Height) {\r
+    Height = (UINT8) RowHeight;\r
+  }\r
+  if (RowWidth < Width) {\r
+    Width = (UINT8) RowWidth;\r
+  }\r
 \r
   for (Ypos = 0; Ypos < Height; Ypos++) {\r
     for (Xpos = 0; Xpos < Width; Xpos++) {\r
-      if ((GlyphBuffer[Ypos] & (1 << Xpos)) != 0) {\r
-        Buffer[Ypos * ImageWidth + (Width - Xpos - 1)] = Foreground;\r
+      if ((GlyphBuffer[Ypos] & (1 << (EFI_GLYPH_WIDTH - Xpos - 1))) != 0) {\r
+        Buffer[Ypos * ImageWidth + Xpos] = Foreground;\r
       } else {\r
         if (!Transparent) {\r
-          Buffer[Ypos * ImageWidth + (Width - Xpos - 1)] = Background;\r
+          Buffer[Ypos * ImageWidth + Xpos] = Background;\r
         }\r
       }\r
     }\r
   }\r
 \r
-  *Origin = Buffer + Width;\r
+  *Origin = *Origin + EFI_GLYPH_WIDTH;\r
 }\r
 \r
 \r
@@ -334,10 +346,10 @@ NarrowGlyphToBlt (
                                   bitmap.\r
   @param  Background              The color of the "off" pixels in the glyph in the\r
                                   bitmap.\r
-  @param  ImageWidth              Width of the character or character cell, in\r
-                                  pixels.\r
-  @param  ImageHeight             Height of the character or character cell, in\r
-                                  pixels.\r
+  @param  ImageWidth              Width of the whole image in pixels.\r
+  @param  BaseLine                BaseLine in the line.\r
+  @param  RowWidth                The width of the text on the line, in pixels.\r
+  @param  RowHeight               The height of the line, in pixels.\r
   @param  Transparent             If TRUE, the Background color is ignored and all\r
                                   "off" pixels in the character's drawn wil use the\r
                                   pixel value from BltBuffer.\r
@@ -354,25 +366,38 @@ GlyphToBlt (
   IN     UINT8                         *GlyphBuffer,\r
   IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,\r
   IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,\r
-  IN     UINTN                         ImageWidth,\r
-  IN     UINTN                         ImageHeight,\r
+  IN     UINT16                        ImageWidth,\r
+  IN     UINT16                        BaseLine,\r
+  IN     UINTN                         RowWidth,\r
+  IN     UINTN                         RowHeight,\r
   IN     BOOLEAN                       Transparent,\r
   IN     CONST EFI_HII_GLYPH_INFO      *Cell,\r
   IN     UINT8                         Attributes,\r
   IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin\r
   )\r
 {\r
-  UINT8                                Xpos;\r
-  UINT8                                Ypos;\r
-  UINT8                                Data;\r
-  UINT8                                Index;\r
-  UINTN                                OffsetY;\r
-  EFI_GRAPHICS_OUTPUT_BLT_PIXEL        *BltBuffer;\r
+  UINT16                                Xpos;\r
+  UINT16                                Ypos;\r
+  UINT8                                 Data;\r
+  UINT16                                Index;\r
+  UINT16                                YposOffset;\r
+  UINTN                                 OffsetY;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL         *BltBuffer;\r
 \r
-  ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL);\r
-  ASSERT (Cell->Width <= ImageWidth && Cell->Height <= ImageHeight);\r
+  ASSERT (Origin != NULL && *Origin != NULL && Cell != NULL);\r
 \r
-  BltBuffer = *Origin;\r
+  //\r
+  // Only adjust origin position if char has no bitmap.\r
+  //\r
+  if (GlyphBuffer == NULL) {\r
+    *Origin = *Origin + Cell->AdvanceX;\r
+    return;\r
+  }\r
+  //\r
+  // Move position to the left-top corner of char.\r
+  //\r
+  BltBuffer  = *Origin + Cell->OffsetX - (Cell->OffsetY + Cell->Height) * ImageWidth;\r
+  YposOffset = (UINT16) (BaseLine - (Cell->OffsetY + Cell->Height));\r
 \r
   //\r
   // Since non-spacing key will be printed OR'd with the previous glyph, don't\r
@@ -386,7 +411,7 @@ GlyphToBlt (
   // The glyph's upper left hand corner pixel is the most significant bit of the\r
   // first bitmap byte.\r
   //\r
-  for (Ypos = 0; Ypos < Cell->Height; Ypos++) {\r
+  for (Ypos = 0; Ypos < Cell->Height && ((UINTN) (Ypos + YposOffset) < RowHeight); Ypos++) {\r
     OffsetY = BITMAP_LEN_1_BIT (Cell->Width, Ypos);\r
 \r
     //\r
@@ -394,12 +419,12 @@ GlyphToBlt (
     //\r
     for (Xpos = 0; Xpos < Cell->Width / 8; Xpos++) {\r
       Data  = *(GlyphBuffer + OffsetY + Xpos);\r
-      for (Index = 0; Index < 8; Index++) {\r
-        if ((Data & (1 << Index)) != 0) {\r
-          BltBuffer[Ypos * ImageWidth + Xpos * 8 + (8 - Index - 1)] = Foreground;\r
+      for (Index = 0; Index < 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {\r
+        if ((Data & (1 << (8 - Index - 1))) != 0) {\r
+          BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;\r
         } else {\r
           if (!Transparent) {\r
-            BltBuffer[Ypos * ImageWidth + Xpos * 8 + (8 - Index - 1)] = Background;\r
+            BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Background;\r
           }\r
         }\r
       }\r
@@ -410,7 +435,7 @@ GlyphToBlt (
       // There are some padding bits in this byte. Ignore them.\r
       //\r
       Data  = *(GlyphBuffer + OffsetY + Xpos);\r
-      for (Index = 0; Index < Cell->Width % 8; Index++) {\r
+      for (Index = 0; Index < Cell->Width % 8 && ((UINTN) (Xpos * 8 + Index + Cell->OffsetX) < RowWidth); Index++) {\r
         if ((Data & (1 << (8 - Index - 1))) != 0) {\r
           BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Foreground;\r
         } else {\r
@@ -423,7 +448,7 @@ GlyphToBlt (
 \r
   } // end of for (Ypos=0...)\r
 \r
-  *Origin = BltBuffer + Cell->Width;\r
+  *Origin = *Origin + Cell->AdvanceX;\r
 }\r
 \r
 \r
@@ -437,10 +462,10 @@ GlyphToBlt (
                                   bitmap.\r
   @param  Background              The color of the "off" pixels in the glyph in the\r
                                   bitmap.\r
-  @param  ImageWidth              Width of the character or character cell, in\r
-                                  pixels.\r
-  @param  ImageHeight             Height of the character or character cell, in\r
-                                  pixels.\r
+  @param  ImageWidth              Width of the whole image in pixels.\r
+  @param  BaseLine                BaseLine in the line.\r
+  @param  RowWidth                The width of the text on the line, in pixels.\r
+  @param  RowHeight               The height of the line, in pixels.\r
   @param  Transparent             If TRUE, the Background color is ignored and all\r
                                   "off" pixels in the character's drawn wil use the\r
                                   pixel value from BltBuffer.\r
@@ -458,8 +483,10 @@ GlyphToImage (
   IN     UINT8                         *GlyphBuffer,\r
   IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,\r
   IN     EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,\r
-  IN     UINTN                         ImageWidth,\r
-  IN     UINTN                         ImageHeight,\r
+  IN     UINT16                        ImageWidth,\r
+  IN     UINT16                        BaseLine,\r
+  IN     UINTN                         RowWidth,\r
+  IN     UINTN                         RowHeight,\r
   IN     BOOLEAN                       Transparent,\r
   IN     CONST EFI_HII_GLYPH_INFO      *Cell,\r
   IN     UINT8                         Attributes,\r
@@ -468,8 +495,7 @@ GlyphToImage (
 {\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL        *Buffer;\r
 \r
-  ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL);\r
-  ASSERT (Cell->Width <= ImageWidth && Cell->Height <= ImageHeight);\r
+  ASSERT (Origin != NULL && *Origin != NULL && Cell != NULL);\r
 \r
   Buffer = *Origin;\r
 \r
@@ -478,13 +504,15 @@ GlyphToImage (
     // This character is a non-spacing key, print it OR'd with the previous glyph.\r
     // without advancing cursor.\r
     //\r
-    Buffer -= Cell->Width;\r
+    Buffer -= Cell->AdvanceX;\r
     GlyphToBlt (\r
       GlyphBuffer,\r
       Foreground,\r
       Background,\r
       ImageWidth,\r
-      ImageHeight,\r
+      BaseLine,\r
+      RowWidth,\r
+      RowHeight,\r
       Transparent,\r
       Cell,\r
       Attributes,\r
@@ -501,7 +529,8 @@ GlyphToImage (
       Foreground,\r
       Background,\r
       ImageWidth,\r
-      ImageHeight,\r
+      RowWidth,\r
+      RowHeight,\r
       Transparent,\r
       Origin\r
       );\r
@@ -511,7 +540,8 @@ GlyphToImage (
       Foreground,\r
       Background,\r
       ImageWidth,\r
-      ImageHeight,\r
+      RowWidth,\r
+      RowHeight,\r
       Transparent,\r
       Origin\r
       );\r
@@ -525,7 +555,8 @@ GlyphToImage (
       Foreground,\r
       Background,\r
       ImageWidth,\r
-      ImageHeight,\r
+      RowWidth,\r
+      RowHeight,\r
       Transparent,\r
       Origin\r
       );\r
@@ -539,7 +570,9 @@ GlyphToImage (
       Foreground,\r
       Background,\r
       ImageWidth,\r
-      ImageHeight,\r
+      BaseLine,\r
+      RowWidth,\r
+      RowHeight,\r
       Transparent,\r
       Cell,\r
       Attributes,\r
@@ -581,7 +614,7 @@ WriteOutputParam (
   OUT UINTN                          *GlyphBufferLen OPTIONAL\r
   )\r
 {\r
-  if (BufferIn == NULL || BufferLen < 1 || InputCell == NULL) {\r
+  if (BufferIn == NULL || InputCell == NULL) {\r
     return EFI_INVALID_PARAMETER;\r
   }\r
 \r
@@ -589,7 +622,7 @@ WriteOutputParam (
     CopyMem (Cell, InputCell, sizeof (EFI_HII_GLYPH_INFO));\r
   }\r
 \r
-  if (GlyphBuffer != NULL) {\r
+  if (GlyphBuffer != NULL && BufferLen > 0) {\r
     *GlyphBuffer = (UINT8 *) AllocateZeroPool (BufferLen);\r
     if (*GlyphBuffer == NULL) {\r
       return EFI_OUT_OF_RESOURCES;\r
@@ -645,10 +678,14 @@ FindGlyphBlock (
   UINT16                              Index;\r
   EFI_HII_GLYPH_INFO                  DefaultCell;\r
   EFI_HII_GLYPH_INFO                  LocalCell;\r
+  INT16                               MinOffsetY;\r
+  UINT16                              BaseLine;\r
 \r
   ASSERT (FontPackage != NULL);\r
   ASSERT (FontPackage->Signature == HII_FONT_PACKAGE_SIGNATURE);\r
-\r
+  BaseLine  = 0;\r
+  MinOffsetY = 0;\r
+  \r
   if (CharValue == (CHAR16) (-1)) {\r
     //\r
     // Collect the cell information specified in font package fixed header.\r
@@ -662,6 +699,15 @@ FindGlyphBlock (
     if (EFI_ERROR (Status)) {\r
       return Status;\r
     }\r
+    CopyMem (\r
+      &LocalCell,\r
+      (UINT8 *) FontPackage->FontPkgHdr + 3 * sizeof (UINT32),\r
+      sizeof (EFI_HII_GLYPH_INFO)\r
+      );\r
+    BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY);\r
+    if (MinOffsetY > LocalCell.OffsetY) {\r
+      MinOffsetY = LocalCell.OffsetY;\r
+    }\r
   }\r
 \r
   BlockPtr    = FontPackage->GlyphBlock;\r
@@ -684,6 +730,17 @@ FindGlyphBlock (
         if (EFI_ERROR (Status)) {\r
           return Status;\r
         }\r
+        CopyMem (\r
+          &LocalCell,\r
+          BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),\r
+          sizeof (EFI_HII_GLYPH_INFO)\r
+          );\r
+        if (BaseLine < LocalCell.Height + LocalCell.OffsetY) {\r
+          BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY);\r
+        }\r
+        if (MinOffsetY > LocalCell.OffsetY) {\r
+          MinOffsetY = LocalCell.OffsetY;\r
+        }\r
       }\r
       BlockPtr += sizeof (EFI_HII_GIBT_DEFAULTS_BLOCK);\r
       break;\r
@@ -725,6 +782,14 @@ FindGlyphBlock (
         BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),\r
         sizeof (EFI_HII_GLYPH_INFO)\r
         );\r
+      if (CharValue == (CHAR16) (-1)) {\r
+        if (BaseLine < LocalCell.Height + LocalCell.OffsetY) {\r
+          BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY);\r
+        }\r
+        if (MinOffsetY > LocalCell.OffsetY) {\r
+          MinOffsetY = LocalCell.OffsetY;\r
+        }\r
+      }\r
       BufferLen = BITMAP_LEN_1_BIT (LocalCell.Width, LocalCell.Height);\r
       if (CharCurrent == CharValue) {\r
         return WriteOutputParam (\r
@@ -747,6 +812,15 @@ FindGlyphBlock (
       CopyMem (&Glyphs.Count, BlockPtr, sizeof (UINT16));\r
       BlockPtr += sizeof (UINT16);\r
 \r
+      if (CharValue == (CHAR16) (-1)) {\r
+        if (BaseLine < Glyphs.Cell.Height + Glyphs.Cell.OffsetY) {\r
+          BaseLine = (UINT16) (Glyphs.Cell.Height + Glyphs.Cell.OffsetY);\r
+        }\r
+        if (MinOffsetY > Glyphs.Cell.OffsetY) {\r
+          MinOffsetY = Glyphs.Cell.OffsetY;\r
+        }\r
+      }\r
+\r
       BufferLen = BITMAP_LEN_1_BIT (Glyphs.Cell.Width, Glyphs.Cell.Height);\r
       for (Index = 0; Index < Glyphs.Count; Index++) {\r
         if (CharCurrent + Index == CharValue) {\r
@@ -829,6 +903,8 @@ FindGlyphBlock (
   }\r
 \r
   if (CharValue == (CHAR16) (-1)) {\r
+    FontPackage->BaseLine = BaseLine;\r
+    FontPackage->Height   = (UINT16) (BaseLine - MinOffsetY);\r
     return EFI_SUCCESS;\r
   }\r
 \r
@@ -1501,10 +1577,13 @@ HiiStringToImage (
   EFI_HII_ROW_INFO                    *RowInfo;\r
   UINTN                               LineWidth;\r
   UINTN                               LineHeight;\r
+  UINTN                               LineOffset;\r
+  UINTN                               LastLineHeight;\r
   UINTN                               BaseLineOffset;\r
   UINT16                              MaxRowNum;\r
   UINT16                              RowIndex;\r
   UINTN                               Index;\r
+  UINTN                               NextIndex;\r
   UINTN                               Index1;\r
   EFI_FONT_DISPLAY_INFO               *StringInfoOut;\r
   EFI_FONT_DISPLAY_INFO               *SystemDefault;\r
@@ -1512,6 +1591,7 @@ HiiStringToImage (
   EFI_STRING                          StringIn;\r
   EFI_STRING                          StringIn2;\r
   UINT16                              Height;\r
+  UINT16                              BaseLine;\r
   EFI_FONT_INFO                       *FontInfo;\r
   BOOLEAN                             SysFontFlag;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL       Foreground;\r
@@ -1522,6 +1602,8 @@ HiiStringToImage (
   UINTN                               RowInfoSize;\r
   BOOLEAN                             LineBreak;\r
   UINTN                               StrLength;\r
+  EFI_GRAPHICS_OUTPUT_BLT_PIXEL       *RowBufferPtr;\r
+  HII_GLOBAL_FONT_INFO                *GlobalFont;\r
 \r
   //\r
   // Check incoming parameters.\r
@@ -1607,6 +1689,7 @@ HiiStringToImage (
   if (SysFontFlag) {\r
     FontInfo   = NULL;\r
     Height     = SystemDefault->FontInfo.FontSize;\r
+    BaseLine   = SystemDefault->FontInfo.FontSize;\r
     Foreground = SystemDefault->ForegroundColor;\r
     Background = SystemDefault->BackgroundColor;\r
 \r
@@ -1624,19 +1707,30 @@ HiiStringToImage (
       SysFontFlag = TRUE;\r
       FontInfo    = NULL;\r
       Height      = SystemDefault->FontInfo.FontSize;\r
+      BaseLine    = SystemDefault->FontInfo.FontSize;\r
       Foreground  = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->ForegroundColor;\r
       Background  = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->BackgroundColor;\r
 \r
     } else if (Status == EFI_SUCCESS) {\r
       FontInfo   = &StringInfoOut->FontInfo;\r
-      Height     = StringInfoOut->FontInfo.FontSize;\r
+      IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont);\r
+      Height     = GlobalFont->FontPackage->Height;\r
+      BaseLine   = GlobalFont->FontPackage->BaseLine;\r
       Foreground = StringInfoOut->ForegroundColor;\r
       Background = StringInfoOut->BackgroundColor;\r
     } else {\r
       goto Exit;\r
     }\r
   }\r
-\r
+  \r
+  //\r
+  // Use the maxinum height of font as the base line.\r
+  // And, use the maxinum height as line height.\r
+  //\r
+  LineHeight     = Height;\r
+  LastLineHeight = Height;\r
+  BaseLineOffset = Height - BaseLine;\r
+  \r
   //\r
   // Parse the string to be displayed to drop some ignored characters.\r
   //\r
@@ -1677,12 +1771,18 @@ HiiStringToImage (
   StringTmp = StringIn2;\r
   StrLength = StrLen(StringPtr);\r
   while (*StringPtr != 0 && Index < StrLength) {\r
+    if (IsLineBreak (*StringPtr) == 0) {\r
+      *StringTmp++ = *StringPtr++;\r
+      Index++;\r
+      continue;\r
+    }\r
+    \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
         GlyphBuf[Index] = NULL;\r
-        *StringTmp++ = *StringPtr++;\r
-        Index++;\r
+        ZeroMem (&Cell[Index], sizeof (Cell[Index]));\r
+        Status = EFI_SUCCESS;\r
       } else {\r
         //\r
         // Unicode 0xFFFD must exist in current hii database if this flag is not set.\r
@@ -1697,17 +1797,16 @@ HiiStringToImage (
                    );\r
         if (EFI_ERROR (Status)) {\r
           Status = EFI_INVALID_PARAMETER;\r
-          goto Exit;\r
         }\r
-        *StringTmp++ = *StringPtr++;\r
-        Index++;\r
       }\r
-    } else if (EFI_ERROR (Status)) {\r
+    }\r
+\r
+    if (EFI_ERROR (Status)) {\r
       goto Exit;\r
-    } else {\r
-      *StringTmp++ = *StringPtr++;\r
-      Index++;\r
     }\r
+\r
+    *StringTmp++ = *StringPtr++;\r
+    Index++;\r
   }\r
   *StringTmp = 0;\r
   StringPtr  = StringIn2;\r
@@ -1720,8 +1819,16 @@ HiiStringToImage (
   //\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
+  if (Image->Height < BltY) {\r
+    //\r
+    // the top edge of the image should be in Image resolution scope.\r
+    //\r
+    Status = EFI_INVALID_PARAMETER;\r
+    goto Exit;\r
+  }\r
+  MaxRowNum = (UINT16) ((Image->Height - BltY) / Height);\r
+  if ((Image->Height - BltY) % Height != 0) {\r
+    LastLineHeight = (Image->Height - BltY) % Height;\r
     MaxRowNum++;\r
   }\r
 \r
@@ -1734,25 +1841,26 @@ HiiStringToImage (
   //\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
+    // 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) {\r
+      if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y && LastLineHeight < LineHeight ) {\r
+        //\r
+        // Don't draw at all if the row's bottom-most on pixel cannot fit.\r
+        //\r
+        break;\r
+      }\r
+      LineHeight = LastLineHeight;\r
+    }\r
+\r
     //\r
     // Calculate how many characters there are in a row.\r
     //\r
@@ -1760,7 +1868,6 @@ HiiStringToImage (
 \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
@@ -1773,25 +1880,32 @@ HiiStringToImage (
       //\r
       // If the glyph of the character is existing, then accumulate the actual printed width\r
       //\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
+      LineWidth += (UINTN) Cell[Index].AdvanceX;\r
 \r
       Index++;\r
     }\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
+    // Record index of next char.\r
+    //\r
+    NextIndex = Index;\r
+    //\r
+    // Return to the previous char.\r
     //\r
     Index--;\r
-    if (!SysFontFlag) {\r
-      LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width);\r
+    if (LineBreak && Index > 0 ) {\r
+      //\r
+      // Return the previous non line break char.\r
+      //\r
+      Index --;\r
     }\r
 \r
+    //\r
+    // If this character is the last character of a row, we need not\r
+    // draw its (AdvanceX - Width - OffsetX) for next character.\r
+    //\r
+    LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);\r
+\r
     //\r
     // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.\r
     //\r
@@ -1809,20 +1923,23 @@ HiiStringToImage (
       // 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 (Index > 0) {\r
+      if (Index > RowInfo[RowIndex].StartIndex) {\r
+        //\r
+        // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).\r
+        //\r
+        LineWidth -= (UINTN) (Cell[Index].Width + Cell[Index].OffsetX);\r
+        LineWidth -= (UINTN) (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);\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].LineWidth      = LineWidth;\r
         RowInfo[RowIndex].LineHeight     = LineHeight;\r
+        RowInfo[RowIndex].BaselineOffset = BaseLineOffset;\r
       } else {\r
         //\r
-        // There is only one column and it can not be drawn so that return directly.\r
+        // There is no enough column to draw any character, so set current line width to zero.\r
+        // And go to draw Next line if LineBreak is set.\r
         //\r
-        Status = EFI_SUCCESS;\r
-        goto Exit;\r
+        RowInfo[RowIndex].LineWidth      = 0;\r
+        goto NextLine;\r
       }\r
     }\r
 \r
@@ -1831,16 +1948,26 @@ HiiStringToImage (
     // 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_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP && \r
+        (RowInfo[RowIndex].LineWidth + BltX > Image->Width || StringPtr[NextIndex] != 0) && \r
+        !LineBreak) {\r
       if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {\r
+        LineWidth = RowInfo[RowIndex].LineWidth;\r
         for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {\r
+          if (Index1 == RowInfo[RowIndex].EndIndex) {\r
+            LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX);\r
+          } else {\r
+            LineWidth -= Cell[Index1].AdvanceX;\r
+          }\r
           if (IsLineBreak (StringPtr[Index1]) > 0) {\r
             LineBreak = TRUE;\r
-            RowInfo[RowIndex].EndIndex = Index1 - 1;\r
+            if (Index1 > RowInfo[RowIndex].StartIndex) {\r
+              RowInfo[RowIndex].EndIndex = Index1 - 1;\r
+            }\r
             //\r
             // relocate to the character after the right-most line break opportunity of this line\r
             //\r
-            Index = Index1 + 1;\r
+            NextIndex = Index1 + 1;\r
             break;\r
           }\r
           //\r
@@ -1850,44 +1977,74 @@ HiiStringToImage (
           if (Index1 == RowInfo[RowIndex].StartIndex)\r
             break;\r
         }\r
+\r
+        //\r
+        // Update LineWidth to the real width\r
+        //\r
+        if (IsLineBreak (StringPtr[Index1]) > 0) {\r
+          if (Index1 == RowInfo[RowIndex].StartIndex) {\r
+            LineWidth = 0;\r
+          } else {\r
+            LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);\r
+          }\r
+          RowInfo[RowIndex].LineWidth = LineWidth;\r
+        }\r
       }\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
       //\r
       if (!LineBreak) {\r
-        Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP);\r
-        Flags |= EFI_HII_OUT_FLAG_CLIP_CLEAN_X;\r
+        LineWidth = RowInfo[RowIndex].LineWidth;\r
+        Index1    = RowInfo[RowIndex].EndIndex;\r
+        if (LineWidth + BltX > Image->Width) {\r
+          if (Index1 > RowInfo[RowIndex].StartIndex) {\r
+            //\r
+            // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).\r
+            //\r
+            LineWidth -= (UINTN) (Cell[Index1].Width + Cell[Index1].OffsetX);\r
+            LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);\r
+            RowInfo[RowIndex].EndIndex       = Index1 - 1;\r
+            RowInfo[RowIndex].LineWidth      = LineWidth;\r
+          } else {\r
+            //\r
+            // There is no enough column to draw any character, so set current line width to zero.\r
+            // And go to draw Next line if LineBreak is set.\r
+            //\r
+            RowInfo[RowIndex].LineWidth = 0;\r
+            goto NextLine;\r
+          }\r
+        }\r
       }\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
+    // LineWidth can't exceed Image width.\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
-        // Don't draw at all if the row's bottom-most on pixel cannot fit.\r
-        //\r
-        break;\r
-      }\r
+    if (RowInfo[RowIndex].LineWidth + BltX > Image->Width) {\r
+      RowInfo[RowIndex].LineWidth = Image->Width - BltX;\r
     }\r
 \r
     //\r
     // Draw it to screen or existing bitmap depending on whether\r
     // EFI_HII_DIRECT_TO_SCREEN is set.\r
     //\r
+    LineOffset = 0;\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
+      BltBuffer = NULL;\r
+      if (RowInfo[RowIndex].LineWidth != 0) {\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
+        //\r
+        // Set BufferPtr to Origin by adding baseline to the starting position.\r
+        //\r
+        BufferPtr = BltBuffer + BaseLine * RowInfo[RowIndex].LineWidth;\r
       }\r
-      BufferPtr = BltBuffer;\r
       for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
-        if (GlyphBuf[Index1] != NULL) {\r
+        if (RowInfo[RowIndex].LineWidth > 0 && RowInfo[RowIndex].LineWidth > LineOffset) {\r
           //\r
           // Only BLT these character which have corrsponding glyph in font basebase.\r
           //\r
@@ -1895,7 +2052,9 @@ HiiStringToImage (
             GlyphBuf[Index1],\r
             Foreground,\r
             Background,\r
-            RowInfo[RowIndex].LineWidth,\r
+            (UINT16) RowInfo[RowIndex].LineWidth,\r
+            BaseLine,\r
+            RowInfo[RowIndex].LineWidth - LineOffset,\r
             RowInfo[RowIndex].LineHeight,\r
             Transparent,\r
             &Cell[Index1],\r
@@ -1904,44 +2063,48 @@ HiiStringToImage (
           );\r
         }\r
         if (ColumnInfoArray != NULL) {\r
-          if (GlyphBuf[Index1] == NULL) {\r
-            *ColumnInfoArray = 0;\r
+          if ((GlyphBuf[Index1] == NULL && Cell[Index1].AdvanceX == 0) \r
+              || RowInfo[RowIndex].LineWidth == 0) {\r
+            *ColumnInfoArray = (UINTN) ~0;\r
           } else {\r
-            *ColumnInfoArray = Cell[Index1 -1].AdvanceX;\r
+            *ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX;\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
+        LineOffset += Cell[Index1].AdvanceX;\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
+      if (BltBuffer != NULL) {\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
         FreePool (BltBuffer);\r
-        goto Exit;\r
       }\r
-\r
-      FreePool (BltBuffer);\r
-\r
     } else {\r
+      //\r
+      // Save the starting position for calculate the starting postition of next row. \r
+      //\r
+      RowBufferPtr = BufferPtr;\r
+      //\r
+      // Set BufferPtr to Origin by adding baseline to the starting position.\r
+      //\r
+      BufferPtr = BufferPtr + BaseLine * Image->Width;\r
       for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {\r
-        if (GlyphBuf[Index1] != NULL) {\r
+        if (RowInfo[RowIndex].LineWidth > 0 && RowInfo[RowIndex].LineWidth > LineOffset) {\r
           //\r
           // Only BLT these character which have corrsponding glyph in font basebase.\r
           //\r
@@ -1950,7 +2113,9 @@ HiiStringToImage (
             Foreground,\r
             Background,\r
             Image->Width,\r
-            Image->Height,\r
+            BaseLine,\r
+            RowInfo[RowIndex].LineWidth - LineOffset,\r
+            RowInfo[RowIndex].LineHeight,\r
             Transparent,\r
             &Cell[Index1],\r
             Attributes[Index1],\r
@@ -1958,22 +2123,36 @@ HiiStringToImage (
           );\r
         }\r
         if (ColumnInfoArray != NULL) {\r
-          if (GlyphBuf[Index1] == NULL) {\r
-            *ColumnInfoArray = 0;\r
+          if ((GlyphBuf[Index1] == NULL && Cell[Index1].AdvanceX == 0) \r
+              || RowInfo[RowIndex].LineWidth == 0) {\r
+            *ColumnInfoArray = (UINTN) ~0;\r
           } else {\r
-            *ColumnInfoArray = Cell[Index1 -1].AdvanceX;\r
+            *ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX;\r
           }\r
           ColumnInfoArray++;\r
         }\r
+        LineOffset += Cell[Index1].AdvanceX;\r
       }\r
+\r
       //\r
-      // Jump to next row\r
+      // Jump to starting position of next row.\r
       //\r
-      BufferPtr += BltX + Image->Width * (LineHeight - 1);\r
+      if (RowIndex == 0) {\r
+        BufferPtr = RowBufferPtr - BltX + LineHeight * Image->Width;\r
+      } else {\r
+        BufferPtr = RowBufferPtr + LineHeight * Image->Width;\r
+      }\r
     }\r
 \r
-    Index++;\r
+NextLine:\r
+    //\r
+    // Recalculate the start point of X/Y axis to draw multi-lines with the order of top-to-down\r
+    //\r
+    BltX = 0;\r
+    BltY += RowInfo[RowIndex].LineHeight;\r
+\r
     RowIndex++;\r
+    Index = NextIndex;\r
 \r
     if (!LineBreak) {\r
       //\r
@@ -1988,12 +2167,16 @@ HiiStringToImage (
   //\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
+    if (RowInfoSize > 0) {\r
+      *RowInfoArray = AllocateZeroPool (RowInfoSize);\r
+      if (*RowInfoArray == NULL) {\r
+        Status = EFI_OUT_OF_RESOURCES;\r
+        goto Exit;\r
+      }\r
+      CopyMem (*RowInfoArray, RowInfo, RowInfoSize);\r
+    } else {\r
+      *RowInfoArray = NULL;\r
     }\r
-    CopyMem (*RowInfoArray, RowInfo, RowInfoSize);\r
   }\r
   if (RowInfoArraySize != NULL) {\r
     *RowInfoArraySize = RowIndex;\r
@@ -2144,7 +2327,6 @@ HiiStringIdToImage (
   CurrentLanguage    = NULL;\r
   BestLanguage       = NULL;\r
   String             = NULL;\r
-  StringInfo         = NULL;\r
   StringFontInfo     = NULL;\r
   NewStringInfo      = NULL;\r
 \r
@@ -2186,7 +2368,7 @@ HiiStringIdToImage (
   if (Language == NULL) {\r
     Language = "";\r
   }\r
-  CurrentLanguage = GetEfiGlobalVariable (L"PlatformLang");\r
+  GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLanguage, NULL);\r
   BestLanguage = GetBestLanguage (\r
                    SupportedLanguages,\r
                    FALSE,\r
@@ -2354,6 +2536,7 @@ HiiGetGlyph (
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      Foreground;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      Background;\r
   EFI_GRAPHICS_OUTPUT_BLT_PIXEL      *BltBuffer;\r
+  UINT16                             BaseLine;\r
 \r
   if (This == NULL || Blt == NULL || *Blt != NULL) {\r
     return EFI_INVALID_PARAMETER;\r
@@ -2392,6 +2575,7 @@ HiiGetGlyph (
     if (EFI_ERROR (Status)) {\r
       goto Exit;\r
     }\r
+    ASSERT (StringInfoOut != NULL);\r
     FontInfo   = &StringInfoOut->FontInfo;\r
     Foreground = StringInfoOut->ForegroundColor;\r
     Background = StringInfoOut->BackgroundColor;\r
@@ -2413,25 +2597,36 @@ HiiGetGlyph (
   Image->Width   = Cell.Width;\r
   Image->Height  = Cell.Height;\r
 \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
-    Status = EFI_OUT_OF_RESOURCES;\r
-    goto Exit;\r
-  }\r
+  if (Image->Width * Image->Height > 0) {\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
+      Status = EFI_OUT_OF_RESOURCES;\r
+      goto Exit;\r
+    }\r
 \r
-  BltBuffer = Image->Image.Bitmap;\r
-  GlyphToImage (\r
-    GlyphBuffer,\r
-    Foreground,\r
-    Background,\r
-    Image->Width,\r
-    Image->Height,\r
-    FALSE,\r
-    &Cell,\r
-    Attributes,\r
-    &BltBuffer\r
-    );\r
+    //\r
+    // Set BaseLine to the char height.\r
+    //\r
+    BaseLine  = (UINT16) (Cell.Height + Cell.OffsetY);\r
+    //\r
+    // Set BltBuffer to the position of Origin. \r
+    //\r
+    BltBuffer = Image->Image.Bitmap + (Cell.Height + Cell.OffsetY) * Image->Width - Cell.OffsetX;\r
+    GlyphToImage (\r
+      GlyphBuffer,\r
+      Foreground,\r
+      Background,\r
+      Image->Width,\r
+      BaseLine,\r
+      Cell.Width + Cell.OffsetX,\r
+      BaseLine - Cell.OffsetY,\r
+      FALSE,\r
+      &Cell,\r
+      Attributes,\r
+      &BltBuffer\r
+      );\r
+  }\r
 \r
   *Blt = Image;\r
   if (Baseline != NULL) {\r
@@ -2622,7 +2817,7 @@ HiiGetFontInfo (
     InfoOut.BackgroundColor = SystemDefault->BackgroundColor;\r
   }\r
   \r
-\r
+  ASSERT (FontInfo != NULL);\r
   FontInfo->FontSize  = InfoOut.FontInfo.FontSize;\r
   FontInfo->FontStyle = InfoOut.FontInfo.FontStyle;\r
 \r