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