[comp.sys.atari.st.tech] detecting GDOS and using vst_load_fonts

steve@thelake.mn.org (Steve Yelvington) (05/29/91)

I'm having trouble figuring out how to use an alternate font
to draw text in a GEM window. I presume I need to check for
the existence of GDOS before calling vst_load_fonts, but
how?

I'm also getting three bombs when calling vst_load_fonts, with
AMCLITE installed and ASSIGN.SYS set up properly (or at least well
enough that GEMINI doesn't complain).

I'd like to install Gemini 9 pt inside an application program.
Do I need to search for "Gemini 9 pt" in the data returned by
vqt_name() or do I search for the filename "BAGE09.FNT"?

Code fragment follows:


open_vwork()
	{
	int i;
	char tmpln[80];
	handle = graf_handle( &char_w, &char_h, &box_w, &box_h);
	for( i=0; i<10; work_in[i++] = 1 );
	work_in[10] = 2;
	v_opnvwk( work_in, &handle, work_out);
	fonts_loaded = work_out[10];
	sprintf(tmpln,"[1][There are %d|fonts available][OK]",fonts_loaded);
	form_alert(1,tmpln);
/* note: it tells me I have one font available */
	fonts_loaded =  vst_load_fonts(handle,2);
/* BOOM! Three big ones and we go no further */
	sprintf(tmpln,"[1][After vst_load_fonts,|there are %d|fonts available][OK]",fonts_loaded);
	form_alert(1,tmpln);
	if (fonts_loaded > 1)
		set_font();
	}

set_font()
	{
/* Wouldn't it be nice if there were a font selector like the 
   file selector? (Volunteers?)  */
	int i,fontindex;
	char fontname[32];
	char *p = "BAGE09.FNT"; /* or should it be "Gemini 9"? */
	if (form_alert(2,"[1][Load BAGE09.FNT?][Yes|No]") == 2) 
		return;
	for (i=0;i<fonts_loaded;i++)
		{
		/* find the font */
		fontindex = vqt_name(handle,i,fontname);
		if(strnicmp(p,fontname,strlen(p))== 0)
			{		
			/* select the font */
			vst_font(handle,fontindex);
			/* set the point size */
			vst_point(handle,9,&char_w, &char_h, &box_w, &box_h);
			return;
			}
		}
	}
		
 ----
 Steve Yelvington, Marine on St. Croix, Minnesota, USA / steve@thelake.mn.org

steve@thelake.mn.org (Steve.Yelvington) (05/30/91)

(This is a repost ... because of a configuration error, the original may
not have achieved the distribution I had intended.)

---

I'm having trouble figuring out how to use an alternate font
to draw text in a GEM window. I presume I need to check for
the existence of GDOS before calling vst_load_fonts, but
how?

I'm also getting three bombs when calling vst_load_fonts, with
AMCLITE installed and ASSIGN.SYS set up properly (or at least well
enough that GEMINI doesn't complain).

I'd like to install Gemini 9 pt inside an application program.
Do I need to search for "Gemini 9 pt" in the data returned by
vqt_name() or do I search for the filename "BAGE09.FNT"?

Code fragment follows:


open_vwork()
	{
	int i;
	char tmpln[80];
	handle = graf_handle( &char_w, &char_h, &box_w, &box_h);
	for( i=0; i<10; work_in[i++] = 1 );
	work_in[10] = 2;
	v_opnvwk( work_in, &handle, work_out);
	fonts_loaded = work_out[10];
	sprintf(tmpln,"[1][There are %d|fonts available][OK]",fonts_loaded);
	form_alert(1,tmpln);
/* note: it tells me I have one font available */
	fonts_loaded =  vst_load_fonts(handle,2);
/* BOOM! Three big ones and we go no further */
	sprintf(tmpln,"[1][After vst_load_fonts,|there are %d|fonts available][OK]",fonts_loaded);
	form_alert(1,tmpln);
	if (fonts_loaded > 1)
		set_font();
	}

set_font()
	{
/* Wouldn't it be nice if there were a font selector like the 
   file selector? (Volunteers?)  */
	int i,fontindex;
	char fontname[32];
	char *p = "BAGE09.FNT"; /* or should it be "Gemini 9"? */
	if (form_alert(2,"[1][Load BAGE09.FNT?][Yes|No]") == 2) 
		return;
	for (i=0;i<fonts_loaded;i++)
		{
		/* find the font */
		fontindex = vqt_name(handle,i,fontname);
		if(strnicmp(p,fontname,strlen(p))== 0)
			{		
			/* select the font */
			vst_font(handle,fontindex);
			/* set the point size */
			vst_point(handle,9,&char_w, &char_h, &box_w, &box_h);
			return;
			}
		}
	}
		
 ----
 Steve Yelvington, Marine on St. Croix, Minnesota, USA / steve@thelake.mn.org

Julian F. Reschke <ONM07@DMSWWU1A.BITNET> (05/31/91)

In article <A1987909308@thelake.mn.org>, steve@thelake.mn.org (Steve Yelvington)
says:
>
>I'm having trouble figuring out how to use an alternate font
>to draw text in a GEM window. I presume I need to check for
>the existence of GDOS before calling vst_load_fonts, but
>how? [...]
>
>
>open_vwork()
>        {
>        int i;
>        char tmpln[80];
>        handle = graf_handle( &char_w, &char_h, &box_w, &box_h);
>        for( i=0; i<10; work_in[i++] = 1 );
>        work_in[10] = 2;
>        v_opnvwk( work_in, &handle, work_out);
>        fonts_loaded = work_out[10];
>        sprintf(tmpln,"[1][There are %d|fonts available][OK]",fonts_loaded);
>        form_alert(1,tmpln);
>/* note: it tells me I have one font available */
>        fonts_loaded =  vst_load_fonts(handle,2);
>/* BOOM! Three big ones and we go no further */

(1) make it: fonts_loaded += vst_load_fonts (handle, ...); You get the
    number of _additional_ fonts.
(2) call vq_gdos() first
(3) No, I really don't know what the problem could be.

>        sprintf(tmpln,"[1][After vst_load_fonts,|there are %d|fonts
>available][OK]",fonts_loaded);
>        form_alert(1,tmpln);
>        if (fonts_loaded > 1)
>                set_font();
>        }
>
>set_font()
>        {
>/* Wouldn't it be nice if there were a font selector like the
>   file selector? (Volunteers?)  */
>        int i,fontindex;
>        char fontname[32];
>        char *p = "BAGE09.FNT"; /* or should it be "Gemini 9"? */

No, it should be 'Gemini'! The font comes in several point sizes, but the
font id is always the same.

>        if (form_alert(2,"[1][Load BAGE09.FNT?][Yes|No]") == 2)
>                return;
>        for (i=0;i<fonts_loaded;i++)
>                {
>                /* find the font */
>                fontindex = vqt_name(handle,i,fontname);
>                if(strnicmp(p,fontname,strlen(p))== 0)
>                        {
>                        /* select the font */
>                        vst_font(handle,fontindex);
>                        /* set the point size */
>                        vst_point(handle,9,&char_w, &char_h, &box_w, &box_h);
>                        return;
>                        }
>                }
>        }
>
> ----
> Steve Yelvington, Marine on St. Croix, Minnesota, USA / steve@thelake.mn.org
___________________________ cut here _____________________________________
Julian F. Reschke, Hensenstr. 142, D-4400 Muenster, Phone: ++49 251 861241
fast eMail: ONM07@DMSWWU1A.BITNET,    slow: jr@ms.maus.de (++49 251 77216)
____________________ correct me if I'm wrong _____________________________

bjoern@drdhh.hanse.de (Bjoern Kriews) (06/03/91)

From article <A1987909308@thelake.mn.org>, by steve@thelake.mn.org (Steve Yelvington):
> 	fonts_loaded =  vst_load_fonts(handle,2);
> /* BOOM! Three big ones and we go no further */

I think you should use 0 instead of 2 because the parameter 'select' is
reserved in Atari-GEM and has to be zero.

I've once written a 'Device Info' program in Turbo-C - you give a device
number from assign.sys - if the devno is equivalent to the value returned 
by graf_handle() it will open a virtual workstation otherwise it'll load
the driver for a physical one. The program checks for GDOS available and
decides whether to open phys_wk/load_fonts or not. It also prints a font-
list. Be aware: Some drivers (printer, plotter...) use different values
for non-existent or default fonts, the tests performed in di.c are not 
taken from any documentation, they ayre just what I figured out.

It uses a Turbo-C library function called vq_gdos() which is official and
implemented as follows:

vq_gdos:
	MOVEQ.L   #-$02,D0
	TRAP      #2
	ADDQ.W    #2,D0
	RTS

I append the source for this little program because I think it is of
general interest:

/*
 *	device info - display information about vdi devices / Turbo-C 2.00
 *	Note: GEM arrays don't hae to be declared when using TC
 *
 *	ANY NOTES, TIPS, HINTS, BUGS, BUGFIXES -> bjoern@drdhh.hanse.de
 *  thanks
 */

#include <vdi.h>
#include <aes.h>
#include <stdio.h>

main(void)
{
	int 	gh,h,i,dev,ret;
  int 	in[11],out[57];
  int		p[10],numfnt;
	char 	fnt[32];

	appl_init();

	gh=h=graf_handle(&i,&i,&i,&i);

	printf("Enter device number: ");
	scanf("%d\n",&dev);

	if(dev!=gh) 
		{
			if(!vq_gdos())
				{
					printf("Can't open physical workstations without GDOS\n");
					appl_exit();
					return 1;
				}
		}

  in[0]=dev;  
  for(i=1;i<10;in[i++]=1);
  	in[10] = 2;

  (dev==gh ? v_opnvwk : v_opnwk)(in,&h,out);

  if(!h)
  	{
    	printf("can't open workstation\n");
      appl_exit(); 
			return 1;
    }

	printf("Handle is %d\n",h);
	printf("Physical Resolution is %u * %u, %d colors\n",
	out[0]+1,out[1]+1,out[13]);
	printf("Pixels are %d um * %d um\n",out[3],out[4]); 	

	if(vq_gdos())
		{
			printf("Loading fonts...\n");
			numfnt=vst_load_fonts(h,0);
			printf("Loaded %d font%s.\n",numfnt,numfnt==1 ? "" : "s");


			printf("Available fonts:\n");
			for(i=1;i<=numfnt+1;++i)
				{
					ret=vqt_name(h,i,fnt);

					if(!(i>1 && (ret==1 || ret==-1)))
						printf("%2d. ID %3d Name: %-32.32s\n",i,ret,fnt);
				}

			vst_unload_fonts(h,0);
		}
	else
		printf("No fonts without GDOS\n");

  (dev==gh ? v_clsvwk : v_clswk)(h);  
  appl_exit();
  return 0;
}
    
Hope that helps, 
	Bjoern   

---
bjoern@drdhh.hanse.de = Bjoern Kriews / Stormsweg 6 / 2000 Hamburg 76 / FRG
"gaaga mahwe Bjoern urgl ufzae Turbo-C bnub"     (J. Willamowius)