Debian Codegraph @

texk/xdvipsk/dpicheck.c

raw
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 #ifndef XDVIPSK
7 #include "dvips.h" /* The copyright notice in that file is included too! */
8 #else
9 #include "xdvips.h" /* The copyright notice in that file is included too! */
10 #endif /* XDVIPSK */
11 /*
12 * The external declarations:
13 */
14 #include "protos.h"
15
16 static integer existsizes[30] = { 0 , 99999999 };
17 static int checkdpi;
18 /*
19 * This routine adds some sizes to `existsizes'.
20 */
21 static void
22 addsiz(int rhsize)
23 {
24 register integer *p;
25 long t, hsize;
26
27 hsize = rhsize;
28 for (p=existsizes; *p < hsize; p++);
29 if (*p == hsize)
30 return;
31 do {
32 t = *p;
33 *p++ = hsize;
34 hsize = t;
35 } while (hsize);
36 }
37 static void
38 adddpi(int hsize)
39 {
40 long a, b, c;
41 int i;
42
43 addsiz(hsize);
44 addsiz((int)((hsize * 116161L + 53020L) / 106040L));
45 a = hsize;
46 b = 0;
47 c = 1;
48 for (i=0; i<9; i++) {
49 b = 6 * b + (a % 5) * c;
50 a = a + a / 5;
51 c = c * 5;
52 if (b > c) {
53 b -= c;
54 a++;
55 }
56 if (b + b >= c)
57 addsiz((int)(a+1));
58 else
59 addsiz((int)a);
60 }
61 }
62 /*
63 * Finally, the routine that checks a size for match.
64 */
65 halfword
66 dpicheck(halfword dpi)
67 {
68 integer i;
69 integer margin = 1 + dpi / 500;
70
71 if (! checkdpi) {
72 adddpi(DPI);
73 checkdpi = 1;
74 }
75 for (i=0; existsizes[i] < dpi; i++);
76 if (existsizes[i]-dpi <= margin)
77 return(existsizes[i]);
78 else if (dpi-existsizes[i-1] <= margin)
79 return(existsizes[i-1]);
80 else
81 return(dpi);
82 }