2 Copyright © 1995-2007, 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 *****************************************************************************/
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
)))
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
)))
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
);
149 /*****************************************************************************/
151 STATIC
struct BufferInfo
*BufferInfoCreate(STRPTR buffer
, LONG bufBytes
, BOOL tagged
, struct DiskfontBase_intern
*DiskfontBase
)
153 struct BufferInfo
*retval
;
155 retval
= (struct BufferInfo
*)AllocMem(sizeof(struct BufferInfo
), MEMF_ANY
| MEMF_CLEAR
);
158 retval
->afh
= (struct AvailFontsHeader
*)buffer
;
159 retval
->afh
->afh_NumEntries
= 0;
160 retval
->space
= bufBytes
-sizeof(struct AvailFontsHeader
);
162 retval
->u
.taf
= (struct TAvailFonts
*)(retval
->afh
+1);
164 retval
->u
.af
= (struct AvailFonts
*)(retval
->afh
+1);
165 retval
->endptr
= (UBYTE
*)buffer
+ bufBytes
;
172 STATIC VOID
BufferInfoAdd(struct BufferInfo
*bi
, UWORD type
, struct TTextAttr
*tattr
, BOOL tagged
, struct DiskfontBase_intern
*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
);
177 bi
->space
-= sizeof(struct AvailFonts
) + strlen(tattr
->tta_Name
)+1;
181 bi
->endptr
-= strlen(tattr
->tta_Name
)+1;
182 strcpy(bi
->endptr
, tattr
->tta_Name
);
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
);
198 memcpy(bi
->endptr
, tattr
->tta_Tags
, size
);
199 bi
->u
.taf
->taf_Attr
.tta_Tags
= (struct TagItem
*)bi
->endptr
;
202 bi
->u
.taf
->taf_Attr
.tta_Tags
= NULL
;
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
;
217 bi
->afh
->afh_NumEntries
++;
222 STATIC VOID
BufferInfoFree(struct BufferInfo
*bi
, struct DiskfontBase_intern
*DiskfontBase
)
224 FreeMem(bi
, sizeof(struct BufferInfo
));
227 /*****************************************************************************/