freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] [ftview] Report the last availabl


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype-demos][master] [ftview] Report the last available index or charcode.
Date: Wed, 17 Nov 2021 03:50:48 +0000

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

Commits:

2 changed files:

Changes:

  • src/ftcommon.c
    ... ... @@ -671,11 +671,40 @@
    671 671
       }
    
    672 672
     
    
    673 673
     
    
    674
    +  /* binary search for the last charcode */
    
    675
    +  static int
    
    676
    +  get_last_char( FT_Face     face,
    
    677
    +                 FT_Int      idx,
    
    678
    +                 FT_ULong    max )
    
    679
    +  {
    
    680
    +    FT_ULong  res, mid, min = 0;
    
    681
    +    FT_UInt   gidx;
    
    682
    +
    
    683
    +
    
    684
    +    /* activate charmap */
    
    685
    +    face->charmap = face->charmaps[idx];
    
    686
    +
    
    687
    +    do
    
    688
    +    {
    
    689
    +      mid = ( min + max ) >> 1;
    
    690
    +      res = FT_Get_Next_Char( face, mid, &gidx );
    
    691
    +
    
    692
    +      if ( gidx )
    
    693
    +        min = res;
    
    694
    +      else
    
    695
    +        max = mid;
    
    696
    +    } while ( max > min );
    
    697
    +
    
    698
    +    return (int)max;
    
    699
    +  }
    
    700
    +
    
    701
    +
    
    674 702
       void
    
    675 703
       FTDemo_Set_Current_Font( FTDemo_Handle*  handle,
    
    676 704
                                PFont           font )
    
    677 705
       {
    
    678 706
         FT_Face  face;
    
    707
    +    int      index = font->cmap_index;
    
    679 708
     
    
    680 709
     
    
    681 710
         handle->current_font   = font;
    
    ... ... @@ -684,8 +713,8 @@
    684 713
         error = FTC_Manager_LookupFace( handle->cache_manager,
    
    685 714
                                         handle->scaler.face_id, &face );
    
    686 715
     
    
    687
    -    if ( font->cmap_index < face->num_charmaps )
    
    688
    -      handle->encoding = face->charmaps[font->cmap_index]->encoding;
    
    716
    +    if ( index < face->num_charmaps )
    
    717
    +      handle->encoding = face->charmaps[index]->encoding;
    
    689 718
         else
    
    690 719
           handle->encoding = FT_ENCODING_ORDER;
    
    691 720
     
    
    ... ... @@ -696,7 +725,7 @@
    696 725
           break;
    
    697 726
     
    
    698 727
         case FT_ENCODING_UNICODE:
    
    699
    -      font->num_indices = 0x110000L;
    
    728
    +      font->num_indices = get_last_char( face, index, 0x110000 ) + 1;
    
    700 729
           break;
    
    701 730
     
    
    702 731
         case FT_ENCODING_ADOBE_LATIN_1:
    
    ... ... @@ -704,16 +733,16 @@
    704 733
         case FT_ENCODING_ADOBE_EXPERT:
    
    705 734
         case FT_ENCODING_ADOBE_CUSTOM:
    
    706 735
         case FT_ENCODING_APPLE_ROMAN:
    
    707
    -      font->num_indices = 0x100L;
    
    736
    +      font->num_indices = 0x100;
    
    708 737
           break;
    
    709 738
     
    
    710 739
         /* some fonts use range 0x00-0x100, others have 0xF000-0xF0FF */
    
    711 740
         case FT_ENCODING_MS_SYMBOL:
    
    712
    -      font->num_indices = 0x10000L;
    
    741
    +      font->num_indices = get_last_char( face, index, 0x10000 ) + 1;
    
    713 742
           break;
    
    714 743
     
    
    715 744
         default:
    
    716
    -      font->num_indices = 0x10000L;
    
    745
    +      font->num_indices = get_last_char( face, index, 0x10000 ) + 1;
    
    717 746
         }
    
    718 747
       }
    
    719 748
     
    

  • src/ftview.c
    ... ... @@ -1573,6 +1573,15 @@
    1573 1573
           }
    
    1574 1574
         }
    
    1575 1575
     
    
    1576
    +    /* Last index or charcode */
    
    1577
    +    snprintf( buf, sizeof ( buf ),
    
    1578
    +              handle->encoding == FT_ENCODING_ORDER   ? "last: %d" :
    
    1579
    +              handle->encoding == FT_ENCODING_UNICODE ? "last: U+%04X" :
    
    1580
    +                                                        "last: 0x%X",
    
    1581
    +              handle->current_font->num_indices - 1 );
    
    1582
    +    grWriteCellString( display->bitmap, 0, display->bitmap->rows - GR_FONT_SIZE,
    
    1583
    +                       buf, display->fore_color );
    
    1584
    +
    
    1576 1585
         grRefreshSurface( display->surface );
    
    1577 1586
       }
    
    1578 1587
     
    


  • reply via email to

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