ReactOS  0.4.15-dev-1200-gc3b3fcd
font.c File Reference
#include "blue.h"
#include <ndk/rtlfuncs.h>
#include <debug.h>
Include dependency graph for font.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

NTSTATUS ExtractFont (_In_ ULONG CodePage, _In_ PUCHAR FontBitField)
 
VOID OpenBitPlane (VOID)
 
VOID CloseBitPlane (VOID)
 
VOID LoadFont (_In_ PUCHAR Bitplane, _In_ PUCHAR FontBitfield)
 
VOID ScrLoadFontTable (_In_ ULONG CodePage)
 
VOID ScrSetFont (_In_ PUCHAR FontBitfield)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 15 of file font.c.

Function Documentation

◆ CloseBitPlane()

VOID CloseBitPlane ( VOID  )

Definition at line 301 of file font.c.

302 {
303  /* disable interrupts */
304  _disable();
305 
306  /* sequence reg */
311 
312  /* graphic reg */
316 
317  /* enable interrupts */
318  _enable();
319 }
void __cdecl _enable(void)
Definition: intrin_arm.h:373
#define SEQ_COMMAND
Definition: blue.h:114
#define SEQ_DATA
Definition: blue.h:115
#define SEQ_MEM_MODE
Definition: blue.h:123
#define SEQ_ENABLE_WRT_PLANE
Definition: blue.h:122
#define SEQ_RESET
Definition: blue.h:121
#define GCT_DATA
Definition: blue.h:118
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:20
#define GCT_RW_MODES
Definition: blue.h:127
#define GCT_GRAPH_MODE
Definition: blue.h:128
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define GCT_COMMAND
Definition: blue.h:117
#define GCT_READ_PLANE
Definition: blue.h:126

Referenced by ScrLoadFontTable(), and ScrSetFont().

◆ ExtractFont()

NTSTATUS ExtractFont ( _In_ ULONG  CodePage,
_In_ PUCHAR  FontBitField 
)

Definition at line 90 of file font.c.

93 {
94  BOOLEAN bFoundFile = FALSE;
95  HANDLE Handle;
97  CHAR FileName[20];
100  UNICODE_STRING LinkName;
102  CFHEADER CabFileHeader;
103  CFFILE CabFile;
104  ULONG CabFileOffset = 0;
106  WCHAR SourceBuffer[MAX_PATH] = { L'\0' };
107  ULONG ReadCP;
108 
111 
112  RtlInitUnicodeString(&LinkName,
113  L"\\SystemRoot");
114 
116  &LinkName,
118  NULL,
119  NULL);
120 
124 
125  if (!NT_SUCCESS(Status))
126  {
127  DPRINT1("ZwOpenSymbolicLinkObject failed with Status 0x%lx\n", Status);
128  return Status;
129  }
130 
131  SourceName.Length = 0;
132  SourceName.MaximumLength = MAX_PATH * sizeof(WCHAR);
133  SourceName.Buffer = SourceBuffer;
134 
135  Status = ZwQuerySymbolicLinkObject(Handle,
136  &SourceName,
137  NULL);
138  ZwClose(Handle);
139 
140  if (!NT_SUCCESS(Status))
141  {
142  DPRINT1("ZwQuerySymbolicLinkObject failed with Status 0x%lx\n", Status);
143  return Status;
144  }
145 
146  Status = RtlAppendUnicodeToString(&SourceName, L"\\vgafonts.cab");
147  if (!NT_SUCCESS(Status))
148  {
149  DPRINT1("RtlAppendUnicodeToString failed with Status 0x%lx\n", Status);
150  return Status;
151  }
152 
154  &SourceName,
156  NULL,
157  NULL);
158 
159  Status = ZwCreateFile(&Handle,
160  GENERIC_READ,
162  &IoStatusBlock,
163  NULL,
165  0,
166  FILE_OPEN,
168  NULL,
169  0);
170  if (!NT_SUCCESS(Status))
171  {
172  DPRINT1("Error: Cannot open vgafonts.cab (0x%lx)\n", Status);
173  return Status;
174  }
175 
176  ByteOffset.QuadPart = 0;
177  Status = ZwReadFile(Handle,
178  NULL,
179  NULL,
180  NULL,
181  &IoStatusBlock,
182  &CabFileHeader,
183  sizeof(CabFileHeader),
184  &ByteOffset,
185  NULL);
186 
187  if (!NT_SUCCESS(Status))
188  {
189  DPRINT1("Error: Cannot read from file (0x%lx)\n", Status);
190  goto Exit;
191  }
192 
193  if (CabFileHeader.Signature != CAB_SIGNATURE)
194  {
195  DPRINT1("Invalid CAB signature: 0x%lx!\n", CabFileHeader.Signature);
197  goto Exit;
198  }
199 
200  // We have a valid CAB file!
201  // Read the file table now and decrement the file count on every file. When it's zero, we read the complete table.
202  ByteOffset.QuadPart = CabFileHeader.FileTableOffset;
203 
204  while (CabFileHeader.FileCount)
205  {
206  Status = ZwReadFile(Handle,
207  NULL,
208  NULL,
209  NULL,
210  &IoStatusBlock,
211  &CabFile,
212  sizeof(CabFile),
213  &ByteOffset,
214  NULL);
215 
216  if (NT_SUCCESS(Status))
217  {
218  ByteOffset.QuadPart += sizeof(CabFile);
219 
220  // We assume here that the file name is max. 19 characters (+ 1 NULL character) long.
221  // This should be enough for our purpose.
222  Status = ZwReadFile(Handle,
223  NULL,
224  NULL,
225  NULL,
226  &IoStatusBlock,
227  FileName,
228  sizeof(FileName),
229  &ByteOffset,
230  NULL);
231 
232  if (NT_SUCCESS(Status))
233  {
234  if (!bFoundFile)
235  {
236  Status = RtlCharToInteger(FileName, 0, &ReadCP);
237  if (NT_SUCCESS(Status) && ReadCP == CodePage)
238  {
239  // We got the correct file.
240  // Save the offset and loop through the rest of the file table to find the position, where the actual data starts.
241  CabFileOffset = CabFile.FileOffset;
242  bFoundFile = TRUE;
243  }
244  }
245 
246  ByteOffset.QuadPart += strlen(FileName) + 1;
247  }
248  }
249 
250  CabFileHeader.FileCount--;
251  }
252 
253  // 8 = Size of a CFFOLDER structure (see cabman). As we don't need the values of that structure, just increase the offset here.
254  ByteOffset.QuadPart += 8;
255  ByteOffset.QuadPart += CabFileOffset;
256 
257  // ByteOffset now contains the offset of the actual data, so we can read the RAW font
258  Status = ZwReadFile(Handle,
259  NULL,
260  NULL,
261  NULL,
262  &IoStatusBlock,
263  FontBitField,
264  2048,
265  &ByteOffset,
266  NULL);
267  if (!NT_SUCCESS(Status))
268  {
269  DPRINT1("ZwReadFile failed with Status 0x%lx\n", Status);
270  }
271 
272 Exit:
273 
274  ZwClose(Handle);
275  return Status;
276 }
#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 OBJ_CASE_INSENSITIVE
Definition: winternl.h:228
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
#define TRUE
Definition: types.h:120
NTSYSAPI NTSTATUS NTAPI ZwClose(_In_ HANDLE Handle)
char CHAR
Definition: xmlstorage.h:175
LONG NTSTATUS
Definition: precomp.h:26
#define OBJ_KERNEL_HANDLE
Definition: winternl.h:231
#define SYMBOLIC_LINK_ALL_ACCESS
Definition: nt_native.h:1267
#define STATUS_INVALID_DEVICE_STATE
Definition: udferr_usr.h:178
#define FALSE
Definition: types.h:117
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:34
Definition: fci.c:89
#define CAB_SIGNATURE
Definition: cabinet.c:47
#define STATUS_UNSUCCESSFUL
Definition: udferr_usr.h:132
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:137
Status
Definition: gdiplustypes.h:24
static const WCHAR L[]
Definition: oid.c:1250
#define GENERIC_READ
Definition: compat.h:135
#define PASSIVE_LEVEL
Definition: env_spec_w32.h:693
#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
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:725

Referenced by ScrLoadFontTable().

◆ LoadFont()

VOID LoadFont ( _In_ PUCHAR  Bitplane,
_In_ PUCHAR  FontBitfield 
)

Definition at line 322 of file font.c.

325 {
326  UINT32 i, j;
327 
328  for (i = 0; i < 256; i++)
329  {
330  for (j = 0; j < 8; j++)
331  {
332  *Bitplane = FontBitfield[i * 8 + j];
333  Bitplane++;
334  }
335 
336  // padding
337  for (j = 8; j < 32; j++)
338  {
339  *Bitplane = 0;
340  Bitplane++;
341  }
342  }
343 }
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(), and ScrSetFont().

◆ OpenBitPlane()

VOID OpenBitPlane ( 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:114
#define SEQ_DATA
Definition: blue.h:115
#define SEQ_MEM_MODE
Definition: blue.h:123
#define SEQ_ENABLE_WRT_PLANE
Definition: blue.h:122
#define SEQ_RESET
Definition: blue.h:121
#define GCT_DATA
Definition: blue.h:118
#define WRITE_PORT_UCHAR(p, d)
Definition: pc98vid.h:20
#define GCT_RW_MODES
Definition: blue.h:127
#define GCT_GRAPH_MODE
Definition: blue.h:128
void __cdecl _disable(void)
Definition: intrin_arm.h:365
#define GCT_COMMAND
Definition: blue.h:117
#define GCT_READ_PLANE
Definition: blue.h:126

Referenced by ScrLoadFontTable(), and ScrSetFont().

◆ ScrLoadFontTable()

VOID ScrLoadFontTable ( _In_ ULONG  CodePage)

Definition at line 26 of file font.c.

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

Referenced by ScrAcquireOwnership(), and ScrIoControl().

◆ ScrSetFont()

VOID ScrSetFont ( _In_ PUCHAR  FontBitfield)

Definition at line 66 of file font.c.

68 {
70  PUCHAR Bitplane;
71 
72  /* open bit plane for font table access */
73  OpenBitPlane();
74 
75  /* get pointer to video memory */
76  BaseAddress.QuadPart = BITPLANE_BASE;
77  Bitplane = (PUCHAR)MmMapIoSpace(BaseAddress, 0xFFFF, MmNonCached);
78 
79  LoadFont(Bitplane, FontBitfield);
80 
81  MmUnmapIoSpace(Bitplane, 0xFFFF);
82 
83  /* close bit plane */
84  CloseBitPlane();
85 }
VOID CloseBitPlane(VOID)
Definition: font.c:301
unsigned char * PUCHAR
Definition: retypes.h:3
PVOID NTAPI MmMapIoSpace(IN PHYSICAL_ADDRESS PhysicalAddress, IN SIZE_T NumberOfBytes, IN MEMORY_CACHING_TYPE CacheType)
Definition: iosup.c:47
_In_ HANDLE _Outptr_result_bytebuffer_ ViewSize PVOID * BaseAddress
Definition: mmfuncs.h:404
VOID LoadFont(_In_ PUCHAR Bitplane, _In_ PUCHAR FontBitfield)
Definition: font.c:322
#define BITPLANE_BASE
Definition: blue.h:100
VOID NTAPI MmUnmapIoSpace(IN PVOID BaseAddress, IN SIZE_T NumberOfBytes)
Definition: iosup.c:193
VOID OpenBitPlane(VOID)
Definition: font.c:280

Referenced by ScrAcquireOwnership(), and ScrIoControl().