PatchworkOS
Loading...
Searching...
No Matches
grf.h
Go to the documentation of this file.
1#ifndef GRF_H
2#define GRF_H
3
4#include <stdint.h>
5
6// This file contains definitions for the grf font format, a font format originally made for PatchworkOS.
7// Source: https://github.com/KaiNorberg/grf
8
9#if defined(_MSC_VER)
10#define GRF_PACK_START __pragma(pack(push, 1))
11#define GRF_PACK_END __pragma(pack(pop))
12#define GRF_PACK_STRUCT
13#elif defined(__GNUC__) || defined(__clang__)
14#define GRF_PACK_START
15#define GRF_PACK_END
16#define GRF_PACK_STRUCT __attribute__((packed))
17#else
18#warning "Unsupported compiler: Structures might not be packed correctly."
19#define GRF_PACK_START
20#define GRF_PACK_END
21#define GRF_PACK_STRUCT
22#endif
23
24#define GRF_MAGIC 0x47524630 // ASCII for "GRF0"
25#define GRF_NONE UINT32_MAX
26
28typedef struct GRF_PACK_STRUCT
29{
30 uint32_t magic; // GRF0.
31 int16_t ascender; // Font ascender in pixels.
32 int16_t descender; // Font descender in pixels.
33 int16_t height; // Total line height in pixels.
34 uint32_t glyphOffsets[256]; // Offsets to each grf_glyph_t in grf_t::buffer, indexed by ascii chars. GRF_NONE means
35 // "none".
36 uint32_t kernOffsets[256]; // Offsets to each grf_kern_block_t in grf_t::buffer, indexed by the starting ascii char.
37 // GRF_NONE means "none".
38 uint8_t buffer[]; // Glyphs and kerning info is stored here. No guarantee of glyph or kerning orders, could be one
39 // after the other, interleaved, etc, always use the offsets.
40} grf_t;
41
42typedef struct GRF_PACK_STRUCT
43{
44 int16_t bearingX; // Horizontal bearing.
45 int16_t bearingY; // Vertical bearing.
46 int16_t advanceX; // Horizontal advance.
47 int16_t advanceY; // Vertical advance, usually 0.
48 uint16_t width; // The width of the buffer in pixels/bytes.
49 uint16_t height; // The height of the buffer in pixels/bytes.
50 uint8_t buffer[]; // The pixel buffer, each pixel is 1 byte.
52
53typedef struct GRF_PACK_STRUCT
54{
55 uint8_t secondChar; // The second character in the kerning pair
56 int16_t offsetX; // The horizontal offset to be added to advanceX for this character pair.
57 int16_t offsetY; // The vertical to be added to advanceY for this character pair, probably 0.
59
60typedef struct GRF_PACK_STRUCT
61{
62 uint16_t amount; // The amount of kerning entries for this char
63 grf_kern_entry_t entries[]; // The entries, these entries will always be sorted by char, so the entry for 'A' is
64 // before 'B', this allows for O(log N) look ups.
67
68#endif // GRF_H
#define GRF_PACK_STRUCT
Definition grf.h:21
#define GRF_PACK_END
Definition grf.h:20
#define GRF_PACK_START
Definition grf.h:19
EFI_PHYSICAL_ADDRESS buffer
Definition mem.c:15
static start_entry_t entries[START_ENTRY_MAX]
Definition start_menu.c:21
__UINT32_TYPE__ uint32_t
Definition stdint.h:15
__UINT8_TYPE__ uint8_t
Definition stdint.h:11
__UINT16_TYPE__ uint16_t
Definition stdint.h:13
__INT16_TYPE__ int16_t
Definition stdint.h:12
uint16_t height
Definition grf.h:49
int16_t bearingY
Definition grf.h:45
uint16_t width
Definition grf.h:48
int16_t advanceX
Definition grf.h:46
int16_t advanceY
Definition grf.h:47
int16_t bearingX
Definition grf.h:44
uint16_t amount
Definition grf.h:62
Definition grf.h:54
int16_t offsetX
Definition grf.h:56
uint8_t secondChar
Definition grf.h:55
int16_t offsetY
Definition grf.h:57
Definition grf.h:29
int16_t ascender
Definition grf.h:31
uint32_t magic
Definition grf.h:30
int16_t height
Definition grf.h:33
int16_t descender
Definition grf.h:32