Back to index

tetex-bin  3.0
pktest.c
Go to the documentation of this file.
00001 /*
00002  * FILE:     pktest.c 
00003  *
00004  * PURPOSE:  This program demonstrates how a PK file can be created from
00005  *           a single character bitmap.
00006  *
00007  * USAGE:    pktest -c<char_code> -W<with> -H<Height> pkname < test.bm
00008  *          (test.bm contains the character from `The GFtoPK processor')
00009  *
00010  * VERSION:  Febr. 1992
00011  *
00012  * AUTHOR:   Piet Tutelaers (rcpt@urc.tue.nl)
00013  */
00014 
00015 int testing = 1;
00016 #include <stdio.h>
00017 #include "basics.h"  /* fatal() */
00018 #include "pkout.h"
00019 
00020 main(int argc, char *argv[])
00021 {
00022    int done, C = 0, W = 0, H = 0, c;
00023    char *myname, *pkname, comment[256];
00024    int next_pixel();
00025        
00026    myname = argv[0];
00027    while (--argc > 0 && (*++argv)[0] == '-') {
00028       done=0;
00029       while ((!done) && (c = *++argv[0])) /* allow multiletter options */
00030          switch (c) {
00031         case 'c':
00032            C = *++argv[0];
00033            if (C == '\0') {
00034               argc--;  C = *++argv[0];
00035            }
00036            break;
00037         case 'H':
00038            if (*++argv[0] == '\0') {
00039               argc--;  argv++;
00040            }
00041            H = atoi(*argv); done = 1;
00042            break;
00043         case 'W':
00044            if (*++argv[0] == '\0') {
00045               argc--;  argv++;
00046            }
00047            W = atoi(*argv); done = 1;
00048            break;
00049         default:
00050            fatal("%s: %c illegal option\n", myname, c);
00051         }
00052    }
00053 
00054    if (argc == 0 || C == 0 || W*H == 0)
00055       fatal("Usage: %s -c<char> -W<width> -H<height> pkfile\n", myname);
00056 
00057    pkname = argv[0];
00058    pk_open(pkname);
00059    
00060    sprintf(comment, "Testfont %s designed at 10 points", pkname);
00061    pk_preamble(comment, 10.0, 1473505522, 120, 120);
00062    printf("character %c Width %d Height %d\n", C, W, H);
00063    pk_char(C, 640796, 25, W, H, -2, 28, next_pixel);
00064    pk_postamble();
00065    pk_close();
00066 }
00067 
00068 /* This function delivers the pixels from the character's bounding box
00069  * from left to right and from top to bottom.
00070  */
00071 int next_pixel()
00072 {  int c;
00073    do { c = getchar();
00074       if (c==EOF) fatal("reading past end of file!\n");
00075       if (c == '*' || c == 'X') return BLACK;
00076       if (c == '.') return WHITE;
00077    } while (1);
00078 }
00079 
00080 /* The character example from GFtoPK:
00081   ********************
00082   ********************
00083   ********************
00084   ********************
00085   **................**
00086   **................**
00087   **................**
00088   ....................
00089   ....................
00090   ..**............**..
00091   ..**............**..
00092   ..**............**..
00093   ..****************..
00094   ..****************..
00095   ..****************..
00096   ..****************..
00097   ..**............**..
00098   ..**............**..
00099   ..**............**..
00100   ....................
00101   ....................
00102   ....................
00103   **................**
00104   **................**
00105   **................**
00106   ********************
00107   ********************
00108   ********************
00109   ********************
00110 */