2 Copyright © 1995-2007, The AROS Development Team. All rights reserved.
5 Desc: Diskfont function OpenDiskFont()
10 #include <graphics/text.h>
11 #include <proto/dos.h>
12 #include <proto/utility.h>
13 #include <proto/graphics.h>
14 #include "diskfont_intern.h"
16 #include <aros/debug.h>
19 /*****************************************************************************
22 #include <clib/diskfont_protos.h>
24 AROS_LH1(struct TextFont
*, OpenDiskFont
,
27 AROS_LHA(struct TextAttr
*, textAttr
, A0
),
30 struct Library
*, DiskfontBase
, 5, Diskfont
)
33 Tries to open the font specified by textAttr. If the font has allready
34 been loaded into memory, it will be opened with OpenFont(). Otherwise
35 OpenDiskFont() will try to load it from disk.
38 textAttr - Description of the font to load. If the textAttr->ta_Style
39 FSF_TAGGED bit is set, it will be treated as a struct TTextAttr.
43 Pointer to a struct TextFont on success, 0 on failure.
55 Internally now the WeighTAMatch function is used to find the best
56 font match. In OS 3.0 and above this graphics function is made
57 private to the library. So in the future maybe this function can
58 be replaced by a more flexible internal mechanism.
60 *****************************************************************************/
64 WORD match_weight
= 0, new_match_weight
;
66 BOOL bestinmemory
= TRUE
;
67 struct TTextAttr
*ttait
;
68 struct TextFont
*tf
= NULL
;
69 STRPTR filepart
= FilePart(textAttr
->ta_Name
), wholename
= textAttr
->ta_Name
;
70 ULONG len
= strlen(filepart
);
72 if (len
>5 && strcasecmp(filepart
+len
-5,".font")==0)
75 D(bug("OpenDiskFont(textAttr=%p)\n", textAttr
));
76 D(bug("Name %s YSize %ld Style 0x%lx Flags 0x%lx\n",
82 /* Check if font is in memory, ignore path */
83 textAttr
->ta_Name
= filepart
;
85 tf
= OpenFont(textAttr
);
88 struct TTextAttr tattr
;
90 tattr
.tta_Name
= tf
->tf_Message
.mn_Node
.ln_Name
;
91 tattr
.tta_YSize
= tf
->tf_YSize
;
92 tattr
.tta_Style
= tf
->tf_Style
;
93 tattr
.tta_Flags
= tf
->tf_Flags
;
94 if (ExtendFont(tf
, NULL
))
96 tattr
.tta_Tags
= TFE(tf
->tf_Extension
)->tfe_Tags
;
97 if (tattr
.tta_Tags
) tattr
.tta_Style
|= FSF_TAGGED
;
100 tattr
.tta_Tags
= NULL
;
102 match_weight
= WeighTAMatch(textAttr
,
103 (struct TextAttr
*)&tattr
,
106 D(bug("OpenDiskFont: Found font in memory weight(%d)\n", match_weight
));
109 D(bug("OpenDiskFont: No font found in memory\n"));
111 textAttr
->ta_Name
= wholename
;
113 if (match_weight
!=MAXFONTMATCHWEIGHT
)
115 iterator
= DF_IteratorInit((struct TTextAttr
*)textAttr
, DFB(DiskfontBase
));
116 if (iterator
== NULL
)
117 D(bug("OpenDiskFont: Error initializing Diskfont Iterator\n"));
120 while ((ttait
= DF_IteratorGetNext(iterator
, DFB(DiskfontBase
)))!=NULL
)
122 ULONG len2
= strlen(ttait
->tta_Name
) - 5;
124 D(bug("OpenDiskFont: Checking font: %s(%d)\n", ttait
->tta_Name
, ttait
->tta_YSize
));
126 D(bug("len: %d len2: %d\n", len
, len2
));
128 if ((len
== len2
) && (strncasecmp(ttait
->tta_Name
, filepart
, len
) == 0))
130 new_match_weight
= WeighTAMatch(textAttr
,
131 (struct TextAttr
*)ttait
,
134 if (new_match_weight
> match_weight
)
136 match_weight
= new_match_weight
;
137 DF_IteratorRemember(iterator
, DFB(DiskfontBase
));
138 bestinmemory
= FALSE
;
139 D(bug("Better weight (%d)\n", match_weight
));
142 D(bug("No better weight (%d)\n", new_match_weight
));
144 if (match_weight
==MAXFONTMATCHWEIGHT
)
149 /* Best still in memory then open this font, otherwise load from disk */
154 tf
= DF_IteratorRememberOpen(iterator
, DFB(DiskfontBase
));
156 DF_IteratorFree(iterator
, DFB(DiskfontBase
));
162 D(bug("extend font\n"));
163 if (ExtendFont(tf
, NULL
))
165 /* FIXME: Check if this is correct for this case */
166 TFE(tf
->tf_Extension
)->tfe_Flags0
|= TE0F_NOREMFONT
;
170 ReturnPtr("OpenDiskFont", struct TextFont
*, tf
);