freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][ftmulti-misc] 3 commits: [ftmulti] Enable


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][ftmulti-misc] 3 commits: [ftmulti] Enable overlap flag testing.
Date: Sun, 12 Feb 2023 01:24:23 +0000

Alexei Podtelezhnikov pushed to branch ftmulti-misc at FreeType / FreeType Demo Programs

Commits:

  • 46b5ae2d
    by Alexei Podtelezhnikov at 2023-02-11T18:30:39-05:00
    [ftmulti] Enable overlap flag testing.
    
    Variation fonts often relay on overlapping contours, which require
    oversampling to render properly. FreeType relies on FT_OUTLINE_OVERLAP
    to trigger the expensive mitigation algorithm. This commit enables
    tinkering with the overlap flags and, therefore, the oversampling.
    Normally, the flags should be set by the font designers sparingly.
    
    The bitmap strike toggle is no longer available, which has never
    been important for the variation font testing.
    
    * src/ftmulti.c (Process_Event): Reassign F4 to overlap toggle.
    (Render_Glyph): Tinker with the overlap flags before rendering.
    
  • 1833b1d1
    by Alexei Podtelezhnikov at 2023-02-11T20:06:16-05:00
    * src/ftmulti.c (Render_All, Render_Text, main): Layout tweaks.
    
  • c2ab3814
    by Alexei Podtelezhnikov at 2023-02-11T20:23:10-05:00
    * src/ftmulti.c (Process_Event): Miscellaneous tweaks.
    
    Set default step at 1/40 which covers most preferable coordinates.
    Adjust the step by doubling or halving it. Round all large-range
    coordinates, not just MM. Wrap the coordinates around.
    

1 changed file:

Changes:

  • src/ftmulti.c
    ... ... @@ -94,7 +94,7 @@
    94 94
       static int  hinted    = 1;         /* is glyph hinting active?    */
    
    95 95
       static int  grouping  = 1;         /* is axis grouping active?    */
    
    96 96
       static int  antialias = 1;         /* is anti-aliasing active?    */
    
    97
    -  static int  use_sbits = 1;         /* do we use embedded bitmaps? */
    
    97
    +  static int  overlaps  = 0x0;       /* flip overlap flags or not?  */
    
    98 98
       static int  Num;                   /* current first glyph index   */
    
    99 99
     
    
    100 100
       static int  res       = 72;
    
    ... ... @@ -103,8 +103,6 @@
    103 103
     
    
    104 104
       static int  Fail;
    
    105 105
     
    
    106
    -  static int  graph_init  = 0;
    
    107
    -
    
    108 106
       static int  render_mode = 1;
    
    109 107
     
    
    110 108
       static FT_MM_Var    *multimaster   = NULL;
    
    ... ... @@ -112,7 +110,7 @@
    112 110
       static FT_Fixed      requested_pos[MAX_MM_AXES];
    
    113 111
       static unsigned int  requested_cnt =  0;
    
    114 112
       static unsigned int  used_num_axis =  0;
    
    115
    -  static int           increment     = 20;  /* for axes */
    
    113
    +  static double        increment     = 0.025;  /* for axes */
    
    116 114
     
    
    117 115
       /*
    
    118 116
        * We use the following arrays to support both the display of all axes and
    
    ... ... @@ -305,8 +303,6 @@
    305 303
         bit = (grBitmap*)surface;
    
    306 304
     
    
    307 305
         fore_color = grFindColor( bit, 255, 255, 255, 255 );  /* white */
    
    308
    -
    
    309
    -    graph_init = 1;
    
    310 306
       }
    
    311 307
     
    
    312 308
     
    
    ... ... @@ -322,6 +318,10 @@
    322 318
         /* first, render the glyph image into a bitmap */
    
    323 319
         if ( glyph->format != FT_GLYPH_FORMAT_BITMAP )
    
    324 320
         {
    
    321
    +      /* overlap flags mitigate AA rendering artifacts in overlaps */
    
    322
    +      /* by oversampling, toggle the flag to test the effect       */
    
    323
    +      glyph->outline.flags ^= overlaps;
    
    324
    +
    
    325 325
           error = FT_Render_Glyph( glyph, antialias ? FT_RENDER_MODE_NORMAL
    
    326 326
                                                     : FT_RENDER_MODE_MONO );
    
    327 327
           if ( error )
    
    ... ... @@ -373,14 +373,11 @@
    373 373
         int  flags;
    
    374 374
     
    
    375 375
     
    
    376
    -    flags = FT_LOAD_DEFAULT;
    
    376
    +    flags = FT_LOAD_NO_BITMAP;
    
    377 377
     
    
    378 378
         if ( !hint )
    
    379 379
           flags |= FT_LOAD_NO_HINTING;
    
    380 380
     
    
    381
    -    if ( !use_sbits )
    
    382
    -      flags |= FT_LOAD_NO_BITMAP;
    
    383
    -
    
    384 381
         return FT_Load_Glyph( face, idx, flags );
    
    385 382
       }
    
    386 383
     
    
    ... ... @@ -394,9 +391,8 @@
    394 391
     
    
    395 392
     
    
    396 393
         start_x = 20 * 8;
    
    397
    -    start_y = pt_size + HEADER_HEIGHT * 3;
    
    398
    -
    
    399
    -    step_y = size->metrics.y_ppem + 10;
    
    394
    +    start_y = size->metrics.y_ppem * 4 / 5 + HEADER_HEIGHT * 3;
    
    395
    +    step_y  = size->metrics.y_ppem + 10;
    
    400 396
     
    
    401 397
         x = start_x;
    
    402 398
         y = start_y;
    
    ... ... @@ -430,7 +426,7 @@
    430 426
               x  = start_x;
    
    431 427
               y += step_y;
    
    432 428
     
    
    433
    -          if ( y >= bit->rows )
    
    429
    +          if ( y >= bit->rows - size->metrics.y_ppem / 5 )
    
    434 430
                 return FT_Err_Ok;
    
    435 431
             }
    
    436 432
     
    
    ... ... @@ -458,9 +454,8 @@
    458 454
     
    
    459 455
     
    
    460 456
         start_x = 20 * 8;
    
    461
    -    start_y = pt_size + HEADER_HEIGHT * 3;
    
    462
    -
    
    463
    -    step_y = size->metrics.y_ppem + 10;
    
    457
    +    start_y = size->metrics.y_ppem * 4 / 5 + HEADER_HEIGHT * 3;
    
    458
    +    step_y  = size->metrics.y_ppem + 10;
    
    464 459
     
    
    465 460
         x = start_x;
    
    466 461
         y = start_y;
    
    ... ... @@ -501,7 +496,7 @@
    501 496
               x  = start_x;
    
    502 497
               y += step_y;
    
    503 498
     
    
    504
    -          if ( y >= bit->rows )
    
    499
    +          if ( y >= bit->rows - size->metrics.y_ppem / 5 )
    
    505 500
                 return FT_Err_Ok;
    
    506 501
             }
    
    507 502
           }
    
    ... ... @@ -558,7 +553,7 @@
    558 553
         grWriteln( "q, ESC      quit ftmulti" );
    
    559 554
         grWriteln( "F2          toggle axis grouping" );
    
    560 555
         grWriteln( "F3          toggle outline hinting" );
    
    561
    -    grWriteln( "F4          toggle embedded bitmaps" );
    
    556
    +    grWriteln( "F4          toggle overlap flags" );
    
    562 557
         grWriteln( "F5          toggle anti-aliasing" );
    
    563 558
         grWriteln( "F6          cycle through hinting engines (if available)" );
    
    564 559
         grLn();
    
    ... ... @@ -608,7 +603,7 @@
    608 603
       Process_Event( void )
    
    609 604
       {
    
    610 605
         grEvent       event;
    
    611
    -    int           i;
    
    606
    +    double        i;
    
    612 607
         unsigned int  axis;
    
    613 608
     
    
    614 609
     
    
    ... ... @@ -645,10 +640,10 @@
    645 640
           break;
    
    646 641
     
    
    647 642
         case grKeyF4:
    
    648
    -      use_sbits  = !use_sbits;
    
    649
    -      new_header = use_sbits
    
    650
    -                     ? "embedded bitmaps are now used if available"
    
    651
    -                     : "embedded bitmaps are now ignored";
    
    643
    +      overlaps  ^= FT_OUTLINE_OVERLAP;
    
    644
    +      new_header = overlaps
    
    645
    +                     ? "overlap flags are flipped"
    
    646
    +                     : "overlap flags are unchanged";
    
    652 647
           break;
    
    653 648
     
    
    654 649
         case grKEY( ',' ):
    
    ... ... @@ -687,14 +682,13 @@
    687 682
         /* MM-related keys */
    
    688 683
     
    
    689 684
         case grKEY( '+' ):
    
    690
    -      /* value 100 is arbitrary */
    
    691
    -      if ( increment < 100 )
    
    692
    -        increment += 1;
    
    685
    +      if ( increment < 0.1 )
    
    686
    +        increment *= 2.0;
    
    693 687
           break;
    
    694 688
     
    
    695 689
         case grKEY( '-' ):
    
    696
    -      if ( increment > 1 )
    
    697
    -        increment -= 1;
    
    690
    +      if ( increment > 0.01 )
    
    691
    +        increment *= 0.5;
    
    698 692
           break;
    
    699 693
     
    
    700 694
         case grKEY( 'a' ):
    
    ... ... @@ -798,7 +792,7 @@
    798 792
         if ( axis < num_shown_axes )
    
    799 793
         {
    
    800 794
           FT_Var_Axis*  a;
    
    801
    -      FT_Fixed      pos;
    
    795
    +      FT_Fixed      pos, rng;
    
    802 796
           unsigned int  n;
    
    803 797
     
    
    804 798
     
    
    ... ... @@ -806,6 +800,7 @@
    806 800
           axis = (unsigned int)shown_axes[axis];
    
    807 801
     
    
    808 802
           a   = multimaster->axis + axis;
    
    803
    +      rng = a->maximum - a->minimum;
    
    809 804
           pos = design_pos[axis];
    
    810 805
     
    
    811 806
           /*
    
    ... ... @@ -814,15 +809,15 @@
    814 809
            * for mac fonts, which have a range of ~3.  And it's rather extreme
    
    815 810
            * for optical size even in PS.
    
    816 811
            */
    
    817
    -      pos += FT_MulDiv( i, a->maximum - a->minimum, 1000 );
    
    812
    +      pos += (FT_Fixed)( i * rng );
    
    818 813
           if ( pos < a->minimum )
    
    819
    -        pos = a->minimum;
    
    820
    -      if ( pos > a->maximum )
    
    821 814
             pos = a->maximum;
    
    815
    +      if ( pos > a->maximum )
    
    816
    +        pos = a->minimum;
    
    822 817
     
    
    823
    -      /* for MM fonts, round the design coordinates to integers,         */
    
    818
    +      /* for MM fonts or large ranges, round the design coordinates      */
    
    824 819
           /* otherwise round to two decimal digits to make the PS name short */
    
    825
    -      if ( !FT_IS_SFNT( face ) )
    
    820
    +      if ( !FT_IS_SFNT( face ) || rng > 0x200000 )
    
    826 821
             pos = FT_RoundFix( pos );
    
    827 822
           else
    
    828 823
           {
    
    ... ... @@ -1178,20 +1173,23 @@
    1178 1173
             grWriteCellString( bit, 0, 2 * HEADER_HEIGHT, Header, fore_color );
    
    1179 1174
     
    
    1180 1175
             strbuf_reset( header );
    
    1181
    -        strbuf_add( header, "axes:" );
    
    1182
    -        grWriteCellString( bit, 0, 3 * HEADER_HEIGHT, Header, fore_color );
    
    1176
    +        strbuf_format( header, "axes (\361 %.1f%%):", 100.0 * increment );
    
    1177
    +        grWriteCellString( bit, 0, 4 * HEADER_HEIGHT, Header, fore_color );
    
    1183 1178
             for ( n = 0; n < num_shown_axes; n++ )
    
    1184 1179
             {
    
    1185 1180
               int  axis = shown_axes[n];
    
    1186 1181
     
    
    1187 1182
     
    
    1188 1183
               strbuf_reset( header );
    
    1189
    -          strbuf_format( header, "%c %.50s%s: %.02f",
    
    1184
    +          strbuf_format( header, "%c %.50s%s:",
    
    1190 1185
                              n + 'A',
    
    1191 1186
                              multimaster->axis[axis].name,
    
    1192
    -                         hidden[axis] ? "*" : "",
    
    1193
    -                         design_pos[axis] / 65536.0 );
    
    1194
    -          grWriteCellString( bit, 0, (int)( n + 4 ) * HEADER_HEIGHT,
    
    1187
    +                         hidden[axis] ? "*" : "" );
    
    1188
    +          if ( design_pos[axis] & 0xFFFF )
    
    1189
    +            strbuf_format( header, "% .2f", design_pos[axis] / 65536.0 );
    
    1190
    +          else
    
    1191
    +            strbuf_format( header,   "% d", design_pos[axis] / 65536 );
    
    1192
    +          grWriteCellString( bit, 0, (int)( n + 5 ) * HEADER_HEIGHT,
    
    1195 1193
                                  Header, fore_color );
    
    1196 1194
             }
    
    1197 1195
     
    
    ... ... @@ -1224,11 +1222,10 @@
    1224 1222
               strbuf_reset( header );
    
    1225 1223
               strbuf_format(
    
    1226 1224
                 header,
    
    1227
    -            "size: %dpt, first glyph: %d, format: %s, axis incr.: %.1f%%",
    
    1225
    +            "size: %dpt, first glyph: %d, format: %s",
    
    1228 1226
                 ptsize,
    
    1229 1227
                 Num,
    
    1230
    -            format_str,
    
    1231
    -            increment / 10.0 );
    
    1228
    +            format_str );
    
    1232 1229
             }
    
    1233 1230
           }
    
    1234 1231
           else
    


  • reply via email to

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