ReactOS  0.4.14-dev-358-gbef841c
font.c File Reference
#include "blue.h"
#include <ntddk.h>
#include <debug.h>
Include dependency graph for font.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

VOID OpenBitPlane ()
 
VOID CloseBitPlane ()
 
VOID LoadFont (PUCHAR Bitplane, PUCHAR FontBitfield)
 
VOID ScrLoadFontTable (UINT32 CodePage)
 
NTSTATUS ExtractFont (UINT32 CodePage, PUCHAR FontBitField)
 
VOID OpenBitPlane (VOID)
 
VOID CloseBitPlane (VOID)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 17 of file font.c.

Function Documentation

◆ CloseBitPlane() [1/2]

VOID CloseBitPlane ( )

Referenced by ScrLoadFontTable().

◆ CloseBitPlane() [2/2]

VOID CloseBitPlane ( VOID  )

Definition at line 280 of file font.c.

281 {
282  /* disable interrupts */
283  _disable();
284 
285  /* sequence reg */
290 
291  /* graphic reg */
295 
296  /* enable interrupts */
297  _enable();
298 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define SEQ_COMMAND
Definition: blue.h:96
#define SEQ_DATA
Definition: blue.h:97
#define SEQ_MEM_MODE
Definition: blue.h:105
#define SEQ_ENABLE_WRT_PLANE
Definition: blue.h:104
#define SEQ_RESET
Definition: blue.h:103
#define GCT_DATA
Definition: blue.h:100
#define GCT_RW_MODES
Definition: blue.h:109
#define GCT_GRAPH_MODE
Definition: blue.h:110
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
#define GCT_COMMAND
Definition: blue.h:99
#define GCT_READ_PLANE
Definition: blue.h:108

◆ ExtractFont()

NTSTATUS ExtractFont ( UINT32  CodePage,
PUCHAR  FontBitField 
)

Definition at line 69 of file font.c.

72 {
73  BOOLEAN bFoundFile = FALSE;
74  HANDLE Handle;
76  CHAR FileName[20];
79  UNICODE_STRING LinkName;
81  CFHEADER CabFileHeader;
82  CFFILE CabFile;
83  ULONG CabFileOffset = 0;
85  WCHAR SourceBuffer[MAX_PATH] = { L'\0' };
86  ULONG ReadCP;
87 
90 
91  RtlInitUnicodeString(&LinkName,
92  L"\\SystemRoot");
93 
95  &LinkName,
97  NULL,
98  NULL);
99 
103 
104  if (!NT_SUCCESS(Status))
105  {
106  DPRINT1("ZwOpenSymbolicLinkObject failed with Status 0x%lx\n", Status);
107  return Status;
108  }
109 
110  SourceName.Length = 0;
111  SourceName.MaximumLength = MAX_PATH * sizeof(WCHAR);
112  SourceName.Buffer = SourceBuffer;
113 
114  Status = ZwQuerySymbolicLinkObject(Handle,
115  &SourceName,
116  NULL);
117  ZwClose(Handle);
118 
119  if (!NT_SUCCESS(Status))
120  {
121  DPRINT1("ZwQuerySymbolicLinkObject failed with Status 0x%lx\n", Status);
122  return Status;
123  }
124 
125  Status = RtlAppendUnicodeToString(&SourceName, L"\\vgafonts.cab");
126  if (!NT_SUCCESS(Status))
127  {
128  DPRINT1("RtlAppendUnicodeToString failed with Status 0x%lx\n", Status);
129  return Status;
130  }
131 
133  &SourceName,
135  NULL,
136  NULL);
137 
138  Status = ZwCreateFile(&Handle,
139  GENERIC_READ,
141  &IoStatusBlock,
142  NULL,
144  0,
145  FILE_OPEN,
147  NULL,
148  0);
149  if (!NT_SUCCESS(Status))
150  {
151  DPRINT1("Error: Cannot open vgafonts.cab (0x%lx)\n", Status);
152  return Status;
153  }
154 
155  ByteOffset.QuadPart = 0;
156  Status = ZwReadFile(Handle,
157  NULL,
158  NULL,
159  NULL,
160  &IoStatusBlock,
161  &CabFileHeader,
162  sizeof(CabFileHeader),
163  &ByteOffset,
164  NULL);
165 
166  if (!NT_SUCCESS(Status))
167  {
168  DPRINT1("Error: Cannot read from file (0x%lx)\n", Status);
169  goto Exit;
170  }
171 
172  if (CabFileHeader.Signature != CAB_SIGNATURE)
173  {
174  DPRINT1("Invalid CAB signature: 0x%lx!\n", CabFileHeader.Signature);
176  goto Exit;
177  }
178 
179  // We have a valid CAB file!
180  // Read the file table now and decrement the file count on every file. When it's zero, we read the complete table.
181  ByteOffset.QuadPart = CabFileHeader.FileTableOffset;
182 
183  while (CabFileHeader.FileCount)
184  {
185  Status = ZwReadFile(Handle,
186  NULL,
187  NULL,
188  NULL,
189  &IoStatusBlock,
190  &CabFile,
191  sizeof(CabFile),
192  &ByteOffset,
193  NULL);
194 
195  if (NT_SUCCESS(Status))
196  {
197  ByteOffset.QuadPart += sizeof(CabFile);
198 
199  // We assume here that the file name is max. 19 characters (+ 1 NULL character) long.
200  // This should be enough for our purpose.
201  Status = ZwReadFile(Handle,
202  NULL,
203  NULL,
204  NULL,
205  &IoStatusBlock,
206  FileName,
207  sizeof(FileName),
208  &ByteOffset,
209  NULL);
210 
211  if (NT_SUCCESS(Status))
212  {
213  if (!bFoundFile)
214  {
215  Status = RtlCharToInteger(FileName, 0, &ReadCP);
216  if (NT_SUCCESS(Status) && ReadCP == CodePage)
217  {
218  // We got the correct file.
219  // Save the offset and loop through the rest of the file table to find the position, where the actual data starts.
220  CabFileOffset = CabFile.FileOffset;
221  bFoundFile = TRUE;
222  }
223  }
224 
225  ByteOffset.QuadPart += strlen(FileName) + 1;
226  }
227  }
228 
229  CabFileHeader.FileCount--;
230  }
231 
232  // 8 = Size of a CFFOLDER structure (see cabman). As we don't need the values of that structure, just increase the offset here.
233  ByteOffset.QuadPart += 8;
234  ByteOffset.QuadPart += CabFileOffset;
235 
236  // ByteOffset now contains the offset of the actual data, so we can read the RAW font
237  Status = ZwReadFile(Handle,
238  NULL,
239  NULL,
240  NULL,
241  &IoStatusBlock,
242  FontBitField,
243  2048,
244  &ByteOffset,
245  NULL);
246  if (!NT_SUCCESS(Status))
247  {
248  DPRINT1("ZwReadFile failed with Status 0x%lx\n", Status);
249  }
250 
251 Exit:
252 
253  ZwClose(Handle);
254  return Status;
255 }
#define KeGetCurrentIrql()
Definition: env_spec_w32.h:706
IN PUNICODE_STRING IN POBJECT_ATTRIBUTES ObjectAttributes
Definition: conport.c:35
NTSYSAPI NTSTATUS NTAPI RtlCharToInteger(PCSZ String, ULONG Base, PULONG Value)
Definition: unicode.c:261
#define TRUE
Definition: types.h:120
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
unsigned char BOOLEAN
smooth NULL
Definition: ftsmooth.c:416
NTSTATUS RtlAppendUnicodeToString(IN PUNICODE_STRING Str1, IN PWSTR Str2)
Definition: string_lib.cpp:62
_In_ HANDLE Handle
Definition: extypes.h:390
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
static void Exit(void)
Definition: sock.c:1331
#define MAX_PATH
Definition: compat.h:26
Definition: fci.c:89
#define CAB_SIGNATURE
Definition: cabinet.c:47
#define OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:124
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
Status
Definition: gdiplustypes.h:24
#define FILE_OPEN
Definition: from_kernel.h:54
static OUT PIO_STATUS_BLOCK IoStatusBlock
Definition: pipe.c:75
WCHAR SourceName[256]
Definition: arping.c:28
Definition: fci.c:65
#define DPRINT1
Definition: precomp.h:8
#define FILE_SYNCHRONOUS_IO_NONALERT
Definition: from_kernel.h:31
unsigned int ULONG
Definition: retypes.h:1
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define InitializeObjectAttributes(p, n, a, r, s)
Definition: reg.c:106
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
NTSYSAPI NTSTATUS NTAPI ZwOpenSymbolicLinkObject(_Out_ PHANDLE SymbolicLinkHandle, _In_ ACCESS_MASK DesiredAccess, _In_ POBJECT_ATTRIBUTES ObjectAttributes)
IN PDCB IN PCCB IN VBO IN OUT PULONG OUT PDIRENT OUT PBCB OUT PVBO ByteOffset
Definition: fatprocs.h:716

Referenced by ScrLoadFontTable().

◆ LoadFont()

VOID LoadFont ( PUCHAR  Bitplane,
PUCHAR  FontBitfield 
)

Definition at line 301 of file font.c.

304 {
305  UINT32 i, j;
306 
307  for (i = 0; i < 256; i++)
308  {
309  for (j = 0; j < 8; j++)
310  {
311  *Bitplane = FontBitfield[i * 8 + j];
312  Bitplane++;
313  }
314 
315  // padding
316  for (j = 8; j < 32; j++)
317  {
318  *Bitplane = 0;
319  Bitplane++;
320  }
321  }
322 }
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
unsigned int UINT32
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint GLint GLint j
Definition: glfuncs.h:250

Referenced by ScrLoadFontTable().

◆ OpenBitPlane() [1/2]

VOID OpenBitPlane ( )

Referenced by ScrLoadFontTable().

◆ OpenBitPlane() [2/2]

VOID OpenBitPlane ( VOID  )

Definition at line 259 of file font.c.

260 {
261  /* disable interrupts */
262  _disable();
263 
264  /* sequence reg */
269 
270  /* graphic reg */
274 
275  /* enable interrupts */
276  _enable();
277 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define SEQ_COMMAND
Definition: blue.h:96
#define SEQ_DATA
Definition: blue.h:97
#define SEQ_MEM_MODE
Definition: blue.h:105
#define SEQ_ENABLE_WRT_PLANE
Definition: blue.h:104
#define SEQ_RESET
Definition: blue.h:103
#define GCT_DATA
Definition: blue.h:100
#define GCT_RW_MODES
Definition: blue.h:109
#define GCT_GRAPH_MODE
Definition: blue.h:110
void __cdecl _disable(void)
Definition: intrin_arm.h:365
void WRITE_PORT_UCHAR(PUCHAR Address, UCHAR Value)
Definition: mach.c:532
#define GCT_COMMAND
Definition: blue.h:99
#define GCT_READ_PLANE
Definition: blue.h:108

◆ ScrLoadFontTable()

VOID ScrLoadFontTable ( UINT32  CodePage)

Definition at line 27 of file font.c.

29 {
31  PUCHAR Bitplane;
32  PUCHAR FontBitfield = NULL;
34 
35  FontBitfield = (PUCHAR)ExAllocatePoolWithTag(NonPagedPool, 2048, TAG_BLUE);
36  if (FontBitfield == NULL)
37  {
38  DPRINT1("ExAllocatePoolWithTag failed\n");
39  return;
40  }
41 
42  /* open bit plane for font table access */
43  OpenBitPlane();
44 
45  /* get pointer to video memory */
46  BaseAddress.QuadPart = BITPLANE_BASE;
47  Bitplane = (PUCHAR)MmMapIoSpace(BaseAddress, 0xFFFF, MmNonCached);
48 
49  Status = ExtractFont(CodePage, FontBitfield);
50  if (NT_SUCCESS(Status))
51  {
52  LoadFont(Bitplane, FontBitfield);
53  }
54  else
55  {
56  DPRINT1("ExtractFont failed with Status 0x%lx\n", Status);
57  }
58 
59  MmUnmapIoSpace(Bitplane, 0xFFFF);
60  ExFreePool(FontBitfield);
61 
62  /* close bit plane */
63  CloseBitPlane();
64 }
unsigned char * PUCHAR
Definition: retypes.h:3
LONG NTSTATUS
Definition: precomp.h:26
NTSTATUS ExtractFont(UINT32 CodePage, PUCHAR FontBitField)
Definition: font.c:69
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
VOID LoadFont(PUCHAR Bitplane, PUCHAR FontBitfield)
Definition: font.c:301
smooth NULL
Definition: ftsmooth.c:416
#define TAG_BLUE
Definition: blue.h:50
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
#define NT_SUCCESS(StatCode)
Definition: apphelp.c:32
#define ExAllocatePoolWithTag(hernya, size, tag)
Definition: env_spec_w32.h:350
#define BITPLANE_BASE
Definition: blue.h:82
Status
Definition: gdiplustypes.h:24
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
VOID OpenBitPlane()
#define DPRINT1
Definition: precomp.h:8
VOID CloseBitPlane()
return STATUS_SUCCESS
Definition: btrfs.c:2938
#define ExFreePool(addr)
Definition: env_spec_w32.h:352

Referenced by ScrAcquireOwnership(), and ScrIoControl().