117 IN CONST CHAR8 *FontName,
128 CHAR8 *TrimmedLineEnd;
138 UINT16 CurrentPageNumber;
146 UINT16 PageSparseCount;
147 UINT8 GlyphSparseCount;
148 BOOLEAN FoundNonZero;
149 UINT32 GlyphOffsetsSize;
150 UINT32 GlyphDataSize;
152 UINTN FontHeaderSize;
154 UINTN FontPageOffsetsSize;
156 UINT16 *FontPageOffsets;
159 UINT16 *SavedFontPageOffsets;
160 UINT8 *SavedGlyphOffsets;
161 UINT8 *SavedGlyphData;
173 if (EFI_ERROR (Status)) {
174 DEBUG ((DEBUG_WARN,
"OCC: Cannot fit %a\n", FontName));
175 return EFI_OUT_OF_RESOURCES;
179 if (HexFontFile == NULL) {
180 return EFI_NOT_FOUND;
185 if (FlexFontPages == NULL) {
186 FreePool (HexFontFile);
187 return EFI_OUT_OF_RESOURCES;
190 for (Pass = 1; Pass <= 2; Pass++) {
193 CurrentPageNumber = MAX_UINT16;
196 GlyphOffsetsSize = 0;
198 NextLine = HexFontFile;
202 CurrentLine = NextLine;
208 while (*CurrentLine !=
'\n' &&
OcIsSpace (*CurrentLine)) {
212 Finished = (*CurrentLine ==
'\0');
215 NextLine = AsciiStrStr (CurrentLine,
"\n");
216 if (NextLine == NULL) {
217 NextLine = &CurrentLine[AsciiStrLen (CurrentLine)];
222 if (*CurrentLine ==
'#') {
229 TrimmedLineEnd = NextLine - 1;
230 while (TrimmedLineEnd >= CurrentLine &&
OcIsSpace (*TrimmedLineEnd)) {
236 if (TrimmedLineEnd == CurrentLine) {
242 Status = EFI_UNSUPPORTED;
247 if (EFI_ERROR (Status)) {
251 PageNumber = (Char >> 7) & 0x1FF;
252 PageChar = Char & 0x7F;
255 if (Finished || (PageNumber != CurrentPageNumber)) {
259 if (CurrentPageNumber != MAX_UINT16) {
262 if (FontPage == NULL) {
263 Status = EFI_OUT_OF_RESOURCES;
267 FontPage->
CharMin = PageCharMin;
268 FontPage->
CharMax = PageCharMax;
282 GlyphDataSize += (
ISO_CHAR_HEIGHT - FontPageHead - FontPageTail) * GlyphSparseCount;
283 if (GlyphSparseCount < PageCharMax - PageCharMin) {
284 GlyphOffsetsSize += (PageCharMax - PageCharMin);
287 if (GlyphSparseCount < PageCharMax - PageCharMin) {
288 GlyphOffsets += (PageCharMax - PageCharMin);
297 CurrentPageNumber = PageNumber;
299 if (FontPageMax == 0) {
300 FontPageMin = CurrentPageNumber;
301 FontPageMax = CurrentPageNumber + 1;
302 }
else if (CurrentPageNumber >= FontPageMax) {
303 FontPageMax = CurrentPageNumber + 1;
306 Status = EFI_UNSUPPORTED;
312 PageCharMin = PageChar;
317 FontPage = FontPages;
325 if (FontPageOffsets != NULL) {
326 ASSERT ((UINT8 *)&FontPageOffsets[CurrentPageNumber - FontPageMin] < SavedGlyphOffsets);
327 FontPageOffsets[CurrentPageNumber - FontPageMin] = PageSparseCount;
330 FontPage->
Glyphs = GlyphData;
340 PageCharMax = PageCharMin + 1;
341 GlyphSparseCount = 0;
342 }
else if (PageChar >= PageCharMax) {
343 PageCharMax = PageChar + 1;
346 Status = EFI_UNSUPPORTED;
355 FoundNonZero = FALSE;
357 if (LineGlyphData[Line] != 0) {
367 if (GlyphHead < FontPageHead) {
368 FontPageHead = GlyphHead;
371 if (GlyphTail < FontPageTail) {
372 FontPageTail = GlyphTail;
376 FontPage->
GlyphOffsets[PageChar - PageCharMin] = GlyphSparseCount;
384 ASSERT ((FlexFontPages != NULL) == (Pass == 1));
385 ASSERT ((*Font != NULL) == (Pass == 2));
387 if (EFI_ERROR (Status)) {
395 FontPageOffsetsSize =
396 ((FontPageMax - FontPageMin) == PageSparseCount)
398 : ((FontPageMax - FontPageMin) *
sizeof (UINT16));
403 FontPageOffsetsSize +
410 *Font = AllocateZeroPool (FontSize);
413 return EFI_OUT_OF_RESOURCES;
416 DEBUG ((DEBUG_INFO,
"OCC: Hex font allocated size %u\n", FontSize));
418 FontPages = (VOID *)((UINT8 *)(*Font) + FontHeaderSize);
419 SavedFontPageOffsets = FontPageOffsets = (VOID *)((UINT8 *)FontPages + FontPagesSize);
420 SavedGlyphOffsets = GlyphOffsets = (VOID *)((UINT8 *)FontPageOffsets + FontPageOffsetsSize);
421 SavedGlyphData = GlyphData = (VOID *)((UINT8 *)GlyphOffsets + GlyphOffsetsSize);
422 SavedEnd = (UINT8 *)GlyphData + GlyphDataSize;
424 if (FontPageOffsetsSize == 0) {
425 FontPageOffsets = NULL;
428 if (GlyphOffsetsSize == 0) {
432 (*Font)->PageMin = FontPageMin;
433 (*Font)->PageMax = FontPageMax;
434 (*Font)->Pages = FontPages;
435 (*Font)->PageOffsets = FontPageOffsets;
445 ASSERT ((UINT8 *)FontPages == (UINT8 *)SavedFontPageOffsets);
446 ASSERT (GlyphOffsets == NULL ? (UINT8 *)SavedGlyphOffsets == (UINT8 *)SavedFontPageOffsets : (UINT8 *)GlyphOffsets == (UINT8 *)SavedGlyphData);
447 ASSERT (GlyphData == SavedEnd);
451 FreePool (HexFontFile);
453 if (!EFI_ERROR (Status)) {
455 Status = EFI_UNSUPPORTED;
460 if (EFI_ERROR (Status)) {
461 if (FlexFontPages != NULL) {