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