home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / stex2-18.zip / SeeTeX / libtex / font.h < prev    next >
C/C++ Source or Header  |  1990-07-10  |  10KB  |  302 lines

  1. /*
  2.  * Copyright (c) 1987, 1989 University of Maryland
  3.  * Department of Computer Science.  All rights reserved.
  4.  * Permission to copy for any purpose is hereby granted
  5.  * so long as this copyright notice remains intact.
  6.  */
  7.  
  8. /*
  9.  * Font file information, readers, etc.
  10.  */
  11.  
  12. #ifndef _MCTEX_TYPES_
  13. #include "types.h"
  14. #endif
  15.  
  16. /*
  17.  * First, font independent information: per glyph info, and per font
  18.  * info.
  19.  */
  20. struct glyph {
  21.     short    g_flags;    /* see below */
  22.     /*
  23.      * The following cannot be used with GetRasterlessFont
  24.      */
  25.     short    g_rotation;    /* see below */
  26.     char    *g_raster;    /* raster, if known */
  27.     /*
  28.      * These, however, do come with rasterless fonts,
  29.      * even though they relate only to the raster.
  30.      */
  31.     i32    g_height;    /* height of bounding box */
  32.     i32    g_width;    /* width of bounding box */
  33.     i32    g_yorigin;    /* y origin (>= 0 -> within box) */
  34.     i32    g_xorigin;    /* x origin (>= 0 -> within box) */
  35.     /*
  36.      * These of course come with every font.
  37.      */
  38.     i32    g_rawtfmwidth;    /* raw TFM width (in FIXes) */
  39.     i32    g_tfmwidth;    /* TFM width in scaled points */
  40.     /*
  41.      * The X and Y escapements come from PK and GF fonts.
  42.      * They are in scaled pixels (65536 scaled pixels = 1 pixel).
  43.      * If they are not defined by the font, these are set to
  44.      * NO_ESCAPEMENT.
  45.      */
  46.     i32    g_xescapement;    /* x escapement (`chardx') */
  47.     i32    g_yescapement;    /* y escapement (`chardy') */
  48. #define    NO_ESCAPEMENT    ((i32)0x89abcdef)
  49.     /*
  50.      * This is provided purely for DVI to device conversion programs.
  51.      */
  52.     int    g_pixwidth;    /* width in pixels */
  53.     /*
  54.      * Mainly for internal use, index is the glyph index within the
  55.      * font.  That is, f->f_gly[i]->g_index == i.
  56.      */
  57.     int    g_index;    /* character index */
  58.     /*
  59.      * g_details and g_integer are purely for the font reading
  60.      * subroutines to use however they will.  g_next makes lists
  61.      * of glyphs while the glyphs are free.
  62.      */
  63.     union {            /* various options */
  64.         char    *g_details;    /* details: arbitrary */
  65.         i32    g_integer;    /* 32 bit integer */
  66.         struct    glyph *g_next;    /* linked list */
  67.     } g_un;
  68. };
  69.  
  70. /*
  71.  * Glyph flags.
  72.  */
  73. #define    GF_VALID    0x0001    /* glyph is `real' */
  74. #define    GF_SEEN        0x0002    /* glyph has been encountered/loaded */
  75.  
  76. #define    GF_USR0        0x0100    /* reserved to user code */
  77. #define    GF_USR1        0x0200    /* reserved to user code */
  78. #define    GF_USR2        0x0400    /* reserved to user code */
  79. #define    GF_USR3        0x0800    /* reserved to user code */
  80.  
  81. /*
  82.  * Rotations are in quarter-pi steps, counterclockwise of course.
  83.  * This order must be maintained; see rotate.c.
  84.  */
  85. #define    ROT_NORM    0        /* no rotation: `normal' position */
  86. #define    ROT_LEFT    1        /* 1/4 turn counterclockwise */
  87. #define    ROT_DOWN    2        /* 1/2 turn, i.e., upside-down */
  88. #define    ROT_RIGHT    3        /* 3/4 turn ccw, or 1/4 turn cw */
  89.  
  90. struct font {
  91.     int    f_flags;    /* see below */
  92.     struct    fontops *f_ops;    /* operations */
  93.     /*
  94.      * f_un is provided for DVI drivers, which typically need
  95.      * some way to translate DVI font numbers into local values.
  96.      * Most seem to need integers.
  97.      */
  98.     union {
  99.         int    f_int;    /* value if int */
  100.         i32    f_i32;    /* value if i32 */
  101.         char    *f_ptr;    /* value if pointer */
  102.     } f_un;
  103. #ifdef notdef
  104.     /* for LRU cacheing; not yet implemented */
  105.     i32    f_lastuse;
  106. #endif
  107.     /*
  108.      * f_details is provided for font reading subroutines.
  109.      * It is intended to be cast to a pointer to a structure
  110.      * that is allocated by those routines, and used to keep
  111.      * track of whatever information those routines need to
  112.      * determine glyph boxes and (if asked for) rasters.
  113.      */
  114.     char    *f_details;    /* type dependent stuff */
  115.     /*
  116.      * f_path is the full pathname to the font file, filled in
  117.      * by GetFont and GetRasterlessFont.  Note that since we
  118.      * hold on to the path until the font is freed, it should be
  119.      * possible to cache glyph accesses on memory-poor machines.
  120.      */
  121.     char    *f_path;    /* font file pathname */
  122.     /*
  123.      * f_dvimag and f_dvidsz are the magnification and design size
  124.      * values from the DVI file.  f_font and f_scaled correspond to
  125.      * TeX's idea of the proper name for the font (e.g., `cmr10',
  126.      * `cmbx10 scaled 1440').  (Note that f_scaled is just the
  127.      * ratio of f_dvimag and f_dvidsz; you could save a bit of memory
  128.      * by eliminating it and altering the routine Font_TeXName()).
  129.      * f_design_size is the font's design size, or 0 for fake (TFM)
  130.      * fonts.  f_checksum should be set by the font reading routines
  131.      * to the font checksum.  If the value is nonzero, it will be
  132.      * compared to the checksum in the DVI file.
  133.      */
  134.     i32    f_dvimag;    /* magnification from DVI file */
  135.     i32    f_dvidsz;    /* design size from DVI file */
  136.     char    *f_font;    /* TeX's name for the font */
  137.     int    f_scaled;    /* the ratio of dvimag to dvidsz, x1000 */
  138.     i32    f_design_size;    /* font design size */
  139.     i32    f_checksum;    /* font checksum, or 0 */
  140.     /*
  141.      * The three values f_pspace, f_nspace, and f_vspace correspond
  142.      * to the amount of positive, negative, and vertical space that
  143.      * limits `kerning' (if horizontal) or `in-line motion' (vertical).
  144.      * f_pspace is equal to 1/6 of f_dvimag, and f_nspace and f_vspace
  145.      * are -4 and 5 times this value respectively.  DVItype puts it
  146.      * this way (slightly edited):
  147.      *
  148.      *    Rounding to the nearest pixel is best done in [this]
  149.      *    manner ... so as to be inoffensive to the eye:  When [a]
  150.      *    horizontal motion is small, like a kern, [the device
  151.      *    position] changes by rounding the kern; but when the
  152.      *    motion is large, [the device position] changes by rounding
  153.      *    the [DVI position] so that accumulated rounding errors
  154.      *    disappear.  We allow a larger space in the negative
  155.      *    direction than in the positive one, because TeX makes
  156.      *    comparatively large backspaces when it positions accents.
  157.      *
  158.      *    Vertical motion is done similarly, but with the threshold
  159.      *    between ``small'' and ``large'' increased by a factor of
  160.      *    five. The idea is to make fractions like ``$1\over2$''
  161.      *    round consistently, but to absorb accumulated rounding
  162.      *    errors in the baseline-skip moves.
  163.      *
  164.      * There is, however, an exception:
  165.      *
  166.      *    A sequence of consecutive rules, or consecutive characters
  167.      *    in a fixed-width font whose width is not an integer number
  168.      *    of pixels, can cause [the device position] to drift far
  169.      *    away from a correctly rounded value.
  170.      *
  171.      * The drift correction is applied after every horizontal or
  172.      * vertical motion, including any resulting from printing a
  173.      * character.
  174.      */
  175.     i32    f_pspace;    /* limit on positive kerns */
  176.     i32    f_nspace;    /* limit on negative kerns */
  177.     i32    f_vspace;    /* limit on vertical `kerns' */
  178.  
  179.     /*
  180.      * If set, f_hppp and f_vppp tell how many pixels there are
  181.      * per scaled point in the font.  For instance, a 300 dpi font
  182.      * has 300pixels/1inch * 1inch/72.27pt * 65536pt/1sp ~=
  183.      * 272046 pixels/sp.
  184.      *
  185.      * If they are zero, the font does not tell us.
  186.      */
  187.     i32    f_hppp;        /* horizontal pixels per point */
  188.     i32    f_vppp;        /* vertical pixels per point */
  189.     /*
  190.      * f_lowch and f_highch bound the region in which f_gly
  191.      * indicies are valid.  Specificially, f_gly[i] may be
  192.      * read or written if and only if i is in the half-open
  193.      * interval [f_lowch..f_highch).  f_gly is an array of
  194.      * pointers to glyph structures.  The structures themselves
  195.      * are not allocated until requested.
  196.      *
  197.      * f_glybase is the actual return from malloc(), since it
  198.      * is theoretically possible for f_gly-f_lowch to become
  199.      * NULL.
  200.      */
  201.     int    f_lowch;    /* first character */
  202.     int    f_highch;    /* last character, plus 1 */
  203.     struct    glyph **f_gly;    /* glyphs */
  204.     struct    glyph **f_glybase;
  205. };
  206.  
  207. /*
  208.  * Macros for rounding DVI and device motions per DVItype rules.
  209.  */
  210. #define    F_SMALLH(f, m) ((m) < (f)->f_pspace && (m) > (f)->f_nspace)
  211. #define    F_SMALLV(f, m) ((m) < (f)->f_vspace && -(m) < (f)->f_vspace)
  212.  
  213. /*
  214.  * Font flags.
  215.  */
  216. #define    FF_RASTERS    0x0001    /* font has rasters */
  217. #define    FF_USR0        0x0100    /* reserved to user code */
  218. #define    FF_USR1        0x0200    /* reserved to user code */
  219. #define    FF_USR2        0x0400    /* reserved to user code */
  220. #define    FF_USR3        0x0800    /* reserved to user code */
  221.  
  222. /*
  223.  * Operations on fonts.
  224.  *
  225.  * The `fo_dpitomag' field is used as a multiplier for a desired
  226.  * resolution in dots per inch.  The result of the multiplication
  227.  * is converted to a font name by multipying by 1000.0 and rounding.
  228.  * The idea is that PXL files will have a multiplier of 5.0, and
  229.  * others will have a multiplier of 1.0.  This suffices for the
  230.  * present, at any rate; in the future, this field may be replaced
  231.  * with something more general.
  232.  *
  233.  * N.B.: more operations may be added as they are discovered to be
  234.  * useful.
  235.  */
  236. struct    fontops {
  237.     char    *fo_name;        /* name, e.g., "gf" */
  238.     int    fo_fakefont;        /* 1="box", 2="blank"; else 0 */
  239.     double    fo_dpitomag;        /* multiplier */
  240.     int    (*fo_read)();        /* open and read the font itself */
  241.     int    (*fo_getgly)();        /* obtain specified glyphs (range) */
  242. #ifdef notdef
  243.     void    (*fo_freegly)();    /* release specified glyphs */
  244. #endif
  245.     int    (*fo_rasterise)();    /* rasterise specified glyphs */
  246.     void    (*fo_freefont)();    /* discard font (free details) */
  247.     struct    fontops *fo_next;    /* purely for font.c */
  248. };
  249.  
  250. /*
  251.  * Return a pointer to the glyph information for character `c' in
  252.  * font `f'.
  253.  */
  254. #define    GLYPH(f, c) \
  255.     ((c) < (f)->f_lowch || (c) >= (f)->f_highch ? (struct glyph *)0 : \
  256.      ((f)->f_gly[c] ? (f)->f_gly[c] : GetGlyph(f, (int)(c))))
  257.  
  258. /*
  259.  * True iff glyph `g' is valid.  Useful for checking return values
  260.  * from GLYPH().
  261.  */
  262. #define    GVALID(g)    ((g) && ((g)->g_flags & GF_VALID))
  263.  
  264. /*
  265.  * True iff glyph g has a raster.
  266.  */
  267. #define    HASRASTER(g)    ((g)->g_height && (g)->g_width)
  268.  
  269. /*
  270.  * Return a pointer to the raster information for glyph `g' in font
  271.  * `f' at rotation `r'.
  272.  */
  273. #define    RASTER(g, f, r)    ((g)->g_rotation == (r) && (g)->g_raster ? \
  274.              (g)->g_raster : GetRaster(g, f, r))
  275.  
  276. /*
  277.  * Function types.
  278.  */
  279. struct    font *GetFont(), *GetRasterlessFont();
  280. struct    glyph *GetGlyph();
  281. char    *GetRaster();
  282. void    FreeFont();
  283. void    FreeGlyph();
  284. void    FreeRaster();
  285. char    *Font_TeXName();
  286. double    DMagFactor();        /* from magfactor.c */
  287. void    fontinit();
  288.  
  289. /*
  290.  * Normally from stdio.h
  291.  */
  292. #ifndef NULL
  293. #define    NULL    0
  294. #endif
  295.  
  296. /*
  297.  * The following environment variable overrides the default font
  298.  * configuration file.  That default is used when fontinit() is not
  299.  * called, or is passed a null pointer.
  300.  */
  301. #define    CONFENV    "TEXFONTDESC"
  302.