1 /****************************************************************************}
3 {* The FreeType project - a Free and Portable Quality TrueType Renderer. *}
5 {* Copyright 1996-1999 by *}
6 {* D. Turner, R.Wilhelm, and W. Lemberg *}
8 {* fdebug : A very simple TrueType bytecode debugger. *}
10 {* NOTE : You must compile the interpreter with the DEBUG_INTERPRETER *}
11 {* macro defined in order to link this program! *}
13 {****************************************************************************/
15 #include <math.h> /* libc ANSI */
27 #ifndef HAVE_POSIX_TERMIOS
28 #include <sys/ioctl.h>
31 #ifndef HAVE_TCGETATTR
32 #define HAVE_TCGETATTR
33 #endif /* HAVE_TCGETATTR */
34 #ifndef HAVE_TCSETATTR
35 #define HAVE_TCSETATTR
36 #endif /* HAVE_TCSETATTR */
38 #endif /* HAVE_POSIX_TERMIOS */
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. */
49 #define Font_Buff_Size 256000 /* this buffer holds all */
50 /* font specific data. */
58 TT_Face_Properties properties
;
66 unsigned char autorun
;
68 /*********************************************************************
70 * Usage : print usage message
72 *********************************************************************/
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
);
86 /*********************************************************************
88 * Init_Keyboard : set the input file descriptor to char-by-char
91 *********************************************************************/
95 struct termios old_termio
;
98 void Init_Keyboard( void )
100 struct termios termio
;
103 #ifndef HAVE_TCGETATTR
104 ioctl( 0, TCGETS
, &old_termio
);
106 tcgetattr( 0, &old_termio
);
111 termio
.c_lflag
&= ~(ICANON
+ECHO
+ECHOE
+ECHOK
+ECHONL
+ECHOKE
);
113 #ifndef HAVE_TCSETATTR
114 ioctl( 0, TCSETS
, &termio
);
116 tcsetattr( 0, TCSANOW
, &termio
);
121 void Reset_Keyboard( voi
)
123 #ifndef HAVE_TCSETATTR
124 ioctl( 0, TCSETS
, &old_termio
);
126 tcsetattr( 0, TCSANOW
, &old_termio
);
134 void Init_Keyboard( void )
139 void Reset_Keyboard( voi
)
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" );
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
);
167 exit( EXIT_FAILURE
);
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
);
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
)
202 char filename
[128+4];
210 if ( strcmp( argv
[1], "--font" ) == 0 )
212 debug_coderange
= TT_CodeRange_Font
;
217 else if ( strcmp( argv
[1], "--cvt" ) == 0 )
219 debug_coderange
= TT_CodeRange_Cvt
;
224 else if ( sscanf( argv
[1], "%d", &Num
) == 1 )
233 /* read the point size for cvt and glyph modes */
236 if ( sscanf( argv
[1], "%d", &ptsize
) != 1 )
245 i
= strlen( argv
[1] );
246 while ( i
> 0 && argv
[1][i
] != '\\' )
248 if ( argv
[1][i
] == '.' )
255 strncpy( filename
, argv
[1], 128 );
257 strncpy( filename
+ strlen(filename
), ".ttf", 4 );
263 Init_Face( filename
);
266 error
= TT_Load_Glyph( instance
, glyph
, Num
, TTLOAD_DEFAULT
);
267 if (error
) Error( "Error during bytecode execution", filename
);
272 Init_Face( filename
);
275 TT_Done_FreeType(engine
);
279 exit( EXIT_SUCCESS
); /* for safety reasons */
281 return 0; /* never reached */