freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype-demos][master] 3 commits: [ftlint] Introduce qui


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] 3 commits: [ftlint] Introduce quiet mode, remove extension guessing.
Date: Fri, 18 Jun 2021 03:41:04 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType Demo Programs

Commits:

2 changed files:

Changes:

  • ChangeLog
    1
    +2021-06-17  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    2
    +
    
    3
    +	* src/ftlint.c (main, Analyze): Fix signed/unsigned mismatch.
    
    4
    +
    
    5
    +2021-06-17  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    6
    +
    
    7
    +	[ftlint] Handle font collections.
    
    8
    +
    
    9
    +	* src/ftlint.c (main): Increment face_index when possible.
    
    10
    +
    
    11
    +2021-06-17  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    12
    +
    
    13
    +	[ftlint] Introduce quiet mode, remove extension guessing.
    
    14
    +
    
    15
    +	With so many supported font formats, it does not make sense to guess
    
    16
    +	the `ttf' or `ttc' extensions.
    
    17
    +
    
    18
    +	* src/ftlint.c (main): Add `-q' option and improve output formatting;
    
    19
    +	remove extension guessing.
    
    20
    +	(Usage): Document it.
    
    21
    +
    
    1 22
     2021-06-15  Alexei Podtelezhnikov  <apodtele@gmail.com>
    
    2 23
     
    
    3 24
     	* src/ftdump.c (Print_Glyfs, Print_Programs): Handle empty glyphs.
    
    ... ... @@ -10,7 +31,7 @@
    10 31
     	the minimum and maximum value at the edges.  We calculate is as a
    
    11 32
     	ratio of the integrals for the absolute second derivative and the
    
    12 33
     	absolute first derivative.  It equals to 2.0 for bitmap fonts and
    
    13
    -	approahes this value for well hinted fonts.
    
    34
    +	approaches this value for well-hinted fonts.
    
    14 35
     
    
    15 36
     	* src/ftlint.c (Analyze): Implement it.
    
    16 37
     	(main): Use it.
    

  • src/ftlint.c
    ... ... @@ -31,8 +31,6 @@
    31 31
     #endif
    
    32 32
     
    
    33 33
     
    
    34
    -#define  xxTEST_PSNAMES
    
    35
    -
    
    36 34
       static FT_Error        error;
    
    37 35
       static FT_Library      library;
    
    38 36
       static FT_Face         face;
    
    ... ... @@ -50,12 +48,13 @@
    50 48
         printf( "ftlint: simple font tester -- part of the FreeType project\n" );
    
    51 49
         printf( "----------------------------------------------------------\n" );
    
    52 50
         printf( "\n" );
    
    53
    -    printf( "Usage: %s [options] ppem fontname[.ttf|.ttc] [fontname2..]\n",
    
    51
    +    printf( "Usage: %s [options] ppem fontname [fontname2..]\n",
    
    54 52
                 name );
    
    55 53
         printf( "\n" );
    
    56 54
         printf( "  -f L    Use hex number L as load flags (see `FT_LOAD_XXX')\n" );
    
    57 55
         printf( "  -r N    Set render mode to N\n" );
    
    58 56
         printf( "  -i I-J  Range of glyph indices to use (default: all)\n" );
    
    57
    +    printf( "  -q      Quiet mode without the rendering analysis\n" );
    
    59 58
     
    
    60 59
         exit( 1 );
    
    61 60
       }
    
    ... ... @@ -82,7 +81,7 @@
    82 81
         /* X-acutance */
    
    83 82
         for ( b = bitmap->buffer, s1 = s2 = 0, i = 0; i < bitmap->rows; i++ )
    
    84 83
         {
    
    85
    -      for ( d0 = d1 = 0, j = 0; j < bitmap->pitch; j++, b++ )
    
    84
    +      for ( d0 = d1 = 0, j = 0; j < bitmap->width; j++, b++ )
    
    86 85
           {
    
    87 86
             d1 -= *b;
    
    88 87
             s2 += d1 >= d0 ? d1 - d0 : d0 - d1;  /* second derivative sum */
    
    ... ... @@ -98,7 +97,7 @@
    98 97
         printf( "X=%.4lf  ", s1 ? (double)s2 / s1 : 2.0 );
    
    99 98
     
    
    100 99
         /* Y-acutance */
    
    101
    -    for ( s1 = s2 = 0, j = 0; j < bitmap->pitch; j++ )
    
    100
    +    for ( s1 = s2 = 0, j = 0; j < bitmap->width; j++ )
    
    102 101
         {
    
    103 102
           b = bitmap->buffer + j;
    
    104 103
           for ( d0 = d1 = 0, i = 0; i < bitmap->rows; i++, b += bitmap->pitch )
    
    ... ... @@ -141,14 +140,14 @@
    141 140
       main( int     argc,
    
    142 141
             char**  argv )
    
    143 142
       {
    
    144
    -    int           i, file_index;
    
    143
    +    int           file_index, face_index;
    
    145 144
         unsigned int  id;
    
    146
    -    char          filename[1024];
    
    147 145
         char*         execname;
    
    148 146
         char*         fname;
    
    149 147
         int           opt;
    
    150
    -    int           first_index = 0;
    
    151
    -    int           last_index = ~0;
    
    148
    +    unsigned int  first_index = 0;
    
    149
    +    unsigned int  last_index = ~0;
    
    150
    +    int           quiet = 0;
    
    152 151
     
    
    153 152
     
    
    154 153
         execname = argv[0];
    
    ... ... @@ -156,7 +155,7 @@
    156 155
         if ( argc < 3 )
    
    157 156
           Usage( execname );
    
    158 157
     
    
    159
    -    while ( ( opt =  getopt( argc, argv, "f:r:i:") ) != -1)
    
    158
    +    while ( ( opt =  getopt( argc, argv, "f:r:i:q") ) != -1)
    
    160 159
         {
    
    161 160
     
    
    162 161
           switch ( opt )
    
    ... ... @@ -195,6 +194,10 @@
    195 194
             }
    
    196 195
             break;
    
    197 196
     
    
    197
    +      case 'q':
    
    198
    +        quiet = 1;
    
    199
    +        break;
    
    200
    +
    
    198 201
           default:
    
    199 202
             Usage( execname );
    
    200 203
             break;
    
    ... ... @@ -205,7 +208,7 @@
    205 208
         argv += optind;
    
    206 209
     
    
    207 210
     
    
    208
    -    if( sscanf( argv[0], "%d", &ptsize) != 1)
    
    211
    +    if( sscanf( argv[0], "%d", &ptsize) != 1 )
    
    209 212
           Usage( execname );
    
    210 213
     
    
    211 214
         error = FT_Init_FreeType( &library );
    
    ... ... @@ -214,108 +217,54 @@
    214 217
     
    
    215 218
     
    
    216 219
         /* Now check all files */
    
    217
    -    for ( file_index = 1; file_index < argc; file_index++ )
    
    220
    +    for ( face_index = 0, file_index = 1; file_index < argc; file_index++ )
    
    218 221
         {
    
    219 222
           fname = argv[file_index];
    
    220 223
     
    
    221
    -      /* try to open the file with no extra extension first */
    
    222
    -      error = FT_New_Face( library, fname, 0, &face );
    
    223
    -      if ( !error )
    
    224
    -      {
    
    225
    -        printf( "%s: \n", fname );
    
    226
    -        goto Success;
    
    227
    -      }
    
    228
    -
    
    224
    +      printf( "%s:\n", fname );
    
    229 225
     
    
    226
    +    Next_Face:
    
    227
    +      error = FT_New_Face( library, fname, face_index, &face );
    
    230 228
           if ( error == FT_Err_Unknown_File_Format )
    
    231 229
           {
    
    232
    -        printf( "unknown format\n" );
    
    230
    +        printf( "  unknown format\n" );
    
    233 231
             continue;
    
    234 232
           }
    
    235
    -
    
    236
    -      /* ok, we could not load the file, try to add an extension to */
    
    237
    -      /* its name if possible..                                     */
    
    238
    -
    
    239
    -      i = (int)strlen( fname );
    
    240
    -      while ( i > 0 && fname[i] != '\\' && fname[i] != '/' )
    
    233
    +      else if ( error )
    
    241 234
           {
    
    242
    -        if ( fname[i] == '.' )
    
    243
    -          i = 0;
    
    244
    -        i--;
    
    235
    +        printf( "  error = 0x%04x\n" , error );
    
    236
    +        continue;
    
    245 237
           }
    
    246 238
     
    
    247
    -#ifndef macintosh
    
    248
    -      snprintf( filename, sizeof ( filename ), "%s%s", fname,
    
    249
    -                ( i >= 0 ) ? ".ttf" : "" );
    
    250
    -#else
    
    251
    -      snprintf( filename, sizeof ( filename ), "%s", fname );
    
    252
    -#endif
    
    253
    -
    
    254
    -      i     = (int)strlen( filename );
    
    255
    -      fname = filename;
    
    239
    +      printf( quiet ? "  %s %s:" : "  %s %s:\n",
    
    240
    +              face->family_name, face->style_name );
    
    256 241
     
    
    257
    -      while ( i >= 0 )
    
    258
    -#ifndef macintosh
    
    259
    -        if ( filename[i] == '/' || filename[i] == '\\' )
    
    260
    -#else
    
    261
    -        if ( filename[i] == ':' )
    
    262
    -#endif
    
    263
    -        {
    
    264
    -          fname = filename + i + 1;
    
    265
    -          i = -1;
    
    266
    -        }
    
    267
    -        else
    
    268
    -          i--;
    
    269
    -
    
    270
    -      printf( "%s: \n", fname );
    
    271
    -
    
    272
    -      /* Load face */
    
    273
    -      error = FT_New_Face( library, filename, 0, &face );
    
    274
    -      if (error)
    
    275
    -      {
    
    276
    -        if (error == FT_Err_Unknown_File_Format)
    
    277
    -          printf( "unknown format\n" );
    
    278
    -        else
    
    279
    -          printf( "could not find/open file (error: %d)\n", error );
    
    280
    -        continue;
    
    281
    -      }
    
    282
    -      if (error) Panic( "Could not open file" );
    
    242
    +      error = FT_Set_Char_Size( face, ptsize << 6, ptsize << 6, 72, 72 );
    
    243
    +      if ( error )
    
    244
    +        Panic( "Could not set character size" );
    
    283 245
     
    
    284
    -  Success:
    
    285 246
           if ( first_index > (unsigned int)face->num_glyphs )
    
    286 247
             first_index = 0;
    
    287 248
           if ( last_index > (unsigned int)face->num_glyphs )
    
    288 249
             last_index = (unsigned int)face->num_glyphs - 1;
    
    289 250
     
    
    290
    -
    
    291
    -#ifdef  TEST_PSNAMES
    
    292
    -      {
    
    293
    -        const char*  ps_name = FT_Get_Postscript_Name( face );
    
    294
    -
    
    295
    -        printf( "[%s] ", ps_name ? ps_name : "." );
    
    296
    -      }
    
    297
    -#endif
    
    298
    -
    
    299
    -      error = FT_Set_Char_Size( face, ptsize << 6, ptsize << 6, 72, 72 );
    
    300
    -      if ( error )
    
    301
    -        Panic( "Could not set character size" );
    
    302
    -
    
    303 251
           Fail = 0;
    
    304 252
           for ( id = first_index; id <= last_index; id++ )
    
    305 253
           {
    
    306 254
             FT_Bitmap  bitmap;
    
    307 255
     
    
    308 256
     
    
    309
    -        printf( "%5u: ", id );
    
    310
    -
    
    311 257
             error = FT_Load_Glyph( face, id, load_flags );
    
    312 258
             if ( error )
    
    313 259
             {
    
    314
    -          printf( "error = 0x%04x\n" , error );
    
    260
    +          printf( "%5u: error = 0x%04x\n", id, error );
    
    315 261
               Fail++;
    
    316 262
               continue;
    
    317 263
             }
    
    318 264
     
    
    265
    +        if ( quiet )
    
    266
    +          continue;
    
    267
    +
    
    319 268
             FT_Render_Glyph( face->glyph, render_mode );
    
    320 269
     
    
    321 270
             FT_Bitmap_Init( &bitmap );
    
    ... ... @@ -323,9 +272,12 @@
    323 272
             /* convert to an 8-bit bitmap with a positive pitch */
    
    324 273
             error = FT_Bitmap_Convert( library, &face->glyph->bitmap, &bitmap, 1 );
    
    325 274
             if ( error )
    
    326
    -          printf( "error = 0x%04x", error );
    
    275
    +        {
    
    276
    +          printf( "%5u: error = 0x%04x\n", id, error );
    
    277
    +          continue;
    
    278
    +        }
    
    327 279
             else
    
    328
    -          printf( "%3ux%-4u ", bitmap.width, bitmap.rows );
    
    280
    +          printf( "%5u: %3ux%-4u ", id, bitmap.width, bitmap.rows );
    
    329 281
     
    
    330 282
             Analyze( &bitmap );
    
    331 283
             Checksum( &bitmap );
    
    ... ... @@ -336,16 +288,22 @@
    336 288
           }
    
    337 289
     
    
    338 290
           if ( Fail == 0 )
    
    339
    -        printf( "OK.\n" );
    
    291
    +        printf( "  OK.\n" );
    
    340 292
           else if ( Fail == 1 )
    
    341
    -        printf( "1 fail.\n" );
    
    293
    +        printf( "  1 fail.\n" );
    
    342 294
           else
    
    343
    -        printf( "%d fails.\n", Fail );
    
    295
    +        printf( "  %d fails.\n", Fail );
    
    296
    +
    
    297
    +      if ( ++face_index == face->num_faces )
    
    298
    +        face_index = 0;
    
    344 299
     
    
    345 300
           FT_Done_Face( face );
    
    301
    +
    
    302
    +      if ( face_index )
    
    303
    +        goto Next_Face;
    
    346 304
         }
    
    347 305
     
    
    348
    -    FT_Done_FreeType(library);
    
    306
    +    FT_Done_FreeType( library );
    
    349 307
         exit( 0 );      /* for safety reasons */
    
    350 308
     
    
    351 309
         /* return 0; */ /* never reached */
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]