home *** CD-ROM | disk | FTP | other *** search
/ World of Shareware - Software Farm 2 / wosw_2.zip / wosw_2 / PRINTING / DVIPS386.ZIP / DPICHECK.C < prev    next >
C/C++ Source or Header  |  1990-11-25  |  2KB  |  80 lines

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