2 Copyright © 2003-2011, The AROS Development Team. All rights reserved.
7 #include <exec/types.h>
8 #include <clib/alib_protos.h>
9 #include <proto/exec.h>
10 #include <proto/diskfont.h>
11 #include <proto/dos.h>
12 #include <proto/graphics.h>
14 #include "muimaster_intern.h"
18 /* #define MYDEBUG 1 */
21 extern struct Library
*MUIMasterBase
;
23 /* Returns a given text font, if necessary it opens the font.
24 * Must be called after Area's MUIM_Setup.
27 struct TextFont
*zune_font_get(Object
*obj
, IPTR font
)
29 struct MUI_GlobalInfo
*mgi
;
30 struct MUI_RenderInfo
*mri
;
31 SIPTR preset
= (SIPTR
) font
;
33 if ((preset
<= (SIPTR
) MUIV_Font_Inherit
)
34 && (preset
>= (SIPTR
) MUIV_Font_NegCount
))
38 mri
= muiRenderInfo(obj
);
39 /* font already loaded, just return it */
40 if (mri
->mri_Fonts
[-preset
])
42 D(bug("zune_font_get : return mri_Fonts[%d]=%lx\n",
43 preset
, mri
->mri_Fonts
[-preset
]));
44 return mri
->mri_Fonts
[-preset
];
47 mgi
= muiGlobalInfo(obj
);
48 /* font name given, load it */
49 name
= mgi
->mgi_Prefs
->fonts
[-preset
];
50 D(bug("zune_font_get : preset=%d, name=%s\n", preset
, name
));
51 if (name
!= NULL
&& name
[0] != 0)
54 if ((ta
.ta_Name
= (char *)AllocVec(strlen(name
) + 10, 0)))
59 strcpy(ta
.ta_Name
, name
);
60 StrToLong(FilePart(ta
.ta_Name
), &size
);
65 if ((p
= PathPart(ta
.ta_Name
)))
67 D(bug("zune_font_get : OpenDiskFont(%s)\n", ta
.ta_Name
));
68 mri
->mri_Fonts
[-preset
] = OpenDiskFont(&ta
);
74 else /* fallback to window normal font */
76 /* avoid infinite recursion */
77 if (preset
!= (SIPTR
) MUIV_Font_Normal
&& preset
78 != (SIPTR
) MUIV_Font_Fixed
)
80 /* don't do this, would result in the font being closed more than once */
81 /* return (mri->mri_Fonts[-preset] = zune_font_get(obj, MUIV_Font_Normal)); */
82 return zune_font_get(obj
, MUIV_Font_Normal
);
86 /* no font loaded, fallback to screen font or system font */
87 if (!mri
->mri_Fonts
[-preset
])
89 if ((SIPTR
) MUIV_Font_Normal
== preset
)
91 struct TextAttr scr_attr
;
92 scr_attr
= *(_screen(obj
)->Font
);
93 scr_attr
.ta_Flags
= 0;
94 D(bug("zune_font_get : OpenDiskFont(%s) (screen font)\n",
96 mri
->mri_Fonts
[-preset
] = OpenDiskFont(&scr_attr
);
98 else /* MUIV_Font_Fixed */
100 struct TextAttr def_attr
;
102 GfxBase
->DefaultFont
->tf_Message
.mn_Node
.ln_Name
;
103 def_attr
.ta_YSize
= GfxBase
->DefaultFont
->tf_YSize
;
104 def_attr
.ta_Style
= GfxBase
->DefaultFont
->tf_Style
;
105 def_attr
.ta_Flags
= GfxBase
->DefaultFont
->tf_Flags
;
106 D(bug("zune_font_get : OpenDiskFont(%s) (system font)\n",
108 mri
->mri_Fonts
[-preset
] = OpenDiskFont(&def_attr
);
111 return mri
->mri_Fonts
[-preset
];
113 return (struct TextFont
*)font
;