about summary refs log tree commit diff
path: root/other/ppmddumpfont.c
blob: 3ab477abb90592560b5ffe0b08d3969910f45c28 (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
#include <stdio.h>
#include <assert.h>

#include "ppm.h"
#include "ppmdfont.h"



static int
untwos(unsigned char const arg) {

    if (arg >= 128)
        return arg - 256;
    else
        return arg;
}



static void
dumpHeader(struct ppmd_fontHeader const fontHeader) {
    
    pm_message("Font has %u characters", fontHeader.characterCount);
    pm_message("Font has code points %u through %u",
               fontHeader.firstCodePoint,
               fontHeader.firstCodePoint + fontHeader.characterCount - 1);
}



static void
dumpGlyph(struct ppmd_glyph const glyph) {

    unsigned int commandNum;

    pm_message("  skip before: %u pixels; skip after: %u pixels; "
               "%u commands:", 
               glyph.header.skipBefore,
               glyph.header.skipAfter,
               glyph.header.commandCount);

    for (commandNum = 0;
         commandNum < glyph.header.commandCount;
         ++commandNum) {
         
        struct ppmd_glyphCommand const glyphCommand =
            glyph.commandList[commandNum];
        
        const char * verbDisp;

        switch (glyphCommand.verb) {
        case CMD_NOOP:     verbDisp = "NOOP";     break;
        case CMD_DRAWLINE: verbDisp = "DRAWLINE"; break;
        case CMD_MOVEPEN:  verbDisp = "MOVEPEN";  break;
        }

        pm_message("    %s %d %d",
                   verbDisp, untwos(glyphCommand.x), untwos(glyphCommand.y));
    }
}



int
main(int argc, char **argv) {

    const struct ppmd_font * fontP;
    unsigned int relativeCodePoint;

    ppm_init(&argc, argv);

    ppmd_read_font(stdin, &fontP);

    dumpHeader(fontP->header);

    for (relativeCodePoint = 0;
         relativeCodePoint < fontP->header.characterCount;
         ++relativeCodePoint) {

        pm_message("Code point %u:",
                   fontP->header.firstCodePoint + relativeCodePoint);

        dumpGlyph(fontP->glyphTable[relativeCodePoint]);
    }

    ppmd_free_font(fontP);
    
    return 0;
}