|
|
DataMuseum.dkPresents historical artifacts from the history of: Commodore CBM-900 |
This is an automatic "excavation" of a thematic subset of
See our Wiki for more about Commodore CBM-900 Excavated with: AutoArchaeologist - Free & Open Source Software. |
top - metrics - download
Length: 9935 (0x26cf)
Types: TextFile
Notes: UNIX file
Names: »f2.c«
└─⟦f27320a65⟧ Bits:30001972 Commodore 900 hard disk image with partial source code
└─⟦2d53db1df⟧ UNIX Filesystem
└─⟦this⟧ »hr/src/desk/f2.c«
#include <stdio.h>
#include <smgr.h>
extern char *malloc();
extern int *bmialloc();
FONT_HEADER *aftable[FM_MAXFONT];
/***********************************************************************
Font_test.c allows application programs the use of a wide
variety of fonts using minimal amounts of system memory.
Accessing a font is done by using the following Font_Mgr.c
functions: FM_open, FM_close, FM_getch, SM_GetInfo
***********************************************************************/
FM_open(ff_name)
char *ff_name;
{
register FONT_HEADER *aft_entry;
register int i;
FILE *fp;
int tbl_entrs, /* number of table entries */
fwords; /* number of words in entire
bitmap image */
#ifdef DEBUG
printf("*** FM_open: %s ****\n", ff_name);
#endif
/* for a few minutes here, fwords will be used to determine
* whether or not there is an index available
*/
fwords = 0;
/* allocate storage for font header */
if(!(aft_entry = (FONT_HEADER *) malloc(sizeof(FONT_HEADER))))
{
printf("FM_open: **** ERROR ****");
printf(" memory allocation ** failed (aft_entry)\n\n");
return(MEM_ALLOC_FAIL);
}
if(!(fp = fopen(ff_name,"r"))) /* input file read only */
{
printf("FM_open: **** ERROR ****");
printf(" input file open ** failed\n\n");
free(aft_entry);
return(FILE_OPEN_FAIL);
}
/* load the FONT_HEADER */
aft_entry->ffirst_char = (int) getc(fp); /* first char of font */
aft_entry->flast_char = (int) getc(fp); /* last char of font */
aft_entry->flast_char &= 0xff; /* possible sign extension*/
aft_entry->font_ascent = getc(fp); /* font ascent */
aft_entry->font_descent = getc(fp); /* font descent */
aft_entry->font_leading = getc(fp); /* font leading */
aft_entry->fmax_width = getc(fp); /* maximum font width */
aft_entry->fmin_width = getc(fp); /* minimum font width */
for(i = 0; i < FM_MAXNLEN; i++)
aft_entry->ffont_name[i] = getc(fp); /* font name */
aft_entry->unused1 = getc(fp); /* unused area 1 */
aft_entry->unused2 = getc(fp); /* unused area 2 */
aft_entry->unused3 = getc(fp); /* unused area 3 */
aft_entry->font_map.rect.origin.x = 0;
aft_entry->font_map.rect.origin.y = 0;
aft_entry->font_map.rect.corner.x = getw(fp);
aft_entry->font_map.rect.corner.y = getw(fp);
i = aft_entry->font_map.rect.corner.x;
aft_entry->font_map.width = (i % 16)? (i/16+1): (i/16);
(aft_entry->font_map.width) *= 16;
for(i = 0; i < FM_MAXFONT; i++)
if(aftable[i]) /* is aftable[i] <> 0 */
if(strcmp(aft_entry->ffont_name,aftable[i]->ffont_name) == 0)
{
if ( i != 0 )
aftable[i]->fopen_count++;
#ifdef DEBUG
printf("---- FONT ALREADY OPEN ---- increment open count\n");
printf(" aftable[%d]->fopen_count = %d\n",i,aftable[i]->fopen_count);
#endif
return(i);
}
for(i = 0; i < FM_MAXFONT; i++)
if(!(aftable[i])) /* is aftable = 0 */
{
fwords = 1;
break;
}
if ( fwords == 0 )
{
printf("FM_open: **** ERROR ****");
printf(" maximum number of (8) fonts already loaded\n\n");
return(TAB_FILLED);
}
#ifdef DEBUG
printf("---- FONT NOT CURRENTLY IN USE ----\n");
printf(" aftable[%d] * available *\n\n",i);
#endif
aftable[i] = aft_entry;
aft_entry->fopen_count = 1;
tbl_entrs = (aft_entry->flast_char) - (aft_entry->ffirst_char) + 3;
#ifdef DEBUG
printf("HEADER COPY:\n");
printf(" first=%d, last=%d\n",aft_entry->ffirst_char,aft_entry->flast_char);
printf(" ascent=%d, descent=%d\n",aft_entry->font_ascent,aft_entry->font_descent);
printf(" leading=%d, maxwidth=%d\n",aft_entry->font_leading,aft_entry->fmax_width);
printf(" minwidth=%d, fid=%d, fontname=%s\n",aft_entry->fmin_width,i,aft_entry->ffont_name);
printf(" tbl_entrs = %d, open_count = %d\n\n",tbl_entrs,aft_entry->fopen_count);
#endif
/* allocate storage for location table */
if(!(aft_entry->loctable = (int *) malloc(tbl_entrs*2)))
{
fclose(fp);
printf("FM_open: **** ERROR ****");
printf(" memory allocation failed (loctable)\n\n");
free(aft_entry);
aftable[i] = (FONT_HEADER *) FONT_NULL;
return(MEM_ALLOC_FAIL);
}
/* allocate storage for kern/width table */
if(!(aft_entry->kwtable = (int *) malloc(tbl_entrs*2)))
{
fclose(fp);
printf("FM_open: **** ERROR ****");
printf(" memory allocation failed (kwtable)\n\n");
free(aft_entry->loctable);
free(aft_entry);
aftable[i] = (FONT_HEADER *) FONT_NULL;
return(MEM_ALLOC_FAIL);
}
/* allocate storage for bitmap */
aft_entry->font_map.base = bmialloc(aft_entry->font_map.rect);
if ( aft_entry->font_map.base == (int *)NULL )
{
fclose(fp);
printf("FM_open: memory fail for bitmap\n");
free(aft_entry->loctable);
free(aft_entry->kwtable);
free(aft_entry);
aftable[i] = (FONT_HEADER *) NULL;
return(MEM_ALLOC_FAIL);
}
if(aft_entry->font_map.base == (int*)NULL)
{
fclose(fp);
printf("FM_open: **** ERROR ****");
printf(" memory allocation ** failed (font_map.base)\n\n");
free(aft_entry->loctable);
free(aft_entry->kwtable);
free(aft_entry);
aftable[i] = (FONT_HEADER *) FONT_NULL;
return(MEM_ALLOC_FAIL);
}
fwords = ((aft_entry->font_map.width) / 16) *
(aft_entry->font_map.rect.corner.y);
fread(aft_entry->loctable, sizeof(int), tbl_entrs, fp);
fread(aft_entry->kwtable, sizeof(int), tbl_entrs, fp);
fread(aft_entry->font_map.base, sizeof(int), fwords, fp);
fclose(fp);
return(i);
}
FM_getch(fmptr)
register GETPTR *fmptr;
{
register FONT_HEADER *aft_entry;
int
pos, /* pos of character in table */
npos, /* pos of next character */
chr_entrs, /* number of entries in table */
char_width, /* width of characters in pixels */
ffid;
#ifdef DEBUG
printf("gfid = %d, gch = %d\n",fmptr->gfid,fmptr->gch);
printf("gbmap = 0x%lx, gpoint = 0x%lx\n",fmptr->gbmap,fmptr->gpoint);
printf("gascent = 0x%lx, gdescent = 0x%lx\n",fmptr->gascent,fmptr->gdescent);
printf("gleading = 0x%lx, gawdth = 0x%lx\n\n",fmptr->gleading,fmptr->gawdth);
#endif
ffid = fmptr->gfid;
if( (ffid >=FM_MAXFONT) || (ffid < 0 ) || (!(aftable[ffid])) )
return(FONT_NOT_OPEN);
aft_entry = aftable[ffid];
#ifdef DEBUG
printf("aftable[%d] = %lx\n\n",ffid,aft_entry);
#endif
chr_entrs = (aft_entry->flast_char) - (aft_entry->ffirst_char);
pos = (fmptr->gch) - (aft_entry->ffirst_char);
for(npos = pos+1; aft_entry->kwtable[npos] == FNOT_EXST; npos++)
;
if((pos < 0) || (pos > chr_entrs))
{
#ifdef DEBUG
printf("FM_getch: **** ERROR ****\n");
printf(" character does not exist in font\n\n");
#endif
pos = (aft_entry->flast_char) - (aft_entry->ffirst_char) + 1;
npos = pos + 1;
}
if(aft_entry->kwtable[pos] == FNOT_EXST)
{
#ifdef DEBUG
printf("FM_getch: **** ERROR ****\n");
printf(" character does not exist in font\n\n");
#endif
pos = (aft_entry->flast_char) - (aft_entry->ffirst_char) + 1;
npos = pos + 1;
}
fmptr->gbmap = aft_entry->font_map;
fmptr->gpoint.x = aft_entry->loctable[pos];
fmptr->gpoint.y = 0;
fmptr->gkern = ((aft_entry->kwtable[pos]) >> 8) & (0x00FF);
char_width = (aft_entry->kwtable[pos]) & (0x00FF);
fmptr->gascent = aft_entry->font_ascent;
fmptr->gdescent = aft_entry->font_descent;
fmptr->gleading = aft_entry->font_leading;
fmptr->gawdth = (aft_entry->loctable[npos]) -
(aft_entry->loctable[pos]);
#ifdef DEBUG
printf("!!!! AFTER ASSIGNMENTS HAVE BEEN MADE !!!\n");
printf("gfid = %d, gch = %d\n",fmptr->gfid,fmptr->gch);
printf("gbmap = 0x%lx, gpoint = 0x%lx\n",fmptr->gbmap,fmptr->gpoint);
printf("******* BITMAP ********\n");
printf("bbase = 0x%lx, bwidth = %d\n",fmptr->gbmap.base,fmptr->gbmap.width);
printf("boriginx = %d, boriginy = %d\n",fmptr->gbmap.rect.origin.x,fmptr->gbmap.rect.origin.y);
printf("bcornerx = %d, bcornery = %d\n",fmptr->gbmap.rect.corner.x,fmptr->gbmap.rect.corner.y);
printf("bpointx = %d, bpointy = %d\n",fmptr->gpoint.x,fmptr->gpoint.y);
printf("gascent = 0x%lx, gdescent = 0x%lx\n",fmptr->gascent,fmptr->gdescent);
printf("gleading = 0x%lx, gawdth = 0x%lx\n\n",fmptr->gleading,fmptr->gawdth);
printf("character %d, pos = %d, char_width = %d\n",fmptr->gch,pos,char_width);
printf("kern = %d, actual width = %d\n\n",fmptr->gkern,fmptr->gawdth);
#endif
return(char_width);
}
FM_close(cfid)
register int cfid; /* font id number */
{
register FONT_HEADER *aft_entry;
#ifdef DEBUG
printf("Font_close: %d\n", cfid);
#endif
if ( cfid == 0 )
return(FCLOSE_OK);
if ( (cfid < 0 ) || (cfid >= FM_MAXFONT) || (!(aftable[cfid])) )
{
return(FNOT_EXST);
}
else
{
aft_entry = aftable[cfid];
aft_entry->fopen_count--;
if(!(aft_entry->fopen_count)) /* is open count = 0 */
{
#ifdef DEBUG
printf("FM_close: dispose handle %d\n\n",aft_entry->font_map.base);
#endif
free(aft_entry->font_map.base);
free(aft_entry->kwtable);
free(aft_entry->loctable);
free(aft_entry);
aftable[cfid] = (FONT_HEADER *) FONT_NULL;
}
return(FCLOSE_OK);
}
}