Hint added.
[AROS.git] / workbench / c / SetDefaultFont.c
blob7a4965b098b558c278ee21bddce49de8101462c3
1 /*
2 Copyright © 1995-2011, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc:
6 Lang: English
7 */
9 /******************************************************************************
11 NAME
13 SetDefaultFont
15 SYNOPSIS
17 FONTNAME/A,FONTSIZE/N/A,SCREEN/S
19 LOCATION
23 FUNCTION
25 Set the default system/screen Font
27 INPUTS
29 FONTNAME -- the name of the font
30 FONTSIZE -- the size of the font
31 SCREEN -- if specified set the default screen font otherwise
32 set the default system font.
34 RESULT
36 NOTES
37 The default system font must be mono spaced (non-proportional)
39 EXAMPLE
41 SetDefaultFont ttcourier 12
43 BUGS
45 SEE ALSO
47 INTERNALS
49 HISTORY
51 ******************************************************************************/
54 #include <exec/exec.h>
55 #include <dos/dos.h>
56 #include <graphics/gfxbase.h>
57 #include <graphics/text.h>
58 #include <proto/exec.h>
59 #include <proto/dos.h>
60 #include <proto/graphics.h>
61 #include <proto/intuition.h>
62 #include <proto/diskfont.h>
64 #include <string.h>
66 const TEXT version[] = "$VER: SetDefaultFont 41.1 (1.2.2001)\n";
68 #define ARG_TEMPLATE "FONTNAME/A,FONTSIZE/N/A,SCREEN/S"
70 enum
72 ARG_FONTNAME = 0,
73 ARG_FONTSIZE,
74 ARG_SCREEN,
75 NOOFARGS
78 static struct RDArgs *myargs;
79 static IPTR args[NOOFARGS];
80 static char s[256];
81 static char *fontname;
82 static LONG fontsize;
83 static BOOL screenfont;
85 static void Cleanup(char *msg)
87 if (msg)
89 Printf("SetDefaultFont: %s\n",msg);
92 if (myargs)
94 FreeArgs(myargs);
98 int GfxBase_version = 0;
99 int IntuitionBase_version = 0;
100 int DiskFontBase_version = 0;
102 static ULONG GetArguments(void)
104 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
106 Fault(IoErr(), 0, s, 255);
107 Cleanup(s);
108 return RETURN_FAIL;
111 fontname = (char *)args[ARG_FONTNAME];
112 fontsize = *(IPTR *)args[ARG_FONTSIZE];
113 screenfont = args[ARG_SCREEN] ? TRUE : FALSE;
115 return 0;
118 static ULONG Action(void)
120 struct TextAttr ta;
121 struct TextFont *font;
123 strcpy(s, fontname);
124 if (!strstr(fontname, ".font")) strcat(s, ".font");
126 ta.ta_Name = s;
127 ta.ta_YSize = fontsize;
128 ta.ta_Style = 0;
129 ta.ta_Flags = 0;
131 font = OpenDiskFont(&ta);
132 if (!font)
134 Cleanup("Can't open font!");
135 return RETURN_FAIL;
138 if (screenfont)
140 SetDefaultScreenFont(font);
142 else
144 if (font->tf_Flags & FPF_PROPORTIONAL)
146 CloseFont(font);
147 Cleanup("The font must be mono spaced (non-proportional)!");
148 return RETURN_ERROR;
151 Forbid();
152 GfxBase->DefaultFont = font;
153 Permit();
156 return 0;
159 int main(void)
161 int rc;
163 rc = GetArguments();
164 if (rc)
165 return rc;
167 rc = Action();
168 if (rc)
169 return rc;
171 Cleanup(0);
172 return 0;