freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] [ftlint] Examine the outline shap


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] [ftlint] Examine the outline shape complexity.
Date: Sun, 26 Mar 2023 02:46:05 +0000

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

Commits:

  • ec7731ec
    by Alexei Podtelezhnikov at 2023-03-25T22:36:53-04:00
    [ftlint] Examine the outline shape complexity.
    
    Measured as a ratio of the outline half-perimeter to the sum of its
    control box dimensions, the shape complexity is a useful metric.
    For example, an `I` and an `M` would have complexities of about
    1.0 and 2.0, respectively.
    
    * src/ftlint.c (Examine): Implement the shape complexity calculation.
    (main) Report the shape complexity.
    * man/ftlint.1: Add a brief explanation.
    

2 changed files:

Changes:

  • man/ftlint.1
    ... ... @@ -18,6 +18,8 @@ ftlint \- simple font tester
    18 18
     .
    
    19 19
     .B ftlint
    
    20 20
     opens the given font(s), loads and renders glyphs at the given ppem value.
    
    21
    +The shape complexity of outline glyphs are examined based on their taxicab
    
    22
    +perimeters: the higher the number, the more complex the shape.
    
    21 23
     For successfully rendered glyphs, it calculates the bitmap MD5 checksum
    
    22 24
     for regression testing as well as horizontal (X) and vertical (Y) acutances
    
    23 25
     for quality assessment.  The acutance is equal to 2.0 for monochrome bitmap
    

  • src/ftlint.c
    ... ... @@ -15,6 +15,7 @@
    15 15
     
    
    16 16
     #include <ft2build.h>
    
    17 17
     #include <freetype/freetype.h>
    
    18
    +#include <freetype/ftoutln.h>
    
    18 19
     #include <freetype/ftbitmap.h>
    
    19 20
     
    
    20 21
     
    
    ... ... @@ -84,6 +85,58 @@
    84 85
       }
    
    85 86
     
    
    86 87
     
    
    88
    +  static void
    
    89
    +  Examine( FT_GlyphSlot  slot )
    
    90
    +  {
    
    91
    +    unsigned long  format = slot->format;
    
    92
    +    FT_Outline*    outline = &slot->outline;
    
    93
    +    short          c, p, first, last;
    
    94
    +    FT_Vector      u, v;
    
    95
    +    FT_Pos         taxi;
    
    96
    +    FT_BBox        cbox;
    
    97
    +
    
    98
    +
    
    99
    +    if ( format != FT_GLYPH_FORMAT_OUTLINE )
    
    100
    +    {
    
    101
    +      putchar( ' ' );
    
    102
    +      putchar( ( format >> 24 ) & 0xFF );
    
    103
    +      putchar( ( format >> 16 ) & 0xFF );
    
    104
    +      putchar( ( format >>  8 ) & 0xFF );
    
    105
    +      putchar( ( format       ) & 0xFF );
    
    106
    +      putchar( ' ' );
    
    107
    +      return;
    
    108
    +    }
    
    109
    +
    
    110
    +    taxi = 0;
    
    111
    +    last = -1;
    
    112
    +    for ( c = 0; c < outline->n_contours; c++ )
    
    113
    +    {
    
    114
    +      first = last + 1;
    
    115
    +      last = outline->contours[c];
    
    116
    +
    
    117
    +      u = outline->points[last];
    
    118
    +      for ( p = first; p <= last; p++ )
    
    119
    +      {
    
    120
    +        v = outline->points[p];
    
    121
    +
    
    122
    +        taxi += v.x > u.x ? v.x - u.x : u.x - v.x;
    
    123
    +        taxi += v.y > u.y ? v.y - u.y : u.y - v.y;
    
    124
    +
    
    125
    +        u = v;
    
    126
    +      }
    
    127
    +    }
    
    128
    +
    
    129
    +    if ( taxi )
    
    130
    +    {
    
    131
    +      FT_Outline_Get_CBox( outline, &cbox );
    
    132
    +      printf( "%5.2f ", 0.5 * taxi /
    
    133
    +                        ( cbox.xMax - cbox.xMin + cbox.yMax - cbox.yMin ) );
    
    134
    +    }
    
    135
    +    else
    
    136
    +      printf( " void " );
    
    137
    +  }
    
    138
    +
    
    139
    +
    
    87 140
       /* Analyze X- and Y-acutance; bitmap should have positive pitch */
    
    88 141
       static void
    
    89 142
       Analyze( FT_Bitmap* bitmap )
    
    ... ... @@ -281,9 +334,9 @@
    281 334
     
    
    282 335
           if ( !quiet )
    
    283 336
           {
    
    284
    -        /*        "NNNNN AAAxBBBB X.XXXX Y.YYYY MMDD55MMDD55MMDD55MMDD55MMDD55MM" */
    
    285
    -        printf( "\n GID  imgsize  Xacut  Yacut  MD5 hashsum" );
    
    286
    -        printf( "\n-------------------------------------------------------------\n" );
    
    337
    +        /*        "NNNNN SS.SS WWWxHHHH X.XXXX Y.YYYY MMDD55MMDD55MMDD55MMDD55MMDD55MM" */
    
    338
    +        printf( "\n GID  shape imgsize  Xacut  Yacut  MD5 hashsum" );
    
    339
    +        printf( "\n-------------------------------------------------------------------\n" );
    
    287 340
           }
    
    288 341
     
    
    289 342
           Fail = 0;
    
    ... ... @@ -309,6 +362,8 @@
    309 362
     
    
    310 363
             printf( "%5u ", id );
    
    311 364
     
    
    365
    +        Examine( face->glyph );
    
    366
    +
    
    312 367
             error = FT_Render_Glyph( face->glyph, render_mode );
    
    313 368
             if ( error && error != FT_Err_Cannot_Render_Glyph )
    
    314 369
             {
    


  • reply via email to

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