]> git.proxmox.com Git - mirror_edk2.git/blob - MdeModulePkg/Universal/HiiDatabaseDxe/Font.c
MdeModulePkg/HiiDatabase: Remove the incorrect calculation of font baseline
[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 }
708
709 BlockPtr = FontPackage->GlyphBlock;
710 CharCurrent = 1;
711 BufferLen = 0;
712
713 while (*BlockPtr != EFI_HII_GIBT_END) {
714 switch (*BlockPtr) {
715 case EFI_HII_GIBT_DEFAULTS:
716 //
717 // Collect all default character cell information specified by
718 // EFI_HII_GIBT_DEFAULTS.
719 //
720 if (CharValue == (CHAR16) (-1)) {
721 Status = NewCell (
722 CharCurrent,
723 &FontPackage->GlyphInfoList,
724 (EFI_HII_GLYPH_INFO *) (BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK))
725 );
726 if (EFI_ERROR (Status)) {
727 return Status;
728 }
729 CopyMem (
730 &LocalCell,
731 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
732 sizeof (EFI_HII_GLYPH_INFO)
733 );
734 if (BaseLine < LocalCell.Height + LocalCell.OffsetY) {
735 BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY);
736 }
737 if (MinOffsetY > LocalCell.OffsetY) {
738 MinOffsetY = LocalCell.OffsetY;
739 }
740 }
741 BlockPtr += sizeof (EFI_HII_GIBT_DEFAULTS_BLOCK);
742 break;
743
744 case EFI_HII_GIBT_DUPLICATE:
745 if (CharCurrent == CharValue) {
746 CopyMem (&CharValue, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (CHAR16));
747 CharCurrent = 1;
748 BlockPtr = FontPackage->GlyphBlock;
749 continue;
750 }
751 CharCurrent++;
752 BlockPtr += sizeof (EFI_HII_GIBT_DUPLICATE_BLOCK);
753 break;
754
755 case EFI_HII_GIBT_EXT1:
756 BlockPtr += *(UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8));
757 break;
758 case EFI_HII_GIBT_EXT2:
759 CopyMem (
760 &Length16,
761 (UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)),
762 sizeof (UINT16)
763 );
764 BlockPtr += Length16;
765 break;
766 case EFI_HII_GIBT_EXT4:
767 CopyMem (
768 &Length32,
769 (UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK) + sizeof (UINT8)),
770 sizeof (UINT32)
771 );
772 BlockPtr += Length32;
773 break;
774
775 case EFI_HII_GIBT_GLYPH:
776 CopyMem (
777 &LocalCell,
778 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
779 sizeof (EFI_HII_GLYPH_INFO)
780 );
781 if (CharValue == (CHAR16) (-1)) {
782 if (BaseLine < LocalCell.Height + LocalCell.OffsetY) {
783 BaseLine = (UINT16) (LocalCell.Height + LocalCell.OffsetY);
784 }
785 if (MinOffsetY > LocalCell.OffsetY) {
786 MinOffsetY = LocalCell.OffsetY;
787 }
788 }
789 BufferLen = BITMAP_LEN_1_BIT (LocalCell.Width, LocalCell.Height);
790 if (CharCurrent == CharValue) {
791 return WriteOutputParam (
792 (UINT8*)((UINTN)BlockPtr + sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8)),
793 BufferLen,
794 &LocalCell,
795 GlyphBuffer,
796 Cell,
797 GlyphBufferLen
798 );
799 }
800 CharCurrent++;
801 BlockPtr += sizeof (EFI_HII_GIBT_GLYPH_BLOCK) - sizeof (UINT8) + BufferLen;
802 break;
803
804 case EFI_HII_GIBT_GLYPHS:
805 BlockPtr += sizeof (EFI_HII_GLYPH_BLOCK);
806 CopyMem (&Glyphs.Cell, BlockPtr, sizeof (EFI_HII_GLYPH_INFO));
807 BlockPtr += sizeof (EFI_HII_GLYPH_INFO);
808 CopyMem (&Glyphs.Count, BlockPtr, sizeof (UINT16));
809 BlockPtr += sizeof (UINT16);
810
811 if (CharValue == (CHAR16) (-1)) {
812 if (BaseLine < Glyphs.Cell.Height + Glyphs.Cell.OffsetY) {
813 BaseLine = (UINT16) (Glyphs.Cell.Height + Glyphs.Cell.OffsetY);
814 }
815 if (MinOffsetY > Glyphs.Cell.OffsetY) {
816 MinOffsetY = Glyphs.Cell.OffsetY;
817 }
818 }
819
820 BufferLen = BITMAP_LEN_1_BIT (Glyphs.Cell.Width, Glyphs.Cell.Height);
821 for (Index = 0; Index < Glyphs.Count; Index++) {
822 if (CharCurrent + Index == CharValue) {
823 return WriteOutputParam (
824 BlockPtr,
825 BufferLen,
826 &Glyphs.Cell,
827 GlyphBuffer,
828 Cell,
829 GlyphBufferLen
830 );
831 }
832 BlockPtr += BufferLen;
833 }
834 CharCurrent = (UINT16) (CharCurrent + Glyphs.Count);
835 break;
836
837 case EFI_HII_GIBT_GLYPH_DEFAULT:
838 Status = GetCell (CharCurrent, &FontPackage->GlyphInfoList, &DefaultCell);
839 if (EFI_ERROR (Status)) {
840 return Status;
841 }
842 BufferLen = BITMAP_LEN_1_BIT (DefaultCell.Width, DefaultCell.Height);
843
844 if (CharCurrent == CharValue) {
845 return WriteOutputParam (
846 BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK),
847 BufferLen,
848 &DefaultCell,
849 GlyphBuffer,
850 Cell,
851 GlyphBufferLen
852 );
853 }
854 CharCurrent++;
855 BlockPtr += sizeof (EFI_HII_GLYPH_BLOCK) + BufferLen;
856 break;
857
858 case EFI_HII_GIBT_GLYPHS_DEFAULT:
859 CopyMem (&Length16, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (UINT16));
860 Status = GetCell (CharCurrent, &FontPackage->GlyphInfoList, &DefaultCell);
861 if (EFI_ERROR (Status)) {
862 return Status;
863 }
864 BufferLen = BITMAP_LEN_1_BIT (DefaultCell.Width, DefaultCell.Height);
865 BlockPtr += sizeof (EFI_HII_GIBT_GLYPHS_DEFAULT_BLOCK) - sizeof (UINT8);
866 for (Index = 0; Index < Length16; Index++) {
867 if (CharCurrent + Index == CharValue) {
868 return WriteOutputParam (
869 BlockPtr,
870 BufferLen,
871 &DefaultCell,
872 GlyphBuffer,
873 Cell,
874 GlyphBufferLen
875 );
876 }
877 BlockPtr += BufferLen;
878 }
879 CharCurrent = (UINT16) (CharCurrent + Length16);
880 break;
881
882 case EFI_HII_GIBT_SKIP1:
883 CharCurrent = (UINT16) (CharCurrent + (UINT16) (*(BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK))));
884 BlockPtr += sizeof (EFI_HII_GIBT_SKIP1_BLOCK);
885 break;
886 case EFI_HII_GIBT_SKIP2:
887 CopyMem (&Length16, BlockPtr + sizeof (EFI_HII_GLYPH_BLOCK), sizeof (UINT16));
888 CharCurrent = (UINT16) (CharCurrent + Length16);
889 BlockPtr += sizeof (EFI_HII_GIBT_SKIP2_BLOCK);
890 break;
891 default:
892 ASSERT (FALSE);
893 break;
894 }
895
896 if (CharValue < CharCurrent) {
897 return EFI_NOT_FOUND;
898 }
899 }
900
901 if (CharValue == (CHAR16) (-1)) {
902 FontPackage->BaseLine = BaseLine;
903 FontPackage->Height = (UINT16) (BaseLine - MinOffsetY);
904 return EFI_SUCCESS;
905 }
906
907 return EFI_NOT_FOUND;
908 }
909
910
911 /**
912 Copy a Font Name to a new created EFI_FONT_INFO structure.
913
914 This is a internal function.
915
916 @param FontName NULL-terminated string.
917 @param FontInfo a new EFI_FONT_INFO which stores the FontName.
918 It's caller's responsibility to free this buffer.
919
920 @retval EFI_SUCCESS FontInfo is allocated and copied with FontName.
921 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
922 task.
923
924 **/
925 EFI_STATUS
926 SaveFontName (
927 IN EFI_STRING FontName,
928 OUT EFI_FONT_INFO **FontInfo
929 )
930 {
931 UINTN FontInfoLen;
932 UINTN NameSize;
933
934 ASSERT (FontName != NULL && FontInfo != NULL);
935
936 NameSize = StrSize (FontName);
937 FontInfoLen = sizeof (EFI_FONT_INFO) - sizeof (CHAR16) + NameSize;
938 *FontInfo = (EFI_FONT_INFO *) AllocateZeroPool (FontInfoLen);
939 if (*FontInfo == NULL) {
940 return EFI_OUT_OF_RESOURCES;
941 }
942
943 StrCpyS ((*FontInfo)->FontName, NameSize / sizeof (CHAR16), FontName);
944 return EFI_SUCCESS;
945 }
946
947
948 /**
949 Retrieve system default font and color.
950
951 @param Private HII database driver private data.
952 @param FontInfo Points to system default font output-related
953 information. It's caller's responsibility to free
954 this buffer.
955 @param FontInfoSize If not NULL, output the size of buffer FontInfo.
956
957 @retval EFI_SUCCESS Cell information is added to the GlyphInfoList.
958 @retval EFI_OUT_OF_RESOURCES The system is out of resources to accomplish the
959 task.
960 @retval EFI_INVALID_PARAMETER Any input parameter is invalid.
961
962 **/
963 EFI_STATUS
964 GetSystemFont (
965 IN HII_DATABASE_PRIVATE_DATA *Private,
966 OUT EFI_FONT_DISPLAY_INFO **FontInfo,
967 OUT UINTN *FontInfoSize OPTIONAL
968 )
969 {
970 EFI_FONT_DISPLAY_INFO *Info;
971 UINTN InfoSize;
972 UINTN NameSize;
973
974 if (Private == NULL || Private->Signature != HII_DATABASE_PRIVATE_DATA_SIGNATURE) {
975 return EFI_INVALID_PARAMETER;
976 }
977 if (FontInfo == NULL) {
978 return EFI_INVALID_PARAMETER;
979 }
980
981 //
982 // The standard font always has the name "sysdefault".
983 //
984 NameSize = StrSize (L"sysdefault");
985 InfoSize = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize;
986 Info = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (InfoSize);
987 if (Info == NULL) {
988 return EFI_OUT_OF_RESOURCES;
989 }
990
991 Info->ForegroundColor = mHiiEfiColors[Private->Attribute & 0x0f];
992 Info->BackgroundColor = mHiiEfiColors[Private->Attribute >> 4];
993 Info->FontInfoMask = EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_SYS_STYLE;
994 Info->FontInfo.FontStyle = 0;
995 Info->FontInfo.FontSize = EFI_GLYPH_HEIGHT;
996 StrCpyS (Info->FontInfo.FontName, NameSize / sizeof (CHAR16), L"sysdefault");
997
998 *FontInfo = Info;
999 if (FontInfoSize != NULL) {
1000 *FontInfoSize = InfoSize;
1001 }
1002 return EFI_SUCCESS;
1003 }
1004
1005
1006 /**
1007 Check whether EFI_FONT_DISPLAY_INFO points to system default font and color or
1008 returns the system default according to the optional inputs.
1009
1010 This is a internal function.
1011
1012 @param Private HII database driver private data.
1013 @param StringInfo Points to the string output information,
1014 including the color and font.
1015 @param SystemInfo If not NULL, points to system default font and color.
1016
1017 @param SystemInfoLen If not NULL, output the length of default system
1018 info.
1019
1020 @retval TRUE Yes, it points to system default.
1021 @retval FALSE No.
1022
1023 **/
1024 BOOLEAN
1025 IsSystemFontInfo (
1026 IN HII_DATABASE_PRIVATE_DATA *Private,
1027 IN EFI_FONT_DISPLAY_INFO *StringInfo,
1028 OUT EFI_FONT_DISPLAY_INFO **SystemInfo, OPTIONAL
1029 OUT UINTN *SystemInfoLen OPTIONAL
1030 )
1031 {
1032 EFI_STATUS Status;
1033 EFI_FONT_DISPLAY_INFO *SystemDefault;
1034 UINTN DefaultLen;
1035 BOOLEAN Flag;
1036
1037 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
1038
1039 if (StringInfo == NULL && SystemInfo == NULL) {
1040 return TRUE;
1041 }
1042
1043 SystemDefault = NULL;
1044 DefaultLen = 0;
1045
1046 Status = GetSystemFont (Private, &SystemDefault, &DefaultLen);
1047 ASSERT_EFI_ERROR (Status);
1048 ASSERT ((SystemDefault != NULL) && (DefaultLen != 0));
1049
1050 //
1051 // Record the system default info.
1052 //
1053 if (SystemInfo != NULL) {
1054 *SystemInfo = SystemDefault;
1055 }
1056
1057 if (SystemInfoLen != NULL) {
1058 *SystemInfoLen = DefaultLen;
1059 }
1060
1061 if (StringInfo == NULL) {
1062 return TRUE;
1063 }
1064
1065 Flag = FALSE;
1066 //
1067 // Check the FontInfoMask to see whether it is retrieving system info.
1068 //
1069 if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) == 0) {
1070 if (StrCmp (StringInfo->FontInfo.FontName, SystemDefault->FontInfo.FontName) != 0) {
1071 goto Exit;
1072 }
1073 }
1074 if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) == 0) {
1075 if (StringInfo->FontInfo.FontSize != SystemDefault->FontInfo.FontSize) {
1076 goto Exit;
1077 }
1078 }
1079 if ((StringInfo->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) == 0) {
1080 if (StringInfo->FontInfo.FontStyle != SystemDefault->FontInfo.FontStyle) {
1081 goto Exit;
1082 }
1083 }
1084 if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == 0) {
1085 if (CompareMem (
1086 &StringInfo->ForegroundColor,
1087 &SystemDefault->ForegroundColor,
1088 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1089 ) != 0) {
1090 goto Exit;
1091 }
1092 }
1093 if ((StringInfo->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == 0) {
1094 if (CompareMem (
1095 &StringInfo->BackgroundColor,
1096 &SystemDefault->BackgroundColor,
1097 sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)
1098 ) != 0) {
1099 goto Exit;
1100 }
1101 }
1102
1103 Flag = TRUE;
1104
1105 Exit:
1106 if (SystemInfo == NULL) {
1107 if (SystemDefault != NULL) {
1108 FreePool (SystemDefault);
1109 }
1110 }
1111 return Flag;
1112 }
1113
1114
1115 /**
1116 This function checks whether EFI_FONT_INFO exists in current database. If
1117 FontInfoMask is specified, check what options can be used to make a match.
1118 Note that the masks relate to where the system default should be supplied
1119 are ignored by this function.
1120
1121 @param Private Hii database private structure.
1122 @param FontInfo Points to EFI_FONT_INFO structure.
1123 @param FontInfoMask If not NULL, describes what options can be used
1124 to make a match between the font requested and
1125 the font available. The caller must guarantee
1126 this mask is valid.
1127 @param FontHandle On entry, Points to the font handle returned by a
1128 previous call to GetFontInfo() or NULL to start
1129 with the first font.
1130 @param GlobalFontInfo If not NULL, output the corresponding globa font
1131 info.
1132
1133 @retval TRUE Existed
1134 @retval FALSE Not existed
1135
1136 **/
1137 BOOLEAN
1138 IsFontInfoExisted (
1139 IN HII_DATABASE_PRIVATE_DATA *Private,
1140 IN EFI_FONT_INFO *FontInfo,
1141 IN EFI_FONT_INFO_MASK *FontInfoMask, OPTIONAL
1142 IN EFI_FONT_HANDLE FontHandle, OPTIONAL
1143 OUT HII_GLOBAL_FONT_INFO **GlobalFontInfo OPTIONAL
1144 )
1145 {
1146 HII_GLOBAL_FONT_INFO *GlobalFont;
1147 HII_GLOBAL_FONT_INFO *GlobalFontBackup1;
1148 HII_GLOBAL_FONT_INFO *GlobalFontBackup2;
1149 LIST_ENTRY *Link;
1150 EFI_FONT_INFO_MASK Mask;
1151 BOOLEAN Matched;
1152 BOOLEAN VagueMatched1;
1153 BOOLEAN VagueMatched2;
1154
1155 ASSERT (Private != NULL && Private->Signature == HII_DATABASE_PRIVATE_DATA_SIGNATURE);
1156 ASSERT (FontInfo != NULL);
1157
1158 //
1159 // Matched flag represents an exactly match; VagueMatched1 repensents a RESIZE
1160 // or RESTYLE match; VagueMatched2 represents a RESIZE | RESTYLE match.
1161 //
1162 Matched = FALSE;
1163 VagueMatched1 = FALSE;
1164 VagueMatched2 = FALSE;
1165
1166 Mask = 0;
1167 GlobalFontBackup1 = NULL;
1168 GlobalFontBackup2 = NULL;
1169
1170 // The process of where the system default should be supplied instead of
1171 // the specified font info beyonds this function's scope.
1172 //
1173 if (FontInfoMask != NULL) {
1174 Mask = *FontInfoMask & (~SYS_FONT_INFO_MASK);
1175 }
1176
1177 //
1178 // If not NULL, FontHandle points to the next node of the last searched font
1179 // node by previous call.
1180 //
1181 if (FontHandle == NULL) {
1182 Link = Private->FontInfoList.ForwardLink;
1183 } else {
1184 Link = (LIST_ENTRY *) FontHandle;
1185 }
1186
1187 for (; Link != &Private->FontInfoList; Link = Link->ForwardLink) {
1188 GlobalFont = CR (Link, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);
1189 if (FontInfoMask == NULL) {
1190 if (CompareMem (GlobalFont->FontInfo, FontInfo, GlobalFont->FontInfoSize) == 0) {
1191 if (GlobalFontInfo != NULL) {
1192 *GlobalFontInfo = GlobalFont;
1193 }
1194 return TRUE;
1195 }
1196 } else {
1197 //
1198 // Check which options could be used to make a match.
1199 //
1200 switch (Mask) {
1201 case EFI_FONT_INFO_ANY_FONT:
1202 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle &&
1203 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1204 Matched = TRUE;
1205 }
1206 break;
1207 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE:
1208 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1209 Matched = TRUE;
1210 }
1211 break;
1212 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE:
1213 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1214 Matched = TRUE;
1215 }
1216 break;
1217 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_ANY_STYLE:
1218 Matched = TRUE;
1219 break;
1220 //
1221 // If EFI_FONT_INFO_RESTYLE is specified, then the system may attempt to
1222 // remove some of the specified styles to meet the style requested.
1223 //
1224 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESTYLE:
1225 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1226 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1227 Matched = TRUE;
1228 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1229 VagueMatched1 = TRUE;
1230 GlobalFontBackup1 = GlobalFont;
1231 }
1232 }
1233 break;
1234 //
1235 // If EFI_FONT_INFO_RESIZE is specified, then the sytem may attempt to
1236 // stretch or shrink a font to meet the size requested.
1237 //
1238 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESIZE:
1239 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1240 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1241 Matched = TRUE;
1242 } else {
1243 VagueMatched1 = TRUE;
1244 GlobalFontBackup1 = GlobalFont;
1245 }
1246 }
1247 break;
1248 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_RESIZE:
1249 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1250 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1251 Matched = TRUE;
1252 } else {
1253 VagueMatched1 = TRUE;
1254 GlobalFontBackup1 = GlobalFont;
1255 }
1256 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1257 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1258 VagueMatched1 = TRUE;
1259 GlobalFontBackup1 = GlobalFont;
1260 } else {
1261 VagueMatched2 = TRUE;
1262 GlobalFontBackup2 = GlobalFont;
1263 }
1264 }
1265 break;
1266 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
1267 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1268 Matched = TRUE;
1269 } else {
1270 VagueMatched1 = TRUE;
1271 GlobalFontBackup1 = GlobalFont;
1272 }
1273 break;
1274 case EFI_FONT_INFO_ANY_FONT | EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
1275 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1276 Matched = TRUE;
1277 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1278 VagueMatched1 = TRUE;
1279 GlobalFontBackup1 = GlobalFont;
1280 }
1281 break;
1282 case EFI_FONT_INFO_ANY_STYLE:
1283 if ((CompareMem (
1284 GlobalFont->FontInfo->FontName,
1285 FontInfo->FontName,
1286 StrSize (FontInfo->FontName)
1287 ) == 0) &&
1288 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1289 Matched = TRUE;
1290 }
1291 break;
1292 case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_ANY_SIZE:
1293 if (CompareMem (
1294 GlobalFont->FontInfo->FontName,
1295 FontInfo->FontName,
1296 StrSize (FontInfo->FontName)
1297 ) == 0) {
1298 Matched = TRUE;
1299 }
1300 break;
1301 case EFI_FONT_INFO_ANY_STYLE | EFI_FONT_INFO_RESIZE:
1302 if (CompareMem (
1303 GlobalFont->FontInfo->FontName,
1304 FontInfo->FontName,
1305 StrSize (FontInfo->FontName)
1306 ) == 0) {
1307 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1308 Matched = TRUE;
1309 } else {
1310 VagueMatched1 = TRUE;
1311 GlobalFontBackup1 = GlobalFont;
1312 }
1313 }
1314 break;
1315 case EFI_FONT_INFO_ANY_SIZE:
1316 if ((CompareMem (
1317 GlobalFont->FontInfo->FontName,
1318 FontInfo->FontName,
1319 StrSize (FontInfo->FontName)
1320 ) == 0) &&
1321 GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1322 Matched = TRUE;
1323 }
1324 break;
1325 case EFI_FONT_INFO_ANY_SIZE | EFI_FONT_INFO_RESTYLE:
1326 if (CompareMem (
1327 GlobalFont->FontInfo->FontName,
1328 FontInfo->FontName,
1329 StrSize (FontInfo->FontName)
1330 ) == 0) {
1331 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1332 Matched = TRUE;
1333 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1334 VagueMatched1 = TRUE;
1335 GlobalFontBackup1 = GlobalFont;
1336 }
1337 }
1338 break;
1339 case EFI_FONT_INFO_RESTYLE:
1340 if ((CompareMem (
1341 GlobalFont->FontInfo->FontName,
1342 FontInfo->FontName,
1343 StrSize (FontInfo->FontName)
1344 ) == 0) &&
1345 GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1346
1347 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1348 Matched = TRUE;
1349 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1350 VagueMatched1 = TRUE;
1351 GlobalFontBackup1 = GlobalFont;
1352 }
1353 }
1354 break;
1355 case EFI_FONT_INFO_RESIZE:
1356 if ((CompareMem (
1357 GlobalFont->FontInfo->FontName,
1358 FontInfo->FontName,
1359 StrSize (FontInfo->FontName)
1360 ) == 0) &&
1361 GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1362
1363 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1364 Matched = TRUE;
1365 } else {
1366 VagueMatched1 = TRUE;
1367 GlobalFontBackup1 = GlobalFont;
1368 }
1369 }
1370 break;
1371 case EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_RESTYLE:
1372 if (CompareMem (
1373 GlobalFont->FontInfo->FontName,
1374 FontInfo->FontName,
1375 StrSize (FontInfo->FontName)
1376 ) == 0) {
1377 if (GlobalFont->FontInfo->FontStyle == FontInfo->FontStyle) {
1378 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1379 Matched = TRUE;
1380 } else {
1381 VagueMatched1 = TRUE;
1382 GlobalFontBackup1 = GlobalFont;
1383 }
1384 } else if ((GlobalFont->FontInfo->FontStyle & FontInfo->FontStyle) == FontInfo->FontStyle) {
1385 if (GlobalFont->FontInfo->FontSize == FontInfo->FontSize) {
1386 VagueMatched1 = TRUE;
1387 GlobalFontBackup1 = GlobalFont;
1388 } else {
1389 VagueMatched2 = TRUE;
1390 GlobalFontBackup2 = GlobalFont;
1391 }
1392 }
1393 }
1394 break;
1395 default:
1396 break;
1397 }
1398
1399 if (Matched) {
1400 if (GlobalFontInfo != NULL) {
1401 *GlobalFontInfo = GlobalFont;
1402 }
1403 return TRUE;
1404 }
1405 }
1406 }
1407
1408 if (VagueMatched1) {
1409 if (GlobalFontInfo != NULL) {
1410 *GlobalFontInfo = GlobalFontBackup1;
1411 }
1412 return TRUE;
1413 } else if (VagueMatched2) {
1414 if (GlobalFontInfo != NULL) {
1415 *GlobalFontInfo = GlobalFontBackup2;
1416 }
1417 return TRUE;
1418 }
1419
1420 return FALSE;
1421 }
1422
1423
1424 /**
1425 Check whether the unicode represents a line break or not.
1426
1427 This is a internal function. Please see Section 27.2.6 of the UEFI Specification
1428 for a description of the supported string format.
1429
1430 @param Char Unicode character
1431
1432 @retval 0 Yes, it forces a line break.
1433 @retval 1 Yes, it presents a line break opportunity
1434 @retval 2 Yes, it requires a line break happen before and after it.
1435 @retval -1 No, it is not a link break.
1436
1437 **/
1438 INT8
1439 IsLineBreak (
1440 IN CHAR16 Char
1441 )
1442 {
1443 switch (Char) {
1444 //
1445 // Mandatory line break characters, which force a line-break
1446 //
1447 case 0x000A:
1448 case 0x000C:
1449 case 0x000D:
1450 case 0x2028:
1451 case 0x2029:
1452 return 0;
1453 //
1454 // Space characters, which is taken as a line-break opportunity
1455 //
1456 case 0x0020:
1457 case 0x1680:
1458 case 0x2000:
1459 case 0x2001:
1460 case 0x2002:
1461 case 0x2003:
1462 case 0x2004:
1463 case 0x2005:
1464 case 0x2006:
1465 case 0x2008:
1466 case 0x2009:
1467 case 0x200A:
1468 case 0x205F:
1469 //
1470 // In-Word Break Opportunities
1471 //
1472 case 0x200B:
1473 return 1;
1474 //
1475 // A space which is not a line-break opportunity
1476 //
1477 case 0x00A0:
1478 case 0x202F:
1479 //
1480 // A hyphen which is not a line-break opportunity
1481 //
1482 case 0x2011:
1483 return -1;
1484 //
1485 // Hyphen characters which describe line break opportunities after the character
1486 //
1487 case 0x058A:
1488 case 0x2010:
1489 case 0x2012:
1490 case 0x2013:
1491 case 0x0F0B:
1492 case 0x1361:
1493 case 0x17D5:
1494 return 1;
1495 //
1496 // A hyphen which describes line break opportunities before and after them, but not between a pair of them
1497 //
1498 case 0x2014:
1499 return 2;
1500 }
1501 return -1;
1502 }
1503
1504
1505 /**
1506 Renders a string to a bitmap or to the display.
1507
1508 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
1509 @param Flags Describes how the string is to be drawn.
1510 @param String Points to the null-terminated string to be
1511 displayed.
1512 @param StringInfo Points to the string output information,
1513 including the color and font. If NULL, then the
1514 string will be output in the default system font
1515 and color.
1516 @param Blt If this points to a non-NULL on entry, this
1517 points to the image, which is Width pixels wide
1518 and Height pixels high. The string will be drawn
1519 onto this image and
1520 EFI_HII_OUT_FLAG_CLIP is implied. If this points
1521 to a NULL on entry, then a buffer
1522 will be allocated to hold the generated image and
1523 the pointer updated on exit. It is the caller's
1524 responsibility to free this buffer.
1525 @param BltX Specifies the offset from the left and top edge
1526 of the image of the first character cell in the
1527 image.
1528 @param BltY Specifies the offset from the left and top edge
1529 of the image of the first character cell in the
1530 image.
1531 @param RowInfoArray If this is non-NULL on entry, then on exit, this
1532 will point to an allocated buffer containing
1533 row information and RowInfoArraySize will be
1534 updated to contain the number of elements.
1535 This array describes the characters which were at
1536 least partially drawn and the heights of the
1537 rows. It is the caller's responsibility to free
1538 this buffer.
1539 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
1540 contains the number of elements in RowInfoArray.
1541 @param ColumnInfoArray If this is non-NULL, then on return it will be
1542 filled with the horizontal offset for each
1543 character in the string on the row where it is
1544 displayed. Non-printing characters will have
1545 the offset ~0. The caller is responsible to
1546 allocate a buffer large enough so that there
1547 is one entry for each character in the string,
1548 not including the null-terminator. It is possible
1549 when character display is normalized that some
1550 character cells overlap.
1551
1552 @retval EFI_SUCCESS The string was successfully rendered.
1553 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
1554 RowInfoArray or Blt.
1555 @retval EFI_INVALID_PARAMETER The String or Blt was NULL.
1556 @retval EFI_INVALID_PARAMETER Flags were invalid combination..
1557
1558 **/
1559 EFI_STATUS
1560 EFIAPI
1561 HiiStringToImage (
1562 IN CONST EFI_HII_FONT_PROTOCOL *This,
1563 IN EFI_HII_OUT_FLAGS Flags,
1564 IN CONST EFI_STRING String,
1565 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
1566 IN OUT EFI_IMAGE_OUTPUT **Blt,
1567 IN UINTN BltX,
1568 IN UINTN BltY,
1569 OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
1570 OUT UINTN *RowInfoArraySize OPTIONAL,
1571 OUT UINTN *ColumnInfoArray OPTIONAL
1572 )
1573 {
1574 EFI_STATUS Status;
1575 HII_DATABASE_PRIVATE_DATA *Private;
1576 UINT8 **GlyphBuf;
1577 EFI_HII_GLYPH_INFO *Cell;
1578 UINT8 *Attributes;
1579 EFI_IMAGE_OUTPUT *Image;
1580 EFI_STRING StringPtr;
1581 EFI_STRING StringTmp;
1582 EFI_HII_ROW_INFO *RowInfo;
1583 UINTN LineWidth;
1584 UINTN LineHeight;
1585 UINTN LineOffset;
1586 UINTN LastLineHeight;
1587 UINTN BaseLineOffset;
1588 UINT16 MaxRowNum;
1589 UINT16 RowIndex;
1590 UINTN Index;
1591 UINTN NextIndex;
1592 UINTN Index1;
1593 EFI_FONT_DISPLAY_INFO *StringInfoOut;
1594 EFI_FONT_DISPLAY_INFO *SystemDefault;
1595 EFI_FONT_HANDLE FontHandle;
1596 EFI_STRING StringIn;
1597 EFI_STRING StringIn2;
1598 UINT16 Height;
1599 UINT16 BaseLine;
1600 EFI_FONT_INFO *FontInfo;
1601 BOOLEAN SysFontFlag;
1602 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
1603 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
1604 BOOLEAN Transparent;
1605 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
1606 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BufferPtr;
1607 UINTN RowInfoSize;
1608 BOOLEAN LineBreak;
1609 UINTN StrLength;
1610 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *RowBufferPtr;
1611 HII_GLOBAL_FONT_INFO *GlobalFont;
1612 UINT32 PreInitBkgnd;
1613
1614 //
1615 // Check incoming parameters.
1616 //
1617
1618 if (This == NULL || String == NULL || Blt == NULL) {
1619 return EFI_INVALID_PARAMETER;
1620 }
1621 if (*Blt == NULL) {
1622 //
1623 // These two flag cannot be used if Blt is NULL upon entry.
1624 //
1625 if ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT) {
1626 return EFI_INVALID_PARAMETER;
1627 }
1628 if ((Flags & EFI_HII_OUT_FLAG_CLIP) == EFI_HII_OUT_FLAG_CLIP) {
1629 return EFI_INVALID_PARAMETER;
1630 }
1631 }
1632 //
1633 // These two flags require that EFI_HII_OUT_FLAG_CLIP be also set.
1634 //
1635 if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_X)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_X) {
1636 return EFI_INVALID_PARAMETER;
1637 }
1638 if ((Flags & (EFI_HII_OUT_FLAG_CLIP | EFI_HII_OUT_FLAG_CLIP_CLEAN_Y)) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) {
1639 return EFI_INVALID_PARAMETER;
1640 }
1641 //
1642 // This flag cannot be used with EFI_HII_OUT_FLAG_CLEAN_X.
1643 //
1644 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)) {
1645 return EFI_INVALID_PARAMETER;
1646 }
1647
1648 if (*Blt == NULL) {
1649 //
1650 // Create a new bitmap and draw the string onto this image.
1651 //
1652 Image = AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
1653 if (Image == NULL) {
1654 return EFI_OUT_OF_RESOURCES;
1655 }
1656 Image->Width = 800;
1657 Image->Height = 600;
1658 Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height *sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
1659 if (Image->Image.Bitmap == NULL) {
1660 FreePool (Image);
1661 return EFI_OUT_OF_RESOURCES;
1662 }
1663
1664 //
1665 // Other flags are not permitted when Blt is NULL.
1666 //
1667 Flags &= EFI_HII_OUT_FLAG_WRAP | EFI_HII_IGNORE_IF_NO_GLYPH | EFI_HII_IGNORE_LINE_BREAK;
1668 *Blt = Image;
1669 }
1670
1671 StrLength = StrLen(String);
1672 GlyphBuf = (UINT8 **) AllocateZeroPool (StrLength * sizeof (UINT8 *));
1673 ASSERT (GlyphBuf != NULL);
1674 Cell = (EFI_HII_GLYPH_INFO *) AllocateZeroPool (StrLength * sizeof (EFI_HII_GLYPH_INFO));
1675 ASSERT (Cell != NULL);
1676 Attributes = (UINT8 *) AllocateZeroPool (StrLength * sizeof (UINT8));
1677 ASSERT (Attributes != NULL);
1678
1679 RowInfo = NULL;
1680 Status = EFI_SUCCESS;
1681 StringIn2 = NULL;
1682 SystemDefault = NULL;
1683 StringIn = NULL;
1684
1685 //
1686 // Calculate the string output information, including specified color and font .
1687 // If StringInfo does not points to system font info, it must indicate an existing
1688 // EFI_FONT_INFO.
1689 //
1690 StringInfoOut = NULL;
1691 FontHandle = NULL;
1692 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
1693 SysFontFlag = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
1694
1695 if (SysFontFlag) {
1696 ASSERT (SystemDefault != NULL);
1697 FontInfo = NULL;
1698 Height = SystemDefault->FontInfo.FontSize;
1699 BaseLine = SystemDefault->FontInfo.FontSize;
1700 Foreground = SystemDefault->ForegroundColor;
1701 Background = SystemDefault->BackgroundColor;
1702
1703 } else {
1704 //
1705 // StringInfo must not be NULL if it is not system info.
1706 //
1707 ASSERT (StringInfo != NULL);
1708 Status = HiiGetFontInfo (This, &FontHandle, (EFI_FONT_DISPLAY_INFO *) StringInfo, &StringInfoOut, NULL);
1709 if (Status == EFI_NOT_FOUND) {
1710 //
1711 // The specified EFI_FONT_DISPLAY_INFO does not exist in current database.
1712 // Use the system font instead. Still use the color specified by StringInfo.
1713 //
1714 SysFontFlag = TRUE;
1715 FontInfo = NULL;
1716 Height = SystemDefault->FontInfo.FontSize;
1717 BaseLine = SystemDefault->FontInfo.FontSize;
1718 Foreground = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->ForegroundColor;
1719 Background = ((EFI_FONT_DISPLAY_INFO *) StringInfo)->BackgroundColor;
1720
1721 } else if (Status == EFI_SUCCESS) {
1722 FontInfo = &StringInfoOut->FontInfo;
1723 IsFontInfoExisted (Private, FontInfo, NULL, NULL, &GlobalFont);
1724 Height = GlobalFont->FontPackage->Height;
1725 BaseLine = GlobalFont->FontPackage->BaseLine;
1726 Foreground = StringInfoOut->ForegroundColor;
1727 Background = StringInfoOut->BackgroundColor;
1728 } else {
1729 goto Exit;
1730 }
1731 }
1732
1733 //
1734 // Use the maxinum height of font as the base line.
1735 // And, use the maxinum height as line height.
1736 //
1737 LineHeight = Height;
1738 LastLineHeight = Height;
1739 BaseLineOffset = Height - BaseLine;
1740
1741 //
1742 // Parse the string to be displayed to drop some ignored characters.
1743 //
1744
1745 StringPtr = String;
1746
1747 //
1748 // Ignore line-break characters only. Hyphens or dash character will be displayed
1749 // without line-break opportunity.
1750 //
1751 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == EFI_HII_IGNORE_LINE_BREAK) {
1752 StringIn = AllocateZeroPool (StrSize (StringPtr));
1753 if (StringIn == NULL) {
1754 Status = EFI_OUT_OF_RESOURCES;
1755 goto Exit;
1756 }
1757 StringTmp = StringIn;
1758 while (*StringPtr != 0) {
1759 if (IsLineBreak (*StringPtr) == 0) {
1760 StringPtr++;
1761 } else {
1762 *StringTmp++ = *StringPtr++;
1763 }
1764 }
1765 *StringTmp = 0;
1766 StringPtr = StringIn;
1767 }
1768 //
1769 // If EFI_HII_IGNORE_IF_NO_GLYPH is set, then characters which have no glyphs
1770 // are not drawn. Otherwise they are replaced wth Unicode character 0xFFFD.
1771 //
1772 StringIn2 = AllocateZeroPool (StrSize (StringPtr));
1773 if (StringIn2 == NULL) {
1774 Status = EFI_OUT_OF_RESOURCES;
1775 goto Exit;
1776 }
1777 Index = 0;
1778 StringTmp = StringIn2;
1779 StrLength = StrLen(StringPtr);
1780 while (*StringPtr != 0 && Index < StrLength) {
1781 if (IsLineBreak (*StringPtr) == 0) {
1782 *StringTmp++ = *StringPtr++;
1783 Index++;
1784 continue;
1785 }
1786
1787 Status = GetGlyphBuffer (Private, *StringPtr, FontInfo, &GlyphBuf[Index], &Cell[Index], &Attributes[Index]);
1788 if (Status == EFI_NOT_FOUND) {
1789 if ((Flags & EFI_HII_IGNORE_IF_NO_GLYPH) == EFI_HII_IGNORE_IF_NO_GLYPH) {
1790 GlyphBuf[Index] = NULL;
1791 ZeroMem (&Cell[Index], sizeof (Cell[Index]));
1792 Status = EFI_SUCCESS;
1793 } else {
1794 //
1795 // Unicode 0xFFFD must exist in current hii database if this flag is not set.
1796 //
1797 Status = GetGlyphBuffer (
1798 Private,
1799 REPLACE_UNKNOWN_GLYPH,
1800 FontInfo,
1801 &GlyphBuf[Index],
1802 &Cell[Index],
1803 &Attributes[Index]
1804 );
1805 if (EFI_ERROR (Status)) {
1806 Status = EFI_INVALID_PARAMETER;
1807 }
1808 }
1809 }
1810
1811 if (EFI_ERROR (Status)) {
1812 goto Exit;
1813 }
1814
1815 *StringTmp++ = *StringPtr++;
1816 Index++;
1817 }
1818 *StringTmp = 0;
1819 StringPtr = StringIn2;
1820
1821 //
1822 // Draw the string according to the specified EFI_HII_OUT_FLAGS and Blt.
1823 // If Blt is not NULL, then EFI_HII_OUT_FLAG_CLIP is implied, render this string
1824 // to an existing image (bitmap or screen depending on flags) pointed by "*Blt".
1825 // Otherwise render this string to a new allocated image and output it.
1826 //
1827 Image = *Blt;
1828 BufferPtr = Image->Image.Bitmap + Image->Width * BltY + BltX;
1829 if (Image->Height < BltY) {
1830 //
1831 // the top edge of the image should be in Image resolution scope.
1832 //
1833 Status = EFI_INVALID_PARAMETER;
1834 goto Exit;
1835 }
1836 MaxRowNum = (UINT16) ((Image->Height - BltY) / Height);
1837 if ((Image->Height - BltY) % Height != 0) {
1838 LastLineHeight = (Image->Height - BltY) % Height;
1839 MaxRowNum++;
1840 }
1841
1842 RowInfo = (EFI_HII_ROW_INFO *) AllocateZeroPool (MaxRowNum * sizeof (EFI_HII_ROW_INFO));
1843 if (RowInfo == NULL) {
1844 Status = EFI_OUT_OF_RESOURCES;
1845 goto Exit;
1846 }
1847
1848 //
1849 // Format the glyph buffer according to flags.
1850 //
1851 Transparent = (BOOLEAN) ((Flags & EFI_HII_OUT_FLAG_TRANSPARENT) == EFI_HII_OUT_FLAG_TRANSPARENT ? TRUE : FALSE);
1852
1853 for (RowIndex = 0, Index = 0; RowIndex < MaxRowNum && StringPtr[Index] != 0; ) {
1854 LineWidth = 0;
1855 LineBreak = FALSE;
1856
1857 //
1858 // Clip the final row if the row's bottom-most on pixel cannot fit when
1859 // EFI_HII_OUT_FLAG_CLEAN_Y is set.
1860 //
1861 if (RowIndex == MaxRowNum - 1) {
1862 if ((Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_Y) == EFI_HII_OUT_FLAG_CLIP_CLEAN_Y && LastLineHeight < LineHeight ) {
1863 //
1864 // Don't draw at all if the row's bottom-most on pixel cannot fit.
1865 //
1866 break;
1867 }
1868 LineHeight = LastLineHeight;
1869 }
1870
1871 //
1872 // Calculate how many characters there are in a row.
1873 //
1874 RowInfo[RowIndex].StartIndex = Index;
1875
1876 while (LineWidth + BltX < Image->Width && StringPtr[Index] != 0) {
1877 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0 &&
1878 IsLineBreak (StringPtr[Index]) == 0) {
1879 //
1880 // It forces a line break that ends this row.
1881 //
1882 Index++;
1883 LineBreak = TRUE;
1884 break;
1885 }
1886
1887 //
1888 // If the glyph of the character is existing, then accumulate the actual printed width
1889 //
1890 LineWidth += (UINTN) Cell[Index].AdvanceX;
1891
1892 Index++;
1893 }
1894
1895 //
1896 // Record index of next char.
1897 //
1898 NextIndex = Index;
1899 //
1900 // Return to the previous char.
1901 //
1902 Index--;
1903 if (LineBreak && Index > 0 ) {
1904 //
1905 // Return the previous non line break char.
1906 //
1907 Index --;
1908 }
1909
1910 //
1911 // If this character is the last character of a row, we need not
1912 // draw its (AdvanceX - Width - OffsetX) for next character.
1913 //
1914 LineWidth -= (UINTN) (Cell[Index].AdvanceX - Cell[Index].Width - Cell[Index].OffsetX);
1915
1916 //
1917 // Clip the right-most character if cannot fit when EFI_HII_OUT_FLAG_CLEAN_X is set.
1918 //
1919 if (LineWidth + BltX <= Image->Width ||
1920 (LineWidth + BltX > Image->Width && (Flags & EFI_HII_OUT_FLAG_CLIP_CLEAN_X) == 0)) {
1921 //
1922 // Record right-most character in RowInfo even if it is partially displayed.
1923 //
1924 RowInfo[RowIndex].EndIndex = Index;
1925 RowInfo[RowIndex].LineWidth = LineWidth;
1926 RowInfo[RowIndex].LineHeight = LineHeight;
1927 RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
1928 } else {
1929 //
1930 // When EFI_HII_OUT_FLAG_CLEAN_X is set, it will not draw a character
1931 // if its right-most on pixel cannot fit.
1932 //
1933 if (Index > RowInfo[RowIndex].StartIndex) {
1934 //
1935 // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
1936 //
1937 LineWidth -= (UINTN) (Cell[Index].Width + Cell[Index].OffsetX);
1938 LineWidth -= (UINTN) (Cell[Index - 1].AdvanceX - Cell[Index - 1].Width - Cell[Index - 1].OffsetX);
1939 RowInfo[RowIndex].EndIndex = Index - 1;
1940 RowInfo[RowIndex].LineWidth = LineWidth;
1941 RowInfo[RowIndex].LineHeight = LineHeight;
1942 RowInfo[RowIndex].BaselineOffset = BaseLineOffset;
1943 } else {
1944 //
1945 // There is no enough column to draw any character, so set current line width to zero.
1946 // And go to draw Next line if LineBreak is set.
1947 //
1948 RowInfo[RowIndex].LineWidth = 0;
1949 goto NextLine;
1950 }
1951 }
1952
1953 //
1954 // EFI_HII_OUT_FLAG_WRAP will wrap the text at the right-most line-break
1955 // opportunity prior to a character whose right-most extent would exceed Width.
1956 // Search the right-most line-break opportunity here.
1957 //
1958 if ((Flags & EFI_HII_OUT_FLAG_WRAP) == EFI_HII_OUT_FLAG_WRAP &&
1959 (RowInfo[RowIndex].LineWidth + BltX > Image->Width || StringPtr[NextIndex] != 0) &&
1960 !LineBreak) {
1961 if ((Flags & EFI_HII_IGNORE_LINE_BREAK) == 0) {
1962 LineWidth = RowInfo[RowIndex].LineWidth;
1963 for (Index1 = RowInfo[RowIndex].EndIndex; Index1 >= RowInfo[RowIndex].StartIndex; Index1--) {
1964 if (Index1 == RowInfo[RowIndex].EndIndex) {
1965 LineWidth -= (Cell[Index1].Width + Cell[Index1].OffsetX);
1966 } else {
1967 LineWidth -= Cell[Index1].AdvanceX;
1968 }
1969 if (IsLineBreak (StringPtr[Index1]) > 0) {
1970 LineBreak = TRUE;
1971 if (Index1 > RowInfo[RowIndex].StartIndex) {
1972 RowInfo[RowIndex].EndIndex = Index1 - 1;
1973 }
1974 //
1975 // relocate to the character after the right-most line break opportunity of this line
1976 //
1977 NextIndex = Index1 + 1;
1978 break;
1979 }
1980 //
1981 // If don't find a line break opportunity from EndIndex to StartIndex,
1982 // then jump out.
1983 //
1984 if (Index1 == RowInfo[RowIndex].StartIndex)
1985 break;
1986 }
1987
1988 //
1989 // Update LineWidth to the real width
1990 //
1991 if (IsLineBreak (StringPtr[Index1]) > 0) {
1992 if (Index1 == RowInfo[RowIndex].StartIndex) {
1993 LineWidth = 0;
1994 } else {
1995 LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
1996 }
1997 RowInfo[RowIndex].LineWidth = LineWidth;
1998 }
1999 }
2000 //
2001 // If no line-break opportunity can be found, then the text will
2002 // behave as if EFI_HII_OUT_FLAG_CLEAN_X is set.
2003 //
2004 if (!LineBreak) {
2005 LineWidth = RowInfo[RowIndex].LineWidth;
2006 Index1 = RowInfo[RowIndex].EndIndex;
2007 if (LineWidth + BltX > Image->Width) {
2008 if (Index1 > RowInfo[RowIndex].StartIndex) {
2009 //
2010 // Don't draw the last char on this row. And, don't draw the second last char (AdvanceX - Width - OffsetX).
2011 //
2012 LineWidth -= (UINTN) (Cell[Index1].Width + Cell[Index1].OffsetX);
2013 LineWidth -= (UINTN) (Cell[Index1 - 1].AdvanceX - Cell[Index1 - 1].Width - Cell[Index1 - 1].OffsetX);
2014 RowInfo[RowIndex].EndIndex = Index1 - 1;
2015 RowInfo[RowIndex].LineWidth = LineWidth;
2016 } else {
2017 //
2018 // There is no enough column to draw any character, so set current line width to zero.
2019 // And go to draw Next line if LineBreak is set.
2020 //
2021 RowInfo[RowIndex].LineWidth = 0;
2022 goto NextLine;
2023 }
2024 }
2025 }
2026 }
2027
2028 //
2029 // LineWidth can't exceed Image width.
2030 //
2031 if (RowInfo[RowIndex].LineWidth + BltX > Image->Width) {
2032 RowInfo[RowIndex].LineWidth = Image->Width - BltX;
2033 }
2034
2035 //
2036 // Draw it to screen or existing bitmap depending on whether
2037 // EFI_HII_DIRECT_TO_SCREEN is set.
2038 //
2039 LineOffset = 0;
2040 if ((Flags & EFI_HII_DIRECT_TO_SCREEN) == EFI_HII_DIRECT_TO_SCREEN) {
2041 BltBuffer = NULL;
2042 if (RowInfo[RowIndex].LineWidth != 0) {
2043 BltBuffer = AllocateZeroPool (RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2044 if (BltBuffer == NULL) {
2045 Status = EFI_OUT_OF_RESOURCES;
2046 goto Exit;
2047 }
2048 //
2049 // Initialize the background color.
2050 //
2051 PreInitBkgnd = Background.Blue | Background.Green << 8 | Background.Red << 16;
2052 SetMem32 (BltBuffer,RowInfo[RowIndex].LineWidth * RowInfo[RowIndex].LineHeight * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL),PreInitBkgnd);
2053 //
2054 // Set BufferPtr to Origin by adding baseline to the starting position.
2055 //
2056 BufferPtr = BltBuffer + BaseLine * RowInfo[RowIndex].LineWidth;
2057 }
2058 for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
2059 if (RowInfo[RowIndex].LineWidth > 0 && RowInfo[RowIndex].LineWidth > LineOffset) {
2060 //
2061 // Only BLT these character which have corrsponding glyph in font basebase.
2062 //
2063 GlyphToImage (
2064 GlyphBuf[Index1],
2065 Foreground,
2066 Background,
2067 (UINT16) RowInfo[RowIndex].LineWidth,
2068 BaseLine,
2069 RowInfo[RowIndex].LineWidth - LineOffset,
2070 RowInfo[RowIndex].LineHeight,
2071 Transparent,
2072 &Cell[Index1],
2073 Attributes[Index1],
2074 &BufferPtr
2075 );
2076 }
2077 if (ColumnInfoArray != NULL) {
2078 if ((GlyphBuf[Index1] == NULL && Cell[Index1].AdvanceX == 0)
2079 || RowInfo[RowIndex].LineWidth == 0) {
2080 *ColumnInfoArray = (UINTN) ~0;
2081 } else {
2082 *ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX;
2083 }
2084 ColumnInfoArray++;
2085 }
2086 LineOffset += Cell[Index1].AdvanceX;
2087 }
2088
2089 if (BltBuffer != NULL) {
2090 Status = Image->Image.Screen->Blt (
2091 Image->Image.Screen,
2092 BltBuffer,
2093 EfiBltBufferToVideo,
2094 0,
2095 0,
2096 BltX,
2097 BltY,
2098 RowInfo[RowIndex].LineWidth,
2099 RowInfo[RowIndex].LineHeight,
2100 0
2101 );
2102 if (EFI_ERROR (Status)) {
2103 FreePool (BltBuffer);
2104 goto Exit;
2105 }
2106
2107 FreePool (BltBuffer);
2108 }
2109 } else {
2110 //
2111 // Save the starting position for calculate the starting postition of next row.
2112 //
2113 RowBufferPtr = BufferPtr;
2114 //
2115 // Set BufferPtr to Origin by adding baseline to the starting position.
2116 //
2117 BufferPtr = BufferPtr + BaseLine * Image->Width;
2118 for (Index1 = RowInfo[RowIndex].StartIndex; Index1 <= RowInfo[RowIndex].EndIndex; Index1++) {
2119 if (RowInfo[RowIndex].LineWidth > 0 && RowInfo[RowIndex].LineWidth > LineOffset) {
2120 //
2121 // Only BLT these character which have corrsponding glyph in font basebase.
2122 //
2123 GlyphToImage (
2124 GlyphBuf[Index1],
2125 Foreground,
2126 Background,
2127 Image->Width,
2128 BaseLine,
2129 RowInfo[RowIndex].LineWidth - LineOffset,
2130 RowInfo[RowIndex].LineHeight,
2131 Transparent,
2132 &Cell[Index1],
2133 Attributes[Index1],
2134 &BufferPtr
2135 );
2136 }
2137 if (ColumnInfoArray != NULL) {
2138 if ((GlyphBuf[Index1] == NULL && Cell[Index1].AdvanceX == 0)
2139 || RowInfo[RowIndex].LineWidth == 0) {
2140 *ColumnInfoArray = (UINTN) ~0;
2141 } else {
2142 *ColumnInfoArray = LineOffset + Cell[Index1].OffsetX + BltX;
2143 }
2144 ColumnInfoArray++;
2145 }
2146 LineOffset += Cell[Index1].AdvanceX;
2147 }
2148
2149 //
2150 // Jump to starting position of next row.
2151 //
2152 if (RowIndex == 0) {
2153 BufferPtr = RowBufferPtr - BltX + LineHeight * Image->Width;
2154 } else {
2155 BufferPtr = RowBufferPtr + LineHeight * Image->Width;
2156 }
2157 }
2158
2159 NextLine:
2160 //
2161 // Recalculate the start point of Y axis to draw multi-lines with the order of top-to-down
2162 //
2163 BltY += RowInfo[RowIndex].LineHeight;
2164
2165 RowIndex++;
2166 Index = NextIndex;
2167
2168 if (!LineBreak) {
2169 //
2170 // If there is not a mandatory line break or line break opportunity, only render one line to image
2171 //
2172 break;
2173 }
2174 }
2175
2176 //
2177 // Write output parameters.
2178 //
2179 RowInfoSize = RowIndex * sizeof (EFI_HII_ROW_INFO);
2180 if (RowInfoArray != NULL) {
2181 if (RowInfoSize > 0) {
2182 *RowInfoArray = AllocateZeroPool (RowInfoSize);
2183 if (*RowInfoArray == NULL) {
2184 Status = EFI_OUT_OF_RESOURCES;
2185 goto Exit;
2186 }
2187 CopyMem (*RowInfoArray, RowInfo, RowInfoSize);
2188 } else {
2189 *RowInfoArray = NULL;
2190 }
2191 }
2192 if (RowInfoArraySize != NULL) {
2193 *RowInfoArraySize = RowIndex;
2194 }
2195
2196 Status = EFI_SUCCESS;
2197
2198 Exit:
2199
2200 for (Index = 0; Index < StrLength; Index++) {
2201 if (GlyphBuf[Index] != NULL) {
2202 FreePool (GlyphBuf[Index]);
2203 }
2204 }
2205 if (StringIn != NULL) {
2206 FreePool (StringIn);
2207 }
2208 if (StringIn2 != NULL) {
2209 FreePool (StringIn2);
2210 }
2211 if (StringInfoOut != NULL) {
2212 FreePool (StringInfoOut);
2213 }
2214 if (RowInfo != NULL) {
2215 FreePool (RowInfo);
2216 }
2217 if (SystemDefault != NULL) {
2218 FreePool (SystemDefault);
2219 }
2220 if (GlyphBuf != NULL) {
2221 FreePool (GlyphBuf);
2222 }
2223 if (Cell != NULL) {
2224 FreePool (Cell);
2225 }
2226 if (Attributes != NULL) {
2227 FreePool (Attributes);
2228 }
2229
2230 return Status;
2231 }
2232
2233
2234 /**
2235 Render a string to a bitmap or the screen containing the contents of the specified string.
2236
2237 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2238 @param Flags Describes how the string is to be drawn.
2239 @param PackageList The package list in the HII database to search
2240 for the specified string.
2241 @param StringId The string's id, which is unique within
2242 PackageList.
2243 @param Language Points to the language for the retrieved string.
2244 If NULL, then the current system language is
2245 used.
2246 @param StringInfo Points to the string output information,
2247 including the color and font. If NULL, then the
2248 string will be output in the default system font
2249 and color.
2250 @param Blt If this points to a non-NULL on entry, this
2251 points to the image, which is Width pixels wide
2252 and Height pixels high. The string will be drawn
2253 onto this image and
2254 EFI_HII_OUT_FLAG_CLIP is implied. If this points
2255 to a NULL on entry, then a buffer
2256 will be allocated to hold the generated image and
2257 the pointer updated on exit. It is the caller's
2258 responsibility to free this buffer.
2259 @param BltX Specifies the offset from the left and top edge
2260 of the image of the first character cell in the
2261 image.
2262 @param BltY Specifies the offset from the left and top edge
2263 of the image of the first character cell in the
2264 image.
2265 @param RowInfoArray If this is non-NULL on entry, then on exit, this
2266 will point to an allocated buffer containing
2267 row information and RowInfoArraySize will be
2268 updated to contain the number of elements.
2269 This array describes the characters which were at
2270 least partially drawn and the heights of the
2271 rows. It is the caller's responsibility to free
2272 this buffer.
2273 @param RowInfoArraySize If this is non-NULL on entry, then on exit it
2274 contains the number of elements in RowInfoArray.
2275 @param ColumnInfoArray If this is non-NULL, then on return it will be
2276 filled with the horizontal offset for each
2277 character in the string on the row where it is
2278 displayed. Non-printing characters will have
2279 the offset ~0. The caller is responsible to
2280 allocate a buffer large enough so that there
2281 is one entry for each character in the string,
2282 not including the null-terminator. It is possible
2283 when character display is normalized that some
2284 character cells overlap.
2285
2286 @retval EFI_SUCCESS The string was successfully rendered.
2287 @retval EFI_OUT_OF_RESOURCES Unable to allocate an output buffer for
2288 RowInfoArray or Blt.
2289 @retval EFI_INVALID_PARAMETER The Blt or PackageList was NULL.
2290 @retval EFI_INVALID_PARAMETER Flags were invalid combination.
2291 @retval EFI_NOT_FOUND The specified PackageList is not in the Database or the stringid is not
2292 in the specified PackageList.
2293
2294 **/
2295 EFI_STATUS
2296 EFIAPI
2297 HiiStringIdToImage (
2298 IN CONST EFI_HII_FONT_PROTOCOL *This,
2299 IN EFI_HII_OUT_FLAGS Flags,
2300 IN EFI_HII_HANDLE PackageList,
2301 IN EFI_STRING_ID StringId,
2302 IN CONST CHAR8* Language,
2303 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo OPTIONAL,
2304 IN OUT EFI_IMAGE_OUTPUT **Blt,
2305 IN UINTN BltX,
2306 IN UINTN BltY,
2307 OUT EFI_HII_ROW_INFO **RowInfoArray OPTIONAL,
2308 OUT UINTN *RowInfoArraySize OPTIONAL,
2309 OUT UINTN *ColumnInfoArray OPTIONAL
2310 )
2311 {
2312 EFI_STATUS Status;
2313 HII_DATABASE_PRIVATE_DATA *Private;
2314 EFI_HII_STRING_PROTOCOL *HiiString;
2315 EFI_STRING String;
2316 UINTN StringSize;
2317 UINTN FontLen;
2318 UINTN NameSize;
2319 EFI_FONT_INFO *StringFontInfo;
2320 EFI_FONT_DISPLAY_INFO *NewStringInfo;
2321 CHAR8 TempSupportedLanguages;
2322 CHAR8 *SupportedLanguages;
2323 UINTN SupportedLanguagesSize;
2324 CHAR8 *CurrentLanguage;
2325 CHAR8 *BestLanguage;
2326
2327 if (This == NULL || PackageList == NULL || Blt == NULL || PackageList == NULL) {
2328 return EFI_INVALID_PARAMETER;
2329 }
2330
2331 if (!IsHiiHandleValid (PackageList)) {
2332 return EFI_NOT_FOUND;
2333 }
2334
2335 //
2336 // Initialize string pointers to be NULL
2337 //
2338 SupportedLanguages = NULL;
2339 CurrentLanguage = NULL;
2340 BestLanguage = NULL;
2341 String = NULL;
2342 StringFontInfo = NULL;
2343 NewStringInfo = NULL;
2344
2345 //
2346 // Get the string to be displayed.
2347 //
2348 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2349 HiiString = &Private->HiiString;
2350
2351 //
2352 // Get the size of supported language.
2353 //
2354 SupportedLanguagesSize = 0;
2355 Status = HiiString->GetLanguages (
2356 HiiString,
2357 PackageList,
2358 &TempSupportedLanguages,
2359 &SupportedLanguagesSize
2360 );
2361 if (Status != EFI_BUFFER_TOO_SMALL) {
2362 return Status;
2363 }
2364
2365 SupportedLanguages = AllocatePool (SupportedLanguagesSize);
2366 if (SupportedLanguages == NULL) {
2367 return EFI_OUT_OF_RESOURCES;
2368 }
2369
2370 Status = HiiString->GetLanguages (
2371 HiiString,
2372 PackageList,
2373 SupportedLanguages,
2374 &SupportedLanguagesSize
2375 );
2376 if (EFI_ERROR (Status)) {
2377 goto Exit;
2378 }
2379
2380 if (Language == NULL) {
2381 Language = "";
2382 }
2383 GetEfiGlobalVariable2 (L"PlatformLang", (VOID**)&CurrentLanguage, NULL);
2384 BestLanguage = GetBestLanguage (
2385 SupportedLanguages,
2386 FALSE,
2387 Language,
2388 (CurrentLanguage == NULL) ? CurrentLanguage : "",
2389 (CHAR8 *) PcdGetPtr (PcdUefiVariableDefaultPlatformLang),
2390 NULL
2391 );
2392 if (BestLanguage == NULL) {
2393 Status = EFI_NOT_FOUND;
2394 goto Exit;
2395 }
2396
2397 StringSize = MAX_STRING_LENGTH;
2398 String = (EFI_STRING) AllocateZeroPool (StringSize);
2399 if (String == NULL) {
2400 Status = EFI_OUT_OF_RESOURCES;
2401 goto Exit;
2402 }
2403
2404 Status = HiiString->GetString (
2405 HiiString,
2406 BestLanguage,
2407 PackageList,
2408 StringId,
2409 String,
2410 &StringSize,
2411 &StringFontInfo
2412 );
2413 if (Status == EFI_BUFFER_TOO_SMALL) {
2414 FreePool (String);
2415 String = (EFI_STRING) AllocateZeroPool (StringSize);
2416 if (String == NULL) {
2417 Status = EFI_OUT_OF_RESOURCES;
2418 goto Exit;
2419 }
2420 Status = HiiString->GetString (
2421 HiiString,
2422 BestLanguage,
2423 PackageList,
2424 StringId,
2425 String,
2426 &StringSize,
2427 NULL
2428 );
2429 }
2430
2431 if (EFI_ERROR (Status)) {
2432 goto Exit;
2433 }
2434
2435 //
2436 // When StringInfo specifies that string will be output in the system default font and color,
2437 // use particular stringfontinfo described in string package instead if exists.
2438 // StringFontInfo equals NULL means system default font attaches with the string block.
2439 //
2440 if (StringFontInfo != NULL && IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, NULL, NULL)) {
2441 NameSize = StrSize (StringFontInfo->FontName);
2442 FontLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (CHAR16) + NameSize;
2443 NewStringInfo = AllocateZeroPool (FontLen);
2444 if (NewStringInfo == NULL) {
2445 Status = EFI_OUT_OF_RESOURCES;
2446 goto Exit;
2447 }
2448 NewStringInfo->FontInfoMask = EFI_FONT_INFO_SYS_FORE_COLOR | EFI_FONT_INFO_SYS_BACK_COLOR;
2449 NewStringInfo->FontInfo.FontStyle = StringFontInfo->FontStyle;
2450 NewStringInfo->FontInfo.FontSize = StringFontInfo->FontSize;
2451 StrCpyS (NewStringInfo->FontInfo.FontName, NameSize / sizeof (CHAR16), StringFontInfo->FontName);
2452
2453 Status = HiiStringToImage (
2454 This,
2455 Flags,
2456 String,
2457 NewStringInfo,
2458 Blt,
2459 BltX,
2460 BltY,
2461 RowInfoArray,
2462 RowInfoArraySize,
2463 ColumnInfoArray
2464 );
2465 goto Exit;
2466 }
2467
2468 Status = HiiStringToImage (
2469 This,
2470 Flags,
2471 String,
2472 StringInfo,
2473 Blt,
2474 BltX,
2475 BltY,
2476 RowInfoArray,
2477 RowInfoArraySize,
2478 ColumnInfoArray
2479 );
2480
2481 Exit:
2482 if (SupportedLanguages != NULL) {
2483 FreePool (SupportedLanguages);
2484 }
2485 if (CurrentLanguage != NULL) {
2486 FreePool (CurrentLanguage);
2487 }
2488 if (BestLanguage != NULL) {
2489 FreePool (BestLanguage);
2490 }
2491 if (String != NULL) {
2492 FreePool (String);
2493 }
2494 if (StringFontInfo != NULL) {
2495 FreePool (StringFontInfo);
2496 }
2497 if (NewStringInfo != NULL) {
2498 FreePool (NewStringInfo);
2499 }
2500
2501 return Status;
2502 }
2503
2504
2505 /**
2506 Convert the glyph for a single character into a bitmap.
2507
2508 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2509 @param Char Character to retrieve.
2510 @param StringInfo Points to the string font and color information
2511 or NULL if the string should use the default
2512 system font and color.
2513 @param Blt Thus must point to a NULL on entry. A buffer will
2514 be allocated to hold the output and the pointer
2515 updated on exit. It is the caller's
2516 responsibility to free this buffer.
2517 @param Baseline Number of pixels from the bottom of the bitmap to
2518 the baseline.
2519
2520 @retval EFI_SUCCESS Glyph bitmap created.
2521 @retval EFI_OUT_OF_RESOURCES Unable to allocate the output buffer Blt.
2522 @retval EFI_WARN_UNKNOWN_GLYPH The glyph was unknown and was replaced with the
2523 glyph for Unicode character 0xFFFD.
2524 @retval EFI_INVALID_PARAMETER Blt is NULL or *Blt is not NULL.
2525
2526 **/
2527 EFI_STATUS
2528 EFIAPI
2529 HiiGetGlyph (
2530 IN CONST EFI_HII_FONT_PROTOCOL *This,
2531 IN CHAR16 Char,
2532 IN CONST EFI_FONT_DISPLAY_INFO *StringInfo,
2533 OUT EFI_IMAGE_OUTPUT **Blt,
2534 OUT UINTN *Baseline OPTIONAL
2535 )
2536 {
2537 EFI_STATUS Status;
2538 HII_DATABASE_PRIVATE_DATA *Private;
2539 EFI_IMAGE_OUTPUT *Image;
2540 UINT8 *GlyphBuffer;
2541 EFI_FONT_DISPLAY_INFO *SystemDefault;
2542 EFI_FONT_DISPLAY_INFO *StringInfoOut;
2543 BOOLEAN Default;
2544 EFI_FONT_HANDLE FontHandle;
2545 EFI_STRING String;
2546 EFI_HII_GLYPH_INFO Cell;
2547 EFI_FONT_INFO *FontInfo;
2548 UINT8 Attributes;
2549 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground;
2550 EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background;
2551 EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer;
2552 UINT16 BaseLine;
2553
2554 if (This == NULL || Blt == NULL || *Blt != NULL) {
2555 return EFI_INVALID_PARAMETER;
2556 }
2557
2558 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2559
2560 Default = FALSE;
2561 Image = NULL;
2562 SystemDefault = NULL;
2563 FontHandle = NULL;
2564 String = NULL;
2565 GlyphBuffer = NULL;
2566 StringInfoOut = NULL;
2567 FontInfo = NULL;
2568
2569 ZeroMem (&Foreground, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2570 ZeroMem (&Background, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2571
2572 Default = IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfo, &SystemDefault, NULL);
2573
2574 if (!Default) {
2575 //
2576 // Find out a EFI_FONT_DISPLAY_INFO which could display the character in
2577 // the specified color and font.
2578 //
2579 String = (EFI_STRING) AllocateZeroPool (sizeof (CHAR16) * 2);
2580 if (String == NULL) {
2581 Status = EFI_OUT_OF_RESOURCES;
2582 goto Exit;
2583 }
2584 *String = Char;
2585 *(String + 1) = 0;
2586
2587 Status = HiiGetFontInfo (This, &FontHandle, StringInfo, &StringInfoOut, String);
2588 if (EFI_ERROR (Status)) {
2589 goto Exit;
2590 }
2591 ASSERT (StringInfoOut != NULL);
2592 FontInfo = &StringInfoOut->FontInfo;
2593 Foreground = StringInfoOut->ForegroundColor;
2594 Background = StringInfoOut->BackgroundColor;
2595 } else {
2596 ASSERT (SystemDefault != NULL);
2597 Foreground = SystemDefault->ForegroundColor;
2598 Background = SystemDefault->BackgroundColor;
2599 }
2600
2601 Status = GetGlyphBuffer (Private, Char, FontInfo, &GlyphBuffer, &Cell, &Attributes);
2602 if (EFI_ERROR (Status)) {
2603 goto Exit;
2604 }
2605
2606 Image = (EFI_IMAGE_OUTPUT *) AllocateZeroPool (sizeof (EFI_IMAGE_OUTPUT));
2607 if (Image == NULL) {
2608 Status = EFI_OUT_OF_RESOURCES;
2609 goto Exit;
2610 }
2611 Image->Width = Cell.Width;
2612 Image->Height = Cell.Height;
2613
2614 if (Image->Width * Image->Height > 0) {
2615 Image->Image.Bitmap = AllocateZeroPool (Image->Width * Image->Height * sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL));
2616 if (Image->Image.Bitmap == NULL) {
2617 FreePool (Image);
2618 Status = EFI_OUT_OF_RESOURCES;
2619 goto Exit;
2620 }
2621
2622 //
2623 // Set BaseLine to the char height.
2624 //
2625 BaseLine = (UINT16) (Cell.Height + Cell.OffsetY);
2626 //
2627 // Set BltBuffer to the position of Origin.
2628 //
2629 BltBuffer = Image->Image.Bitmap + (Cell.Height + Cell.OffsetY) * Image->Width - Cell.OffsetX;
2630 GlyphToImage (
2631 GlyphBuffer,
2632 Foreground,
2633 Background,
2634 Image->Width,
2635 BaseLine,
2636 Cell.Width + Cell.OffsetX,
2637 BaseLine - Cell.OffsetY,
2638 FALSE,
2639 &Cell,
2640 Attributes,
2641 &BltBuffer
2642 );
2643 }
2644
2645 *Blt = Image;
2646 if (Baseline != NULL) {
2647 *Baseline = Cell.OffsetY;
2648 }
2649
2650 Status = EFI_SUCCESS;
2651
2652 Exit:
2653
2654 if (Status == EFI_NOT_FOUND) {
2655 //
2656 // Glyph is unknown and replaced with the glyph for unicode character 0xFFFD
2657 //
2658 if (Char != REPLACE_UNKNOWN_GLYPH) {
2659 Status = HiiGetGlyph (This, REPLACE_UNKNOWN_GLYPH, StringInfo, Blt, Baseline);
2660 if (!EFI_ERROR (Status)) {
2661 Status = EFI_WARN_UNKNOWN_GLYPH;
2662 }
2663 } else {
2664 Status = EFI_WARN_UNKNOWN_GLYPH;
2665 }
2666 }
2667
2668 if (SystemDefault != NULL) {
2669 FreePool (SystemDefault);
2670 }
2671 if (StringInfoOut != NULL) {
2672 FreePool (StringInfoOut);
2673 }
2674 if (String != NULL) {
2675 FreePool (String);
2676 }
2677 if (GlyphBuffer != NULL) {
2678 FreePool (GlyphBuffer);
2679 }
2680
2681 return Status;
2682 }
2683
2684
2685 /**
2686 This function iterates through fonts which match the specified font, using
2687 the specified criteria. If String is non-NULL, then all of the characters in
2688 the string must exist in order for a candidate font to be returned.
2689
2690 @param This A pointer to the EFI_HII_FONT_PROTOCOL instance.
2691 @param FontHandle On entry, points to the font handle returned by a
2692 previous call to GetFontInfo() or NULL to start
2693 with the first font. On return, points to the
2694 returned font handle or points to NULL if there
2695 are no more matching fonts.
2696 @param StringInfoIn Upon entry, points to the font to return information
2697 about. If NULL, then the information about the system
2698 default font will be returned.
2699 @param StringInfoOut Upon return, contains the matching font's information.
2700 If NULL, then no information is returned. This buffer
2701 is allocated with a call to the Boot Service AllocatePool().
2702 It is the caller's responsibility to call the Boot
2703 Service FreePool() when the caller no longer requires
2704 the contents of StringInfoOut.
2705 @param String Points to the string which will be tested to
2706 determine if all characters are available. If
2707 NULL, then any font is acceptable.
2708
2709 @retval EFI_SUCCESS Matching font returned successfully.
2710 @retval EFI_NOT_FOUND No matching font was found.
2711 @retval EFI_INVALID_PARAMETER StringInfoIn->FontInfoMask is an invalid combination.
2712 @retval EFI_OUT_OF_RESOURCES There were insufficient resources to complete the
2713 request.
2714
2715 **/
2716 EFI_STATUS
2717 EFIAPI
2718 HiiGetFontInfo (
2719 IN CONST EFI_HII_FONT_PROTOCOL *This,
2720 IN OUT EFI_FONT_HANDLE *FontHandle,
2721 IN CONST EFI_FONT_DISPLAY_INFO *StringInfoIn, OPTIONAL
2722 OUT EFI_FONT_DISPLAY_INFO **StringInfoOut,
2723 IN CONST EFI_STRING String OPTIONAL
2724 )
2725 {
2726 HII_DATABASE_PRIVATE_DATA *Private;
2727 EFI_STATUS Status;
2728 EFI_FONT_DISPLAY_INFO *SystemDefault;
2729 EFI_FONT_DISPLAY_INFO InfoOut;
2730 UINTN StringInfoOutLen;
2731 EFI_FONT_INFO *FontInfo;
2732 HII_GLOBAL_FONT_INFO *GlobalFont;
2733 EFI_STRING StringIn;
2734 EFI_FONT_HANDLE LocalFontHandle;
2735
2736 if (This == NULL) {
2737 return EFI_INVALID_PARAMETER;
2738 }
2739
2740 StringInfoOutLen = 0;
2741 FontInfo = NULL;
2742 SystemDefault = NULL;
2743 LocalFontHandle = NULL;
2744 if (FontHandle != NULL) {
2745 LocalFontHandle = *FontHandle;
2746 }
2747
2748 Private = HII_FONT_DATABASE_PRIVATE_DATA_FROM_THIS (This);
2749
2750 //
2751 // Already searched to the end of the whole list, return directly.
2752 //
2753 if (LocalFontHandle == &Private->FontInfoList) {
2754 LocalFontHandle = NULL;
2755 Status = EFI_NOT_FOUND;
2756 goto Exit;
2757 }
2758
2759 //
2760 // Get default system display info, if StringInfoIn points to
2761 // system display info, return it directly.
2762 //
2763 if (IsSystemFontInfo (Private, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, &SystemDefault, &StringInfoOutLen)) {
2764 //
2765 // System font is the first node. When handle is not NULL, system font can not
2766 // be found any more.
2767 //
2768 if (LocalFontHandle == NULL) {
2769 if (StringInfoOut != NULL) {
2770 *StringInfoOut = AllocateCopyPool (StringInfoOutLen, SystemDefault);
2771 if (*StringInfoOut == NULL) {
2772 Status = EFI_OUT_OF_RESOURCES;
2773 LocalFontHandle = NULL;
2774 goto Exit;
2775 }
2776 }
2777
2778 LocalFontHandle = Private->FontInfoList.ForwardLink;
2779 Status = EFI_SUCCESS;
2780 goto Exit;
2781 } else {
2782 LocalFontHandle = NULL;
2783 Status = EFI_NOT_FOUND;
2784 goto Exit;
2785 }
2786 }
2787
2788 //
2789 // StringInfoIn must not be NULL if it is not system default font info.
2790 //
2791 ASSERT (StringInfoIn != NULL);
2792 //
2793 // Check the font information mask to make sure it is valid.
2794 //
2795 if (((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ==
2796 (EFI_FONT_INFO_SYS_FONT | EFI_FONT_INFO_ANY_FONT)) ||
2797 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ==
2798 (EFI_FONT_INFO_SYS_SIZE | EFI_FONT_INFO_ANY_SIZE)) ||
2799 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ==
2800 (EFI_FONT_INFO_SYS_STYLE | EFI_FONT_INFO_ANY_STYLE)) ||
2801 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ==
2802 (EFI_FONT_INFO_RESIZE | EFI_FONT_INFO_ANY_SIZE)) ||
2803 ((StringInfoIn->FontInfoMask & (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE)) ==
2804 (EFI_FONT_INFO_RESTYLE | EFI_FONT_INFO_ANY_STYLE))) {
2805 return EFI_INVALID_PARAMETER;
2806 }
2807
2808 //
2809 // Parse the font information mask to find a matching font.
2810 //
2811
2812 CopyMem (&InfoOut, (EFI_FONT_DISPLAY_INFO *) StringInfoIn, sizeof (EFI_FONT_DISPLAY_INFO));
2813
2814 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FONT) == EFI_FONT_INFO_SYS_FONT) {
2815 Status = SaveFontName (SystemDefault->FontInfo.FontName, &FontInfo);
2816 } else {
2817 Status = SaveFontName (((EFI_FONT_DISPLAY_INFO *) StringInfoIn)->FontInfo.FontName, &FontInfo);
2818 }
2819 if (EFI_ERROR (Status)) {
2820 goto Exit;
2821 }
2822
2823 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_SIZE) == EFI_FONT_INFO_SYS_SIZE) {
2824 InfoOut.FontInfo.FontSize = SystemDefault->FontInfo.FontSize;
2825 }
2826 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_STYLE) == EFI_FONT_INFO_SYS_STYLE) {
2827 InfoOut.FontInfo.FontStyle = SystemDefault->FontInfo.FontStyle;
2828 }
2829 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_FORE_COLOR) == EFI_FONT_INFO_SYS_FORE_COLOR) {
2830 InfoOut.ForegroundColor = SystemDefault->ForegroundColor;
2831 }
2832 if ((StringInfoIn->FontInfoMask & EFI_FONT_INFO_SYS_BACK_COLOR) == EFI_FONT_INFO_SYS_BACK_COLOR) {
2833 InfoOut.BackgroundColor = SystemDefault->BackgroundColor;
2834 }
2835
2836 ASSERT (FontInfo != NULL);
2837 FontInfo->FontSize = InfoOut.FontInfo.FontSize;
2838 FontInfo->FontStyle = InfoOut.FontInfo.FontStyle;
2839
2840 if (IsFontInfoExisted (Private, FontInfo, &InfoOut.FontInfoMask, LocalFontHandle, &GlobalFont)) {
2841 //
2842 // Test to guarantee all characters are available in the found font.
2843 //
2844 if (String != NULL) {
2845 StringIn = String;
2846 while (*StringIn != 0) {
2847 Status = FindGlyphBlock (GlobalFont->FontPackage, *StringIn, NULL, NULL, NULL);
2848 if (EFI_ERROR (Status)) {
2849 LocalFontHandle = NULL;
2850 goto Exit;
2851 }
2852 StringIn++;
2853 }
2854 }
2855 //
2856 // Write to output parameter
2857 //
2858 if (StringInfoOut != NULL) {
2859 StringInfoOutLen = sizeof (EFI_FONT_DISPLAY_INFO) - sizeof (EFI_FONT_INFO) + GlobalFont->FontInfoSize;
2860 *StringInfoOut = (EFI_FONT_DISPLAY_INFO *) AllocateZeroPool (StringInfoOutLen);
2861 if (*StringInfoOut == NULL) {
2862 Status = EFI_OUT_OF_RESOURCES;
2863 LocalFontHandle = NULL;
2864 goto Exit;
2865 }
2866
2867 CopyMem (*StringInfoOut, &InfoOut, sizeof (EFI_FONT_DISPLAY_INFO));
2868 CopyMem (&(*StringInfoOut)->FontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);
2869 }
2870
2871 LocalFontHandle = GlobalFont->Entry.ForwardLink;
2872 Status = EFI_SUCCESS;
2873 goto Exit;
2874 }
2875
2876 Status = EFI_NOT_FOUND;
2877
2878 Exit:
2879
2880 if (FontHandle != NULL) {
2881 *FontHandle = LocalFontHandle;
2882 }
2883
2884 if (SystemDefault != NULL) {
2885 FreePool (SystemDefault);
2886 }
2887 if (FontInfo != NULL) {
2888 FreePool (FontInfo);
2889 }
2890 return Status;
2891 }
2892
2893