@@ -32,17 +32,14 @@ namespace woff2 {
3232
3333namespace {
3434
35- using std::string;
36- using std::vector;
37-
38-
3935// simple glyph flags
4036const int kGlyfOnCurve = 1 << 0 ;
4137const int kGlyfXShort = 1 << 1 ;
4238const int kGlyfYShort = 1 << 2 ;
4339const int kGlyfRepeat = 1 << 3 ;
4440const int kGlyfThisXIsSame = 1 << 4 ;
4541const int kGlyfThisYIsSame = 1 << 5 ;
42+ const int kOverlapSimple = 1 << 6 ;
4643
4744// composite glyph flags
4845// See CompositeGlyph.java in sfntly for full definitions
@@ -53,6 +50,9 @@ const int FLAG_WE_HAVE_AN_X_AND_Y_SCALE = 1 << 6;
5350const int FLAG_WE_HAVE_A_TWO_BY_TWO = 1 << 7 ;
5451const int FLAG_WE_HAVE_INSTRUCTIONS = 1 << 8 ;
5552
53+ // glyf flags
54+ const int FLAG_OVERLAP_SIMPLE_BITMAP = 1 << 0 ;
55+
5656const size_t kCheckSumAdjustmentOffset = 8 ;
5757
5858const size_t kEndPtsOfContoursOffset = 10 ;
@@ -191,8 +191,9 @@ bool TripletDecode(const uint8_t* flags_in, const uint8_t* in, size_t in_size,
191191// This function stores just the point data. On entry, dst points to the
192192// beginning of a simple glyph. Returns true on success.
193193bool StorePoints (unsigned int n_points, const Point* points,
194- unsigned int n_contours, unsigned int instruction_length,
195- uint8_t * dst, size_t dst_size, size_t * glyph_size) {
194+ unsigned int n_contours, unsigned int instruction_length,
195+ bool has_overlap_bit, uint8_t * dst, size_t dst_size,
196+ size_t * glyph_size) {
196197 // I believe that n_contours < 65536, in which case this is safe. However, a
197198 // comment and/or an assert would be good.
198199 unsigned int flag_offset = kEndPtsOfContoursOffset + 2 * n_contours + 2 +
@@ -207,6 +208,10 @@ bool StorePoints(unsigned int n_points, const Point* points,
207208 for (unsigned int i = 0 ; i < n_points; ++i) {
208209 const Point& point = points[i];
209210 int flag = point.on_curve ? kGlyfOnCurve : 0 ;
211+ if (has_overlap_bit && i == 0 ) {
212+ flag |= kOverlapSimple ;
213+ }
214+
210215 int dx = point.x - last_x;
211216 int dy = point.y - last_y;
212217 if (dx == 0 ) {
@@ -404,13 +409,20 @@ bool ReconstructGlyf(const uint8_t* data, Table* glyf_table,
404409 WOFF2Out* out) {
405410 static const int kNumSubStreams = 7 ;
406411 Buffer file (data, glyf_table->transform_length );
407- uint32_t version;
412+ uint16_t version;
408413 std::vector<std::pair<const uint8_t *, size_t > > substreams (kNumSubStreams );
409414 const size_t glyf_start = out->Size ();
410415
411- if (PREDICT_FALSE (!file.ReadU32 (&version))) {
416+ if (PREDICT_FALSE (!file.ReadU16 (&version))) {
417+ return FONT_COMPRESSION_FAILURE ();
418+ }
419+
420+ uint16_t flags;
421+ if (PREDICT_FALSE (!file.ReadU16 (&flags))) {
412422 return FONT_COMPRESSION_FAILURE ();
413423 }
424+ bool has_overlap_bitmap = (flags & FLAG_OVERLAP_SIMPLE_BITMAP);
425+
414426 if (PREDICT_FALSE (!file.ReadU16 (&info->num_glyphs ) ||
415427 !file.ReadU16 (&info->index_format ))) {
416428 return FONT_COMPRESSION_FAILURE ();
@@ -448,6 +460,17 @@ bool ReconstructGlyf(const uint8_t* data, Table* glyf_table,
448460 Buffer bbox_stream (substreams[5 ].first , substreams[5 ].second );
449461 Buffer instruction_stream (substreams[6 ].first , substreams[6 ].second );
450462
463+ const uint8_t * overlap_bitmap = nullptr ;
464+ unsigned int overlap_bitmap_length = 0 ;
465+ if (has_overlap_bitmap) {
466+ overlap_bitmap_length = (info->num_glyphs + 7 ) >> 3 ;
467+ overlap_bitmap = data + offset;
468+ if (PREDICT_FALSE (overlap_bitmap_length >
469+ glyf_table->transform_length - offset)) {
470+ return FONT_COMPRESSION_FAILURE ();
471+ }
472+ }
473+
451474 std::vector<uint32_t > loca_values (info->num_glyphs + 1 );
452475 std::vector<unsigned int > n_points_vec;
453476 std::unique_ptr<Point[]> points;
@@ -601,8 +624,12 @@ bool ReconstructGlyf(const uint8_t* data, Table* glyf_table,
601624 }
602625 glyph_size += instruction_size;
603626
604- if (PREDICT_FALSE (!StorePoints (total_n_points, points.get (), n_contours,
605- instruction_size, glyph_buf.get (), glyph_buf_size, &glyph_size))) {
627+ bool has_overlap_bit =
628+ has_overlap_bitmap && overlap_bitmap[i >> 3 ] & (0x80 >> (i & 7 ));
629+
630+ if (PREDICT_FALSE (!StorePoints (
631+ total_n_points, points.get (), n_contours, instruction_size,
632+ has_overlap_bit, glyph_buf.get (), glyph_buf_size, &glyph_size))) {
606633 return FONT_COMPRESSION_FAILURE ();
607634 }
608635 } else {
0 commit comments