/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ * |_o_o|\\ Copyright (c) 1987 The Software Distillery. All Rights Reserved * * |. o.| || Written by Doug Walker * * | . | || The Software Distillery * * | o | || 235 Trillingham Lane * * | . |// Cary, NC 27511 * * ====== BBS:(919)-471-6436 * \* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "mydebug.h" #include "exec/types.h" #include "exec/memory.h" #include "intuition/intuition.h" #include "stdio.h" #include "hackicon.h" extern struct iconfont *fonts[2]; extern struct IntuiText MiscText[]; extern int fontnum; extern USHORT colormap[]; extern struct Window *Window; extern struct ViewPort *ViewPort; LoadFont(name, num) char *name; int num; { FILE *fp; int i; register struct Image *curimage; register struct iconfont *ifont; register USHORT *dataptr, *endptr; if(name == NULL) return(1); BUG(1, ("LoadFont: Enter, name=%s, num=%d\n", name, num)) if(num<0) { for(num=0; num= MAXFONTS) { AutoRequest(Window, &MiscText[4], NULL, &MiscText[2], 0, 0, 410, 90); return(1); } } if(fonts[num]) FreeMem(fonts[num], sizeof(struct iconfont)); fontnum = num; if(!(ifont = fonts[num] = (struct iconfont *) AllocMem(sizeof(struct iconfont), MEMF_CHIP | MEMF_CLEAR))) { AutoRequest(Window, &MiscText[3], NULL, &MiscText[2], 0, 0, 410, 90); return(1); } strcpy(ifont->filename, name); if(NULL == (fp = fopen(name, "rb"))) { BUG(4, ("LoadFont: Null fp, initializing font.\n")) movmem(colormap, ifont->colormap, 16*sizeof(USHORT)); ifont->firstchar = 255; ifont->lastchar = 0; } else { BUG(4, ("LoadFont: reading color data.\n")) for(i=0; i<16; i++) { colormap[i] = ifont->colormap[i] = (getc(fp) << 8) | getc(fp); BUG(9, ("LoadFont: colormap[%d] = %4x\n", i, colormap[i])) } LoadRGB4(ViewPort, colormap, 16); ifont->firstchar = getc(fp); ifont->lastchar = getc(fp); } BUG(2, ("LoadFont: firstchar=%d, lastchar=%d\n",ifont->firstchar,ifont->lastchar)) for(i=0, curimage=ifont->images, dataptr = ifont->idata; i<256; i++, curimage++, dataptr += ILENGTH) { curimage->NextImage = (i < 255 ? curimage+1 : NULL); curimage->LeftEdge = IXCALC(i); curimage->TopEdge = IYCALC(i); curimage->Width = IWIDTH; curimage->Height = IHEIGHT; curimage->Depth = IDEPTH; curimage->ImageData = dataptr; curimage->PlanePick = 0x0F; curimage->PlaneOnOff = 0x00; } BUG(8, ("LoadFont: Done calculating image structs\n")) if(fp) { for(dataptr= ifont->idata + (ILENGTH*ifont->firstchar), endptr = ifont->idata + (ILENGTH*ifont->lastchar); dataptr <= endptr; dataptr += ILENGTH) for(i=0; iRPort, ifont->images, 0, 0); SetWindowTitles(Window, name, name); BUG(1, ("LoadFont: Exit\n")) return(0); } SaveFont(name) char *name; { FILE *fp, *fopen(); int i, j; unsigned char *cptr; if(name == NULL) name = fonts[fontnum]->filename; BUG(1, ("SaveFont: save %s as %s\n", fonts[fontnum]->filename, name)) if(!strcmp(name, fonts[fontnum]->filename) && !(fonts[fontnum]->flags & CHANGED) ) return(0); if(!(fp=fopen(name, "wb"))) { AutoRequest(Window, MiscText, NULL, &MiscText[2], 0, 0, 410, 90); return(1); } for(i=0, cptr= (unsigned char *)colormap; i<16; i++) { putc(*(cptr++), fp); putc(*(cptr++), fp); } for(i = fonts[fontnum]->firstchar; i<=fonts[fontnum]->lastchar; i++) { for(cptr=(unsigned char *)(fonts[fontnum]->idata+(ILENGTH*i)), j=0; j= ILENGTH) fonts[fontnum]->firstchar++; else break; } for(i = fonts[fontnum]->lastchar; i>=fonts[fontnum]->firstchar; i--) { for(cptr=(unsigned char *)(fonts[fontnum]->idata+(ILENGTH*i)), j=0; j= ILENGTH) fonts[fontnum]->lastchar--; else break; } putc(fonts[fontnum]->firstchar, fp); putc(fonts[fontnum]->lastchar, fp); for(i=fonts[fontnum]->firstchar, cptr=(unsigned char *)(fonts[fontnum]->idata+(ILENGTH*i)); i<=fonts[fontnum]->lastchar; i++) for(j=0; jflags &= (~CHANGED); return(0); }