Back to index

tetex-bin  3.0
dpicheck.c
Go to the documentation of this file.
00001 /*
00002  *   This software is Copyright 1988 by Radical Eye Software.
00003  */
00004 /*
00005  *   dpicheck of dvips.c.  Checks the dots per inch to make sure
00006  *   it exists.  The fonts which exist are DPI at the appropriate
00007  *   magnifications.
00008  */
00009 #include "dvips.h"
00010 extern int actualdpi ;
00011 static integer existsizes[30] = { 0 , 99999999 } ;
00012 static int checkdpi ;
00013 /*
00014  *   This routine adds some sizes to `existsizes'.
00015  */
00016 void addsiz P1C(int, rhsize)
00017 {
00018    register integer *p ;
00019    long t, hsize ;
00020 
00021    hsize = rhsize ;
00022    for (p=existsizes; *p < hsize; p++) ;
00023    if (*p == hsize)
00024       return ;
00025    do {
00026       t = *p ;
00027       *p++ = hsize ;
00028       hsize = t ;
00029    } while (hsize) ;
00030 }
00031 void adddpi P1C(int, hsize)
00032 {
00033    long a, b, c ;
00034    int i ;
00035 
00036    addsiz(hsize) ;
00037    addsiz((int)((hsize * 116161L + 53020L) / 106040L)) ;
00038    a = hsize ;
00039    b = 0 ;
00040    c = 1 ;
00041    for (i=0; i<9; i++) {
00042       b = 6 * b + (a % 5) * c ;
00043       a = a + a / 5 ;
00044       c = c * 5 ;
00045       if (b > c) {
00046          b -= c ;
00047          a++ ;
00048       }
00049       if (b + b >= c)
00050          addsiz((int)(a+1)) ;
00051       else
00052          addsiz((int)a) ;
00053    }
00054 }
00055 /*
00056  *   Finally, the routine that checks a size for match.
00057  */
00058 halfword
00059 dpicheck P1C(halfword, dpi)
00060 {
00061    integer i ;
00062    integer margin = 1 + dpi / 500 ;
00063 
00064    if (! checkdpi) {
00065       adddpi(DPI) ;
00066       checkdpi = 1 ;
00067    }
00068    for (i=0; existsizes[i] < dpi; i++) ;
00069    if (existsizes[i]-dpi <= margin)
00070       return(existsizes[i]) ;
00071    else if (dpi-existsizes[i-1] <= margin)
00072       return(existsizes[i-1]) ;
00073    else
00074       return(dpi) ;
00075 }