3 This file contains the keyboard processing code to the HII database.
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
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.
17 #include "HiiDatabase.h"
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
23 UINT8 mUnknownGlyph
[38] = {
67 IN EFI_HII_PROTOCOL
*This
,
70 OUT UINT8
**GlyphBuffer
,
72 IN OUT UINT32
*InternalStatus
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.
94 EFI_HII_GLOBAL_DATA
*GlobalData
;
95 EFI_HII_DATA
*HiiData
;
105 return EFI_INVALID_PARAMETER
;
108 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
110 GlobalData
= HiiData
->GlobalData
;
111 Count
= sizeof (GlobalData
->NarrowGlyphs
->GlyphCol1
);
114 SearchLocation
= *Index
;
117 if (Source
[Location
] == NARROW_CHAR
|| Source
[Location
] == WIDE_CHAR
) {
121 // We don't know what glyph database to look in - let's figure it out
123 if (*InternalStatus
== 0) {
125 // Determine if we are looking for narrow or wide glyph data
128 if (Source
[SearchLocation
] == NARROW_CHAR
|| Source
[SearchLocation
] == WIDE_CHAR
) {
130 // We found something that identifies what glyph database to look in
132 if (Source
[SearchLocation
] == WIDE_CHAR
) {
134 *BitWidth
= WIDE_WIDTH
;
135 *InternalStatus
= WIDE_CHAR
;
140 *BitWidth
= NARROW_WIDTH
;
141 *InternalStatus
= NARROW_CHAR
;
146 } while (SearchLocation
-- > 0);
149 if (*InternalStatus
== NARROW_CHAR
) {
151 *BitWidth
= NARROW_WIDTH
;
152 } else if (*InternalStatus
== WIDE_CHAR
) {
154 *BitWidth
= WIDE_WIDTH
;
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....
162 *BitWidth
= NARROW_WIDTH
;
165 Character
= Source
[Location
];
168 if (GlobalData
->NarrowGlyphs
[Character
].UnicodeWeight
!= 0x0000) {
169 *GlyphBuffer
= (UINT8
*) (&GlobalData
->NarrowGlyphs
[Character
]);
170 Attributes
= GlobalData
->NarrowGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
173 // Glyph is uninitialized - return an error, but hand back the glyph
175 *GlyphBuffer
= (UINT8
*) (&GlobalData
->NarrowGlyphs
[Character
]);
176 *Index
= (UINT16
) (Location
+ 1);
177 return EFI_NOT_FOUND
;
183 if (GlobalData
->WideGlyphs
[Character
].UnicodeWeight
!= 0x0000) {
184 *GlyphBuffer
= (UINT8
*) (&GlobalData
->WideGlyphs
[Character
]);
185 Attributes
= GlobalData
->WideGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
188 // Glyph is uninitialized - return an error, but hand back the glyph
190 *GlyphBuffer
= (UINT8
*) (&GlobalData
->WideGlyphs
[Character
]);
191 *Index
= (UINT16
) (Location
+ 1);
192 return EFI_NOT_FOUND
;
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.
199 for (; Attributes
!= 0; Location
++) {
201 // Character is the Unicode value which is the index into the Glyph array.
203 Character
= Source
[Location
];
206 for (Value
= 0; Value
!= Count
; Value
++) {
207 *GlyphBuffer
[Location
+ Value
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
] |
208 GlobalData
->NarrowGlyphs
[Character
].GlyphCol1
[Value
]);
211 Attributes
= GlobalData
->NarrowGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
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
]);
220 Attributes
= GlobalData
->WideGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
224 // Source[*Index] should point to the next character to process
226 *Index
= (UINT16
) (Location
+ 1);
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
,
240 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
247 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
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
;
254 BltBuffer
[Y
* Width
* Count
+ (Width
- X
- 1)] = Background
;