46 #include FT_FREETYPE_H
51 #define forever for (;;)
59 #define GOOD_FONTS_DIR "/home/wl/freetype-testfonts"
93 unsigned int isbinary: 1;
94 unsigned int isascii: 1;
95 unsigned int ishex: 1;
163 for ( gid = 0; gid < face->
num_glyphs; ++gid )
192 fprintf( stderr,
"Can't initialize FreeType.\n" );
209 for ( i = 0; i <
num; ++
i )
228 if ( extensions ==
NULL )
231 pt = strrchr( filename,
'.' );
234 if ( pt < strrchr( filename,
'/' ) )
237 for ( i = 0; extensions[
i] !=
NULL; ++
i )
238 if ( strcasecmp( pt + 1, extensions[i] ) == 0 ||
239 strcasecmp( pt, extensions[i] ) == 0 )
252 item->isbinary = item->isascii = item->ishex =
false;
254 foo = fopen( item->name,
"rb" );
258 int ch1 = getc( foo );
259 int ch2 = getc( foo );
260 int ch3 = getc( foo );
261 int ch4 = getc( foo );
266 if ( ( ch1 == 0 && ch2 == 1 && ch3 == 0 && ch4 == 0 ) ||
267 ( ch1 ==
'O' && ch2 ==
'T' && ch3 ==
'T' && ch4 ==
'O' ) ||
268 ( ch1 ==
't' && ch2 ==
'r' && ch3 ==
'u' && ch4 ==
'e' ) ||
269 ( ch1 ==
't' && ch2 ==
't' && ch3 ==
'c' && ch4 ==
'f' ) )
272 item->isbinary =
true;
274 else if ( ch1 == 0x80 && ch2 ==
'\01' )
277 item->isbinary =
true;
279 else if ( ch1 ==
'%' && ch2 ==
'!' )
282 if ( strstr( item->name,
".pfa" ) !=
NULL ||
283 strstr( item->name,
".PFA" ) !=
NULL )
286 item->isascii =
true;
288 else if ( ch1 == 1 && ch2 == 0 && ch3 == 4 )
291 item->isbinary =
true;
293 else if ( ch1 ==
'S' && ch2 ==
'T' && ch3 ==
'A' && ch4 ==
'R' )
298 else if ( ch1 ==
'P' && ch2 ==
'F' && ch3 ==
'R' && ch4 ==
'0' )
301 item->isbinary =
true;
303 else if ( ( ch1 ==
'\1' && ch2 ==
'f' && ch3 ==
'c' && ch4 ==
'p' ) ||
304 ( ch1 ==
'M' && ch2 ==
'Z' ) )
307 item->isbinary =
true;
312 "Can't recognize file type of `%s', assuming binary\n",
314 item->isbinary =
true;
319 fprintf( stderr,
"Can't open `%s' for typing the file.\n",
321 item->isbinary =
true;
341 for ( i = 0; fontdirs[
i] !=
NULL; ++
i )
343 examples = opendir( fontdirs[i] );
344 if ( examples ==
NULL )
347 "Can't open example font directory `%s'\n",
352 while ( ( ent = readdir( examples ) ) !=
NULL )
354 snprintf( buffer,
sizeof ( buffer ),
355 "%s/%s", fontdirs[i], ent->d_name );
356 if ( stat( buffer, &statb ) == -1 || S_ISDIR( statb.st_mode ) )
358 if ( extensions ==
NULL ||
extmatch( buffer, extensions ) )
366 fprintf( stderr,
"Can't allocate memory\n" );
379 closedir( examples );
384 fprintf( stderr,
"Can't find matching font files.\n" );
406 if ( low - high < 0x10000L )
407 return low + ( ( random() >> 8 ) % ( high + 1 - low ) );
409 return low + ( random() % ( high + 1 -
low ) );
423 good = fopen( item->name,
"r" );
426 fprintf( stderr,
"Can't open `%s'\n", item->name );
430 new = fopen( newfont,
"w+" );
433 fprintf( stderr,
"Can't create temporary output file `%s'\n",
438 while ( ( len = fread( buffer, 1,
sizeof ( buffer ), good ) ) > 0 )
439 fwrite( buffer, 1, len,
new );
444 for ( i = 0; i < err_cnt; ++
i )
448 if ( item->isbinary )
450 else if ( item->isascii )
486 write( 2,
"Timeout... ", 11 );
494 static int test_num = 0;
498 sprintf( buffer,
"%s/test%d",
results_dir, test_num++ );
515 if ( WIFSIGNALED ( status ) )
516 printf(
"Error found in file `%s'\n", buffer );
522 fprintf( stderr,
"Can't fork test case.\n" );
534 fprintf( out,
"%s [options] -- Generate random erroneous fonts\n"
535 " and attempt to parse them with FreeType.\n\n", name );
537 fprintf( out,
" --all All non-directory files are assumed to be fonts.\n" );
538 fprintf( out,
" --check-outlines Make sure we can parse the outlines of each glyph.\n" );
539 fprintf( out,
" --dir <path> Append <path> to list of font search directories.\n" );
540 fprintf( out,
" --error-count <cnt> Introduce <cnt> single byte errors into each font.\n" );
541 fprintf( out,
" --error-fraction <frac> Introduce <frac>*filesize single byte errors\n"
542 " into each font.\n" );
543 fprintf( out,
" --ext <ext> Add <ext> to list of extensions indicating fonts.\n" );
544 fprintf( out,
" --help Print this.\n" );
545 fprintf( out,
" --nohints Turn off hinting.\n" );
546 fprintf( out,
" --rasterize Attempt to rasterize each glyph.\n" );
547 fprintf( out,
" --results <dir> Directory in which to place the test fonts.\n" );
548 fprintf( out,
" --size <float> Use the given font size for the tests.\n" );
549 fprintf( out,
" --test <file> Run a single test on an already existing file.\n" );
559 int dcnt = 0, ecnt = 0, rset =
false, allexts =
false;
562 char* testfile =
NULL;
565 dirs =
calloc( argc + 1,
sizeof (
char ** ) );
566 exts =
calloc( argc + 1,
sizeof (
char ** ) );
568 for ( i = 1; i < argc; ++
i )
571 if ( pt[0] ==
'-' && pt[1] ==
'-' )
574 if ( strcmp( pt,
"-all" ) == 0 )
576 else if ( strcmp( pt,
"-check-outlines" ) == 0 )
578 else if ( strcmp( pt,
"-dir" ) == 0 )
579 dirs[dcnt++] = argv[++
i];
580 else if ( strcmp( pt,
"-error-count" ) == 0 )
588 fprintf( stderr,
"Bad value for error-count: %s\n", argv[i] );
592 else if ( strcmp( pt,
"-error-fraction" ) == 0 )
600 fprintf( stderr,
"Bad value for error-fraction: %s\n", argv[i] );
604 else if ( strcmp( pt,
"-ext" ) == 0 )
605 exts[ecnt++] = argv[++
i];
606 else if ( strcmp( pt,
"-help" ) == 0 )
608 usage( stdout, argv[0] );
611 else if ( strcmp( pt,
"-nohints" ) == 0 )
613 else if ( strcmp( pt,
"-rasterize" ) == 0 )
615 else if ( strcmp( pt,
"-results" ) == 0 )
617 else if ( strcmp( pt,
"-size" ) == 0 )
622 fprintf( stderr,
"Bad value for size: %s\n", argv[i] );
626 else if ( strcmp( pt,
"-test" ) == 0 )
627 testfile = argv[++
i];
630 usage( stderr, argv[0] );
637 else if ( ecnt == 0 )
643 if ( testfile !=
NULL )
static int getRandom(int low, int high)
static int FT_CubicTo(const FT_Vector *cp1, const FT_Vector *cp2, const FT_Vector *to, void *user)
static int extmatch(char *filename, char **extensions)
static struct fontlist * fontlist
static int FT_MoveTo(const FT_Vector *to, void *user)
int main(int argc, char **argv)
char * strdup(const char *inStr)
static int getErrorCnt(struct fontlist *item)
static char * results_dir
static void TestFace(FT_Face face)
#define FT_LOAD_NO_HINTING
static void do_test(void)
static void ExecuteTest(char *testfont)
EGLImageKHR EGLint * name
FT_Init_FreeType(FT_Library *alibrary)
static void abort_test(int sig)
FT_Load_Glyph(FT_Face face, FT_UInt glyph_index, FT_Int32 load_flags)
EGLContext EGLenum EGLClientBuffer buffer
FT_Set_Char_Size(FT_Face face, FT_F26Dot6 char_width, FT_F26Dot6 char_height, FT_UInt horz_resolution, FT_UInt vert_resolution)
static int FT_LineTo(const FT_Vector *to, void *user)
#define ft_render_mode_normal
FT_Render_Glyph(FT_GlyphSlot slot, FT_Render_Mode render_mode)
FT_BEGIN_HEADER FT_Outline_Decompose(FT_Outline *outline, const FT_Outline_Funcs *func_interface, void *user)
static int error_fraction
static FT_F26Dot6 font_size
static int FT_ConicTo(const FT_Vector *_cp, const FT_Vector *to, void *user)
static char * default_ext_list[]
static char * default_dir_list[]
FT_New_Face(FT_Library library, const char *filepathname, FT_Long face_index, FT_Face *aface)
FT_Done_Face(FT_Face face)
static FT_Outline_Funcs outlinefuncs
static int check_outlines
#define FT_LOAD_NO_BITMAP
static void figurefiletype(struct fontlist *item)
#define FT_IS_SCALABLE(face)
GLsizeiptr const GLvoid GLenum usage
static void FindFonts(char **fontdirs, char **extensions)
static int copyfont(struct fontlist *item, char *newfont)