| 1 |
/* |
| 2 |
* dpicheck of dvips.c. Checks the dots per inch to make sure |
| 3 |
* it exists. The fonts which exist are DPI at the appropriate |
| 4 |
* magnifications. |
| 5 |
*/ |
| 6 |
#include "dvips.h" /* The copyright notice in that file is included too! */ |
| 7 |
/* |
| 8 |
* The external declarations: |
| 9 |
*/ |
| 10 |
#include "protos.h" |
| 11 |
|
| 12 |
static integer existsizes[30] = { 0 , 99999999 }; |
| 13 |
static int checkdpi; |
| 14 |
/* |
| 15 |
* This routine adds some sizes to `existsizes'. |
| 16 |
*/ |
| 17 |
static void |
| 18 |
addsiz(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 |
static void |
| 34 |
adddpi(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(halfword dpi) |
| 63 |
{ |
| 64 |
integer i; |
| 65 |
integer margin = 1 + dpi / 500; |
| 66 |
|
| 67 |
if (! checkdpi) { |
| 68 |
adddpi(DPI); |
| 69 |
checkdpi = 1; |
| 70 |
} |
| 71 |
for (i=0; existsizes[i] < dpi; i++); |
| 72 |
if (existsizes[i]-dpi <= margin) |
| 73 |
return(existsizes[i]); |
| 74 |
else if (dpi-existsizes[i-1] <= margin) |
| 75 |
return(existsizes[i-1]); |
| 76 |
else |
| 77 |
return(dpi); |
| 78 |
} |