MCPcopy Create free account
hub / github.com/NetHack/NetHack / load_font

Function load_font

sys/msdos/font.c:13–138  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11static uint32 *uni_8to32(const char *);
12
13struct BitmapFont *
14load_font(const char *filename)
15{
16 FILE *fp;
17 struct BitmapFont *font = NULL;
18 unsigned char header[32];
19 size_t size;
20 uint32 magic;
21 uint32 version;
22 uint32 headersize;
23 uint32 fontflags;
24 uint32 length;
25 uint32 charsize;
26 uint32 height;
27 uint32 width;
28 uint32 bwidth, memsize;
29 uint32 i;
30
31 fp = fopen(filename, "rb");
32 if (fp == NULL) goto error;
33
34 /* Read the PSF header */
35 size = fread(header, 1, sizeof(header), fp);
36 if (size != sizeof(header)) goto error;
37
38 /* Convert from little endian order */
39 magic = read_u32(header + 0);
40 if (magic != 0x864AB572) goto error;
41 version = read_u32(header + 4);
42 if (version != 0) goto error;
43 headersize = read_u32(header + 8);
44 if (headersize < sizeof(header)) goto error;
45 fontflags = read_u32(header + 12);
46 length = read_u32(header + 16);
47 charsize = read_u32(header + 20);
48 height = read_u32(header + 24);
49 width = read_u32(header + 28);
50
51 /* Check that the declared character size can hold the declared width
52 and height */
53 bwidth = (width + 7) / 8;
54 memsize = bwidth * height;
55 if (memsize > charsize) goto error;
56
57 /* Allocate a font structure */
58 font = (struct BitmapFont *) alloc(sizeof(struct BitmapFont));
59 memset(font, 0, sizeof(struct BitmapFont));
60
61 /* Dimensions of the font */
62 font->width = width;
63 font->height = height;
64 font->num_glyphs = length;
65
66 /* The glyph array */
67 font->glyphs = (unsigned char **) alloc(length * sizeof(unsigned char *));
68 memset(font->glyphs, 0, length * sizeof(unsigned char *));
69
70 /* Read the glyphs */

Callers 2

vga_InitFunction · 0.85
vesa_InitFunction · 0.85

Calls 8

freadFunction · 0.85
fseekFunction · 0.85
uni_8to32Function · 0.85
add_unicode_indexFunction · 0.85
fcloseFunction · 0.85
free_fontFunction · 0.85
read_u32Function · 0.70
allocFunction · 0.50

Tested by

no test coverage detected