4 Copyright (c) 2004 - 2018, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "FrontPage.h"
12 EFI_GUID mFontPackageGuid
= {
13 0x78941450, 0x90ab, 0x4fb1, {0xb7, 0x5f, 0x58, 0x92, 0x14, 0xe2, 0x4a, 0xc}
16 #define NARROW_GLYPH_NUMBER 8
17 #define WIDE_GLYPH_NUMBER 75
21 /// This 4-bytes total array length is required by HiiAddPackages()
26 // This is the Font package definition
28 EFI_HII_PACKAGE_HEADER Header
;
29 UINT16 NumberOfNarrowGlyphs
;
30 UINT16 NumberOfWideGlyphs
;
31 EFI_NARROW_GLYPH NarrowArray
[NARROW_GLYPH_NUMBER
];
32 EFI_WIDE_GLYPH WideArray
[WIDE_GLYPH_NUMBER
];
35 FONT_PACK_BIN mFontBin
= {
36 sizeof (FONT_PACK_BIN
),
38 sizeof (FONT_PACK_BIN
) - sizeof (UINT32
),
39 EFI_HII_PACKAGE_SIMPLE_FONTS
,
248 Routine to export glyphs to the HII database. This is in addition to whatever is defined in the Graphics Console driver.
256 EFI_HII_HANDLE HiiHandle
;
258 HiiHandle
= HiiAddPackages (
264 ASSERT (HiiHandle
!= NULL
);
268 Get next language from language code list (with separator ';').
270 If LangCode is NULL, then ASSERT.
271 If Lang is NULL, then ASSERT.
273 @param LangCode On input: point to first language in the list. On
274 output: point to next language in the list, or
275 NULL if no more language in the list.
276 @param Lang The first language in the list.
282 IN OUT CHAR8
**LangCode
,
289 ASSERT (LangCode
!= NULL
);
290 ASSERT (*LangCode
!= NULL
);
291 ASSERT (Lang
!= NULL
);
294 StringPtr
= *LangCode
;
295 while (StringPtr
[Index
] != 0 && StringPtr
[Index
] != ';') {
299 CopyMem (Lang
, StringPtr
, Index
);
302 if (StringPtr
[Index
] == ';') {
305 *LangCode
= StringPtr
+ Index
;
309 Check if lang is in supported language codes according to language string.
311 This code is used to check if lang is in in supported language codes. It can handle
312 RFC4646 and ISO639 language tags.
313 In ISO639 language tags, take 3-characters as a delimitation to find matched string.
314 In RFC4646 language tags, take semicolon as a delimitation to find matched string.
317 SupportedLang = "engfraengfra"
318 Iso639Language = TRUE
319 Lang = "eng", the return value is "TRUE", or
320 Lang = "chs", the return value is "FALSE".
322 SupportedLang = "en;fr;en-US;fr-FR"
323 Iso639Language = FALSE
324 Lang = "en", the return value is "TRUE", or
325 Lang = "zh", the return value is "FALSE".
327 @param SupportedLang Platform supported language codes.
328 @param Lang Configured language.
329 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646.
331 @retval TRUE lang is in supported language codes.
332 @retval FALSE lang is not in supported language codes.
336 IsLangInSupportedLangCodes(
337 IN CHAR8
*SupportedLang
,
339 IN BOOLEAN Iso639Language
344 UINTN LanguageLength
;
346 if (Iso639Language
) {
347 CompareLength
= ISO_639_2_ENTRY_SIZE
;
348 for (Index
= 0; Index
< AsciiStrLen (SupportedLang
); Index
+= CompareLength
) {
349 if (AsciiStrnCmp (Lang
, SupportedLang
+ Index
, CompareLength
) == 0) {
351 // Successfully find the Lang string in SupportedLang string.
359 // Compare RFC4646 language code
361 for (LanguageLength
= 0; Lang
[LanguageLength
] != '\0'; LanguageLength
++);
363 for (; *SupportedLang
!= '\0'; SupportedLang
+= CompareLength
) {
365 // Skip ';' characters in SupportedLang
367 for (; *SupportedLang
!= '\0' && *SupportedLang
== ';'; SupportedLang
++);
369 // Determine the length of the next language code in SupportedLang
371 for (CompareLength
= 0; SupportedLang
[CompareLength
] != '\0' && SupportedLang
[CompareLength
] != ';'; CompareLength
++);
373 if ((CompareLength
== LanguageLength
) &&
374 (AsciiStrnCmp (Lang
, SupportedLang
, CompareLength
) == 0)) {
376 // Successfully find the Lang string in SupportedLang string.
386 Initialize Lang or PlatformLang variable, if Lang or PlatformLang variable is not found,
387 or it has been set to an unsupported value(not one of platform supported language codes),
388 set the default language code to it.
390 @param LangName Language name, L"Lang" or L"PlatformLang".
391 @param SupportedLang Platform supported language codes.
392 @param DefaultLang Default language code.
393 @param Iso639Language A bool value to signify if the handler is operated on ISO639 or RFC4646,
394 TRUE for L"Lang" LangName or FALSE for L"PlatformLang" LangName.
398 InitializeLangVariable (
400 IN CHAR8
*SupportedLang
,
401 IN CHAR8
*DefaultLang
,
402 IN BOOLEAN Iso639Language
408 // Find current Lang or PlatformLang from EFI Variable.
410 GetEfiGlobalVariable2 (LangName
, (VOID
**) &Lang
, NULL
);
412 // If Lang or PlatformLang variable is not found,
413 // or it has been set to an unsupported value(not one of the supported language codes),
414 // set the default language code to it.
416 if ((Lang
== NULL
) || !IsLangInSupportedLangCodes (SupportedLang
, Lang
, Iso639Language
)) {
418 // The default language code should be one of the supported language codes.
420 ASSERT (IsLangInSupportedLangCodes (SupportedLang
, DefaultLang
, Iso639Language
));
421 BdsDxeSetVariableAndReportStatusCodeOnError (
423 &gEfiGlobalVariableGuid
,
424 EFI_VARIABLE_NON_VOLATILE
| EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
425 AsciiStrSize (DefaultLang
),
436 Determine the current language that will be used
437 based on language related EFI Variables.
439 @param LangCodesSettingRequired - If required to set LangCodes variable
444 BOOLEAN LangCodesSettingRequired
449 CHAR8
*PlatformLangCodes
;
453 LangCodes
= (CHAR8
*)PcdGetPtr (PcdUefiVariableDefaultLangCodes
);
454 PlatformLangCodes
= (CHAR8
*)PcdGetPtr (PcdUefiVariableDefaultPlatformLangCodes
);
455 if (LangCodesSettingRequired
) {
456 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate
)) {
458 // UEFI 2.0 depricated this variable so we support turning it off
460 Status
= gRT
->SetVariable (
462 &gEfiGlobalVariableGuid
,
463 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
464 AsciiStrSize (LangCodes
),
468 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
470 ASSERT_EFI_ERROR (Status
);
473 Status
= gRT
->SetVariable (
474 L
"PlatformLangCodes",
475 &gEfiGlobalVariableGuid
,
476 EFI_VARIABLE_BOOTSERVICE_ACCESS
| EFI_VARIABLE_RUNTIME_ACCESS
,
477 AsciiStrSize (PlatformLangCodes
),
481 // Platform needs to make sure setting volatile variable before calling 3rd party code shouldn't fail.
483 ASSERT_EFI_ERROR (Status
);
486 if (!FeaturePcdGet (PcdUefiVariableDefaultLangDeprecate
)) {
488 // UEFI 2.0 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
);