about summary refs log tree commit diff
path: root/lib/ppmdfont.h
blob: aa220dc0f67eddb4dd13e7fec3d62e6aa5597ae0 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#ifndef PPMDFONT_INCLUDED
#define PPMDFONT_INCLUDED

#include <stdio.h>

/* A font file has the following format, with proper packing:

    struct ppmd_fontHeader fontHeader;
    struct {
        struct ppmd_glyphHeader glyphHeader;
        struct ppmd_glyphCommand glyphCommand[N];
    } glyph[M]

    Where:
        M is fontHeader.characterCount
        N is glyphHeader.commandCount

    glyph[i] is the glyph for code point Q,
      where i = Q - fontHeader.firstCodePoint

*/

struct ppmd_fontHeader {
    char signature[8];             /* "ppmdfont" */
    unsigned char format;          /* 0x01 */
    unsigned char characterCount;
        /* Number of characters in this font */
    unsigned char firstCodePoint;
        /* lowest code point in the font */
};

struct ppmd_glyphHeader {
    unsigned char commandCount;
        /* Number of struct glyphCommand that follow */
    unsigned char skipBefore;
    unsigned char skipAfter;
};

enum ppmd_glyphCommandVerb {CMD_NOOP     = 0,
                            CMD_DRAWLINE = 1,
                            CMD_MOVEPEN  = 2
};

struct ppmd_glyphCommand {
    enum ppmd_glyphCommandVerb verb;
    unsigned char x;
    unsigned char y;
};

struct ppmd_glyph {
    struct ppmd_glyphHeader header;
    const struct ppmd_glyphCommand * commandList;
};

struct ppmd_font {
    struct ppmd_fontHeader header;
    const struct ppmd_glyph * glyphTable;
};

void
ppmd_set_font(const struct ppmd_font * const newFontP);

const struct ppmd_font *
ppmd_get_font(void);

void
ppmd_read_font(FILE *                    const ifP,
               const struct ppmd_font ** const fontPP);

void
ppmd_free_font(const struct ppmd_font * const fontP);


#endif