]> git.proxmox.com Git - mirror_edk2.git/blobdiff - IntelFrameworkPkg/Library/FrameworkUefiLib/UefiLibPrint.c
Sync FrameworkUefiLib with the MdePkg UefiLib
[mirror_edk2.git] / IntelFrameworkPkg / Library / FrameworkUefiLib / UefiLibPrint.c
index 6d1fda6dc2f72e166e7b0701ea3300515fe9d17a..3f4f4f5f57ec70085a5e0eb3a0bfab335bf27aae 100644 (file)
@@ -59,12 +59,14 @@ InternalPrint (
   IN  VA_LIST                          Marker\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
   UINTN   Return;\r
   CHAR16  *Buffer;\r
   UINTN   BufferSize;\r
 \r
   ASSERT (Format != NULL);\r
   ASSERT (((UINTN) Format & BIT0) == 0);\r
+  ASSERT (Console != NULL);\r
 \r
   BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
 \r
@@ -77,7 +79,10 @@ InternalPrint (
     //\r
     // To be extra safe make sure Console has been initialized\r
     //\r
-    Console->OutputString (Console, Buffer);\r
+    Status = Console->OutputString (Console, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      Return = 0;\r
+    }\r
   }\r
 \r
   FreePool (Buffer);\r
@@ -96,6 +101,7 @@ InternalPrint (
   PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->ConOut is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated Unicode format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -134,6 +140,7 @@ Print (
   PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->StdErr is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated Unicode format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -188,11 +195,13 @@ AsciiInternalPrint (
   IN  VA_LIST                          Marker\r
   )\r
 {\r
+  EFI_STATUS  Status;\r
   UINTN   Return;\r
   CHAR16  *Buffer;\r
   UINTN   BufferSize;\r
 \r
   ASSERT (Format != NULL);\r
+  ASSERT (Console != NULL);\r
 \r
   BufferSize = (PcdGet32 (PcdUefiLibMaxPrintBufferSize) + 1) * sizeof (CHAR16);\r
 \r
@@ -205,7 +214,10 @@ AsciiInternalPrint (
     //\r
     // To be extra safe make sure Console has been initialized\r
     //\r
-    Console->OutputString (Console, Buffer);\r
+    Status = Console->OutputString (Console, Buffer);\r
+    if (EFI_ERROR (Status)) {\r
+      Return = 0;\r
+    }\r
   }\r
 \r
   FreePool (Buffer);\r
@@ -223,6 +235,7 @@ AsciiInternalPrint (
   string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r
   PcdUefiLibMaxPrintBufferSize characters are sent to ConOut.\r
   If Format is NULL, then ASSERT().\r
+  If gST->ConOut is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated ASCII format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -261,6 +274,7 @@ AsciiPrint (
   string is greater than PcdUefiLibMaxPrintBufferSize, then only the first \r
   PcdUefiLibMaxPrintBufferSize characters are sent to StdErr.\r
   If Format is NULL, then ASSERT().\r
+  If gST->StdErr is NULL, then ASSERT().\r
 \r
   @param Format   Null-terminated ASCII format string.\r
   @param ...      Variable argument list whose contents are accessed based \r
@@ -347,6 +361,9 @@ InternalPrintGraphic (
   EFI_UGA_DRAW_PROTOCOL               *UgaDraw;\r
   EFI_SIMPLE_TEXT_OUTPUT_PROTOCOL     *Sto;\r
   EFI_HANDLE                          ConsoleHandle;\r
+  UINTN                               Width;\r
+  UINTN                               Height;\r
+  UINTN                               Delta;\r
 \r
   HorizontalResolution  = 0;\r
   VerticalResolution    = 0;\r
@@ -355,6 +372,8 @@ InternalPrintGraphic (
 \r
   ConsoleHandle = gST->ConsoleOutHandle;\r
 \r
+  ASSERT( ConsoleHandle != NULL);\r
+\r
   Status = gBS->HandleProtocol (\r
                   ConsoleHandle,\r
                   &gEfiGraphicsOutputProtocolGuid,\r
@@ -464,7 +483,9 @@ InternalPrintGraphic (
     //\r
     Status = HiiFont->StringToImage (\r
                          HiiFont,\r
-                         EFI_HII_IGNORE_IF_NO_GLYPH,\r
+                         EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_OUT_FLAG_CLIP |\r
+                         EFI_HII_OUT_FLAG_CLIP_CLEAN_X | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y |\r
+                         EFI_HII_IGNORE_LINE_BREAK,\r
                          Buffer,\r
                          &FontInfo,\r
                          &Blt,\r
@@ -478,11 +499,20 @@ InternalPrintGraphic (
     if (!EFI_ERROR (Status)) {\r
       ASSERT (RowInfoArray != NULL);\r
       //\r
-      // Line breaks are handled by caller of DrawUnicodeWeightAtCursorN, so the updated parameter RowInfoArraySize by StringToImage will\r
+      // Explicit Line break characters are ignored, so the updated parameter RowInfoArraySize by StringToImage will\r
       // always be 1 or 0 (if there is no valid Unicode Char can be printed). ASSERT here to make sure.\r
       //\r
       ASSERT (RowInfoArraySize <= 1);\r
 \r
+      if (RowInfoArraySize != 0) {\r
+        Width  = RowInfoArray[0].LineWidth;\r
+        Height = RowInfoArray[0].LineHeight;\r
+        Delta  = Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL);\r
+      } else {\r
+        Width  = 0;\r
+        Height = 0;\r
+        Delta  = 0;\r
+      }\r
       Status = UgaDraw->Blt (\r
                           UgaDraw,\r
                           (EFI_UGA_PIXEL *) Blt->Image.Bitmap,\r
@@ -491,9 +521,9 @@ InternalPrintGraphic (
                           PointY,\r
                           PointX,\r
                           PointY,\r
-                          RowInfoArray[0].LineWidth,\r
-                          RowInfoArray[0].LineHeight,\r
-                          Blt->Width * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)\r
+                          Width,\r
+                          Height,\r
+                          Delta\r
                           );\r
     } else {\r
       goto Error;\r
@@ -505,7 +535,11 @@ InternalPrintGraphic (
   //\r
   // Calculate the number of actual printed characters\r
   //\r
+  if (RowInfoArraySize != 0) {\r
   PrintNum = RowInfoArray[0].EndIndex - RowInfoArray[0].StartIndex + 1;\r
+  } else {\r
+    PrintNum = 0;\r
+  }\r
 \r
   FreePool (RowInfoArray);\r
   FreePool (Blt);\r
@@ -540,6 +574,7 @@ Error:
   string is printed, and 0 is returned.\r
   If Format is NULL, then ASSERT().\r
   If Format is not aligned on a 16-bit boundary, then ASSERT().\r
+  If gST->ConsoleOutputHandle is NULL, then ASSERT().\r
 \r
   @param  PointX       X coordinate to print the string.\r
   @param  PointY       Y coordinate to print the string.\r
@@ -616,6 +651,7 @@ PrintXY (
   If the EFI_HII_FONT_PROTOCOL is not present in the handle database, then no \r
   string is printed, and 0 is returned.\r
   If Format is NULL, then ASSERT().\r
+  If gST->ConsoleOutputHandle is NULL, then ASSERT().\r
 \r
   @param  PointX       X coordinate to print the string.\r
   @param  PointY       Y coordinate to print the string.\r