Updated PCI IDs to latest snapshot.
[tangerine.git] / workbench / libs / muimaster / font.c
blobee50584ac841c20afb1e718bd8d460477f0edb12
1 /*
2 Copyright © 2003, The AROS Development Team. All rights reserved.
3 $Id$
4 */
6 #include <string.h>
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"
15 #include "font.h"
16 #include "prefs.h"
18 /* #define MYDEBUG 1 */
19 #include "debug.h"
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, LONG preset)
29 struct MUI_GlobalInfo *mgi;
30 struct MUI_RenderInfo *mri;
32 if ((preset <= MUIV_Font_Inherit) && (preset >= MUIV_Font_NegCount))
34 CONST_STRPTR name;
36 mri = muiRenderInfo(obj);
37 /* font already loaded, just return it */
38 if (mri->mri_Fonts[-preset])
40 D(bug("zune_font_get : return mri_Fonts[%d]=%lx\n",
41 preset, mri->mri_Fonts[-preset]));
42 return mri->mri_Fonts[-preset];
45 mgi = muiGlobalInfo(obj);
46 /* font name given, load it */
47 name = mgi->mgi_Prefs->fonts[-preset];
48 D(bug("zune_font_get : preset=%d, name=%s\n", preset, name));
49 if (name != NULL && name[0] != 0)
51 struct TextAttr ta;
52 if ((ta.ta_Name = (char*)AllocVec(strlen(name)+10,0)))
54 char *p;
55 LONG size;
57 strcpy(ta.ta_Name,name);
58 StrToLong(FilePart(ta.ta_Name),&size);
59 ta.ta_YSize = size;
60 ta.ta_Style = 0;
61 ta.ta_Flags = 0;
63 if ((p = PathPart(ta.ta_Name)))
64 strcpy(p,".font");
65 D(bug("zune_font_get : OpenDiskFont(%s)\n",
66 ta.ta_Name));
67 mri->mri_Fonts[-preset] = OpenDiskFont(&ta);
69 FreeVec(ta.ta_Name);
73 else /* fallback to window normal font */
75 if (preset != MUIV_Font_Normal && preset != MUIV_Font_Fixed) /* avoid infinite recursion */
77 /* dont do this, would result in the font being closed more than once */
78 /* return (mri->mri_Fonts[-preset] = zune_font_get(obj, MUIV_Font_Normal)); */
79 return zune_font_get(obj, MUIV_Font_Normal);
83 /* no font loaded, fallback to screen font or system font */
84 if (!mri->mri_Fonts[-preset])
86 if (MUIV_Font_Normal == preset)
88 struct TextAttr scr_attr;
89 scr_attr = *(_screen(obj)->Font);
90 scr_attr.ta_Flags = 0;
91 D(bug("zune_font_get : OpenDiskFont(%s) (screen font)\n", scr_attr.ta_Name));
92 mri->mri_Fonts[-preset] = OpenDiskFont(&scr_attr);
94 else /* MUIV_Font_Fixed */
96 struct TextAttr def_attr;
97 def_attr.ta_Name = GfxBase->DefaultFont->tf_Message.mn_Node.ln_Name;
98 def_attr.ta_YSize = GfxBase->DefaultFont->tf_YSize;
99 def_attr.ta_Style = GfxBase->DefaultFont->tf_Style;
100 def_attr.ta_Flags = GfxBase->DefaultFont->tf_Flags;
101 D(bug("zune_font_get : OpenDiskFont(%s) (system font)\n", def_attr.ta_Name));
102 mri->mri_Fonts[-preset] = OpenDiskFont(&def_attr);
105 return mri->mri_Fonts[-preset];
107 return (struct TextFont *)preset;