misc/libfreetype/src/tools/ftrandom/ftrandom.c
author koda
Mon, 25 Apr 2011 01:46:54 +0200
changeset 5172 88f2e05288ba
permissions -rw-r--r--
aaand let's add freetype as well while we are at it other smaller changes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
5172
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     1
/* Copyright (C) 2005, 2007, 2008 by George Williams */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     2
/*
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     3
 * Redistribution and use in source and binary forms, with or without
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     4
 * modification, are permitted provided that the following conditions are met:
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     5
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     6
 * Redistributions of source code must retain the above copyright notice, this
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     7
 * list of conditions and the following disclaimer.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     8
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
     9
 * Redistributions in binary form must reproduce the above copyright notice,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    10
 * this list of conditions and the following disclaimer in the documentation
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    11
 * and/or other materials provided with the distribution.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    12
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    13
 * The name of the author may not be used to endorse or promote products
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    14
 * derived from this software without specific prior written permission.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    15
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    16
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    17
 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    18
 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    19
 * EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    20
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    21
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    22
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    23
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    24
 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    25
 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    26
 */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    27
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    28
/* modified by Werner Lemberg <wl@gnu.org>       */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    29
/* This file is now part of the FreeType library */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    30
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    31
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    32
#include <stdio.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    33
#include <stdlib.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    34
#include <string.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    35
#include <strings.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    36
#include <sys/types.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    37
#include <sys/stat.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    38
#include <sys/wait.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    39
#include <unistd.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    40
#include <dirent.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    41
#include <math.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    42
#include <signal.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    43
#include <time.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    44
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    45
#include <ft2build.h>
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    46
#include FT_FREETYPE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    47
#include FT_OUTLINE_H
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    48
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    49
#define true     1
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    50
#define false    0
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    51
#define forever  for (;;)
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    52
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    53
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    54
  static int    check_outlines = false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    55
  static int    nohints        = false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    56
  static int    rasterize      = false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    57
  static char*  results_dir    = "results";
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    58
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    59
#define GOOD_FONTS_DIR  "/home/wl/freetype-testfonts"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    60
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    61
  static char*  default_dir_list[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    62
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    63
    GOOD_FONTS_DIR,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    64
    NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    65
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    66
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    67
  static char*  default_ext_list[] =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    68
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    69
    "ttf",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    70
    "otf",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    71
    "ttc",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    72
    "cid",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    73
    "pfb",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    74
    "pfa",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    75
    "bdf",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    76
    "pcf",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    77
    "pfr",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    78
    "fon",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    79
    "otb",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    80
    "cff",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    81
    NULL
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    82
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    83
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    84
  static int  error_count    = 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    85
  static int  error_fraction = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    86
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    87
  static FT_F26Dot6  font_size = 12 * 64;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    88
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    89
  static struct fontlist
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    90
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    91
    char*         name;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    92
    int           len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    93
    unsigned int  isbinary: 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    94
    unsigned int  isascii: 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    95
    unsigned int  ishex: 1;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    96
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    97
  } *fontlist;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    98
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
    99
  static int  fcnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   100
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   101
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   102
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   103
  FT_MoveTo( const FT_Vector  *to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   104
             void             *user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   105
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   106
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   107
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   108
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   109
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   110
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   111
  FT_LineTo( const FT_Vector  *to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   112
             void             *user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   113
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   114
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   115
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   116
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   117
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   118
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   119
  FT_ConicTo( const FT_Vector  *_cp,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   120
              const FT_Vector  *to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   121
              void             *user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   122
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   123
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   124
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   125
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   126
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   127
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   128
  FT_CubicTo( const FT_Vector  *cp1,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   129
              const FT_Vector  *cp2,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   130
              const FT_Vector  *to,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   131
              void             *user )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   132
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   133
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   134
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   135
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   136
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   137
  static FT_Outline_Funcs outlinefuncs =
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   138
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   139
    FT_MoveTo,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   140
    FT_LineTo,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   141
    FT_ConicTo,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   142
    FT_CubicTo,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   143
    0, 0          /* No shift, no delta */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   144
  };
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   145
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   146
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   147
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   148
  TestFace( FT_Face  face )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   149
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   150
    int  gid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   151
    int  load_flags = FT_LOAD_DEFAULT;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   152
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   153
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   154
    if ( check_outlines         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   155
         FT_IS_SCALABLE( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   156
      load_flags = FT_LOAD_NO_BITMAP;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   157
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   158
    if ( nohints )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   159
      load_flags |= FT_LOAD_NO_HINTING;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   160
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   161
    FT_Set_Char_Size( face, 0, font_size, 72, 72 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   162
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   163
    for ( gid = 0; gid < face->num_glyphs; ++gid )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   164
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   165
      if ( check_outlines         &&
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   166
           FT_IS_SCALABLE( face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   167
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   168
        if ( !FT_Load_Glyph( face, gid, load_flags ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   169
          FT_Outline_Decompose( &face->glyph->outline, &outlinefuncs, NULL );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   170
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   171
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   172
        FT_Load_Glyph( face, gid, load_flags );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   173
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   174
      if ( rasterize )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   175
        FT_Render_Glyph( face->glyph, ft_render_mode_normal );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   176
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   177
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   178
    FT_Done_Face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   179
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   180
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   181
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   182
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   183
  ExecuteTest( char*  testfont )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   184
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   185
    FT_Library  context;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   186
    FT_Face     face;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   187
    int         i, num;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   188
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   189
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   190
    if ( FT_Init_FreeType( &context ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   191
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   192
      fprintf( stderr, "Can't initialize FreeType.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   193
      exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   194
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   195
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   196
    if ( FT_New_Face( context, testfont, 0, &face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   197
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   198
      /* The font is erroneous, so if this fails that's ok. */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   199
      exit( 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   200
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   201
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   202
    if ( face->num_faces == 1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   203
      TestFace( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   204
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   205
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   206
      num = face->num_faces;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   207
      FT_Done_Face( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   208
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   209
      for ( i = 0; i < num; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   210
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   211
        if ( !FT_New_Face( context, testfont, i, &face ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   212
          TestFace( face );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   213
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   214
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   215
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   216
    exit( 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   217
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   218
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   219
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   220
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   221
  extmatch( char*   filename,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   222
            char**  extensions )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   223
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   224
    int    i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   225
    char*  pt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   226
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   227
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   228
    if ( extensions == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   229
      return true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   230
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   231
    pt = strrchr( filename, '.' );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   232
    if ( pt == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   233
      return false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   234
    if ( pt < strrchr( filename, '/' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   235
      return false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   236
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   237
    for ( i = 0; extensions[i] != NULL; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   238
      if ( strcasecmp( pt + 1, extensions[i] ) == 0 ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   239
           strcasecmp( pt,     extensions[i] ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   240
        return true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   241
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   242
    return false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   243
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   244
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   245
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   246
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   247
  figurefiletype( struct fontlist*  item )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   248
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   249
    FILE*  foo;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   250
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   251
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   252
    item->isbinary = item->isascii = item->ishex = false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   253
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   254
    foo = fopen( item->name, "rb" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   255
    if ( foo != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   256
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   257
      /* Try to guess the file type from the first few characters... */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   258
      int  ch1 = getc( foo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   259
      int  ch2 = getc( foo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   260
      int  ch3 = getc( foo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   261
      int  ch4 = getc( foo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   262
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   263
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   264
      fclose( foo );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   265
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   266
      if ( ( ch1 == 0   && ch2 == 1   && ch3 == 0   && ch4 == 0   ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   267
           ( ch1 == 'O' && ch2 == 'T' && ch3 == 'T' && ch4 == 'O' ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   268
           ( ch1 == 't' && ch2 == 'r' && ch3 == 'u' && ch4 == 'e' ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   269
           ( ch1 == 't' && ch2 == 't' && ch3 == 'c' && ch4 == 'f' ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   270
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   271
        /* ttf, otf, ttc files */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   272
        item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   273
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   274
      else if ( ch1 == 0x80 && ch2 == '\01' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   275
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   276
        /* PFB header */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   277
        item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   278
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   279
      else if ( ch1 == '%' && ch2 == '!' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   280
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   281
        /* Random PostScript */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   282
        if ( strstr( item->name, ".pfa" ) != NULL ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   283
             strstr( item->name, ".PFA" ) != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   284
          item->ishex = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   285
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   286
          item->isascii = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   287
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   288
      else if ( ch1 == 1 && ch2 == 0 && ch3 == 4 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   289
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   290
        /* Bare CFF */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   291
        item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   292
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   293
      else if ( ch1 == 'S' && ch2 == 'T' && ch3 == 'A' && ch4 == 'R' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   294
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   295
        /* BDF */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   296
        item->ishex = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   297
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   298
      else if ( ch1 == 'P' && ch2 == 'F' && ch3 == 'R' && ch4 == '0' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   299
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   300
        /* PFR */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   301
        item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   302
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   303
      else if ( ( ch1 == '\1' && ch2 == 'f' && ch3 == 'c' && ch4 == 'p' ) ||
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   304
                ( ch1 == 'M'  && ch2 == 'Z' )                             )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   305
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   306
        /* Windows FON */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   307
        item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   308
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   309
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   310
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   311
        fprintf( stderr,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   312
                 "Can't recognize file type of `%s', assuming binary\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   313
                 item->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   314
        item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   315
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   316
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   317
    else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   318
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   319
      fprintf( stderr, "Can't open `%s' for typing the file.\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   320
               item->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   321
      item->isbinary = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   322
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   323
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   324
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   325
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   326
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   327
  FindFonts( char**  fontdirs,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   328
             char**  extensions )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   329
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   330
    DIR*            examples;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   331
    struct dirent*  ent;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   332
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   333
    int             i, max;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   334
    char            buffer[1025];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   335
    struct stat     statb;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   336
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   337
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   338
    max  = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   339
    fcnt = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   340
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   341
    for ( i = 0; fontdirs[i] != NULL; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   342
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   343
      examples = opendir( fontdirs[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   344
      if ( examples == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   345
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   346
        fprintf( stderr,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   347
                 "Can't open example font directory `%s'\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   348
                 fontdirs[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   349
        exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   350
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   351
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   352
      while ( ( ent = readdir( examples ) ) != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   353
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   354
        snprintf( buffer, sizeof ( buffer ),
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   355
                  "%s/%s", fontdirs[i], ent->d_name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   356
        if ( stat( buffer, &statb ) == -1 || S_ISDIR( statb.st_mode ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   357
          continue;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   358
        if ( extensions == NULL || extmatch( buffer, extensions ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   359
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   360
          if ( fcnt >= max )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   361
          {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   362
            max += 100;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   363
            fontlist = realloc( fontlist, max * sizeof ( struct fontlist ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   364
            if ( fontlist == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   365
            {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   366
              fprintf( stderr, "Can't allocate memory\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   367
              exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   368
            }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   369
          }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   370
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   371
          fontlist[fcnt].name = strdup( buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   372
          fontlist[fcnt].len  = statb.st_size;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   373
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   374
          figurefiletype( &fontlist[fcnt] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   375
          ++fcnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   376
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   377
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   378
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   379
      closedir( examples );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   380
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   381
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   382
    if ( fcnt == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   383
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   384
      fprintf( stderr, "Can't find matching font files.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   385
      exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   386
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   387
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   388
    fontlist[fcnt].name = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   389
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   390
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   391
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   392
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   393
  getErrorCnt( struct fontlist*  item )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   394
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   395
    if ( error_count == 0 && error_fraction == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   396
      return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   397
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   398
    return error_count + ceil( error_fraction * item->len );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   399
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   400
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   401
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   402
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   403
  getRandom( int  low,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   404
             int  high )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   405
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   406
    if ( low - high < 0x10000L )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   407
      return low + ( ( random() >> 8 ) % ( high + 1 - low ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   408
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   409
    return low + ( random() % ( high + 1 - low ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   410
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   411
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   412
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   413
  static int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   414
  copyfont( struct fontlist*  item,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   415
            char*             newfont )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   416
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   417
    static char  buffer[8096];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   418
    FILE         *good, *new;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   419
    int          len;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   420
    int          i, err_cnt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   421
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   422
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   423
    good = fopen( item->name, "r" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   424
    if ( good == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   425
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   426
      fprintf( stderr, "Can't open `%s'\n", item->name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   427
      return false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   428
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   429
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   430
    new = fopen( newfont, "w+" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   431
    if ( new == NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   432
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   433
      fprintf( stderr, "Can't create temporary output file `%s'\n",
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   434
               newfont );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   435
      exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   436
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   437
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   438
    while ( ( len = fread( buffer, 1, sizeof ( buffer ), good ) ) > 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   439
      fwrite( buffer, 1, len, new );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   440
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   441
    fclose( good );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   442
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   443
    err_cnt = getErrorCnt( item );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   444
    for ( i = 0; i < err_cnt; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   445
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   446
      fseek( new, getRandom( 0, item->len - 1 ), SEEK_SET );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   447
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   448
      if ( item->isbinary )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   449
        putc( getRandom( 0, 0xff ), new );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   450
      else if ( item->isascii )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   451
        putc( getRandom( 0x20, 0x7e ), new );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   452
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   453
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   454
        int  hex = getRandom( 0, 15 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   455
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   456
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   457
        if ( hex < 10 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   458
          hex += '0';
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   459
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   460
          hex += 'A' - 10;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   461
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   462
        putc( hex, new );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   463
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   464
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   465
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   466
    if ( ferror( new ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   467
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   468
      fclose( new );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   469
      unlink( newfont );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   470
      return false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   471
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   472
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   473
    fclose( new );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   474
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   475
    return true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   476
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   477
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   478
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   479
  static int  child_pid;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   480
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   481
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   482
  abort_test( int  sig )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   483
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   484
    /* If a time-out happens, then kill the child */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   485
    kill( child_pid, SIGFPE );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   486
    write( 2, "Timeout... ", 11 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   487
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   488
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   489
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   490
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   491
  do_test( void )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   492
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   493
    int         i        = getRandom( 0, fcnt - 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   494
    static int  test_num = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   495
    char        buffer[1024];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   496
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   497
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   498
    sprintf( buffer, "%s/test%d", results_dir, test_num++ );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   499
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   500
    if ( copyfont ( &fontlist[i], buffer ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   501
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   502
      signal( SIGALRM, abort_test );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   503
      /* Anything that takes more than 20 seconds */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   504
      /* to parse and/or rasterize is an error.   */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   505
      alarm( 20 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   506
      if ( ( child_pid = fork() ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   507
        ExecuteTest( buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   508
      else if ( child_pid != -1 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   509
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   510
        int  status;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   511
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   512
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   513
        waitpid( child_pid, &status, 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   514
        alarm( 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   515
        if ( WIFSIGNALED ( status ) )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   516
          printf( "Error found in file `%s'\n", buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   517
        else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   518
          unlink( buffer );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   519
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   520
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   521
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   522
        fprintf( stderr, "Can't fork test case.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   523
        exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   524
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   525
      alarm( 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   526
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   527
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   528
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   529
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   530
  static void
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   531
  usage( FILE*  out,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   532
         char*  name )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   533
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   534
    fprintf( out, "%s [options] -- Generate random erroneous fonts\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   535
                  "  and attempt to parse them with FreeType.\n\n", name );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   536
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   537
    fprintf( out, "  --all                    All non-directory files are assumed to be fonts.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   538
    fprintf( out, "  --check-outlines         Make sure we can parse the outlines of each glyph.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   539
    fprintf( out, "  --dir <path>             Append <path> to list of font search directories.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   540
    fprintf( out, "  --error-count <cnt>      Introduce <cnt> single byte errors into each font.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   541
    fprintf( out, "  --error-fraction <frac>  Introduce <frac>*filesize single byte errors\n"
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   542
                  "                           into each font.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   543
    fprintf( out, "  --ext <ext>              Add <ext> to list of extensions indicating fonts.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   544
    fprintf( out, "  --help                   Print this.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   545
    fprintf( out, "  --nohints                Turn off hinting.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   546
    fprintf( out, "  --rasterize              Attempt to rasterize each glyph.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   547
    fprintf( out, "  --results <dir>          Directory in which to place the test fonts.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   548
    fprintf( out, "  --size <float>           Use the given font size for the tests.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   549
    fprintf( out, "  --test <file>            Run a single test on an already existing file.\n" );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   550
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   551
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   552
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   553
  int
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   554
  main( int     argc,
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   555
        char**  argv )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   556
  {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   557
    char    **dirs, **exts;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   558
    char    *pt, *end;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   559
    int     dcnt = 0, ecnt = 0, rset = false, allexts = false;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   560
    int     i;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   561
    time_t  now;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   562
    char*   testfile = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   563
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   564
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   565
    dirs = calloc( argc + 1, sizeof ( char ** ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   566
    exts = calloc( argc + 1, sizeof ( char ** ) );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   567
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   568
    for ( i = 1; i < argc; ++i )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   569
    {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   570
      pt = argv[i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   571
      if ( pt[0] == '-' && pt[1] == '-' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   572
        ++pt;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   573
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   574
      if ( strcmp( pt, "-all" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   575
        allexts = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   576
      else if ( strcmp( pt, "-check-outlines" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   577
        check_outlines = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   578
      else if ( strcmp( pt, "-dir" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   579
        dirs[dcnt++] = argv[++i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   580
      else if ( strcmp( pt, "-error-count" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   581
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   582
        if ( !rset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   583
          error_fraction = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   584
        rset = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   585
        error_count = strtol( argv[++i], &end, 10 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   586
        if ( *end != '\0' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   587
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   588
          fprintf( stderr, "Bad value for error-count: %s\n", argv[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   589
          exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   590
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   591
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   592
      else if ( strcmp( pt, "-error-fraction" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   593
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   594
        if ( !rset )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   595
          error_count = 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   596
        rset = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   597
        error_fraction = strtod( argv[++i], &end );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   598
        if ( *end != '\0' )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   599
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   600
          fprintf( stderr, "Bad value for error-fraction: %s\n", argv[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   601
          exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   602
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   603
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   604
      else if ( strcmp( pt, "-ext" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   605
        exts[ecnt++] = argv[++i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   606
      else if ( strcmp( pt, "-help" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   607
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   608
        usage( stdout, argv[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   609
        exit( 0 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   610
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   611
      else if ( strcmp( pt, "-nohints" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   612
        nohints = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   613
      else if ( strcmp( pt, "-rasterize" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   614
        rasterize = true;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   615
      else if ( strcmp( pt, "-results" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   616
        results_dir = argv[++i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   617
      else if ( strcmp( pt, "-size" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   618
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   619
        font_size = (FT_F26Dot6)( strtod( argv[++i], &end ) * 64 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   620
        if ( *end != '\0' || font_size < 64 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   621
        {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   622
          fprintf( stderr, "Bad value for size: %s\n", argv[i] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   623
          exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   624
        }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   625
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   626
      else if ( strcmp( pt, "-test" ) == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   627
        testfile = argv[++i];
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   628
      else
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   629
      {
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   630
        usage( stderr, argv[0] );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   631
        exit( 1 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   632
      }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   633
    }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   634
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   635
    if ( allexts )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   636
      exts = NULL;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   637
    else if ( ecnt == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   638
      exts = default_ext_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   639
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   640
    if ( dcnt == 0 )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   641
      dirs = default_dir_list;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   642
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   643
    if ( testfile != NULL )
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   644
      ExecuteTest( testfile );         /* This should never return */
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   645
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   646
    time( &now );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   647
    srandom( now );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   648
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   649
    FindFonts( dirs, exts );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   650
    mkdir( results_dir, 0755 );
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   651
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   652
    forever
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   653
      do_test();
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   654
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   655
    return 0;
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   656
  }
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   657
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   658
88f2e05288ba aaand let's add freetype as well while we are at it
koda
parents:
diff changeset
   659
/* EOF */