Don't call InvertPixelArray with negative width and/or height.
[tangerine.git] / workbench / c / SetDefaultFont.c
blob7b9805f6756b937e6ca64badff8bdc7081633569
1 /*
2 Copyright © 1995-2001, 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
21 Workbench:C
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 <stdio.h>
65 #include <string.h>
66 #include <stdlib.h>
68 static const char version[] = "$VER: SetDefaultFont 41.0 (01.02.2001)\n";
70 #define ARG_TEMPLATE "FONTNAME/A,FONTSIZE/N/A,SCREEN/S"
72 enum
74 ARG_FONTNAME = 0,
75 ARG_FONTSIZE,
76 ARG_SCREEN,
77 NOOFARGS
80 static struct RDArgs *myargs;
81 static IPTR args[NOOFARGS];
82 static char s[256];
83 static char *fontname;
84 static LONG fontsize;
85 static BOOL screenfont;
87 static void Cleanup(char *msg, WORD rc)
89 if (msg)
91 printf("SetDefaultFont: %s\n",msg);
94 if (myargs)
96 FreeArgs(myargs);
99 exit(rc);
102 int GfxBase_version = 0;
103 int IntuitionBase_version = 0;
104 int DiskFontBase_version = 0;
106 static void GetArguments(void)
108 if (!(myargs = ReadArgs(ARG_TEMPLATE, args, 0)))
110 Fault(IoErr(), 0, s, 255);
111 Cleanup(s, RETURN_FAIL);
114 fontname = (char *)args[ARG_FONTNAME];
115 fontsize = *(IPTR *)args[ARG_FONTSIZE];
116 screenfont = args[ARG_SCREEN] ? TRUE : FALSE;
119 static void Action(void)
121 struct TextAttr ta;
122 struct TextFont *font;
124 strcpy(s, fontname);
125 if (!strstr(fontname, ".font")) strcat(s, ".font");
127 ta.ta_Name = s;
128 ta.ta_YSize = fontsize;
129 ta.ta_Style = 0;
130 ta.ta_Flags = 0;
132 font = OpenDiskFont(&ta);
133 if (!font)
135 Cleanup("Can't open font!", 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_ERROR);
151 Forbid();
152 GfxBase->DefaultFont = font;
153 Permit();
157 int main(void)
159 GetArguments();
160 Action();
161 Cleanup(0, RETURN_OK);
163 return 0;