[Contents] [index] [Help] [Retrace] [browse <] [Browse >]

The diskfont.library function availfonts() fills in a memory area
designated by you with a list of all of the fonts available to the system.
AvailFonts() searches the AmigaDOS directory path currently assigned to
FONTS: and locates all available fonts.  If you haven't issued a DOS
Assign command to change the FONTS: directory path, it defaults to the
sys:fonts directory.

    LONG AvailFonts( struct AvailFontsHeader *mybuffer, LONG bufBytes,
                     LONG flags );

availfonts() fills in a memory area, mybuffer, which is bufbytes bytes
long, with an availfontsheader structure:

    struct AvailFontsHeader {
        UWORD   afh_NumEntries;      /* number of AvailFonts elements */
        /* struct AvailFonts afh_AF[], or struct TAvailFonts afh_TAF[]; */
    };

This structure is followed by an array of availfonts structures with the
number of entries in the array equal to afh_NumEntries:

    struct AvailFonts {
        UWORD   af_Type;            /* MEMORY, DISK, or SCALED */
        struct TextAttr af_Attr;    /* text attributes for font */
    };

Each availfonts structure describes a font available to the os.  the flags
field lets availfonts() know which fonts you want to hear about.  at
present, there are four possible flags:

AFF_MEMORY  Create AvailFonts structures for all textfont's currently in
            the system list.

AFF_DISK    Create AvailFonts structures for all textfont's that are
            currently available from disk.

AFF_SCALED  Create AvailFonts structures for textfont's that do not have
            their fpf_designed flag set.  if the aff_scaled flag is not
            present, availfonts() will not create availfonts structures
            for fonts that have been scaled, which do not have the
            FPF_DESIGNED flag set.

AFF_TAGGED  These AvailFonts structures are really tavailfonts structures.
            These structures were created for Release 2 to allow
            availfonts() to list tag values:

            struct TAvailFonts {
                UWORD   taf_Type;           /* MEMORY, DISK, or SCALED */
                struct TTextAttr taf_Attr;  /* text attributes for font */
            };

Notice that AFF_MEMORY and AFF_DISK are not mutually exclusive; a font
that is currently in memory may also be available for loading from disk.
In this case, the font will appear twice in the array of availfonts (or
TAvailFonts) structures.

If availfonts() fails without any major system problems, it will be
because the buffer for the availfontsheader structure was not big enough
to contain all of the AvailFonts or TAvailFonts structures.  In this case,
AvailFonts() returns the number of additional bytes that mybuffer needed
to contain all of the TAvailFonts or AvailFonts structures.  You can then
use that return value to figure out how big the buffer needs to be,
allocate that memory, and try AvailFonts() again:

int afShortage, afSize;
struct AvailFontsHeader *afh;
 . . .

    afSize = AvailFonts(afh, 0L, AFF_MEMORY|AFF_DISK|AFF_SCALED|
                                                     AFF_TAGGED);
    do
    {
        afh = (struct AvailFontsHeader *) AllocMem(afSize, 0);
        if (afh)
        {
            afShortage = AvailFonts(afh, afSize, AFF_MEMORY|AFF_DISK|
                                                 AFF_SCALED|AFF_TAGGED);
            if (afShortage)
            {
                FreeMem(afh, afSize);
                afSize += afShortage;
            }
        }
        else
        {
            fail("AllocMem of AvailFonts buffer afh failed\n");
            break;
        }
    } while (afShortage); /* if (afh) non-zero here, then:             */
                          /* 1. it points to a valid AvailFontsHeader, */
                          /* 2. it must have FreeMem(afh, afSize)      */
                          /* called for it after use. */

The following code, AvailFonts.c, uses availfonts() to find out what fonts
are available to the system.  It uses this information to open every
available font (one at a time), print some information about the font
(including the ta_devicedpi tag values if they are present), and renders a
sample of the font into a clipping region.

     availfonts.c