]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
Clean up HiiDatabase for Doxygen comments requirement.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / Font.c
1 /** @file
2 Implementation for EFI_HII_FONT_PROTOCOL.
3
4
5 Copyright (c) 2007 - 2008, 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
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 STATIC EFI_GRAPHICS_OUTPUT_BLT_PIXEL mEfiColors[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 = mEfiColors[Private->Attribute & 0x0f];
916 Info->BackgroundColor = mEfiColors[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 SafeFreePool (SystemDefault);
1028 }
1029 return Flag;
1030 }
1031
1032
1033 /**
1034 This function checks whether EFI_FONT_INFO exists in current database. If
1035 FontInfoMask is specified, check what options can be used to make a match.
1036 Note that the masks relate to where the system default should be supplied
1037 are ignored by this function.
1038
1039 @param Private Hii database private structure.
1040 @param FontInfo Points to EFI_FONT_INFO structure.
1041 @param FontInfoMask If not NULL, describes what options can be used
1042 to make a match between the font requested and
1043 the font available. The caller must guarantee
1044 this mask is valid.
1045 @param FontHandle On entry, Points to the font handle returned by a
1046 previous call to GetFontInfo() or NULL to start
1047 with the first font.
1048 @param GlobalFontInfo If not NULL, output the corresponding globa font
1049 info.
1050
1051 @retval TRUE Existed
1052 @retval FALSE Not existed
1053
1054 **/
1055 BOOLEAN
1056 IsFontInfoExisted (
1057 IN HII_DATABASE_PRIVATE_DATA *Private,
1058 IN EFI_FONT_INFO *FontInfo,
1059 IN EFI_FONT_INFO_MASK *FontInfoMask, OPTIONAL
1060 IN EFI_FONT_HANDLE FontHandle, OPTIONAL
1061 OUT HII_GLOBAL_FONT_INFO **GlobalFontInfo OPTIONAL
1062 )
1063 {
1064 HII_GLOBAL_FONT_INFO *GlobalFont;
1065 HII_GLOBAL_FONT_INFO *GlobalFontBackup1;
1066 HII_GLOBAL_FONT_INFO *GlobalFontBackup2;
1067 LIST_ENTRY *Link;
1068 EFI_FONT_INFO_MASK Mask;
1069 BOOLEAN Matched;
1070 BOOLEAN VagueMatched1;
1071 BOOLEAN VagueMatched2;
1072
1073 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
1074 ASSERT (FontInfo != NULL);
1075
1076 //
1077 // Matched flag represents an exactly match; VagueMatched1 repensents a RESIZE
1078 // or RESTYLE match; VagueMatched2 represents a RESIZE | RESTYLE match.
1079 //
1080 Matched = FALSE;
1081 VagueMatched1 = FALSE;
1082 VagueMatched2 = FALSE;
1083
1084 Mask = 0;
1085 GlobalFontBackup1 = NULL;
1086 GlobalFontBackup2 = NULL;
1087
1088 // The process of where the system default should be supplied instead of
1089 // the specified font info beyonds this function's scope.
1090 //
1091 if (FontInfoMask != NULL) {
1092 Mask = *FontInfoMask & (~SYS_FONT_INFO_MASK);
1093 }
1094
1095 //
1096 // If not NULL, FontHandle points to the next node of the last searched font
1097 // node by previous call.
1098 //
1099 if (FontHandle == NULL) {
1100 Link = Private->FontInfoList.ForwardLink;
1101 } else {
1102 Link = (LIST_ENTRY *) FontHandle;
1103 }
1104
1105 for (; Link != &Private->FontInfoList; Link = Link->ForwardLink) {
1106 GlobalFont = CR (Link, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);
1107 if (FontInfoMask == NULL) {
1108 if (CompareMem (GlobalFont->FontInfo, FontInfo, GlobalFont->FontInfoSize) == 0) {
1109 if (GlobalFontInfo != NULL) {
1110 *GlobalFontInfo = GlobalFont;
1111 }
1112 return TRUE;
1113 }
1114 } else {
1115 //
1116 // Check which options could be used to make a match.
1117 //
1118 switch (Mask) {
1119 case EFI_FONT_INFO_ANY_FONT:
1120 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle &&
1121 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1122 Matched = TRUE;
1123 }
1124 break;
1125 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE:
1126 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1127 Matched = TRUE;
1128 }
1129 break;
1130 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE:
1131 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1132 Matched = TRUE;
1133 }
1134 break;
1135 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_ANY_STYLE:
1136 Matched = TRUE;
1137 break;
1138 //
1139 // If EFI_FONT_INFO_RESTYLE is specified, then the system may attempt to
1140 // remove some of the specified styles to meet the style requested.
1141 //
1142 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESTYLE:
1143 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1144 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1145 Matched = TRUE;
1146 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1147 VagueMatched1 = TRUE;
1148 GlobalFontBackup1 = GlobalFont;
1149 }
1150 }
1151 break;
1152 //
1153 // If EFI_FONT_INFO_RESIZE is specified, then the sytem may attempt to
1154 // stretch or shrink a font to meet the size requested.
1155 //
1156 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESIZE:
1157 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1158 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1159 Matched = TRUE;
1160 } else {
1161 VagueMatched1 = TRUE;
1162 GlobalFontBackup1 = GlobalFont;
1163 }
1164 }
1165 break;
1166 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_RESIZE:
1167 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1168 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1169 Matched = TRUE;
1170 } else {
1171 VagueMatched1 = TRUE;
1172 GlobalFontBackup1 = GlobalFont;
1173 }
1174 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1175 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1176 VagueMatched1 = TRUE;
1177 GlobalFontBackup1 = GlobalFont;
1178 } else {
1179 VagueMatched2 = TRUE;
1180 GlobalFontBackup2 = GlobalFont;
1181 }
1182 }
1183 break;
1184 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
1185 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1186 Matched = TRUE;
1187 } else {
1188 VagueMatched1 = TRUE;
1189 GlobalFontBackup1 = GlobalFont;
1190 }
1191 break;
1192 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
1193 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1194 Matched = TRUE;
1195 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1196 VagueMatched1 = TRUE;
1197 GlobalFontBackup1 = GlobalFont;
1198 }
1199 break;
1200 case EFI_FONT_INFO_ANY_STYLE:
1201 if ((CompareMem (
1202 GlobalFont->FontInfo->FontName,
1203 FontInfo->FontName,
1204 StrSize (FontInfo->FontName)
1205 ) == 0) &&
1206 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1207 Matched = TRUE;
1208 }
1209 break;
1210 case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_ANY_SIZE:
1211 if (CompareMem (
1212 GlobalFont->FontInfo->FontName,
1213 FontInfo->FontName,
1214 StrSize (FontInfo->FontName)
1215 ) == 0) {
1216 Matched = TRUE;
1217 }
1218 break;
1219 case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
1220 if (CompareMem (
1221 GlobalFont->FontInfo->FontName,
1222 FontInfo->FontName,
1223 StrSize (FontInfo->FontName)
1224 ) == 0) {
1225 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1226 Matched = TRUE;
1227 } else {
1228 VagueMatched1 = TRUE;
1229 GlobalFontBackup1 = GlobalFont;
1230 }
1231 }
1232 break;
1233 case EFI_FONT_INFO_ANY_SIZE:
1234 if ((CompareMem (
1235 GlobalFont->FontInfo->FontName,
1236 FontInfo->FontName,
1237 StrSize (FontInfo->FontName)
1238 ) == 0) &&
1239 GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1240 Matched = TRUE;
1241 }
1242 break;
1243 case EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
1244 if (CompareMem (
1245 GlobalFont->FontInfo->FontName,
1246 FontInfo->FontName,
1247 StrSize (FontInfo->FontName)
1248 ) == 0) {
1249 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1250 Matched = TRUE;
1251 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1252 VagueMatched1 = TRUE;
1253 GlobalFontBackup1 = GlobalFont;
1254 }
1255 }
1256 break;
1257 case EFI_FONT_INFO_RESTYLE:
1258 if ((CompareMem (
1259 GlobalFont->FontInfo->FontName,
1260 FontInfo->FontName,
1261 StrSize (FontInfo->FontName)
1262 ) == 0) &&
1263 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1264
1265 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1266 Matched = TRUE;
1267 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1268 VagueMatched1 = TRUE;
1269 GlobalFontBackup1 = GlobalFont;
1270 }
1271 }
1272 break;
1273 case EFI_FONT_INFO_RESIZE:
1274 if ((CompareMem (
1275 GlobalFont->FontInfo->FontName,
1276 FontInfo->FontName,
1277 StrSize (FontInfo->FontName)
1278 ) == 0) &&
1279 GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1280
1281 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1282 Matched = TRUE;
1283 } else {
1284 VagueMatched1 = TRUE;
1285 GlobalFontBackup1 = GlobalFont;
1286 }
1287 }
1288 break;
1289 case EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_RESTYLE:
1290 if (CompareMem (
1291 GlobalFont->FontInfo->FontName,
1292 FontInfo->FontName,
1293 StrSize (FontInfo->FontName)
1294 ) == 0) {
1295 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1296 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1297 Matched = TRUE;
1298 } else {
1299 VagueMatched1 = TRUE;
1300 GlobalFontBackup1 = GlobalFont;
1301 }
1302 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1303 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1304 VagueMatched1 = TRUE;
1305 GlobalFontBackup1 = GlobalFont;
1306 } else {
1307 VagueMatched2 = TRUE;
1308 GlobalFontBackup2 = GlobalFont;
1309 }
1310 }
1311 }
1312 break;
1313 default:
1314 break;
1315 }
1316
1317 if (Matched) {
1318 if (GlobalFontInfo != NULL) {
1319 *GlobalFontInfo = GlobalFont;
1320 }
1321 return TRUE;
1322 }
1323 }
1324 }
1325
1326 if (VagueMatched1) {
1327 if (GlobalFontInfo != NULL) {
1328 *GlobalFontInfo = GlobalFontBackup1;
1329 }
1330 return TRUE;
1331 } else if (VagueMatched2) {
1332 if (GlobalFontInfo != NULL) {
1333 *GlobalFontInfo = GlobalFontBackup2;
1334 }
1335 return TRUE;
1336 }
1337
1338 return FALSE;
1339 }
1340
1341
1342 /**
1343 Check whether the unicode represents a line break or not.
1344
1345 This is a internal function.
1346
1347 @param Char Unicode character
1348
1349 @retval 0 Yes, it is a line break.
1350 @retval 1 Yes, it is a hyphen that desires a line break
1351 after this character.
1352 @retval 2 Yes, it is a dash that desires a line break
1353 before and after it.
1354 @retval -1 No, it is not a link break.
1355
1356 **/
1357 INT8
1358 IsLineBreak (
1359 IN CHAR16 Char
1360 )
1361 {
1362 UINT8 Byte1;
1363 UINT8 Byte2;
1364
1365 //
1366 // In little endian, Byte1 is the low byte of Char, Byte2 is the high byte of Char.
1367 //
1368 Byte1 = *((UINT8 *) (&Char));
1369 Byte2 = *(((UINT8 *) (&Char) + 1));
1370
1371 if (Byte2 == 0x20) {
1372 switch (Byte1) {
1373 case 0x00:
1374 case 0x01:
1375 case 0x02:
1376 case 0x03:
1377 case 0x04:
1378 case 0x05:
1379 case 0x06:
1380 case 0x08:
1381 case 0x09:
1382 case 0x0A:
1383 case 0x0B:
1384 case 0x28:
1385 case 0x29:
1386 case 0x5F:
1387 return 0;
1388 case 0x10:
1389 case 0x12:
1390 case 0x13:
1391 return 1;
1392 case 0x14:
1393 //
1394 // BUGBUG: Does it really require line break before it and after it?
1395 //
1396 return 2;
1397 }
1398 } else if (Byte2 == 0x00) {
1399 switch (Byte1) {
1400 case 0x20:
1401 case 0x0C:
1402 case 0x0D:
1403 return 0;
1404 }
1405 }
1406
1407 switch (Char) {
1408 case 0x1680:
1409 return 0;
1410 case 0x058A:
1411 case 0x0F0B:
1412 case 0x1361:
1413 case 0x17D5:
1414 return 1;
1415 }
1416
1417 return -1;
1418 }
1419
1420
1421 /**
1422 Renders a string to a bitmap or to the display.
1423
1424 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
1425 @param Flags Describes how the string is to be drawn.
1426 @param String Points to the null-terminated string to be
1427 displayed.
1428 @param StringInfo Points to the string output information,
1429 including the color and font. If NULL, then the
1430 string will be output in the default system font
1431 and color.
1432 @param Blt If this points to a non-NULL on entry, this
1433 points to the image, which is Width pixels wide
1434 and Height pixels high. The string will be drawn
1435 onto this image and
1436 EFI_HII_OUT_FLAG_CLIP is implied. If this points
1437 to a NULL on entry, then a buffer
1438 will be allocated to hold the generated image and
1439 the pointer updated on exit. It is the caller's
1440 responsibility to free this buffer.
1441 @param BltX Specifies the offset from the left and top edge
1442 of the image of the first character cell in the
1443 image.
1444 @param BltY Specifies the offset from the left and top edge
1445 of the image of the first character cell in the
1446 image.
1447 @param RowInfoArray If this is non-NULL on entry, then on exit, this
1448 will point to an allocated buffer containing
1449 row information and RowInfoArraySize will be
1450 updated to contain the number of elements.
1451 This array describes the characters which were at
1452 least partially drawn and the heights of the
1453 rows. It is the caller's responsibility to free
1454 this buffer.
1455 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
1456 contains the number of elements in RowInfoArray.
1457 @param ColumnInfoArray If this is non-NULL, then on return it will be
1458 filled with the horizontal offset for each
1459 character in the string on the row where it is
1460 displayed. Non-printing characters will have
1461 the offset ~0. The caller is responsible to
1462 allocate a buffer large enough so that there
1463 is one entry for each character in the string,
1464 not including the null-terminator. It is possible
1465 when character display is normalized that some
1466 character cells overlap.
1467
1468 @retval EFI_SUCCESS The string was successfully rendered.
1469 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
1470 RowInfoArray or Blt.
1471 @retval EFI_INVALID_PARAMETER The String or Blt was NULL.
1472 @retval EFI_INVALID_PARAMETER Flags were invalid combination..
1473
1474 **/
1475 EFI_STATUS
1476 EFIAPI
1477 HiiStringToImage (
1478 IN CONST EFI_HII_FONT_PROTOCOL *This,
1479 IN EFI_HII_OUT_FLAGS Flags,
1480 IN CONST EFI_STRING String,
1481 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
1482 IN OUT EFI_IMAGE_OUTPUT **Blt,
1483 IN UINTN BltX,
1484 IN UINTN BltY,
1485 OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
1486 OUT UINTN *RowInfoArraySize OPTIONAL,
1487 OUT UINTN *ColumnInfoArray OPTIONAL
1488 )
1489 {
1490 EFI_STATUS Status;
1491 HII_DATABASE_PRIVATE_DATA *Private;
1492 UINT8 **GlyphBuf;
1493 EFI_HII_GLYPH_INFO *Cell;
1494 UINT8 *Attributes;
1495 EFI_IMAGE_OUTPUT *Image;
1496 EFI_STRING StringPtr;
1497 EFI_STRING StringTmp;
1498 EFI_HII_ROW_INFO *RowInfo;
1499 UINTN LineWidth;
1500 UINTN LineHeight;
1501 UINTN BaseLineOffset;
1502 UINT16 MaxRowNum;
1503 UINT16 RowIndex;
1504 UINTN Index;
1505 UINTN Index1;
1506 EFI_FONT_DISPLAY_INFO *StringInfoOut;
1507 EFI_FONT_DISPLAY_INFO *SystemDefault;
1508 EFI_FONT_HANDLE FontHandle;
1509 EFI_STRING StringIn;
1510 EFI_STRING StringIn2;
1511 UINT16 Height;
1512 EFI_FONT_INFO *FontInfo;
1513 BOOLEAN SysFontFlag;
1514 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
1515 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
1516 BOOLEAN Transparent;
1517 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
1518 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BufferPtr;
1519 UINTN RowInfoSize;
1520 BOOLEAN LineBreak;
1521
1522 //
1523 // Check incoming parameters.
1524 //
1525
1526 if (This == NULL || String == NULL || Blt == NULL) {
1527 return EFI_INVALID_PARAMETER;
1528 }
1529 if (*Blt == NULL) {
1530 //
1531 // These two flag cannot be used if Blt is NULL upon entry.
1532 //
1533 if ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT) {
1534 return EFI_INVALID_PARAMETER;
1535 }
1536 if ((Flags & EFI_HII_OUT_FLAG_CLIP) == EFI_HII_OUT_FLAG_CLIP) {
1537 return EFI_INVALID_PARAMETER;
1538 }
1539 }
1540 //
1541 // These two flags require that EFI_HII_OUT_FLAG_CLIP be also set.
1542 //
1543 if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_X) {
1544 return EFI_INVALID_PARAMETER;
1545 }
1546 if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {
1547 return EFI_INVALID_PARAMETER;
1548 }
1549 //
1550 // This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X.
1551 //
1552 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)) {
1553 return EFI_INVALID_PARAMETER;
1554 }
1555
1556 GlyphBuf = (UINT8 **) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (UINT8 *));
1557 ASSERT (GlyphBuf != NULL);
1558 Cell = (EFI_HII_GLYPH_INFO *) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (EFI_HII_GLYPH_INFO));
1559 ASSERT (Cell != NULL);
1560 Attributes = (UINT8 *) AllocateZeroPool (MAX_STRING_LENGTH * sizeof (UINT8));
1561 ASSERT (Attributes != NULL);
1562
1563 RowInfo = NULL;
1564 Status = EFI_SUCCESS;
1565 StringIn2 = NULL;
1566 SystemDefault = NULL;
1567
1568 //
1569 // Calculate the string output information, including specified color and font .
1570 // If StringInfo does not points to system font info, it must indicate an existing
1571 // EFI_FONT_INFO.
1572 //
1573 StringInfoOut = NULL;
1574 FontHandle = NULL;
1575 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1576 SysFontFlag = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
1577
1578 if (SysFontFlag) {
1579 FontInfo = NULL;
1580 Height = SystemDefault->FontInfo.FontSize;
1581 Foreground = SystemDefault->ForegroundColor;
1582 Background = SystemDefault->BackgroundColor;
1583
1584 } else {
1585 Status = HiiGetFontInfo (This, &FontHandle, (EFI_FONT_DISPLAY_INFO *) StringInfo, &StringInfoOut, NULL);
1586 if (Status == EFI_NOT_FOUND) {
1587 //
1588 // The specified EFI_FONT_DISPLAY_INFO does not exist in current database.
1589 // Use the system font instead. Still use the color specified by StringInfo.
1590 //
1591 SysFontFlag = TRUE;
1592 FontInfo = NULL;
1593 Height = SystemDefault->FontInfo.FontSize;
1594 Foreground = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->ForegroundColor;
1595 Background = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->BackgroundColor;
1596
1597 } else {
1598 FontInfo = &StringInfoOut->FontInfo;
1599 Height = StringInfoOut->FontInfo.FontSize;
1600 Foreground = StringInfoOut->ForegroundColor;
1601 Background = StringInfoOut->BackgroundColor;
1602 }
1603 }
1604
1605 //
1606 // Parse the string to be displayed to drop some ignored characters.
1607 //
1608
1609 StringPtr = String;
1610 StringIn = NULL;
1611
1612 //
1613 // Ignore line-break characters only. Hyphens or dash character will be displayed
1614 // without line-break opportunity.
1615 //
1616 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == EFI_HII_IGNORE_LINE_BREAK) {
1617 StringIn = AllocateZeroPool (StrSize (StringPtr));
1618 if (StringIn == NULL) {
1619 Status = EFI_OUT_OF_RESOURCES;
1620 goto Exit;
1621 }
1622 StringTmp = StringIn;
1623 while (*StringPtr != 0) {
1624 if (IsLineBreak (*StringPtr) == 0) {
1625 StringPtr++;
1626 } else {
1627 *StringTmp++ = *StringPtr++;
1628 }
1629 }
1630 *StringTmp = 0;
1631 StringPtr = StringIn;
1632 }
1633 //
1634 // If EFI_HII_IGNORE_IF_NO_GLYPH is set, then characters which have no glyphs
1635 // are not drawn. Otherwise they are replaced wth Unicode character 0xFFFD.
1636 //
1637 StringIn2 = AllocateZeroPool (StrSize (StringPtr));
1638 if (StringIn2 == NULL) {
1639 Status = EFI_OUT_OF_RESOURCES;
1640 goto Exit;
1641 }
1642 Index = 0;
1643 StringTmp = StringIn2;
1644
1645 while (*StringPtr != 0 && Index < MAX_STRING_LENGTH) {
1646 Status = GetGlyphBuffer (Private, *StringPtr, FontInfo, &GlyphBuf[Index], &Cell[Index], &Attributes[Index]);
1647 if (Status == EFI_NOT_FOUND) {
1648 if ((Flags & EFI_HII_IGNORE_IF_NO_GLYPH) == EFI_HII_IGNORE_IF_NO_GLYPH) {
1649 SafeFreePool (GlyphBuf[Index]);
1650 GlyphBuf[Index] = NULL;
1651 StringPtr++;
1652 } else {
1653 //
1654 // Unicode 0xFFFD must exist in current hii database if this flag is not set.
1655 //
1656 Status = GetGlyphBuffer (
1657 Private,
1658 REPLACE_UNKNOWN_GLYPH,
1659 FontInfo,
1660 &GlyphBuf[Index],
1661 &Cell[Index],
1662 &Attributes[Index]
1663 );
1664 if (EFI_ERROR (Status)) {
1665 Status = EFI_INVALID_PARAMETER;
1666 goto Exit;
1667 }
1668 *StringTmp++ = *StringPtr++;
1669 Index++;
1670 }
1671 } else if (EFI_ERROR (Status)) {
1672 goto Exit;
1673 } else {
1674 *StringTmp++ = *StringPtr++;
1675 Index++;
1676 }
1677 }
1678 *StringTmp = 0;
1679 StringPtr = StringIn2;
1680
1681 //
1682 // Draw the string according to the specified EFI_HII_OUT_FLAGS and Blt.
1683 // If Blt is not NULL, then EFI_HII_OUT_FLAG_CLIP is implied, render this string
1684 // to an existing image (bitmap or screen depending on flags) pointed by "*Blt".
1685 // Otherwise render this string to a new allocated image and output it.
1686 //
1687 if (*Blt != NULL) {
1688 Image = *Blt;
1689 BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX;
1690 MaxRowNum = (UINT16) (Image->Height / Height);
1691 if (Image->Height % Height != 0) {
1692 MaxRowNum++;
1693 }
1694
1695 RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO));
1696 if (RowInfo == NULL) {
1697 Status = EFI_OUT_OF_RESOURCES;
1698 goto Exit;
1699 }
1700
1701 //
1702 // Format the glyph buffer according to flags.
1703 //
1704
1705 Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE);
1706 if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {
1707 //
1708 // Don't draw at all if there is only one row and
1709 // the row's bottom-most on pixel cannot fit.
1710 //
1711 if (MaxRowNum == 1 && SysFontFlag) {
1712 Status = EFI_SUCCESS;
1713 goto Exit;
1714 }
1715 }
1716
1717 for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) {
1718 LineWidth = 0;
1719 LineHeight = 0;
1720 BaseLineOffset = 0;
1721 LineBreak = FALSE;
1722
1723 //
1724 // Calculate how many characters there are in a row.
1725 //
1726 RowInfo[RowIndex].StartIndex = Index;
1727
1728 while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) {
1729 LineWidth += (UINTN) Cell[Index].AdvanceX;
1730 if (LineHeight < Cell[Index].Height) {
1731 LineHeight = (UINTN) Cell[Index].Height;
1732 }
1733 BaseLineOffset += (UINTN) Cell[Index].OffsetY;
1734
1735 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0 &&
1736 (Flags & EFI_HII_OUT_FLAG_WRAP) == 0 &&
1737 IsLineBreak (StringPtr[Index]) > 0) {
1738 //
1739 // It is a line break that ends this row.
1740 //
1741 Index++;
1742 break;
1743 }
1744
1745 Index++;
1746 }
1747
1748 //
1749 // If this character is the last character of a row, we need not
1750 // draw its (AdvanceX - Width) for next character.
1751 //
1752 Index--;
1753 if (!SysFontFlag) {
1754 LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width);
1755 }
1756
1757 //
1758 // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break
1759 // opportunity prior to a character whose right-most extent would exceed Width.
1760 // Search the right-most line-break opportunity here.
1761 //
1762 if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP) {
1763 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {
1764 for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {
1765 if (IsLineBreak (StringPtr[Index1]) > 0) {
1766 LineBreak = TRUE;
1767 RowInfo[RowIndex].EndIndex = Index1 - 1;
1768 break;
1769 }
1770 }
1771 }
1772 //
1773 // If no line-break opportunity can be found, then the text will
1774 // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.
1775 //
1776 if (!LineBreak) {
1777 Flags &= (~ (EFI_HII_OUT_FLAGS) EFI_HII_OUT_FLAG_WRAP);
1778 Flags |= EFI_HII_OUT_FLAG_CLIP_CLEAN_X;
1779 }
1780 }
1781
1782 //
1783 // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
1784 //
1785 if (LineWidth + BltX <= Image->Width ||
1786 (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) {
1787 //
1788 // Record right-most character in RowInfo even if it is partially displayed.
1789 //
1790 RowInfo[RowIndex].EndIndex = Index;
1791 RowInfo[RowIndex].LineWidth = LineWidth;
1792 RowInfo[RowIndex].LineHeight = LineHeight;
1793 RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
1794 } else {
1795 //
1796 // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character
1797 // if its right-most on pixel cannot fit.
1798 //
1799 if (Index > 0) {
1800 RowInfo[RowIndex].EndIndex = Index - 1;
1801 RowInfo[RowIndex].LineWidth = LineWidth - Cell[Index].AdvanceX;
1802 RowInfo[RowIndex].BaselineOffset = BaseLineOffset - Cell[Index].OffsetY;
1803 if (LineHeight > Cell[Index - 1].Height) {
1804 LineHeight = Cell[Index - 1].Height;
1805 }
1806 RowInfo[RowIndex].LineHeight = LineHeight;
1807 } else {
1808 //
1809 // There is only one column and it can not be drawn so that return directly.
1810 //
1811 Status = EFI_SUCCESS;
1812 goto Exit;
1813 }
1814 }
1815
1816 //
1817 // Clip the final row if the row's bottom-most on pixel cannot fit when
1818 // EFI_HII_OUT_FLAG_CLEAN_Y is set.
1819 //
1820 if (RowIndex == MaxRowNum - 1 && Image->Height < LineHeight) {
1821 LineHeight = Image->Height;
1822 if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {
1823 //
1824 // Don't draw at all if the row's bottom-most on pixel cannot fit.
1825 //
1826 break;
1827 }
1828 }
1829
1830 //
1831 // Draw it to screen or existing bitmap depending on whether
1832 // EFI_HII_DIRECT_TO_SCREEN is set.
1833 //
1834 if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {
1835 BltBuffer = AllocateZeroPool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
1836 if (BltBuffer == NULL) {
1837 Status = EFI_OUT_OF_RESOURCES;
1838 goto Exit;
1839 }
1840 BufferPtr = BltBuffer;
1841 for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
1842 GlyphToImage (
1843 GlyphBuf[Index1],
1844 Foreground,
1845 Background,
1846 RowInfo[RowIndex].LineWidth,
1847 RowInfo[RowIndex].LineHeight,
1848 Transparent,
1849 &Cell[Index1],
1850 Attributes[Index1],
1851 &BufferPtr
1852 );
1853 if (ColumnInfoArray != NULL) {
1854 if (Index1 == RowInfo[RowIndex].StartIndex) {
1855 *ColumnInfoArray = 0;
1856 } else {
1857 *ColumnInfoArray = Cell[Index1 -1].AdvanceX;
1858 }
1859 ColumnInfoArray++;
1860 }
1861 }
1862 Status = Image->Image.Screen->Blt (
1863 Image->Image.Screen,
1864 BltBuffer,
1865 EfiBltBufferToVideo,
1866 0,
1867 0,
1868 BltX,
1869 BltY,
1870 RowInfo[RowIndex].LineWidth,
1871 RowInfo[RowIndex].LineHeight,
1872 0
1873 );
1874 if (EFI_ERROR (Status)) {
1875 SafeFreePool (BltBuffer);
1876 goto Exit;
1877 }
1878
1879 SafeFreePool (BltBuffer);
1880
1881 } else {
1882 for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
1883 GlyphToImage (
1884 GlyphBuf[Index1],
1885 Foreground,
1886 Background,
1887 Image->Width,
1888 Image->Height,
1889 Transparent,
1890 &Cell[Index1],
1891 Attributes[Index1],
1892 &BufferPtr
1893 );
1894 if (ColumnInfoArray != NULL) {
1895 if (Index1 == RowInfo[RowIndex].StartIndex) {
1896 *ColumnInfoArray = 0;
1897 } else {
1898 *ColumnInfoArray = Cell[Index1 -1].AdvanceX;
1899 }
1900 ColumnInfoArray++;
1901 }
1902 }
1903 //
1904 // Jump to next row
1905 //
1906 BufferPtr += BltX + Image->Width * (LineHeight - 1);
1907 }
1908
1909 Index++;
1910 RowIndex++;
1911
1912 }
1913
1914 //
1915 // Write output parameters.
1916 //
1917 RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO);
1918 if (RowInfoArray != NULL) {
1919 *RowInfoArray = AllocateZeroPool (RowInfoSize);
1920 if (*RowInfoArray == NULL) {
1921 Status = EFI_OUT_OF_RESOURCES;
1922 goto Exit;
1923 }
1924 CopyMem (*RowInfoArray, RowInfo, RowInfoSize);
1925 }
1926 if (RowInfoArraySize != NULL) {
1927 *RowInfoArraySize = RowIndex;
1928 }
1929
1930 } else {
1931 //
1932 // Create a new bitmap and draw the string onto this image.
1933 //
1934 Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
1935 if (Image == NULL) {
1936 return EFI_OUT_OF_RESOURCES;
1937 }
1938 Image->Width = 800;
1939 Image->Height = 600;
1940 Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height *sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
1941 if (Image->Image.Bitmap == NULL) {
1942 SafeFreePool (Image);
1943 return EFI_OUT_OF_RESOURCES;
1944 }
1945
1946 //
1947 // Other flags are not permitted when Blt is NULL.
1948 //
1949 Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK;
1950 Status = HiiStringToImage (
1951 This,
1952 Flags,
1953 String,
1954 StringInfo,
1955 &Image,
1956 BltX,
1957 BltY,
1958 RowInfoArray,
1959 RowInfoArraySize,
1960 ColumnInfoArray
1961 );
1962 if (EFI_ERROR (Status)) {
1963 return Status;
1964 }
1965
1966 *Blt = Image;
1967 }
1968
1969 Status = EFI_SUCCESS;
1970
1971 Exit:
1972
1973 for (Index = 0; Index < MAX_STRING_LENGTH; Index++) {
1974 SafeFreePool (GlyphBuf[Index]);
1975 }
1976 SafeFreePool (StringIn);
1977 SafeFreePool (StringIn2);
1978 SafeFreePool (StringInfoOut);
1979 SafeFreePool (RowInfo);
1980 SafeFreePool (SystemDefault);
1981 SafeFreePool (GlyphBuf);
1982 SafeFreePool (Cell);
1983 SafeFreePool (Attributes);
1984
1985 return Status;
1986 }
1987
1988
1989 /**
1990 Render a string to a bitmap or the screen containing the contents of the specified string.
1991
1992 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
1993 @param Flags Describes how the string is to be drawn.
1994 @param PackageList The package list in the HII database to search
1995 for the specified string.
1996 @param StringId The string's id, which is unique within
1997 PackageList.
1998 @param Language Points to the language for the retrieved string.
1999 If NULL, then the current system language is
2000 used.
2001 @param StringInfo Points to the string output information,
2002 including the color and font. If NULL, then the
2003 string will be output in the default system font
2004 and color.
2005 @param Blt If this points to a non-NULL on entry, this
2006 points to the image, which is Width pixels wide
2007 and Height pixels high. The string will be drawn
2008 onto this image and
2009 EFI_HII_OUT_FLAG_CLIP is implied. If this points
2010 to a NULL on entry, then a buffer
2011 will be allocated to hold the generated image and
2012 the pointer updated on exit. It is the caller's
2013 responsibility to free this buffer.
2014 @param BltX Specifies the offset from the left and top edge
2015 of the image of the first character cell in the
2016 image.
2017 @param BltY Specifies the offset from the left and top edge
2018 of the image of the first character cell in the
2019 image.
2020 @param RowInfoArray If this is non-NULL on entry, then on exit, this
2021 will point to an allocated buffer containing
2022 row information and RowInfoArraySize will be
2023 updated to contain the number of elements.
2024 This array describes the characters which were at
2025 least partially drawn and the heights of the
2026 rows. It is the caller's responsibility to free
2027 this buffer.
2028 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
2029 contains the number of elements in RowInfoArray.
2030 @param ColumnInfoArray If this is non-NULL, then on return it will be
2031 filled with the horizontal offset for each
2032 character in the string on the row where it is
2033 displayed. Non-printing characters will have
2034 the offset ~0. The caller is responsible to
2035 allocate a buffer large enough so that there
2036 is one entry for each character in the string,
2037 not including the null-terminator. It is possible
2038 when character display is normalized that some
2039 character cells overlap.
2040
2041 @retval EFI_SUCCESS The string was successfully rendered.
2042 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
2043 RowInfoArray or Blt.
2044 @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL.
2045 @retval EFI_INVALID_PARAMETER Flags were invalid combination.
2046 @retval EFI_NOT_FOUND The specified PackageList is not in the Database or the stringid is not
2047 in the specified PackageList.
2048
2049 **/
2050 EFI_STATUS
2051 EFIAPI
2052 HiiStringIdToImage (
2053 IN CONST EFI_HII_FONT_PROTOCOL *This,
2054 IN EFI_HII_OUT_FLAGS Flags,
2055 IN EFI_HII_HANDLE PackageList,
2056 IN EFI_STRING_ID StringId,
2057 IN CONST CHAR8* Language,
2058 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
2059 IN OUT EFI_IMAGE_OUTPUT **Blt,
2060 IN UINTN BltX,
2061 IN UINTN BltY,
2062 OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
2063 OUT UINTN *RowInfoArraySize OPTIONAL,
2064 OUT UINTN *ColumnInfoArray OPTIONAL
2065 )
2066 {
2067 EFI_STATUS Status;
2068 HII_DATABASE_PRIVATE_DATA *Private;
2069 EFI_STRING String;
2070 UINTN StringSize;
2071 UINTN FontLen;
2072 EFI_FONT_INFO *StringFontInfo;
2073 EFI_FONT_DISPLAY_INFO *NewStringInfo;
2074 CHAR8 CurrentLang[RFC_3066_ENTRY_SIZE];
2075
2076 if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {
2077 return EFI_INVALID_PARAMETER;
2078 }
2079
2080 if (!IsHiiHandleValid (PackageList)) {
2081 return EFI_NOT_FOUND;
2082 }
2083
2084 //
2085 // When Language points to NULL, current system language is used.
2086 //
2087 if (Language != NULL) {
2088 AsciiStrCpy (CurrentLang, (CHAR8 *) Language);
2089 } else {
2090 HiiLibGetCurrentLanguage (CurrentLang);
2091 }
2092
2093 //
2094 // Get the string to be displayed.
2095 //
2096
2097 StringSize = MAX_STRING_LENGTH;
2098 String = (EFI_STRING) AllocateZeroPool (StringSize);
2099 if (String == NULL) {
2100 return EFI_OUT_OF_RESOURCES;
2101 }
2102
2103 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2104 StringFontInfo = NULL;
2105 NewStringInfo = NULL;
2106
2107 Status = Private->HiiString.GetString (
2108 &Private->HiiString,
2109 CurrentLang,
2110 PackageList,
2111 StringId,
2112 String,
2113 &StringSize,
2114 &StringFontInfo
2115 );
2116 if (Status == EFI_BUFFER_TOO_SMALL) {
2117 SafeFreePool (String);
2118 String = (EFI_STRING) AllocateZeroPool (StringSize);
2119 if (String == NULL) {
2120 return EFI_OUT_OF_RESOURCES;
2121 }
2122 Status = Private->HiiString.GetString (
2123 &Private->HiiString,
2124 Language,
2125 PackageList,
2126 StringId,
2127 String,
2128 &StringSize,
2129 NULL
2130 );
2131
2132 }
2133
2134 if (EFI_ERROR (Status)) {
2135 goto Exit;
2136 }
2137
2138 //
2139 // When StringInfo specifies that string will be output in the system default font and color,
2140 // use particular stringfontinfo described in string package instead if exists.
2141 // StringFontInfo equals NULL means system default font attaches with the string block.
2142 //
2143 if (StringFontInfo != NULL && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, NULL, NULL)) {
2144 FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + StrSize (StringFontInfo->FontName);
2145 NewStringInfo = AllocateZeroPool (FontLen);
2146 if (NewStringInfo == NULL) {
2147 Status = EFI_OUT_OF_RESOURCES;
2148 goto Exit;
2149 }
2150 NewStringInfo->FontInfoMask = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR;
2151 NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle;
2152 NewStringInfo->FontInfo.FontSize = StringFontInfo->FontSize;
2153 StrCpy (NewStringInfo->FontInfo.FontName, StringFontInfo->FontName);
2154
2155 Status = HiiStringToImage (
2156 This,
2157 Flags,
2158 String,
2159 NewStringInfo,
2160 Blt,
2161 BltX,
2162 BltY,
2163 RowInfoArray,
2164 RowInfoArraySize,
2165 ColumnInfoArray
2166 );
2167 goto Exit;
2168 }
2169
2170 Status = HiiStringToImage (
2171 This,
2172 Flags,
2173 String,
2174 StringInfo,
2175 Blt,
2176 BltX,
2177 BltY,
2178 RowInfoArray,
2179 RowInfoArraySize,
2180 ColumnInfoArray
2181 );
2182
2183 Exit:
2184 SafeFreePool (String);
2185 SafeFreePool (StringFontInfo);
2186 SafeFreePool (NewStringInfo);
2187
2188 return Status;
2189 }
2190
2191
2192 /**
2193 Convert the glyph for a single character into a bitmap.
2194
2195 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2196 @param Char Character to retrieve.
2197 @param StringInfo Points to the string font and color information
2198 or NULL if the string should use the default
2199 system font and color.
2200 @param Blt Thus must point to a NULL on entry. A buffer will
2201 be allocated to hold the output and the pointer
2202 updated on exit. It is the caller's
2203 responsibility to free this buffer.
2204 @param Baseline Number of pixels from the bottom of the bitmap to
2205 the baseline.
2206
2207 @retval EFI_SUCCESS Glyph bitmap created.
2208 @retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer Blt.
2209 @retval EFI_WARN_UNKNOWN_GLYPH The glyph was unknown and was replaced with the
2210 glyph for Unicode character 0xFFFD.
2211 @retval EFI_INVALID_PARAMETER Blt is NULL or *Blt is not NULL.
2212
2213 **/
2214 EFI_STATUS
2215 EFIAPI
2216 HiiGetGlyph (
2217 IN CONST EFI_HII_FONT_PROTOCOL *This,
2218 IN CHAR16 Char,
2219 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo,
2220 OUT EFI_IMAGE_OUTPUT **Blt,
2221 OUT UINTN *Baseline OPTIONAL
2222 )
2223 {
2224 EFI_STATUS Status;
2225 HII_DATABASE_PRIVATE_DATA *Private;
2226 EFI_IMAGE_OUTPUT *Image;
2227 UINT8 *GlyphBuffer;
2228 EFI_FONT_DISPLAY_INFO *SystemDefault;
2229 EFI_FONT_DISPLAY_INFO *StringInfoOut;
2230 BOOLEAN Default;
2231 EFI_FONT_HANDLE FontHandle;
2232 EFI_STRING String;
2233 EFI_HII_GLYPH_INFO Cell;
2234 EFI_FONT_INFO *FontInfo;
2235 UINT8 Attributes;
2236 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
2237 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
2238 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
2239
2240 if (This == NULL || Blt == NULL || *Blt != NULL) {
2241 return EFI_INVALID_PARAMETER;
2242 }
2243
2244 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2245
2246 Default = FALSE;
2247 Image = NULL;
2248 SystemDefault = NULL;
2249 FontHandle = NULL;
2250 String = NULL;
2251 GlyphBuffer = NULL;
2252 StringInfoOut = NULL;
2253 FontInfo = NULL;
2254
2255 ZeroMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2256 ZeroMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2257
2258 Default = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
2259
2260 if (!Default) {
2261 //
2262 // Find out a EFI_FONT_DISPLAY_INFO which could display the character in
2263 // the specified color and font.
2264 //
2265 String = (EFI_STRING) AllocateZeroPool (sizeof (CHAR16) * 2);
2266 if (String == NULL) {
2267 Status = EFI_OUT_OF_RESOURCES;
2268 goto Exit;
2269 }
2270 *String = Char;
2271 *(String + 1) = 0;
2272
2273 Status = HiiGetFontInfo (This, &FontHandle, StringInfo, &StringInfoOut, String);
2274 if (EFI_ERROR (Status)) {
2275 goto Exit;
2276 }
2277 FontInfo = &StringInfoOut->FontInfo;
2278 Foreground = StringInfoOut->ForegroundColor;
2279 Background = StringInfoOut->BackgroundColor;
2280 } else {
2281 Foreground = SystemDefault->ForegroundColor;
2282 Background = SystemDefault->BackgroundColor;
2283 }
2284
2285 Status = GetGlyphBuffer (Private, Char, FontInfo, &GlyphBuffer, &Cell, &Attributes);
2286 if (EFI_ERROR (Status)) {
2287 goto Exit;
2288 }
2289
2290 Image = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
2291 if (Image == NULL) {
2292 Status = EFI_OUT_OF_RESOURCES;
2293 goto Exit;
2294 }
2295 Image->Width = Cell.Width;
2296 Image->Height = Cell.Height;
2297
2298 Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2299 if (Image->Image.Bitmap == NULL) {
2300 SafeFreePool (Image);
2301 Status = EFI_OUT_OF_RESOURCES;
2302 goto Exit;
2303 }
2304
2305 BltBuffer = Image->Image.Bitmap;
2306 GlyphToImage (
2307 GlyphBuffer,
2308 Foreground,
2309 Background,
2310 Image->Width,
2311 Image->Height,
2312 FALSE,
2313 &Cell,
2314 Attributes,
2315 &BltBuffer
2316 );
2317
2318 *Blt = Image;
2319 if (Baseline != NULL) {
2320 *Baseline = Cell.OffsetY;
2321 }
2322
2323 Status = EFI_SUCCESS;
2324
2325 Exit:
2326
2327 if (Status == EFI_NOT_FOUND) {
2328 //
2329 // Glyph is unknown and replaced with the glyph for unicode character 0xFFFD
2330 //
2331 if (Char != REPLACE_UNKNOWN_GLYPH) {
2332 Status = HiiGetGlyph (This, REPLACE_UNKNOWN_GLYPH, StringInfo, Blt, Baseline);
2333 if (!EFI_ERROR (Status)) {
2334 Status = EFI_WARN_UNKNOWN_GLYPH;
2335 }
2336 } else {
2337 Status = EFI_WARN_UNKNOWN_GLYPH;
2338 }
2339 }
2340
2341 SafeFreePool (SystemDefault);
2342 SafeFreePool (StringInfoOut);
2343 SafeFreePool (String);
2344 SafeFreePool (GlyphBuffer);
2345
2346 return Status;
2347 }
2348
2349
2350 /**
2351 This function iterates through fonts which match the specified font, using
2352 the specified criteria. If String is non-NULL, then all of the characters in
2353 the string must exist in order for a candidate font to be returned.
2354
2355 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2356 @param FontHandle On entry, points to the font handle returned by a
2357 previous call to GetFontInfo() or NULL to start
2358 with the first font. On return, points to the
2359 returned font handle or points to NULL if there
2360 are no more matching fonts.
2361 @param StringInfoIn Upon entry, points to the font to return
2362 information about.
2363 If NULL, then the information about the system default
2364 font will be returned.
2365 @param StringInfoOut Upon return, contains the matching font's
2366 information. If NULL, then no information is
2367 returned. It's caller's responsibility to free
2368 this buffer.
2369 @param String Points to the string which will be tested to
2370 determine if all characters are available. If
2371 NULL, then any font is acceptable.
2372
2373 @retval EFI_SUCCESS Matching font returned successfully.
2374 @retval EFI_NOT_FOUND No matching font was found.
2375 @retval EFI_INVALID_PARAMETER StringInfoIn->FontInfoMask is an invalid combination.
2376 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
2377 request.
2378
2379 **/
2380 EFI_STATUS
2381 EFIAPI
2382 HiiGetFontInfo (
2383 IN CONST EFI_HII_FONT_PROTOCOL *This,
2384 IN OUT EFI_FONT_HANDLE *FontHandle,
2385 IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn, OPTIONAL
2386 OUT EFI_FONT_DISPLAY_INFO **StringInfoOut,
2387 IN CONST EFI_STRING String OPTIONAL
2388 )
2389 {
2390 HII_DATABASE_PRIVATE_DATA *Private;
2391 EFI_STATUS Status;
2392 EFI_FONT_DISPLAY_INFO *SystemDefault;
2393 EFI_FONT_DISPLAY_INFO InfoOut;
2394 UINTN StringInfoOutLen;
2395 EFI_FONT_INFO *FontInfo;
2396 HII_GLOBAL_FONT_INFO *GlobalFont;
2397 EFI_STRING StringIn;
2398 EFI_FONT_HANDLE LocalFontHandle;
2399
2400 if (This == NULL) {
2401 return EFI_INVALID_PARAMETER;
2402 }
2403
2404 FontInfo = NULL;
2405 SystemDefault = NULL;
2406 LocalFontHandle = NULL;
2407 if (FontHandle != NULL) {
2408 LocalFontHandle = *FontHandle;
2409 }
2410
2411 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2412
2413 //
2414 // Already searched to the end of the whole list, return directly.
2415 //
2416 if (LocalFontHandle == &Private->FontInfoList) {
2417 LocalFontHandle = NULL;
2418 Status = EFI_NOT_FOUND;
2419 goto Exit;
2420 }
2421
2422 //
2423 // Get default system display info, if StringInfoIn points to
2424 // system display info, return it directly.
2425 //
2426 if (IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, &SystemDefault, &StringInfoOutLen)) {
2427 //
2428 // System font is the first node. When handle is not NULL, system font can not
2429 // be found any more.
2430 //
2431 if (LocalFontHandle == NULL) {
2432 if (StringInfoOut != NULL) {
2433 *StringInfoOut = AllocateCopyPool (StringInfoOutLen, SystemDefault);
2434 if (*StringInfoOut == NULL) {
2435 Status = EFI_OUT_OF_RESOURCES;
2436 LocalFontHandle = NULL;
2437 goto Exit;
2438 }
2439 }
2440
2441 LocalFontHandle = Private->FontInfoList.ForwardLink;
2442 Status = EFI_SUCCESS;
2443 goto Exit;
2444 } else {
2445 LocalFontHandle = NULL;
2446 Status = EFI_NOT_FOUND;
2447 goto Exit;
2448 }
2449 }
2450
2451 //
2452 // Check the font information mask to make sure it is valid.
2453 //
2454 if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ==
2455 (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ||
2456 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ==
2457 (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ||
2458 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ==
2459 (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ||
2460 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ==
2461 (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ||
2462 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)) ==
2463 (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) {
2464 return EFI_INVALID_PARAMETER;
2465 }
2466
2467 //
2468 // Parse the font information mask to find a matching font.
2469 //
2470
2471 CopyMem (&InfoOut, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, sizeof (EFI_FONT_DISPLAY_INFO));
2472
2473 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FONT) == EFI_FONT_INFO_SYS_FONT) {
2474 Status = SaveFontName (SystemDefault->FontInfo.FontName, &FontInfo);
2475 } else {
2476 Status = SaveFontName (((EFI_FONT_DISPLAY_INFO *) StringInfoIn)->FontInfo.FontName, &FontInfo);
2477 }
2478 if (EFI_ERROR (Status)) {
2479 goto Exit;
2480 }
2481
2482 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_SIZE) == EFI_FONT_INFO_SYS_SIZE) {
2483 InfoOut.FontInfo.FontSize = SystemDefault->FontInfo.FontSize;
2484 }
2485 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) {
2486 InfoOut.FontInfo.FontStyle = SystemDefault->FontInfo.FontStyle;
2487 }
2488 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) {
2489 InfoOut.ForegroundColor = SystemDefault->ForegroundColor;
2490 }
2491 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) {
2492 InfoOut.BackgroundColor = SystemDefault->BackgroundColor;
2493 }
2494
2495
2496 FontInfo->FontSize = InfoOut.FontInfo.FontSize;
2497 FontInfo->FontStyle = InfoOut.FontInfo.FontStyle;
2498
2499 if (IsFontInfoExisted (Private, FontInfo, &InfoOut.FontInfoMask, LocalFontHandle, &GlobalFont)) {
2500 if (String != NULL) {
2501 //
2502 // Test to guarantee all characters are available in the found font.
2503 //
2504 StringIn = String;
2505 while (*StringIn != 0) {
2506 Status = FindGlyphBlock (GlobalFont->FontPackage, *StringIn, NULL, NULL, NULL);
2507 if (EFI_ERROR (Status)) {
2508 LocalFontHandle = NULL;
2509 goto Exit;
2510 }
2511 StringIn++;
2512 }
2513
2514 //
2515 // Write to output parameter
2516 //
2517 if (StringInfoOut != NULL) {
2518 StringInfoOutLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (EFI_FONT_INFO) + GlobalFont->FontInfoSize;
2519 *StringInfoOut = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (StringInfoOutLen);
2520 if (*StringInfoOut == NULL) {
2521 Status = EFI_OUT_OF_RESOURCES;
2522 LocalFontHandle = NULL;
2523 goto Exit;
2524 }
2525 CopyMem (*StringInfoOut, &InfoOut, sizeof (EFI_FONT_DISPLAY_INFO));
2526 CopyMem (&(*StringInfoOut)->FontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);
2527 }
2528 LocalFontHandle = GlobalFont->Entry.ForwardLink;
2529
2530 Status = EFI_SUCCESS;
2531 goto Exit;
2532 }
2533 } else {
2534 LocalFontHandle = NULL;
2535 }
2536
2537 Status = EFI_NOT_FOUND;
2538
2539 Exit:
2540
2541 if (FontHandle != NULL) {
2542 *FontHandle = LocalFontHandle;
2543 }
2544
2545 SafeFreePool (SystemDefault);
2546 SafeFreePool (FontInfo);
2547 return Status;
2548 }
2549
2550