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.
24 // Include common header file for this module.
26 #include "CommonHeader.h"
28 #include "HiiDatabase.h"
31 // We only need to define a wide glyph, since we will seed the narrow glyph with EFI_NARROW_GLYPH size of
32 // this data structure
34 UINT8 mUnknownGlyph
[38] = {
78 IN EFI_HII_PROTOCOL
*This
,
81 OUT UINT8
**GlyphBuffer
,
83 IN OUT UINT32
*InternalStatus
88 Translates a Unicode character into the corresponding font glyph.
89 If the Source was pointing to a non-spacing character, the next Source[*Index]
90 character will be parsed and OR'd to the GlyphBuffer until a spacing character
91 is found in the Source. Since non-spacing characters are considered to be the
92 same pixel width as a regular character their BitWidth will be reflected correctly
93 however due to their special attribute, they are considered to be zero advancing width.
94 This basically means that the cursor would not advance, thus the character that follows
95 it would overlay the non-spacing character. The Index is modified to reflect both the
96 incoming array entry into the Source string but also the outgoing array entry after having
97 parsed the equivalent of a single Glyph's worth of data.
105 EFI_HII_GLOBAL_DATA
*GlobalData
;
106 EFI_HII_DATA
*HiiData
;
110 UINTN SearchLocation
;
116 return EFI_INVALID_PARAMETER
;
119 HiiData
= EFI_HII_DATA_FROM_THIS (This
);
121 GlobalData
= HiiData
->GlobalData
;
122 Count
= sizeof (GlobalData
->NarrowGlyphs
->GlyphCol1
);
125 SearchLocation
= *Index
;
128 if (Source
[Location
] == NARROW_CHAR
|| Source
[Location
] == WIDE_CHAR
) {
132 // We don't know what glyph database to look in - let's figure it out
134 if (*InternalStatus
== 0) {
136 // Determine if we are looking for narrow or wide glyph data
139 if (Source
[SearchLocation
] == NARROW_CHAR
|| Source
[SearchLocation
] == WIDE_CHAR
) {
141 // We found something that identifies what glyph database to look in
143 if (Source
[SearchLocation
] == WIDE_CHAR
) {
145 *BitWidth
= WIDE_WIDTH
;
146 *InternalStatus
= WIDE_CHAR
;
151 *BitWidth
= NARROW_WIDTH
;
152 *InternalStatus
= NARROW_CHAR
;
157 } while (SearchLocation
-- > 0);
160 if (*InternalStatus
== NARROW_CHAR
) {
162 *BitWidth
= NARROW_WIDTH
;
163 } else if (*InternalStatus
== WIDE_CHAR
) {
165 *BitWidth
= WIDE_WIDTH
;
168 // Without otherwise knowing what the width is narrow (e.g. someone passed in a string with index of 0
169 // we wouldn't be able to determine the width of the data.)
170 // BUGBUG - do we go to wide database and if exist, ignore narrow? Check Unicode spec....
173 *BitWidth
= NARROW_WIDTH
;
176 Character
= Source
[Location
];
179 if (GlobalData
->NarrowGlyphs
[Character
].UnicodeWeight
!= 0x0000) {
180 *GlyphBuffer
= (UINT8
*) (&GlobalData
->NarrowGlyphs
[Character
]);
181 Attributes
= GlobalData
->NarrowGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
184 // Glyph is uninitialized - return an error, but hand back the glyph
186 *GlyphBuffer
= (UINT8
*) (&GlobalData
->NarrowGlyphs
[Character
]);
187 *Index
= (UINT16
) (Location
+ 1);
188 return EFI_NOT_FOUND
;
194 if (GlobalData
->WideGlyphs
[Character
].UnicodeWeight
!= 0x0000) {
195 *GlyphBuffer
= (UINT8
*) (&GlobalData
->WideGlyphs
[Character
]);
196 Attributes
= GlobalData
->WideGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
199 // Glyph is uninitialized - return an error, but hand back the glyph
201 *GlyphBuffer
= (UINT8
*) (&GlobalData
->WideGlyphs
[Character
]);
202 *Index
= (UINT16
) (Location
+ 1);
203 return EFI_NOT_FOUND
;
207 // This is a non-spacing character. It will be followed by either more non-spacing
208 // characters or a regular character. We need to OR together the data associated with each.
210 for (; Attributes
!= 0; Location
++) {
212 // Character is the Unicode value which is the index into the Glyph array.
214 Character
= Source
[Location
];
217 for (Value
= 0; Value
!= Count
; Value
++) {
218 *GlyphBuffer
[Location
+ Value
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
] |
219 GlobalData
->NarrowGlyphs
[Character
].GlyphCol1
[Value
]);
222 Attributes
= GlobalData
->NarrowGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
224 for (Value
= 0; Value
!= Count
; Value
++) {
225 *GlyphBuffer
[Location
+ Value
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
] |
226 GlobalData
->WideGlyphs
[Character
].GlyphCol1
[Value
]);
227 *GlyphBuffer
[Location
+ Value
+ Count
] = (UINT8
) (*GlyphBuffer
[Location
+ Value
+ Count
] |
228 GlobalData
->WideGlyphs
[Character
].GlyphCol2
[Value
]);
231 Attributes
= GlobalData
->WideGlyphs
[Character
].Attributes
& EFI_GLYPH_NON_SPACING
;
235 // Source[*Index] should point to the next character to process
237 *Index
= (UINT16
) (Location
+ 1);
244 IN EFI_HII_PROTOCOL
*This
,
245 IN UINT8
*GlyphBuffer
,
246 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground
,
247 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background
,
251 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL
*BltBuffer
258 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
260 for (Y
= 0; Y
< Height
; Y
++) {
261 for (X
= 0; X
< Width
; X
++) {
262 if ((((EFI_NARROW_GLYPH
*) GlyphBuffer
)->GlyphCol1
[Y
] & (1 << X
)) != 0) {
263 BltBuffer
[Y
* Width
* Count
+ (Width
- X
- 1)] = Foreground
;
265 BltBuffer
[Y
* Width
* Count
+ (Width
- X
- 1)] = Background
;