]>
Commit | Line | Data |
---|---|---|
4259256b | 1 | /**@file\r |
4259256b | 2 | This file contains the Glyph related function.\r |
3 | \r | |
4 | Copyright (c) 2006 - 2008, Intel Corporation\r | |
5 | All rights reserved. This program and the accompanying materials\r | |
6 | are licensed and made available under the terms and conditions of the BSD License\r | |
7 | which accompanies this distribution. The full text of the license may be found at\r | |
8 | http://opensource.org/licenses/bsd-license.php\r | |
9 | \r | |
10 | THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,\r | |
11 | WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.\r | |
12 | \r | |
13 | **/\r | |
14 | \r | |
15 | \r | |
16 | #include "HiiDatabase.h"\r | |
17 | \r | |
133a9dfb | 18 | EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}};\r |
19 | \r | |
20 | BOOLEAN mSysFontColorCached = FALSE;\r | |
21 | EFI_GRAPHICS_OUTPUT_BLT_PIXEL mSysFGColor = {0};\r | |
59336178 | 22 | \r |
59336178 | 23 | \r |
0368663f | 24 | /**\r |
a9d85320 | 25 | Translates a Unicode character into the corresponding font glyph.\r |
0368663f | 26 | \r |
a9d85320 | 27 | Notes:\r |
28 | This function is only called by Graphics Console module and GraphicsLib. \r | |
29 | Wrap the Framework HII GetGlyph function to UEFI Font Protocol.\r | |
30 | \r | |
31 | EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib \r | |
32 | complying to UEFI HII.\r | |
33 | \r | |
34 | @param This A pointer to the EFI_HII_PROTOCOL instance.\r | |
35 | @param Source A pointer to a Unicode string.\r | |
36 | @param Index On input, the offset into the string from which to fetch the character. On successful completion, the \r | |
37 | index is updated to the first character past the character(s) making up the just extracted glyph. \r | |
38 | @param GlyphBuffer Pointer to an array where the glyphs corresponding to the characters in the source may be stored. \r | |
39 | GlyphBuffer is assumed to be wide enough to accept a wide glyph character.\r | |
40 | @param BitWidth If EFI_SUCCESS was returned, the UINT16 pointed to by this value is filled with the length of the glyph in pixels. \r | |
41 | It is unchanged if the call was unsuccessful.\r | |
42 | @param InternalStatus To save the time required to read the string from the beginning on each glyph extraction \r | |
43 | (for example, to ensure that the narrow versus wide glyph mode is correct), this value is \r | |
44 | updated each time the function is called with the status that is local to the call. The cell pointed \r | |
45 | to by this parameter must be initialized to zero prior to invoking the call the first time for any string.\r | |
46 | \r | |
47 | @retval EFI_SUCCESS It worked.\r | |
48 | @retval EFI_NOT_FOUND A glyph for a character was not found.\r | |
49 | \r | |
0368663f | 50 | \r |
51 | **/\r | |
4259256b | 52 | EFI_STATUS\r |
53 | EFIAPI\r | |
54 | HiiGetGlyph (\r | |
55 | IN EFI_HII_PROTOCOL *This,\r | |
56 | IN CHAR16 *Source,\r | |
57 | IN OUT UINT16 *Index,\r | |
58 | OUT UINT8 **GlyphBuffer,\r | |
59 | OUT UINT16 *BitWidth,\r | |
60 | IN OUT UINT32 *InternalStatus\r | |
61 | )\r | |
4259256b | 62 | {\r |
133a9dfb | 63 | EFI_STATUS Status;\r |
64 | EFI_IMAGE_OUTPUT *Blt;\r | |
65 | EFI_FONT_DISPLAY_INFO *FontInfo;\r | |
66 | UINTN Xpos;\r | |
67 | UINTN Ypos;\r | |
68 | UINTN BaseLine;\r | |
69 | \r | |
70 | if (!mSysFontColorCached) {\r | |
71 | //\r | |
72 | // Cache the system font's foreground color.\r | |
73 | //\r | |
74 | Status = mHiiFontProtocol->GetFontInfo (\r | |
75 | mHiiFontProtocol,\r | |
76 | NULL,\r | |
77 | NULL,\r | |
78 | &FontInfo,\r | |
79 | NULL\r | |
80 | );\r | |
81 | \r | |
82 | if (!EFI_ERROR (Status)) {\r | |
83 | ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0);\r | |
84 | mSysFGColor = FontInfo->ForegroundColor;\r | |
85 | FreePool (FontInfo);\r | |
86 | \r | |
87 | mSysFontColorCached = TRUE;\r | |
88 | }\r | |
89 | \r | |
90 | }\r | |
91 | \r | |
92 | Blt = NULL;\r | |
93 | Status = mHiiFontProtocol->GetGlyph (\r | |
94 | mHiiFontProtocol,\r | |
95 | Source[*Index],\r | |
96 | NULL,\r | |
97 | &Blt,\r | |
98 | &BaseLine\r | |
99 | );\r | |
100 | \r | |
bc3fc71a | 101 | if (!EFI_ERROR (Status) && (Status != EFI_WARN_UNKNOWN_GLYPH)) {\r |
133a9dfb | 102 | //\r |
103 | // For simplicity, we only handle Narrow Glyph.\r | |
104 | //\r | |
133a9dfb | 105 | if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) {\r |
106 | \r | |
107 | ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer));\r | |
108 | mNarrowGlyphBuffer.UnicodeWeight = *Source;\r | |
109 | for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) {\r | |
110 | for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) {\r | |
111 | if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) {\r | |
98b16b9d | 112 | mNarrowGlyphBuffer.GlyphCol1[Ypos] = (UINT8) (mNarrowGlyphBuffer.GlyphCol1[Ypos] | (1 << (EFI_GLYPH_WIDTH - 1 - Xpos)));\r |
133a9dfb | 113 | }\r |
114 | }\r | |
115 | }\r | |
116 | \r | |
117 | *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer;\r | |
118 | *BitWidth = EFI_GLYPH_WIDTH;\r | |
119 | *Index += 1;\r | |
120 | } else {\r | |
121 | Status = EFI_NOT_FOUND;\r | |
122 | }\r | |
123 | \r | |
124 | }\r | |
125 | \r | |
bc3fc71a | 126 | if (EFI_ERROR (Status) || (Status == EFI_WARN_UNKNOWN_GLYPH)) {\r |
127 | if (Status == EFI_WARN_UNKNOWN_GLYPH) {\r | |
128 | Status = EFI_NOT_FOUND;\r | |
129 | }\r | |
133a9dfb | 130 | *GlyphBuffer = NULL;\r |
131 | }\r | |
132 | return Status;\r | |
4259256b | 133 | }\r |
134 | \r | |
0368663f | 135 | /**\r |
a9d85320 | 136 | Translates a glyph into the format required for input to the Universal Graphics Adapter (UGA) Block Transfer (BLT) routines.\r |
137 | \r | |
138 | Notes:\r | |
0368663f | 139 | This function is only called by Graphics Console module and GraphicsLib. \r |
140 | EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib \r | |
141 | complying to UEFI HII.\r | |
142 | \r | |
a9d85320 | 143 | @param This A pointer to the EFI_HII_PROTOCOL instance.\r |
144 | @param GlyphBuffer A pointer to the buffer that contains glyph data. \r | |
145 | @param Foreground The foreground setting requested to be used for the generated BltBuffer data. Type EFI_UGA_PIXEL is defined in "Related Definitions" below.\r | |
146 | @param Background The background setting requested to be used for the generated BltBuffer data. \r | |
147 | @param Count The entry in the BltBuffer upon which to act.\r | |
148 | @param Width The width in bits of the glyph being converted.\r | |
149 | @param Height The height in bits of the glyph being converted\r | |
150 | @param BltBuffer A pointer to the buffer that contains the data that is ready to be used by the UGA BLT routines. \r | |
151 | \r | |
152 | @retval EFI_SUCCESS It worked.\r | |
153 | @retval EFI_NOT_FOUND A glyph for a character was not found.\r | |
154 | \r | |
0368663f | 155 | \r |
156 | **/\r | |
4259256b | 157 | EFI_STATUS\r |
158 | EFIAPI\r | |
159 | HiiGlyphToBlt (\r | |
160 | IN EFI_HII_PROTOCOL *This,\r | |
161 | IN UINT8 *GlyphBuffer,\r | |
162 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,\r | |
163 | IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,\r | |
164 | IN UINTN Count,\r | |
165 | IN UINTN Width,\r | |
166 | IN UINTN Height,\r | |
167 | IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer\r | |
168 | )\r | |
169 | {\r | |
133a9dfb | 170 | UINTN X;\r |
171 | UINTN Y;\r | |
172 | \r | |
173 | //\r | |
174 | // Convert Monochrome bitmap of the Glyph to BltBuffer structure\r | |
175 | //\r | |
176 | for (Y = 0; Y < Height; Y++) {\r | |
177 | for (X = 0; X < Width; X++) {\r | |
178 | if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {\r | |
179 | BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;\r | |
180 | } else {\r | |
181 | BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;\r | |
182 | }\r | |
183 | }\r | |
184 | }\r | |
185 | \r | |
186 | return EFI_SUCCESS;\r | |
4259256b | 187 | }\r |