4 Copyright (c) 2004 - 2014, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
16 #include "FrontPage.h"
18 EFI_GUID mFontPackageGuid
= {
19 0x78941450, 0x90ab, 0x4fb1, {0xb7, 0x5f, 0x58, 0x92, 0x14, 0xe2, 0x4a, 0xc}
22 #define NARROW_GLYPH_NUMBER 8
23 #define WIDE_GLYPH_NUMBER 75
27 /// This 4-bytes total array length is required by HiiAddPackages()
32 // This is the Font package definition
34 EFI_HII_PACKAGE_HEADER Header
;
35 UINT16 NumberOfNarrowGlyphs
;
36 UINT16 NumberOfWideGlyphs
;
37 EFI_NARROW_GLYPH NarrowArray
[NARROW_GLYPH_NUMBER
];
38 EFI_WIDE_GLYPH WideArray
[WIDE_GLYPH_NUMBER
];
41 FONT_PACK_BIN mFontBin
= {
42 sizeof (FONT_PACK_BIN
),
44 sizeof (FONT_PACK_BIN
) - sizeof (UINT32
),
45 EFI_HII_PACKAGE_SIMPLE_FONTS
,
254 Routine to export glyphs to the HII database. This is in addition to whatever is defined in the Graphics Console driver.
262 EFI_HII_HANDLE HiiHandle
;
264 HiiHandle
= HiiAddPackages (
270 ASSERT (HiiHandle
!= NULL
);
274 Get next language from language code list (with separator ';').
276 If LangCode is NULL, then ASSERT.
277 If Lang is NULL, then ASSERT.
279 @param LangCode On input: point to first language in the list. On
280 output: point to next language in the list, or
281 NULL if no more language in the list.
282 @param Lang The first language in the list.
288 IN OUT CHAR8
**LangCode
,
295 ASSERT (LangCode
!= NULL
);
296 ASSERT (*LangCode
!= NULL
);
297 ASSERT (Lang
!= NULL
);
300 StringPtr
= *LangCode
;
301 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
305 CopyMem (Lang
, StringPtr
, Index
);
308 if (StringPtr
[Index
] == ';') {
311 *LangCode
= StringPtr
+ Index
;
315 Check if lang is in supported language codes according to language string.
317 This code is used to check if lang is in in supported language codes. It can handle
318 RFC4646 and ISO639 language tags.
319 In ISO639 language tags, take 3-characters as a delimitation to find matched string.
320 In RFC4646 language tags, take semicolon as a delimitation to find matched string.
323 SupportedLang = "engfraengfra"
324 Iso639Language = TRUE
325 Lang = "eng", the return value is "TRUE", or
326 Lang = "chs", the return value is "FALSE".
328 SupportedLang = "en;fr;en-US;fr-FR"
329 Iso639Language = FALSE
330 Lang = "en", the return value is "TRUE", or
331 Lang = "zh", the return value is "FALSE".
333 @param SupportedLang Platform supported language codes.
334 @param Lang Configured language.
335 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646.
337 @retval TRUE lang is in supported language codes.
338 @retval FALSE lang is not in supported language codes.
342 IsLangInSupportedLangCodes(
343 IN CHAR8
*SupportedLang
,
345 IN BOOLEAN Iso639Language
350 UINTN LanguageLength
;
352 if (Iso639Language
) {
353 CompareLength
= ISO_639_2_ENTRY_SIZE
;
354 for (Index
= 0; Index
< AsciiStrLen (SupportedLang
); Index
+= CompareLength
) {
355 if (AsciiStrnCmp (Lang
, SupportedLang
+ Index
, CompareLength
) == 0) {
357 // Successfully find the Lang string in SupportedLang string.
365 // Compare RFC4646 language code
367 for (LanguageLength
= 0; Lang
[LanguageLength
] != '\0'; LanguageLength
++);
369 for (; *SupportedLang
!= '\0'; SupportedLang
+= CompareLength
) {
371 // Skip ';' characters in SupportedLang
373 for (; *SupportedLang
!= '\0' && *SupportedLang
== ';'; SupportedLang
++);
375 // Determine the length of the next language code in SupportedLang
377 for (CompareLength
= 0; SupportedLang
[CompareLength
] != '\0' && SupportedLang
[CompareLength
] != ';'; CompareLength
++);
379 if ((CompareLength
== LanguageLength
) &&
380 (AsciiStrnCmp (Lang
, SupportedLang
, CompareLength
) == 0)) {
382 // Successfully find the Lang string in SupportedLang string.
392 Initialize Lang or PlatformLang variable, if Lang or PlatformLang variable is not found,
393 or it has been set to an unsupported value(not one of platform supported language codes),
394 set the default language code to it.
396 @param LangName Language name, L"Lang" or L"PlatformLang".
397 @param SupportedLang Platform supported language codes.
398 @param DefaultLang Default language code.
399 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646,
400 TRUE for L"Lang" LangName or FALSE for L"PlatformLang" LangName.
404 InitializeLangVariable (
406 IN CHAR8
*SupportedLang
,
407 IN CHAR8
*DefaultLang
,
408 IN BOOLEAN Iso639Language
414 // Find current Lang or PlatformLang from EFI Variable.
416 GetEfiGlobalVariable2 (LangName
, (VOID
**) &Lang
, NULL
);
418 // If Lang or PlatformLang variable is not found,
419 // or it has been set to an unsupported value(not one of the supported language codes),
420 // set the default language code to it.
422 if ((Lang
== NULL
) || !IsLangInSupportedLangCodes (SupportedLang
, Lang
, Iso639Language
)) {
424 // The default language code should be one of the supported language codes.
426 ASSERT (IsLangInSupportedLangCodes (SupportedLang
, DefaultLang
, Iso639Language
));
427 BdsDxeSetVariableAndReportStatusCodeOnError (
429 &gEfiGlobalVariableGuid
,
430 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
431 AsciiStrSize (DefaultLang
),
442 Determine the current language that will be used
443 based on language related EFI Variables.
445 @param LangCodesSettingRequired - If required to set LangCodes variable
450 BOOLEAN LangCodesSettingRequired
455 CHAR8
*PlatformLangCodes
;
459 LangCodes
= (CHAR8
*)PcdGetPtr (PcdUefiVariableDefaultLangCodes
);
460 PlatformLangCodes
= (CHAR8
*)PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
);
461 if (LangCodesSettingRequired
) {
462 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate
)) {
464 // UEFI 2.0 depricated this variable so we support turning it off
466 Status
= gRT
->SetVariable (
468 &gEfiGlobalVariableGuid
,
469 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
470 AsciiStrSize (LangCodes
),
474 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
476 ASSERT_EFI_ERROR (Status
);
479 Status
= gRT
->SetVariable (
480 L
"PlatformLangCodes",
481 &gEfiGlobalVariableGuid
,
482 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
483 AsciiStrSize (PlatformLangCodes
),
487 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
489 ASSERT_EFI_ERROR (Status
);
492 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate
)) {
494 // UEFI 2.0 depricated this variable so we support turning it off
496 InitializeLangVariable (L
"Lang", LangCodes
, (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
), TRUE
);
498 InitializeLangVariable (L
"PlatformLang", PlatformLangCodes
, (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
), FALSE
);