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