]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
Update the copyright notice format
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Font.c
1 /** @file
2 Implementation for EFI_HII_FONT_PROTOCOL.
3
4
5 Copyright (c) 2007 - 2010, Intel Corporation. All rights reserved.<BR>
6 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
10
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.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mHiiEfiColors[16] = {
20 //
21 // B G R
22 //
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
39 };
40
41
42 /**
43 Insert a character cell information to the list specified by GlyphInfoList.
44
45 This is a internal function.
46
47 @param CharValue Unicode character value, which identifies a glyph
48 block.
49 @param GlyphInfoList HII_GLYPH_INFO list head.
50 @param Cell Incoming character cell information.
51
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
54 task.
55
56 **/
57 EFI_STATUS
58 NewCell (
59 IN CHAR16 CharValue,
60 IN LIST_ENTRY *GlyphInfoList,
61 IN EFI_HII_GLYPH_INFO *Cell
62 )
63 {
64 HII_GLYPH_INFO *GlyphInfo;
65
66 ASSERT (Cell != NULL && GlyphInfoList != NULL);
67
68 GlyphInfo = (HII_GLYPH_INFO *) AllocateZeroPool (sizeof (HII_GLYPH_INFO));
69 if (GlyphInfo == NULL) {
70 return EFI_OUT_OF_RESOURCES;
71 }
72
73 //
74 // GlyphInfoList stores a list of default character cell information, each is
75 // identified by "CharId".
76 //
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);
81
82 return EFI_SUCCESS;
83 }
84
85
86 /**
87 Get a character cell information from the list specified by GlyphInfoList.
88
89 This is a internal function.
90
91 @param CharValue Unicode character value, which identifies a glyph
92 block.
93 @param GlyphInfoList HII_GLYPH_INFO list head.
94 @param Cell Buffer which stores output character cell
95 information.
96
97 @retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
98 @retval EFI_NOT_FOUND The character info specified by CharValue does
99 not exist.
100
101 **/
102 EFI_STATUS
103 GetCell (
104 IN CHAR16 CharValue,
105 IN LIST_ENTRY *GlyphInfoList,
106 OUT EFI_HII_GLYPH_INFO *Cell
107 )
108 {
109 HII_GLYPH_INFO *GlyphInfo;
110 LIST_ENTRY *Link;
111
112 ASSERT (Cell != NULL && GlyphInfoList != NULL);
113
114 //
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.
119 //
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.
123 //
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));
128 return EFI_SUCCESS;
129 }
130 }
131
132 return EFI_NOT_FOUND;
133 }
134
135
136 /**
137 Convert the glyph for a single character into a bitmap.
138
139 This is a internal function.
140
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.
149
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.
154
155 **/
156 EFI_STATUS
157 GetGlyphBuffer (
158 IN HII_DATABASE_PRIVATE_DATA *Private,
159 IN CHAR16 Char,
160 IN EFI_FONT_INFO *StringInfo,
161 OUT UINT8 **GlyphBuffer,
162 OUT EFI_HII_GLYPH_INFO *Cell,
163 OUT UINT8 *Attributes OPTIONAL
164 )
165 {
166 HII_DATABASE_RECORD *Node;
167 LIST_ENTRY *Link;
168 HII_SIMPLE_FONT_PACKAGE_INSTANCE *SimpleFont;
169 LIST_ENTRY *Link1;
170 UINT16 Index;
171 EFI_NARROW_GLYPH Narrow;
172 EFI_WIDE_GLYPH Wide;
173 HII_GLOBAL_FONT_INFO *GlobalFont;
174 UINTN HeaderSize;
175 EFI_NARROW_GLYPH *NarrowPtr;
176 EFI_WIDE_GLYPH *WidePtr;
177
178 if (GlyphBuffer == NULL || Cell == NULL) {
179 return EFI_INVALID_PARAMETER;
180 }
181 if (Private == NULL || Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE) {
182 return EFI_INVALID_PARAMETER;
183 }
184
185 ZeroMem (Cell, sizeof (EFI_HII_GLYPH_INFO));
186
187 //
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).
192 //
193 if (StringInfo != NULL) {
194 if(!IsFontInfoExisted (Private, StringInfo, NULL, NULL, &GlobalFont)) {
195 return EFI_INVALID_PARAMETER;
196 }
197 if (Attributes != NULL) {
198 *Attributes = PROPORTIONAL_GLYPH;
199 }
200 return FindGlyphBlock (GlobalFont->FontPackage, Char, GlyphBuffer, Cell, NULL);
201 } else {
202 HeaderSize = sizeof (EFI_HII_SIMPLE_FONT_PACKAGE_HDR);
203
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
209 ) {
210 SimpleFont = CR (Link1, HII_SIMPLE_FONT_PACKAGE_INSTANCE, SimpleFontEntry, HII_S_FONT_PACKAGE_SIGNATURE);
211 //
212 // Search the narrow glyph array
213 //
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;
221 }
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);
229 }
230 return EFI_SUCCESS;
231 }
232 }
233 //
234 // Search the wide glyph array
235 //
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;
243 }
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);
252 }
253 return EFI_SUCCESS;
254 }
255 }
256 }
257 }
258 }
259
260 return EFI_NOT_FOUND;
261 }
262
263 /**
264 Convert bitmap data of the glyph to blt structure.
265
266 This is a internal function.
267
268 @param GlyphBuffer Buffer points to bitmap data of glyph.
269 @param Foreground The color of the "on" pixels in the glyph in the
270 bitmap.
271 @param Background The color of the "off" pixels in the glyph in the
272 bitmap.
273 @param ImageWidth Width of the character or character cell, in
274 pixels.
275 @param ImageHeight Height of the character or character cell, in
276 pixels.
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
282 next glyph's origin.
283
284 **/
285 VOID
286 NarrowGlyphToBlt (
287 IN UINT8 *GlyphBuffer,
288 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
289 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
290 IN UINTN ImageWidth,
291 IN UINTN ImageHeight,
292 IN BOOLEAN Transparent,
293 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin
294 )
295 {
296 UINT8 Xpos;
297 UINT8 Ypos;
298 UINT8 Height;
299 UINT8 Width;
300 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer;
301
302 ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL);
303
304 Height = EFI_GLYPH_HEIGHT;
305 Width = EFI_GLYPH_WIDTH;
306
307 ASSERT (Width <= ImageWidth && Height <= ImageHeight);
308
309 Buffer = *Origin;
310
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;
315 } else {
316 if (!Transparent) {
317 Buffer[Ypos * ImageWidth + (Width - Xpos - 1)] = Background;
318 }
319 }
320 }
321 }
322
323 *Origin = Buffer + Width;
324 }
325
326
327 /**
328 Convert bitmap data of the glyph to blt structure.
329
330 This is a internal function.
331
332 @param GlyphBuffer Buffer points to bitmap data of glyph.
333 @param Foreground The color of the "on" pixels in the glyph in the
334 bitmap.
335 @param Background The color of the "off" pixels in the glyph in the
336 bitmap.
337 @param ImageWidth Width of the character or character cell, in
338 pixels.
339 @param ImageHeight Height of the character or character cell, in
340 pixels.
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
348 next glyph's origin.
349
350
351 **/
352 VOID
353 GlyphToBlt (
354 IN UINT8 *GlyphBuffer,
355 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
356 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
357 IN UINTN ImageWidth,
358 IN UINTN ImageHeight,
359 IN BOOLEAN Transparent,
360 IN CONST EFI_HII_GLYPH_INFO *Cell,
361 IN UINT8 Attributes,
362 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin
363 )
364 {
365 UINT8 Xpos;
366 UINT8 Ypos;
367 UINT8 Data;
368 UINT8 Index;
369 UINTN OffsetY;
370 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
371
372 ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL);
373 ASSERT (Cell->Width <= ImageWidth && Cell->Height <= ImageHeight);
374
375 BltBuffer = *Origin;
376
377 //
378 // Since non-spacing key will be printed OR'd with the previous glyph, don't
379 // write 0.
380 //
381 if ((Attributes & EFI_GLYPH_NON_SPACING) == EFI_GLYPH_NON_SPACING) {
382 Transparent = TRUE;
383 }
384
385 //
386 // The glyph's upper left hand corner pixel is the most significant bit of the
387 // first bitmap byte.
388 //
389 for (Ypos = 0; Ypos < Cell->Height; Ypos++) {
390 OffsetY = BITMAP_LEN_1_BIT (Cell->Width, Ypos);
391
392 //
393 // All bits in these bytes are meaningful.
394 //
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;
400 } else {
401 if (!Transparent) {
402 BltBuffer[Ypos * ImageWidth + Xpos * 8 + (8 - Index - 1)] = Background;
403 }
404 }
405 }
406 }
407
408 if (Cell->Width % 8 != 0) {
409 //
410 // There are some padding bits in this byte. Ignore them.
411 //
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;
416 } else {
417 if (!Transparent) {
418 BltBuffer[Ypos * ImageWidth + Xpos * 8 + Index] = Background;
419 }
420 }
421 }
422 } // end of if (Width % 8...)
423
424 } // end of for (Ypos=0...)
425
426 *Origin = BltBuffer + Cell->Width;
427 }
428
429
430 /**
431 Convert bitmap data of the glyph to blt structure.
432
433 This is a internal function.
434
435 @param GlyphBuffer Buffer points to bitmap data of glyph.
436 @param Foreground The color of the "on" pixels in the glyph in the
437 bitmap.
438 @param Background The color of the "off" pixels in the glyph in the
439 bitmap.
440 @param ImageWidth Width of the character or character cell, in
441 pixels.
442 @param ImageHeight Height of the character or character cell, in
443 pixels.
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
451 next glyph's origin.
452
453 @return Points to the address of next origin node in BltBuffer.
454
455 **/
456 VOID
457 GlyphToImage (
458 IN UINT8 *GlyphBuffer,
459 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
460 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
461 IN UINTN ImageWidth,
462 IN UINTN ImageHeight,
463 IN BOOLEAN Transparent,
464 IN CONST EFI_HII_GLYPH_INFO *Cell,
465 IN UINT8 Attributes,
466 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL **Origin
467 )
468 {
469 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *Buffer;
470
471 ASSERT (GlyphBuffer != NULL && Origin != NULL && *Origin != NULL);
472 ASSERT (Cell->Width <= ImageWidth && Cell->Height <= ImageHeight);
473
474 Buffer = *Origin;
475
476 if ((Attributes & EFI_GLYPH_NON_SPACING) == EFI_GLYPH_NON_SPACING) {
477 //
478 // This character is a non-spacing key, print it OR'd with the previous glyph.
479 // without advancing cursor.
480 //
481 Buffer -= Cell->Width;
482 GlyphToBlt (
483 GlyphBuffer,
484 Foreground,
485 Background,
486 ImageWidth,
487 ImageHeight,
488 Transparent,
489 Cell,
490 Attributes,
491 &Buffer
492 );
493
494 } else if ((Attributes & EFI_GLYPH_WIDE) == EFI_GLYPH_WIDE) {
495 //
496 // This character is wide glyph, i.e. 16 pixels * 19 pixels.
497 // Draw it as two narrow glyphs.
498 //
499 NarrowGlyphToBlt (
500 GlyphBuffer,
501 Foreground,
502 Background,
503 ImageWidth,
504 ImageHeight,
505 Transparent,
506 Origin
507 );
508
509 NarrowGlyphToBlt (
510 GlyphBuffer + EFI_GLYPH_HEIGHT,
511 Foreground,
512 Background,
513 ImageWidth,
514 ImageHeight,
515 Transparent,
516 Origin
517 );
518
519 } else if ((Attributes & NARROW_GLYPH) == NARROW_GLYPH) {
520 //
521 // This character is narrow glyph, i.e. 8 pixels * 19 pixels.
522 //
523 NarrowGlyphToBlt (
524 GlyphBuffer,
525 Foreground,
526 Background,
527 ImageWidth,
528 ImageHeight,
529 Transparent,
530 Origin
531 );
532
533 } else if ((Attributes & PROPORTIONAL_GLYPH) == PROPORTIONAL_GLYPH) {
534 //
535 // This character is proportional glyph, i.e. Cell->Width * Cell->Height pixels.
536 //
537 GlyphToBlt (
538 GlyphBuffer,
539 Foreground,
540 Background,
541 ImageWidth,
542 ImageHeight,
543 Transparent,
544 Cell,
545 Attributes,
546 Origin
547 );
548 }
549 }
550
551
552 /**
553 Write the output parameters of FindGlyphBlock().
554
555 This is a internal function.
556
557 @param BufferIn Buffer which stores the bitmap data of the found
558 block.
559 @param BufferLen Length of BufferIn.
560 @param InputCell Buffer which stores cell information of the
561 encoded bitmap.
562 @param GlyphBuffer Output the corresponding bitmap data of the found
563 block. It is the caller's responsiblity to free
564 this buffer.
565 @param Cell Output cell information of the encoded bitmap.
566 @param GlyphBufferLen If not NULL, output the length of GlyphBuffer.
567
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
571 task.
572
573 **/
574 EFI_STATUS
575 WriteOutputParam (
576 IN UINT8 *BufferIn,
577 IN UINTN BufferLen,
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
582 )
583 {
584 if (BufferIn == NULL || BufferLen < 1 || InputCell == NULL) {
585 return EFI_INVALID_PARAMETER;
586 }
587
588 if (Cell != NULL) {
589 CopyMem (Cell, InputCell, sizeof (EFI_HII_GLYPH_INFO));
590 }
591
592 if (GlyphBuffer != NULL) {
593 *GlyphBuffer = (UINT8 *) AllocateZeroPool (BufferLen);
594 if (*GlyphBuffer == NULL) {
595 return EFI_OUT_OF_RESOURCES;
596 }
597 CopyMem (*GlyphBuffer, BufferIn, BufferLen);
598 }
599
600 if (GlyphBufferLen != NULL) {
601 *GlyphBufferLen = BufferLen;
602 }
603
604 return EFI_SUCCESS;
605 }
606
607
608 /**
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.
612
613 @param FontPackage Hii string package instance.
614 @param CharValue Unicode character value, which identifies a glyph
615 block.
616 @param GlyphBuffer Output the corresponding bitmap data of the found
617 block. It is the caller's responsiblity to free
618 this buffer.
619 @param Cell Output cell information of the encoded bitmap.
620 @param GlyphBufferLen If not NULL, output the length of GlyphBuffer.
621
622 @retval EFI_SUCCESS The bitmap data is retrieved successfully.
623 @retval EFI_NOT_FOUND The specified CharValue does not exist in current
624 database.
625 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
626 task.
627
628 **/
629 EFI_STATUS
630 FindGlyphBlock (
631 IN HII_FONT_PACKAGE_INSTANCE *FontPackage,
632 IN CHAR16 CharValue,
633 OUT UINT8 **GlyphBuffer, OPTIONAL
634 OUT EFI_HII_GLYPH_INFO *Cell, OPTIONAL
635 OUT UINTN *GlyphBufferLen OPTIONAL
636 )
637 {
638 EFI_STATUS Status;
639 UINT8 *BlockPtr;
640 UINT16 CharCurrent;
641 UINT16 Length16;
642 UINT32 Length32;
643 EFI_HII_GIBT_GLYPHS_BLOCK Glyphs;
644 UINTN BufferLen;
645 UINT16 Index;
646 EFI_HII_GLYPH_INFO DefaultCell;
647 EFI_HII_GLYPH_INFO LocalCell;
648
649 ASSERT (FontPackage != NULL);
650 ASSERT (FontPackage->Signature == HII_FONT_PACKAGE_SIGNATURE);
651
652 if (CharValue == (CHAR16) (-1)) {
653 //
654 // Collect the cell information specified in font package fixed header.
655 // Use CharValue =0 to represent this particular cell.
656 //
657 Status = NewCell (
658 0,
659 &FontPackage->GlyphInfoList,
660 (EFI_HII_GLYPH_INFO *) ((UINT8 *) FontPackage->FontPkgHdr + 3 * sizeof (UINT32))
661 );
662 if (EFI_ERROR (Status)) {
663 return Status;
664 }
665 }
666
667 BlockPtr = FontPackage->GlyphBlock;
668 CharCurrent = 1;
669 BufferLen = 0;
670
671 while (*BlockPtr != EFI_HII_GIBT_END) {
672 switch (*BlockPtr) {
673 case EFI_HII_GIBT_DEFAULTS:
674 //
675 // Collect all default character cell information specified by
676 // EFI_HII_GIBT_DEFAULTS.
677 //
678 if (CharValue == (CHAR16) (-1)) {
679 Status = NewCell (
680 CharCurrent,
681 &FontPackage->GlyphInfoList,
682 (EFI_HII_GLYPH_INFO *) (BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK))
683 );
684 if (EFI_ERROR (Status)) {
685 return Status;
686 }
687 }
688 BlockPtr += sizeof (EFI_HII_GIBT_DEFAULTS_BLOCK);
689 break;
690
691 case EFI_HII_GIBT_DUPLICATE:
692 if (CharCurrent == CharValue) {
693 CopyMem (&CharValue, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (CHAR16));
694 CharCurrent = 1;
695 BlockPtr = FontPackage->GlyphBlock;
696 continue;
697 }
698 CharCurrent++;
699 BlockPtr += sizeof (EFI_HII_GIBT_DUPLICATE_BLOCK);
700 break;
701
702 case EFI_HII_GIBT_EXT1:
703 BlockPtr += *(BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8));
704 break;
705 case EFI_HII_GIBT_EXT2:
706 CopyMem (
707 &Length16,
708 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8),
709 sizeof (UINT16)
710 );
711 BlockPtr += Length16;
712 break;
713 case EFI_HII_GIBT_EXT4:
714 CopyMem (
715 &Length32,
716 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8),
717 sizeof (UINT32)
718 );
719 BlockPtr += Length32;
720 break;
721
722 case EFI_HII_GIBT_GLYPH:
723 CopyMem (
724 &LocalCell,
725 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
726 sizeof (EFI_HII_GLYPH_INFO)
727 );
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),
732 BufferLen,
733 &LocalCell,
734 GlyphBuffer,
735 Cell,
736 GlyphBufferLen
737 );
738 }
739 CharCurrent++;
740 BlockPtr += sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8) + BufferLen;
741 break;
742
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);
749
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 (
754 BlockPtr,
755 BufferLen,
756 &Glyphs.Cell,
757 GlyphBuffer,
758 Cell,
759 GlyphBufferLen
760 );
761 }
762 BlockPtr += BufferLen;
763 }
764 CharCurrent = (UINT16) (CharCurrent + Glyphs.Count);
765 break;
766
767 case EFI_HII_GIBT_GLYPH_DEFAULT:
768 Status = GetCell (CharCurrent, &FontPackage->GlyphInfoList, &DefaultCell);
769 if (EFI_ERROR (Status)) {
770 return Status;
771 }
772 BufferLen = BITMAP_LEN_1_BIT (DefaultCell.Width, DefaultCell.Height);
773
774 if (CharCurrent == CharValue) {
775 return WriteOutputParam (
776 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
777 BufferLen,
778 &DefaultCell,
779 GlyphBuffer,
780 Cell,
781 GlyphBufferLen
782 );
783 }
784 CharCurrent++;
785 BlockPtr += sizeof (EFI_HII_GLYPH_BLOCK) + BufferLen;
786 break;
787
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)) {
792 return Status;
793 }
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 (
799 BlockPtr,
800 BufferLen,
801 &DefaultCell,
802 GlyphBuffer,
803 Cell,
804 GlyphBufferLen
805 );
806 }
807 BlockPtr += BufferLen;
808 }
809 CharCurrent = (UINT16) (CharCurrent + Length16);
810 break;
811
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);
815 break;
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);
820 break;
821 default:
822 ASSERT (FALSE);
823 break;
824 }
825
826 if (CharValue < CharCurrent) {
827 return EFI_NOT_FOUND;
828 }
829 }
830
831 if (CharValue == (CHAR16) (-1)) {
832 return EFI_SUCCESS;
833 }
834
835 return EFI_NOT_FOUND;
836 }
837
838
839 /**
840 Copy a Font Name to a new created EFI_FONT_INFO structure.
841
842 This is a internal function.
843
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.
847
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
850 task.
851
852 **/
853 EFI_STATUS
854 SaveFontName (
855 IN EFI_STRING FontName,
856 OUT EFI_FONT_INFO **FontInfo
857 )
858 {
859 UINTN FontInfoLen;
860
861 ASSERT (FontName != NULL && FontInfo != NULL);
862
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;
867 }
868
869 StrCpy ((*FontInfo)->FontName, FontName);
870 return EFI_SUCCESS;
871 }
872
873
874 /**
875 Retrieve system default font and color.
876
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
880 this buffer.
881 @param FontInfoSize If not NULL, output the size of buffer FontInfo.
882
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
885 task.
886 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
887
888 **/
889 EFI_STATUS
890 GetSystemFont (
891 IN HII_DATABASE_PRIVATE_DATA *Private,
892 OUT EFI_FONT_DISPLAY_INFO **FontInfo,
893 OUT UINTN *FontInfoSize OPTIONAL
894 )
895 {
896 EFI_FONT_DISPLAY_INFO *Info;
897 UINTN InfoSize;
898
899 if (Private == NULL || Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE) {
900 return EFI_INVALID_PARAMETER;
901 }
902 if (FontInfo == NULL) {
903 return EFI_INVALID_PARAMETER;
904 }
905
906 //
907 // The standard font always has the name "sysdefault".
908 //
909 InfoSize = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + StrSize (L"sysdefault");
910 Info = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (InfoSize);
911 if (Info == NULL) {
912 return EFI_OUT_OF_RESOURCES;
913 }
914
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");
921
922 *FontInfo = Info;
923 if (FontInfoSize != NULL) {
924 *FontInfoSize = InfoSize;
925 }
926 return EFI_SUCCESS;
927 }
928
929
930 /**
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.
933
934 This is a internal function.
935
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.
940
941 @param SystemInfoLen If not NULL, output the length of default system
942 info.
943
944 @retval TRUE Yes, it points to system default.
945 @retval FALSE No.
946
947 **/
948 BOOLEAN
949 IsSystemFontInfo (
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
954 )
955 {
956 EFI_STATUS Status;
957 EFI_FONT_DISPLAY_INFO *SystemDefault;
958 UINTN DefaultLen;
959 BOOLEAN Flag;
960
961 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
962
963 if (StringInfo == NULL && SystemInfo == NULL) {
964 return TRUE;
965 }
966
967 Status = GetSystemFont (Private, &SystemDefault, &DefaultLen);
968 ASSERT_EFI_ERROR (Status);
969
970 //
971 // Record the system default info.
972 //
973 if (SystemInfo != NULL) {
974 *SystemInfo = SystemDefault;
975 }
976
977 if (SystemInfoLen != NULL) {
978 *SystemInfoLen = DefaultLen;
979 }
980
981 if (StringInfo == NULL) {
982 return TRUE;
983 }
984
985 Flag = FALSE;
986 //
987 // Check the FontInfoMask to see whether it is retrieving system info.
988 //
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) {
991 goto Exit;
992 }
993 }
994 if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == 0) {
995 if (StringInfo->FontInfo.FontSize != SystemDefault->FontInfo.FontSize) {
996 goto Exit;
997 }
998 }
999 if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == 0) {
1000 if (StringInfo->FontInfo.FontStyle != SystemDefault->FontInfo.FontStyle) {
1001 goto Exit;
1002 }
1003 }
1004 if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == 0) {
1005 if (CompareMem (
1006 &StringInfo->ForegroundColor,
1007 &SystemDefault->ForegroundColor,
1008 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1009 ) != 0) {
1010 goto Exit;
1011 }
1012 }
1013 if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == 0) {
1014 if (CompareMem (
1015 &StringInfo->BackgroundColor,
1016 &SystemDefault->BackgroundColor,
1017 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1018 ) != 0) {
1019 goto Exit;
1020 }
1021 }
1022
1023 Flag = TRUE;
1024
1025 Exit:
1026 if (SystemInfo == NULL) {
1027 if (SystemDefault != NULL) {
1028 FreePool (SystemDefault);
1029 }
1030 }
1031 return Flag;
1032 }
1033
1034
1035 /**
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.
1040
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
1046 this mask is valid.
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
1051 info.
1052
1053 @retval TRUE Existed
1054 @retval FALSE Not existed
1055
1056 **/
1057 BOOLEAN
1058 IsFontInfoExisted (
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
1064 )
1065 {
1066 HII_GLOBAL_FONT_INFO *GlobalFont;
1067 HII_GLOBAL_FONT_INFO *GlobalFontBackup1;
1068 HII_GLOBAL_FONT_INFO *GlobalFontBackup2;
1069 LIST_ENTRY *Link;
1070 EFI_FONT_INFO_MASK Mask;
1071 BOOLEAN Matched;
1072 BOOLEAN VagueMatched1;
1073 BOOLEAN VagueMatched2;
1074
1075 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
1076 ASSERT (FontInfo != NULL);
1077
1078 //
1079 // Matched flag represents an exactly match; VagueMatched1 repensents a RESIZE
1080 // or RESTYLE match; VagueMatched2 represents a RESIZE | RESTYLE match.
1081 //
1082 Matched = FALSE;
1083 VagueMatched1 = FALSE;
1084 VagueMatched2 = FALSE;
1085
1086 Mask = 0;
1087 GlobalFontBackup1 = NULL;
1088 GlobalFontBackup2 = NULL;
1089
1090 // The process of where the system default should be supplied instead of
1091 // the specified font info beyonds this function's scope.
1092 //
1093 if (FontInfoMask != NULL) {
1094 Mask = *FontInfoMask & (~SYS_FONT_INFO_MASK);
1095 }
1096
1097 //
1098 // If not NULL, FontHandle points to the next node of the last searched font
1099 // node by previous call.
1100 //
1101 if (FontHandle == NULL) {
1102 Link = Private->FontInfoList.ForwardLink;
1103 } else {
1104 Link = (LIST_ENTRY *) FontHandle;
1105 }
1106
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;
1113 }
1114 return TRUE;
1115 }
1116 } else {
1117 //
1118 // Check which options could be used to make a match.
1119 //
1120 switch (Mask) {
1121 case EFI_FONT_INFO_ANY_FONT:
1122 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle &&
1123 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1124 Matched = TRUE;
1125 }
1126 break;
1127 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE:
1128 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1129 Matched = TRUE;
1130 }
1131 break;
1132 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE:
1133 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1134 Matched = TRUE;
1135 }
1136 break;
1137 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_ANY_STYLE:
1138 Matched = TRUE;
1139 break;
1140 //
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.
1143 //
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) {
1147 Matched = TRUE;
1148 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1149 VagueMatched1 = TRUE;
1150 GlobalFontBackup1 = GlobalFont;
1151 }
1152 }
1153 break;
1154 //
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.
1157 //
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) {
1161 Matched = TRUE;
1162 } else {
1163 VagueMatched1 = TRUE;
1164 GlobalFontBackup1 = GlobalFont;
1165 }
1166 }
1167 break;
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) {
1171 Matched = TRUE;
1172 } else {
1173 VagueMatched1 = TRUE;
1174 GlobalFontBackup1 = GlobalFont;
1175 }
1176 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1177 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1178 VagueMatched1 = TRUE;
1179 GlobalFontBackup1 = GlobalFont;
1180 } else {
1181 VagueMatched2 = TRUE;
1182 GlobalFontBackup2 = GlobalFont;
1183 }
1184 }
1185 break;
1186 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
1187 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1188 Matched = TRUE;
1189 } else {
1190 VagueMatched1 = TRUE;
1191 GlobalFontBackup1 = GlobalFont;
1192 }
1193 break;
1194 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
1195 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1196 Matched = TRUE;
1197 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1198 VagueMatched1 = TRUE;
1199 GlobalFontBackup1 = GlobalFont;
1200 }
1201 break;
1202 case EFI_FONT_INFO_ANY_STYLE:
1203 if ((CompareMem (
1204 GlobalFont->FontInfo->FontName,
1205 FontInfo->FontName,
1206 StrSize (FontInfo->FontName)
1207 ) == 0) &&
1208 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1209 Matched = TRUE;
1210 }
1211 break;
1212 case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_ANY_SIZE:
1213 if (CompareMem (
1214 GlobalFont->FontInfo->FontName,
1215 FontInfo->FontName,
1216 StrSize (FontInfo->FontName)
1217 ) == 0) {
1218 Matched = TRUE;
1219 }
1220 break;
1221 case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
1222 if (CompareMem (
1223 GlobalFont->FontInfo->FontName,
1224 FontInfo->FontName,
1225 StrSize (FontInfo->FontName)
1226 ) == 0) {
1227 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1228 Matched = TRUE;
1229 } else {
1230 VagueMatched1 = TRUE;
1231 GlobalFontBackup1 = GlobalFont;
1232 }
1233 }
1234 break;
1235 case EFI_FONT_INFO_ANY_SIZE:
1236 if ((CompareMem (
1237 GlobalFont->FontInfo->FontName,
1238 FontInfo->FontName,
1239 StrSize (FontInfo->FontName)
1240 ) == 0) &&
1241 GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1242 Matched = TRUE;
1243 }
1244 break;
1245 case EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
1246 if (CompareMem (
1247 GlobalFont->FontInfo->FontName,
1248 FontInfo->FontName,
1249 StrSize (FontInfo->FontName)
1250 ) == 0) {
1251 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1252 Matched = TRUE;
1253 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1254 VagueMatched1 = TRUE;
1255 GlobalFontBackup1 = GlobalFont;
1256 }
1257 }
1258 break;
1259 case EFI_FONT_INFO_RESTYLE:
1260 if ((CompareMem (
1261 GlobalFont->FontInfo->FontName,
1262 FontInfo->FontName,
1263 StrSize (FontInfo->FontName)
1264 ) == 0) &&
1265 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1266
1267 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1268 Matched = TRUE;
1269 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1270 VagueMatched1 = TRUE;
1271 GlobalFontBackup1 = GlobalFont;
1272 }
1273 }
1274 break;
1275 case EFI_FONT_INFO_RESIZE:
1276 if ((CompareMem (
1277 GlobalFont->FontInfo->FontName,
1278 FontInfo->FontName,
1279 StrSize (FontInfo->FontName)
1280 ) == 0) &&
1281 GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1282
1283 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1284 Matched = TRUE;
1285 } else {
1286 VagueMatched1 = TRUE;
1287 GlobalFontBackup1 = GlobalFont;
1288 }
1289 }
1290 break;
1291 case EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_RESTYLE:
1292 if (CompareMem (
1293 GlobalFont->FontInfo->FontName,
1294 FontInfo->FontName,
1295 StrSize (FontInfo->FontName)
1296 ) == 0) {
1297 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1298 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1299 Matched = TRUE;
1300 } else {
1301 VagueMatched1 = TRUE;
1302 GlobalFontBackup1 = GlobalFont;
1303 }
1304 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1305 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1306 VagueMatched1 = TRUE;
1307 GlobalFontBackup1 = GlobalFont;
1308 } else {
1309 VagueMatched2 = TRUE;
1310 GlobalFontBackup2 = GlobalFont;
1311 }
1312 }
1313 }
1314 break;
1315 default:
1316 break;
1317 }
1318
1319 if (Matched) {
1320 if (GlobalFontInfo != NULL) {
1321 *GlobalFontInfo = GlobalFont;
1322 }
1323 return TRUE;
1324 }
1325 }
1326 }
1327
1328 if (VagueMatched1) {
1329 if (GlobalFontInfo != NULL) {
1330 *GlobalFontInfo = GlobalFontBackup1;
1331 }
1332 return TRUE;
1333 } else if (VagueMatched2) {
1334 if (GlobalFontInfo != NULL) {
1335 *GlobalFontInfo = GlobalFontBackup2;
1336 }
1337 return TRUE;
1338 }
1339
1340 return FALSE;
1341 }
1342
1343
1344 /**
1345 Check whether the unicode represents a line break or not.
1346
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.
1349
1350 @param Char Unicode character
1351
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.
1356
1357 **/
1358 INT8
1359 IsLineBreak (
1360 IN CHAR16 Char
1361 )
1362 {
1363 switch (Char) {
1364 //
1365 // Mandatory line break characters, which force a line-break
1366 //
1367 case 0x000C:
1368 case 0x000D:
1369 case 0x2028:
1370 case 0x2029:
1371 return 0;
1372 //
1373 // Space characters, which is taken as a line-break opportunity
1374 //
1375 case 0x0020:
1376 case 0x1680:
1377 case 0x2000:
1378 case 0x2001:
1379 case 0x2002:
1380 case 0x2003:
1381 case 0x2004:
1382 case 0x2005:
1383 case 0x2006:
1384 case 0x2008:
1385 case 0x2009:
1386 case 0x200A:
1387 case 0x205F:
1388 //
1389 // In-Word Break Opportunities
1390 //
1391 case 0x200B:
1392 return 1;
1393 //
1394 // A space which is not a line-break opportunity
1395 //
1396 case 0x00A0:
1397 case 0x202F:
1398 //
1399 // A hyphen which is not a line-break opportunity
1400 //
1401 case 0x2011:
1402 return -1;
1403 //
1404 // Hyphen characters which describe line break opportunities after the character
1405 //
1406 case 0x058A:
1407 case 0x2010:
1408 case 0x2012:
1409 case 0x2013:
1410 case 0x0F0B:
1411 case 0x1361:
1412 case 0x17D5:
1413 return 1;
1414 //
1415 // A hyphen which describes line break opportunities before and after them, but not between a pair of them
1416 //
1417 case 0x2014:
1418 return 2;
1419 }
1420 return -1;
1421 }
1422
1423
1424 /**
1425 Renders a string to a bitmap or to the display.
1426
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
1430 displayed.
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
1434 and color.
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
1438 onto this image and
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
1446 image.
1447 @param BltY Specifies the offset from the left and top edge
1448 of the image of the first character cell in the
1449 image.
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
1457 this buffer.
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.
1470
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..
1476
1477 **/
1478 EFI_STATUS
1479 EFIAPI
1480 HiiStringToImage (
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,
1486 IN UINTN BltX,
1487 IN UINTN BltY,
1488 OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
1489 OUT UINTN *RowInfoArraySize OPTIONAL,
1490 OUT UINTN *ColumnInfoArray OPTIONAL
1491 )
1492 {
1493 EFI_STATUS Status;
1494 HII_DATABASE_PRIVATE_DATA *Private;
1495 UINT8 **GlyphBuf;
1496 EFI_HII_GLYPH_INFO *Cell;
1497 UINT8 *Attributes;
1498 EFI_IMAGE_OUTPUT *Image;
1499 EFI_STRING StringPtr;
1500 EFI_STRING StringTmp;
1501 EFI_HII_ROW_INFO *RowInfo;
1502 UINTN LineWidth;
1503 UINTN LineHeight;
1504 UINTN BaseLineOffset;
1505 UINT16 MaxRowNum;
1506 UINT16 RowIndex;
1507 UINTN Index;
1508 UINTN Index1;
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;
1514 UINT16 Height;
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;
1522 UINTN RowInfoSize;
1523 BOOLEAN LineBreak;
1524 UINTN StrLength;
1525
1526 //
1527 // Check incoming parameters.
1528 //
1529
1530 if (This == NULL || String == NULL || Blt == NULL) {
1531 return EFI_INVALID_PARAMETER;
1532 }
1533 if (*Blt == NULL) {
1534 //
1535 // These two flag cannot be used if Blt is NULL upon entry.
1536 //
1537 if ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT) {
1538 return EFI_INVALID_PARAMETER;
1539 }
1540 if ((Flags & EFI_HII_OUT_FLAG_CLIP) == EFI_HII_OUT_FLAG_CLIP) {
1541 return EFI_INVALID_PARAMETER;
1542 }
1543 }
1544 //
1545 // These two flags require that EFI_HII_OUT_FLAG_CLIP be also set.
1546 //
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;
1549 }
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;
1552 }
1553 //
1554 // This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X.
1555 //
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;
1558 }
1559
1560 if (*Blt == NULL) {
1561 //
1562 // Create a new bitmap and draw the string onto this image.
1563 //
1564 Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
1565 if (Image == NULL) {
1566 return EFI_OUT_OF_RESOURCES;
1567 }
1568 Image->Width = 800;
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) {
1572 FreePool (Image);
1573 return EFI_OUT_OF_RESOURCES;
1574 }
1575
1576 //
1577 // Other flags are not permitted when Blt is NULL.
1578 //
1579 Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK;
1580 *Blt = Image;
1581 }
1582
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);
1590
1591 RowInfo = NULL;
1592 Status = EFI_SUCCESS;
1593 StringIn2 = NULL;
1594 SystemDefault = NULL;
1595 StringIn = NULL;
1596
1597 //
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
1600 // EFI_FONT_INFO.
1601 //
1602 StringInfoOut = NULL;
1603 FontHandle = NULL;
1604 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1605 SysFontFlag = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
1606
1607 if (SysFontFlag) {
1608 FontInfo = NULL;
1609 Height = SystemDefault->FontInfo.FontSize;
1610 Foreground = SystemDefault->ForegroundColor;
1611 Background = SystemDefault->BackgroundColor;
1612
1613 } else {
1614 //
1615 // StringInfo must not be NULL if it is not system info.
1616 //
1617 ASSERT (StringInfo != NULL);
1618 Status = HiiGetFontInfo (This, &FontHandle, (EFI_FONT_DISPLAY_INFO *) StringInfo, &StringInfoOut, NULL);
1619 if (Status == EFI_NOT_FOUND) {
1620 //
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.
1623 //
1624 SysFontFlag = TRUE;
1625 FontInfo = NULL;
1626 Height = SystemDefault->FontInfo.FontSize;
1627 Foreground = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->ForegroundColor;
1628 Background = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->BackgroundColor;
1629
1630 } else if (Status == EFI_SUCCESS) {
1631 FontInfo = &StringInfoOut->FontInfo;
1632 Height = StringInfoOut->FontInfo.FontSize;
1633 Foreground = StringInfoOut->ForegroundColor;
1634 Background = StringInfoOut->BackgroundColor;
1635 } else {
1636 goto Exit;
1637 }
1638 }
1639
1640 //
1641 // Parse the string to be displayed to drop some ignored characters.
1642 //
1643
1644 StringPtr = String;
1645
1646 //
1647 // Ignore line-break characters only. Hyphens or dash character will be displayed
1648 // without line-break opportunity.
1649 //
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;
1654 goto Exit;
1655 }
1656 StringTmp = StringIn;
1657 while (*StringPtr != 0) {
1658 if (IsLineBreak (*StringPtr) == 0) {
1659 StringPtr++;
1660 } else {
1661 *StringTmp++ = *StringPtr++;
1662 }
1663 }
1664 *StringTmp = 0;
1665 StringPtr = StringIn;
1666 }
1667 //
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.
1670 //
1671 StringIn2 = AllocateZeroPool (StrSize (StringPtr));
1672 if (StringIn2 == NULL) {
1673 Status = EFI_OUT_OF_RESOURCES;
1674 goto Exit;
1675 }
1676 Index = 0;
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++;
1685 Index++;
1686 } else {
1687 //
1688 // Unicode 0xFFFD must exist in current hii database if this flag is not set.
1689 //
1690 Status = GetGlyphBuffer (
1691 Private,
1692 REPLACE_UNKNOWN_GLYPH,
1693 FontInfo,
1694 &GlyphBuf[Index],
1695 &Cell[Index],
1696 &Attributes[Index]
1697 );
1698 if (EFI_ERROR (Status)) {
1699 Status = EFI_INVALID_PARAMETER;
1700 goto Exit;
1701 }
1702 *StringTmp++ = *StringPtr++;
1703 Index++;
1704 }
1705 } else if (EFI_ERROR (Status)) {
1706 goto Exit;
1707 } else {
1708 *StringTmp++ = *StringPtr++;
1709 Index++;
1710 }
1711 }
1712 *StringTmp = 0;
1713 StringPtr = StringIn2;
1714
1715 //
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.
1720 //
1721 Image = *Blt;
1722 BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX;
1723 MaxRowNum = (UINT16) (Image->Height / Height);
1724 if (Image->Height % Height != 0) {
1725 MaxRowNum++;
1726 }
1727
1728 RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO));
1729 if (RowInfo == NULL) {
1730 Status = EFI_OUT_OF_RESOURCES;
1731 goto Exit;
1732 }
1733
1734 //
1735 // Format the glyph buffer according to flags.
1736 //
1737
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) {
1740 //
1741 // Don't draw at all if there is only one row and
1742 // the row's bottom-most on pixel cannot fit.
1743 //
1744 if (MaxRowNum == 1 && SysFontFlag) {
1745 Status = EFI_SUCCESS;
1746 goto Exit;
1747 }
1748 }
1749
1750 for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) {
1751 LineWidth = 0;
1752 LineHeight = 0;
1753 BaseLineOffset = 0;
1754 LineBreak = FALSE;
1755
1756 //
1757 // Calculate how many characters there are in a row.
1758 //
1759 RowInfo[RowIndex].StartIndex = Index;
1760
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) {
1765 //
1766 // It forces a line break that ends this row.
1767 //
1768 Index++;
1769 LineBreak = TRUE;
1770 break;
1771 }
1772
1773 //
1774 // If the glyph of the character is existing, then accumulate the actual printed width
1775 //
1776 if (GlyphBuf[Index] != NULL) {
1777 LineWidth += (UINTN) Cell[Index].AdvanceX;
1778 if (LineHeight < Cell[Index].Height) {
1779 LineHeight = (UINTN) Cell[Index].Height;
1780 }
1781 }
1782
1783 Index++;
1784 }
1785
1786 //
1787 // If this character is the last character of a row, we need not
1788 // draw its (AdvanceX - Width) for next character.
1789 //
1790 Index--;
1791 if (!SysFontFlag) {
1792 LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width);
1793 }
1794
1795 //
1796 // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
1797 //
1798 if (LineWidth + BltX <= Image->Width ||
1799 (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) {
1800 //
1801 // Record right-most character in RowInfo even if it is partially displayed.
1802 //
1803 RowInfo[RowIndex].EndIndex = Index;
1804 RowInfo[RowIndex].LineWidth = LineWidth;
1805 RowInfo[RowIndex].LineHeight = LineHeight;
1806 RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
1807 } else {
1808 //
1809 // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character
1810 // if its right-most on pixel cannot fit.
1811 //
1812 if (Index > 0) {
1813 RowInfo[RowIndex].EndIndex = Index - 1;
1814 RowInfo[RowIndex].LineWidth = LineWidth - Cell[Index].AdvanceX;
1815 RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
1816 if (LineHeight > Cell[Index - 1].Height) {
1817 LineHeight = Cell[Index - 1].Height;
1818 }
1819 RowInfo[RowIndex].LineHeight = LineHeight;
1820 } else {
1821 //
1822 // There is only one column and it can not be drawn so that return directly.
1823 //
1824 Status = EFI_SUCCESS;
1825 goto Exit;
1826 }
1827 }
1828
1829 //
1830 // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break
1831 // opportunity prior to a character whose right-most extent would exceed Width.
1832 // Search the right-most line-break opportunity here.
1833 //
1834 if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP) {
1835 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {
1836 for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {
1837 if (IsLineBreak (StringPtr[Index1]) > 0) {
1838 LineBreak = TRUE;
1839 RowInfo[RowIndex].EndIndex = Index1 - 1;
1840 //
1841 // relocate to the character after the right-most line break opportunity of this line
1842 //
1843 Index = Index1 + 1;
1844 break;
1845 }
1846 //
1847 // If don't find a line break opportunity from EndIndex to StartIndex,
1848 // then jump out.
1849 //
1850 if (Index1 == RowInfo[RowIndex].StartIndex)
1851 break;
1852 }
1853 }
1854 //
1855 // If no line-break opportunity can be found, then the text will
1856 // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.
1857 //
1858 if (!LineBreak) {
1859 Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP);
1860 Flags |= EFI_HII_OUT_FLAG_CLIP_CLEAN_X;
1861 }
1862 }
1863
1864 //
1865 // Clip the final row if the row's bottom-most on pixel cannot fit when
1866 // EFI_HII_OUT_FLAG_CLEAN_Y is set.
1867 //
1868 if (RowIndex == MaxRowNum - 1 && Image->Height < LineHeight) {
1869 LineHeight = Image->Height;
1870 if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {
1871 //
1872 // Don't draw at all if the row's bottom-most on pixel cannot fit.
1873 //
1874 break;
1875 }
1876 }
1877
1878 //
1879 // Draw it to screen or existing bitmap depending on whether
1880 // EFI_HII_DIRECT_TO_SCREEN is set.
1881 //
1882 if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {
1883 BltBuffer = AllocateZeroPool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
1884 if (BltBuffer == NULL) {
1885 Status = EFI_OUT_OF_RESOURCES;
1886 goto Exit;
1887 }
1888 BufferPtr = BltBuffer;
1889 for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
1890 if (GlyphBuf[Index1] != NULL) {
1891 //
1892 // Only BLT these character which have corrsponding glyph in font basebase.
1893 //
1894 GlyphToImage (
1895 GlyphBuf[Index1],
1896 Foreground,
1897 Background,
1898 RowInfo[RowIndex].LineWidth,
1899 RowInfo[RowIndex].LineHeight,
1900 Transparent,
1901 &Cell[Index1],
1902 Attributes[Index1],
1903 &BufferPtr
1904 );
1905 }
1906 if (ColumnInfoArray != NULL) {
1907 if (GlyphBuf[Index1] == NULL) {
1908 *ColumnInfoArray = 0;
1909 } else {
1910 *ColumnInfoArray = Cell[Index1 -1].AdvanceX;
1911 }
1912 ColumnInfoArray++;
1913 }
1914 }
1915 //
1916 // Recalculate the start point of X/Y axis to draw multi-lines with the order of top-to-down
1917 //
1918 if (RowIndex != 0) {
1919 BltX = 0;
1920 BltY += RowInfo[RowIndex].LineHeight;
1921 }
1922
1923 Status = Image->Image.Screen->Blt (
1924 Image->Image.Screen,
1925 BltBuffer,
1926 EfiBltBufferToVideo,
1927 0,
1928 0,
1929 BltX,
1930 BltY,
1931 RowInfo[RowIndex].LineWidth,
1932 RowInfo[RowIndex].LineHeight,
1933 0
1934 );
1935 if (EFI_ERROR (Status)) {
1936 FreePool (BltBuffer);
1937 goto Exit;
1938 }
1939
1940 FreePool (BltBuffer);
1941
1942 } else {
1943 for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
1944 if (GlyphBuf[Index1] != NULL) {
1945 //
1946 // Only BLT these character which have corrsponding glyph in font basebase.
1947 //
1948 GlyphToImage (
1949 GlyphBuf[Index1],
1950 Foreground,
1951 Background,
1952 Image->Width,
1953 Image->Height,
1954 Transparent,
1955 &Cell[Index1],
1956 Attributes[Index1],
1957 &BufferPtr
1958 );
1959 }
1960 if (ColumnInfoArray != NULL) {
1961 if (GlyphBuf[Index1] == NULL) {
1962 *ColumnInfoArray = 0;
1963 } else {
1964 *ColumnInfoArray = Cell[Index1 -1].AdvanceX;
1965 }
1966 ColumnInfoArray++;
1967 }
1968 }
1969 //
1970 // Jump to next row
1971 //
1972 BufferPtr += BltX + Image->Width * (LineHeight - 1);
1973 }
1974
1975 Index++;
1976 RowIndex++;
1977
1978 if (!LineBreak) {
1979 //
1980 // If there is not a mandatory line break or line break opportunity, only render one line to image
1981 //
1982 break;
1983 }
1984 }
1985
1986 //
1987 // Write output parameters.
1988 //
1989 RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO);
1990 if (RowInfoArray != NULL) {
1991 *RowInfoArray = AllocateZeroPool (RowInfoSize);
1992 if (*RowInfoArray == NULL) {
1993 Status = EFI_OUT_OF_RESOURCES;
1994 goto Exit;
1995 }
1996 CopyMem (*RowInfoArray, RowInfo, RowInfoSize);
1997 }
1998 if (RowInfoArraySize != NULL) {
1999 *RowInfoArraySize = RowIndex;
2000 }
2001
2002 Status = EFI_SUCCESS;
2003
2004 Exit:
2005
2006 for (Index = 0; Index < StrLength; Index++) {
2007 if (GlyphBuf[Index] != NULL) {
2008 FreePool (GlyphBuf[Index]);
2009 }
2010 }
2011 if (StringIn != NULL) {
2012 FreePool (StringIn);
2013 }
2014 if (StringIn2 != NULL) {
2015 FreePool (StringIn2);
2016 }
2017 if (StringInfoOut != NULL) {
2018 FreePool (StringInfoOut);
2019 }
2020 if (RowInfo != NULL) {
2021 FreePool (RowInfo);
2022 }
2023 if (SystemDefault != NULL) {
2024 FreePool (SystemDefault);
2025 }
2026 if (GlyphBuf != NULL) {
2027 FreePool (GlyphBuf);
2028 }
2029 if (Cell != NULL) {
2030 FreePool (Cell);
2031 }
2032 if (Attributes != NULL) {
2033 FreePool (Attributes);
2034 }
2035
2036 return Status;
2037 }
2038
2039
2040 /**
2041 Render a string to a bitmap or the screen containing the contents of the specified string.
2042
2043 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2044 @param Flags Describes how the string is to be drawn.
2045 @param PackageList The package list in the HII database to search
2046 for the specified string.
2047 @param StringId The string's id, which is unique within
2048 PackageList.
2049 @param Language Points to the language for the retrieved string.
2050 If NULL, then the current system language is
2051 used.
2052 @param StringInfo Points to the string output information,
2053 including the color and font. If NULL, then the
2054 string will be output in the default system font
2055 and color.
2056 @param Blt If this points to a non-NULL on entry, this
2057 points to the image, which is Width pixels wide
2058 and Height pixels high. The string will be drawn
2059 onto this image and
2060 EFI_HII_OUT_FLAG_CLIP is implied. If this points
2061 to a NULL on entry, then a buffer
2062 will be allocated to hold the generated image and
2063 the pointer updated on exit. It is the caller's
2064 responsibility to free this buffer.
2065 @param BltX Specifies the offset from the left and top edge
2066 of the image of the first character cell in the
2067 image.
2068 @param BltY Specifies the offset from the left and top edge
2069 of the image of the first character cell in the
2070 image.
2071 @param RowInfoArray If this is non-NULL on entry, then on exit, this
2072 will point to an allocated buffer containing
2073 row information and RowInfoArraySize will be
2074 updated to contain the number of elements.
2075 This array describes the characters which were at
2076 least partially drawn and the heights of the
2077 rows. It is the caller's responsibility to free
2078 this buffer.
2079 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
2080 contains the number of elements in RowInfoArray.
2081 @param ColumnInfoArray If this is non-NULL, then on return it will be
2082 filled with the horizontal offset for each
2083 character in the string on the row where it is
2084 displayed. Non-printing characters will have
2085 the offset ~0. The caller is responsible to
2086 allocate a buffer large enough so that there
2087 is one entry for each character in the string,
2088 not including the null-terminator. It is possible
2089 when character display is normalized that some
2090 character cells overlap.
2091
2092 @retval EFI_SUCCESS The string was successfully rendered.
2093 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
2094 RowInfoArray or Blt.
2095 @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL.
2096 @retval EFI_INVALID_PARAMETER Flags were invalid combination.
2097 @retval EFI_NOT_FOUND The specified PackageList is not in the Database or the stringid is not
2098 in the specified PackageList.
2099
2100 **/
2101 EFI_STATUS
2102 EFIAPI
2103 HiiStringIdToImage (
2104 IN CONST EFI_HII_FONT_PROTOCOL *This,
2105 IN EFI_HII_OUT_FLAGS Flags,
2106 IN EFI_HII_HANDLE PackageList,
2107 IN EFI_STRING_ID StringId,
2108 IN CONST CHAR8* Language,
2109 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
2110 IN OUT EFI_IMAGE_OUTPUT **Blt,
2111 IN UINTN BltX,
2112 IN UINTN BltY,
2113 OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
2114 OUT UINTN *RowInfoArraySize OPTIONAL,
2115 OUT UINTN *ColumnInfoArray OPTIONAL
2116 )
2117 {
2118 EFI_STATUS Status;
2119 HII_DATABASE_PRIVATE_DATA *Private;
2120 EFI_HII_STRING_PROTOCOL *HiiString;
2121 EFI_STRING String;
2122 UINTN StringSize;
2123 UINTN FontLen;
2124 EFI_FONT_INFO *StringFontInfo;
2125 EFI_FONT_DISPLAY_INFO *NewStringInfo;
2126 CHAR8 TempSupportedLanguages;
2127 CHAR8 *SupportedLanguages;
2128 UINTN SupportedLanguagesSize;
2129 CHAR8 *CurrentLanguage;
2130 CHAR8 *BestLanguage;
2131
2132 if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {
2133 return EFI_INVALID_PARAMETER;
2134 }
2135
2136 if (!IsHiiHandleValid (PackageList)) {
2137 return EFI_NOT_FOUND;
2138 }
2139
2140 //
2141 // Initialize string pointers to be NULL
2142 //
2143 SupportedLanguages = NULL;
2144 CurrentLanguage = NULL;
2145 BestLanguage = NULL;
2146 String = NULL;
2147 StringInfo = NULL;
2148 StringFontInfo = NULL;
2149 NewStringInfo = NULL;
2150
2151 //
2152 // Get the string to be displayed.
2153 //
2154 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2155 HiiString = &Private->HiiString;
2156
2157 //
2158 // Get the size of supported language.
2159 //
2160 SupportedLanguagesSize = 0;
2161 Status = HiiString->GetLanguages (
2162 HiiString,
2163 PackageList,
2164 &TempSupportedLanguages,
2165 &SupportedLanguagesSize
2166 );
2167 if (Status != EFI_BUFFER_TOO_SMALL) {
2168 return Status;
2169 }
2170
2171 SupportedLanguages = AllocatePool (SupportedLanguagesSize);
2172 if (SupportedLanguages == NULL) {
2173 return EFI_OUT_OF_RESOURCES;
2174 }
2175
2176 Status = HiiString->GetLanguages (
2177 HiiString,
2178 PackageList,
2179 SupportedLanguages,
2180 &SupportedLanguagesSize
2181 );
2182 if (EFI_ERROR (Status)) {
2183 goto Exit;
2184 }
2185
2186 if (Language == NULL) {
2187 Language = "";
2188 }
2189 CurrentLanguage = GetEfiGlobalVariable (L"PlatformLang");
2190 BestLanguage = GetBestLanguage (
2191 SupportedLanguages,
2192 FALSE,
2193 Language,
2194 (CurrentLanguage == NULL) ? CurrentLanguage : "",
2195 (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
2196 NULL
2197 );
2198 if (BestLanguage == NULL) {
2199 Status = EFI_NOT_FOUND;
2200 goto Exit;
2201 }
2202
2203 StringSize = MAX_STRING_LENGTH;
2204 String = (EFI_STRING) AllocateZeroPool (StringSize);
2205 if (String == NULL) {
2206 Status = EFI_OUT_OF_RESOURCES;
2207 goto Exit;
2208 }
2209
2210 Status = HiiString->GetString (
2211 HiiString,
2212 BestLanguage,
2213 PackageList,
2214 StringId,
2215 String,
2216 &StringSize,
2217 &StringFontInfo
2218 );
2219 if (Status == EFI_BUFFER_TOO_SMALL) {
2220 FreePool (String);
2221 String = (EFI_STRING) AllocateZeroPool (StringSize);
2222 if (String == NULL) {
2223 Status = EFI_OUT_OF_RESOURCES;
2224 goto Exit;
2225 }
2226 Status = HiiString->GetString (
2227 HiiString,
2228 BestLanguage,
2229 PackageList,
2230 StringId,
2231 String,
2232 &StringSize,
2233 NULL
2234 );
2235 }
2236
2237 if (EFI_ERROR (Status)) {
2238 goto Exit;
2239 }
2240
2241 //
2242 // When StringInfo specifies that string will be output in the system default font and color,
2243 // use particular stringfontinfo described in string package instead if exists.
2244 // StringFontInfo equals NULL means system default font attaches with the string block.
2245 //
2246 if (StringFontInfo != NULL && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, NULL, NULL)) {
2247 FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + StrSize (StringFontInfo->FontName);
2248 NewStringInfo = AllocateZeroPool (FontLen);
2249 if (NewStringInfo == NULL) {
2250 Status = EFI_OUT_OF_RESOURCES;
2251 goto Exit;
2252 }
2253 NewStringInfo->FontInfoMask = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR;
2254 NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle;
2255 NewStringInfo->FontInfo.FontSize = StringFontInfo->FontSize;
2256 StrCpy (NewStringInfo->FontInfo.FontName, StringFontInfo->FontName);
2257
2258 Status = HiiStringToImage (
2259 This,
2260 Flags,
2261 String,
2262 NewStringInfo,
2263 Blt,
2264 BltX,
2265 BltY,
2266 RowInfoArray,
2267 RowInfoArraySize,
2268 ColumnInfoArray
2269 );
2270 goto Exit;
2271 }
2272
2273 Status = HiiStringToImage (
2274 This,
2275 Flags,
2276 String,
2277 StringInfo,
2278 Blt,
2279 BltX,
2280 BltY,
2281 RowInfoArray,
2282 RowInfoArraySize,
2283 ColumnInfoArray
2284 );
2285
2286 Exit:
2287 if (SupportedLanguages != NULL) {
2288 FreePool (SupportedLanguages);
2289 }
2290 if (CurrentLanguage != NULL) {
2291 FreePool (CurrentLanguage);
2292 }
2293 if (BestLanguage != NULL) {
2294 FreePool (BestLanguage);
2295 }
2296 if (String != NULL) {
2297 FreePool (String);
2298 }
2299 if (StringFontInfo != NULL) {
2300 FreePool (StringFontInfo);
2301 }
2302 if (NewStringInfo != NULL) {
2303 FreePool (NewStringInfo);
2304 }
2305
2306 return Status;
2307 }
2308
2309
2310 /**
2311 Convert the glyph for a single character into a bitmap.
2312
2313 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2314 @param Char Character to retrieve.
2315 @param StringInfo Points to the string font and color information
2316 or NULL if the string should use the default
2317 system font and color.
2318 @param Blt Thus must point to a NULL on entry. A buffer will
2319 be allocated to hold the output and the pointer
2320 updated on exit. It is the caller's
2321 responsibility to free this buffer.
2322 @param Baseline Number of pixels from the bottom of the bitmap to
2323 the baseline.
2324
2325 @retval EFI_SUCCESS Glyph bitmap created.
2326 @retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer Blt.
2327 @retval EFI_WARN_UNKNOWN_GLYPH The glyph was unknown and was replaced with the
2328 glyph for Unicode character 0xFFFD.
2329 @retval EFI_INVALID_PARAMETER Blt is NULL or *Blt is not NULL.
2330
2331 **/
2332 EFI_STATUS
2333 EFIAPI
2334 HiiGetGlyph (
2335 IN CONST EFI_HII_FONT_PROTOCOL *This,
2336 IN CHAR16 Char,
2337 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo,
2338 OUT EFI_IMAGE_OUTPUT **Blt,
2339 OUT UINTN *Baseline OPTIONAL
2340 )
2341 {
2342 EFI_STATUS Status;
2343 HII_DATABASE_PRIVATE_DATA *Private;
2344 EFI_IMAGE_OUTPUT *Image;
2345 UINT8 *GlyphBuffer;
2346 EFI_FONT_DISPLAY_INFO *SystemDefault;
2347 EFI_FONT_DISPLAY_INFO *StringInfoOut;
2348 BOOLEAN Default;
2349 EFI_FONT_HANDLE FontHandle;
2350 EFI_STRING String;
2351 EFI_HII_GLYPH_INFO Cell;
2352 EFI_FONT_INFO *FontInfo;
2353 UINT8 Attributes;
2354 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
2355 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
2356 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
2357
2358 if (This == NULL || Blt == NULL || *Blt != NULL) {
2359 return EFI_INVALID_PARAMETER;
2360 }
2361
2362 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2363
2364 Default = FALSE;
2365 Image = NULL;
2366 SystemDefault = NULL;
2367 FontHandle = NULL;
2368 String = NULL;
2369 GlyphBuffer = NULL;
2370 StringInfoOut = NULL;
2371 FontInfo = NULL;
2372
2373 ZeroMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2374 ZeroMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2375
2376 Default = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
2377
2378 if (!Default) {
2379 //
2380 // Find out a EFI_FONT_DISPLAY_INFO which could display the character in
2381 // the specified color and font.
2382 //
2383 String = (EFI_STRING) AllocateZeroPool (sizeof (CHAR16) * 2);
2384 if (String == NULL) {
2385 Status = EFI_OUT_OF_RESOURCES;
2386 goto Exit;
2387 }
2388 *String = Char;
2389 *(String + 1) = 0;
2390
2391 Status = HiiGetFontInfo (This, &FontHandle, StringInfo, &StringInfoOut, String);
2392 if (EFI_ERROR (Status)) {
2393 goto Exit;
2394 }
2395 ASSERT (StringInfoOut != NULL);
2396 FontInfo = &StringInfoOut->FontInfo;
2397 Foreground = StringInfoOut->ForegroundColor;
2398 Background = StringInfoOut->BackgroundColor;
2399 } else {
2400 Foreground = SystemDefault->ForegroundColor;
2401 Background = SystemDefault->BackgroundColor;
2402 }
2403
2404 Status = GetGlyphBuffer (Private, Char, FontInfo, &GlyphBuffer, &Cell, &Attributes);
2405 if (EFI_ERROR (Status)) {
2406 goto Exit;
2407 }
2408
2409 Image = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
2410 if (Image == NULL) {
2411 Status = EFI_OUT_OF_RESOURCES;
2412 goto Exit;
2413 }
2414 Image->Width = Cell.Width;
2415 Image->Height = Cell.Height;
2416
2417 Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2418 if (Image->Image.Bitmap == NULL) {
2419 FreePool (Image);
2420 Status = EFI_OUT_OF_RESOURCES;
2421 goto Exit;
2422 }
2423
2424 BltBuffer = Image->Image.Bitmap;
2425 GlyphToImage (
2426 GlyphBuffer,
2427 Foreground,
2428 Background,
2429 Image->Width,
2430 Image->Height,
2431 FALSE,
2432 &Cell,
2433 Attributes,
2434 &BltBuffer
2435 );
2436
2437 *Blt = Image;
2438 if (Baseline != NULL) {
2439 *Baseline = Cell.OffsetY;
2440 }
2441
2442 Status = EFI_SUCCESS;
2443
2444 Exit:
2445
2446 if (Status == EFI_NOT_FOUND) {
2447 //
2448 // Glyph is unknown and replaced with the glyph for unicode character 0xFFFD
2449 //
2450 if (Char != REPLACE_UNKNOWN_GLYPH) {
2451 Status = HiiGetGlyph (This, REPLACE_UNKNOWN_GLYPH, StringInfo, Blt, Baseline);
2452 if (!EFI_ERROR (Status)) {
2453 Status = EFI_WARN_UNKNOWN_GLYPH;
2454 }
2455 } else {
2456 Status = EFI_WARN_UNKNOWN_GLYPH;
2457 }
2458 }
2459
2460 if (SystemDefault != NULL) {
2461 FreePool (SystemDefault);
2462 }
2463 if (StringInfoOut != NULL) {
2464 FreePool (StringInfoOut);
2465 }
2466 if (String != NULL) {
2467 FreePool (String);
2468 }
2469 if (GlyphBuffer != NULL) {
2470 FreePool (GlyphBuffer);
2471 }
2472
2473 return Status;
2474 }
2475
2476
2477 /**
2478 This function iterates through fonts which match the specified font, using
2479 the specified criteria. If String is non-NULL, then all of the characters in
2480 the string must exist in order for a candidate font to be returned.
2481
2482 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2483 @param FontHandle On entry, points to the font handle returned by a
2484 previous call to GetFontInfo() or NULL to start
2485 with the first font. On return, points to the
2486 returned font handle or points to NULL if there
2487 are no more matching fonts.
2488 @param StringInfoIn Upon entry, points to the font to return
2489 information about.
2490 If NULL, then the information about the system default
2491 font will be returned.
2492 @param StringInfoOut Upon return, contains the matching font's
2493 information. If NULL, then no information is
2494 returned. It's caller's responsibility to free
2495 this buffer.
2496 @param String Points to the string which will be tested to
2497 determine if all characters are available. If
2498 NULL, then any font is acceptable.
2499
2500 @retval EFI_SUCCESS Matching font returned successfully.
2501 @retval EFI_NOT_FOUND No matching font was found.
2502 @retval EFI_INVALID_PARAMETER StringInfoIn->FontInfoMask is an invalid combination.
2503 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
2504 request.
2505
2506 **/
2507 EFI_STATUS
2508 EFIAPI
2509 HiiGetFontInfo (
2510 IN CONST EFI_HII_FONT_PROTOCOL *This,
2511 IN OUT EFI_FONT_HANDLE *FontHandle,
2512 IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn, OPTIONAL
2513 OUT EFI_FONT_DISPLAY_INFO **StringInfoOut,
2514 IN CONST EFI_STRING String OPTIONAL
2515 )
2516 {
2517 HII_DATABASE_PRIVATE_DATA *Private;
2518 EFI_STATUS Status;
2519 EFI_FONT_DISPLAY_INFO *SystemDefault;
2520 EFI_FONT_DISPLAY_INFO InfoOut;
2521 UINTN StringInfoOutLen;
2522 EFI_FONT_INFO *FontInfo;
2523 HII_GLOBAL_FONT_INFO *GlobalFont;
2524 EFI_STRING StringIn;
2525 EFI_FONT_HANDLE LocalFontHandle;
2526
2527 if (This == NULL) {
2528 return EFI_INVALID_PARAMETER;
2529 }
2530
2531 FontInfo = NULL;
2532 SystemDefault = NULL;
2533 LocalFontHandle = NULL;
2534 if (FontHandle != NULL) {
2535 LocalFontHandle = *FontHandle;
2536 }
2537
2538 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2539
2540 //
2541 // Already searched to the end of the whole list, return directly.
2542 //
2543 if (LocalFontHandle == &Private->FontInfoList) {
2544 LocalFontHandle = NULL;
2545 Status = EFI_NOT_FOUND;
2546 goto Exit;
2547 }
2548
2549 //
2550 // Get default system display info, if StringInfoIn points to
2551 // system display info, return it directly.
2552 //
2553 if (IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, &SystemDefault, &StringInfoOutLen)) {
2554 //
2555 // System font is the first node. When handle is not NULL, system font can not
2556 // be found any more.
2557 //
2558 if (LocalFontHandle == NULL) {
2559 if (StringInfoOut != NULL) {
2560 *StringInfoOut = AllocateCopyPool (StringInfoOutLen, SystemDefault);
2561 if (*StringInfoOut == NULL) {
2562 Status = EFI_OUT_OF_RESOURCES;
2563 LocalFontHandle = NULL;
2564 goto Exit;
2565 }
2566 }
2567
2568 LocalFontHandle = Private->FontInfoList.ForwardLink;
2569 Status = EFI_SUCCESS;
2570 goto Exit;
2571 } else {
2572 LocalFontHandle = NULL;
2573 Status = EFI_NOT_FOUND;
2574 goto Exit;
2575 }
2576 }
2577
2578 //
2579 // StringInfoIn must not be NULL if it is not system default font info.
2580 //
2581 ASSERT (StringInfoIn != NULL);
2582 //
2583 // Check the font information mask to make sure it is valid.
2584 //
2585 if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ==
2586 (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ||
2587 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ==
2588 (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ||
2589 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ==
2590 (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ||
2591 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ==
2592 (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ||
2593 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)) ==
2594 (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) {
2595 return EFI_INVALID_PARAMETER;
2596 }
2597
2598 //
2599 // Parse the font information mask to find a matching font.
2600 //
2601
2602 CopyMem (&InfoOut, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, sizeof (EFI_FONT_DISPLAY_INFO));
2603
2604 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FONT) == EFI_FONT_INFO_SYS_FONT) {
2605 Status = SaveFontName (SystemDefault->FontInfo.FontName, &FontInfo);
2606 } else {
2607 Status = SaveFontName (((EFI_FONT_DISPLAY_INFO *) StringInfoIn)->FontInfo.FontName, &FontInfo);
2608 }
2609 if (EFI_ERROR (Status)) {
2610 goto Exit;
2611 }
2612
2613 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_SIZE) == EFI_FONT_INFO_SYS_SIZE) {
2614 InfoOut.FontInfo.FontSize = SystemDefault->FontInfo.FontSize;
2615 }
2616 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) {
2617 InfoOut.FontInfo.FontStyle = SystemDefault->FontInfo.FontStyle;
2618 }
2619 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) {
2620 InfoOut.ForegroundColor = SystemDefault->ForegroundColor;
2621 }
2622 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) {
2623 InfoOut.BackgroundColor = SystemDefault->BackgroundColor;
2624 }
2625
2626 ASSERT (FontInfo != NULL);
2627 FontInfo->FontSize = InfoOut.FontInfo.FontSize;
2628 FontInfo->FontStyle = InfoOut.FontInfo.FontStyle;
2629
2630 if (IsFontInfoExisted (Private, FontInfo, &InfoOut.FontInfoMask, LocalFontHandle, &GlobalFont)) {
2631 //
2632 // Test to guarantee all characters are available in the found font.
2633 //
2634 if (String != NULL) {
2635 StringIn = String;
2636 while (*StringIn != 0) {
2637 Status = FindGlyphBlock (GlobalFont->FontPackage, *StringIn, NULL, NULL, NULL);
2638 if (EFI_ERROR (Status)) {
2639 LocalFontHandle = NULL;
2640 goto Exit;
2641 }
2642 StringIn++;
2643 }
2644 }
2645 //
2646 // Write to output parameter
2647 //
2648 if (StringInfoOut != NULL) {
2649 StringInfoOutLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (EFI_FONT_INFO) + GlobalFont->FontInfoSize;
2650 *StringInfoOut = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (StringInfoOutLen);
2651 if (*StringInfoOut == NULL) {
2652 Status = EFI_OUT_OF_RESOURCES;
2653 LocalFontHandle = NULL;
2654 goto Exit;
2655 }
2656
2657 CopyMem (*StringInfoOut, &InfoOut, sizeof (EFI_FONT_DISPLAY_INFO));
2658 CopyMem (&(*StringInfoOut)->FontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);
2659 }
2660
2661 LocalFontHandle = GlobalFont->Entry.ForwardLink;
2662 Status = EFI_SUCCESS;
2663 goto Exit;
2664 }
2665
2666 Status = EFI_NOT_FOUND;
2667
2668 Exit:
2669
2670 if (FontHandle != NULL) {
2671 *FontHandle = LocalFontHandle;
2672 }
2673
2674 if (SystemDefault != NULL) {
2675 FreePool (SystemDefault);
2676 }
2677 if (FontInfo != NULL) {
2678 FreePool (FontInfo);
2679 }
2680 return Status;
2681 }
2682
2683