muimaster.library: Area class will not eat wheel movement messages
[AROS.git] / workbench / libs / diskfont / availfonts.c
blob6ad9d3fbc8d506a1d9030fddfb9070dab1be3eca
1 /*
2 Copyright © 1995-2007, 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 *DiskfontBase);
30 STATIC VOID BufferInfoAdd(struct BufferInfo *bi, UWORD type, struct TTextAttr *tattr, BOOL tagged, struct DiskfontBase *DiskfontBase);
31 STATIC VOID BufferInfoFree(struct BufferInfo *bi, struct DiskfontBase *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
92 LONG retval = 0;
93 APTR iterator;
94 struct TTextAttr *attr;
95 BOOL tagged = (flags & AFF_TAGGED) ? TRUE : FALSE;
96 struct BufferInfo *bi;
98 D(bug("AvailFonts(buffer=%p, bufbytes=%d,flags=%d)\n", buffer, bufBytes, flags));
100 bi = BufferInfoCreate(buffer, bufBytes, tagged, DFB(DiskfontBase));
102 if (flags & AFF_MEMORY)
104 iterator = MF_IteratorInit(DFB(DiskfontBase));
105 while((attr = MF_IteratorGetNext(iterator, DFB(DiskfontBase)))!=NULL)
107 if ((!IS_SCALED_FONT(attr) || (flags & AFF_SCALED))
108 && !(IS_OUTLINE_FONT(attr) && (flags & AFF_BITMAP)))
110 /* TODO: CHECKME */
112 /* taf_Type only ever seems to contain one of AFF_MEMORY/AFF_DISK/AFF_SCALED,
113 but not a combination of these. */
114 UWORD type = IS_SCALED_FONT(attr) ? AFF_SCALED : AFF_MEMORY;
116 BufferInfoAdd(bi, type, attr, tagged, DFB(DiskfontBase));
119 MF_IteratorFree(iterator, DFB(DiskfontBase));
122 if (flags & AFF_DISK)
124 iterator = DF_IteratorInit(NULL, DFB(DiskfontBase));
125 while((attr = DF_IteratorGetNext(iterator, DFB(DiskfontBase)))!=NULL)
127 if ((!IS_SCALED_FONT(attr) || (flags & AFF_SCALED))
128 && !(IS_OUTLINE_FONT(attr) && (flags & AFF_BITMAP)))
130 /* TODO: CHECKME */
131 /* For disk fonts the type is always AFF_DISK ??? */
132 BufferInfoAdd(bi, AFF_DISK, attr, tagged, DFB(DiskfontBase));
135 DF_IteratorFree(iterator, DFB(DiskfontBase));
138 retval = bi->space>=0 ? 0 : -bi->space;
140 BufferInfoFree(bi, DFB(DiskfontBase));
142 ReturnInt ("AvailFonts", ULONG, retval);
144 AROS_LIBFUNC_EXIT
146 } /* AvailFonts */
149 /*****************************************************************************/
151 STATIC struct BufferInfo *BufferInfoCreate(STRPTR buffer, LONG bufBytes, BOOL tagged, struct DiskfontBase *DiskfontBase)
153 struct BufferInfo *retval;
155 retval = (struct BufferInfo *)AllocMem(sizeof(struct BufferInfo), MEMF_ANY | MEMF_CLEAR);
156 if (retval != NULL)
158 retval->afh = (struct AvailFontsHeader *)buffer;
159 retval->afh->afh_NumEntries = 0;
160 retval->space = bufBytes-sizeof(struct AvailFontsHeader);
161 if (tagged)
162 retval->u.taf = (struct TAvailFonts *)(retval->afh+1);
163 else
164 retval->u.af = (struct AvailFonts *)(retval->afh+1);
165 retval->endptr = (UBYTE *)buffer + bufBytes;
168 return retval;
172 STATIC VOID BufferInfoAdd(struct BufferInfo *bi, UWORD type, struct TTextAttr *tattr, BOOL tagged, struct DiskfontBase *DiskfontBase)
174 if (tagged && tattr->tta_Tags!=NULL)
175 bi->space -= sizeof(struct TAvailFonts) + strlen(tattr->tta_Name)+1 + NumTags(tattr->tta_Tags, DiskfontBase)*sizeof(struct TagItem);
176 else
177 bi->space -= sizeof(struct AvailFonts) + strlen(tattr->tta_Name)+1;
179 if (bi->space >= 0)
181 bi->endptr -= strlen(tattr->tta_Name)+1;
182 strcpy(bi->endptr, tattr->tta_Name);
184 if (tagged)
186 LONG size;
188 bi->u.taf->taf_Type = type;
189 bi->u.taf->taf_Attr.tta_Name = bi->endptr;
190 bi->u.taf->taf_Attr.tta_YSize = tattr->tta_YSize;
191 bi->u.taf->taf_Attr.tta_Style = tattr->tta_Style;
192 bi->u.taf->taf_Attr.tta_Flags = tattr->tta_Flags;
194 if (tattr->tta_Tags!=NULL)
196 size = NumTags(tattr->tta_Tags, DiskfontBase)*sizeof(struct TagItem);
197 bi->endptr -= size;
198 memcpy(bi->endptr, tattr->tta_Tags, size);
199 bi->u.taf->taf_Attr.tta_Tags = (struct TagItem *)bi->endptr;
201 else
202 bi->u.taf->taf_Attr.tta_Tags = NULL;
204 bi->u.taf++;
206 else
208 bi->u.af->af_Type = type;
209 bi->u.af->af_Attr.ta_Name = bi->endptr;
210 bi->u.af->af_Attr.ta_YSize = tattr->tta_YSize;
211 bi->u.af->af_Attr.ta_Style = tattr->tta_Style;
212 bi->u.af->af_Attr.ta_Flags = tattr->tta_Flags;
214 bi->u.af++;
217 bi->afh->afh_NumEntries++;
222 STATIC VOID BufferInfoFree(struct BufferInfo *bi, struct DiskfontBase *DiskfontBase)
224 FreeMem(bi, sizeof(struct BufferInfo));
227 /*****************************************************************************/