Tabs to spaces, more consistent formatting.
[AROS.git] / workbench / libs / muimaster / font.c
blobac336693e3d6c77a3da5d05b60379638c19c8b9f
1 /*
2 Copyright © 2003-2011, 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, 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))
36 CONST_STRPTR name;
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)
53 struct TextAttr ta;
54 if ((ta.ta_Name = (char *)AllocVec(strlen(name) + 10, 0)))
56 char *p;
57 LONG size;
59 strcpy(ta.ta_Name, name);
60 StrToLong(FilePart(ta.ta_Name), &size);
61 ta.ta_YSize = size;
62 ta.ta_Style = 0;
63 ta.ta_Flags = 0;
65 if ((p = PathPart(ta.ta_Name)))
66 strcpy(p, ".font");
67 D(bug("zune_font_get : OpenDiskFont(%s)\n", ta.ta_Name));
68 mri->mri_Fonts[-preset] = OpenDiskFont(&ta);
70 FreeVec(ta.ta_Name);
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",
95 scr_attr.ta_Name));
96 mri->mri_Fonts[-preset] = OpenDiskFont(&scr_attr);
98 else /* MUIV_Font_Fixed */
100 struct TextAttr def_attr;
101 def_attr.ta_Name =
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",
107 def_attr.ta_Name));
108 mri->mri_Fonts[-preset] = OpenDiskFont(&def_attr);
111 return mri->mri_Fonts[-preset];
113 return (struct TextFont *)font;