ReactOS 0.4.16-dev-122-g325d74c
bootvid_font_generator.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS BootVid Font Generator Utility
3 * LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
4 * PURPOSE: Generates the FontData array for the bootdata.c file of bootvid.dll
5 * COPYRIGHT: Copyright 2016 Colin Finck <colin@reactos.org>
6 */
7
8#include <stdio.h>
9#include <conio.h>
10#include <windows.h>
11
12/*
13 * Enable this #define if you want to dump the generated character on screen
14 */
15// #define DUMP_CHAR_ON_SCREEN
16
17// Windows original Blue Screen font is "Lucida Console" at FONT_SIZE 10 with no offsets.
18#define FONT_NAME_DEF "Lucida Console" // "DejaVu Sans Mono" // "Anonymous Pro"
19#define FONT_SIZE_DEF 10
20#define X_OFFSET_DEF 0 // 0 // 1
21#define Y_OFFSET_DEF 0
22
23#define HEIGHT 13 // Must be == BOOTCHAR_HEIGHT (see reactos/drivers/base/bootvid/precomp.h)
24#define WIDTH 8 // 8 bits == 1 byte
25
26#ifdef DUMP_CHAR_ON_SCREEN
31static void DumpCharacterOnScreen(DWORD BmpBits[])
32{
33 int i, j;
34
35 for (i = 0; i < HEIGHT; i++)
36 {
37 for (j = WIDTH; --j >= 0;)
38 {
39 if (BmpBits[i] >> j & 0x1)
40 putchar(' ');
41 else
42 putchar('#');
43 }
44
45 putchar('\n');
46 }
47}
48
49#else
50
54static void DumpCharacterFontData(DWORD BmpBits[])
55{
56 static int iBegin = 0;
57 int i;
58
59 fprintf(stdout, " ");
60
61 for (i = 0; i < HEIGHT; i++)
62 fprintf(stdout, "0x%02lX, ", BmpBits[i]);
63
64 fprintf(stdout, " // %d\n", iBegin);
65 iBegin += HEIGHT;
66}
67#endif
68
72static BOOL PlotCharacter(HDC hDC, HFONT hFont, INT XOffset, INT YOffset, CHAR Character, DWORD BmpBits[])
73{
74 BOOL bReturnValue = FALSE;
75 HBITMAP hOldBmp;
76 HFONT hOldFont;
77 HBITMAP hBmp = NULL;
78 BYTE BmpInfo[sizeof(BITMAPINFO) + sizeof(RGBQUAD)];
79 PBITMAPINFO pBmpInfo = (PBITMAPINFO)&BmpInfo;
80
82 if (!hBmp)
83 {
84 fprintf(stderr, "CreateCompatibleBitmap failed with error %lu!\n", GetLastError());
85 goto Cleanup;
86 }
87
88 hOldBmp = SelectObject(hDC, hBmp);
89 hOldFont = SelectObject(hDC, hFont);
90 SetBkColor(hDC, RGB(0, 0, 0));
91 SetTextColor(hDC, RGB(255, 255, 255));
92 TextOutA(hDC, XOffset, YOffset, &Character, 1);
93
94 /*
95 * Use enough memory for BITMAPINFO and one additional color in the color table.
96 * BITMAPINFO already contains a color table entry for a single color and
97 * GetDIBits needs space for two colors (black and white).
98 */
99 ZeroMemory(&BmpInfo, sizeof(BmpInfo));
100 pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
101 pBmpInfo->bmiHeader.biHeight = -HEIGHT;
102 pBmpInfo->bmiHeader.biWidth = WIDTH;
103 pBmpInfo->bmiHeader.biBitCount = 1;
104 pBmpInfo->bmiHeader.biPlanes = 1;
105
106 bReturnValue = TRUE;
107
108 if (!GetDIBits(hDC, hBmp, 0, HEIGHT, BmpBits, pBmpInfo, 0))
109 {
110 fprintf(stderr, "GetDIBits failed with error %lu!\n", GetLastError());
111 bReturnValue = FALSE;
112 }
113
114 SelectObject(hDC, hOldBmp);
115 SelectObject(hDC, hOldFont);
116
117Cleanup:
118 if (hBmp)
119 DeleteObject(hBmp);
120
121 return bReturnValue;
122}
123
124static void DumpFont(LPSTR FontName, INT FontSize, INT XOffset, INT YOffset)
125{
126 int iHeight;
127 HDC hDC = NULL;
128 HFONT hFont = NULL;
129
130 DWORD BmpBits[HEIGHT];
131 USHORT c;
132
134 if (!hDC)
135 {
136 fprintf(stderr, "CreateCompatibleDC failed with error %lu!\n", GetLastError());
137 goto Cleanup;
138 }
139
140 iHeight = -MulDiv(FontSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
141 hFont = CreateFontA(iHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
144 if (!hFont)
145 {
146 fprintf(stderr, "CreateFont failed with error %lu!\n", GetLastError());
147 goto Cleanup;
148 }
149
150 for (c = 0; c < 256; c++)
151 {
152 PlotCharacter(hDC, hFont, XOffset, YOffset, (CHAR)c, BmpBits);
153
154#ifdef DUMP_CHAR_ON_SCREEN
155 DumpCharacterOnScreen(BmpBits);
156 fprintf(stdout, "\nPress any key to continue...\n");
157 _getch();
158 system("cls");
159#else
160 DumpCharacterFontData(BmpBits);
161#endif
162 }
163
164Cleanup:
165 if (hFont)
167
168 if (hDC)
169 DeleteDC(hDC);
170}
171
172int main(int argc, char** argv)
173{
174 /* Validate the arguments */
175 if (argc > 5 || (argc >= 2 && strncmp(argv[1], "/?", 2) == 0))
176 {
178 "Usage: %s \"font name\" [font size] [X-offset] [Y-offset]\n"
179 "Default font name is: \"%s\"\n"
180 "Default font size is: %i\n"
181 "Default X-offset is: %i\n"
182 "Default Y-offset is: %i\n",
183 argv[0],
185
186 return -1;
187 }
188
189 DumpFont((argc <= 1) ? FONT_NAME_DEF : argv[1],
190 (argc <= 2) ? FONT_SIZE_DEF : atoi(argv[2]),
191 (argc <= 3) ? X_OFFSET_DEF : atoi(argv[3]),
192 (argc <= 4) ? Y_OFFSET_DEF : atoi(argv[4]));
193 return 0;
194}
static HDC hDC
Definition: 3dtext.c:33
static int argc
Definition: ServiceArgs.c:12
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
HFONT hFont
Definition: main.c:53
#define WIDTH
static void DumpFont(LPSTR FontName, INT FontSize, INT XOffset, INT YOffset)
#define X_OFFSET_DEF
#define FONT_NAME_DEF
static void DumpCharacterFontData(DWORD BmpBits[])
#define FONT_SIZE_DEF
static BOOL PlotCharacter(HDC hDC, HFONT hFont, INT XOffset, INT YOffset, CHAR Character, DWORD BmpBits[])
#define HEIGHT
#define Y_OFFSET_DEF
int putchar(int c)
Definition: crtsupp.c:12
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
static const WCHAR Cleanup[]
Definition: register.c:80
#define RGB(r, g, b)
Definition: precomp.h:71
ULONG RGBQUAD
Definition: precomp.h:59
int main()
Definition: test.c:6
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
pKey DeleteObject()
const GLubyte * c
Definition: glext.h:8905
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
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
#define stdout
Definition: stdio.h:99
#define stderr
Definition: stdio.h:100
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define c
Definition: ke_i.h:80
static HBITMAP
Definition: button.c:44
static HDC
Definition: imagelist.c:88
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define argv
Definition: mplay32.c:18
INT WINAPI MulDiv(INT nNumber, INT nNumerator, INT nDenominator)
Definition: muldiv.c:25
unsigned short USHORT
Definition: pedump.c:61
int __cdecl system(_In_opt_z_ const char *_Command)
int _getch()
Definition: getch.c:16
USHORT biBitCount
Definition: precomp.h:46
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1476
int32_t INT
Definition: typedefs.h:58
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FIXED_PITCH
Definition: wingdi.h:444
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:999
int WINAPI GetDIBits(_In_ HDC hdc, _In_ HBITMAP hbm, _In_ UINT start, _In_ UINT cLines, _Out_opt_ LPVOID lpvBits, _At_((LPBITMAPINFOHEADER) lpbmi, _Inout_) LPBITMAPINFO lpbmi, _In_ UINT usage)
#define LOGPIXELSY
Definition: wingdi.h:719
BOOL WINAPI TextOutA(_In_ HDC hdc, _In_ int x, _In_ int y, _In_reads_(c) LPCSTR lpString, _In_ int c)
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1546
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:415
#define ANSI_CHARSET
Definition: wingdi.h:383
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:426
#define FW_NORMAL
Definition: wingdi.h:373
struct tagBITMAPINFO BITMAPINFO
HFONT WINAPI CreateFontA(_In_ int, _In_ int, _In_ int, _In_ int, _In_ int, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_ DWORD, _In_opt_ LPCSTR)
struct tagBITMAPINFO * PBITMAPINFO
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:918
BOOL WINAPI DeleteDC(_In_ HDC)
#define NONANTIALIASED_QUALITY
Definition: wingdi.h:439
char * LPSTR
Definition: xmlstorage.h:182
char CHAR
Definition: xmlstorage.h:175
unsigned char BYTE
Definition: xxhash.c:193