ReactOS  0.4.15-dev-2144-g2282205
bootvid_font_generator.c File Reference
#include <stdio.h>
#include <conio.h>
#include <windows.h>
Include dependency graph for bootvid_font_generator.c:

Go to the source code of this file.

Macros

#define FONT_NAME_DEF   "Lucida Console"
 
#define FONT_SIZE_DEF   10
 
#define X_OFFSET_DEF   0
 
#define Y_OFFSET_DEF   0
 
#define HEIGHT   13
 
#define WIDTH   8
 

Functions

static void DumpCharacterFontData (DWORD BmpBits[])
 
static BOOL PlotCharacter (HDC hDC, HFONT hFont, INT XOffset, INT YOffset, CHAR Character, DWORD BmpBits[])
 
static void DumpFont (LPSTR FontName, INT FontSize, INT XOffset, INT YOffset)
 
int main (int argc, char **argv)
 

Macro Definition Documentation

◆ FONT_NAME_DEF

#define FONT_NAME_DEF   "Lucida Console"

Definition at line 18 of file bootvid_font_generator.c.

◆ FONT_SIZE_DEF

#define FONT_SIZE_DEF   10

Definition at line 19 of file bootvid_font_generator.c.

◆ HEIGHT

#define HEIGHT   13

Definition at line 23 of file bootvid_font_generator.c.

◆ WIDTH

#define WIDTH   8

Definition at line 24 of file bootvid_font_generator.c.

◆ X_OFFSET_DEF

#define X_OFFSET_DEF   0

Definition at line 20 of file bootvid_font_generator.c.

◆ Y_OFFSET_DEF

#define Y_OFFSET_DEF   0

Definition at line 21 of file bootvid_font_generator.c.

Function Documentation

◆ DumpCharacterFontData()

static void DumpCharacterFontData ( DWORD  BmpBits[])
static

Dump the FontData for the bootvid/i386/bootdata.c array.

Definition at line 54 of file bootvid_font_generator.c.

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 }
FILE * stdout
#define HEIGHT
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
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

Referenced by DumpFont().

◆ DumpFont()

static void DumpFont ( LPSTR  FontName,
INT  FontSize,
INT  XOffset,
INT  YOffset 
)
static

Definition at line 124 of file bootvid_font_generator.c.

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 }
static BOOL PlotCharacter(HDC hDC, HFONT hFont, INT XOffset, INT YOffset, CHAR Character, DWORD BmpBits[])
char CHAR
Definition: xmlstorage.h:175
static HDC
Definition: imagelist.c:92
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HDC WINAPI CreateCompatibleDC(_In_opt_ HDC hdc)
HFONT hFont
Definition: main.c:53
FILE * stdout
#define HEIGHT
#define FALSE
Definition: types.h:117
_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
#define NONANTIALIASED_QUALITY
Definition: wingdi.h:438
int __cdecl system(_In_opt_z_ const char *_Command)
const GLubyte * c
Definition: glext.h:8905
#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)
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)
static HDC hDC
Definition: 3dtext.c:33
BOOL WINAPI DeleteDC(_In_ HDC)
unsigned short USHORT
Definition: pedump.c:61
#define NULL
Definition: types.h:112
#define FW_NORMAL
Definition: wingdi.h:372
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
#define c
Definition: ke_i.h:80
FILE * stderr
#define LOGPIXELSY
Definition: wingdi.h:718
#define ANSI_CHARSET
Definition: wingdi.h:382
int _getch()
Definition: getch.c:16
#define MulDiv(x, y, z)
Definition: gdifloat.h:86

Referenced by main().

◆ main()

int main ( int argc  ,
char **  argv 
)

Definition at line 172 of file bootvid_font_generator.c.

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 FONT_NAME_DEF
static void DumpFont(LPSTR FontName, INT FontSize, INT XOffset, INT YOffset)
#define argv
Definition: mplay32.c:18
FILE * stdout
#define Y_OFFSET_DEF
_Check_return_opt_ _CRTIMP int __cdecl fprintf(_Inout_ FILE *_File, _In_z_ _Printf_format_string_ const char *_Format,...)
int strncmp(const char *String1, const char *String2, ACPI_SIZE Count)
Definition: utclib.c:534
_Check_return_ int __cdecl atoi(_In_z_ const char *_Str)
#define X_OFFSET_DEF

◆ PlotCharacter()

static BOOL PlotCharacter ( HDC  hDC,
HFONT  hFont,
INT  XOffset,
INT  YOffset,
CHAR  Character,
DWORD  BmpBits[] 
)
static

Use GDI APIs to load a monospace font and plot a single character into a bitmap.

Definition at line 72 of file bootvid_font_generator.c.

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 }
BITMAPINFOHEADER bmiHeader
Definition: wingdi.h:1475
#define RGB(r, g, b)
Definition: precomp.h:62
HBITMAP WINAPI CreateCompatibleBitmap(_In_ HDC hdc, _In_ INT cx, _In_ INT cy)
#define TRUE
Definition: types.h:120
struct tagBITMAPINFOHEADER BITMAPINFOHEADER
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1499
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1664
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
HFONT hFont
Definition: main.c:53
#define HEIGHT
COLORREF WINAPI SetBkColor(_In_ HDC, _In_ COLORREF)
Definition: dc.c:977
#define FALSE
Definition: types.h:117
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,...)
ULONG RGBQUAD
Definition: precomp.h:50
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned char BYTE
Definition: xxhash.c:193
COLORREF WINAPI SetTextColor(_In_ HDC, _In_ COLORREF)
Definition: text.c:888
static HDC hDC
Definition: 3dtext.c:33
#define NULL
Definition: types.h:112
BOOL WINAPI TextOutA(_In_ HDC hdc, _In_ int x, _In_ int y, _In_reads_(c) LPCSTR lpString, _In_ int c)
static DWORD *static HFONT(WINAPI *pCreateFontIndirectExA)(const ENUMLOGFONTEXDVA *)
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)
FILE * stderr
struct tagBITMAPINFO * PBITMAPINFO
static HBITMAP
Definition: button.c:44
#define WIDTH
struct tagBITMAPINFO BITMAPINFO

Referenced by DumpFont().