2 Copyright © 1995-2001, The AROS Development Team. All rights reserved.
5 Desc: Main fileof diskfont function AvailFonts()
10 #include "diskfont_intern.h"
13 #include <aros/debug.h>
15 /****************************************************************************/
19 struct AvailFontsHeader
*afh
;
22 struct TAvailFonts
*taf
;
23 struct AvailFonts
*af
;
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 /*****************************************************************************
36 #include <clib/diskfont_protos.h>
38 AROS_LH3(LONG
, AvailFonts
,
41 AROS_LHA(STRPTR
, buffer
, A0
),
42 AROS_LHA(LONG
, bufBytes
, D0
),
43 AROS_LHA(LONG
, flags
, D1
),
46 struct Library
*, DiskfontBase
, 6, Diskfont
)
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.
57 buffer - pointer to a buffer in which the font descriptions
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
68 shortage - 0 if buffer was big enough or a number telling
69 how much additional place is needed.
72 If the routine failes, then the afh_Numentries field
73 in the AvailFontsHeader will be 0.
80 OpenDiskfont(), <diskfont/diskfont.h>
85 27-11-96 digulla automatically created from
86 diskfont_lib.fd and clib/diskfont_protos.h
88 *****************************************************************************/
91 AROS_LIBBASE_EXT_DECL(struct Library
*,DiskfontBase
)
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
)))
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
)))
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
);
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
);
159 retval
->afh
= (struct AvailFontsHeader
*)buffer
;
160 retval
->afh
->afh_NumEntries
= 0;
161 retval
->space
= bufBytes
-sizeof(struct AvailFontsHeader
);
163 retval
->u
.taf
= (struct TAvailFonts
*)(retval
->afh
+1);
165 retval
->u
.af
= (struct AvailFonts
*)(retval
->afh
+1);
166 retval
->endptr
= (UBYTE
*)buffer
+ bufBytes
;
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
);
178 bi
->space
-= sizeof(struct AvailFonts
) + strlen(tattr
->tta_Name
)+1;
182 bi
->endptr
-= strlen(tattr
->tta_Name
)+1;
183 strcpy(bi
->endptr
, tattr
->tta_Name
);
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
);
199 memcpy(bi
->endptr
, tattr
->tta_Tags
, size
);
200 bi
->u
.taf
->taf_Attr
.tta_Tags
= (struct TagItem
*)bi
->endptr
;
203 bi
->u
.taf
->taf_Attr
.tta_Tags
= NULL
;
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
;
218 bi
->afh
->afh_NumEntries
++;
223 STATIC VOID
BufferInfoFree(struct BufferInfo
*bi
, struct DiskfontBase_intern
*DiskfontBase
)
225 FreeMem(bi
, sizeof(struct BufferInfo
));
228 /*****************************************************************************/