revert between 56095 -> 55830 in arch
[AROS.git] / workbench / c / SetDefaultFont.c
blob1d94e8cfbd54a800e82230d75a01bd910d4798d4
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 FreeArgs(myargs);
95 int GfxBase_version = 0;
96 int IntuitionBase_version = 0;
97 int DiskFontBase_version = 0;
99 static ULONG GetArguments(void)
101 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
103 Fault(IoErr(), 0, s, 255);
104 Cleanup(s);
105 return RETURN_FAIL;
108 fontname = (char *)args[ARG_FONTNAME];
109 fontsize = *(IPTR *)args[ARG_FONTSIZE];
110 screenfont = args[ARG_SCREEN] ? TRUE : FALSE;
112 return 0;
115 static ULONG Action(void)
117 struct TextAttr ta;
118 struct TextFont *font;
120 strcpy(s, fontname);
121 if (!strstr(fontname, ".font")) strcat(s, ".font");
123 ta.ta_Name = s;
124 ta.ta_YSize = fontsize;
125 ta.ta_Style = 0;
126 ta.ta_Flags = 0;
128 font = OpenDiskFont(&ta);
129 if (!font)
131 Cleanup("Can't open font!");
132 return RETURN_FAIL;
135 if (screenfont)
137 SetDefaultScreenFont(font);
139 else
141 if (font->tf_Flags & FPF_PROPORTIONAL)
143 CloseFont(font);
144 Cleanup("The font must be mono spaced (non-proportional)!");
145 return RETURN_ERROR;
148 Forbid();
149 GfxBase->DefaultFont = font;
150 Permit();
153 return 0;
156 int main(void)
158 int rc;
160 rc = GetArguments();
161 if (rc)
162 return rc;
164 rc = Action();
165 if (rc)
166 return rc;
168 Cleanup(0);
169 return 0;