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