home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / text / tex / pastex / source / dvips / dpicheck.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-01-08  |  1.7 KB  |  90 lines

  1. /*
  2.  *   This software is Copyright 1988 by Radical Eye Software.
  3.  */
  4. /*
  5.  *   dpicheck of dvips.c.  Checks the dots per inch to make sure
  6.  *   it exists.  The fonts which exist are DPI at the appropriate
  7.  *   magnifications.
  8.  */
  9. #include "dvips.h"
  10. #ifdef AMIGA
  11. #include "dpicheck_protos.h"
  12. #endif
  13. extern int actualdpi ;
  14. static integer existsizes[30] = { 0 , 99999999 } ;
  15. static int checkdpi ;
  16. /*
  17.  *   This routine adds some sizes to `existsizes'.
  18.  */
  19. void addsiz(rhsize)
  20. int rhsize ;
  21. {
  22.    register integer *p ;
  23.    long t, hsize ;
  24.  
  25.    hsize = rhsize ;
  26.    for (p=existsizes; *p < hsize; p++) ;
  27.    if (*p == hsize)
  28.       return ;
  29.    do {
  30.       t = *p ;
  31.       *p++ = hsize ;
  32.       hsize = t ;
  33.    } while (hsize) ;
  34. }
  35. void adddpi(hsize)
  36. int hsize ;
  37. {
  38.    long a, b, c ;
  39.    int i ;
  40.  
  41.    addsiz(hsize) ;
  42.    addsiz((int)((hsize * 116161L + 53020L) / 106040L)) ;
  43.    a = hsize ;
  44.    b = 0 ;
  45.    c = 1 ;
  46.    for (i=0; i<9; i++) {
  47.       b = 6 * b + (a % 5) * c ;
  48.       a = a + a / 5 ;
  49.       c = c * 5 ;
  50.       if (b > c) {
  51.          b -= c ;
  52.          a++ ;
  53.       }
  54.       if (b + b >= c)
  55.          addsiz((int)(a+1)) ;
  56.       else
  57.          addsiz((int)a) ;
  58.    }
  59. }
  60. /*
  61.  *   Finally, the routine that checks a size for match.
  62.  */
  63. halfword
  64. dpicheck(dpi)
  65. halfword dpi ;
  66. {
  67.    integer i ;
  68.    integer margin = 1 + dpi / 500 ;
  69.  
  70.    if (! checkdpi) {
  71.       adddpi(DPI) ;
  72.       checkdpi = 1 ;
  73.    }
  74.    for (i=0; existsizes[i] < dpi; i++) ;
  75.    if (existsizes[i]-dpi <= margin)
  76. #ifdef AMIGA
  77.       return (halfword) (existsizes[i]) ;
  78. #else
  79.       return(existsizes[i]) ;
  80. #endif
  81.    else if (dpi-existsizes[i-1] <= margin)
  82. #ifdef AMIGA
  83.      return (halfword) (existsizes[i-1]) ;
  84. #else
  85.       return(existsizes[i-1]) ;
  86. #endif
  87.    else
  88.       return(dpi) ;
  89. }
  90.