New bitmap method SetRGBConversionFunction which can be used to
[tangerine.git] / workbench / libs / diskfont / availfonts.c
blobf6663bf2b663273572b94580f7b2a980e8bdd3cd
1 /*
2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Main fileof diskfont function AvailFonts()
6 Lang: english
7 */
10 #include "diskfont_intern.h"
11 #include <string.h>
13 #include <aros/debug.h>
15 /****************************************************************************/
17 struct BufferInfo
19 struct AvailFontsHeader *afh;
20 LONG space;
21 union {
22 struct TAvailFonts *taf;
23 struct AvailFonts *af;
24 } u;
25 UBYTE *endptr;
29 STATIC struct BufferInfo *BufferInfoCreate(STRPTR buffer, LONG bufBytes, BOOL tagged, struct DiskfontBase_intern *DiskfontBase);
30 STATIC VOID BufferInfoAdd(struct BufferInfo *bi, UWORD type, struct TTextAttr *tattr, BOOL tagged, struct DiskfontBase_intern *DiskfontBase);
31 STATIC VOID BufferInfoFree(struct BufferInfo *bi, struct DiskfontBase_intern *DiskfontBase);
33 /*****************************************************************************
35 NAME */
36 #include <clib/diskfont_protos.h>
38 AROS_LH3(LONG, AvailFonts,
40 /* SYNOPSIS */
41 AROS_LHA(STRPTR, buffer, A0),
42 AROS_LHA(LONG , bufBytes, D0),
43 AROS_LHA(LONG , flags, D1),
45 /* LOCATION */
46 struct Library *, DiskfontBase, 6, Diskfont)
48 /* FUNCTION
49 Fill the supplied buffer with info about the available fonts.
50 The buffer will after function execution first contains a
51 struct AvailFontsHeader, and then an array of struct AvailFonts
52 element (or TAvailFonts elements if AFF_TAGGED is specified in the
53 flags parameter). If the buffer is not big enough for the
54 descriptions than the additional length needed will be returned.
56 INPUTS
57 buffer - pointer to a buffer in which the font descriptions
58 should be placed.
60 bufBytes - size of the supplied buffer.
62 flags - flags telling what kind of fonts to load,
63 for example AFF_TAGGED for tagged fonts also,
64 AFF_MEMORY for fonts in memory, AFF_DISK for fonts
65 on disk.
67 RESULT
68 shortage - 0 if buffer was big enough or a number telling
69 how much additional place is needed.
71 NOTES
72 If the routine failes, then the afh_Numentries field
73 in the AvailFontsHeader will be 0.
75 EXAMPLE
77 BUGS
79 SEE ALSO
80 OpenDiskfont(), <diskfont/diskfont.h>
82 INTERNALS
84 HISTORY
85 27-11-96 digulla automatically created from
86 diskfont_lib.fd and clib/diskfont_protos.h
88 *****************************************************************************/
90 AROS_LIBFUNC_INIT
91 AROS_LIBBASE_EXT_DECL(struct Library *,DiskfontBase)
93 LONG retval = 0;
94 APTR iterator;
95 struct TTextAttr *attr;
96 BOOL tagged = (flags & AFF_TAGGED) ? TRUE : FALSE;
97 struct BufferInfo *bi;
99 D(bug("AvailFonts(buffer=%p, bufbytes=%d,flags=%d)\n", buffer, bufBytes, flags));
101 bi = BufferInfoCreate(buffer, bufBytes, tagged, DFB(DiskfontBase));
103 if (flags & AFF_MEMORY)
105 iterator = MF_IteratorInit(DFB(DiskfontBase));
106 while((attr = MF_IteratorGetNext(iterator, DFB(DiskfontBase)))!=NULL)
108 if ((!IS_SCALED_FONT(attr) || (flags & AFF_SCALED))
109 && !(IS_OUTLINE_FONT(attr) && (flags & AFF_BITMAP)))
111 #warning CHECKME
113 /* taf_Type only ever seems to contain one of AFF_MEMORY/AFF_DISK/AFF_SCALED,
114 but not a combination of these. */
115 UWORD type = IS_SCALED_FONT(attr) ? AFF_SCALED : AFF_MEMORY;
117 BufferInfoAdd(bi, type, attr, tagged, DFB(DiskfontBase));
120 MF_IteratorFree(iterator, DFB(DiskfontBase));
123 if (flags & AFF_DISK)
125 iterator = DF_IteratorInit(NULL, DFB(DiskfontBase));
126 while((attr = DF_IteratorGetNext(iterator, DFB(DiskfontBase)))!=NULL)
128 if ((!IS_SCALED_FONT(attr) || (flags & AFF_SCALED))
129 && !(IS_OUTLINE_FONT(attr) && (flags & AFF_BITMAP)))
131 #warning CHECKME
132 /* For disk fonts the type is always AFF_DISK ??? */
133 BufferInfoAdd(bi, AFF_DISK, attr, tagged, DFB(DiskfontBase));
136 DF_IteratorFree(iterator, DFB(DiskfontBase));
139 retval = bi->space>=0 ? 0 : -bi->space;
141 BufferInfoFree(bi, DFB(DiskfontBase));
143 ReturnInt ("AvailFonts", ULONG, retval);
145 AROS_LIBFUNC_EXIT
147 } /* AvailFonts */
150 /*****************************************************************************/
152 STATIC struct BufferInfo *BufferInfoCreate(STRPTR buffer, LONG bufBytes, BOOL tagged, struct DiskfontBase_intern *DiskfontBase)
154 struct BufferInfo *retval;
156 retval = (struct BufferInfo *)AllocMem(sizeof(struct BufferInfo), MEMF_ANY | MEMF_CLEAR);
157 if (retval != NULL)
159 retval->afh = (struct AvailFontsHeader *)buffer;
160 retval->afh->afh_NumEntries = 0;
161 retval->space = bufBytes-sizeof(struct AvailFontsHeader);
162 if (tagged)
163 retval->u.taf = (struct TAvailFonts *)(retval->afh+1);
164 else
165 retval->u.af = (struct AvailFonts *)(retval->afh+1);
166 retval->endptr = (UBYTE *)buffer + bufBytes;
169 return retval;
173 STATIC VOID BufferInfoAdd(struct BufferInfo *bi, UWORD type, struct TTextAttr *tattr, BOOL tagged, struct DiskfontBase_intern *DiskfontBase)
175 if (tagged && tattr->tta_Tags!=NULL)
176 bi->space -= sizeof(struct TAvailFonts) + strlen(tattr->tta_Name)+1 + NumTags(tattr->tta_Tags, DiskfontBase)*sizeof(struct TagItem);
177 else
178 bi->space -= sizeof(struct AvailFonts) + strlen(tattr->tta_Name)+1;
180 if (bi->space >= 0)
182 bi->endptr -= strlen(tattr->tta_Name)+1;
183 strcpy(bi->endptr, tattr->tta_Name);
185 if (tagged)
187 LONG size;
189 bi->u.taf->taf_Type = type;
190 bi->u.taf->taf_Attr.tta_Name = bi->endptr;
191 bi->u.taf->taf_Attr.tta_YSize = tattr->tta_YSize;
192 bi->u.taf->taf_Attr.tta_Style = tattr->tta_Style;
193 bi->u.taf->taf_Attr.tta_Flags = tattr->tta_Flags;
195 if (tattr->tta_Tags!=NULL)
197 size = NumTags(tattr->tta_Tags, DiskfontBase)*sizeof(struct TagItem);
198 bi->endptr -= size;
199 memcpy(bi->endptr, tattr->tta_Tags, size);
200 bi->u.taf->taf_Attr.tta_Tags = (struct TagItem *)bi->endptr;
202 else
203 bi->u.taf->taf_Attr.tta_Tags = NULL;
205 bi->u.taf++;
207 else
209 bi->u.af->af_Type = type;
210 bi->u.af->af_Attr.ta_Name = bi->endptr;
211 bi->u.af->af_Attr.ta_YSize = tattr->tta_YSize;
212 bi->u.af->af_Attr.ta_Style = tattr->tta_Style;
213 bi->u.af->af_Attr.ta_Flags = tattr->tta_Flags;
215 bi->u.af++;
218 bi->afh->afh_NumEntries++;
223 STATIC VOID BufferInfoFree(struct BufferInfo *bi, struct DiskfontBase_intern *DiskfontBase)
225 FreeMem(bi, sizeof(struct BufferInfo));
228 /*****************************************************************************/