2 Implementation for EFI_HII_FONT_PROTOCOL.
5 Copyright (c) 2007 - 2009, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
17 #include "HiiDatabase.h"
19 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mHiiEfiColors
[16] = {
23 {0x00, 0x00, 0x00, 0x00}, // BLACK
24 {0x98, 0x00, 0x00, 0x00}, // BLUE
25 {0x00, 0x98, 0x00, 0x00}, // GREEN
26 {0x98, 0x98, 0x00, 0x00}, // CYAN
27 {0x00, 0x00, 0x98, 0x00}, // RED
28 {0x98, 0x00, 0x98, 0x00}, // MAGENTA
29 {0x00, 0x98, 0x98, 0x00}, // BROWN
30 {0x98, 0x98, 0x98, 0x00}, // LIGHTGRAY
31 {0x30, 0x30, 0x30, 0x00}, // DARKGRAY - BRIGHT BLACK
32 {0xff, 0x00, 0x00, 0x00}, // LIGHTBLUE
33 {0x00, 0xff, 0x00, 0x00}, // LIGHTGREEN
34 {0xff, 0xff, 0x00, 0x00}, // LIGHTCYAN
35 {0x00, 0x00, 0xff, 0x00}, // LIGHTRED
36 {0xff, 0x00, 0xff, 0x00}, // LIGHTMAGENTA
37 {0x00, 0xff, 0xff, 0x00}, // YELLOW
38 {0xff, 0xff, 0xff, 0x00}, // WHITE
43 Insert a character cell information to the list specified by GlyphInfoList.
45 This is a internal function.
47 @param CharValue Unicode character value, which identifies a glyph
49 @param GlyphInfoList HII_GLYPH_INFO list head.
50 @param Cell Incoming character cell information.
52 @retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
53 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
60 IN LIST_ENTRY
*GlyphInfoList
,
61 IN EFI_HII_GLYPH_INFO
*Cell
64 HII_GLYPH_INFO
*GlyphInfo
;
66 ASSERT (Cell
!= NULL
&& GlyphInfoList
!= NULL
);
68 GlyphInfo
= (HII_GLYPH_INFO
*) AllocateZeroPool (sizeof (HII_GLYPH_INFO
));
69 if (GlyphInfo
== NULL
) {
70 return EFI_OUT_OF_RESOURCES
;
74 // GlyphInfoList stores a list of default character cell information, each is
75 // identified by "CharId".
77 GlyphInfo
->Signature
= HII_GLYPH_INFO_SIGNATURE
;
78 GlyphInfo
->CharId
= CharValue
;
79 CopyMem (&GlyphInfo
->Cell
, Cell
, sizeof (EFI_HII_GLYPH_INFO
));
80 InsertTailList (GlyphInfoList
, &GlyphInfo
->Entry
);
87 Get a character cell information from the list specified by GlyphInfoList.
89 This is a internal function.
91 @param CharValue Unicode character value, which identifies a glyph
93 @param GlyphInfoList HII_GLYPH_INFO list head.
94 @param Cell Buffer which stores output character cell
97 @retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
98 @retval EFI_NOT_FOUND The character info specified by CharValue does
105 IN LIST_ENTRY
*GlyphInfoList
,
106 OUT EFI_HII_GLYPH_INFO
*Cell
109 HII_GLYPH_INFO
*GlyphInfo
;
112 ASSERT (Cell
!= NULL
&& GlyphInfoList
!= NULL
);
115 // Since the EFI_HII_GIBT_DEFAULTS block won't increment CharValueCurrent,
116 // the value of "CharId" of a default character cell which is used for a
117 // EFI_HII_GIBT_GLYPH_DEFAULT or EFI_HII_GIBT_GLYPHS_DEFAULT should be
118 // less or equal to the value of "CharValueCurrent" of this default block.
120 // For instance, if the CharId of a GlyphInfoList is {1, 3, 7}, a default glyph
121 // with CharValue equals "7" uses the GlyphInfo with CharId = 7;
122 // a default glyph with CharValue equals "6" uses the GlyphInfo with CharId = 3.
124 for (Link
= GlyphInfoList
->BackLink
; Link
!= GlyphInfoList
; Link
= Link
->BackLink
) {
125 GlyphInfo
= CR (Link
, HII_GLYPH_INFO
, Entry
, HII_GLYPH_INFO_SIGNATURE
);
126 if (GlyphInfo
->CharId
<= CharValue
) {
127 CopyMem (Cell
, &GlyphInfo
->Cell
, sizeof (EFI_HII_GLYPH_INFO
));
132 return EFI_NOT_FOUND
;
137 Convert the glyph for a single character into a bitmap.
139 This is a internal function.
141 @param Private HII database driver private data.
142 @param Char Character to retrieve.
143 @param StringInfo Points to the string font and color information
144 or NULL if the string should use the default
145 system font and color.
146 @param GlyphBuffer Buffer to store the retrieved bitmap data.
147 @param Cell Points to EFI_HII_GLYPH_INFO structure.
148 @param Attributes If not NULL, output the glyph attributes if any.
150 @retval EFI_SUCCESS Glyph bitmap outputted.
151 @retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer GlyphBuffer.
152 @retval EFI_NOT_FOUND The glyph was unknown can not be found.
153 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
158 IN HII_DATABASE_PRIVATE_DATA
*Private
,
160 IN EFI_FONT_INFO
*StringInfo
,
161 OUT UINT8
**GlyphBuffer
,
162 OUT EFI_HII_GLYPH_INFO
*Cell
,
163 OUT UINT8
*Attributes OPTIONAL
166 HII_DATABASE_RECORD
*Node
;
168 HII_SIMPLE_FONT_PACKAGE_INSTANCE
*SimpleFont
;
171 EFI_NARROW_GLYPH Narrow
;
173 HII_GLOBAL_FONT_INFO
*GlobalFont
;
175 EFI_NARROW_GLYPH
*NarrowPtr
;
176 EFI_WIDE_GLYPH
*WidePtr
;
178 if (GlyphBuffer
== NULL
|| Cell
== NULL
) {
179 return EFI_INVALID_PARAMETER
;
181 if (Private
== NULL
|| Private
->Signature
!= HII_DATABASE_PRIVATE_DATA_SIGNATURE
) {
182 return EFI_INVALID_PARAMETER
;
185 ZeroMem (Cell
, sizeof (EFI_HII_GLYPH_INFO
));
188 // If StringInfo is not NULL, it must point to an existing EFI_FONT_INFO rather
189 // than system default font and color.
190 // If NULL, try to find the character in simplified font packages since
191 // default system font is the fixed font (narrow or wide glyph).
193 if (StringInfo
!= NULL
) {
194 if(!IsFontInfoExisted (Private
, StringInfo
, NULL
, NULL
, &GlobalFont
)) {
195 return EFI_INVALID_PARAMETER
;
197 if (Attributes
!= NULL
) {
198 *Attributes
= PROPORTIONAL_GLYPH
;
200 return FindGlyphBlock (GlobalFont
->FontPackage
, Char
, GlyphBuffer
, Cell
, NULL
);
202 HeaderSize
= sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR
);
204 for (Link
= Private
->DatabaseList
.ForwardLink
; Link
!= &Private
->DatabaseList
; Link
= Link
->ForwardLink
) {
205 Node
= CR (Link
, HII_DATABASE_RECORD
, DatabaseEntry
, HII_DATABASE_RECORD_SIGNATURE
);
206 for (Link1
= Node
->PackageList
->SimpleFontPkgHdr
.ForwardLink
;
207 Link1
!= &Node
->PackageList
->SimpleFontPkgHdr
;
208 Link1
= Link1
->ForwardLink
210 SimpleFont
= CR (Link1
, HII_SIMPLE_FONT_PACKAGE_INSTANCE
, SimpleFontEntry
, HII_S_FONT_PACKAGE_SIGNATURE
);
212 // Search the narrow glyph array
214 NarrowPtr
= (EFI_NARROW_GLYPH
*) ((UINT8
*) (SimpleFont
->SimpleFontPkgHdr
) + HeaderSize
);
215 for (Index
= 0; Index
< SimpleFont
->SimpleFontPkgHdr
->NumberOfNarrowGlyphs
; Index
++) {
216 CopyMem (&Narrow
, NarrowPtr
+ Index
,sizeof (EFI_NARROW_GLYPH
));
217 if (Narrow
.UnicodeWeight
== Char
) {
218 *GlyphBuffer
= (UINT8
*) AllocateZeroPool (EFI_GLYPH_HEIGHT
);
219 if (*GlyphBuffer
== NULL
) {
220 return EFI_OUT_OF_RESOURCES
;
222 Cell
->Width
= EFI_GLYPH_WIDTH
;
223 Cell
->Height
= EFI_GLYPH_HEIGHT
;
224 Cell
->OffsetY
= NARROW_BASELINE
;
225 Cell
->AdvanceX
= Cell
->Width
;
226 CopyMem (*GlyphBuffer
, Narrow
.GlyphCol1
, Cell
->Height
);
227 if (Attributes
!= NULL
) {
228 *Attributes
= (UINT8
) (Narrow
.Attributes
| NARROW_GLYPH
);
234 // Search the wide glyph array
236 WidePtr
= (EFI_WIDE_GLYPH
*) (NarrowPtr
+ SimpleFont
->SimpleFontPkgHdr
->NumberOfNarrowGlyphs
);
237 for (Index
= 0; Index
< SimpleFont
->SimpleFontPkgHdr
->NumberOfWideGlyphs
; Index
++) {
238 CopyMem (&Wide
, WidePtr
+ Index
, sizeof (EFI_WIDE_GLYPH
));
239 if (Wide
.UnicodeWeight
== Char
) {
240 *GlyphBuffer
= (UINT8
*) AllocateZeroPool (EFI_GLYPH_HEIGHT
* 2);
241 if (*GlyphBuffer
== NULL
) {
242 return EFI_OUT_OF_RESOURCES
;
244 Cell
->Width
= EFI_GLYPH_WIDTH
* 2;
245 Cell
->Height
= EFI_GLYPH_HEIGHT
;
246 Cell
->OffsetY
= WIDE_BASELINE
;
247 Cell
->AdvanceX
= Cell
->Width
;
248 CopyMem (*GlyphBuffer
, Wide
.GlyphCol1
, EFI_GLYPH_HEIGHT
);
249 CopyMem (*GlyphBuffer
+ EFI_GLYPH_HEIGHT
, Wide
.GlyphCol2
, EFI_GLYPH_HEIGHT
);
250 if (Attributes
!= NULL
) {
251 *Attributes
= (UINT8
) (Wide
.Attributes
| EFI_GLYPH_WIDE
);
260 return EFI_NOT_FOUND
;
264 Convert bitmap data of the glyph to blt structure.
266 This is a internal function.
268 @param GlyphBuffer Buffer points to bitmap data of glyph.
269 @param Foreground The color of the "on" pixels in the glyph in the
271 @param Background The color of the "off" pixels in the glyph in the
273 @param ImageWidth Width of the character or character cell, in
275 @param ImageHeight Height of the character or character cell, in
277 @param Transparent If TRUE, the Background color is ignored and all
278 "off" pixels in the character's drawn wil use the
279 pixel value from BltBuffer.
280 @param Origin On input, points to the origin of the to be
281 displayed character, on output, points to the
287 IN UINT8
*GlyphBuffer
,
288 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
,
289 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
,
291 IN UINTN ImageHeight
,
292 IN BOOLEAN Transparent
,
293 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**Origin
300 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Buffer
;
302 ASSERT (GlyphBuffer
!= NULL
&& Origin
!= NULL
&& *Origin
!= NULL
);
304 Height
= EFI_GLYPH_HEIGHT
;
305 Width
= EFI_GLYPH_WIDTH
;
307 ASSERT (Width
<= ImageWidth
&& Height
<= ImageHeight
);
311 for (Ypos
= 0; Ypos
< Height
; Ypos
++) {
312 for (Xpos
= 0; Xpos
< Width
; Xpos
++) {
313 if ((GlyphBuffer
[Ypos
] & (1 << Xpos
)) != 0) {
314 Buffer
[Ypos
* ImageWidth
+ (Width
- Xpos
- 1)] = Foreground
;
317 Buffer
[Ypos
* ImageWidth
+ (Width
- Xpos
- 1)] = Background
;
323 *Origin
= Buffer
+ Width
;
328 Convert bitmap data of the glyph to blt structure.
330 This is a internal function.
332 @param GlyphBuffer Buffer points to bitmap data of glyph.
333 @param Foreground The color of the "on" pixels in the glyph in the
335 @param Background The color of the "off" pixels in the glyph in the
337 @param ImageWidth Width of the character or character cell, in
339 @param ImageHeight Height of the character or character cell, in
341 @param Transparent If TRUE, the Background color is ignored and all
342 "off" pixels in the character's drawn wil use the
343 pixel value from BltBuffer.
344 @param Cell Points to EFI_HII_GLYPH_INFO structure.
345 @param Attributes The attribute of incoming glyph in GlyphBuffer.
346 @param Origin On input, points to the origin of the to be
347 displayed character, on output, points to the
354 IN UINT8
*GlyphBuffer
,
355 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
,
356 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
,
358 IN UINTN ImageHeight
,
359 IN BOOLEAN Transparent
,
360 IN CONST EFI_HII_GLYPH_INFO
*Cell
,
362 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**Origin
370 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
372 ASSERT (GlyphBuffer
!= NULL
&& Origin
!= NULL
&& *Origin
!= NULL
);
373 ASSERT (Cell
->Width
<= ImageWidth
&& Cell
->Height
<= ImageHeight
);
378 // Since non-spacing key will be printed OR'd with the previous glyph, don't
381 if ((Attributes
& EFI_GLYPH_NON_SPACING
) == EFI_GLYPH_NON_SPACING
) {
386 // The glyph's upper left hand corner pixel is the most significant bit of the
387 // first bitmap byte.
389 for (Ypos
= 0; Ypos
< Cell
->Height
; Ypos
++) {
390 OffsetY
= BITMAP_LEN_1_BIT (Cell
->Width
, Ypos
);
393 // All bits in these bytes are meaningful.
395 for (Xpos
= 0; Xpos
< Cell
->Width
/ 8; Xpos
++) {
396 Data
= *(GlyphBuffer
+ OffsetY
+ Xpos
);
397 for (Index
= 0; Index
< 8; Index
++) {
398 if ((Data
& (1 << Index
)) != 0) {
399 BltBuffer
[Ypos
* ImageWidth
+ Xpos
* 8 + (8 - Index
- 1)] = Foreground
;
402 BltBuffer
[Ypos
* ImageWidth
+ Xpos
* 8 + (8 - Index
- 1)] = Background
;
408 if (Cell
->Width
% 8 != 0) {
410 // There are some padding bits in this byte. Ignore them.
412 Data
= *(GlyphBuffer
+ OffsetY
+ Xpos
);
413 for (Index
= 0; Index
< Cell
->Width
% 8; Index
++) {
414 if ((Data
& (1 << (8 - Index
- 1))) != 0) {
415 BltBuffer
[Ypos
* ImageWidth
+ Xpos
* 8 + Index
] = Foreground
;
418 BltBuffer
[Ypos
* ImageWidth
+ Xpos
* 8 + Index
] = Background
;
422 } // end of if (Width % 8...)
424 } // end of for (Ypos=0...)
426 *Origin
= BltBuffer
+ Cell
->Width
;
431 Convert bitmap data of the glyph to blt structure.
433 This is a internal function.
435 @param GlyphBuffer Buffer points to bitmap data of glyph.
436 @param Foreground The color of the "on" pixels in the glyph in the
438 @param Background The color of the "off" pixels in the glyph in the
440 @param ImageWidth Width of the character or character cell, in
442 @param ImageHeight Height of the character or character cell, in
444 @param Transparent If TRUE, the Background color is ignored and all
445 "off" pixels in the character's drawn wil use the
446 pixel value from BltBuffer.
447 @param Cell Points to EFI_HII_GLYPH_INFO structure.
448 @param Attributes The attribute of incoming glyph in GlyphBuffer.
449 @param Origin On input, points to the origin of the to be
450 displayed character, on output, points to the
453 @return Points to the address of next origin node in BltBuffer.
458 IN UINT8
*GlyphBuffer
,
459 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
,
460 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
,
462 IN UINTN ImageHeight
,
463 IN BOOLEAN Transparent
,
464 IN CONST EFI_HII_GLYPH_INFO
*Cell
,
466 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
**Origin
469 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*Buffer
;
471 ASSERT (GlyphBuffer
!= NULL
&& Origin
!= NULL
&& *Origin
!= NULL
);
472 ASSERT (Cell
->Width
<= ImageWidth
&& Cell
->Height
<= ImageHeight
);
476 if ((Attributes
& EFI_GLYPH_NON_SPACING
) == EFI_GLYPH_NON_SPACING
) {
478 // This character is a non-spacing key, print it OR'd with the previous glyph.
479 // without advancing cursor.
481 Buffer
-= Cell
->Width
;
494 } else if ((Attributes
& EFI_GLYPH_WIDE
) == EFI_GLYPH_WIDE
) {
496 // This character is wide glyph, i.e. 16 pixels * 19 pixels.
497 // Draw it as two narrow glyphs.
510 GlyphBuffer
+ EFI_GLYPH_HEIGHT
,
519 } else if ((Attributes
& NARROW_GLYPH
) == NARROW_GLYPH
) {
521 // This character is narrow glyph, i.e. 8 pixels * 19 pixels.
533 } else if ((Attributes
& PROPORTIONAL_GLYPH
) == PROPORTIONAL_GLYPH
) {
535 // This character is proportional glyph, i.e. Cell->Width * Cell->Height pixels.
553 Write the output parameters of FindGlyphBlock().
555 This is a internal function.
557 @param BufferIn Buffer which stores the bitmap data of the found
559 @param BufferLen Length of BufferIn.
560 @param InputCell Buffer which stores cell information of the
562 @param GlyphBuffer Output the corresponding bitmap data of the found
563 block. It is the caller's responsiblity to free
565 @param Cell Output cell information of the encoded bitmap.
566 @param GlyphBufferLen If not NULL, output the length of GlyphBuffer.
568 @retval EFI_SUCCESS The operation is performed successfully.
569 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
570 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
578 IN EFI_HII_GLYPH_INFO
*InputCell
,
579 OUT UINT8
**GlyphBuffer
, OPTIONAL
580 OUT EFI_HII_GLYPH_INFO
*Cell
, OPTIONAL
581 OUT UINTN
*GlyphBufferLen OPTIONAL
584 if (BufferIn
== NULL
|| BufferLen
< 1 || InputCell
== NULL
) {
585 return EFI_INVALID_PARAMETER
;
589 CopyMem (Cell
, InputCell
, sizeof (EFI_HII_GLYPH_INFO
));
592 if (GlyphBuffer
!= NULL
) {
593 *GlyphBuffer
= (UINT8
*) AllocateZeroPool (BufferLen
);
594 if (*GlyphBuffer
== NULL
) {
595 return EFI_OUT_OF_RESOURCES
;
597 CopyMem (*GlyphBuffer
, BufferIn
, BufferLen
);
600 if (GlyphBufferLen
!= NULL
) {
601 *GlyphBufferLen
= BufferLen
;
609 Parse all glyph blocks to find a glyph block specified by CharValue.
610 If CharValue = (CHAR16) (-1), collect all default character cell information
611 within this font package and backup its information.
613 @param FontPackage Hii string package instance.
614 @param CharValue Unicode character value, which identifies a glyph
616 @param GlyphBuffer Output the corresponding bitmap data of the found
617 block. It is the caller's responsiblity to free
619 @param Cell Output cell information of the encoded bitmap.
620 @param GlyphBufferLen If not NULL, output the length of GlyphBuffer.
622 @retval EFI_SUCCESS The bitmap data is retrieved successfully.
623 @retval EFI_NOT_FOUND The specified CharValue does not exist in current
625 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
631 IN HII_FONT_PACKAGE_INSTANCE
*FontPackage
,
633 OUT UINT8
**GlyphBuffer
, OPTIONAL
634 OUT EFI_HII_GLYPH_INFO
*Cell
, OPTIONAL
635 OUT UINTN
*GlyphBufferLen OPTIONAL
643 EFI_HII_GIBT_GLYPHS_BLOCK Glyphs
;
646 EFI_HII_GLYPH_INFO DefaultCell
;
647 EFI_HII_GLYPH_INFO LocalCell
;
649 ASSERT (FontPackage
!= NULL
);
650 ASSERT (FontPackage
->Signature
== HII_FONT_PACKAGE_SIGNATURE
);
652 if (CharValue
== (CHAR16
) (-1)) {
654 // Collect the cell information specified in font package fixed header.
655 // Use CharValue =0 to represent this particular cell.
659 &FontPackage
->GlyphInfoList
,
660 (EFI_HII_GLYPH_INFO
*) ((UINT8
*) FontPackage
->FontPkgHdr
+ 3 * sizeof (UINT32
))
662 if (EFI_ERROR (Status
)) {
667 BlockPtr
= FontPackage
->GlyphBlock
;
671 while (*BlockPtr
!= EFI_HII_GIBT_END
) {
673 case EFI_HII_GIBT_DEFAULTS
:
675 // Collect all default character cell information specified by
676 // EFI_HII_GIBT_DEFAULTS.
678 if (CharValue
== (CHAR16
) (-1)) {
681 &FontPackage
->GlyphInfoList
,
682 (EFI_HII_GLYPH_INFO
*) (BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
))
684 if (EFI_ERROR (Status
)) {
688 BlockPtr
+= sizeof (EFI_HII_GIBT_DEFAULTS_BLOCK
);
691 case EFI_HII_GIBT_DUPLICATE
:
692 if (CharCurrent
== CharValue
) {
693 CopyMem (&CharValue
, BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
), sizeof (CHAR16
));
695 BlockPtr
= FontPackage
->GlyphBlock
;
699 BlockPtr
+= sizeof (EFI_HII_GIBT_DUPLICATE_BLOCK
);
702 case EFI_HII_GIBT_EXT1
:
703 BlockPtr
+= *(BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
) + sizeof (UINT8
));
705 case EFI_HII_GIBT_EXT2
:
708 BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
) + sizeof (UINT8
),
711 BlockPtr
+= Length16
;
713 case EFI_HII_GIBT_EXT4
:
716 BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
) + sizeof (UINT8
),
719 BlockPtr
+= Length32
;
722 case EFI_HII_GIBT_GLYPH
:
725 BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
),
726 sizeof (EFI_HII_GLYPH_INFO
)
728 BufferLen
= BITMAP_LEN_1_BIT (LocalCell
.Width
, LocalCell
.Height
);
729 if (CharCurrent
== CharValue
) {
730 return WriteOutputParam (
731 BlockPtr
+ sizeof (EFI_HII_GIBT_GLYPH_BLOCK
) - sizeof (UINT8
),
740 BlockPtr
+= sizeof (EFI_HII_GIBT_GLYPH_BLOCK
) - sizeof (UINT8
) + BufferLen
;
743 case EFI_HII_GIBT_GLYPHS
:
744 BlockPtr
+= sizeof (EFI_HII_GLYPH_BLOCK
);
745 CopyMem (&Glyphs
.Cell
, BlockPtr
, sizeof (EFI_HII_GLYPH_INFO
));
746 BlockPtr
+= sizeof (EFI_HII_GLYPH_INFO
);
747 CopyMem (&Glyphs
.Count
, BlockPtr
, sizeof (UINT16
));
748 BlockPtr
+= sizeof (UINT16
);
750 BufferLen
= BITMAP_LEN_1_BIT (Glyphs
.Cell
.Width
, Glyphs
.Cell
.Height
);
751 for (Index
= 0; Index
< Glyphs
.Count
; Index
++) {
752 if (CharCurrent
+ Index
== CharValue
) {
753 return WriteOutputParam (
762 BlockPtr
+= BufferLen
;
764 CharCurrent
= (UINT16
) (CharCurrent
+ Glyphs
.Count
);
767 case EFI_HII_GIBT_GLYPH_DEFAULT
:
768 Status
= GetCell (CharCurrent
, &FontPackage
->GlyphInfoList
, &DefaultCell
);
769 if (EFI_ERROR (Status
)) {
772 BufferLen
= BITMAP_LEN_1_BIT (DefaultCell
.Width
, DefaultCell
.Height
);
774 if (CharCurrent
== CharValue
) {
775 return WriteOutputParam (
776 BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
),
785 BlockPtr
+= sizeof (EFI_HII_GLYPH_BLOCK
) + BufferLen
;
788 case EFI_HII_GIBT_GLYPHS_DEFAULT
:
789 CopyMem (&Length16
, BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
), sizeof (UINT16
));
790 Status
= GetCell (CharCurrent
, &FontPackage
->GlyphInfoList
, &DefaultCell
);
791 if (EFI_ERROR (Status
)) {
794 BufferLen
= BITMAP_LEN_1_BIT (DefaultCell
.Width
, DefaultCell
.Height
);
795 BlockPtr
+= sizeof (EFI_HII_GIBT_GLYPHS_DEFAULT_BLOCK
) - sizeof (UINT8
);
796 for (Index
= 0; Index
< Length16
; Index
++) {
797 if (CharCurrent
+ Index
== CharValue
) {
798 return WriteOutputParam (
807 BlockPtr
+= BufferLen
;
809 CharCurrent
= (UINT16
) (CharCurrent
+ Length16
);
812 case EFI_HII_GIBT_SKIP1
:
813 CharCurrent
= (UINT16
) (CharCurrent
+ (UINT16
) (*(BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
))));
814 BlockPtr
+= sizeof (EFI_HII_GIBT_SKIP1_BLOCK
);
816 case EFI_HII_GIBT_SKIP2
:
817 CopyMem (&Length16
, BlockPtr
+ sizeof (EFI_HII_GLYPH_BLOCK
), sizeof (UINT16
));
818 CharCurrent
= (UINT16
) (CharCurrent
+ Length16
);
819 BlockPtr
+= sizeof (EFI_HII_GIBT_SKIP2_BLOCK
);
826 if (CharValue
< CharCurrent
) {
827 return EFI_NOT_FOUND
;
831 if (CharValue
== (CHAR16
) (-1)) {
835 return EFI_NOT_FOUND
;
840 Copy a Font Name to a new created EFI_FONT_INFO structure.
842 This is a internal function.
844 @param FontName NULL-terminated string.
845 @param FontInfo a new EFI_FONT_INFO which stores the FontName.
846 It's caller's responsibility to free this buffer.
848 @retval EFI_SUCCESS FontInfo is allocated and copied with FontName.
849 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
855 IN EFI_STRING FontName
,
856 OUT EFI_FONT_INFO
**FontInfo
861 ASSERT (FontName
!= NULL
&& FontInfo
!= NULL
);
863 FontInfoLen
= sizeof (EFI_FONT_INFO
) - sizeof (CHAR16
) + StrSize (FontName
);
864 *FontInfo
= (EFI_FONT_INFO
*) AllocateZeroPool (FontInfoLen
);
865 if (*FontInfo
== NULL
) {
866 return EFI_OUT_OF_RESOURCES
;
869 StrCpy ((*FontInfo
)->FontName
, FontName
);
875 Retrieve system default font and color.
877 @param Private HII database driver private data.
878 @param FontInfo Points to system default font output-related
879 information. It's caller's responsibility to free
881 @param FontInfoSize If not NULL, output the size of buffer FontInfo.
883 @retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
884 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
886 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
891 IN HII_DATABASE_PRIVATE_DATA
*Private
,
892 OUT EFI_FONT_DISPLAY_INFO
**FontInfo
,
893 OUT UINTN
*FontInfoSize OPTIONAL
896 EFI_FONT_DISPLAY_INFO
*Info
;
899 if (Private
== NULL
|| Private
->Signature
!= HII_DATABASE_PRIVATE_DATA_SIGNATURE
) {
900 return EFI_INVALID_PARAMETER
;
902 if (FontInfo
== NULL
) {
903 return EFI_INVALID_PARAMETER
;
907 // The standard font always has the name "sysdefault".
909 InfoSize
= sizeof (EFI_FONT_DISPLAY_INFO
) - sizeof (CHAR16
) + StrSize (L
"sysdefault");
910 Info
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (InfoSize
);
912 return EFI_OUT_OF_RESOURCES
;
915 Info
->ForegroundColor
= mHiiEfiColors
[Private
->Attribute
& 0x0f];
916 Info
->BackgroundColor
= mHiiEfiColors
[Private
->Attribute
>> 4];
917 Info
->FontInfoMask
= EFI_FONT_INFO_SYS_FONT
| EFI_FONT_INFO_SYS_SIZE
| EFI_FONT_INFO_SYS_STYLE
;
918 Info
->FontInfo
.FontStyle
= 0;
919 Info
->FontInfo
.FontSize
= EFI_GLYPH_HEIGHT
;
920 StrCpy (Info
->FontInfo
.FontName
, L
"sysdefault");
923 if (FontInfoSize
!= NULL
) {
924 *FontInfoSize
= InfoSize
;
931 Check whether EFI_FONT_DISPLAY_INFO points to system default font and color or
932 returns the system default according to the optional inputs.
934 This is a internal function.
936 @param Private HII database driver private data.
937 @param StringInfo Points to the string output information,
938 including the color and font.
939 @param SystemInfo If not NULL, points to system default font and color.
941 @param SystemInfoLen If not NULL, output the length of default system
944 @retval TRUE Yes, it points to system default.
950 IN HII_DATABASE_PRIVATE_DATA
*Private
,
951 IN EFI_FONT_DISPLAY_INFO
*StringInfo
,
952 OUT EFI_FONT_DISPLAY_INFO
**SystemInfo
, OPTIONAL
953 OUT UINTN
*SystemInfoLen OPTIONAL
957 EFI_FONT_DISPLAY_INFO
*SystemDefault
;
961 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
963 if (StringInfo
== NULL
&& SystemInfo
== NULL
) {
967 Status
= GetSystemFont (Private
, &SystemDefault
, &DefaultLen
);
968 ASSERT_EFI_ERROR (Status
);
971 // Record the system default info.
973 if (SystemInfo
!= NULL
) {
974 *SystemInfo
= SystemDefault
;
977 if (SystemInfoLen
!= NULL
) {
978 *SystemInfoLen
= DefaultLen
;
981 if (StringInfo
== NULL
) {
987 // Check the FontInfoMask to see whether it is retrieving system info.
989 if ((StringInfo
->FontInfoMask
& (EFI_FONT_INFO_SYS_FONT
| EFI_FONT_INFO_ANY_FONT
)) == 0) {
990 if (StrCmp (StringInfo
->FontInfo
.FontName
, SystemDefault
->FontInfo
.FontName
) != 0) {
994 if ((StringInfo
->FontInfoMask
& (EFI_FONT_INFO_SYS_SIZE
| EFI_FONT_INFO_ANY_SIZE
)) == 0) {
995 if (StringInfo
->FontInfo
.FontSize
!= SystemDefault
->FontInfo
.FontSize
) {
999 if ((StringInfo
->FontInfoMask
& (EFI_FONT_INFO_SYS_STYLE
| EFI_FONT_INFO_ANY_STYLE
)) == 0) {
1000 if (StringInfo
->FontInfo
.FontStyle
!= SystemDefault
->FontInfo
.FontStyle
) {
1004 if ((StringInfo
->FontInfoMask
& EFI_FONT_INFO_SYS_FORE_COLOR
) == 0) {
1006 &StringInfo
->ForegroundColor
,
1007 &SystemDefault
->ForegroundColor
,
1008 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1013 if ((StringInfo
->FontInfoMask
& EFI_FONT_INFO_SYS_BACK_COLOR
) == 0) {
1015 &StringInfo
->BackgroundColor
,
1016 &SystemDefault
->BackgroundColor
,
1017 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
)
1026 if (SystemInfo
== NULL
) {
1027 if (SystemDefault
!= NULL
) {
1028 FreePool (SystemDefault
);
1036 This function checks whether EFI_FONT_INFO exists in current database. If
1037 FontInfoMask is specified, check what options can be used to make a match.
1038 Note that the masks relate to where the system default should be supplied
1039 are ignored by this function.
1041 @param Private Hii database private structure.
1042 @param FontInfo Points to EFI_FONT_INFO structure.
1043 @param FontInfoMask If not NULL, describes what options can be used
1044 to make a match between the font requested and
1045 the font available. The caller must guarantee
1047 @param FontHandle On entry, Points to the font handle returned by a
1048 previous call to GetFontInfo() or NULL to start
1049 with the first font.
1050 @param GlobalFontInfo If not NULL, output the corresponding globa font
1053 @retval TRUE Existed
1054 @retval FALSE Not existed
1059 IN HII_DATABASE_PRIVATE_DATA
*Private
,
1060 IN EFI_FONT_INFO
*FontInfo
,
1061 IN EFI_FONT_INFO_MASK
*FontInfoMask
, OPTIONAL
1062 IN EFI_FONT_HANDLE FontHandle
, OPTIONAL
1063 OUT HII_GLOBAL_FONT_INFO
**GlobalFontInfo OPTIONAL
1066 HII_GLOBAL_FONT_INFO
*GlobalFont
;
1067 HII_GLOBAL_FONT_INFO
*GlobalFontBackup1
;
1068 HII_GLOBAL_FONT_INFO
*GlobalFontBackup2
;
1070 EFI_FONT_INFO_MASK Mask
;
1072 BOOLEAN VagueMatched1
;
1073 BOOLEAN VagueMatched2
;
1075 ASSERT (Private
!= NULL
&& Private
->Signature
== HII_DATABASE_PRIVATE_DATA_SIGNATURE
);
1076 ASSERT (FontInfo
!= NULL
);
1079 // Matched flag represents an exactly match; VagueMatched1 repensents a RESIZE
1080 // or RESTYLE match; VagueMatched2 represents a RESIZE | RESTYLE match.
1083 VagueMatched1
= FALSE
;
1084 VagueMatched2
= FALSE
;
1087 GlobalFontBackup1
= NULL
;
1088 GlobalFontBackup2
= NULL
;
1090 // The process of where the system default should be supplied instead of
1091 // the specified font info beyonds this function's scope.
1093 if (FontInfoMask
!= NULL
) {
1094 Mask
= *FontInfoMask
& (~SYS_FONT_INFO_MASK
);
1098 // If not NULL, FontHandle points to the next node of the last searched font
1099 // node by previous call.
1101 if (FontHandle
== NULL
) {
1102 Link
= Private
->FontInfoList
.ForwardLink
;
1104 Link
= (LIST_ENTRY
*) FontHandle
;
1107 for (; Link
!= &Private
->FontInfoList
; Link
= Link
->ForwardLink
) {
1108 GlobalFont
= CR (Link
, HII_GLOBAL_FONT_INFO
, Entry
, HII_GLOBAL_FONT_INFO_SIGNATURE
);
1109 if (FontInfoMask
== NULL
) {
1110 if (CompareMem (GlobalFont
->FontInfo
, FontInfo
, GlobalFont
->FontInfoSize
) == 0) {
1111 if (GlobalFontInfo
!= NULL
) {
1112 *GlobalFontInfo
= GlobalFont
;
1118 // Check which options could be used to make a match.
1121 case EFI_FONT_INFO_ANY_FONT
:
1122 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
&&
1123 GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1127 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_ANY_STYLE
:
1128 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1132 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_ANY_SIZE
:
1133 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1137 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_ANY_SIZE
| EFI_FONT_INFO_ANY_STYLE
:
1141 // If EFI_FONT_INFO_RESTYLE is specified, then the system may attempt to
1142 // remove some of the specified styles to meet the style requested.
1144 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_RESTYLE
:
1145 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1146 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1148 } else if ((GlobalFont
->FontInfo
->FontStyle
& FontInfo
->FontStyle
) == FontInfo
->FontStyle
) {
1149 VagueMatched1
= TRUE
;
1150 GlobalFontBackup1
= GlobalFont
;
1155 // If EFI_FONT_INFO_RESIZE is specified, then the sytem may attempt to
1156 // stretch or shrink a font to meet the size requested.
1158 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_RESIZE
:
1159 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1160 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1163 VagueMatched1
= TRUE
;
1164 GlobalFontBackup1
= GlobalFont
;
1168 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_RESTYLE
| EFI_FONT_INFO_RESIZE
:
1169 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1170 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1173 VagueMatched1
= TRUE
;
1174 GlobalFontBackup1
= GlobalFont
;
1176 } else if ((GlobalFont
->FontInfo
->FontStyle
& FontInfo
->FontStyle
) == FontInfo
->FontStyle
) {
1177 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1178 VagueMatched1
= TRUE
;
1179 GlobalFontBackup1
= GlobalFont
;
1181 VagueMatched2
= TRUE
;
1182 GlobalFontBackup2
= GlobalFont
;
1186 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_ANY_STYLE
| EFI_FONT_INFO_RESIZE
:
1187 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1190 VagueMatched1
= TRUE
;
1191 GlobalFontBackup1
= GlobalFont
;
1194 case EFI_FONT_INFO_ANY_FONT
| EFI_FONT_INFO_ANY_SIZE
| EFI_FONT_INFO_RESTYLE
:
1195 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1197 } else if ((GlobalFont
->FontInfo
->FontStyle
& FontInfo
->FontStyle
) == FontInfo
->FontStyle
) {
1198 VagueMatched1
= TRUE
;
1199 GlobalFontBackup1
= GlobalFont
;
1202 case EFI_FONT_INFO_ANY_STYLE
:
1204 GlobalFont
->FontInfo
->FontName
,
1206 StrSize (FontInfo
->FontName
)
1208 GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1212 case EFI_FONT_INFO_ANY_STYLE
| EFI_FONT_INFO_ANY_SIZE
:
1214 GlobalFont
->FontInfo
->FontName
,
1216 StrSize (FontInfo
->FontName
)
1221 case EFI_FONT_INFO_ANY_STYLE
| EFI_FONT_INFO_RESIZE
:
1223 GlobalFont
->FontInfo
->FontName
,
1225 StrSize (FontInfo
->FontName
)
1227 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1230 VagueMatched1
= TRUE
;
1231 GlobalFontBackup1
= GlobalFont
;
1235 case EFI_FONT_INFO_ANY_SIZE
:
1237 GlobalFont
->FontInfo
->FontName
,
1239 StrSize (FontInfo
->FontName
)
1241 GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1245 case EFI_FONT_INFO_ANY_SIZE
| EFI_FONT_INFO_RESTYLE
:
1247 GlobalFont
->FontInfo
->FontName
,
1249 StrSize (FontInfo
->FontName
)
1251 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1253 } else if ((GlobalFont
->FontInfo
->FontStyle
& FontInfo
->FontStyle
) == FontInfo
->FontStyle
) {
1254 VagueMatched1
= TRUE
;
1255 GlobalFontBackup1
= GlobalFont
;
1259 case EFI_FONT_INFO_RESTYLE
:
1261 GlobalFont
->FontInfo
->FontName
,
1263 StrSize (FontInfo
->FontName
)
1265 GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1267 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1269 } else if ((GlobalFont
->FontInfo
->FontStyle
& FontInfo
->FontStyle
) == FontInfo
->FontStyle
) {
1270 VagueMatched1
= TRUE
;
1271 GlobalFontBackup1
= GlobalFont
;
1275 case EFI_FONT_INFO_RESIZE
:
1277 GlobalFont
->FontInfo
->FontName
,
1279 StrSize (FontInfo
->FontName
)
1281 GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1283 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1286 VagueMatched1
= TRUE
;
1287 GlobalFontBackup1
= GlobalFont
;
1291 case EFI_FONT_INFO_RESIZE
| EFI_FONT_INFO_RESTYLE
:
1293 GlobalFont
->FontInfo
->FontName
,
1295 StrSize (FontInfo
->FontName
)
1297 if (GlobalFont
->FontInfo
->FontStyle
== FontInfo
->FontStyle
) {
1298 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1301 VagueMatched1
= TRUE
;
1302 GlobalFontBackup1
= GlobalFont
;
1304 } else if ((GlobalFont
->FontInfo
->FontStyle
& FontInfo
->FontStyle
) == FontInfo
->FontStyle
) {
1305 if (GlobalFont
->FontInfo
->FontSize
== FontInfo
->FontSize
) {
1306 VagueMatched1
= TRUE
;
1307 GlobalFontBackup1
= GlobalFont
;
1309 VagueMatched2
= TRUE
;
1310 GlobalFontBackup2
= GlobalFont
;
1320 if (GlobalFontInfo
!= NULL
) {
1321 *GlobalFontInfo
= GlobalFont
;
1328 if (VagueMatched1
) {
1329 if (GlobalFontInfo
!= NULL
) {
1330 *GlobalFontInfo
= GlobalFontBackup1
;
1333 } else if (VagueMatched2
) {
1334 if (GlobalFontInfo
!= NULL
) {
1335 *GlobalFontInfo
= GlobalFontBackup2
;
1345 Check whether the unicode represents a line break or not.
1347 This is a internal function. Please see Section 27.2.6 of the UEFI Specification
1348 for a description of the supported string format.
1350 @param Char Unicode character
1352 @retval 0 Yes, it forces a line break.
1353 @retval 1 Yes, it presents a line break opportunity
1354 @retval 2 Yes, it requires a line break happen before and after it.
1355 @retval -1 No, it is not a link break.
1365 // Mandatory line break characters, which force a line-break
1373 // Space characters, which is taken as a line-break opportunity
1389 // In-Word Break Opportunities
1394 // A space which is not a line-break opportunity
1399 // A hyphen which is not a line-break opportunity
1404 // Hyphen characters which describe line break opportunities after the character
1415 // A hyphen which describes line break opportunities before and after them, but not between a pair of them
1425 Renders a string to a bitmap or to the display.
1427 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
1428 @param Flags Describes how the string is to be drawn.
1429 @param String Points to the null-terminated string to be
1431 @param StringInfo Points to the string output information,
1432 including the color and font. If NULL, then the
1433 string will be output in the default system font
1435 @param Blt If this points to a non-NULL on entry, this
1436 points to the image, which is Width pixels wide
1437 and Height pixels high. The string will be drawn
1439 EFI_HII_OUT_FLAG_CLIP is implied. If this points
1440 to a NULL on entry, then a buffer
1441 will be allocated to hold the generated image and
1442 the pointer updated on exit. It is the caller's
1443 responsibility to free this buffer.
1444 @param BltX Specifies the offset from the left and top edge
1445 of the image of the first character cell in the
1447 @param BltY Specifies the offset from the left and top edge
1448 of the image of the first character cell in the
1450 @param RowInfoArray If this is non-NULL on entry, then on exit, this
1451 will point to an allocated buffer containing
1452 row information and RowInfoArraySize will be
1453 updated to contain the number of elements.
1454 This array describes the characters which were at
1455 least partially drawn and the heights of the
1456 rows. It is the caller's responsibility to free
1458 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
1459 contains the number of elements in RowInfoArray.
1460 @param ColumnInfoArray If this is non-NULL, then on return it will be
1461 filled with the horizontal offset for each
1462 character in the string on the row where it is
1463 displayed. Non-printing characters will have
1464 the offset ~0. The caller is responsible to
1465 allocate a buffer large enough so that there
1466 is one entry for each character in the string,
1467 not including the null-terminator. It is possible
1468 when character display is normalized that some
1469 character cells overlap.
1471 @retval EFI_SUCCESS The string was successfully rendered.
1472 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
1473 RowInfoArray or Blt.
1474 @retval EFI_INVALID_PARAMETER The String or Blt was NULL.
1475 @retval EFI_INVALID_PARAMETER Flags were invalid combination..
1481 IN CONST EFI_HII_FONT_PROTOCOL
*This
,
1482 IN EFI_HII_OUT_FLAGS Flags
,
1483 IN CONST EFI_STRING String
,
1484 IN CONST EFI_FONT_DISPLAY_INFO
*StringInfo OPTIONAL
,
1485 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
1488 OUT EFI_HII_ROW_INFO
**RowInfoArray OPTIONAL
,
1489 OUT UINTN
*RowInfoArraySize OPTIONAL
,
1490 OUT UINTN
*ColumnInfoArray OPTIONAL
1494 HII_DATABASE_PRIVATE_DATA
*Private
;
1496 EFI_HII_GLYPH_INFO
*Cell
;
1498 EFI_IMAGE_OUTPUT
*Image
;
1499 EFI_STRING StringPtr
;
1500 EFI_STRING StringTmp
;
1501 EFI_HII_ROW_INFO
*RowInfo
;
1504 UINTN BaseLineOffset
;
1509 EFI_FONT_DISPLAY_INFO
*StringInfoOut
;
1510 EFI_FONT_DISPLAY_INFO
*SystemDefault
;
1511 EFI_FONT_HANDLE FontHandle
;
1512 EFI_STRING StringIn
;
1513 EFI_STRING StringIn2
;
1515 EFI_FONT_INFO
*FontInfo
;
1516 BOOLEAN SysFontFlag
;
1517 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
1518 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
1519 BOOLEAN Transparent
;
1520 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
1521 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BufferPtr
;
1527 // Check incoming parameters.
1530 if (This
== NULL
|| String
== NULL
|| Blt
== NULL
) {
1531 return EFI_INVALID_PARAMETER
;
1535 // These two flag cannot be used if Blt is NULL upon entry.
1537 if ((Flags
& EFI_HII_OUT_FLAG_TRANSPARENT
) == EFI_HII_OUT_FLAG_TRANSPARENT
) {
1538 return EFI_INVALID_PARAMETER
;
1540 if ((Flags
& EFI_HII_OUT_FLAG_CLIP
) == EFI_HII_OUT_FLAG_CLIP
) {
1541 return EFI_INVALID_PARAMETER
;
1545 // These two flags require that EFI_HII_OUT_FLAG_CLIP be also set.
1547 if ((Flags
& (EFI_HII_OUT_FLAG_CLIP
| EFI_HII_OUT_FLAG_CLIP_CLEAN_X
)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_X
) {
1548 return EFI_INVALID_PARAMETER
;
1550 if ((Flags
& (EFI_HII_OUT_FLAG_CLIP
| EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
) {
1551 return EFI_INVALID_PARAMETER
;
1554 // This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X.
1556 if ((Flags
& (EFI_HII_OUT_FLAG_WRAP
| EFI_HII_OUT_FLAG_CLIP_CLEAN_X
)) == (EFI_HII_OUT_FLAG_WRAP
| EFI_HII_OUT_FLAG_CLIP_CLEAN_X
)) {
1557 return EFI_INVALID_PARAMETER
;
1562 // Create a new bitmap and draw the string onto this image.
1564 Image
= AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
1565 if (Image
== NULL
) {
1566 return EFI_OUT_OF_RESOURCES
;
1569 Image
->Height
= 600;
1570 Image
->Image
.Bitmap
= AllocateZeroPool (Image
->Width
* Image
->Height
*sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1571 if (Image
->Image
.Bitmap
== NULL
) {
1573 return EFI_OUT_OF_RESOURCES
;
1577 // Other flags are not permitted when Blt is NULL.
1579 Flags
&= EFI_HII_OUT_FLAG_WRAP
| EFI_HII_IGNORE_IF_NO_GLYPH
| EFI_HII_IGNORE_LINE_BREAK
;
1583 StrLength
= StrLen(String
);
1584 GlyphBuf
= (UINT8
**) AllocateZeroPool (StrLength
* sizeof (UINT8
*));
1585 ASSERT (GlyphBuf
!= NULL
);
1586 Cell
= (EFI_HII_GLYPH_INFO
*) AllocateZeroPool (StrLength
* sizeof (EFI_HII_GLYPH_INFO
));
1587 ASSERT (Cell
!= NULL
);
1588 Attributes
= (UINT8
*) AllocateZeroPool (StrLength
* sizeof (UINT8
));
1589 ASSERT (Attributes
!= NULL
);
1592 Status
= EFI_SUCCESS
;
1594 SystemDefault
= NULL
;
1598 // Calculate the string output information, including specified color and font .
1599 // If StringInfo does not points to system font info, it must indicate an existing
1602 StringInfoOut
= NULL
;
1604 Private
= HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
1605 SysFontFlag
= IsSystemFontInfo (Private
, (EFI_FONT_DISPLAY_INFO
*) StringInfo
, &SystemDefault
, NULL
);
1609 Height
= SystemDefault
->FontInfo
.FontSize
;
1610 Foreground
= SystemDefault
->ForegroundColor
;
1611 Background
= SystemDefault
->BackgroundColor
;
1615 // StringInfo must not be NULL if it is not system info.
1617 ASSERT (StringInfo
!= NULL
);
1618 Status
= HiiGetFontInfo (This
, &FontHandle
, (EFI_FONT_DISPLAY_INFO
*) StringInfo
, &StringInfoOut
, NULL
);
1619 if (Status
== EFI_NOT_FOUND
) {
1621 // The specified EFI_FONT_DISPLAY_INFO does not exist in current database.
1622 // Use the system font instead. Still use the color specified by StringInfo.
1626 Height
= SystemDefault
->FontInfo
.FontSize
;
1627 Foreground
= ((EFI_FONT_DISPLAY_INFO
*) StringInfo
)->ForegroundColor
;
1628 Background
= ((EFI_FONT_DISPLAY_INFO
*) StringInfo
)->BackgroundColor
;
1630 } else if (Status
== EFI_SUCCESS
) {
1631 FontInfo
= &StringInfoOut
->FontInfo
;
1632 Height
= StringInfoOut
->FontInfo
.FontSize
;
1633 Foreground
= StringInfoOut
->ForegroundColor
;
1634 Background
= StringInfoOut
->BackgroundColor
;
1641 // Parse the string to be displayed to drop some ignored characters.
1647 // Ignore line-break characters only. Hyphens or dash character will be displayed
1648 // without line-break opportunity.
1650 if ((Flags
& EFI_HII_IGNORE_LINE_BREAK
) == EFI_HII_IGNORE_LINE_BREAK
) {
1651 StringIn
= AllocateZeroPool (StrSize (StringPtr
));
1652 if (StringIn
== NULL
) {
1653 Status
= EFI_OUT_OF_RESOURCES
;
1656 StringTmp
= StringIn
;
1657 while (*StringPtr
!= 0) {
1658 if (IsLineBreak (*StringPtr
) == 0) {
1661 *StringTmp
++ = *StringPtr
++;
1665 StringPtr
= StringIn
;
1668 // If EFI_HII_IGNORE_IF_NO_GLYPH is set, then characters which have no glyphs
1669 // are not drawn. Otherwise they are replaced wth Unicode character 0xFFFD.
1671 StringIn2
= AllocateZeroPool (StrSize (StringPtr
));
1672 if (StringIn2
== NULL
) {
1673 Status
= EFI_OUT_OF_RESOURCES
;
1677 StringTmp
= StringIn2
;
1678 StrLength
= StrLen(StringPtr
);
1679 while (*StringPtr
!= 0 && Index
< StrLength
) {
1680 Status
= GetGlyphBuffer (Private
, *StringPtr
, FontInfo
, &GlyphBuf
[Index
], &Cell
[Index
], &Attributes
[Index
]);
1681 if (Status
== EFI_NOT_FOUND
) {
1682 if ((Flags
& EFI_HII_IGNORE_IF_NO_GLYPH
) == EFI_HII_IGNORE_IF_NO_GLYPH
) {
1683 GlyphBuf
[Index
] = NULL
;
1684 *StringTmp
++ = *StringPtr
++;
1688 // Unicode 0xFFFD must exist in current hii database if this flag is not set.
1690 Status
= GetGlyphBuffer (
1692 REPLACE_UNKNOWN_GLYPH
,
1698 if (EFI_ERROR (Status
)) {
1699 Status
= EFI_INVALID_PARAMETER
;
1702 *StringTmp
++ = *StringPtr
++;
1705 } else if (EFI_ERROR (Status
)) {
1708 *StringTmp
++ = *StringPtr
++;
1713 StringPtr
= StringIn2
;
1716 // Draw the string according to the specified EFI_HII_OUT_FLAGS and Blt.
1717 // If Blt is not NULL, then EFI_HII_OUT_FLAG_CLIP is implied, render this string
1718 // to an existing image (bitmap or screen depending on flags) pointed by "*Blt".
1719 // Otherwise render this string to a new allocated image and output it.
1722 BufferPtr
= Image
->Image
.Bitmap
+ Image
->Width
* BltY
+ BltX
;
1723 MaxRowNum
= (UINT16
) (Image
->Height
/ Height
);
1724 if (Image
->Height
% Height
!= 0) {
1728 RowInfo
= (EFI_HII_ROW_INFO
*) AllocateZeroPool (MaxRowNum
* sizeof (EFI_HII_ROW_INFO
));
1729 if (RowInfo
== NULL
) {
1730 Status
= EFI_OUT_OF_RESOURCES
;
1735 // Format the glyph buffer according to flags.
1738 Transparent
= (BOOLEAN
) ((Flags
& EFI_HII_OUT_FLAG_TRANSPARENT
) == EFI_HII_OUT_FLAG_TRANSPARENT
? TRUE
: FALSE
);
1739 if ((Flags
& EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
) {
1741 // Don't draw at all if there is only one row and
1742 // the row's bottom-most on pixel cannot fit.
1744 if (MaxRowNum
== 1 && SysFontFlag
) {
1745 Status
= EFI_SUCCESS
;
1750 for (RowIndex
= 0, Index
= 0; RowIndex
< MaxRowNum
&& StringPtr
[Index
] != 0; ) {
1757 // Calculate how many characters there are in a row.
1759 RowInfo
[RowIndex
].StartIndex
= Index
;
1761 while (LineWidth
+ BltX
< Image
->Width
&& StringPtr
[Index
] != 0) {
1762 if ((Flags
& EFI_HII_IGNORE_LINE_BREAK
) == 0 &&
1763 (Flags
& EFI_HII_OUT_FLAG_WRAP
) == 0 &&
1764 IsLineBreak (StringPtr
[Index
]) == 0) {
1766 // It forces a line break that ends this row.
1773 // If the glyph of the character is existing, then accumulate the actual printed width
1775 if (GlyphBuf
[Index
] != NULL
) {
1776 LineWidth
+= (UINTN
) Cell
[Index
].AdvanceX
;
1777 if (LineHeight
< Cell
[Index
].Height
) {
1778 LineHeight
= (UINTN
) Cell
[Index
].Height
;
1786 // If this character is the last character of a row, we need not
1787 // draw its (AdvanceX - Width) for next character.
1791 LineWidth
-= (UINTN
) (Cell
[Index
].AdvanceX
- Cell
[Index
].Width
);
1795 // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
1797 if (LineWidth
+ BltX
<= Image
->Width
||
1798 (LineWidth
+ BltX
> Image
->Width
&& (Flags
& EFI_HII_OUT_FLAG_CLIP_CLEAN_X
) == 0)) {
1800 // Record right-most character in RowInfo even if it is partially displayed.
1802 RowInfo
[RowIndex
].EndIndex
= Index
;
1803 RowInfo
[RowIndex
].LineWidth
= LineWidth
;
1804 RowInfo
[RowIndex
].LineHeight
= LineHeight
;
1805 RowInfo
[RowIndex
].BaselineOffset
= BaseLineOffset
;
1808 // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character
1809 // if its right-most on pixel cannot fit.
1812 RowInfo
[RowIndex
].EndIndex
= Index
- 1;
1813 RowInfo
[RowIndex
].LineWidth
= LineWidth
- Cell
[Index
].AdvanceX
;
1814 RowInfo
[RowIndex
].BaselineOffset
= BaseLineOffset
;
1815 if (LineHeight
> Cell
[Index
- 1].Height
) {
1816 LineHeight
= Cell
[Index
- 1].Height
;
1818 RowInfo
[RowIndex
].LineHeight
= LineHeight
;
1821 // There is only one column and it can not be drawn so that return directly.
1823 Status
= EFI_SUCCESS
;
1829 // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break
1830 // opportunity prior to a character whose right-most extent would exceed Width.
1831 // Search the right-most line-break opportunity here.
1833 if ((Flags
& EFI_HII_OUT_FLAG_WRAP
) == EFI_HII_OUT_FLAG_WRAP
) {
1834 if ((Flags
& EFI_HII_IGNORE_LINE_BREAK
) == 0) {
1835 for (Index1
= RowInfo
[RowIndex
].EndIndex
; Index1
>= RowInfo
[RowIndex
].StartIndex
; Index1
--) {
1836 if (IsLineBreak (StringPtr
[Index1
]) > 0) {
1838 RowInfo
[RowIndex
].EndIndex
= Index1
- 1;
1840 // relocate to the character after the right-most line break opportunity of this line
1848 // If no line-break opportunity can be found, then the text will
1849 // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.
1852 Flags
&= (~ (EFI_HII_OUT_FLAGS
) EFI_HII_OUT_FLAG_WRAP
);
1853 Flags
|= EFI_HII_OUT_FLAG_CLIP_CLEAN_X
;
1858 // Clip the final row if the row's bottom-most on pixel cannot fit when
1859 // EFI_HII_OUT_FLAG_CLEAN_Y is set.
1861 if (RowIndex
== MaxRowNum
- 1 && Image
->Height
< LineHeight
) {
1862 LineHeight
= Image
->Height
;
1863 if ((Flags
& EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y
) {
1865 // Don't draw at all if the row's bottom-most on pixel cannot fit.
1872 // Draw it to screen or existing bitmap depending on whether
1873 // EFI_HII_DIRECT_TO_SCREEN is set.
1875 if ((Flags
& EFI_HII_DIRECT_TO_SCREEN
) == EFI_HII_DIRECT_TO_SCREEN
) {
1876 BltBuffer
= AllocateZeroPool (RowInfo
[RowIndex
].LineWidth
* RowInfo
[RowIndex
].LineHeight
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
1877 if (BltBuffer
== NULL
) {
1878 Status
= EFI_OUT_OF_RESOURCES
;
1881 BufferPtr
= BltBuffer
;
1882 for (Index1
= RowInfo
[RowIndex
].StartIndex
; Index1
<= RowInfo
[RowIndex
].EndIndex
; Index1
++) {
1883 if (GlyphBuf
[Index1
] != NULL
) {
1885 // Only BLT these character which have corrsponding glyph in font basebase.
1891 RowInfo
[RowIndex
].LineWidth
,
1892 RowInfo
[RowIndex
].LineHeight
,
1899 if (ColumnInfoArray
!= NULL
) {
1900 if (GlyphBuf
[Index1
] == NULL
) {
1901 *ColumnInfoArray
= 0;
1903 *ColumnInfoArray
= Cell
[Index1
-1].AdvanceX
;
1909 // Recalculate the start point of X/Y axis to draw multi-lines with the order of top-to-down
1911 if (RowIndex
!= 0) {
1913 BltY
+= RowInfo
[RowIndex
].LineHeight
;
1916 Status
= Image
->Image
.Screen
->Blt (
1917 Image
->Image
.Screen
,
1919 EfiBltBufferToVideo
,
1924 RowInfo
[RowIndex
].LineWidth
,
1925 RowInfo
[RowIndex
].LineHeight
,
1928 if (EFI_ERROR (Status
)) {
1929 FreePool (BltBuffer
);
1933 FreePool (BltBuffer
);
1936 for (Index1
= RowInfo
[RowIndex
].StartIndex
; Index1
<= RowInfo
[RowIndex
].EndIndex
; Index1
++) {
1937 if (GlyphBuf
[Index1
] != NULL
) {
1939 // Only BLT these character which have corrsponding glyph in font basebase.
1953 if (ColumnInfoArray
!= NULL
) {
1954 if (GlyphBuf
[Index1
] == NULL
) {
1955 *ColumnInfoArray
= 0;
1957 *ColumnInfoArray
= Cell
[Index1
-1].AdvanceX
;
1965 BufferPtr
+= BltX
+ Image
->Width
* (LineHeight
- 1);
1971 if (Flags
& EFI_HII_IGNORE_LINE_BREAK
) {
1973 // If setting IGNORE_LINE_BREAK attribute, only render one line to image
1980 // Write output parameters.
1982 RowInfoSize
= RowIndex
* sizeof (EFI_HII_ROW_INFO
);
1983 if (RowInfoArray
!= NULL
) {
1984 *RowInfoArray
= AllocateZeroPool (RowInfoSize
);
1985 if (*RowInfoArray
== NULL
) {
1986 Status
= EFI_OUT_OF_RESOURCES
;
1989 CopyMem (*RowInfoArray
, RowInfo
, RowInfoSize
);
1991 if (RowInfoArraySize
!= NULL
) {
1992 *RowInfoArraySize
= RowIndex
;
1995 Status
= EFI_SUCCESS
;
1999 for (Index
= 0; Index
< StrLength
; Index
++) {
2000 if (GlyphBuf
[Index
] != NULL
) {
2001 FreePool (GlyphBuf
[Index
]);
2004 if (StringIn
!= NULL
) {
2005 FreePool (StringIn
);
2007 if (StringIn2
!= NULL
) {
2008 FreePool (StringIn2
);
2010 if (StringInfoOut
!= NULL
) {
2011 FreePool (StringInfoOut
);
2013 if (RowInfo
!= NULL
) {
2016 if (SystemDefault
!= NULL
) {
2017 FreePool (SystemDefault
);
2019 if (GlyphBuf
!= NULL
) {
2020 FreePool (GlyphBuf
);
2025 if (Attributes
!= NULL
) {
2026 FreePool (Attributes
);
2034 Render a string to a bitmap or the screen containing the contents of the specified string.
2036 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2037 @param Flags Describes how the string is to be drawn.
2038 @param PackageList The package list in the HII database to search
2039 for the specified string.
2040 @param StringId The string's id, which is unique within
2042 @param Language Points to the language for the retrieved string.
2043 If NULL, then the current system language is
2045 @param StringInfo Points to the string output information,
2046 including the color and font. If NULL, then the
2047 string will be output in the default system font
2049 @param Blt If this points to a non-NULL on entry, this
2050 points to the image, which is Width pixels wide
2051 and Height pixels high. The string will be drawn
2053 EFI_HII_OUT_FLAG_CLIP is implied. If this points
2054 to a NULL on entry, then a buffer
2055 will be allocated to hold the generated image and
2056 the pointer updated on exit. It is the caller's
2057 responsibility to free this buffer.
2058 @param BltX Specifies the offset from the left and top edge
2059 of the image of the first character cell in the
2061 @param BltY Specifies the offset from the left and top edge
2062 of the image of the first character cell in the
2064 @param RowInfoArray If this is non-NULL on entry, then on exit, this
2065 will point to an allocated buffer containing
2066 row information and RowInfoArraySize will be
2067 updated to contain the number of elements.
2068 This array describes the characters which were at
2069 least partially drawn and the heights of the
2070 rows. It is the caller's responsibility to free
2072 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
2073 contains the number of elements in RowInfoArray.
2074 @param ColumnInfoArray If this is non-NULL, then on return it will be
2075 filled with the horizontal offset for each
2076 character in the string on the row where it is
2077 displayed. Non-printing characters will have
2078 the offset ~0. The caller is responsible to
2079 allocate a buffer large enough so that there
2080 is one entry for each character in the string,
2081 not including the null-terminator. It is possible
2082 when character display is normalized that some
2083 character cells overlap.
2085 @retval EFI_SUCCESS The string was successfully rendered.
2086 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
2087 RowInfoArray or Blt.
2088 @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL.
2089 @retval EFI_INVALID_PARAMETER Flags were invalid combination.
2090 @retval EFI_NOT_FOUND The specified PackageList is not in the Database or the stringid is not
2091 in the specified PackageList.
2096 HiiStringIdToImage (
2097 IN CONST EFI_HII_FONT_PROTOCOL
*This
,
2098 IN EFI_HII_OUT_FLAGS Flags
,
2099 IN EFI_HII_HANDLE PackageList
,
2100 IN EFI_STRING_ID StringId
,
2101 IN CONST CHAR8
* Language
,
2102 IN CONST EFI_FONT_DISPLAY_INFO
*StringInfo OPTIONAL
,
2103 IN OUT EFI_IMAGE_OUTPUT
**Blt
,
2106 OUT EFI_HII_ROW_INFO
**RowInfoArray OPTIONAL
,
2107 OUT UINTN
*RowInfoArraySize OPTIONAL
,
2108 OUT UINTN
*ColumnInfoArray OPTIONAL
2112 HII_DATABASE_PRIVATE_DATA
*Private
;
2113 EFI_HII_STRING_PROTOCOL
*HiiString
;
2117 EFI_FONT_INFO
*StringFontInfo
;
2118 EFI_FONT_DISPLAY_INFO
*NewStringInfo
;
2119 CHAR8 TempSupportedLanguages
;
2120 CHAR8
*SupportedLanguages
;
2121 UINTN SupportedLanguagesSize
;
2122 CHAR8
*CurrentLanguage
;
2123 CHAR8
*BestLanguage
;
2125 if (This
== NULL
|| PackageList
== NULL
|| Blt
== NULL
|| PackageList
== NULL
) {
2126 return EFI_INVALID_PARAMETER
;
2129 if (!IsHiiHandleValid (PackageList
)) {
2130 return EFI_NOT_FOUND
;
2134 // Initialize string pointers to be NULL
2136 SupportedLanguages
= NULL
;
2137 CurrentLanguage
= NULL
;
2138 BestLanguage
= NULL
;
2141 StringFontInfo
= NULL
;
2142 NewStringInfo
= NULL
;
2145 // Get the string to be displayed.
2147 Private
= HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2148 HiiString
= &Private
->HiiString
;
2151 // Get the size of supported language.
2153 SupportedLanguagesSize
= 0;
2154 Status
= HiiString
->GetLanguages (
2157 &TempSupportedLanguages
,
2158 &SupportedLanguagesSize
2160 if (Status
!= EFI_BUFFER_TOO_SMALL
) {
2164 SupportedLanguages
= AllocatePool (SupportedLanguagesSize
);
2165 if (SupportedLanguages
== NULL
) {
2166 return EFI_OUT_OF_RESOURCES
;
2169 Status
= HiiString
->GetLanguages (
2173 &SupportedLanguagesSize
2175 if (EFI_ERROR (Status
)) {
2179 if (Language
== NULL
) {
2182 CurrentLanguage
= GetEfiGlobalVariable (L
"PlatformLang");
2183 BestLanguage
= GetBestLanguage (
2187 (CurrentLanguage
== NULL
) ? CurrentLanguage
: "",
2188 (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
),
2191 if (BestLanguage
== NULL
) {
2192 Status
= EFI_NOT_FOUND
;
2196 StringSize
= MAX_STRING_LENGTH
;
2197 String
= (EFI_STRING
) AllocateZeroPool (StringSize
);
2198 if (String
== NULL
) {
2199 Status
= EFI_OUT_OF_RESOURCES
;
2203 Status
= HiiString
->GetString (
2212 if (Status
== EFI_BUFFER_TOO_SMALL
) {
2214 String
= (EFI_STRING
) AllocateZeroPool (StringSize
);
2215 if (String
== NULL
) {
2216 Status
= EFI_OUT_OF_RESOURCES
;
2219 Status
= HiiString
->GetString (
2230 if (EFI_ERROR (Status
)) {
2235 // When StringInfo specifies that string will be output in the system default font and color,
2236 // use particular stringfontinfo described in string package instead if exists.
2237 // StringFontInfo equals NULL means system default font attaches with the string block.
2239 if (StringFontInfo
!= NULL
&& IsSystemFontInfo (Private
, (EFI_FONT_DISPLAY_INFO
*) StringInfo
, NULL
, NULL
)) {
2240 FontLen
= sizeof (EFI_FONT_DISPLAY_INFO
) - sizeof (CHAR16
) + StrSize (StringFontInfo
->FontName
);
2241 NewStringInfo
= AllocateZeroPool (FontLen
);
2242 if (NewStringInfo
== NULL
) {
2243 Status
= EFI_OUT_OF_RESOURCES
;
2246 NewStringInfo
->FontInfoMask
= EFI_FONT_INFO_SYS_FORE_COLOR
| EFI_FONT_INFO_SYS_BACK_COLOR
;
2247 NewStringInfo
->FontInfo
.FontStyle
= StringFontInfo
->FontStyle
;
2248 NewStringInfo
->FontInfo
.FontSize
= StringFontInfo
->FontSize
;
2249 StrCpy (NewStringInfo
->FontInfo
.FontName
, StringFontInfo
->FontName
);
2251 Status
= HiiStringToImage (
2266 Status
= HiiStringToImage (
2280 if (SupportedLanguages
!= NULL
) {
2281 FreePool (SupportedLanguages
);
2283 if (CurrentLanguage
!= NULL
) {
2284 FreePool (CurrentLanguage
);
2286 if (BestLanguage
!= NULL
) {
2287 FreePool (BestLanguage
);
2289 if (String
!= NULL
) {
2292 if (StringFontInfo
!= NULL
) {
2293 FreePool (StringFontInfo
);
2295 if (NewStringInfo
!= NULL
) {
2296 FreePool (NewStringInfo
);
2304 Convert the glyph for a single character into a bitmap.
2306 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2307 @param Char Character to retrieve.
2308 @param StringInfo Points to the string font and color information
2309 or NULL if the string should use the default
2310 system font and color.
2311 @param Blt Thus must point to a NULL on entry. A buffer will
2312 be allocated to hold the output and the pointer
2313 updated on exit. It is the caller's
2314 responsibility to free this buffer.
2315 @param Baseline Number of pixels from the bottom of the bitmap to
2318 @retval EFI_SUCCESS Glyph bitmap created.
2319 @retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer Blt.
2320 @retval EFI_WARN_UNKNOWN_GLYPH The glyph was unknown and was replaced with the
2321 glyph for Unicode character 0xFFFD.
2322 @retval EFI_INVALID_PARAMETER Blt is NULL or *Blt is not NULL.
2328 IN CONST EFI_HII_FONT_PROTOCOL
*This
,
2330 IN CONST EFI_FONT_DISPLAY_INFO
*StringInfo
,
2331 OUT EFI_IMAGE_OUTPUT
**Blt
,
2332 OUT UINTN
*Baseline OPTIONAL
2336 HII_DATABASE_PRIVATE_DATA
*Private
;
2337 EFI_IMAGE_OUTPUT
*Image
;
2339 EFI_FONT_DISPLAY_INFO
*SystemDefault
;
2340 EFI_FONT_DISPLAY_INFO
*StringInfoOut
;
2342 EFI_FONT_HANDLE FontHandle
;
2344 EFI_HII_GLYPH_INFO Cell
;
2345 EFI_FONT_INFO
*FontInfo
;
2347 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
;
2348 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
;
2349 EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
;
2351 if (This
== NULL
|| Blt
== NULL
|| *Blt
!= NULL
) {
2352 return EFI_INVALID_PARAMETER
;
2355 Private
= HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2359 SystemDefault
= NULL
;
2363 StringInfoOut
= NULL
;
2366 ZeroMem (&Foreground
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
2367 ZeroMem (&Background
, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
2369 Default
= IsSystemFontInfo (Private
, (EFI_FONT_DISPLAY_INFO
*) StringInfo
, &SystemDefault
, NULL
);
2373 // Find out a EFI_FONT_DISPLAY_INFO which could display the character in
2374 // the specified color and font.
2376 String
= (EFI_STRING
) AllocateZeroPool (sizeof (CHAR16
) * 2);
2377 if (String
== NULL
) {
2378 Status
= EFI_OUT_OF_RESOURCES
;
2384 Status
= HiiGetFontInfo (This
, &FontHandle
, StringInfo
, &StringInfoOut
, String
);
2385 if (EFI_ERROR (Status
)) {
2388 FontInfo
= &StringInfoOut
->FontInfo
;
2389 Foreground
= StringInfoOut
->ForegroundColor
;
2390 Background
= StringInfoOut
->BackgroundColor
;
2392 Foreground
= SystemDefault
->ForegroundColor
;
2393 Background
= SystemDefault
->BackgroundColor
;
2396 Status
= GetGlyphBuffer (Private
, Char
, FontInfo
, &GlyphBuffer
, &Cell
, &Attributes
);
2397 if (EFI_ERROR (Status
)) {
2401 Image
= (EFI_IMAGE_OUTPUT
*) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT
));
2402 if (Image
== NULL
) {
2403 Status
= EFI_OUT_OF_RESOURCES
;
2406 Image
->Width
= Cell
.Width
;
2407 Image
->Height
= Cell
.Height
;
2409 Image
->Image
.Bitmap
= AllocateZeroPool (Image
->Width
* Image
->Height
* sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL
));
2410 if (Image
->Image
.Bitmap
== NULL
) {
2412 Status
= EFI_OUT_OF_RESOURCES
;
2416 BltBuffer
= Image
->Image
.Bitmap
;
2430 if (Baseline
!= NULL
) {
2431 *Baseline
= Cell
.OffsetY
;
2434 Status
= EFI_SUCCESS
;
2438 if (Status
== EFI_NOT_FOUND
) {
2440 // Glyph is unknown and replaced with the glyph for unicode character 0xFFFD
2442 if (Char
!= REPLACE_UNKNOWN_GLYPH
) {
2443 Status
= HiiGetGlyph (This
, REPLACE_UNKNOWN_GLYPH
, StringInfo
, Blt
, Baseline
);
2444 if (!EFI_ERROR (Status
)) {
2445 Status
= EFI_WARN_UNKNOWN_GLYPH
;
2448 Status
= EFI_WARN_UNKNOWN_GLYPH
;
2452 if (SystemDefault
!= NULL
) {
2453 FreePool (SystemDefault
);
2455 if (StringInfoOut
!= NULL
) {
2456 FreePool (StringInfoOut
);
2458 if (String
!= NULL
) {
2461 if (GlyphBuffer
!= NULL
) {
2462 FreePool (GlyphBuffer
);
2470 This function iterates through fonts which match the specified font, using
2471 the specified criteria. If String is non-NULL, then all of the characters in
2472 the string must exist in order for a candidate font to be returned.
2474 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2475 @param FontHandle On entry, points to the font handle returned by a
2476 previous call to GetFontInfo() or NULL to start
2477 with the first font. On return, points to the
2478 returned font handle or points to NULL if there
2479 are no more matching fonts.
2480 @param StringInfoIn Upon entry, points to the font to return
2482 If NULL, then the information about the system default
2483 font will be returned.
2484 @param StringInfoOut Upon return, contains the matching font's
2485 information. If NULL, then no information is
2486 returned. It's caller's responsibility to free
2488 @param String Points to the string which will be tested to
2489 determine if all characters are available. If
2490 NULL, then any font is acceptable.
2492 @retval EFI_SUCCESS Matching font returned successfully.
2493 @retval EFI_NOT_FOUND No matching font was found.
2494 @retval EFI_INVALID_PARAMETER StringInfoIn->FontInfoMask is an invalid combination.
2495 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
2502 IN CONST EFI_HII_FONT_PROTOCOL
*This
,
2503 IN OUT EFI_FONT_HANDLE
*FontHandle
,
2504 IN CONST EFI_FONT_DISPLAY_INFO
*StringInfoIn
, OPTIONAL
2505 OUT EFI_FONT_DISPLAY_INFO
**StringInfoOut
,
2506 IN CONST EFI_STRING String OPTIONAL
2509 HII_DATABASE_PRIVATE_DATA
*Private
;
2511 EFI_FONT_DISPLAY_INFO
*SystemDefault
;
2512 EFI_FONT_DISPLAY_INFO InfoOut
;
2513 UINTN StringInfoOutLen
;
2514 EFI_FONT_INFO
*FontInfo
;
2515 HII_GLOBAL_FONT_INFO
*GlobalFont
;
2516 EFI_STRING StringIn
;
2517 EFI_FONT_HANDLE LocalFontHandle
;
2520 return EFI_INVALID_PARAMETER
;
2524 SystemDefault
= NULL
;
2525 LocalFontHandle
= NULL
;
2526 if (FontHandle
!= NULL
) {
2527 LocalFontHandle
= *FontHandle
;
2530 Private
= HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This
);
2533 // Already searched to the end of the whole list, return directly.
2535 if (LocalFontHandle
== &Private
->FontInfoList
) {
2536 LocalFontHandle
= NULL
;
2537 Status
= EFI_NOT_FOUND
;
2542 // Get default system display info, if StringInfoIn points to
2543 // system display info, return it directly.
2545 if (IsSystemFontInfo (Private
, (EFI_FONT_DISPLAY_INFO
*) StringInfoIn
, &SystemDefault
, &StringInfoOutLen
)) {
2547 // System font is the first node. When handle is not NULL, system font can not
2548 // be found any more.
2550 if (LocalFontHandle
== NULL
) {
2551 if (StringInfoOut
!= NULL
) {
2552 *StringInfoOut
= AllocateCopyPool (StringInfoOutLen
, SystemDefault
);
2553 if (*StringInfoOut
== NULL
) {
2554 Status
= EFI_OUT_OF_RESOURCES
;
2555 LocalFontHandle
= NULL
;
2560 LocalFontHandle
= Private
->FontInfoList
.ForwardLink
;
2561 Status
= EFI_SUCCESS
;
2564 LocalFontHandle
= NULL
;
2565 Status
= EFI_NOT_FOUND
;
2571 // StringInfoIn must not be NULL if it is not system default font info.
2573 ASSERT (StringInfoIn
!= NULL
);
2575 // Check the font information mask to make sure it is valid.
2577 if (((StringInfoIn
->FontInfoMask
& (EFI_FONT_INFO_SYS_FONT
| EFI_FONT_INFO_ANY_FONT
)) ==
2578 (EFI_FONT_INFO_SYS_FONT
| EFI_FONT_INFO_ANY_FONT
)) ||
2579 ((StringInfoIn
->FontInfoMask
& (EFI_FONT_INFO_SYS_SIZE
| EFI_FONT_INFO_ANY_SIZE
)) ==
2580 (EFI_FONT_INFO_SYS_SIZE
| EFI_FONT_INFO_ANY_SIZE
)) ||
2581 ((StringInfoIn
->FontInfoMask
& (EFI_FONT_INFO_SYS_STYLE
| EFI_FONT_INFO_ANY_STYLE
)) ==
2582 (EFI_FONT_INFO_SYS_STYLE
| EFI_FONT_INFO_ANY_STYLE
)) ||
2583 ((StringInfoIn
->FontInfoMask
& (EFI_FONT_INFO_RESIZE
| EFI_FONT_INFO_ANY_SIZE
)) ==
2584 (EFI_FONT_INFO_RESIZE
| EFI_FONT_INFO_ANY_SIZE
)) ||
2585 ((StringInfoIn
->FontInfoMask
& (EFI_FONT_INFO_RESTYLE
| EFI_FONT_INFO_ANY_STYLE
)) ==
2586 (EFI_FONT_INFO_RESTYLE
| EFI_FONT_INFO_ANY_STYLE
))) {
2587 return EFI_INVALID_PARAMETER
;
2591 // Parse the font information mask to find a matching font.
2594 CopyMem (&InfoOut
, (EFI_FONT_DISPLAY_INFO
*) StringInfoIn
, sizeof (EFI_FONT_DISPLAY_INFO
));
2596 if ((StringInfoIn
->FontInfoMask
& EFI_FONT_INFO_SYS_FONT
) == EFI_FONT_INFO_SYS_FONT
) {
2597 Status
= SaveFontName (SystemDefault
->FontInfo
.FontName
, &FontInfo
);
2599 Status
= SaveFontName (((EFI_FONT_DISPLAY_INFO
*) StringInfoIn
)->FontInfo
.FontName
, &FontInfo
);
2601 if (EFI_ERROR (Status
)) {
2605 if ((StringInfoIn
->FontInfoMask
& EFI_FONT_INFO_SYS_SIZE
) == EFI_FONT_INFO_SYS_SIZE
) {
2606 InfoOut
.FontInfo
.FontSize
= SystemDefault
->FontInfo
.FontSize
;
2608 if ((StringInfoIn
->FontInfoMask
& EFI_FONT_INFO_SYS_STYLE
) == EFI_FONT_INFO_SYS_STYLE
) {
2609 InfoOut
.FontInfo
.FontStyle
= SystemDefault
->FontInfo
.FontStyle
;
2611 if ((StringInfoIn
->FontInfoMask
& EFI_FONT_INFO_SYS_FORE_COLOR
) == EFI_FONT_INFO_SYS_FORE_COLOR
) {
2612 InfoOut
.ForegroundColor
= SystemDefault
->ForegroundColor
;
2614 if ((StringInfoIn
->FontInfoMask
& EFI_FONT_INFO_SYS_BACK_COLOR
) == EFI_FONT_INFO_SYS_BACK_COLOR
) {
2615 InfoOut
.BackgroundColor
= SystemDefault
->BackgroundColor
;
2619 FontInfo
->FontSize
= InfoOut
.FontInfo
.FontSize
;
2620 FontInfo
->FontStyle
= InfoOut
.FontInfo
.FontStyle
;
2622 if (IsFontInfoExisted (Private
, FontInfo
, &InfoOut
.FontInfoMask
, LocalFontHandle
, &GlobalFont
)) {
2624 // Test to guarantee all characters are available in the found font.
2626 if (String
!= NULL
) {
2628 while (*StringIn
!= 0) {
2629 Status
= FindGlyphBlock (GlobalFont
->FontPackage
, *StringIn
, NULL
, NULL
, NULL
);
2630 if (EFI_ERROR (Status
)) {
2631 LocalFontHandle
= NULL
;
2638 // Write to output parameter
2640 if (StringInfoOut
!= NULL
) {
2641 StringInfoOutLen
= sizeof (EFI_FONT_DISPLAY_INFO
) - sizeof (EFI_FONT_INFO
) + GlobalFont
->FontInfoSize
;
2642 *StringInfoOut
= (EFI_FONT_DISPLAY_INFO
*) AllocateZeroPool (StringInfoOutLen
);
2643 if (*StringInfoOut
== NULL
) {
2644 Status
= EFI_OUT_OF_RESOURCES
;
2645 LocalFontHandle
= NULL
;
2649 CopyMem (*StringInfoOut
, &InfoOut
, sizeof (EFI_FONT_DISPLAY_INFO
));
2650 CopyMem (&(*StringInfoOut
)->FontInfo
, GlobalFont
->FontInfo
, GlobalFont
->FontInfoSize
);
2653 LocalFontHandle
= GlobalFont
->Entry
.ForwardLink
;
2654 Status
= EFI_SUCCESS
;
2658 Status
= EFI_NOT_FOUND
;
2662 if (FontHandle
!= NULL
) {
2663 *FontHandle
= LocalFontHandle
;
2666 if (SystemDefault
!= NULL
) {
2667 FreePool (SystemDefault
);
2669 if (FontInfo
!= NULL
) {
2670 FreePool (FontInfo
);