1 /*
2  * FILE:     pktest.c
3  *
4  * PURPOSE:  This program demonstrates how a PK file can be created from
5  *           a single character bitmap.
6  *
7  * USAGE:    pktest -c<char_code> -W<with> -H<Height> pkname < test.bm
8  *	     (test.bm contains the character from `The GFtoPK processor')
9  *
10  * VERSION:  1.7 (December 2014)
11  *
12  * AUTHOR:   Piet Tutelaers (rcpt@urc.tue.nl)
13  */
14 
15 int testing = 1;
16 #include <stdio.h>
17 #include "basics.h"	/* fatal() */
18 #include "pkout.h"
19 
20 static int next_pixel(void);
21 
main(int argc,char * argv[])22 int main(int argc, char *argv[])
23 {
24    int done, C = 0, W = 0, H = 0, c;
25    const char *myname;
26    char *pkname, comment[256];
27 
28    myname = argv[0];
29    while (--argc > 0 && (*++argv)[0] == '-') {
30       done=0;
31       while ((!done) && (c = *++argv[0])) /* allow multiletter options */
32          switch (c) {
33       	 case 'c':
34       	    C = *++argv[0];
35       	    if (C == '\0') {
36       	       argc--;  C = *++argv[0];
37       	    }
38       	    break;
39       	 case 'H':
40       	    if (*++argv[0] == '\0') {
41       	       argc--;  argv++;
42       	    }
43 	    H = atoi(*argv); done = 1;
44       	    break;
45       	 case 'W':
46       	    if (*++argv[0] == '\0') {
47       	       argc--;  argv++;
48       	    }
49 	    W = atoi(*argv); done = 1;
50       	    break;
51       	 default:
52       	    fatal("%s: %c illegal option\n", myname, c);
53       	 }
54    }
55 
56    if (argc == 0 || C == 0 || W*H == 0)
57       fatal("Usage: %s -c<char> -W<width> -H<height> pkfile\n", myname);
58 
59    pkname = argv[0];
60    pk_open(pkname);
61 
62    sprintf(comment, "Testfont %s designed at 10 points", pkname);
63    pk_preamble(comment, 10.0, 1473505522, 120, 120);
64    printf("character %c Width %d Height %d\n", C, W, H);
65    pk_char(C, 640796, 25, W, H, -2, 28, next_pixel);
66    pk_postamble();
67    pk_close();
68    return 0;
69 }
70 
71 /* This function delivers the pixels from the character's bounding box
72  * from left to right and from top to bottom.
73  */
next_pixel(void)74 static int next_pixel(void)
75 {  int c;
76    do { c = getchar();
77       if (c==EOF) fatal("reading past end of file!\n");
78       if (c == '*' || c == 'X') return BLACK;
79       if (c == '.') return WHITE;
80    } while (1);
81 }
82 
83 /* The character example from GFtoPK:
84   ********************
85   ********************
86   ********************
87   ********************
88   **................**
89   **................**
90   **................**
91   ....................
92   ....................
93   ..**............**..
94   ..**............**..
95   ..**............**..
96   ..****************..
97   ..****************..
98   ..****************..
99   ..****************..
100   ..**............**..
101   ..**............**..
102   ..**............**..
103   ....................
104   ....................
105   ....................
106   **................**
107   **................**
108   **................**
109   ********************
110   ********************
111   ********************
112   ********************
113 */
114