freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype-demos][master] 4 commits: * src/output.c: Handle


From: Werner Lemberg (@wl)
Subject: [Git][freetype/freetype-demos][master] 4 commits: * src/output.c: Handle `\0` specially.
Date: Mon, 08 May 2023 04:54:04 +0000

Werner Lemberg pushed to branch master at FreeType / FreeType Demo Programs

Commits:

  • cca8c1cc
    by Werner Lemberg at 2023-05-08T04:53:01+00:00
    * src/output.c: Handle `\0` specially.
    
    Broken or intentionally invalidated fonts might contain NULL bytes at
    arbitrary places.
    
  • 2c53b921
    by Werner Lemberg at 2023-05-08T04:53:01+00:00
    [ftdump] Code cleanup.
    
    * src/ftdump.c (Print_MM_Axes): Move code to find an English name entry
    to...
    (get_english_name_entry): ... this new function.
    
  • 381fe118
    by Werner Lemberg at 2023-05-08T04:53:01+00:00
    [ftdump] Show more variation font info.
    
    * src/ftdump.c (Print_MM_Axes): Rename to...
    (Print_MM_Info): ...this.
    Show Variation Font PostScript name prefix.
    Show named instances.
    
  • c7c92e58
    by Werner Lemberg at 2023-05-08T04:53:01+00:00
    * src/ftdump.c (Print_Sfnt_Tables): Insert spaces between bytes.
    

2 changed files:

Changes:

  • src/ftdump.c
    ... ... @@ -687,7 +687,7 @@
    687 687
           else
    
    688 688
             continue;
    
    689 689
     
    
    690
    -      printf( "  %2lu: %c%c%c%c %02X%02X%02X%02X...\n", i,
    
    690
    +      printf( "  %2lu: %c%c%c%c   %02X %02X %02X %02X ...\n", i,
    
    691 691
                                        (FT_Char)( tag >> 24 ),
    
    692 692
                                        (FT_Char)( tag >> 16 ),
    
    693 693
                                        (FT_Char)( tag >>  8 ),
    
    ... ... @@ -838,19 +838,53 @@
    838 838
     
    
    839 839
     
    
    840 840
       static void
    
    841
    -  Print_MM_Axes( FT_Face  face )
    
    841
    +  get_english_name_entry( FT_Face       face,
    
    842
    +                          FT_UInt       strid,
    
    843
    +                          FT_SfntName*  entry )
    
    844
    +  {
    
    845
    +    FT_UInt  num_names = FT_Get_Sfnt_Name_Count( face );
    
    846
    +    FT_UInt  i;
    
    847
    +
    
    848
    +    FT_SfntName  name;
    
    849
    +
    
    850
    +
    
    851
    +    for ( i = 0; i < num_names; i++ )
    
    852
    +    {
    
    853
    +      error = FT_Get_Sfnt_Name( face, i, &name );
    
    854
    +      if ( error )
    
    855
    +        continue;
    
    856
    +
    
    857
    +      if ( name.name_id == strid )
    
    858
    +      {
    
    859
    +        /* XXX we don't have support for Apple's new `ltag' table yet, */
    
    860
    +        /* thus we ignore TT_PLATFORM_APPLE_UNICODE                    */
    
    861
    +        if ( ( name.platform_id == TT_PLATFORM_MACINTOSH &&
    
    862
    +               name.language_id == TT_MAC_LANGID_ENGLISH )        ||
    
    863
    +             ( name.platform_id == TT_PLATFORM_MICROSOFT        &&
    
    864
    +               ( name.language_id & 0xFF )
    
    865
    +                                == TT_MS_LANGID_ENGLISH_GENERAL ) )
    
    866
    +          break;
    
    867
    +      }
    
    868
    +    }
    
    869
    +
    
    870
    +    if ( i < num_names )
    
    871
    +      *entry = name;
    
    872
    +  }
    
    873
    +
    
    874
    +
    
    875
    +  static void
    
    876
    +  Print_MM_Info( FT_Face  face )
    
    842 877
       {
    
    843 878
         FT_MM_Var*       mm;
    
    844 879
         FT_Multi_Master  dummy;
    
    845
    -    FT_UInt          is_GX, i, num_names;
    
    880
    +    FT_SfntName      name;
    
    881
    +    FT_UInt          is_GX, i;
    
    846 882
     
    
    847 883
     
    
    848 884
         /* MM or GX axes */
    
    849 885
         error = FT_Get_Multi_Master( face, &dummy );
    
    850 886
         is_GX = error ? 1 : 0;
    
    851 887
     
    
    852
    -    printf( "%s axes\n", is_GX ? "GX" : "MM" );
    
    853
    -
    
    854 888
         error = FT_Get_MM_Var( face, &mm );
    
    855 889
         if ( error )
    
    856 890
         {
    
    ... ... @@ -858,60 +892,134 @@
    858 892
           return;
    
    859 893
         }
    
    860 894
     
    
    861
    -    num_names = FT_Get_Sfnt_Name_Count( face );
    
    895
    +    printf( "%s info\n", is_GX ? "GX" : "MM" );
    
    896
    +
    
    897
    +    printf( "  axes (%u)\n", mm->num_axis );
    
    862 898
     
    
    863 899
         for ( i = 0; i < mm->num_axis; i++ )
    
    864 900
         {
    
    865
    -      FT_SfntName  name;
    
    866
    -
    
    867
    -
    
    868 901
           name.string = NULL;
    
    869 902
     
    
    870 903
           if ( is_GX )
    
    871
    -      {
    
    872
    -        FT_UInt  strid = mm->axis[i].strid;
    
    873
    -        FT_UInt  j;
    
    874
    -
    
    875
    -
    
    876
    -        /* iterate over all name entries        */
    
    877
    -        /* to find an English entry for `strid' */
    
    878
    -
    
    879
    -        for ( j = 0; j < num_names; j++ )
    
    880
    -        {
    
    881
    -          error = FT_Get_Sfnt_Name( face, j, &name );
    
    882
    -          if ( error )
    
    883
    -            continue;
    
    884
    -
    
    885
    -          if ( name.name_id == strid )
    
    886
    -          {
    
    887
    -            /* XXX we don't have support for Apple's new `ltag' table yet, */
    
    888
    -            /* thus we ignore TT_PLATFORM_APPLE_UNICODE                    */
    
    889
    -            if ( ( name.platform_id == TT_PLATFORM_MACINTOSH &&
    
    890
    -                   name.language_id == TT_MAC_LANGID_ENGLISH )        ||
    
    891
    -                 ( name.platform_id == TT_PLATFORM_MICROSOFT        &&
    
    892
    -                   ( name.language_id & 0xFF )
    
    893
    -                                    == TT_MS_LANGID_ENGLISH_GENERAL ) )
    
    894
    -              break;
    
    895
    -          }
    
    896
    -        }
    
    897
    -      }
    
    904
    +        get_english_name_entry( face, mm->axis[i].strid, &name );
    
    898 905
     
    
    906
    +      printf( "    %u: ", i );
    
    899 907
           if ( name.string )
    
    900 908
           {
    
    901 909
             if ( name.platform_id == TT_PLATFORM_MACINTOSH )
    
    902
    -          put_ascii( name.string, name.string_len, 3 );
    
    910
    +          put_ascii( name.string, name.string_len, 0 );
    
    903 911
             else
    
    904
    -          put_unicode_be16( name.string, name.string_len, 3, utf8 );
    
    912
    +          put_unicode_be16( name.string, name.string_len, 0, utf8 );
    
    905 913
           }
    
    906 914
           else
    
    907
    -        printf( "   %s", mm->axis[i].name );
    
    915
    +        printf( "%s", mm->axis[i].name );
    
    908 916
     
    
    909
    -      printf( ": [%g;%g], default %g\n",
    
    917
    +      printf( ", [%g;%g], default %g\n",
    
    910 918
                   mm->axis[i].minimum / 65536.0,
    
    911 919
                   mm->axis[i].maximum / 65536.0,
    
    912 920
                   mm->axis[i].def / 65536.0 );
    
    913 921
         }
    
    914 922
     
    
    923
    +    if ( is_GX )
    
    924
    +    {
    
    925
    +      FT_Fixed*    coords;
    
    926
    +      const char*  ps_name;
    
    927
    +
    
    928
    +      FT_Long              instance_count;
    
    929
    +      FT_UInt              default_named_instance;
    
    930
    +      FT_Var_Named_Style*  named_styles;
    
    931
    +
    
    932
    +
    
    933
    +      /* Show Variation PostScript Name Prefix. */
    
    934
    +
    
    935
    +      coords = (FT_Fixed*)malloc( mm->num_axis * sizeof ( FT_Fixed ) );
    
    936
    +      if ( coords == NULL )
    
    937
    +        return;
    
    938
    +
    
    939
    +      /* We temporarily activate variation font handling.  Because we */
    
    940
    +      /* use the default axes, the now retrieved PS name is identical */
    
    941
    +      /* to the PS name prefix.                                       */
    
    942
    +      FT_Get_Var_Design_Coordinates( face, mm->num_axis, coords );
    
    943
    +      FT_Set_Var_Design_Coordinates( face, mm->num_axis, coords );
    
    944
    +
    
    945
    +      ps_name = FT_Get_Postscript_Name( face );
    
    946
    +      if ( ps_name == NULL )
    
    947
    +        ps_name = "UNAVAILABLE";
    
    948
    +
    
    949
    +      printf( "\n"
    
    950
    +              "  VF PS name prefix: %s\n", ps_name );
    
    951
    +
    
    952
    +      /* Switch off variation font handling. */
    
    953
    +      FT_Set_Var_Design_Coordinates( face, 0, NULL );
    
    954
    +
    
    955
    +      free( coords );
    
    956
    +
    
    957
    +
    
    958
    +      /* Show named instances. */
    
    959
    +
    
    960
    +      instance_count = face->style_flags >> 16;
    
    961
    +      named_styles   = mm->namedstyle;
    
    962
    +
    
    963
    +      FT_Get_Default_Named_Instance( face, &default_named_instance );
    
    964
    +      default_named_instance--;   /* `named_styles` is a zero-based array */
    
    965
    +
    
    966
    +      printf( "\n" );
    
    967
    +      printf( "  named instances (%lu)\n", instance_count );
    
    968
    +
    
    969
    +      for ( i = 0; i < instance_count; i++ )
    
    970
    +      {
    
    971
    +        int        pos;
    
    972
    +        FT_UInt    j;
    
    973
    +        FT_Bool    semicolon;
    
    974
    +        FT_Fixed*  c;
    
    975
    +
    
    976
    +
    
    977
    +        /* Since FreeType starts the instance numbering with value 1 */
    
    978
    +        /* in `face_index` we report the same here for consistency.  */
    
    979
    +        pos = printf( "    %u: ", i + 1);
    
    980
    +
    
    981
    +        name.string = NULL;
    
    982
    +        get_english_name_entry( face, named_styles[i].strid, &name );
    
    983
    +        if ( name.string )
    
    984
    +        {
    
    985
    +          if ( name.platform_id == TT_PLATFORM_MACINTOSH )
    
    986
    +            put_ascii( name.string, name.string_len, 0 );
    
    987
    +          else
    
    988
    +            put_unicode_be16( name.string, name.string_len, 0, utf8 );
    
    989
    +        }
    
    990
    +        else
    
    991
    +          printf( "UNAVAILABLE" );
    
    992
    +        printf( "%s\n", i == default_named_instance ? " (default)" : "" );
    
    993
    +
    
    994
    +        name.string = NULL;
    
    995
    +        get_english_name_entry( face, named_styles[i].psid, &name );
    
    996
    +        printf( "%*s   PS: ", pos, "" );
    
    997
    +        if ( name.string )
    
    998
    +        {
    
    999
    +          if ( name.platform_id == TT_PLATFORM_MACINTOSH )
    
    1000
    +            put_ascii( name.string, name.string_len, 0 );
    
    1001
    +          else
    
    1002
    +            put_unicode_be16( name.string, name.string_len, 0, utf8 );
    
    1003
    +        }
    
    1004
    +        else
    
    1005
    +          printf( "UNAVAILABLE" );
    
    1006
    +        printf( "\n" );
    
    1007
    +
    
    1008
    +        semicolon = 0;
    
    1009
    +        c         = named_styles[i].coords;
    
    1010
    +
    
    1011
    +        printf( "%*scoord: (", pos, "" );
    
    1012
    +        for ( j = 0; j < mm->num_axis; j++ )
    
    1013
    +        {
    
    1014
    +          printf( "%s%g", semicolon ? ";" : "", c[j] / 65536.0);
    
    1015
    +          semicolon = 1;
    
    1016
    +        }
    
    1017
    +        printf( ")\n" );
    
    1018
    +      }
    
    1019
    +
    
    1020
    +      printf( "\n" );
    
    1021
    +    }
    
    1022
    +
    
    915 1023
         FT_Done_MM_Var( face->glyph->library, mm );
    
    916 1024
       }
    
    917 1025
     
    
    ... ... @@ -1485,7 +1593,7 @@
    1485 1593
           if ( FT_HAS_MULTIPLE_MASTERS( face ) )
    
    1486 1594
           {
    
    1487 1595
             printf( "\n" );
    
    1488
    -        Print_MM_Axes( face );
    
    1596
    +        Print_MM_Info( face );
    
    1489 1597
           }
    
    1490 1598
     
    
    1491 1599
           FT_Done_Face( face );
    

  • src/output.c
    ... ... @@ -37,6 +37,11 @@
    37 37
         {
    
    38 38
           switch ( string[i] )
    
    39 39
           {
    
    40
    +      case '\0':
    
    41
    +        *out++ = '\\';
    
    42
    +        *out++ = '0';
    
    43
    +        break;
    
    44
    +
    
    40 45
           case '\n':
    
    41 46
             *out++ = '\\';
    
    42 47
             *out++ = 'n';
    
    ... ... @@ -125,6 +130,7 @@
    125 130
             }
    
    126 131
             break;
    
    127 132
     
    
    133
    +      case '\0':
    
    128 134
           case '\r':
    
    129 135
           case '\t':
    
    130 136
           case '\\':
    
    ... ... @@ -196,6 +202,11 @@
    196 202
     
    
    197 203
           switch ( ch )
    
    198 204
           {
    
    205
    +      case '\0':
    
    206
    +        *out++ = '\\';
    
    207
    +        *out++ = '0';
    
    208
    +        continue;
    
    209
    +
    
    199 210
           case '\n':
    
    200 211
             *out++ = '\\';
    
    201 212
             *out++ = 'n';
    
    ... ... @@ -350,6 +361,7 @@
    350 361
             }
    
    351 362
             continue;
    
    352 363
     
    
    364
    +      case '\0':
    
    353 365
           case '\r':
    
    354 366
           case '\t':
    
    355 367
           case '\\':
    


  • reply via email to

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