Debian Codegraph @

texk/ps2pk/pktest.c

raw
1 /* FILE: pktest.c
2 * PURPOSE: This program demonstrates how a PK file can be created from
3 * a single character bitmap.
4 * USAGE: pktest -c<char_code> -W<with> -H<Height> pkname < test.bm
5 * (test.bm contains the character from `The GFtoPK processor')
6 * AUTHOR: Piet Tutelaers
7 * (see README for license)
8 */
9
10 int testing = 1;
11 #include <stdio.h>
12 #include "basics.h" /* fatal() */
13 #include "pkout.h"
14
15 static int next_pixel(void);
16
17 int main(int argc, char *argv[])
18 {
19 int done, C = 0, W = 0, H = 0, c;
20 const char *myname;
21 char *pkname, comment[256];
22
23 myname = argv[0];
24 while (--argc > 0 && (*++argv)[0] == '-') {
25 done=0;
26 while ((!done) && (c = *++argv[0])) /* allow multiletter options */
27 switch (c) {
28 case 'c':
29 C = *++argv[0];
30 if (C == '\0') {
31 argc--; C = *++argv[0];
32 }
33 break;
34 case 'H':
35 if (*++argv[0] == '\0') {
36 argc--; argv++;
37 }
38 H = atoi(*argv); done = 1;
39 break;
40 case 'W':
41 if (*++argv[0] == '\0') {
42 argc--; argv++;
43 }
44 W = atoi(*argv); done = 1;
45 break;
46 default:
47 fatal("%s: %c invalid option\n", myname, c);
48 }
49 }
50
51 if (argc == 0 || C == 0 || W*H == 0) {
52 msg ("pktest (ps2pk) version " PACKAGE_VERSION " (" TL_VERSION ")\n");
53 msg ("Usage: %s -c<char> -W<width> -H<height> pkfile\n", myname);
54 fatal("\nEmail bug reports to %s.\n", PACKAGE_BUGREPORT);
55 }
56
57 pkname = argv[0];
58 pk_open(pkname);
59
60 sprintf(comment, "Testfont %s designed at 10 points", pkname);
61 pk_preamble(comment, 10.0, 1473505522, 120, 120);
62 printf("character %c Width %d Height %d\n", C, W, H);
63 pk_char(C, 640796, 25, W, H, -2, 28, next_pixel);
64 pk_postamble();
65 pk_close();
66 return 0;
67 }
68
69 /* This function delivers the pixels from the character's bounding box
70 * from left to right and from top to bottom.
71 */
72 static int next_pixel(void)
73 { int c;
74 do { c = getchar();
75 if (c==EOF) fatal("reading past end of file!\n");
76 if (c == '*' || c == 'X') return BLACK;
77 if (c == '.') return WHITE;
78 } while (1);
79 }
80
81 /* The character example from GFtoPK:
82 ********************
83 ********************
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 */