]> git.proxmox.com Git - mirror_edk2.git/blame_incremental - MdeModulePkg/Universal/HiiDatabaseDxe/String.c
UEFI HII: Merge UEFI HII support changes from branch.
[mirror_edk2.git] / MdeModulePkg / Universal / HiiDatabaseDxe / String.c
... / ...
CommitLineData
1/** @file\r
2\r
3Copyright (c) 2007, Intel Corporation\r
4All rights reserved. This program and the accompanying materials\r
5are licensed and made available under the terms and conditions of the BSD License\r
6which accompanies this distribution. The full text of the license may be found at\r
7http://opensource.org/licenses/bsd-license.php\r
8\r
9THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r
10WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r
11\r
12Module Name:\r
13\r
14 String.c\r
15\r
16Abstract:\r
17\r
18 Implementation for EFI_HII_STRING_PROTOCOL.\r
19\r
20Revision History\r
21\r
22\r
23**/\r
24\r
25\r
26#include "HiiDatabase.h"\r
27\r
28CHAR16 mLanguageWindow[16] = {\r
29 0x0000, 0x0080, 0x0100, 0x0300,\r
30 0x2000, 0x2080, 0x2100, 0x3000,\r
31 0x0080, 0x00C0, 0x0400, 0x0600,\r
32 0x0900, 0x3040, 0x30A0, 0xFF00\r
33};\r
34\r
35\r
36/**\r
37 This function checks whether a global font info is referred by local\r
38 font info list or not. (i.e. HII_FONT_INFO is generated.) If not, create\r
39 a HII_FONT_INFO to refer it locally.\r
40\r
41 @param Private Hii database private structure.\r
42 @param StringPackage HII string package instance.\r
43 @param DuplicateEnable If true, duplicate HII_FONT_INFO which refers to\r
44 the same EFI_FONT_INFO is permitted. Otherwise it\r
45 is not allowed.\r
46 @param GlobalFontInfo Input a global font info which specify a\r
47 EFI_FONT_INFO.\r
48 @param LocalFontInfo Output a local font info which refers to a\r
49 EFI_FONT_INFO.\r
50\r
51 @retval TRUE Already referred before calling this function.\r
52 @retval FALSE Not referred before calling this function.\r
53\r
54**/\r
55STATIC\r
56BOOLEAN\r
57ReferFontInfoLocally (\r
58 IN HII_DATABASE_PRIVATE_DATA *Private,\r
59 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
60 IN BOOLEAN DuplicateEnable,\r
61 IN HII_GLOBAL_FONT_INFO *GlobalFontInfo,\r
62 OUT HII_FONT_INFO **LocalFontInfo\r
63 )\r
64{\r
65 HII_FONT_INFO *LocalFont;\r
66 LIST_ENTRY *Link;\r
67\r
68 ASSERT (Private != NULL && StringPackage != NULL && GlobalFontInfo != NULL && LocalFontInfo != NULL);\r
69\r
70 if (!DuplicateEnable) {\r
71 for (Link = StringPackage->FontInfoList.ForwardLink;\r
72 Link != &StringPackage->FontInfoList;\r
73 Link = Link->ForwardLink\r
74 ) {\r
75 LocalFont = CR (Link, HII_FONT_INFO, Entry, HII_FONT_INFO_SIGNATURE);\r
76 if (LocalFont->GlobalEntry == &GlobalFontInfo->Entry) {\r
77 //\r
78 // Already referred by local font info list, return directly.\r
79 //\r
80 *LocalFontInfo = LocalFont;\r
81 return TRUE;\r
82 }\r
83 }\r
84 }\r
85 //\r
86 // Since string package tool set FontId initially to 0 and increases it\r
87 // progressively by one, StringPackage->FondId always represents an unique\r
88 // and available FontId.\r
89 //\r
90 // FontId identifies EFI_FONT_INFO in local string package uniquely.\r
91 // GlobalEntry points to a HII_GLOBAL_FONT_INFO which identifies\r
92 // EFI_FONT_INFO uniquely in whole hii database.\r
93 //\r
94 LocalFont = (HII_FONT_INFO *) AllocateZeroPool (sizeof (HII_FONT_INFO));\r
95 ASSERT (LocalFont != NULL);\r
96\r
97 LocalFont->Signature = HII_FONT_INFO_SIGNATURE;\r
98 LocalFont->FontId = StringPackage->FontId;\r
99 LocalFont->GlobalEntry = &GlobalFontInfo->Entry;\r
100 InsertTailList (&StringPackage->FontInfoList, &LocalFont->Entry);\r
101\r
102 StringPackage->FontId++;\r
103\r
104 *LocalFontInfo = LocalFont;\r
105 return FALSE;\r
106}\r
107\r
108\r
109/**\r
110 Convert Ascii string text to unicode string test.\r
111\r
112 @param StringSrc Points to current null-terminated Ascii string.\r
113 @param StringDest Buffer to store the converted string text.\r
114 @param BufferSize Length of the buffer.\r
115\r
116 @retval EFI_SUCCESS The string text was outputed successfully.\r
117 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string\r
118 text. BufferSize is updated to the required buffer\r
119 size.\r
120\r
121**/\r
122STATIC\r
123EFI_STATUS\r
124ConvertToUnicodeText (\r
125 OUT EFI_STRING StringDest,\r
126 IN CHAR8 *StringSrc,\r
127 IN OUT UINTN *BufferSize\r
128 )\r
129{\r
130 UINTN StringSize;\r
131 UINTN Index;\r
132\r
133 ASSERT (StringSrc != NULL && BufferSize != NULL);\r
134\r
135 StringSize = AsciiStrSize (StringSrc) * 2;\r
136 if (*BufferSize < StringSize) {\r
137 *BufferSize = StringSize;\r
138 return EFI_BUFFER_TOO_SMALL;\r
139 }\r
140\r
141 for (Index = 0; Index < AsciiStrLen (StringSrc); Index++) {\r
142 StringDest[Index] = (CHAR16) StringSrc[Index];\r
143 }\r
144\r
145 StringDest[Index] = 0;\r
146 return EFI_SUCCESS;\r
147}\r
148\r
149\r
150/**\r
151 Calculate the size of StringSrc and output it. If StringDest is not NULL,\r
152 copy string text from src to dest.\r
153\r
154 @param StringSrc Points to current null-terminated string.\r
155 @param StringDest Buffer to store the string text.\r
156 @param BufferSize Length of the buffer.\r
157\r
158 @retval EFI_SUCCESS The string text was outputed successfully.\r
159 @retval EFI_BUFFER_TOO_SMALL Buffer is insufficient to store the found string\r
160 text. BufferSize is updated to the required buffer\r
161 size.\r
162\r
163**/\r
164STATIC\r
165EFI_STATUS\r
166GetUnicodeStringTextOrSize (\r
167 OUT EFI_STRING StringDest, OPTIONAL\r
168 IN UINT8 *StringSrc,\r
169 IN OUT UINTN *BufferSize\r
170 )\r
171{\r
172 UINTN StringSize;\r
173 CHAR16 Zero;\r
174 UINT8 *StringPtr;\r
175\r
176 ASSERT (StringSrc != NULL && BufferSize != NULL);\r
177\r
178 ZeroMem (&Zero, sizeof (CHAR16));\r
179 StringSize = sizeof (CHAR16);\r
180 StringPtr = StringSrc;\r
181 while (CompareMem (StringPtr, &Zero, sizeof (CHAR16)) != 0) {\r
182 StringSize += sizeof (CHAR16);\r
183 StringPtr += sizeof (CHAR16);\r
184 }\r
185\r
186 if (StringDest != NULL) {\r
187 if (*BufferSize < StringSize) {\r
188 *BufferSize = StringSize;\r
189 return EFI_BUFFER_TOO_SMALL;\r
190 }\r
191 CopyMem (StringDest, StringSrc, StringSize);\r
192 return EFI_SUCCESS;\r
193 }\r
194\r
195 *BufferSize = StringSize;\r
196 return EFI_SUCCESS;\r
197}\r
198\r
199\r
200/**\r
201 Copy string font info to a buffer.\r
202\r
203 @param StringPackage Hii string package instance.\r
204 @param FontId Font identifier which is unique in a string\r
205 package.\r
206 @param StringFontInfo Buffer to record the output font info. It's\r
207 caller's responsibility to free this buffer.\r
208\r
209 @retval EFI_SUCCESS The string font is outputed successfully.\r
210 @retval EFI_NOT_FOUND The specified font id does not exist.\r
211\r
212**/\r
213STATIC\r
214EFI_STATUS\r
215GetStringFontInfo (\r
216 IN HII_STRING_PACKAGE_INSTANCE *StringPackage,\r
217 IN UINT8 FontId,\r
218 OUT EFI_FONT_INFO **StringFontInfo\r
219 )\r
220{\r
221 LIST_ENTRY *Link;\r
222 HII_FONT_INFO *FontInfo;\r
223 HII_GLOBAL_FONT_INFO *GlobalFont;\r
224\r
225 ASSERT (StringFontInfo != NULL && StringPackage != NULL);\r
226\r
227 for (Link = StringPackage->FontInfoList.ForwardLink; Link != &StringPackage->FontInfoList; Link = Link->ForwardLink) {\r
228 FontInfo = CR (Link, HII_FONT_INFO, Entry, HII_FONT_INFO_SIGNATURE);\r
229 if (FontInfo->FontId == FontId) {\r
230 GlobalFont = CR (FontInfo->GlobalEntry, HII_GLOBAL_FONT_INFO, Entry, HII_GLOBAL_FONT_INFO_SIGNATURE);\r
231 *StringFontInfo = (EFI_FONT_INFO *) AllocateZeroPool (GlobalFont->FontInfoSize);\r
232 if (*StringFontInfo == NULL) {\r
233 return EFI_OUT_OF_RESOURCES;\r
234 }\r
235 CopyMem (*StringFontInfo, GlobalFont->FontInfo, GlobalFont->FontInfoSize);\r
236 return EFI_SUCCESS;\r
237 }\r
238 }\r
239\r
240 return EFI_NOT_FOUND;\r
241}\r
242\r
243\r
244/**\r
245 Parse all string blocks to find a String block specified by StringId.\r
246 If StringId = (EFI_STRING_ID) (-1), find out all EFI_HII_SIBT_FONT blocks\r
247 within this string package and backup its information.\r
248 If StringId = 0, output the string id of last string block (EFI_HII_SIBT_END).\r
249\r
250 @param Private Hii database private structure.\r
251 @param StringPackage Hii string package instance.\r
252