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