Back to index

tetex-bin  3.0
Defines | Typedefs | Functions | Variables
ps2pk.c File Reference
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "basics.h"
#include "filenames.h"
#include "psearch.h"
#include "pkout.h"
#include "ffilest.h"

Go to the source code of this file.

Defines

#define Succesful   85
#define POINTSPERINCH   72.27
#define DEFAULTRES   300
#define DEFAULTPOINTSIZE   10.0

Typedefs

typedef char * encoding [256]
typedef unsigned int UINT32

Functions

int Type1OpenScalable ()
int Type1RegisterFontFileFunctions ()
void Type1CloseFont ()
void getenc (char **, char **, encoding, int[256])
UINT32 checksum (encoding, int[256])
UINT32 old_checksum (encoding, int[256])
 main (int argc, argv)
int next_pixel ()
void first_pixel (CharInfoRec *G)
void print_pixmap ()
INT32 TFMwidth (int wx)
int h_escapement (int wx)
void add_option (char *option, char *value)
int CheckFSFormat (int format, int fmask, int *bit, int *byte, int *scan, int *glyph, int *image)
long MakeAtom (char *p, unsigned int len, Bool foo)
 GetClientResolutions (int *resP)
char * Xalloc (size_t size)
void Xfree (void *p)
void FontDefaultFormat ()
void FontFileRegisterRenderer ()
 GenericGetBitmaps ()
 GenericGetExtents ()
void FontParseXLFDName ()
 FontComputeInfoAccelerators ()

Variables

FontScalableRec vals
FontEntryRec entry
char * encfile = NULL
char * afmfile
char ps2pk_args [MAXSTRLEN] = "none"
double pointsize = 0.0
int W
int H
int base_resolution = DEFAULTRES
int x_resolution = 0
int y_resolution = 0
int verbose = 0
int debug = 0
UINT32(* pchecksum )(encoding, int[256]) = checksum
static int row
static int col
static int data
static int bitno
static unsigned char * p_data
static float HXU = -1.0

Define Documentation

#define DEFAULTPOINTSIZE   10.0

Definition at line 218 of file ps2pk.c.

#define DEFAULTRES   300

Definition at line 217 of file ps2pk.c.

#define POINTSPERINCH   72.27

Definition at line 216 of file ps2pk.c.

#define Succesful   85

Definition at line 202 of file ps2pk.c.


Typedef Documentation

typedef char* encoding[256]

Definition at line 213 of file ps2pk.c.

typedef unsigned int UINT32

Definition at line 229 of file ps2pk.c.


Function Documentation

void add_option ( char *  option,
char *  value 
)

Definition at line 645 of file ps2pk.c.

                                           {
   static char *p_args = NULL;

   if (p_args == NULL) {
      p_args = ps2pk_args;
      sprintf(p_args, "%s%s", option, value);
   }
   else
      sprintf(p_args, " %s%s", option, value);
   p_args+= strlen(p_args);
}

Here is the call graph for this function:

Here is the caller graph for this function:

int CheckFSFormat ( int  format,
int  fmask,
int bit,
int byte,
int scan,
int glyph,
int image 
)

Definition at line 659 of file ps2pk.c.

{
       *bit = *byte = 1;
       *glyph = *scan = *image = 1;
       return Successful;
 
}
UINT32 checksum ( encoding  ev,
int  width[256] 
)

Definition at line 598 of file ps2pk.c.

{
   row = col = 0;
   p_data = (unsigned char *) G->bits;
   W = G->metrics.rightSideBearing - G->metrics.leftSideBearing;
   H = G->metrics.ascent + G->metrics.descent;
   bitno = 0; 
}

Here is the caller graph for this function:

Definition at line 709 of file ps2pk.c.

{ ; }

Definition at line 701 of file ps2pk.c.

{ ; }

Definition at line 703 of file ps2pk.c.

{ ; }

Definition at line 708 of file ps2pk.c.

{ ; }

Definition at line 705 of file ps2pk.c.

{ ; }

Definition at line 706 of file ps2pk.c.

{ ; }

Definition at line 676 of file ps2pk.c.

{
       *resP = 0;
}
void getenc ( char **  ,
char **  ,
encoding  ,
int  [256] 
)

Definition at line 127 of file encoding.c.

{  int i, len, SCMseen, Ccnt, wx, cc;
   FILE *afm;
   char *name, ns;
   
   for (i=0; i < 256; i++) { ev[i] = NULL; width[i] = -1000; }
   if (encfile) {
      enc = fopen(encfile, "r");
      if (enc == NULL) fatal("Can't open %s\n", encfile);
      if (nextsymbol() != '/') fatal("missing '/encoding' in %s\n", encfile);
      *encname = nextpsname();
      if (nextsymbol() != '[') fatal("missing '[' in %s\n", encfile);
      i = 0;
      while (i < 256 && (ns = nextsymbol()) == '/') {
         name = my_string(pline);
         if (strcmp(name, ".notdef") == 0) { 
            i++; remove_string();
            continue; 
         }
         addcc(name, i++);
      }
      if (i != 256) fatal("missing %d symbols in %s\n", 256-i, encfile);
      if (nextsymbol() != ']') fatal("missing ']' in %s\n", encfile);
      fclose(enc);
   }
   afm = fopen(afmfile, "r");
   if (afm == NULL) fatal("Can't open %s\n", afmfile);
   /*
    * Scan header of AFM file and take the FontName and EncodingScheme
    * (used for identification purposes in the PK postamble)
    * Stop after reading `StartCharMetrics'.
    */
   SCMseen = 0; Ccnt = 0;
   while (fgets(line, LINEBUF-1, afm)) {
      if (strncmp(line, "FontName", 8) == 0) { 
        pline = value_after(line, "FontName"); 
        len = strlen(pline);
        if (*(pline+len-1) == '\n') {
           *(pline+len-1) = '\0'; len--;
        }
        *fontname = malloc(len + 1);
        if (*fontname == NULL) fatal("Out of memory\n");
         strcpy(*fontname, pline);
      }
      else if (encname == NULL && strncmp(line, "EncodingScheme", 8) == 0) { 
        pline = value_after(line, "EncodingScheme"); 
        len = strlen(pline);
        if (*(pline+len-1) == '\n') {
           *(pline+len-1) = '\0'; len--;
        }
        *encname = malloc(len + 1);
        if (*encname == NULL) fatal("Out of memory\n");
        strcpy(*encname, pline);
      }
      else if (strncmp(line, "StartCharMetrics", 16) == 0) {
         SCMseen = 1; break;
      }
   }
   if (SCMseen == 0) fatal("%s: no metrics info\n", afmfile);
   while (fgets(line, LINEBUF-1, afm)) {
      if (strncmp(line, "EndCharMetrics", 14) == 0) break;
      if (strncmp(line, "C ", 2) != 0) 
         fatal("%s: unexpected line\n", afmfile);

      /* Gracefully terminate when the AFM file is not valid.  Every line */
      /* in the AFM file should specify a "C"haracter, a "WX"idth, and    */
      /* a "N"ame. (ndw)
      */
      pline = value_after(line, "C"); 
      if (pline == NULL)
         fatal("\nBad char metric in %s (no char):\n\t %s\n", afmfile, line);
      cc = decimal(pline);
      pline = value_after(pline, "WX"); 
      if (pline == NULL)
         fatal("\nBad char metric in %s (no width):\n\t %s\n", afmfile, line);
      wx = decimal(pline);
      pline = value_after(pline, "N"); 
      if (pline == NULL)
         fatal("\nBad char metric in %s (no name):\n\t %s\n", afmfile, line);
      name = my_string(pline);
      
      if (encfile) {
         if ((i = getcc(name)) == -1) {
            remove_string();
            continue;
        }
         do { /* allow more occurences per name */
            ev[i] = name; width[i] = wx;
            i = getcc(name);
         }
         while (i >= 0);
      }
      else if (cc >= 0 && cc <= 255) { /* ndw: 10/13/92 */
        ev[cc] = name; width[cc] = wx;
      }
      else if (cc > 255)
        msg("Char code %d ignored (out of range).\n", cc);
      Ccnt++;
   }
   if (Ccnt == 0) fatal("%s: no characters selected\n", afmfile);   
}

Here is the call graph for this function:

Here is the caller graph for this function:

int h_escapement ( int  wx)

Definition at line 637 of file ps2pk.c.

{
   if (HXU == -1.0) 
      HXU = (pointsize * x_resolution) / 72270.0;
   return wx * HXU +  0.5;
}

Here is the caller graph for this function:

main ( int  argc,
argv   
)

Definition at line 234 of file ps2pk.c.

{  char *argp, c;
   int done, i;
   char *myname = "ps2pk", *psname, *psbasename, *afmname = NULL,
       *encname = NULL, *psfile = NULL, *psfilebn, pkname[80],
       *t1inputs, *psrespath, *resourcedb, *AFM_fontname = NULL,
       *encodingscheme = NULL;

   FontPtr fontptr;
   unsigned char glyphcode[1]; /* must be an array */
   CharInfoRec *glyphs[1];
   unsigned int count;
   int charcode, rc = -1, charno;
   char comment[256];
   long cs;
   encoding ev;
   int WX[256];

   float efactor = 1.0, slant = 0.0;
   
   /* proto's */
   int next_pixel();
   void print_pixmap();
   void first_pixel(CharInfoRec *);
   INT32 TFMwidth(int);
   int h_escapement(int);
   void add_option(char *, char *);

   while (--argc > 0 && (*++argv)[0] == '-') {
      done=0;
      while ((!done) && (c = *++argv[0]))  /* allow -bcK like options */
        switch (c) {
        case 'a':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           afmname = argv[0]; 
           done = 1;
           break;
        case 'd':
           debug = 1;
           break;
        case 'e':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           encname = argv[0]; 
           add_option("-e", encname);
           done = 1;
           break;
        case 'E':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           efactor = atof(argv[0]);
           add_option("-E", argv[0]);
           done = 1;
           break;
        case 'O':
           pchecksum = old_checksum;
           add_option("-O", "");
           break;
        case 'P':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           pointsize = atof(argv[0]); 
           add_option("-P", argv[0]);
           done = 1;
           break;
        case 'R':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           base_resolution = atoi(argv[0]); 
           add_option("-R", argv[0]);
           done = 1;
           break;
        case 'S':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           slant = atof(argv[0]);
           add_option("-S", argv[0]);
           done = 1;
           break;
        case 'X':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           x_resolution = atoi(argv[0]); done = 1;
           if (y_resolution == 0) y_resolution = x_resolution;
           add_option("-X", argv[0]);
           break;
        case 'Y':
           if (*++argv[0] == '\0') {
              argc--; argv++;
           }
           y_resolution = atoi(argv[0]); done = 1;
           if (x_resolution == 0) x_resolution = y_resolution;
           add_option("-Y", argv[0]);
           break;
        case 'v':
           verbose = 1;
           break;
        default:
           fatal("%s: %c illegal option\n", myname, c);
        }
      }

   if (argc < 1 || argc >2) {
      msg  ("Ps2pk: version 1.5 (1992-96)\n");
      msg  ("Usage: %s [ options ] type1font [pkname]\n", myname);
      msg  ("options: -d -v -e<enc> -X<xres> -E<expansion> -S<slant>\n");
      fatal("options: -O -P<pointsize> -Y<yres> -a<AFM> -R<baseres>\n");
   }

   psname = argv[0]; argc--; argv++;

#ifdef KPATHSEA
   kpse_set_progname(myname);
#endif

#ifndef KPATHSEA
   if (ps_resource(psname)) {
      /* if psname does neither contain a DIRSEP or `.' character
       * then find the filename of this resource in one of the PS
       * resource database(s) available in PSRESOURCEPATH.
       */
      char **names, **files; int i, count;

      psrespath = path(PSRESOURCEPATH, getenv("PSRESOURCEPATH"));
      if (verbose) msg("PSRESOURCEPATH := %s\n", psrespath);

      count = ListPSResourceFiles(psrespath, NULL,
       "FontOutline", psname, &names, &files);
      if (count == 0)
        fatal("No FontOutline resource found for %s\n", psname);
      if (verbose && count > 1) {
        msg("More than one FontOutline resource for %s\n", psname);
        for (i = 0; i < count; i++) msg("\t<%s>\n", files[i]);
      }
      psfile = files[0];
      if (verbose) msg("Resource <%s>\n", psfile);
      psbasename = psname;
   }
   
   if (psfile != NULL) {
      char **names, **files; int count;

      if (afmname == NULL || ps_resource(afmname)) {
        if (afmname == NULL) afmname = psname;
         count = ListPSResourceFiles(psrespath, NULL,
          "FontAFM", afmname, &names, &files);
         if (count == 0)
           fatal("No FontAFM resource found for %s\n", afmname);
         if (verbose && count > 1) {
           msg("More than one FontAFM resource for %s\n", afmname);
           for (i = 0; i < count; i++) msg("\t<%s>\n", files[i]);
        }
         afmfile = files[0];
         if (verbose) msg("Resource <%s>\n", afmfile);
      }
      else fatal("%s: invalid resource name\n", afmname);

      if (encname != NULL) {
        if (!ps_resource(encname)) 
            fatal("%s: invalid Encoding resource\n", encname);
         count = ListPSResourceFiles(psrespath, NULL,
           "Encoding", encname, &names, &files);
         if (count == 0)
           fatal("No Encoding resource found for %s\n", encname);
         if (verbose && count > 1) {
           msg("More than one Encoding resource for %s\n", encname);
           for (i = 0; i < count; i++) msg("\t<%s>\n", files[i]);
         }
         encfile = files[0];
         if (verbose) msg("Resource <%s>\n", encfile);
      }
   }
   else { /* No PS resource database or no resource for type1font */
#endif   
#ifdef KPATHSEA
     psfile = kpse_find_file(psname,kpse_type1_format,0);
     if (!psfile) {
       /* kpse_find_file does not look for alternate suffixes */
       char *altname = newname(psname, ".pfb");
       psfile = kpse_find_file(altname, kpse_type1_format, 0);
       free(altname);
     }
     if (!psfile)
       fatal("%s: PS file %s not found!\n", program_invocation_name,
            psname);
     if (afmname == NULL)
       afmname = newname(psname, ".afm");
     afmfile = kpse_find_file(afmname,kpse_afm_format,0);
     if (!afmfile)
       fatal("%s: AFM file %s not found!\n", program_invocation_name,
            afmname);
     
     if (encname) {
       encfile = kpse_find_file(encname,kpse_enc_format,0);
       if (!encfile)
        fatal("%s: enc file %s not found!\n", program_invocation_name,
              encname);
     }
     else
       encfile = NULL;
     printf("psfile = %s\n", psfile);
     printf("afmfile = %s\n", afmfile);
     if (encfile) printf("encfile = %s\n", encfile);
#else
     t1inputs = path(T1INPUTS, getenv("T1INPUTS"));
     if (verbose) msg("T1INPUTS := %s\n", t1inputs);
     
     psfile = search_file(t1inputs, psname, FATAL);
     if (verbose) msg("Font file <%s>\n", psfile);
     
     if (afmname ==  NULL) afmname = newname(psfile, ".afm");
     afmfile = search_file(t1inputs, afmname, FATAL);
     if (verbose) msg("AFM file <%s>\n", afmfile);
     
     /* get encoding when -e<enc> provided */
     if (encname) {
       encfile = search_file(t1inputs, encname, FATAL);
       if (verbose) msg("Encoding file <%s>\n", encfile);
     }
#endif
     psbasename = basename(psname, extension(psname));
#ifndef KPATHSEA
   }
#endif
   psfilebn = basename(psfile, NULL);

   if (pointsize == 0.0) pointsize = DEFAULTPOINTSIZE;
   if (x_resolution == 0) x_resolution = DEFAULTRES;
   if (y_resolution == 0) y_resolution = x_resolution;
   if (verbose)
      msg("Loading encoding vector from %s ...",
        encname? encname: basename(afmfile, NULL));
   getenc(&AFM_fontname, &encodingscheme, ev, WX);
   if (efactor != 1.0)
      for (i=0; i < 256; i++) {
         if (ev[i] == NULL) continue;
         WX[i] = WX[i] * efactor + 0.5;
      }
   if (verbose) msg(" done\n");
   
   if (argc == 1) strcpy(pkname,  argv[0]);
   else 
      sprintf(pkname, "%s%d.%dpk", psbasename,
         (int) (pointsize + 0.5), x_resolution);
    
   /* next values are needed! */
   vals.x =     x_resolution;
   vals.y =     y_resolution;
   vals.point = 10.0 * pointsize + 0.5; /* DECIPOINTS */
   vals.pixel = pointsize * y_resolution / POINTSPERINCH + 0.5;
   
   if (verbose) msg("Checking type1 font %s ...", psfilebn);
   Type1RegisterFontFileFunctions();
   if (verbose) msg(" done\n");

       /* next line prevents UNIX core dumps */
   entry.name.name = "-adobe-utopia-medium-r-normal--0-0-0-0-p-0-iso8859-1";
   if (verbose)
      msg("Creating character glyphs for %s ...", psfilebn);
   rc = Type1OpenScalable(ev, &fontptr, 0, &entry, 
            psfile, &vals, 0, 0, efactor, slant);
   if (rc != Succesful) 
      fatal("Type1OpenScalable error (result: %d) on %s \n",  rc, psfile);
   if (verbose) msg(" done\n");

   pk_open(pkname);
   sprintf(comment, "%s rendered at %f points", psbasename, pointsize);
   cs = pchecksum(ev, WX);
   pk_preamble(comment, pointsize, cs, x_resolution, y_resolution);
   charno = 0;
   if (verbose) msg("Creating %s from %s\n", pkname, psfilebn);
   for (charcode = 0; charcode < 256; charcode++) {
      if (ev[charcode] == NULL) continue;
      glyphcode[0] = charcode;
      (fontptr->get_glyphs)(fontptr, 1, glyphcode, 0, &count, glyphs);
      if (count > 0) {
         if (debug) {
            msg("'%03o ", charcode); charno++;
            if (charno == 8) { 
               msg("%c", '\n'); charno = 0;
            }
         }
        first_pixel(glyphs[0]); /* assigns W and H */
         pk_char(charcode,                   /* charcode */
            TFMwidth(WX[charcode]),                 /* TFMwidth */
            h_escapement(WX[charcode]),             /* h_escapement */
            W, H,                            /* width and height */
            - glyphs[0]->metrics.leftSideBearing,  /* h_offset */
            glyphs[0]->metrics.ascent,             /* v_offset */
            next_pixel);                     /* pixel generator */
      }
   }
   if (debug) msg("%c", '\n');
   ps2pk_postamble(psbasename, encodingscheme,
              base_resolution, x_resolution, y_resolution, pointsize,
             ps2pk_args);
   pk_close();
   exit(0);
}

Here is the call graph for this function:

long MakeAtom ( char *  p,
unsigned int  len,
Bool  foo 
)

Definition at line 668 of file ps2pk.c.

{
       return (long)p;
}

Definition at line 584 of file ps2pk.c.

{  int pixel;

   while (row < H) {
       if (col++ < W) { 
           if (bitno == 0) { data = *p_data++; bitno = 8; }
           pixel = data & 0x80? BLACK: WHITE; 
           data <<= 1; bitno--; return pixel;
       }
       col = 0; row++; bitno = 0;
   }
   fatal("Not that many pixels!\n");
} 
UINT32 old_checksum ( encoding  ev,
int  width[256] 
)

Definition at line 547 of file ps2pk.c.

{
   int i, leftbit ;
   UINT32 s1 = 0, s2 = 0;
   char *p ;

   for (i=0; i<256; i++) {
      if (ev[i] == NULL) continue;
      s1 = (s1<<1) ^ width[i];                   /* left shift */
      for (p=ev[i]; *p; p++)
        s2 = s2 * 3 + *p ;
   }
   return (s1<<1) ^ s2 ;
}

Here is the caller graph for this function:

Definition at line 607 of file ps2pk.c.

{  int c, r;
   unsigned char *save_p_data;

   save_p_data = p_data;
   if (W*H == 0) return; /* easy */
   for (r = 0; r < H; r++) {
      for (c = 0; c < W; c++)
        if (next_pixel() == BLACK) msg("%c", 'X');
        else msg("%c", '.');
      msg("%c", '\n');
   }
   /* reset data for scanning pixmap */
   p_data = save_p_data;
   bitno = 0; row = 0; col = 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

INT32 TFMwidth ( int  wx)

Definition at line 628 of file ps2pk.c.

{  
   return (((wx  / 1000) << 20) +
           (((wx % 1000) << 20) + 500) / 1000) ;
}

Here is the caller graph for this function:

Definition at line 553 of file t1funcs.c.

{
    int i;
 
    T1InitStdProps();
    for (i=0; i < sizeof(renderers) / sizeof(FontRendererRec); i++)
            FontFileRegisterRenderer(&renderers[i]);
}

Here is the call graph for this function:

char* Xalloc ( size_t  size)

Definition at line 682 of file ps2pk.c.

{  char *p;
   p = malloc(size);
   if (p == NULL) fatal("Out of memory\n");
   return p;
}
void Xfree ( void p)

Definition at line 689 of file ps2pk.c.

{
       free(p);
}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

char * afmfile

Definition at line 210 of file ps2pk.c.

Definition at line 222 of file ps2pk.c.

int bitno [static]

Definition at line 581 of file ps2pk.c.

int col [static]

Definition at line 580 of file ps2pk.c.

int data [static]

Definition at line 581 of file ps2pk.c.

int debug = 0

Definition at line 226 of file ps2pk.c.

char* encfile = NULL

Definition at line 210 of file ps2pk.c.

Definition at line 201 of file ps2pk.c.

int H

Definition at line 221 of file ps2pk.c.

float HXU = -1.0 [static]

Definition at line 634 of file ps2pk.c.

unsigned char* p_data [static]

Definition at line 582 of file ps2pk.c.

Definition at line 232 of file ps2pk.c.

double pointsize = 0.0

Definition at line 220 of file ps2pk.c.

char ps2pk_args[MAXSTRLEN] = "none"

Definition at line 212 of file ps2pk.c.

int row [static]

Definition at line 580 of file ps2pk.c.

Definition at line 200 of file ps2pk.c.

int verbose = 0

Definition at line 226 of file ps2pk.c.

int W

Definition at line 221 of file ps2pk.c.

Definition at line 223 of file ps2pk.c.

Definition at line 224 of file ps2pk.c.