summaryrefslogtreecommitdiff
path: root/IntelFrameworkModulePkg/Universal/HiiDataBaseDxe/Fonts.c
blob: 2c3980da633eb7c3b532ead383af2038b5c09d38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/*++

Copyright (c) 2006, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:

  Fonts.c

Abstract:

  This file contains the Glyph/Font processing code to the HII database.

--*/


//
// Include common header file for this module.
//
#include "CommonHeader.h"

#include "HiiDatabase.h"

//
// We only need to define a wide glyph, since we will seed the narrow glyph with EFI_NARROW_GLYPH size of
// this data structure
//
UINT8 mUnknownGlyph[38] = {
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xAA,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xaa,
  0x55,
  0xAA
};

EFI_STATUS
EFIAPI
HiiGetGlyph (
  IN     EFI_HII_PROTOCOL   *This,
  IN     CHAR16             *Source,
  IN OUT UINT16             *Index,
  OUT    UINT8              **GlyphBuffer,
  OUT    UINT16             *BitWidth,
  IN OUT UINT32             *InternalStatus
  )
/*++

Routine Description:
  Translates a Unicode character into the corresponding font glyph.  
  If the Source was pointing to a non-spacing character, the next Source[*Index]
  character will be parsed and OR'd to the GlyphBuffer until a spacing character
  is found in the Source.  Since non-spacing characters are considered to be the
  same pixel width as a regular character their BitWidth will be reflected correctly
  however due to their special attribute, they are considered to be zero advancing width.
  This basically means that the cursor would not advance, thus the character that follows
  it would overlay the non-spacing character.  The Index is modified to reflect both the
  incoming array entry into the Source string but also the outgoing array entry after having
  parsed the equivalent of a single Glyph's worth of data.

Arguments:

Returns: 

--*/
{
  EFI_HII_GLOBAL_DATA *GlobalData;
  EFI_HII_DATA        *HiiData;
  UINTN               Count;
  BOOLEAN             Narrow;
  UINTN               Location;
  UINTN               SearchLocation;
  UINTN               Value;
  CHAR16              Character;
  UINTN               Attributes;

  if (This == NULL) {
    return EFI_INVALID_PARAMETER;
  }

  HiiData         = EFI_HII_DATA_FROM_THIS (This);

  GlobalData      = HiiData->GlobalData;
  Count           = sizeof (GlobalData->NarrowGlyphs->GlyphCol1);

  Location        = *Index;
  SearchLocation  = *Index;
  Narrow          = TRUE;

  if (Source[Location] == NARROW_CHAR || Source[Location] == WIDE_CHAR) {
    *InternalStatus = 0;
  }
  //
  // We don't know what glyph database to look in - let's figure it out
  //
  if (*InternalStatus == 0) {
    //
    // Determine if we are looking for narrow or wide glyph data
    //
    do {
      if (Source[SearchLocation] == NARROW_CHAR || Source[SearchLocation] == WIDE_CHAR) {
        //
        // We found something that identifies what glyph database to look in
        //
        if (Source[SearchLocation] == WIDE_CHAR) {
          Narrow          = FALSE;
          *BitWidth       = WIDE_WIDTH;
          *InternalStatus = WIDE_CHAR;
          Location++;
          break;
        } else {
          Narrow          = TRUE;
          *BitWidth       = NARROW_WIDTH;
          *InternalStatus = NARROW_CHAR;
          Location++;
          break;
        }
      }
    } while (SearchLocation-- > 0);
  }

  if (*InternalStatus == NARROW_CHAR) {
    Narrow    = TRUE;
    *BitWidth = NARROW_WIDTH;
  } else if (*InternalStatus == WIDE_CHAR) {
    Narrow    = FALSE;
    *BitWidth = WIDE_WIDTH;
  } else {
    //
    // Without otherwise knowing what the width is narrow (e.g. someone passed in a string with index of 0
    // we wouldn't be able to determine the width of the data.)
    // BUGBUG - do we go to wide database and if exist, ignore narrow?  Check Unicode spec....
    //
    Narrow    = TRUE;
    *BitWidth = NARROW_WIDTH;
  }

  Character = Source[Location];

  if (Narrow) {
    if (GlobalData->NarrowGlyphs[Character].UnicodeWeight != 0x0000) {
      *GlyphBuffer  = (UINT8 *) (&GlobalData->NarrowGlyphs[Character]);
      Attributes    = GlobalData->NarrowGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
    } else {
      //
      // Glyph is uninitialized - return an error, but hand back the glyph
      //
      *GlyphBuffer  = (UINT8 *) (&GlobalData->NarrowGlyphs[Character]);
      *Index        = (UINT16) (Location + 1);
      return EFI_NOT_FOUND;
    }
  } else {
    //
    // Wide character
    //
    if (GlobalData->WideGlyphs[Character].UnicodeWeight != 0x0000) {
      *GlyphBuffer  = (UINT8 *) (&GlobalData->WideGlyphs[Character]);
      Attributes    = GlobalData->WideGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
    } else {
      //
      // Glyph is uninitialized - return an error, but hand back the glyph
      //
      *GlyphBuffer  = (UINT8 *) (&GlobalData->WideGlyphs[Character]);
      *Index        = (UINT16) (Location + 1);
      return EFI_NOT_FOUND;
    }
  }
  //
  // This is a non-spacing character.  It will be followed by either more non-spacing
  // characters or a regular character.  We need to OR together the data associated with each.
  //
  for (; Attributes != 0; Location++) {
    //
    // Character is the Unicode value which is the index into the Glyph array.
    //
    Character = Source[Location];

    if (Narrow) {
      for (Value = 0; Value != Count; Value++) {
        *GlyphBuffer[Location + Value] = (UINT8) (*GlyphBuffer[Location + Value] |
                                                  GlobalData->NarrowGlyphs[Character].GlyphCol1[Value]);
      }

      Attributes = GlobalData->NarrowGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
    } else {
      for (Value = 0; Value != Count; Value++) {
        *GlyphBuffer[Location + Value] = (UINT8) (*GlyphBuffer[Location + Value] | 
                                                  GlobalData->WideGlyphs[Character].GlyphCol1[Value]);
        *GlyphBuffer[Location + Value + Count] = (UINT8) (*GlyphBuffer[Location + Value + Count] |
                                                          GlobalData->WideGlyphs[Character].GlyphCol2[Value]);
      }

      Attributes = GlobalData->WideGlyphs[Character].Attributes & EFI_GLYPH_NON_SPACING;
    }
  }
  //
  // Source[*Index] should point to the next character to process
  //
  *Index = (UINT16) (Location + 1);
  return EFI_SUCCESS;
}

EFI_STATUS
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
  )
{
  UINTN X;
  UINTN Y;

  //
  // Convert Monochrome bitmap of the Glyph to BltBuffer structure
  //
  for (Y = 0; Y < Height; Y++) {
    for (X = 0; X < Width; X++) {
      if ((((EFI_NARROW_GLYPH *) GlyphBuffer)->GlyphCol1[Y] & (1 << X)) != 0) {
        BltBuffer[Y * Width * Count + (Width - X - 1)] = Foreground;
      } else {
        BltBuffer[Y * Width * Count + (Width - X - 1)] = Background;
      }
    }
  }

  return EFI_SUCCESS;
}