4 Copyright (c) 2004 - 2013, 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.
405 InitializeLangVariable (
407 IN CHAR8
*SupportedLang
,
408 IN CHAR8
*DefaultLang
,
409 IN BOOLEAN Iso639Language
416 // Find current Lang or PlatformLang from EFI Variable.
418 Status
= GetEfiGlobalVariable2 (LangName
, &Lang
, NULL
);
420 // If Lang or PlatformLang variable is not found,
421 // or it has been set to an unsupported value(not one of the supported language codes),
422 // set the default language code to it.
424 if (EFI_ERROR (Status
) || !IsLangInSupportedLangCodes (SupportedLang
, Lang
, Iso639Language
)) {
426 // The default language code should be one of the supported language codes.
428 ASSERT (IsLangInSupportedLangCodes (SupportedLang
, DefaultLang
, Iso639Language
));
429 Status
= gRT
->SetVariable (
431 &gEfiGlobalVariableGuid
,
432 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
433 AsciiStrSize (DefaultLang
),
444 Determine the current language that will be used
445 based on language related EFI Variables.
447 @param LangCodesSettingRequired - If required to set LangCodes variable
452 BOOLEAN LangCodesSettingRequired
457 CHAR8
*PlatformLangCodes
;
461 LangCodes
= (CHAR8
*)PcdGetPtr (PcdUefiVariableDefaultLangCodes
);
462 PlatformLangCodes
= (CHAR8
*)PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
);
463 if (LangCodesSettingRequired
) {
464 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate
)) {
466 // UEFI 2.1 depricated this variable so we support turning it off
468 Status
= gRT
->SetVariable (
470 &gEfiGlobalVariableGuid
,
471 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
472 AsciiStrSize (LangCodes
),
477 Status
= gRT
->SetVariable (
478 L
"PlatformLangCodes",
479 &gEfiGlobalVariableGuid
,
480 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
481 AsciiStrSize (PlatformLangCodes
),
486 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate
)) {
488 // UEFI 2.1 depricated this variable so we support turning it off
490 InitializeLangVariable (L
"Lang", LangCodes
, (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultLang
), TRUE
);
492 InitializeLangVariable (L
"PlatformLang", PlatformLangCodes
, (CHAR8
*) PcdGetPtr (PcdUefiVariableDefaultPlatformLang
), FALSE
);