freetype-commit
[Top][All Lists]
Advanced

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

[Git][freetype/freetype][master] [woff2] Support overlap flag for simple


From: Werner Lemberg (@wl)
Subject: [Git][freetype/freetype][master] [woff2] Support overlap flag for simple glyphs.
Date: Sun, 20 Mar 2022 07:38:31 +0000

Werner Lemberg pushed to branch master at FreeType / FreeType

Commits:

2 changed files:

Changes:

  • src/sfnt/sfwoff2.c
    ... ... @@ -84,6 +84,8 @@
    84 84
     #define BBOX_STREAM         5
    
    85 85
     #define INSTRUCTION_STREAM  6
    
    86 86
     
    
    87
    +#define HAVE_OVERLAP_SIMPLE_BITMAP  0x1
    
    88
    +
    
    87 89
     
    
    88 90
       static void
    
    89 91
       stream_close( FT_Stream  stream )
    
    ... ... @@ -522,6 +524,7 @@
    522 524
                     const WOFF2_Point  points,
    
    523 525
                     FT_UShort          n_contours,
    
    524 526
                     FT_UShort          instruction_len,
    
    527
    +                FT_Bool            have_overlap,
    
    525 528
                     FT_Byte*           dst,
    
    526 529
                     FT_ULong           dst_size,
    
    527 530
                     FT_ULong*          glyph_size )
    
    ... ... @@ -549,6 +552,9 @@
    549 552
           FT_Int   dy   = point.y - last_y;
    
    550 553
     
    
    551 554
     
    
    555
    +      if ( i == 0 && have_overlap )
    
    556
    +        flag |= GLYF_OVERLAP_SIMPLE;
    
    557
    +
    
    552 558
           if ( dx == 0 )
    
    553 559
             flag |= GLYF_THIS_X_IS_SAME;
    
    554 560
           else if ( dx > -256 && dx < 256 )
    
    ... ... @@ -833,15 +839,18 @@
    833 839
     
    
    834 840
         FT_UInt  num_substreams = 7;
    
    835 841
     
    
    842
    +    FT_UShort  option_flags;
    
    836 843
         FT_UShort  num_glyphs;
    
    837 844
         FT_UShort  index_format;
    
    838 845
         FT_ULong   expected_loca_length;
    
    839 846
         FT_UInt    offset;
    
    840 847
         FT_UInt    i;
    
    841 848
         FT_ULong   points_size;
    
    842
    -    FT_ULong   bitmap_length;
    
    843 849
         FT_ULong   glyph_buf_size;
    
    844 850
         FT_ULong   bbox_bitmap_offset;
    
    851
    +    FT_ULong   bbox_bitmap_length;
    
    852
    +    FT_ULong   overlap_bitmap_offset = 0;
    
    853
    +    FT_ULong   overlap_bitmap_length = 0;
    
    845 854
     
    
    846 855
         const FT_ULong  glyf_start  = *out_offset;
    
    847 856
         FT_ULong        dest_offset = *out_offset;
    
    ... ... @@ -857,15 +866,17 @@
    857 866
         if ( FT_NEW_ARRAY( substreams, num_substreams ) )
    
    858 867
           goto Fail;
    
    859 868
     
    
    860
    -    if ( FT_STREAM_SKIP( 4 ) )
    
    869
    +    if ( FT_STREAM_SKIP( 2 ) )
    
    870
    +      goto Fail;
    
    871
    +    if ( FT_READ_USHORT( option_flags ) )
    
    861 872
           goto Fail;
    
    862 873
         if ( FT_READ_USHORT( num_glyphs ) )
    
    863 874
           goto Fail;
    
    864 875
         if ( FT_READ_USHORT( index_format ) )
    
    865 876
           goto Fail;
    
    866 877
     
    
    867
    -    FT_TRACE4(( "num_glyphs = %u; index_format = %u\n",
    
    868
    -                num_glyphs, index_format ));
    
    878
    +    FT_TRACE4(( "option_flags = %u; num_glyphs = %u; index_format = %u\n",
    
    879
    +                option_flags, num_glyphs, index_format ));
    
    869 880
     
    
    870 881
         info->num_glyphs = num_glyphs;
    
    871 882
     
    
    ... ... @@ -878,7 +889,7 @@
    878 889
         if ( info->loca_table->dst_length != expected_loca_length )
    
    879 890
           goto Fail;
    
    880 891
     
    
    881
    -    offset = ( 2 + num_substreams ) * 4;
    
    892
    +    offset = 2 + 2 + 2 + 2 + ( num_substreams * 4 );
    
    882 893
         if ( offset > info->glyf_table->TransformLength )
    
    883 894
           goto Fail;
    
    884 895
     
    
    ... ... @@ -901,6 +912,20 @@
    901 912
           offset += substream_size;
    
    902 913
         }
    
    903 914
     
    
    915
    +    if ( option_flags & HAVE_OVERLAP_SIMPLE_BITMAP )
    
    916
    +    {
    
    917
    +      /* Size of overlapBitmap = floor((numGlyphs + 7) / 8) */
    
    918
    +      overlap_bitmap_length = ( num_glyphs + 7U ) >> 3;
    
    919
    +      if ( overlap_bitmap_length > info->glyf_table->TransformLength - offset )
    
    920
    +        goto Fail;
    
    921
    +
    
    922
    +      overlap_bitmap_offset = pos + offset;
    
    923
    +
    
    924
    +      FT_TRACE5(( "  Overlap bitmap: offset = %lu; size = %lu;\n",
    
    925
    +                  overlap_bitmap_offset, overlap_bitmap_length ));
    
    926
    +      offset += overlap_bitmap_length;
    
    927
    +    }
    
    928
    +
    
    904 929
         if ( FT_NEW_ARRAY( loca_values, num_glyphs + 1 ) )
    
    905 930
           goto Fail;
    
    906 931
     
    
    ... ... @@ -908,8 +933,9 @@
    908 933
         bbox_bitmap_offset = substreams[BBOX_STREAM].offset;
    
    909 934
     
    
    910 935
         /* Size of bboxBitmap = 4 * floor((numGlyphs + 31) / 32) */
    
    911
    -    bitmap_length                   = ( ( num_glyphs + 31U ) >> 5 ) << 2;
    
    912
    -    substreams[BBOX_STREAM].offset += bitmap_length;
    
    936
    +    bbox_bitmap_length              = ( ( num_glyphs + 31U ) >> 5 ) << 2;
    
    937
    +    /* bboxStreamSize is the combined size of bboxBitmap and bboxStream. */
    
    938
    +    substreams[BBOX_STREAM].offset += bbox_bitmap_length;
    
    913 939
     
    
    914 940
         glyph_buf_size = WOFF2_DEFAULT_GLYPH_BUF;
    
    915 941
         if ( FT_NEW_ARRAY( glyph_buf, glyph_buf_size ) )
    
    ... ... @@ -1025,8 +1051,11 @@
    1025 1051
             FT_ULong   flag_size;
    
    1026 1052
             FT_ULong   triplet_size;
    
    1027 1053
             FT_ULong   triplet_bytes_used;
    
    1028
    -        FT_Byte*   flags_buf   = NULL;
    
    1029
    -        FT_Byte*   triplet_buf = NULL;
    
    1054
    +        FT_Bool    have_overlap  = FALSE;
    
    1055
    +        FT_Byte    overlap_bitmap;
    
    1056
    +        FT_ULong   overlap_offset;
    
    1057
    +        FT_Byte*   flags_buf     = NULL;
    
    1058
    +        FT_Byte*   triplet_buf   = NULL;
    
    1030 1059
             FT_UShort  instruction_size;
    
    1031 1060
             FT_ULong   size_needed;
    
    1032 1061
             FT_Int     end_point;
    
    ... ... @@ -1035,6 +1064,17 @@
    1035 1064
             FT_Byte*   pointer = NULL;
    
    1036 1065
     
    
    1037 1066
     
    
    1067
    +        /* Set `have_overlap`. */
    
    1068
    +        if ( overlap_bitmap_offset )
    
    1069
    +        {
    
    1070
    +          overlap_offset = overlap_bitmap_offset + ( i >> 3 );
    
    1071
    +          if ( FT_STREAM_SEEK( overlap_offset ) ||
    
    1072
    +               FT_READ_BYTE( overlap_bitmap )   )
    
    1073
    +            goto Fail;
    
    1074
    +          if ( overlap_bitmap & ( 0x80 >> ( i & 7 ) ) )
    
    1075
    +            have_overlap = TRUE;
    
    1076
    +        }
    
    1077
    +
    
    1038 1078
             if ( FT_NEW_ARRAY( n_points_arr, n_contours ) )
    
    1039 1079
               goto Fail;
    
    1040 1080
     
    
    ... ... @@ -1155,6 +1195,7 @@
    1155 1195
                                points,
    
    1156 1196
                                n_contours,
    
    1157 1197
                                instruction_size,
    
    1198
    +                           have_overlap,
    
    1158 1199
                                glyph_buf,
    
    1159 1200
                                glyph_buf_size,
    
    1160 1201
                                &glyph_size ) )
    

  • src/sfnt/sfwoff2.h
    ... ... @@ -56,6 +56,7 @@ FT_BEGIN_HEADER
    56 56
     #define GLYF_REPEAT          1 << 3
    
    57 57
     #define GLYF_THIS_X_IS_SAME  1 << 4
    
    58 58
     #define GLYF_THIS_Y_IS_SAME  1 << 5
    
    59
    +#define GLYF_OVERLAP_SIMPLE  1 << 6
    
    59 60
     
    
    60 61
       /* Other constants */
    
    61 62
     #define CONTOUR_OFFSET_END_POINT  10
    


  • reply via email to

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