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