home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume14 / cat2deskjet / part01 / djinfo.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-08-30  |  5.3 KB  |  182 lines

  1. /*
  2.  *  djinfo.c -- prints information contained in an HP DeskJet soft font file.
  3.  *  Copyright (C) 1990 Vassilis Prevelakis
  4.  *
  5.  *  This program is free software; you can redistribute it and/or modify
  6.  *  it under the terms of the GNU General Public License as published by
  7.  *  the Free Software Foundation and included with this distribution in the
  8.  *  file named LICENSE.
  9.  *
  10.  *  This program is distributed in the hope that it will be useful,
  11.  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  12.  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  13.  *  GNU General Public License for more details.
  14.  *
  15.  *  You should have received a copy of the GNU General Public License
  16.  *  along with this program; if not, write to the Free Software
  17.  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18.  *
  19.  *  Bugs fixes, comments etc. to:
  20.  *       Vasilis Prevelakis
  21.  *       Centre Universitaire d'Informatique (CUI)
  22.  *       12 Rue du Lac, Geneva, Switzerland CH-1207
  23.  *  email: vp@cui.unige.ch
  24.  *  uucp:  ...!mcsun!cui!vp
  25.  */
  26.  
  27. #include <stdio.h>
  28.  
  29. typedef unsigned char u_char;
  30. typedef unsigned short u_short;
  31.  
  32. FILE* fd;
  33.  
  34. struct fdb {
  35.     u_short    size;        /* always 72 */
  36.     u_char    format;        /* DeskJet only: header format (5 or 9) */
  37.     u_char    ftype;        /* zero for 7-bit font */
  38.     short    xxx1;        /* RESERVED, must be zero */
  39.     u_short    baseline;    /* in dots */
  40.     u_short cell_width;    /* in dots */
  41.     u_short cell_height;    /* in dots */
  42.     u_char orientation;    /* 0 portrait, 1 landscape */
  43.     u_char spacing;        /* 0 fixed, 1 proportional */
  44.     u_short symbol;
  45.     u_short pitch;        /* in quarter dots */
  46.     u_short height;        /* in quarter dots */
  47.     u_short xHeight;    /* in quarter dots -- IGNORED */
  48.     u_char w_type;        /* IGNORED, == 0 */
  49.     u_char style;
  50.     char str_weight;
  51.     u_char typeface;
  52.     u_char    slant;        /* DeskJet only */
  53.     u_char s_style;
  54.     u_char quality;        /* DeskJet only */
  55.     u_char placement;    /* DeskJet only */
  56.     char ud_dst;
  57.     u_char ud_height;    /* IGNORED, == 3 */
  58.     u_short    t_height;    /* IGNORED, == 0 */
  59.     u_short t_width;    /* IGNORED, == 0 */
  60.     u_short firstcode;    /* DeskJet only */
  61.     u_short lastcode;     /* DeskJet only */
  62.     u_char ext_pitch;    /* IGNORED by DeskJet == 0 */
  63.     u_char ext_height;    /* IGNORED by DeskJet == 0 */
  64.     short xxx5[3];        /* RESERVED, must be zero */
  65. #define MAXNAME 16
  66.     char fname[MAXNAME];
  67.     /* following fields DeskJet only */
  68.     u_short hres;        /* horizontal resolution == 600 */
  69.     u_short vres;        /* vertical resolution == 300 */
  70.     char ud2_dst;
  71.     u_char ud2_height;
  72.     char bud_dst;
  73.     u_char bud_height;
  74.     u_short psbs;        /* number of subsequent bytes == 20 */
  75.     u_short font_size;
  76.     char oneway;
  77.     char compressed;
  78.     u_char holdtime;
  79.     char nohalfpitch;
  80.     char nodoublepitch;
  81.     char nohalfheight;
  82.     char nobold;
  83.     char nodraft;
  84.     char boldmethod;
  85.     char xxx7;        /* RESERVED, must be zero */
  86.     u_short baseoff2;
  87. /* following fields used by DeskJet PLUS **ONLY** */
  88.     u_short baseoff3;
  89.     u_short baseoff4;
  90. } myfdb;
  91.  
  92. void loc_char(cc)
  93. char cc;
  94. {
  95.     int c;
  96.  
  97.     while ((c = getc(fd)) != cc)
  98.         if (c < 0)
  99.             exit(0);
  100. }
  101.     
  102. main(argc, argv)
  103. int argc;
  104. char **argv;
  105. {
  106.     int c;
  107.     int i;
  108.     struct fdb myfdb;
  109.     u_char *vp;
  110.  
  111.     if (argc != 2)
  112.     {
  113.         printf("usage: xx filename\n");
  114.         exit(1);
  115.     }
  116.  
  117.     if ((fd = fopen(argv[1], "rb")) == NULL)
  118.     {
  119.         printf("Couldn't open %s.\n", argv[1]);
  120.         exit(1);
  121.     }
  122.     do {
  123.         do {
  124.             loc_char(0x1b);
  125.         } while (getc(fd) != ')');
  126.     } while (getc(fd) != 's');
  127.     loc_char('W');
  128.     /* printf("now at %ld\n", ftell(fd)); */
  129.     fread(&myfdb, sizeof(struct fdb), 1, fd);
  130.  
  131. #define vp_swab(X) ((((u_short)X & 0xff) << 8) | (((u_short)X & 0xff00) >> 8))
  132.     myfdb.size = vp_swab(myfdb.size);
  133.     myfdb.baseline = vp_swab(myfdb.baseline);
  134.     myfdb.cell_width = vp_swab(myfdb.cell_width);
  135.     myfdb.cell_height = vp_swab(myfdb.cell_height);
  136.     myfdb.symbol = vp_swab(myfdb.symbol);
  137.     myfdb.pitch = vp_swab(myfdb.pitch);
  138.     myfdb.height = vp_swab(myfdb.height);
  139.     myfdb.xHeight = vp_swab(myfdb.xHeight);
  140.     myfdb.t_height = vp_swab(myfdb.t_height);
  141.     myfdb.t_width = vp_swab(myfdb.t_width);
  142.     myfdb.firstcode = vp_swab(myfdb.firstcode);
  143.     myfdb.lastcode = vp_swab(myfdb.lastcode);
  144.     myfdb.hres = vp_swab(myfdb.hres);
  145.     myfdb.vres = vp_swab(myfdb.vres);
  146.     myfdb.psbs = vp_swab(myfdb.psbs);
  147.     myfdb.font_size = vp_swab(myfdb.font_size);
  148.     myfdb.baseoff2 = vp_swab(myfdb.baseoff2);
  149.     myfdb.baseoff3 = vp_swab(myfdb.baseoff3);
  150.     myfdb.baseoff4 = vp_swab(myfdb.baseoff4);
  151.     
  152.     myfdb.fname[MAXNAME-1] = '\0';
  153. printf("Font name: %s.\n", myfdb.fname);
  154. printf("size=%d, format=%d, ftype=%d, baseline=%d, width=%d, height=%d\n",
  155.     (int)myfdb.size, (int)myfdb.format, (int)myfdb.ftype,
  156.     (int)myfdb.baseline,
  157.     (int)myfdb.cell_width, (int)myfdb.cell_height);
  158.  
  159. printf("orien=%d, spacing=%d, pitch=%d, height=%d, xHeight=%d, w_type=%d\n",
  160.     (int)myfdb.orientation, (int)myfdb.spacing, (int)myfdb.pitch,
  161.     (int)myfdb.height,
  162.     (int)myfdb.xHeight, (int)myfdb.w_type);
  163.  
  164. printf("style=%d, str_weight=%d, typeface=%d, slant=%d, s_style=%d\n",
  165.     (int)myfdb.style, (int)myfdb.str_weight,(int)myfdb.typeface,
  166.     (int)myfdb.slant, (int)myfdb.s_style);
  167.  
  168. printf("quality=%d, placement=%d, t_height=%d, t_width=%d, Fcode=%d, Lcode=%d\n",
  169.     (int)myfdb.quality, (int)myfdb.placement, (int)myfdb.t_height,
  170.     (int)myfdb.t_width,
  171.     (int)myfdb.firstcode, (int)myfdb.lastcode);
  172.  
  173. printf("hres=%d, vres=%d, psbs=%d, size=%u\n",
  174.     (int)myfdb.hres, (int)myfdb.vres,
  175.     (int)myfdb.psbs, (unsigned int)myfdb.font_size);
  176.  
  177. printf("baseoff2=%d, baseoff3=%d, baseoff4=%d\n",  
  178.     (int)myfdb.baseoff2, (int)myfdb.baseoff3, (int)myfdb.baseoff4);
  179. }
  180.     
  181.  
  182.