|
|
1.1 ! root 1: /******************************************************************* ! 2: * * ! 3: * File: CIFPLOT/fonts.c * ! 4: * Written by Dan Fitzpatrick * ! 5: * copyright 1980 -- Regents of the University of California * ! 6: * * ! 7: ********************************************************************/ ! 8: ! 9: #include <stdio.h> ! 10: #include <vfont.h> ! 11: #include "defs.h" ! 12: #include "globals.h" ! 13: #include "structs.h" ! 14: #include "out_structs.h" ! 15: #include "alloc.h" ! 16: ! 17: IMPORT char *Concat(); ! 18: IMPORT alloc(); ! 19: IMPORT Error(); ! 20: ! 21: FORWARD real TCompare(); ! 22: ! 23: struct header header; ! 24: struct dispatch dispatch[256]; ! 25: char *bits; ! 26: ! 27: char *fontfile = "R.6"; ! 28: ! 29: InitText() ! 30: { ! 31: char *s; ! 32: int fonts; ! 33: int i; ! 34: ! 35: /* Get the font file */ ! 36: s = Concat("/usr/lib/vfont/",fontfile,0); ! 37: if((fonts = open(s,0)) == -1) { ! 38: perror(s); ! 39: Error("Can't get font file",RUNTIME); ! 40: } ! 41: /* Get the header and check magic number */ ! 42: if(read(fonts,&header,sizeof(header)) != sizeof(header)) { ! 43: perror(s); ! 44: Error("Bad read in font file",RUNTIME); ! 45: } ! 46: if(header.magic != 0436) { ! 47: Error("Bad magic numer in font file",RUNTIME); ! 48: } ! 49: /* Get dispatches */ ! 50: if(read(fonts,dispatch,sizeof(dispatch)) != sizeof(dispatch)) { ! 51: perror(s); ! 52: Error("Bad read in font file",RUNTIME); ! 53: } ! 54: /* Allocate space for bit map and read in bits */ ! 55: bits = (char *) alloc(header.size); ! 56: if(read(fonts,bits,header.size) != header.size) { ! 57: perror(s); ! 58: Error("Can't read bit map in font file",RUNTIME); ! 59: } ! 60: /* Close font file */ ! 61: if(close(fonts) != 0) { ! 62: perror(s); ! 63: Error("Can't close font file",RUNTIME); ! 64: } ! 65: /* Find the possible range up and down in which the text fits */ ! 66: TextUp = TextDown = 0; ! 67: for(i=0;i<256;i++) { ! 68: if(dispatch[i].nbytes && TextUp < dispatch[i].up) ! 69: TextUp = dispatch[i].up; ! 70: if(dispatch[i].nbytes && TextDown < dispatch[i].down) ! 71: TextDown = dispatch[i].down; ! 72: } ! 73: } ! 74: ! 75: DrawText(s,i,ypos,xpos) ! 76: char *s; ! 77: int i,ypos,xpos; ! 78: { ! 79: if(!text) return; ! 80: /* For all characters in string call DrawChar offset each character ! 81: * by the width of the previous one */ ! 82: for(;*s;s++) { ! 83: ypos += DrawChar(*s,i,ypos,xpos); ! 84: } ! 85: } ! 86: ! 87: int ! 88: DrawChar(ch,i,ypos,xpos) ! 89: char ch; ! 90: int i,ypos,xpos; ! 91: { ! 92: int nbytes,j; ! 93: char *addr; ! 94: ! 95: /* It white space return an offset */ ! 96: if(ch == ' ' || ch == '\t' ) return((int) dispatch['t'].width); ! 97: ! 98: blank(ypos-1,ypos+1+dispatch[ch].width,xpos); ! 99: /* If the line lines in appropriate range fill in bits for character */ ! 100: if(-dispatch[ch].down < i && i <= dispatch[ch].up) { ! 101: addr = bits+dispatch[ch].addr; ! 102: nbytes = (dispatch[ch].right + dispatch[ch].left + 7)/8; ! 103: addr += (dispatch[ch].up - i)*nbytes; ! 104: for(j=0; j<nbytes; j++) ! 105: match(addr[j],j*8 - dispatch[ch].left + ypos,xpos); ! 106: } ! 107: return((int) dispatch[ch].width); ! 108: } ! 109: ! 110: TextLength(s) ! 111: char *s; ! 112: { ! 113: int len; ! 114: len = 0; ! 115: for(;*s;s++) ! 116: len += TextWidth(*s); ! 117: return(len); ! 118: } ! 119: ! 120: TextWidth(ch) ! 121: char ch; ! 122: { ! 123: return( (ch == ' ' || ch == '\t') ? dispatch['t'].width : dispatch[ch].width); ! 124: } ! 125: ! 126: ClipText(s,rx,ry,adjust) ! 127: char *s; ! 128: real rx,ry; ! 129: char adjust; ! 130: { ! 131: int x,y; ! 132: int len; ! 133: char *p; ! 134: TextStruct *t; ! 135: ! 136: if(!text) return; ! 137: switch(adjust) { ! 138: case 'l': ! 139: /* Left adjust */ ! 140: x = CONVERT(rx); ! 141: y = CONVERT(ry); ! 142: break; ! 143: case 'c': ! 144: case 'C': ! 145: /* Center adjust */ ! 146: x = CONVERT(rx) + TextUp/2; ! 147: y = CONVERT(ry) - TextLength(s)/2; ! 148: break; ! 149: case 'r': ! 150: case 'R': ! 151: /* Right adjust */ ! 152: x = CONVERT(rx); ! 153: y = CONVERT(ry) - TextLength(s); ! 154: break; ! 155: case 'S': ! 156: /* Adjust for symbol name */ ! 157: if(!printSymbolName) return; ! 158: x = CONVERT(rx) + TextUp + 7; ! 159: y = CONVERT(ry) + 5; ! 160: break; ! 161: case 'T': ! 162: /* Adjust for point name */ ! 163: x = CONVERT(rx) + TextUp+1; ! 164: y = CONVERT(ry)+1; ! 165: break; ! 166: default: ! 167: Error("Unknown text adjustment in ClipText",INTERNAL); ! 168: } ! 169: for(;*s && y < 0;s++) y += TextWidth(*s); ! 170: len = y; ! 171: for(p = s; *p && len < NoPixcels; p++) len += TextWidth(*p); ! 172: *p = '\0'; ! 173: if(*s == '\0') return; ! 174: t = GetTextStruct(); ! 175: t->str = s; ! 176: t->xpos = x; t->ypos = y; ! 177: PutList(t,&TextList,TCompare); ! 178: return; ! 179: } ! 180: ! 181: /* ! 182: testfont() ! 183: { ! 184: int nbytes; ! 185: char ch; ! 186: char *addr; ! 187: int i; ! 188: int j; ! 189: ! 190: vopen(); ! 191: for(i = 40; i > -20; i--) { ! 192: DrawText("abcDE2@q Now is the time for all good men to come to the aid ... !@#$%^&*()_+}{|~`':::;<>.,",i,13); ! 193: } ! 194: vclose(); ! 195: } ! 196: ! 197: display(i) ! 198: int i; ! 199: { ! 200: int k; ! 201: for(k=0;k<8;k++) { ! 202: if(i & 0x80) putchar('x'); ! 203: else putchar(' '); ! 204: i = i << 1; ! 205: } ! 206: } ! 207: */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.