contrib/OWB: add correct SDL dependency, fix compilers used
[AROS-Contrib.git] / freetype1 / test / fdebug.c
blob31025ba6bc397713186905a9a26edcbb20ebb29e
1 /****************************************************************************}
2 {* *}
3 {* The FreeType project - a Free and Portable Quality TrueType Renderer. *}
4 {* *}
5 {* Copyright 1996-1999 by *}
6 {* D. Turner, R.Wilhelm, and W. Lemberg *}
7 {* *}
8 {* fdebug : A very simple TrueType bytecode debugger. *}
9 {* *}
10 {* NOTE : You must compile the interpreter with the DEBUG_INTERPRETER *}
11 {* macro defined in order to link this program! *}
12 {* *}
13 {****************************************************************************/
15 #include <math.h> /* libc ANSI */
16 #include <stdio.h>
17 #include <stdlib.h>
18 #include <string.h>
20 #include "freetype.h"
21 #include "tttypes.h"
22 #include "ttdebug.h"
23 #include "ttobjs.h"
26 #ifdef UNIX
27 #ifndef HAVE_POSIX_TERMIOS
28 #include <sys/ioctl.h>
29 #include <termio.h>
30 #else
31 #ifndef HAVE_TCGETATTR
32 #define HAVE_TCGETATTR
33 #endif /* HAVE_TCGETATTR */
34 #ifndef HAVE_TCSETATTR
35 #define HAVE_TCSETATTR
36 #endif /* HAVE_TCSETATTR */
37 #include <termios.h>
38 #endif /* HAVE_POSIX_TERMIOS */
39 #endif
41 /* MAGIC: This variable is only defined in ttinterp.c if the */
42 /* macro DEBUG_INTERPRETER is set. It specifies the code */
43 /* range to debug. By default, it is TT_CodeRange_Glyph. */
44 /* */
45 extern
46 int debug_coderange;
49 #define Font_Buff_Size 256000 /* this buffer holds all */
50 /* font specific data. */
52 TT_Engine engine;
53 TT_Face face;
54 TT_Instance instance;
55 TT_Glyph glyph;
56 TT_Error error;
58 TT_Face_Properties properties;
60 int num_glyphs;
61 int ptsize;
63 Int Fail;
64 Int Num;
65 int mode = 2;
66 unsigned char autorun;
68 /*********************************************************************
70 * Usage : print usage message
72 *********************************************************************/
74 static
75 void Usage( const char* execname )
77 TT_Message( "fdebug: a simple TrueType bytecode debugger - part of the FreeType project\n" );
78 TT_Message( "--------------------------------------------------------------------------\n\n");
79 TT_Message( "Usage: %s glyphnum ppem fontname[.ttf]\n", execname );
80 TT_Message( " or %s --cvt ppem fontname[.ttf]\n", execname );
81 TT_Message( " or %s --font fontname[.ttf]\n\n", execname );
82 exit( EXIT_FAILURE );
86 /*********************************************************************
88 * Init_Keyboard : set the input file descriptor to char-by-char
89 * mode on Unix..
91 *********************************************************************/
93 #ifdef UNIX
95 struct termios old_termio;
97 static
98 void Init_Keyboard( void )
100 struct termios termio;
103 #ifndef HAVE_TCGETATTR
104 ioctl( 0, TCGETS, &old_termio );
105 #else
106 tcgetattr( 0, &old_termio );
107 #endif
109 termio = old_termio;
111 termio.c_lflag &= ~(ICANON+ECHO+ECHOE+ECHOK+ECHONL+ECHOKE);
113 #ifndef HAVE_TCSETATTR
114 ioctl( 0, TCSETS, &termio );
115 #else
116 tcsetattr( 0, TCSANOW, &termio );
117 #endif
120 static
121 void Reset_Keyboard( voi )
123 #ifndef HAVE_TCSETATTR
124 ioctl( 0, TCSETS, &old_termio );
125 #else
126 tcsetattr( 0, TCSANOW, &old_termio );
127 #endif
131 #else
133 static
134 void Init_Keyboard( void )
138 static
139 void Reset_Keyboard( voi )
143 #endif
145 static
146 void Print_Banner( void )
148 TT_Message( "fdebug - a simple TrueType bytecode debugger for FreeType\n" );
149 TT_Message( "------------------------------------------------------------\n" );
150 TT_Message( "type '?' for help - copyright 1996-1999 the FreeType Project\n\n" );
154 static
155 void Error( const char* message,
156 const char* filename )
158 static char tempstr[256];
160 sprintf( tempstr, "ERROR (%s): %s\n", filename, message );
161 TT_Message( tempstr );
163 sprintf( tempstr, " code = 0x%04lx\n", error );
164 TT_Message( tempstr );
166 Reset_Keyboard();
167 exit( EXIT_FAILURE );
171 static
172 void Init_Face( const char* filename )
174 error = TT_Init_FreeType(&engine);
175 if (error) Error( "could not initialise FreeType", filename );
177 /* open face object */
178 error = TT_Open_Face( engine, filename, &face );
179 if (error) Error( "could not find or open file", filename );
181 /* get properties */
182 TT_Get_Face_Properties( face, &properties );
183 num_glyphs = properties.num_Glyphs;
185 /* create instance */
186 error = TT_New_Instance( face, &instance );
187 if (error) Error( "could not create instance", filename );
189 error = TT_New_Glyph( face, &glyph );
190 if (error) Error( "could not create glyph container", filename );
192 TT_Set_Instance_Resolutions( instance, 96, 96 );
194 error = TT_Set_Instance_CharSize( instance, ptsize << 6 );
195 if (error) Error( "could not set text size", filename );
199 int main( int argc, char** argv )
201 int i;
202 char filename[128+4];
203 char* execname;
206 execname = argv[0];
207 if ( argc < 2 )
208 Usage( execname );
210 if ( strcmp( argv[1], "--font" ) == 0 )
212 debug_coderange = TT_CodeRange_Font;
213 mode = 0;
214 argc--;
215 argv++;
217 else if ( strcmp( argv[1], "--cvt" ) == 0 )
219 debug_coderange = TT_CodeRange_Cvt;
220 argv++;
221 argc--;
222 mode = 1;
224 else if ( sscanf( argv[1], "%d", &Num ) == 1 )
226 mode = 2;
227 argv++;
228 argc--;
230 else
231 Usage( execname );
233 /* read the point size for cvt and glyph modes */
234 if (mode > 0)
236 if ( sscanf( argv[1], "%d", &ptsize ) != 1 )
237 Usage( execname );
238 argc--;
239 argv++;
242 if ( argc != 2 )
243 Usage(execname);
245 i = strlen( argv[1] );
246 while ( i > 0 && argv[1][i] != '\\' )
248 if ( argv[1][i] == '.' )
249 i = 0;
250 i--;
253 filename[128] = 0;
255 strncpy( filename, argv[1], 128 );
256 if ( i >= 0 )
257 strncpy( filename + strlen(filename), ".ttf", 4 );
259 Init_Keyboard();
261 if (mode == 2)
263 Init_Face( filename );
264 Print_Banner();
266 error = TT_Load_Glyph( instance, glyph, Num, TTLOAD_DEFAULT );
267 if (error) Error( "Error during bytecode execution", filename );
269 else
271 Print_Banner();
272 Init_Face( filename );
275 TT_Done_FreeType(engine);
277 Reset_Keyboard();
279 exit( EXIT_SUCCESS ); /* for safety reasons */
281 return 0; /* never reached */
285 /* End */