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