summaryrefslogtreecommitdiff
path: root/Build/source/libs/freetype/freetype-1.5/test/ftlint.c
blob: ed240a5aea8c1ffcb7c75186c33c4ff4787fc92b (plain)
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
286
287
288
289
290
291
292
293
294
295
296
/****************************************************************************/
/*                                                                          */
/*  The FreeType project -- a free and portable quality TrueType renderer.  */
/*                                                                          */
/*  Copyright 1996-2000 by                                                  */
/*  D. Turner, R.Wilhelm, and W. Lemberg                                    */
/*                                                                          */
/*  ftlint: a simple TrueType instruction tester.                           */
/*                                                                          */
/*  NOTE:  This is just a test program that is used to show off and         */
/*         debug the current engine.                                        */
/*                                                                          */
/****************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "common.h"
#include "freetype.h"

/*
 *  Basically, an external program using FreeType shouldn't depend on an
 *  internal file of the FreeType library, especially not on ft_conf.h -- but
 *  to avoid another configure script which tests for the existence of the
 *  i18n stuff we include ft_conf.h here since we can be sure that our test
 *  programs use the same configuration options as the library itself.
 */

#include "ft_conf.h"


#ifdef HAVE_LIBINTL_H

#ifdef HAVE_LOCALE_H
#include <locale.h>
#endif

#include <libintl.h>
#include "ftxerr18.h"

#else /* !HAVE_LIBINTL_H */

#define gettext( x )  ( x )

  /* We ignore error message strings with this function */

  static char*
  TT_ErrToString18( TT_Error  error )
  {
    static char  temp[32];


    sprintf( temp, "0x%04lx", error );
    return temp;
  }

#endif /* !HAVE_LIBINTL_H */


  TT_Error     error;

  TT_Engine    engine;

  TT_Face      face;
  TT_Instance  instance;
  TT_Glyph     glyph;

  TT_Outline        outline;
  TT_Glyph_Metrics  metrics;

  TT_Face_Properties  properties;

  unsigned int  num_glyphs;
  int           ptsize;

  int  Fail;
  int  Num;


  static TT_Error
  LoadTrueTypeChar( int  idx )
  {
    return TT_Load_Glyph( instance, glyph, idx, TTLOAD_DEFAULT );
  }


  static void
  Usage( char*  name )
  {
    char*  gt;


    gt = gettext( "ftlint: Simple TrueType instruction tester -- part of the FreeType project" );
    fprintf( stderr, "%s\n", gt );
    separator_line( stderr, strlen( gt ) );

    fprintf( stderr, gettext(
             "Usage: %s ppem fontname[.ttf|.ttc] [fontname2..]\n\n" ), name );

    exit( EXIT_FAILURE );
  }


  int
  main( int  argc, char**  argv )
  {
    int           i, file_index;
    unsigned int  id;
    char          filename[128 + 4];
    char          alt_filename[128 + 4];
    char*         execname;
    char*         fname;


#ifdef HAVE_LIBINTL_H
    setlocale( LC_ALL, "" );
    bindtextdomain( "freetype", LOCALEDIR );
    textdomain( "freetype" );
#endif

    execname = argv[0];

    if ( argc < 3 )
      Usage( execname );

    if ( sscanf( argv[1], "%d", &ptsize ) != 1 )
      Usage( execname );

    /* Initialize engine */
    if ( (error = TT_Init_FreeType( &engine )) )
    {
      fprintf( stderr,
               gettext( "Error while initializing engine.\n" ) );
      goto Failure;
    }

    /* Now check all files */
    for ( file_index = 2; file_index < argc; file_index++ )
    {
      fname = argv[file_index];
      i     = strlen( fname );
      while ( i > 0 && fname[i] != '\\' && fname[i] != '/' )
      {
        if ( fname[i] == '.' )
          i = 0;
        i--;
      }

      filename[128] = '\0';
      alt_filename[128] = '\0';

      strncpy( filename, fname, 128 );
      strncpy( alt_filename, fname, 128 );

      if ( i >= 0 )
      {
        strncpy( filename + strlen( filename ), ".ttf", 4 );
        strncpy( alt_filename + strlen( alt_filename ), ".ttc", 4 );
      }

      /* Load face */
      error = TT_Open_Face( engine, filename, &face );

      if ( error == TT_Err_Could_Not_Open_File )
      {
        strcpy( filename, alt_filename );
        error = TT_Open_Face( engine, alt_filename, &face );
      }

      i     = strlen( filename );
      fname = filename;

      while ( i >= 0 )
        if ( filename[i] == '/' || filename[i] == '\\' )
        {
          fname = filename + i + 1;
          i = -1;
        }
        else
          i--;

      fprintf( stderr, "%s: ", fname );

      if ( error == TT_Err_Could_Not_Open_File )
      {
        fprintf( stderr, gettext( "Could not find or open %s.\n" ),
                 filename );
        goto Fail_Face;
      }
      if ( error )
      {
        fprintf( stderr, gettext( "Error while opening %s.\n" ), filename );
        goto Fail_Face;
      }

      /* get face properties */

      TT_Get_Face_Properties( face, &properties );
      num_glyphs = properties.num_Glyphs;

      /* create glyph */
      error = TT_New_Glyph( face, &glyph );
      if ( error )
      {
        fprintf( stderr,
                 gettext( "Could not create glyph container.\n" ) );
        goto Fail_Glyph;
      }

      /* create instance */
      error = TT_New_Instance( face, &instance );
      if ( error )
      {
        fprintf( stderr, gettext( "Could not create instance.\n" ) );
        goto Fail_Instance;
      }

      error = TT_Set_Instance_PixelSizes( instance,
                                          ptsize,
                                          ptsize,
                                          ptsize*3/4 );
      if ( error )
      {
        fprintf( stderr,
                 gettext( "Could not set point size to %d.\n" ),
                 ptsize );
        goto Fail_Set;
      }

      Fail = 0;

      for ( id = 0; id < num_glyphs; id++ )
      {
        if ( (error = LoadTrueTypeChar( id )) )
        {
          if ( Fail < 10 )
          {
            fprintf( stderr, !Fail ? gettext( "Error with\n  " ) : "  " );
            fprintf( stderr, gettext( "glyph %4u: %s\n" ),
                     id, TT_ErrToString18( error ) );
          }
          Fail++;
        }
      }

      if ( Fail == 0 )
        fprintf( stderr, "OK.\n" );
      else
      {
        fprintf( stderr, "  " );
        if ( Fail == 1 )
          fprintf( stderr, gettext( "1 fail.\n" ) );
        else
          fprintf( stderr, gettext( "%d fails.\n" ), Fail );
      }

      /* hush complaints at the end of the loop */
      error = 0;

    Fail_Set:
      TT_Done_Instance( instance );
    Fail_Instance:
      TT_Done_Glyph( glyph );
    Fail_Glyph:
      TT_Close_Face( face );
    Fail_Face:
      ;


      if ( error )
      { 
        fprintf( stderr, "  " );
        fprintf( stderr, gettext( "FreeType error message: %s\n" ),
                 TT_ErrToString18( error ) );
      }
    }

    TT_Done_FreeType( engine );

    exit( EXIT_SUCCESS );      /* for safety reasons */

    return 0;       /* never reached */

  Failure:
    fprintf( stderr, "  " );
    fprintf( stderr, gettext( "FreeType error message: %s\n" ),
             TT_ErrToString18( error ) );

    exit( EXIT_FAILURE );

    return 0;       /* never reached */
  }


/* End */