]> git.proxmox.com Git - mirror_edk2.git/blob - IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Fonts.c
Correct all header files for doxygen format and correct the license issue for VgaClas...
[mirror_edk2.git] / IntelFrameworkModulePkg / Universal / HiiDataBaseDxe / Fonts.c
1 /**@file
2
3 This file contains the keyboard processing code to the HII database.
4
5 Copyright (c) 2006, Intel Corporation
6 All rights reserved. This program and the accompanying materials
7 are licensed and made available under the terms and conditions of the BSD License
8 which accompanies this distribution. The full text of the license may be found at
9 http://opensource.org/licenses/bsd-license.php
10
11 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
12 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 //
20 // We only need to define a wide glyph, since we will seed the narrow glyph with EFI_NARROW_GLYPH size of
21 // this data structure
22 //
23 UINT8 mUnknownGlyph[38] = {
24 0xaa,
25 0x55,
26 0xaa,
27 0x55,
28 0xaa,
29 0x55,
30 0xaa,
31 0x55,
32 0xaa,
33 0x55,
34 0xaa,
35 0x55,
36 0xaa,
37 0x55,
38 0xaa,
39 0x55,
40 0xaa,
41 0x55,
42 0xAA,
43 0xaa,
44 0x55,
45 0xaa,
46 0x55,
47 0xaa,
48 0x55,
49 0xaa,
50 0x55,
51 0xaa,
52 0x55,
53 0xaa,
54 0x55,
55 0xaa,
56 0x55,
57 0xaa,
58 0x55,
59 0xaa,
60 0x55,
61 0xAA
62 };
63
64 EFI_STATUS
65 EFIAPI
66 HiiGetGlyph (
67 IN EFI_HII_PROTOCOL *This,
68 IN CHAR16 *Source,
69 IN OUT UINT16 *Index,
70 OUT UINT8 **GlyphBuffer,
71 OUT UINT16 *BitWidth,
72 IN OUT UINT32 *InternalStatus
73 )
74 /*++
75
76 Routine Description:
77 Translates a Unicode character into the corresponding font glyph.
78 If the Source was pointing to a non-spacing character, the next Source[*Index]
79 character will be parsed and OR'd to the GlyphBuffer until a spacing character
80 is found in the Source. Since non-spacing characters are considered to be the
81 same pixel width as a regular character their BitWidth will be reflected correctly
82 however due to their special attribute, they are considered to be zero advancing width.
83 This basically means that the cursor would not advance, thus the character that follows
84 it would overlay the non-spacing character. The Index is modified to reflect both the
85 incoming array entry into the Source string but also the outgoing array entry after having
86 parsed the equivalent of a single Glyph's worth of data.
87
88 Arguments:
89
90 Returns:
91
92 --*/
93 {
94 EFI_HII_GLOBAL_DATA *GlobalData;
95 EFI_HII_DATA *HiiData;
96 UINTN Count;
97 BOOLEAN Narrow;
98 UINTN Location;
99 UINTN SearchLocation;
100 UINTN Value;
101 CHAR16 Character;
102 UINTN Attributes;
103
104 if (This == NULL) {
105 return EFI_INVALID_PARAMETER;
106 }
107
108 HiiData = EFI_HII_DATA_FROM_THIS (This);
109
110 GlobalData = HiiData->GlobalData;
111 Count = sizeof (GlobalData->NarrowGlyphs->GlyphCol1);
112
113 Location = *Index;
114 SearchLocation = *Index;
115 Narrow = TRUE;
116
117 if (Source[Location] == NARROW_CHAR || Source[Location] == WIDE_CHAR) {
118 *InternalStatus = 0;
119 }
120 //
121 // We don't know what glyph database to look in - let's figure it out
122 //
123 if (*InternalStatus == 0) {
124 //
125 // Determine if we are looking for narrow or wide glyph data
126 //
127 do {
128 if (Source[SearchLocation] == NARROW_CHAR || Source[SearchLocation] == WIDE_CHAR) {
129 //
130 // We found something that identifies what glyph database to look in
131 //
132 if (Source[SearchLocation] == WIDE_CHAR) {
133 Narrow = FALSE;
134 *BitWidth = WIDE_WIDTH;
135 *InternalStatus = WIDE_CHAR;
136 Location++;
137 break;
138 } else {
139 Narrow = TRUE;
140 *BitWidth = NARROW_WIDTH;
141 *InternalStatus = NARROW_CHAR;
142 Location++;
143 break;
144 }
145 }
146 } while (SearchLocation-- > 0);
147 }
148
149 if (*InternalStatus == NARROW_CHAR) {
150 Narrow = TRUE;
151 *BitWidth = NARROW_WIDTH;
152 } else if (*InternalStatus == WIDE_CHAR) {
153 Narrow = FALSE;
154 *BitWidth = WIDE_WIDTH;
155 } else {
156 //
157 // Without otherwise knowing what the width is narrow (e.g. someone passed in a string with index of 0
158 // we wouldn't be able to determine the width of the data.)
159 // BUGBUG - do we go to wide database and if exist, ignore narrow? Check Unicode spec....
160 //
161 Narrow = TRUE;
162 *BitWidth = NARROW_WIDTH;
163 }
164
165 Character = Source[Location];
166
167 if (Narrow) {
168 if (GlobalData->NarrowGlyphs[Character].UnicodeWeight != 0x0000) {
169 *GlyphBuffer = (UINT8 *) (&GlobalData->NarrowGlyphs[Character]);
170 Attributes = GlobalData->NarrowGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
171 } else {
172 //
173 // Glyph is uninitialized - return an error, but hand back the glyph
174 //
175 *GlyphBuffer = (UINT8 *) (&GlobalData->NarrowGlyphs[Character]);
176 *Index = (UINT16) (Location + 1);
177 return EFI_NOT_FOUND;
178 }
179 } else {
180 //
181 // Wide character
182 //
183 if (GlobalData->WideGlyphs[Character].UnicodeWeight != 0x0000) {
184 *GlyphBuffer = (UINT8 *) (&GlobalData->WideGlyphs[Character]);
185 Attributes = GlobalData->WideGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
186 } else {
187 //
188 // Glyph is uninitialized - return an error, but hand back the glyph
189 //
190 *GlyphBuffer = (UINT8 *) (&GlobalData->WideGlyphs[Character]);
191 *Index = (UINT16) (Location + 1);
192 return EFI_NOT_FOUND;
193 }
194 }
195 //
196 // This is a non-spacing character. It will be followed by either more non-spacing
197 // characters or a regular character. We need to OR together the data associated with each.
198 //
199 for (; Attributes != 0; Location++) {
200 //
201 // Character is the Unicode value which is the index into the Glyph array.
202 //
203 Character = Source[Location];
204
205 if (Narrow) {
206 for (Value = 0; Value != Count; Value++) {
207 *GlyphBuffer[Location + Value] = (UINT8) (*GlyphBuffer[Location + Value] |
208 GlobalData->NarrowGlyphs[Character].GlyphCol1[Value]);
209 }
210
211 Attributes = GlobalData->NarrowGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
212 } else {
213 for (Value = 0; Value != Count; Value++) {
214 *GlyphBuffer[Location + Value] = (UINT8) (*GlyphBuffer[Location + Value] |
215 GlobalData->WideGlyphs[Character].GlyphCol1[Value]);
216 *GlyphBuffer[Location + Value + Count] = (UINT8) (*GlyphBuffer[Location + Value + Count] |
217 GlobalData->WideGlyphs[Character].GlyphCol2[Value]);
218 }
219
220 Attributes = GlobalData->WideGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
221 }
222 }
223 //
224 // Source[*Index] should point to the next character to process
225 //
226 *Index = (UINT16) (Location + 1);
227 return EFI_SUCCESS;
228 }
229
230 EFI_STATUS
231 EFIAPI
232 HiiGlyphToBlt (
233 IN EFI_HII_PROTOCOL *This,
234 IN UINT8 *GlyphBuffer,
235 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
236 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
237 IN UINTN Count,
238 IN UINTN Width,
239 IN UINTN Height,
240 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer
241 )
242 {
243 UINTN X;
244 UINTN Y;
245
246 //
247 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
248 //
249 for (Y = 0; Y < Height; Y++) {
250 for (X = 0; X < Width; X++) {
251 if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {
252 BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;
253 } else {
254 BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;
255 }
256 }
257 }
258
259 return EFI_SUCCESS;
260 }