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
27
GRF_PACK_START
28
typedef
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
42
typedef
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.
51
}
grf_glyph_t
;
52
53
typedef
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.
58
}
grf_kern_entry_t
;
59
60
typedef
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.
65
}
grf_kern_block_t
;
66
GRF_PACK_END
67
68
#endif
// GRF_H
GRF_PACK_STRUCT
#define GRF_PACK_STRUCT
Definition
grf.h:21
GRF_PACK_END
#define GRF_PACK_END
Definition
grf.h:20
GRF_PACK_START
#define GRF_PACK_START
Definition
grf.h:19
buffer
EFI_PHYSICAL_ADDRESS buffer
Definition
mem.c:15
entries
static start_entry_t entries[START_ENTRY_MAX]
Definition
start_menu.c:21
stdint.h
uint32_t
__UINT32_TYPE__ uint32_t
Definition
stdint.h:15
uint8_t
__UINT8_TYPE__ uint8_t
Definition
stdint.h:11
uint16_t
__UINT16_TYPE__ uint16_t
Definition
stdint.h:13
int16_t
__INT16_TYPE__ int16_t
Definition
stdint.h:12
grf_glyph_t
Definition
grf.h:43
grf_glyph_t::height
uint16_t height
Definition
grf.h:49
grf_glyph_t::bearingY
int16_t bearingY
Definition
grf.h:45
grf_glyph_t::width
uint16_t width
Definition
grf.h:48
grf_glyph_t::advanceX
int16_t advanceX
Definition
grf.h:46
grf_glyph_t::advanceY
int16_t advanceY
Definition
grf.h:47
grf_glyph_t::bearingX
int16_t bearingX
Definition
grf.h:44
grf_kern_block_t
Definition
grf.h:61
grf_kern_block_t::amount
uint16_t amount
Definition
grf.h:62
grf_kern_entry_t
Definition
grf.h:54
grf_kern_entry_t::offsetX
int16_t offsetX
Definition
grf.h:56
grf_kern_entry_t::secondChar
uint8_t secondChar
Definition
grf.h:55
grf_kern_entry_t::offsetY
int16_t offsetY
Definition
grf.h:57
grf_t
Definition
grf.h:29
grf_t::ascender
int16_t ascender
Definition
grf.h:31
grf_t::magic
uint32_t magic
Definition
grf.h:30
grf_t::height
int16_t height
Definition
grf.h:33
grf_t::descender
int16_t descender
Definition
grf.h:32
src
libpatchwork
grf.h
Generated by
1.9.8