src/vflbanner.c

/* [<][>]
[^][v][top][bottom][index][help] */

FUNCTIONS

This source file includes following functions.
  1. main
  2. usage
  3. vflbanner

   1 /* 
   2  * vflbanner.c - a banner by VFlib
   3  * by Hirotsugu Kakugawa
   4  *
   5  *
   6  */
   7 /*
   8  * Copyright (C) 1998 Hirotsugu Kakugawa. 
   9  * All rights reserved.
  10  *
  11  * This program is free software; you can redistribute it and/or modify
  12  * it under the terms of the GNU General Public License as published by
  13  * the Free Software Foundation; either version 2, or (at your option)
  14  * any later version.
  15  * 
  16  * This program is distributed in the hope that it will be useful,
  17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19  * GNU General Public License for more details.
  20  * 
  21  * You should have received a copy of the GNU General Public License
  22  * along with this program; if not, write to the Free Software
  23  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  
  24  */
  25 
  26 #include "config.h"
  27 #include <stdio.h>
  28 #include <stdlib.h>
  29 #include <ctype.h>
  30 #ifdef HAVE_UNISTD_H
  31 # include <unistd.h>
  32 #endif
  33 #include "VFlib-3_6.h"
  34 
  35 #define  DEFAULT_FONT  "timR18.pcf"
  36 
  37 
  38 char    *vflibcap;
  39 char    *fontname;
  40 double   mag;
  41 
  42 void  usage(void);
  43 void  vflbanner(FILE *fp);
  44 
  45 
  46 int
  47 main(int argc, char **argv)
     /* [<][>][^][v][top][bottom][index][help] */
  48 {
  49   vflibcap = NULL;
  50   fontname = DEFAULT_FONT;
  51   mag      = 1.0;
  52 
  53   --argc; argv++;
  54   while (argc > 0){
  55     if ((argc >= 1)
  56         && ((strcmp(argv[0], "-h") == 0) || (strcmp(argv[0], "--help") == 0))){
  57       usage();
  58       exit(0);
  59     } else if ((argc >= 2) && (strcmp(argv[0], "-v") == 0)){
  60       --argc; argv++;
  61       vflibcap = argv[0];
  62       --argc; argv++;
  63     } else if ((argc >= 2) && (strcmp(argv[0], "-f") == 0)){
  64       --argc; argv++;
  65       fontname = argv[0];
  66       --argc; argv++;
  67     } else if ((argc >= 2) && (strcmp(argv[0], "-m") == 0)){
  68       --argc; argv++;
  69       mag = atof(argv[0]);
  70       --argc; argv++;
  71     } else {
  72       break;
  73     }
  74   }
  75 
  76   vflbanner(stdin);
  77 
  78   return 0;
  79 }
  80 
  81 void usage(void)
     /* [<][>][^][v][top][bottom][index][help] */
  82 {
  83   printf("vflbanner - a banner program using VFlib\n");
  84   printf("Usage: vflbanner [-v vflibcap] [-m mag] [-f fontname]\n"); 
  85   printf("This program reads a text from standard input.  It supports\n");
  86   printf("1-bit encoded font only. Thus, `ctextpgm' is better than this.\n");
  87 }
  88 
  89 
  90 void
  91 vflbanner(FILE  *fp)
     /* [<][>][^][v][top][bottom][index][help] */
  92 {
  93   int  fid;
  94   int  ch; 
  95   int  pos_x, pos_y; 
  96   VF_BITMAP  bm, page_bm;
  97   struct vf_s_bitmaplist  PageBuff;
  98 
  99   if (VF_Init(vflibcap, NULL) < 0){
 100     printf("VFlib initialization error");
 101     switch (vf_error){
 102     case VF_ERR_INTERNAL:
 103       printf(" - Internal error.\n"); break;
 104     case VF_ERR_NO_MEMORY:
 105       printf(" - Server runs out of memory.\n"); break;
 106     case VF_ERR_NO_VFLIBCAP:
 107       printf(" -  No vflibcap.\n"); break;
 108     default: 
 109       printf(" -  Error code %d\n", vf_error); break;
 110     }
 111     fflush(stdout);
 112     exit(1);
 113   }
 114 
 115   if ((fid = VF_OpenFont1(fontname, -1, -1, -1, mag, mag)) < 0)
 116     return;
 117     
 118   VF_BitmapListInit(&PageBuff);
 119 
 120   pos_x = pos_y = 0; 
 121   while ((ch = getc(fp)) != EOF){
 122     if (iscntrl(ch))
 123       continue;
 124     if (!isprint(ch))
 125       ch = ' ';
 126     if ((bm = VF_GetBitmap1(fid, (long)ch, 1, 1)) == NULL)
 127       continue;
 128     VF_BitmapListPut(&PageBuff, bm, pos_x, pos_y);
 129     pos_x = pos_x + bm->mv_x;
 130   }
 131 
 132   page_bm = VF_BitmapListCompose(&PageBuff);
 133   VF_DumpBitmap(page_bm);
 134   VF_BitmapListFinish(&PageBuff);
 135   VF_FreeBitmap(page_bm);
 136 
 137   VF_CloseFont(fid);
 138 }
 139 
 140 /*EOF*/

/* [<][>][^][v][top][bottom][index][help] */