/*
    (C) 1995-96 AROS - The Amiga Replacement OS
    $Id: listfonts.c,v 1.6 1997/07/29 07:30:05 digulla Exp $

    Desc: Demo/test of diskfont/AvailFonts()
    Lang: English.
*/


#include <proto/diskfont.h>
#include <proto/exec.h>
#include <diskfont/diskfont.h>
#include <exec/memory.h>
#include <stdio.h>

#include <proto/dos.h>

#define DEBUG 1
#include <aros/debug.h>

struct Library *DiskfontBase;

int main(int argc, char ** argv)
{
    ULONG afshortage;
    IPTR  pargs[2];

    struct AvailFontsHeader *afh;
    struct AvailFonts *afptr;

    /* Try to guess how many bytes are needed */
    ULONG afsize	= 10000;

    if (!(DiskfontBase = OpenLibrary("diskfont.library", 0L)))
    {
	VPrintf ("Couldn't open diskfont.library\n", NULL);
	return (RETURN_FAIL);
    }

    do
    {
	afh = (struct AvailFontsHeader *)AllocMem(afsize, MEMF_ANY);
	if (afh)
	{
	    afshortage = AvailFonts((STRPTR)afh, afsize, AFF_MEMORY|AFF_DISK);
	    if (afshortage)
	    {
		FreeMem(afh, afsize);
		afsize += afshortage;
		afh = (struct AvailFontsHeader*)(-1L);
	    }
	}
    } while (afshortage && afh);

    if (afh)
    {
	/* Print some info about the fonts */
	UWORD count;

	pargs[0] = afh->afh_NumEntries;
	VPrintf("Number of fonts found: %d\n", pargs);

	/* Get pointer to the first AvailFonts item */
	afptr = (struct AvailFonts*)&afh[1];

	for (count = afh->afh_NumEntries; count; count --)
	{
	    pargs[0] = (IPTR)afptr->af_Attr.ta_Name;
	    pargs[1] = afptr->af_Attr.ta_YSize;

	    VPrintf ("Font name: %-30.s Font YSize: %d\n", pargs);

	    afptr ++;
	}
    }

    CloseLibrary(DiskfontBase);
    return (RETURN_OK);
}
