ReactOS  0.4.13-dev-698-g77671f0
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
27 
31 static 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 
54 static 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 
72 static 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 
117 Cleanup:
118  if (hBmp)
119  DeleteObject(hBmp);
120 
121  return bReturnValue;
122 }
123 
124 static 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 
164 Cleanup:
165  if (hFont)
167 
168  if (hDC)
169  DeleteDC(hDC);
170 }
171 
172 int main(int argc, char** argv)
173 {
174  /* Validate the arguments */
175  if (argc > 5 || (argc >= 2 && strncmp(argv[1], "/?", 2) == 0))
176  {
177  fprintf(stdout,
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 }
#define FONT_SIZE_DEF
static int argc
Definition: ServiceArgs.c:12
#define TRUE
Definition: types.h:120
static BOOL PlotCharacter(HDC hDC, HFONT hFont, INT XOffset, INT YOffset, CHAR Character, DWORD BmpBits[])
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1454
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
char CHAR
Definition: xmlstorage.h:175
_In_ CLIPOBJ _In_ BRUSHOBJ _In_ LONG x1
Definition: winddi.h:3706
#define FONT_NAME_DEF
static void DumpFont(LPSTR FontName, INT FontSize, INT XOffset, INT YOffset)
static HDC
Definition: imagelist.c:92
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1059
#define ZeroMemory
Definition: winbase.h:1635
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
#define argv
Definition: mplay32.c:18
char * LPSTR
Definition: xmlstorage.h:182
int32_t INT
Definition: typedefs.h:56
int main(int argc, char **argv)
HFONT hFont
Definition: main.c:53
FILE * stdout
#define HEIGHT
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:975
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
#define Y_OFFSET_DEF
unsigned int BOOL
Definition: ntddk_ex.h:94
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
#define FIXED_PITCH
Definition: wingdi.h:443
#define CLIP_DEFAULT_PRECIS
Definition: wingdi.h:425
int putchar(int c)
Definition: crtsupp.c:12
smooth NULL
Definition: ftsmooth.c:416
#define NONANTIALIASED_QUALITY
Definition: wingdi.h:438
int __cdecl system(_In_opt_z_ const char *_Command)
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 RGB(r, g, b)
Definition: wingdi.h:2918
const GLubyte * c
Definition: glext.h:8905
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
#define OUT_DEFAULT_PRECIS
Definition: wingdi.h:414
unsigned long DWORD
Definition: ntddk_ex.h:95
static void DumpCharacterFontData(DWORD BmpBits[])
int WINAPI GetDeviceCaps(_In_opt_ HDC, _In_ int)
unsigned char BYTE
Definition: mem.h:68
static const WCHAR Cleanup[]
Definition: register.c:80
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)
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:886
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
unsigned short USHORT
Definition: pedump.c:61
BOOL WINAPI TextOutA(_In_ HDC hdc, _In_ int x, _In_ int y, _In_reads_(c) LPCSTR lpString, _In_ int c)
#define FW_NORMAL
Definition: wingdi.h:372
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
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 c
Definition: ke_i.h:80
FILE * stderr
#define LOGPIXELSY
Definition: wingdi.h:718
struct tagBITMAPINFO * PBITMAPINFO
static HBITMAP
Definition: button.c:44
#define ANSI_CHARSET
Definition: wingdi.h:382
int _getch()
Definition: getch.c:16
#define WIDTH
#define X_OFFSET_DEF
#define MulDiv(x, y, z)
Definition: gdifloat.h:86
struct tagBITMAPINFO BITMAPINFO