home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / compsrcs / unix / volume03 / lcat2 < prev    next >
Encoding:
Internet Message Format  |  1988-09-11  |  6.2 KB

  1. From: linus!mnetor!clewis (Chris Lewis)
  2. Subject: Troff->HP Laserjet filter - newfonts.c
  3. Newsgroups: mod.sources
  4. Approved: jpn@panda.UUCP
  5.  
  6. Mod.sources:  Volume 3, Issue 100
  7. Submitted by: linus!mnetor!clewis (Chris Lewis)
  8.  
  9.  
  10. OOPS!  I somehow forgot to ship one of the source files for my
  11. Troff->HP Laserjet filter.  Here it is:
  12. [sorry about that]
  13.  
  14. #!/bin/sh
  15. echo 'Start of pack.out, part 01 of 01:'
  16. echo 'x - newfonts.c'
  17. sed 's/^X//' > newfonts.c << '/'
  18. X/*****************************************************************
  19. X
  20. X    Copyright 1985. All Rights Reserved Chris Lewis
  21. X
  22. X    Module          : newfonts.c 1.3
  23. X    Date submitted  : 86/01/30 09:19:57
  24. X    Author          : Chris Lewis
  25. X    Origin          : Permission to copy and further distribute is 
  26. X              freely given provided this copyright notice remains 
  27. X              intact and that this software is not sold for profit.
  28. X    Description     : Description of the file
  29. X
  30. X******************************************************************/
  31. X
  32. X#ifndef lint
  33. Xstatic char SrcId[] = "@(#) newfonts.c:1.3";
  34. X#endif
  35. X#include <stdio.h>
  36. X#include "../fonts/mkfonts/vfont.h"
  37. X
  38. Xextern FILE    *diagFile;
  39. X#define    DEBUGPRINTF    if (diagFile) debugprintf
  40. Xextern    char    *fontLib;
  41. X
  42. Xstatic int    dpi = 75;
  43. X
  44. Xstatic struct header header;
  45. Xstatic struct dispatch D[256];
  46. Xstatic unsigned char imageTable[BUFSIZ*10];
  47. X
  48. X/*    "s" is font name, point is desired point size, if (flag), use
  49. X    bigger fonts if possible    */
  50. Xloadfont(s, point, quality)
  51. Xchar    *s;
  52. Xint    point; 
  53. Xint    quality; {
  54. X    static char oldfont[BUFSIZ], buf[BUFSIZ], fontBuf[BUFSIZ];
  55. X    FILE   *f;
  56. X    register int i;
  57. X    sprintf(buf, "%s.%d", s, point);
  58. X    if (strcmp(oldfont, buf) == 0)
  59. X        return(dpi);
  60. X    strcpy(oldfont, buf);
  61. X    if (s[0] != '/') {
  62. X        strcpy(buf, fontLib);
  63. X        strcat(buf, s);
  64. X    }
  65. X    if (quality > 1) {
  66. X        i = point * 4;
  67. X        dpi = 300;
  68. X        do {
  69. X            sprintf(fontBuf, "%s.%d", buf, i);
  70. X            DEBUGPRINTF("Trying for font %s\n", fontBuf);
  71. X            if (access(fontBuf, 04) == 0)
  72. X                goto useit;
  73. X            i >>= 1;
  74. X            dpi /= 2;
  75. X        } while (dpi >= 75);
  76. X        dpi = 0;
  77. X        return(0);
  78. X    } else {
  79. X        sprintf(fontBuf, "%s.%d", buf, point);
  80. X        dpi = 75;
  81. X    }
  82. X
  83. Xuseit:
  84. X
  85. X    if (!(f = fopen(fontBuf, "r"))) {
  86. X        fprintf(stderr, "lcat: Could not load font %s, using native\n",
  87. X            fontBuf);
  88. X        dpi = 0;
  89. X        return(0);
  90. X    }
  91. X    DEBUGPRINTF("Loaded font %s (dpi: %d)\n", fontBuf, dpi);
  92. X    if (fread(&header, sizeof(header), 1, f) != 1) {
  93. X        fprintf(stderr, "lcat: Bad font file header\n");
  94. X        exit(1);
  95. X    }
  96. X    if (header.magic != 0436) {
  97. X        fprintf(stderr, "lcat: Bad font magic number\n");
  98. X        exit(1);
  99. X    }
  100. X    if (fread(D, sizeof(struct dispatch), 256, f) != 256) {
  101. X        fprintf(stderr, "lcat: Could not load font dispatch table\n");
  102. X        exit(1);
  103. X    }
  104. X    if (fread(imageTable, 1, header.size, f) != header.size) {
  105. X        fprintf(stderr, "lcat: Error reading image table\n");
  106. X        exit(1);
  107. X    }
  108. X    return(dpi);
  109. X}
  110. X
  111. X#define    UNASS    0
  112. X
  113. Xstatic unsigned char flashtovfnt[108] = {
  114. X    /*   1  */    'h',    /*h*/
  115. X    /*   2  */    't',    /*t*/
  116. X    /*   3  */    'n',    /*n*/
  117. X    /*   4  */    'm',    /*m*/
  118. X    /*   5  */    'l',    /*l*/
  119. X    /*   6  */    'i',    /*i*/
  120. X    /*   7  */    'z',    /*z*/
  121. X    /*   8  */    's',    /*s*/
  122. X    /*   9  */    'd',    /*d*/
  123. X    /*  10  */    'b',    /*b*/
  124. X    /*  11  */    'x',    /*x*/
  125. X    /*  12  */    'f',    /*f*/
  126. X    /*  13  */    'j',    /*j*/
  127. X    /*  14  */    'u',    /*u*/
  128. X    /*  15  */    'k',    /*k*/
  129. X    /*  16  */    UNASS,    /*unassigned*/
  130. X    /*  17  */    'p',    /*p*/
  131. X    /*  18  */    UNASS,    /*3/4 em*/
  132. X    /*  19  */    ';',    /*;*/
  133. X    /*  20  */    UNASS,    /*unassigned*/
  134. X    /*  21  */    'a',    /*a*/
  135. X    /*  22  */    '_',    /*horizontal rule*/
  136. X    /*  23  */    'c',    /*c*/
  137. X    /*  24  */    '`',    /*` open*/
  138. X    /*  25  */    'e',    /*e*/
  139. X    /*  26  */    '\'',    /*' close*/
  140. X    /*  27  */    'o',    /*o*/
  141. X    /*  28  */    UNASS,    /*1/4*/
  142. X    /*  29  */    'r',    /*r*/
  143. X    /*  30  */    UNASS,    /*1/2*/
  144. X    /*  31  */    'v',    /*v*/
  145. X    /*  32  */    '-',    /*- hyphen*/
  146. X    /*  33  */    'w',    /*w*/
  147. X    /*  34  */    'q',    /*q*/
  148. X    /*  35  */    '/',    /*/*/
  149. X    /*  36  */    '.',    /*.*/
  150. X    /*  37  */    'g',    /*g*/
  151. X    /*  38  */    UNASS,    /*3/4*/
  152. X    /*  39  */    ',',    /*,*/
  153. X    /*  40  */    '&',    /*&*/
  154. X    /*  41  */    'y',    /*y*/
  155. X    /*  42  */    UNASS,    /*unassigned*/
  156. X    /*  43  */    '%',    /*%*/
  157. X    /*  44  */    UNASS,    /*unassigned*/
  158. X    /*  45  */    'Q',    /*Q*/
  159. X    /*  46  */    'T',    /*T*/
  160. X    /*  47  */    'O',    /*O*/
  161. X    /*  48  */    'H',    /*H*/
  162. X    /*  49  */    'N',    /*N*/
  163. X    /*  50  */    'M',    /*M*/
  164. X    /*  51  */    'L',    /*L*/
  165. X    /*  52  */    'R',    /*R*/
  166. X    /*  53  */    'G',    /*G*/
  167. X    /*  54  */    'I',    /*I*/
  168. X    /*  55  */    'P',    /*P*/
  169. X    /*  56  */    'C',    /*C*/
  170. X    /*  57  */    'V',    /*V*/
  171. X    /*  58  */    'E',    /*E*/
  172. X    /*  59  */    'Z',    /*Z*/
  173. X    /*  60  */    'D',    /*D*/
  174. X    /*  61  */    'B',    /*B*/
  175. X    /*  62  */    'S',    /*S*/
  176. X    /*  63  */    'Y',    /*Y*/
  177. X    /* from here on are actually code 1-45, upper half of font */
  178. X    /*  64  */    'F',    /*F*/
  179. X    /*  65  */    'X',    /*X*/
  180. X    /*  66  */    'A',    /*A*/
  181. X    /*  67  */    'W',    /*W*/
  182. X    /*  68  */    'J',    /*J*/
  183. X    /*  69  */    'U',    /*U*/
  184. X    /*  70  */    'K',    /*K*/
  185. X    /*  71  */    '0',    /*0*/
  186. X    /*  72  */    '1',    /*1*/
  187. X    /*  73  */    '2',    /*2*/
  188. X    /*  74  */    '3',    /*3*/
  189. X    /*  75  */    '4',    /*4*/
  190. X    /*  76  */    '5',    /*5*/
  191. X    /*  77  */    '6',    /*6*/
  192. X    /*  78  */    '7',    /*7*/
  193. X    /*  79  */    '8',    /*8*/
  194. X    /*  80  */    '9',    /*9*/
  195. X    /*  81  */    '*',    /***/
  196. X    /*  82  */    '-',    /*minus*/
  197. X    /*  83  */    UNASS,    /*fi*/
  198. X    /*  84  */    UNASS,    /*fl*/
  199. X    /*  85  */    UNASS,    /*ff*/
  200. X    /*  86  */    0xa2,    /*cent sign*/
  201. X    /*  87  */    UNASS,    /*ffl*/
  202. X    /*  88  */    UNASS,    /*ffi*/
  203. X    /*  89  */    '(',    /*(*/
  204. X    /*  90  */    ')',    /*)*/
  205. X    /*  91  */    '[',    /*[*/
  206. X    /*  92  */    ']',    /*]*/
  207. X    /*  93  */    UNASS,    /*degree*/
  208. X    /*  94  */    UNASS,    /*dagger*/
  209. X    /*  95  */    '=',    /*=*/
  210. X    /*  96  */    0xa8,    /*registered*/
  211. X    /*  97  */    ':',    /*:*/
  212. X    /*  98  */    '+',    /*+*/
  213. X    /*  99  */    UNASS,    /*unassigned*/
  214. X    /* 100  */    '!',    /*!*/
  215. X    /* 101  */    0xd7,    /*bullet*/
  216. X    /* 102  */    '?',    /*?*/
  217. X    /* 103  */    UNASS,    /*foot mark*/
  218. X    /* 104  */    '|',    /*|*/
  219. X    /* 105  */    UNASS,    /*unassigned*/
  220. X    /* 106  */    0xa9,    /*copyright*/
  221. X    /* 107  */    UNASS,    /*square*/
  222. X    /* 108  */    '$'    /*$*/
  223. X};
  224. X
  225. Xflashrast(ch, points, ftype)
  226. Xint    ch, points, ftype; {
  227. X    register int idx = flashtovfnt[ch];
  228. X    register int i,j,H,V;
  229. X    register unsigned char *bp;
  230. X    V = D[idx].up + D[idx].down;
  231. X    H = (D[idx].left + D[idx].right + 7) / 8;
  232. X    bp = &imageTable[D[idx].addr];
  233. X    DEBUGPRINTF("ch=%d,idx=%d,V=%d,H=%d\n", ch, idx, V, H);
  234. X    printf("\033&a-%dV", (D[idx].up * 720) / dpi);
  235. X    printf("\033*t%dR", dpi);
  236. X    for (i = 0; i < V; i++) {
  237. X        printf("\033*r1A");
  238. X        printf("\033*b%dW", H);
  239. X        for (j = 0; j < H; j++)
  240. X            putchar(*bp++);
  241. X    }
  242. X    printf("\033*rB");
  243. X}
  244. /
  245. echo 'Part 01 of pack.out complete.'
  246. exit
  247.  
  248.  
  249.