1 /** @file
2 This file contains the Glyph related function.
3
4 Copyright (c) 2006 - 2010, Intel Corporation. All rights reserved.<BR>
5 This program and the accompanying materials
6 are licensed and made available under the terms and conditions of the BSD License
7 which accompanies this distribution. The full text of the license may be found at
8 http://opensource.org/licenses/bsd-license.php
9
10 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
11 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
12
13 **/
14
15
16 #include "HiiDatabase.h"
17
18 EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}};
19
20 BOOLEAN mSysFontColorCached = FALSE;
21 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mSysFGColor = {0};
22
23
24 /**
25 Translates a Unicode character into the corresponding font glyph.
26
27 Notes:
28 This function is only called by Graphics Console module and GraphicsLib.
29 Wrap the Framework HII GetGlyph function to UEFI Font Protocol.
30
31 EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib
32 complying to UEFI HII.
33
34 @param This A pointer to the EFI_HII_PROTOCOL instance.
35 @param Source A pointer to a Unicode string.
36 @param Index On input, the offset into the string from which to fetch the character. On successful completion, the
37 index is updated to the first character past the character(s) making up the just extracted glyph.
38 @param GlyphBuffer Pointer to an array where the glyphs corresponding to the characters in the source may be stored.
39 GlyphBuffer is assumed to be wide enough to accept a wide glyph character.
40 @param BitWidth If EFI_SUCCESS was returned, the UINT16 pointed to by this value is filled with the length of the glyph in pixels.
41 It is unchanged if the call was unsuccessful.
42 @param InternalStatus To save the time required to read the string from the beginning on each glyph extraction
43 (for example, to ensure that the narrow versus wide glyph mode is correct), this value is
44 updated each time the function is called with the status that is local to the call. The cell pointed
45 to by this parameter must be initialized to zero prior to invoking the call the first time for any string.
46
47 @retval EFI_SUCCESS It worked.
48 @retval EFI_NOT_FOUND A glyph for a character was not found.
49
50
51 **/
52 EFI_STATUS
53 EFIAPI
HiiGetGlyph(IN EFI_HII_PROTOCOL * This,IN CHAR16 * Source,IN OUT UINT16 * Index,OUT UINT8 ** GlyphBuffer,OUT UINT16 * BitWidth,IN OUT UINT32 * InternalStatus)54 HiiGetGlyph (
55 IN EFI_HII_PROTOCOL *This,
56 IN CHAR16 *Source,
57 IN OUT UINT16 *Index,
58 OUT UINT8 **GlyphBuffer,
59 OUT UINT16 *BitWidth,
60 IN OUT UINT32 *InternalStatus
61 )
62 {
63 EFI_STATUS Status;
64 EFI_IMAGE_OUTPUT *Blt;
65 EFI_FONT_DISPLAY_INFO *FontInfo;
66 UINTN Xpos;
67 UINTN Ypos;
68 UINTN BaseLine;
69
70 if (!mSysFontColorCached) {
71 //
72 // Cache the system font's foreground color.
73 //
74 Status = mHiiFontProtocol->GetFontInfo (
75 mHiiFontProtocol,
76 NULL,
77 NULL,
78 &FontInfo,
79 NULL
80 );
81
82 if (!EFI_ERROR (Status)) {
83 ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0);
84 mSysFGColor = FontInfo->ForegroundColor;
85 FreePool (FontInfo);
86
87 mSysFontColorCached = TRUE;
88 }
89
90 }
91
92 Blt = NULL;
93 Status = mHiiFontProtocol->GetGlyph (
94 mHiiFontProtocol,
95 Source[*Index],
96 NULL,
97 &Blt,
98 &BaseLine
99 );
100
101 if (!EFI_ERROR (Status) && (Status != EFI_WARN_UNKNOWN_GLYPH)) {
102 //
103 // For simplicity, we only handle Narrow Glyph.
104 //
105 if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) {
106
107 ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer));
108 mNarrowGlyphBuffer.UnicodeWeight = *Source;
109 for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) {
110 for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) {
111 if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) {
112 mNarrowGlyphBuffer.GlyphCol1[Ypos] = (UINT8) (mNarrowGlyphBuffer.GlyphCol1[Ypos] | (1 << (EFI_GLYPH_WIDTH - 1 - Xpos)));
113 }
114 }
115 }
116
117 *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer;
118 *BitWidth = EFI_GLYPH_WIDTH;
119 *Index += 1;
120 } else {
121 Status = EFI_NOT_FOUND;
122 }
123
124 }
125
126 if (EFI_ERROR (Status) || (Status == EFI_WARN_UNKNOWN_GLYPH)) {
127 if (Status == EFI_WARN_UNKNOWN_GLYPH) {
128 Status = EFI_NOT_FOUND;
129 }
130 *GlyphBuffer = NULL;
131 }
132 return Status;
133 }
134
135 /**
136 Translates a glyph into the format required for input to the Universal Graphics Adapter (UGA) Block Transfer (BLT) routines.
137
138 Notes:
139 This function is only called by Graphics Console module and GraphicsLib.
140 EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib
141 complying to UEFI HII.
142
143 @param This A pointer to the EFI_HII_PROTOCOL instance.
144 @param GlyphBuffer A pointer to the buffer that contains glyph data.
145 @param Foreground The foreground setting requested to be used for the generated BltBuffer data. Type EFI_UGA_PIXEL is defined in "Related Definitions" below.
146 @param Background The background setting requested to be used for the generated BltBuffer data.
147 @param Count The entry in the BltBuffer upon which to act.
148 @param Width The width in bits of the glyph being converted.
149 @param Height The height in bits of the glyph being converted
150 @param BltBuffer A pointer to the buffer that contains the data that is ready to be used by the UGA BLT routines.
151
152 @retval EFI_SUCCESS It worked.
153 @retval EFI_NOT_FOUND A glyph for a character was not found.
154
155
156 **/
157 EFI_STATUS
158 EFIAPI
HiiGlyphToBlt(IN EFI_HII_PROTOCOL * This,IN UINT8 * GlyphBuffer,IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,IN UINTN Count,IN UINTN Width,IN UINTN Height,IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL * BltBuffer)159 HiiGlyphToBlt (
160 IN EFI_HII_PROTOCOL *This,
161 IN UINT8 *GlyphBuffer,
162 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
163 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
164 IN UINTN Count,
165 IN UINTN Width,
166 IN UINTN Height,
167 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer
168 )
169 {
170 UINTN Xpos;
171 UINTN Ypos;
172
173 //
174 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
175 //
176 for (Ypos = 0; Ypos < Height; Ypos++) {
177 for (Xpos = 0; Xpos < Width; Xpos++) {
178 if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Ypos] & (1 << Xpos)) != 0) {
179 BltBuffer[Ypos * Width * Count + (Width - Xpos - 1)] = Foreground;
180 } else {
181 BltBuffer[Ypos * Width * Count + (Width - Xpos - 1)] = Background;
182 }
183 }
184 }
185
186 return EFI_SUCCESS;
187 }
188