home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 5 / DATAFILE_PDCD5.iso / utilities / t / tex / !dvips / Documents / Fonts / Source / h / dvips < prev    next >
Encoding:
Text File  |  1994-10-23  |  8.7 KB  |  272 lines

  1. /*
  2.  *   This is dvips, a freely redistributable PostScript driver
  3.  *   for dvi files.  It is (C) Copyright 1986-94 by Tomas Rokicki.
  4.  *   You may modify and use this program to your heart's content,
  5.  *   so long as you send modifications to Tomas Rokicki.  It can
  6.  *   be included in any distribution, commercial or otherwise, so
  7.  *   long as the banner string defined below is not modified (except
  8.  *   for the version number) and this banner is printed on program
  9.  *   invocation, or can be printed on program invocation with the -? option.
  10.  */
  11.  
  12. /*   This file is the header for dvips's global data structures. */
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <ctype.h>
  18. #include "paths.h"
  19. #include "debug.h"
  20. #ifdef VMS
  21. #include "[]vms.h"
  22. #endif /* VMS */
  23. extern    int    chdir(char *);
  24. extern    char    *getcwd(char *,int);
  25. /*
  26.  *   We use malloc and free; these may need to be customized for your
  27.  *   site.
  28.  */
  29. #define BANNER \
  30.              "This is dvips 5.55 Copyright 1986, 1994 Radical Eye Software\n"
  31.  
  32. char *mymalloc() ;
  33. /*
  34.  *   Is your malloc big?
  35.  */
  36. #if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP)
  37. #define SMALLMALLOC
  38. #endif
  39. #if defined(OS2) && defined(_MSC_VER)
  40. #define SMALLMALLOC
  41. #endif
  42. /*
  43.  *   Constants, used to increase or decrease the capacity of this program.
  44.  *
  45.  *   Strings are now more dynamically allocated, so STRINGSIZE is not the
  46.  *   strict limit it once was.  However, it still sets the maximum size
  47.  *   of a string that can be handled in specials, so it should not be
  48.  *   set too small.
  49.  */
  50. #define STRINGSIZE (25000)  /* maximum number of strings in program */
  51. #define RASTERCHUNK (8192)  /* size of chunk of raster */
  52. #define MINCHUNK (240)      /* minimum size char to get own raster */
  53. #define STACKSIZE (100)     /* maximum stack size for dvi files */
  54. #define MAXFRAME (10)       /* maximum depth of virtual font recursion */
  55. #define MAXFONTHD (100)     /* number of unique names of included fonts */
  56. #define STDOUTSIZE (75)     /* width of a standard output line */
  57. /*
  58.  *   Other constants, which define printer-dependent stuff.
  59.  */
  60. #define SWMEM (180000)      /* available virtual memory in PostScript printer */
  61. #define DPI (actualdpi)     /* dots per inch */
  62. #define VDPI (vactualdpi)   /* dots per inch */
  63. #define RES_TOLERANCE(dpi) ((int)(1+dpi/500))
  64.                             /* error in file name resolution versus desired */
  65. #define FONTCOST (298)      /* overhead cost of each sw font */
  66. #define PSFONTCOST (1100)   /* overhead cost for PostScript fonts */
  67. #define PSCHARCOST (20)     /* overhead cost for PostScript font chars */
  68. #define DNFONTCOST (35000)  /* overhead cost for downloaded PS font */
  69. #define CHARCOST (15)       /* overhead cost for each character */
  70. #define OVERCOST (30000)    /* cost of overhead */
  71. #define DICTITEMCOST (20)   /* cost per key, value in dictionary */
  72. #define NAMECOST (40)       /* overhead cost of each new name */
  73. /*
  74.  *   Type declarations.  integer must be a 32-bit signed; shalfword must
  75.  *   be a sixteen-bit signed; halfword must be a sixteen-bit unsigned;
  76.  *   quarterword must be an eight-bit unsigned.
  77.  */
  78. #if (defined(MSDOS) && !defined(DJGPP)) || (defined(OS2) && defined(_MSC_VER))
  79. typedef long integer;
  80. #else
  81. typedef int integer;
  82. #endif
  83. typedef char boolean;
  84. typedef double real;
  85. typedef short shalfword ;
  86. typedef unsigned short halfword ;
  87. typedef unsigned char quarterword ;
  88. #ifndef __THINK__
  89. typedef short Boolean ;
  90. #endif
  91. /*
  92.  *   If the machine has a default integer size of 16 bits, and 32-bit
  93.  *   integers must be manipulated with %ld, set the macro SHORTINT.
  94.  */
  95. #ifdef XENIX
  96. #define SHORTINT
  97. #else
  98. #undef SHORTINT
  99. #endif
  100. #if defined(MSDOS) && !defined(__EMX__) && !defined(DJGPP)
  101. #define SHORTINT
  102. #endif
  103. #if defined(OS2) && defined(_MSC_VER)
  104. #define SHORTINT
  105. #endif
  106.  
  107. /*
  108.  *   This is the structure definition for resident fonts.  We use
  109.  *   a small and simple hash table to handle these.  We don't need
  110.  *   a big hash table.
  111.  */
  112. #define RESHASHPRIME (73)
  113. struct resfont {
  114.    struct resfont *next ;
  115.    char *Keyname, *PSname, *TeXname ;
  116.    char *specialinstructions ;
  117.    char *downloadheader ; /* possibly multiple files */
  118.    quarterword sent ;
  119. } ;
  120.  
  121. /*
  122.  *   A chardesc describes an individual character.  Before the fonts are
  123.  *   downloaded, the flags indicate that the character has already been used
  124.  *   with the following meanings:
  125.  */
  126. typedef struct {
  127.    integer TFMwidth ;
  128.    quarterword *packptr ;
  129.    shalfword pixelwidth ;
  130.    quarterword flags, dmy ;
  131. } chardesctype ;
  132. #define EXISTS (1)
  133. #define PREVPAGE (2)
  134. #define THISPAGE (4)
  135. #define TOOBIG (8) /* not used at the moment */
  136. #define REPACKED (16)
  137. #define BIGCHAR (32)
  138. #define STATUSFLAGS (EXISTS|REPACKED|BIGCHAR)
  139. /*
  140.  *   A fontdesc describes a font.  The name, area, and scalename are located in
  141.  *   the string pool. The nextsize pointer is used to link fonts that are used
  142.  *   in included psfiles and differ only in scaledsize.  Such fonts also have
  143.  *   a non-NULL scalename that gives the scaledsize as found in the included
  144.  *   file.  The psflag indicates that the font has been used in an included
  145.  *   psfile.  It can be 0, PREVPAGE, THISPAGE, or EXISTS.
  146.  */
  147. typedef struct tfd {
  148.    integer checksum, scaledsize, designsize, thinspace ;
  149.    halfword dpi, loadeddpi ;
  150.    halfword alreadyscaled ;
  151.    halfword psname ;
  152.    halfword loaded ;
  153.    halfword maxchars ;
  154.    char *name, *area ;
  155.    struct resfont *resfont ;
  156.    struct tft *localfonts ;
  157.    struct tfd *next ;
  158.    struct tfd *nextsize;
  159.    char *scalename;
  160.    quarterword psflag;
  161.    chardesctype chardesc[256] ;
  162. } fontdesctype ;
  163.  
  164. /*  A fontmap associates a fontdesc with a font number.
  165.  */
  166. typedef struct tft {
  167.    integer fontnum ;
  168.    fontdesctype *desc ;
  169.    struct tft *next ;
  170. } fontmaptype ;
  171.  
  172. /*   Virtual fonts require a `macro' capability that is implemented by
  173.  *   using a stack of `frames'.
  174.  */
  175. typedef struct {
  176.    quarterword *curp, *curl ;
  177.    fontdesctype *curf ;
  178.    fontmaptype *ff ;
  179. } frametype ;
  180.  
  181. /*
  182.  *   The next type holds the font usage information in a 256-bit table;
  183.  *   there's a 1 for each character that was used in a section.
  184.  */
  185. typedef struct {
  186.    fontdesctype *fd ;
  187.    halfword psfused ;
  188.    halfword bitmap[16] ;
  189. } charusetype ;
  190.  
  191. /*   Next we want to record the relevant data for a section.  A section is
  192.  *   a largest portion of the document whose font usage does not overflow
  193.  *   the capacity of the printer.  (If a single page does overflow the
  194.  *   capacity all by itself, it is made into its own section and a warning
  195.  *   message is printed; the page is still printed.)
  196.  *
  197.  *   The sections are in a linked list, built during the prescan phase and
  198.  *   processed in proper order (so that pages stack correctly on output) during
  199.  *   the second phase.
  200.  */
  201. typedef struct t {
  202.    integer bos ;
  203.    struct t *next ;
  204.    halfword numpages ;
  205. } sectiontype ;
  206.  
  207. /*
  208.  *   Sections are actually represented not by sectiontype but by a more
  209.  *   complex data structure of variable size, having the following layout:
  210.  *      sectiontype sect ;
  211.  *      charusetype charuse[numfonts] ;
  212.  *      fontdesctype *sentinel = NULL ;
  213.  *   (Here numfonts is the number of bitmap fonts currently defined.)
  214.  *    Since we can't declare this or take a sizeof it, we build it and
  215.  *   manipulate it ourselves (see the end of the prescan routine).
  216.  */
  217. /*
  218.  *   This is how we build up headers and other lists.
  219.  */
  220. struct header_list {
  221.    struct header_list *next ;
  222.    char *Hname ;
  223.    char name[1] ;
  224. } ;
  225. /*
  226.  *   Some machines define putlong in their library.
  227.  *   We get around this here.
  228.  */
  229. #define putlong was_putlong
  230. /*
  231.  *   Information on available paper sizes is stored here.
  232.  */
  233. struct papsiz {
  234.    struct papsiz *next ;
  235.    integer xsize, ysize ;
  236.    char *name ;
  237.    char *specdat ;
  238. } ;
  239. #ifdef MVSXA /* IBM: MVS/XA */
  240. /* this is where we fix problems with conflicts for truncation
  241.    of long names (we might only do this if LONGNAME not set but ...) */
  242. #   define pprescanpages pprscnpgs  /* confict with pprescan */
  243. #   define flushDashedPath flshDshdPth  /* conflict with flushDash */
  244. #   define PageList PgList  /* re-definition conflict with pagelist  */
  245. /* adding ascii2ebcdic conversion table to extern */
  246.     extern char ascii2ebcdic[] ;
  247. #endif  /* IBM: MVS/XA */
  248. #ifdef VMCMS /* IBM: VM/CMS */
  249. /* this is where we fix problems with conflicts for truncation
  250.    of long names (we might only do this if LONGNAME not set but ...) */
  251. #   define pprescanpages pprscnpgs  /* confict with pprescan */
  252. #   define flushDashedPath flshDshdPth  /* conflict with flushDash */
  253. /* adding ascii2ebcdic conversion table to extern */
  254.     extern char ascii2ebcdic[] ;
  255. /* redefining fopen for VMCMS, see DVIPSCMS.C */
  256.     extern FILE *cmsfopen() ;
  257. #   ifdef fopen
  258. #      undef fopen
  259. #   endif
  260. #   define fopen cmsfopen
  261. #endif  /* IBM: VM/CMS */
  262. /*
  263.  *   Remove namespace conflict with standard library on Macintosh
  264.  */
  265. #ifdef __THINK__
  266. #define newstring newpoolstring
  267. #endif
  268.  
  269. #ifndef VOID
  270. #define VOID void
  271. #endif
  272.