[comp.sys.atari.st.tech] GDOS fonts without GDOS

micro@imada.dk (Claus Pedersen) (09/06/90)

Hi;
   Our system has been down for what seems like years without News. But before
this long and dark period in my life, someone asked if somebody could tell
(or show) how to use GDOS fonts with the VDI _without_ GDOS... Well, I can, and
I have a short C program which should show this, but it was never send due to 
the about catastrophy. I can send it now, but is the subject out of date??

Now a simple question:
   How can I use the fonts I have installed in the fontring, in objects???


Klaus (micro@imada.dk)

archbold (Archie Jaszcz) (09/09/90)

micro@imada.dk (Claus Pedersen) writes:
> this long and dark period in my life, someone asked if somebody could tell
> (or show) how to use GDOS fonts with the VDI _without_ GDOS... Well, I can, a
> I have a short C program which should show this, but it was never send due to
> the about catastrophy. I can send it now, but is the subject out of date??

        Sure it's not out of date!  Post it!  

                                Archbold

micro@imada.dk (Claus Pedersen) (09/12/90)

Hi;
   Included at the end of this file is a simple program which load a GDOS font
and installes it for use by the VDI, so that all normal VDI functions work
normally...
   The function Load_font loads the font (both M68000 and Intel format), into
a buffer passed by you.
   This demo program don't econimize on memory, but has a fixed buffer for one
font...

Klaus (micro@imada.dk)

--------------------------8<----------------------8<------------------------

/********************************************\
|** FNTTEST.C is (c) Klaus Pedersen. 7/90  **|
|** Written in Borland Turbo C v2.0        **|
\********************************************/

#include <linea.h>
#include <tos.h>
#include <vdi.h>
#define FONTNAME "atss24hi.fnt"

typedef unsigned char byte;

long ItoM(long x)
{union xbx
	{	long l;
		struct { byte b0; byte b1; byte b2; byte b3; } b;
	} a, b;
	a.l = x;
	b.b.b0 = a.b.b3;
	b.b.b1 = a.b.b2;
	b.b.b2 = a.b.b1;
	b.b.b3 = a.b.b0;
	return b.l;
}


void sItoM(int *x)
{struct bytes { byte b0;byte b1; };
 byte b;
 struct bytes *a = (struct bytes *)x;
	b = a->b0;
	a->b0 = a->b1;
	a->b1 = b;
}

	
int Load_font(char *n, FONT_HDR *b)
{int j, f, Char_count;
 long l;
 #define ofz_fnt( ident ) ((int)&(((FONT_HDR *)0)->ident))
 static int FixTab[] = 
 		{	ofz_fnt(id), ofz_fnt(size), ofz_fnt(ade_lo),
			ofz_fnt(ade_hi), ofz_fnt(top_dist), ofz_fnt(asc_dist),
			ofz_fnt(hlf_dist), ofz_fnt(des_dist), ofz_fnt(bot_dist),
			ofz_fnt(wchr_wdt), ofz_fnt(wcel_wdt), ofz_fnt(lft_ofst),
			ofz_fnt(rgt_ofst), ofz_fnt(thckning), ofz_fnt(undrline),
			ofz_fnt(frm_wdt), ofz_fnt(frm_hgt), -1
		};
	if ((f=Fopen(n, 0)) > 0)
	{	l = Fseek(0, f, 2);
		Fseek(0, f, 0);
		Fread(f, l, b);
		Fclose(f);
		if (b->flags.f68000)
		{	b->hz_ofst = (char *)( (char *)b + (long)b->hz_ofst );
			b->ch_ofst = (int  *)( (char *)b + (long)b->ch_ofst );
			b->fnt_dta = (void *)( (char *)b + (long)b->fnt_dta );
		}
		else
		{	j = 0;
			do
			{	sItoM( (int *)(FixTab[j++] + (byte *)b) ); }
			while ( FixTab[j] != -1 );
			b->hz_ofst = (char *)( (char *)b + ItoM((long)b->hz_ofst) );
			b->ch_ofst = (int  *)( (char *)b + ItoM((long)b->ch_ofst) );
			b->fnt_dta = (void *)( (char *)b + ItoM((long)b->fnt_dta) );
			Char_count = b->ade_hi - b->ade_lo;
			for(j = 0; j <= Char_count; j++)
				sItoM( &( b->ch_ofst[j] ) );
		}
		return 1;
	}
	return 0;
}


/* Reserve space to the font... */ 
int fh[0x8000l]; /* 64 Kb for a font... */
FONT_HDR *font_b = (FONT_HDR *)fh;

main()
{FONT_HDR *old_font;
 int hchar, wchar, hbox, wbox;
 int handle, ph;
 static int work_in[] = {1,1,1,1,1,1,1,1,1,1,2,0}, work_out[57];

	ph = graf_handle(&wchar, &hchar, &wbox, &hbox);
	work_in[0] = handle = ph;
	v_opnvwk(work_in, &handle, work_out);
	
	linea_init();

	if ( Load_font(FONTNAME, font_b) )
	{	/* Insert the font into the font-ring... */
		old_font = Vdiesc->font_ring[0];
		Vdiesc->font_ring[0] = font_b;
		font_b->next = old_font;
		Vdiesc->font_count++;
		
		/* do vdi stuff with font */
		vst_font(handle, font_b->id);
		vst_point(handle, font_b->size, &wchar, &hchar, &wbox, &hbox);
		v_gtext(handle, 10,200, "Testing... Testing...");
		
		/* Remove the font again... */
		Vdiesc->font_count--;
		Vdiesc->font_ring[0] = old_font;
	}
	v_clsvwk(handle);
	return 0;
}