1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285
|
/****************************************************************************}
{* *}
{* The FreeType project - a Free and Portable Quality TrueType Renderer. *}
{* *}
{* Copyright 1996-1999 by *}
{* D. Turner, R.Wilhelm, and W. Lemberg *}
{* *}
{* fdebug : A very simple TrueType bytecode debugger. *}
{* *}
{* NOTE : You must compile the interpreter with the DEBUG_INTERPRETER *}
{* macro defined in order to link this program! *}
{* *}
{****************************************************************************/
#include <math.h> /* libc ANSI */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "freetype.h"
#include "tttypes.h"
#include "ttdebug.h"
#include "ttobjs.h"
#ifdef UNIX
#ifndef HAVE_POSIX_TERMIOS
#include <sys/ioctl.h>
#include <termio.h>
#else
#ifndef HAVE_TCGETATTR
#define HAVE_TCGETATTR
#endif /* HAVE_TCGETATTR */
#ifndef HAVE_TCSETATTR
#define HAVE_TCSETATTR
#endif /* HAVE_TCSETATTR */
#include <termios.h>
#endif /* HAVE_POSIX_TERMIOS */
#endif
/* MAGIC: This variable is only defined in ttinterp.c if the */
/* macro DEBUG_INTERPRETER is set. It specifies the code */
/* range to debug. By default, it is TT_CodeRange_Glyph. */
/* */
extern
int debug_coderange;
#define Font_Buff_Size 256000 /* this buffer holds all */
/* font specific data. */
TT_Engine engine;
TT_Face face;
TT_Instance instance;
TT_Glyph glyph;
TT_Error error;
TT_Face_Properties properties;
int num_glyphs;
int ptsize;
Int Fail;
Int Num;
int mode = 2;
unsigned char autorun;
/*********************************************************************
*
* Usage : print usage message
*
*********************************************************************/
static
void Usage( const char* execname )
{
TT_Message( "fdebug: a simple TrueType bytecode debugger - part of the FreeType project\n" );
TT_Message( "--------------------------------------------------------------------------\n\n");
TT_Message( "Usage: %s glyphnum ppem fontname[.ttf]\n", execname );
TT_Message( " or %s --cvt ppem fontname[.ttf]\n", execname );
TT_Message( " or %s --font fontname[.ttf]\n\n", execname );
exit( EXIT_FAILURE );
}
/*********************************************************************
*
* Init_Keyboard : set the input file descriptor to char-by-char
* mode on Unix..
*
*********************************************************************/
#ifdef UNIX
struct termios old_termio;
static
void Init_Keyboard( void )
{
struct termios termio;
#ifndef HAVE_TCGETATTR
ioctl( 0, TCGETS, &old_termio );
#else
tcgetattr( 0, &old_termio );
#endif
termio = old_termio;
termio.c_lflag &= ~(ICANON+ECHO+ECHOE+ECHOK+ECHONL+ECHOKE);
#ifndef HAVE_TCSETATTR
ioctl( 0, TCSETS, &termio );
#else
tcsetattr( 0, TCSANOW, &termio );
#endif
}
static
void Reset_Keyboard( voi )
{
#ifndef HAVE_TCSETATTR
ioctl( 0, TCSETS, &old_termio );
#else
tcsetattr( 0, TCSANOW, &old_termio );
#endif
}
#else
static
void Init_Keyboard( void )
{
}
static
void Reset_Keyboard( voi )
{
}
#endif
static
void Print_Banner( void )
{
TT_Message( "fdebug - a simple TrueType bytecode debugger for FreeType\n" );
TT_Message( "------------------------------------------------------------\n" );
TT_Message( "type '?' for help - copyright 1996-1999 the FreeType Project\n\n" );
}
static
void Error( const char* message,
const char* filename )
{
static char tempstr[256];
sprintf( tempstr, "ERROR (%s): %s\n", filename, message );
TT_Message( tempstr );
sprintf( tempstr, " code = 0x%04lx\n", error );
TT_Message( tempstr );
Reset_Keyboard();
exit( EXIT_FAILURE );
}
static
void Init_Face( const char* filename )
{
error = TT_Init_FreeType(&engine);
if (error) Error( "could not initialise FreeType", filename );
/* open face object */
error = TT_Open_Face( engine, filename, &face );
if (error) Error( "could not find or open file", filename );
/* get properties */
TT_Get_Face_Properties( face, &properties );
num_glyphs = properties.num_Glyphs;
/* create instance */
error = TT_New_Instance( face, &instance );
if (error) Error( "could not create instance", filename );
error = TT_New_Glyph( face, &glyph );
if (error) Error( "could not create glyph container", filename );
TT_Set_Instance_Resolutions( instance, 96, 96 );
error = TT_Set_Instance_CharSize( instance, ptsize << 6 );
if (error) Error( "could not set text size", filename );
}
int main( int argc, char** argv )
{
int i;
char filename[128+4];
char* execname;
execname = argv[0];
if ( argc < 2 )
Usage( execname );
if ( strcmp( argv[1], "--font" ) == 0 )
{
debug_coderange = TT_CodeRange_Font;
mode = 0;
argc--;
argv++;
}
else if ( strcmp( argv[1], "--cvt" ) == 0 )
{
debug_coderange = TT_CodeRange_Cvt;
argv++;
argc--;
mode = 1;
}
else if ( sscanf( argv[1], "%d", &Num ) == 1 )
{
mode = 2;
argv++;
argc--;
}
else
Usage( execname );
/* read the point size for cvt and glyph modes */
if (mode > 0)
{
if ( sscanf( argv[1], "%d", &ptsize ) != 1 )
Usage( execname );
argc--;
argv++;
}
if ( argc != 2 )
Usage(execname);
i = strlen( argv[1] );
while ( i > 0 && argv[1][i] != '\\' )
{
if ( argv[1][i] == '.' )
i = 0;
i--;
}
filename[128] = 0;
strncpy( filename, argv[1], 128 );
if ( i >= 0 )
strncpy( filename + strlen(filename), ".ttf", 4 );
Init_Keyboard();
if (mode == 2)
{
Init_Face( filename );
Print_Banner();
error = TT_Load_Glyph( instance, glyph, Num, TTLOAD_DEFAULT );
if (error) Error( "Error during bytecode execution", filename );
}
else
{
Print_Banner();
Init_Face( filename );
}
TT_Done_FreeType(engine);
Reset_Keyboard();
exit( EXIT_SUCCESS ); /* for safety reasons */
return 0; /* never reached */
}
/* End */
|