freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][gsoc-craig-2023] Wrap up all glyph variant algo


From: Craig White (@gerzytet)
Subject: [Git][freetype/freetype][gsoc-craig-2023] Wrap up all glyph variant algorithm
Date: Wed, 27 Sep 2023 02:44:12 +0000

Craig White pushed to branch gsoc-craig-2023 at FreeType / FreeType

Commits:

  • e0f9830b
    by Craig White at 2023-09-26T22:43:47-04:00
    Wrap up all glyph variant algorithm
    

1 changed file:

Changes:

  • src/autofit/afadjust.c
    ... ... @@ -223,7 +223,7 @@ af_reverse_character_map_lookup_( AF_ReverseCharacterMap map, FT_Int glyph_index
    223 223
         }
    
    224 224
         /* Binary search for reverse character map entry */
    
    225 225
         FT_Int low = 0;
    
    226
    -    FT_Int high = map->length - 1;
    
    226
    +    FT_Int high = length - 1;
    
    227 227
         while ( high >= low )
    
    228 228
         {
    
    229 229
             FT_Int mid = ( high + low ) / 2;
    
    ... ... @@ -283,6 +283,13 @@ af_reverse_character_map_entry_compare( const void *a, const void *b ) {
    283 283
     }
    
    284 284
     
    
    285 285
     #ifdef FT_CONFIG_OPTION_USE_HARFBUZZ
    
    286
    +/*Recursive algorithm to find all glyphs that a codepoint could turn into from the GSUB table.
    
    287
    +buffer: a buffer containing only the input codepoint
    
    288
    +feature_tag_pool: the current list of features under consideration
    
    289
    +current_features: the current list of features being applied
    
    290
    +num_features: length of current_features
    
    291
    +result: the set of glyphs in the answer
    
    292
    +*/
    
    286 293
     FT_LOCAL_DEF( FT_Error )
    
    287 294
     af_all_glyph_variants_helper( hb_font_t *font,
    
    288 295
                                   hb_buffer_t *buffer,
    
    ... ... @@ -291,6 +298,8 @@ af_all_glyph_variants_helper( hb_font_t *font,
    291 298
                                   FT_UInt32 num_features,
    
    292 299
                                   hb_set_t* result )
    
    293 300
     {
    
    301
    +    /*get the list of glyphs that are created by only transforming based on the
    
    302
    +    features in current features*/
    
    294 303
         hb_set_t *baseline_glyphs = hb_set_create();
    
    295 304
         if ( !hb_set_allocation_successful( baseline_glyphs ) )
    
    296 305
         {
    
    ... ... @@ -302,7 +311,13 @@ af_all_glyph_variants_helper( hb_font_t *font,
    302 311
                                      current_features,
    
    303 312
                                      num_features,
    
    304 313
                                      baseline_glyphs );
    
    314
    +    if ( !hb_set_allocation_successful( baseline_glyphs ) )
    
    315
    +    {
    
    316
    +        return FT_Err_Out_Of_Memory;
    
    317
    +    }
    
    305 318
     
    
    319
    +    /*Add these baseline glyphs to the results.  The baseline glyphs
    
    320
    +    will contain at minimum the glyph specified by CMAP*/
    
    306 321
         hb_set_union( result, baseline_glyphs );
    
    307 322
         if ( !hb_set_allocation_successful( result ) )
    
    308 323
         {
    
    ... ... @@ -313,26 +328,27 @@ af_all_glyph_variants_helper( hb_font_t *font,
    313 328
             return FT_Err_Ok;
    
    314 329
         }
    
    315 330
     
    
    316
    -    /*set the feature to apply to the entire input buffer*/
    
    331
    +    /*setup to try adding different features to current_features
    
    332
    +    to see if any of them have an effect of the glyphs we get from
    
    333
    +    hb_ot_shape_glyphs_closure*/
    
    317 334
         current_features[num_features].start = HB_FEATURE_GLOBAL_START;
    
    318 335
         current_features[num_features].end = HB_FEATURE_GLOBAL_END;
    
    319 336
         current_features[num_features].value = 1; /*set the feature to enabled*/
    
    320 337
         /*quote from docs about value attribute:
    
    321 338
         0 disables the feature, non-zero (usually 1) enables the feature. For features implemented as lookup type 3 (like 'salt') the value is a one based index into the alternates.
    
    322
    -    this does not handle these lookup type 3 cases fully*/
    
    339
    +    this algorithm does not handle these lookup type 3 cases fully*/
    
    323 340
     
    
    324
    -    /*feature tag will be determined by trying all feature tags, looking for anything that affects the result of the lookup*/
    
    325 341
         hb_set_t *new_glyphs = hb_set_create();
    
    326 342
         if ( !hb_set_allocation_successful( new_glyphs ) )
    
    327 343
         {
    
    328 344
             return FT_Err_Out_Of_Memory;
    
    329 345
         }
    
    346
    +
    
    330 347
         hb_tag_t feature_tag = HB_SET_VALUE_INVALID;
    
    331 348
         while ( hb_set_next( feature_tag_pool, &feature_tag ) )
    
    332 349
         {
    
    333 350
             hb_set_clear( new_glyphs );
    
    334 351
             current_features[num_features].tag = feature_tag;
    
    335
    -        FT_TRACE4(("P3. num: %d\n", num_features));
    
    336 352
             hb_ot_shape_glyphs_closure ( font,
    
    337 353
                                          buffer,
    
    338 354
                                          current_features,
    
    ... ... @@ -343,12 +359,13 @@ af_all_glyph_variants_helper( hb_font_t *font,
    343 359
                 return FT_Err_Out_Of_Memory;
    
    344 360
             }
    
    345 361
     
    
    346
    -        hb_set_subtract( new_glyphs, baseline_glyphs );
    
    347
    -        /*glyphs now contains all glyphs that were added to the*/
    
    348
    -        /*closure as a result of adding this feature*/
    
    349
    -        /*If this is not a subset of result, this feature is relevant*/
    
    350
    -        /*and we should recurse*/
    
    351
    -        if ( !hb_set_is_subset( new_glyphs, result ) )
    
    362
    +        hb_set_subtract( new_glyphs, result );
    
    363
    +        /*new_glyphs now contains all glyphs that appeared in the result
    
    364
    +        of hb_ot_shape_glyphs_closure that haven't already been accounted for in the result.
    
    365
    +        If this contains any glyphs, we also need to try this feature
    
    366
    +        in combination will other features by recursing
    
    367
    +        */
    
    368
    +        if ( hb_set_get_population( new_glyphs ) != 0 )
    
    352 369
             {
    
    353 370
                 /*remove this feature from the feature pool so that
    
    354 371
                 the later recursion won't try it*/
    
    ... ... @@ -386,12 +403,15 @@ af_all_glyph_variants( FT_Face face,
    386 403
         FT_Memory memory = face->memory;
    
    387 404
         FT_Error error;
    
    388 405
         hb_face_t *hb_face = hb_font_get_face( hb_font );
    
    406
    +
    
    407
    +    /*The set of all feature tags in the font*/
    
    389 408
         hb_set_t  *feature_tags = hb_set_create();
    
    390 409
         if ( !hb_set_allocation_successful( feature_tags ) )
    
    391 410
         {
    
    392 411
             return FT_Err_Out_Of_Memory;
    
    393 412
         }
    
    394 413
     
    
    414
    +    /*populate feature_tags using the output of hb_ot_layout_table_get_feature_tags*/
    
    395 415
         FT_Bool feature_list_done = 0;
    
    396 416
         unsigned int start_offset = 0;
    
    397 417
         while ( !feature_list_done ) {
    
    ... ... @@ -417,6 +437,7 @@ af_all_glyph_variants( FT_Face face,
    417 437
             }
    
    418 438
         }
    
    419 439
     
    
    440
    +    /*make a buffer only consisting of the given codepoint*/
    
    420 441
         hb_buffer_t *codepoint_buffer = hb_buffer_create();
    
    421 442
         if ( !hb_buffer_allocation_successful( codepoint_buffer ) )
    
    422 443
         {
    
    ... ... @@ -430,12 +451,15 @@ af_all_glyph_variants( FT_Face face,
    430 451
                                  HB_DIRECTION_LTR);
    
    431 452
         hb_buffer_add( codepoint_buffer, codepoint, 0 );
    
    432 453
     
    
    454
    +    /*The array of features that will be used by the recursive part
    
    455
    +    it will have at most as many entries as there are features, so
    
    456
    +    make the length = length of feature_tags*/
    
    433 457
         hb_feature_t *feature_buffer;
    
    434
    -    if ( FT_NEW_ARRAY( feature_buffer, hb_set_get_population( feature_tags ) ) ) {
    
    458
    +    if ( FT_NEW_ARRAY( feature_buffer, hb_set_get_population( feature_tags ) ) )
    
    459
    +    {
    
    435 460
             return error;
    
    436 461
         }
    
    437 462
     
    
    438
    -    /*hb_codepoint_t and hb_tag_t are both uint32_t, so we can put feature tags inside hb_set*/
    
    439 463
         error = af_all_glyph_variants_helper( hb_font,
    
    440 464
                                               codepoint_buffer,
    
    441 465
                                               feature_tags,
    
    ... ... @@ -446,7 +470,7 @@ af_all_glyph_variants( FT_Face face,
    446 470
         hb_set_destroy( feature_tags );
    
    447 471
         hb_buffer_destroy( codepoint_buffer );
    
    448 472
         FT_FREE( feature_buffer );
    
    449
    -    return FT_Err_Ok;
    
    473
    +    return error;
    
    450 474
     }
    
    451 475
     #endif /*FT_CONFIG_OPTION_USE_HARFBUZZ*/
    
    452 476
     
    
    ... ... @@ -492,21 +516,18 @@ af_reverse_character_map_new( AF_ReverseCharacterMap *map, AF_FaceGlobals global
    492 516
             goto harfbuzz_path_Exit;
    
    493 517
         }
    
    494 518
     
    
    495
    -
    
    496
    -    /*
    
    497
    -    af_all_glyph_variants( FT_Face face,
    
    498
    -                       hb_font_t *hb_font,
    
    499
    -                       FT_UInt32 codepoint,
    
    500
    -                       hb_set_t* result )*/
    
    501
    -
    
    519
    +    /*find alll glyph variants of the codepoints, then make an entry from
    
    520
    +    the glyph to the codepoint for each one*/
    
    502 521
         for ( FT_Long i = 0; i < AF_ADJUSTMENT_DATABASE_LENGTH; i++ )
    
    503 522
         {
    
    504 523
             FT_UInt32 codepoint = adjustment_database[i].codepoint;
    
    524
    +
    
    505 525
             error = af_all_glyph_variants( face,
    
    506 526
                                            hb_font,
    
    507 527
                                            codepoint,
    
    508 528
                                            result_set );
    
    509
    -        if ( error ) {
    
    529
    +        if ( error )
    
    530
    +        {
    
    510 531
                 goto harfbuzz_path_Exit;
    
    511 532
             }
    
    512 533
     
    
    ... ... @@ -518,14 +539,13 @@ af_reverse_character_map_new( AF_ReverseCharacterMap *map, AF_FaceGlobals global
    518 539
                     goto harfbuzz_path_Exit;
    
    519 540
                 }
    
    520 541
     
    
    542
    +            FT_Long insert_point = ( *map )->length;
    
    521 543
                 ( *map )->length++;
    
    522
    -            ( *map )->entries[i].glyph_index = glyph;
    
    523
    -            ( *map )->entries[i].codepoint = codepoint;
    
    524
    -
    
    544
    +            ( *map )->entries[insert_point].glyph_index = glyph;
    
    545
    +            ( *map )->entries[insert_point].codepoint = codepoint;
    
    525 546
             }
    
    526 547
     
    
    527 548
             hb_set_clear( result_set );
    
    528
    -
    
    529 549
         }
    
    530 550
     harfbuzz_path_Exit:
    
    531 551
         hb_set_destroy( result_set );
    
    ... ... @@ -567,11 +587,6 @@ harfbuzz_path_Exit:
    567 587
             af_reverse_character_map_entry_compare
    
    568 588
         );
    
    569 589
     
    
    570
    -    for ( FT_Long i = 0; i < ( *map )->length; i++ )
    
    571
    -    {
    
    572
    -        FT_TRACE4(("char: %c, glyph: %d\n", ( *map )->entries[i].codepoint, ( *map )->entries[i].glyph_index ) );
    
    573
    -    }
    
    574
    -
    
    575 590
         FT_TRACE4(( "    reverse character map built successfully"\
    
    576 591
                     " with %d entries\n", (*map)->length ));
    
    577 592
     
    


  • reply via email to

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