]> git.proxmox.com Git - mirror_edk2.git/blob - EdkCompatibilityPkg/Compatibility/FrameworkHiiToUefiHiiThunk/Fonts.c
1) Add in code to sync Browser Data with the NvMapOverride that may be updated by...
[mirror_edk2.git] / EdkCompatibilityPkg / Compatibility / FrameworkHiiToUefiHiiThunk / Fonts.c
1 /**@file
2
3 This file contains the Glyph related function.
4
5 Copyright (c) 2006 - 2008, 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
10
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.
13
14 **/
15
16
17 #include "HiiDatabase.h"
18
19 EFI_NARROW_GLYPH mNarrowGlyphBuffer = {0, 0, {0}};
20
21 BOOLEAN mSysFontColorCached = FALSE;
22 EFI_GRAPHICS_OUTPUT_BLT_PIXEL mSysFGColor = {0};
23
24
25 /**
26 This function is only called by Graphics Console module and GraphicsLib.
27 EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib
28 complying to UEFI HII.
29
30 This function will ASSERT and return EFI_UNSUPPORTED.
31
32 @param This N.A.
33 @param Source N.A.
34 @param Index N.A.
35 @param GlyphBuffer N.A.
36 @param BitWidth N.A.
37 @param InternalStatus N.A.
38
39 @return EFI_UNSUPPORTED N.A.
40
41 **/
42 EFI_STATUS
43 EFIAPI
44 HiiGetGlyph (
45 IN EFI_HII_PROTOCOL *This,
46 IN CHAR16 *Source,
47 IN OUT UINT16 *Index,
48 OUT UINT8 **GlyphBuffer,
49 OUT UINT16 *BitWidth,
50 IN OUT UINT32 *InternalStatus
51 )
52 {
53 EFI_STATUS Status;
54 EFI_IMAGE_OUTPUT *Blt;
55 EFI_FONT_DISPLAY_INFO *FontInfo;
56 UINTN Xpos;
57 UINTN Ypos;
58 UINTN BaseLine;
59
60 if (!mSysFontColorCached) {
61 //
62 // Cache the system font's foreground color.
63 //
64 Status = mHiiFontProtocol->GetFontInfo (
65 mHiiFontProtocol,
66 NULL,
67 NULL,
68 &FontInfo,
69 NULL
70 );
71
72 if (!EFI_ERROR (Status)) {
73 ASSERT (StrCmp (FontInfo->FontInfo.FontName, L"sysdefault") == 0);
74 mSysFGColor = FontInfo->ForegroundColor;
75 FreePool (FontInfo);
76
77 mSysFontColorCached = TRUE;
78 }
79
80 }
81
82 Blt = NULL;
83 Status = mHiiFontProtocol->GetGlyph (
84 mHiiFontProtocol,
85 Source[*Index],
86 NULL,
87 &Blt,
88 &BaseLine
89 );
90
91 if (!EFI_ERROR (Status)) {
92 //
93 // For simplicity, we only handle Narrow Glyph.
94 //
95 ASSERT (Blt->Height == EFI_GLYPH_HEIGHT);
96 ASSERT (Blt->Width == EFI_GLYPH_WIDTH);
97
98 if (Blt->Height == EFI_GLYPH_HEIGHT && Blt->Width == EFI_GLYPH_WIDTH) {
99
100 ZeroMem (&mNarrowGlyphBuffer, sizeof (mNarrowGlyphBuffer));
101 mNarrowGlyphBuffer.UnicodeWeight = *Source;
102 for (Ypos = 0; Ypos < EFI_GLYPH_HEIGHT; Ypos++) {
103 for (Xpos = 0; Xpos < EFI_GLYPH_WIDTH; Xpos++) {
104 if (CompareMem (&Blt->Image.Bitmap[Ypos * EFI_GLYPH_WIDTH + Xpos], &mSysFGColor, sizeof (EFI_GRAPHICS_OUTPUT_BLT_PIXEL)) == 0) {
105 mNarrowGlyphBuffer.GlyphCol1[Ypos] |= 1 << (EFI_GLYPH_WIDTH - 1 - Xpos);
106 }
107 }
108 }
109
110 *GlyphBuffer = (UINT8 *) &mNarrowGlyphBuffer;
111 *BitWidth = EFI_GLYPH_WIDTH;
112 *Index += 1;
113 } else {
114 Status = EFI_NOT_FOUND;
115 }
116
117 }
118
119 if (EFI_ERROR (Status)) {
120 *GlyphBuffer = NULL;
121 }
122 return Status;
123 }
124
125 /**
126 This function is only called by Graphics Console module and GraphicsLib.
127 EDK II provides a UEFI Graphics Console module. ECP provides a GraphicsLib
128 complying to UEFI HII.
129
130 This function will ASSERT and return EFI_UNSUPPORTED.
131
132 @param This N.A.
133 @param GlyphBuffer N.A.
134 @param Foreground N.A.
135 @param Background N.A.
136 @param Count N.A.
137 @param Width N.A.
138 @param Height N.A.
139 @param BltBuffer N.A.
140
141 @return EFI_UNSUPPORTED N.A.
142
143 **/
144 EFI_STATUS
145 EFIAPI
146 HiiGlyphToBlt (
147 IN EFI_HII_PROTOCOL *This,
148 IN UINT8 *GlyphBuffer,
149 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Foreground,
150 IN EFI_GRAPHICS_OUTPUT_BLT_PIXEL Background,
151 IN UINTN Count,
152 IN UINTN Width,
153 IN UINTN Height,
154 IN OUT EFI_GRAPHICS_OUTPUT_BLT_PIXEL *BltBuffer
155 )
156 {
157 UINTN X;
158 UINTN Y;
159
160 //
161 // Convert Monochrome bitmap of the Glyph to BltBuffer structure
162 //
163 for (Y = 0; Y < Height; Y++) {
164 for (X = 0; X < Width; X++) {
165 if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {
166 BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;
167 } else {
168 BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;
169 }
170 }
171 }
172
173 return EFI_SUCCESS;
174 }