2016-01-06 09:31:53 +00:00
|
|
|
/*
|
2016-01-07 00:29:41 +00:00
|
|
|
* PROJECT: ReactOS BootVid Font Generator Utility
|
2016-01-06 09:31:53 +00:00
|
|
|
* LICENSE: GNU GPLv2 or any later version as published by the Free Software Foundation
|
2016-01-07 01:23:51 +00:00
|
|
|
* PURPOSE: Generates the FontData array for the bootdata.c file of bootvid.dll
|
2016-01-06 09:31:53 +00:00
|
|
|
* COPYRIGHT: Copyright 2016 Colin Finck <colin@reactos.org>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdio.h>
|
2016-01-07 00:29:41 +00:00
|
|
|
#include <conio.h>
|
|
|
|
#include <windows.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Enable this #define if you want to dump the generated character on screen
|
|
|
|
*/
|
|
|
|
// #define DUMP_CHAR_ON_SCREEN
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
// Windows original Blue Screen font is "Lucida Console" at FONT_SIZE 10 with no offsets.
|
2016-01-07 00:29:41 +00:00
|
|
|
#define FONT_NAME_DEF "Lucida Console" // "DejaVu Sans Mono" // "Anonymous Pro"
|
|
|
|
#define FONT_SIZE_DEF 10
|
|
|
|
#define X_OFFSET_DEF 0 // 0 // 1
|
|
|
|
#define Y_OFFSET_DEF 0
|
|
|
|
|
|
|
|
#define HEIGHT 13 // Must be == BOOTCHAR_HEIGHT (see reactos/drivers/base/bootvid/precomp.h)
|
|
|
|
#define WIDTH 8 // 8 bits == 1 byte
|
2016-01-06 09:31:53 +00:00
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
#ifdef DUMP_CHAR_ON_SCREEN
|
2016-01-06 09:31:53 +00:00
|
|
|
/**
|
|
|
|
* Sketch the character on the console screen using ASCII characters.
|
|
|
|
* Allows you to easily check if the font fits properly into the 8x13 box.
|
|
|
|
*/
|
2016-01-07 00:29:41 +00:00
|
|
|
static void DumpCharacterOnScreen(DWORD BmpBits[])
|
2016-01-06 09:31:53 +00:00
|
|
|
{
|
2016-01-07 00:29:41 +00:00
|
|
|
int i, j;
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < HEIGHT; i++)
|
|
|
|
{
|
|
|
|
for (j = WIDTH; --j >= 0;)
|
|
|
|
{
|
|
|
|
if (BmpBits[i] >> j & 0x1)
|
|
|
|
putchar(' ');
|
|
|
|
else
|
|
|
|
putchar('#');
|
|
|
|
}
|
|
|
|
|
|
|
|
putchar('\n');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
#else
|
|
|
|
|
2016-01-06 09:31:53 +00:00
|
|
|
/**
|
|
|
|
* Dump the FontData for the bootvid/i386/bootdata.c array.
|
|
|
|
*/
|
2016-01-07 00:29:41 +00:00
|
|
|
static void DumpCharacterFontData(DWORD BmpBits[])
|
2016-01-06 09:31:53 +00:00
|
|
|
{
|
|
|
|
static int iBegin = 0;
|
|
|
|
int i;
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
fprintf(stdout, " ");
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
for (i = 0; i < HEIGHT; i++)
|
2016-01-07 00:29:41 +00:00
|
|
|
fprintf(stdout, "0x%02lX, ", BmpBits[i]);
|
2016-01-06 09:31:53 +00:00
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
fprintf(stdout, " // %d\n", iBegin);
|
2016-01-06 09:31:53 +00:00
|
|
|
iBegin += HEIGHT;
|
|
|
|
}
|
2016-01-07 00:29:41 +00:00
|
|
|
#endif
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Use GDI APIs to load a monospace font and plot a single character into a bitmap.
|
|
|
|
*/
|
2016-01-07 00:29:41 +00:00
|
|
|
static BOOL PlotCharacter(HDC hDC, HFONT hFont, INT XOffset, INT YOffset, CHAR Character, DWORD BmpBits[])
|
2016-01-06 09:31:53 +00:00
|
|
|
{
|
|
|
|
BOOL bReturnValue = FALSE;
|
2016-01-07 00:29:41 +00:00
|
|
|
HBITMAP hOldBmp;
|
|
|
|
HFONT hOldFont;
|
2016-01-06 09:31:53 +00:00
|
|
|
HBITMAP hBmp = NULL;
|
2016-01-07 00:29:41 +00:00
|
|
|
BYTE BmpInfo[sizeof(BITMAPINFO) + sizeof(RGBQUAD)];
|
|
|
|
PBITMAPINFO pBmpInfo = (PBITMAPINFO)&BmpInfo;
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
hBmp = CreateCompatibleBitmap(hDC, WIDTH, HEIGHT);
|
|
|
|
if (!hBmp)
|
|
|
|
{
|
2016-01-07 00:29:41 +00:00
|
|
|
fprintf(stderr, "CreateCompatibleBitmap failed with error %lu!\n", GetLastError());
|
2016-01-06 09:31:53 +00:00
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
hOldBmp = SelectObject(hDC, hBmp);
|
|
|
|
hOldFont = SelectObject(hDC, hFont);
|
2016-01-06 09:31:53 +00:00
|
|
|
SetBkColor(hDC, RGB(0, 0, 0));
|
|
|
|
SetTextColor(hDC, RGB(255, 255, 255));
|
2016-01-07 00:29:41 +00:00
|
|
|
TextOutA(hDC, XOffset, YOffset, &Character, 1);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Use enough memory for BITMAPINFO and one additional color in the color table.
|
|
|
|
* BITMAPINFO already contains a color table entry for a single color and
|
|
|
|
* GetDIBits needs space for two colors (black and white).
|
|
|
|
*/
|
|
|
|
ZeroMemory(&BmpInfo, sizeof(BmpInfo));
|
2016-01-06 09:31:53 +00:00
|
|
|
pBmpInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
pBmpInfo->bmiHeader.biHeight = -HEIGHT;
|
|
|
|
pBmpInfo->bmiHeader.biWidth = WIDTH;
|
|
|
|
pBmpInfo->bmiHeader.biBitCount = 1;
|
|
|
|
pBmpInfo->bmiHeader.biPlanes = 1;
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
bReturnValue = TRUE;
|
|
|
|
|
2016-01-06 09:31:53 +00:00
|
|
|
if (!GetDIBits(hDC, hBmp, 0, HEIGHT, BmpBits, pBmpInfo, 0))
|
|
|
|
{
|
2016-01-07 00:29:41 +00:00
|
|
|
fprintf(stderr, "GetDIBits failed with error %lu!\n", GetLastError());
|
|
|
|
bReturnValue = FALSE;
|
2016-01-06 09:31:53 +00:00
|
|
|
}
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
SelectObject(hDC, hOldBmp);
|
|
|
|
SelectObject(hDC, hOldFont);
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
Cleanup:
|
|
|
|
if (hBmp)
|
|
|
|
DeleteObject(hBmp);
|
|
|
|
|
|
|
|
return bReturnValue;
|
|
|
|
}
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
static void DumpFont(LPSTR FontName, INT FontSize, INT XOffset, INT YOffset)
|
2016-01-06 09:31:53 +00:00
|
|
|
{
|
2016-01-07 00:29:41 +00:00
|
|
|
int iHeight;
|
|
|
|
HDC hDC = NULL;
|
|
|
|
HFONT hFont = NULL;
|
|
|
|
|
2016-01-06 09:31:53 +00:00
|
|
|
DWORD BmpBits[HEIGHT];
|
2016-01-07 00:29:41 +00:00
|
|
|
USHORT c;
|
|
|
|
|
|
|
|
hDC = CreateCompatibleDC(NULL);
|
|
|
|
if (!hDC)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "CreateCompatibleDC failed with error %lu!\n", GetLastError());
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
|
|
|
|
|
|
|
iHeight = -MulDiv(FontSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);
|
|
|
|
hFont = CreateFontA(iHeight, 0, 0, 0, FW_NORMAL, FALSE, FALSE, FALSE,
|
2016-01-07 01:23:51 +00:00
|
|
|
ANSI_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS,
|
|
|
|
NONANTIALIASED_QUALITY, FIXED_PITCH, FontName);
|
2016-01-07 00:29:41 +00:00
|
|
|
if (!hFont)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "CreateFont failed with error %lu!\n", GetLastError());
|
|
|
|
goto Cleanup;
|
|
|
|
}
|
2016-01-06 09:31:53 +00:00
|
|
|
|
|
|
|
for (c = 0; c < 256; c++)
|
|
|
|
{
|
2016-01-07 00:29:41 +00:00
|
|
|
PlotCharacter(hDC, hFont, XOffset, YOffset, (CHAR)c, BmpBits);
|
2016-01-06 09:31:53 +00:00
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
#ifdef DUMP_CHAR_ON_SCREEN
|
2016-01-06 09:31:53 +00:00
|
|
|
DumpCharacterOnScreen(BmpBits);
|
2016-01-07 00:29:41 +00:00
|
|
|
fprintf(stdout, "\nPress any key to continue...\n");
|
|
|
|
_getch();
|
2016-01-06 09:31:53 +00:00
|
|
|
system("cls");
|
|
|
|
#else
|
|
|
|
DumpCharacterFontData(BmpBits);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2016-01-07 00:29:41 +00:00
|
|
|
Cleanup:
|
|
|
|
if (hFont)
|
|
|
|
DeleteObject(hFont);
|
|
|
|
|
|
|
|
if (hDC)
|
|
|
|
DeleteDC(hDC);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
/* Validate the arguments */
|
|
|
|
if (argc > 5 || (argc >= 2 && strncmp(argv[1], "/?", 2) == 0))
|
|
|
|
{
|
|
|
|
fprintf(stdout,
|
|
|
|
"Usage: %s \"font name\" [font size] [X-offset] [Y-offset]\n"
|
|
|
|
"Default font name is: \"%s\"\n"
|
|
|
|
"Default font size is: %i\n"
|
|
|
|
"Default X-offset is: %i\n"
|
|
|
|
"Default Y-offset is: %i\n",
|
|
|
|
argv[0],
|
|
|
|
FONT_NAME_DEF, FONT_SIZE_DEF, X_OFFSET_DEF, Y_OFFSET_DEF);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
DumpFont((argc <= 1) ? FONT_NAME_DEF : argv[1],
|
|
|
|
(argc <= 2) ? FONT_SIZE_DEF : atoi(argv[2]),
|
|
|
|
(argc <= 3) ? X_OFFSET_DEF : atoi(argv[3]),
|
|
|
|
(argc <= 4) ? Y_OFFSET_DEF : atoi(argv[4]));
|
2016-01-06 09:31:53 +00:00
|
|
|
return 0;
|
|
|
|
}
|