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
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.
18 This file contains the Glyph/Font processing code to the HII database.
23 #include "HiiDatabase.h"
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
29 UINT8 mUnknownGlyph
[38] = {
73 IN EFI_HII_PROTOCOL
*This
,
76 OUT UINT8
**GlyphBuffer
,
78 IN OUT UINT32
*InternalStatus
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.
100 EFI_HII_GLOBAL_DATA
*GlobalData
;
101 EFI_HII_DATA
*HiiData
;
105 UINTN SearchLocation
;
111 return EFI_INVALID_PARAMETER
;
114 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
116 GlobalData
= HiiData
->GlobalData
;
117 Count
= sizeof (GlobalData
->NarrowGlyphs
->GlyphCol1
);
120 SearchLocation
= *Index
;
123 if (Source
[Location
] == NARROW_CHAR
|| Source
[Location
] == WIDE_CHAR
) {
127 // We don't know what glyph database to look in - let's figure it out
129 if (*InternalStatus
== 0) {
131 // Determine if we are looking for narrow or wide glyph data
134 if (Source
[SearchLocation
] == NARROW_CHAR
|| Source
[SearchLocation
] == WIDE_CHAR
) {
136 // We found something that identifies what glyph database to look in
138 if (Source
[SearchLocation
] == WIDE_CHAR
) {
140 *BitWidth
= WIDE_WIDTH
;
141 *InternalStatus
= WIDE_CHAR
;
146 *BitWidth
= NARROW_WIDTH
;
147 *InternalStatus
= NARROW_CHAR
;
152 } while (SearchLocation
-- > 0);
155 if (*InternalStatus
== NARROW_CHAR
) {
157 *BitWidth
= NARROW_WIDTH
;
158 } else if (*InternalStatus
== WIDE_CHAR
) {
160 *BitWidth
= WIDE_WIDTH
;
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....
168 *BitWidth
= NARROW_WIDTH
;
171 Character
= Source
[Location
];
174 if (GlobalData
->NarrowGlyphs
[Character
].UnicodeWeight
!= 0x0000) {
175 *GlyphBuffer
= (UINT8
*) (&GlobalData
->NarrowGlyphs
[Character
]);
176 Attributes
= GlobalData
->NarrowGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
179 // Glyph is uninitialized - return an error, but hand back the glyph
181 *GlyphBuffer
= (UINT8
*) (&GlobalData
->NarrowGlyphs
[Character
]);
182 *Index
= (UINT16
) (Location
+ 1);
183 return EFI_NOT_FOUND
;
189 if (GlobalData
->WideGlyphs
[Character
].UnicodeWeight
!= 0x0000) {
190 *GlyphBuffer
= (UINT8
*) (&GlobalData
->WideGlyphs
[Character
]);
191 Attributes
= GlobalData
->WideGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
194 // Glyph is uninitialized - return an error, but hand back the glyph
196 *GlyphBuffer
= (UINT8
*) (&GlobalData
->WideGlyphs
[Character
]);
197 *Index
= (UINT16
) (Location
+ 1);
198 return EFI_NOT_FOUND
;
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.
205 for (; Attributes
!= 0; Location
++) {
207 // Character is the Unicode value which is the index into the Glyph array.
209 Character
= Source
[Location
];
212 for (Value
= 0; Value
!= Count
; Value
++) {
213 *GlyphBuffer
[Location
+ Value
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
] |
214 GlobalData
->NarrowGlyphs
[Character
].GlyphCol1
[Value
]);
217 Attributes
= GlobalData
->NarrowGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
219 for (Value
= 0; Value
!= Count
; Value
++) {
220 *GlyphBuffer
[Location
+ Value
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
] |
221 GlobalData
->WideGlyphs
[Character
].GlyphCol1
[Value
]);
222 *GlyphBuffer
[Location
+ Value
+ Count
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
+ Count
] |
223 GlobalData
->WideGlyphs
[Character
].GlyphCol2
[Value
]);
226 Attributes
= GlobalData
->WideGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
230 // Source[*Index] should point to the next character to process
232 *Index
= (UINT16
) (Location
+ 1);
239 IN EFI_HII_PROTOCOL
*This
,
240 IN UINT8
*GlyphBuffer
,
241 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
,
242 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
,
246 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
253 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
255 for (Y
= 0; Y
< Height
; Y
++) {
256 for (X
= 0; X
< Width
; X
++) {
257 if ((((EFI_NARROW_GLYPH
*) GlyphBuffer
)->GlyphCol1
[Y
] & (1 << X
)) != 0) {
258 BltBuffer
[Y
* Width
* Count
+ (Width
- X
- 1)] = Foreground
;
260 BltBuffer
[Y
* Width
* Count
+ (Width
- X
- 1)] = Background
;