]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c
Change the status code to EFI_NOT_FOUND for Framework Hii's GetGlyph if EFI_WARN_UNKN...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Fonts.c
1 /**@file
2 This file contains the Glyph related function.
3
4 Copyright (c) 2006 - 2008, Intel Corporation
5 All rights reserved. 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
9
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.
12
13 **/
14
15
16 #include "HiiDatabase.h"
17
18 EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}};
19
20 BOOLEAN mSysFontColorCached = FALSE;
21 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mSysFGColor = {0};
22
23
24 /**
25 This function is only called by Graphics Console module and GraphicsLib.
26 EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib
27 complying to UEFI HII.
28
29 This function will ASSERT and return EFI_UNSUPPORTED.
30
31 @param This N.A.
32 @param Source N.A.
33 @param Index N.A.
34 @param GlyphBuffer N.A.
35 @param BitWidth N.A.
36 @param InternalStatus N.A.
37
38 @return EFI_UNSUPPORTED N.A.
39
40 **/
41 EFI_STATUS
42 EFIAPI
43 HiiGetGlyph (
44 IN EFI_HII_PROTOCOL *This,
45 IN CHAR16 *Source,
46 IN OUT UINT16 *Index,
47 OUT UINT8 **GlyphBuffer,
48 OUT UINT16 *BitWidth,
49 IN OUT UINT32 *InternalStatus
50 )
51 {
52 EFI_STATUS Status;
53 EFI_IMAGE_OUTPUT *Blt;
54 EFI_FONT_DISPLAY_INFO *FontInfo;
55 UINTN Xpos;
56 UINTN Ypos;
57 UINTN BaseLine;
58
59 if (!mSysFontColorCached) {
60 //
61 // Cache the system font's foreground color.
62 //
63 Status = mHiiFontProtocol->GetFontInfo (
64 mHiiFontProtocol,
65 NULL,
66 NULL,
67 &FontInfo,
68 NULL
69 );
70
71 if (!EFI_ERROR (Status)) {
72 ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0);
73 mSysFGColor = FontInfo->ForegroundColor;
74 FreePool (FontInfo);
75
76 mSysFontColorCached = TRUE;
77 }
78
79 }
80
81 Blt = NULL;
82 Status = mHiiFontProtocol->GetGlyph (
83 mHiiFontProtocol,
84 Source[*Index],
85 NULL,
86 &Blt,
87 &BaseLine
88 );
89
90 if (!EFI_ERROR (Status) && (Status != EFI_WARN_UNKNOWN_GLYPH)) {
91 //
92 // For simplicity, we only handle Narrow Glyph.
93 //
94 if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) {
95
96 ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer));
97 mNarrowGlyphBuffer.UnicodeWeight = *Source;
98 for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) {
99 for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) {
100 if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) {
101 mNarrowGlyphBuffer.GlyphCol1[Ypos] |= 1 << (EFI_GLYPH_WIDTH - 1 - Xpos);
102 }
103 }
104 }
105
106 *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer;
107 *BitWidth = EFI_GLYPH_WIDTH;
108 *Index += 1;
109 } else {
110 Status = EFI_NOT_FOUND;
111 }
112
113 }
114
115 if (EFI_ERROR (Status) || (Status == EFI_WARN_UNKNOWN_GLYPH)) {
116 if (Status == EFI_WARN_UNKNOWN_GLYPH) {
117 Status = EFI_NOT_FOUND;
118 }
119 *GlyphBuffer = NULL;
120 }
121 return Status;
122 }
123
124 /**
125 This function is only called by Graphics Console module and GraphicsLib.
126 EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib
127 complying to UEFI HII.
128
129 This function will ASSERT and return EFI_UNSUPPORTED.
130
131 @param This N.A.
132 @param GlyphBuffer N.A.
133 @param Foreground N.A.
134 @param Background N.A.
135 @param Count N.A.
136 @param Width N.A.
137 @param Height N.A.
138 @param BltBuffer N.A.
139
140 @return EFI_UNSUPPORTED N.A.
141
142 **/
143 EFI_STATUS
144 EFIAPI
145 HiiGlyphToBlt (
146 IN EFI_HII_PROTOCOL *This,
147 IN UINT8 *GlyphBuffer,
148 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
149 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
150 IN UINTN Count,
151 IN UINTN Width,
152 IN UINTN Height,
153 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer
154 )
155 {
156 UINTN X;
157 UINTN Y;
158
159 //
160 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
161 //
162 for (Y = 0; Y < Height; Y++) {
163 for (X = 0; X < Width; X++) {
164 if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {
165 BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;
166 } else {
167 BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;
168 }
169 }
170 }
171
172 return EFI_SUCCESS;
173 }