From c817992f495cba21bf468014f22afe349fbc799f Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Thu, 3 May 2018 10:53:20 -0700 Subject: [PATCH] [subset] Write out a format 4, plat 0 encoding record to match fontTools. --- src/hb-ot-cmap-table.hh | 24 +++++++++++++++--------- test/api/test-subset-cmap.c | 2 +- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 7e42b4fc8..883ac3a5f 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -764,7 +764,7 @@ struct cmap inline size_t final_size() const { return 4 // header - + 8 * 2 // 2 EncodingRecord + + 8 * 3 // 3 EncodingRecord + CmapSubtableFormat4::get_sub_table_size (this->format4_segments) + CmapSubtableFormat12::get_sub_table_size (this->format12_groups); } @@ -807,24 +807,30 @@ struct cmap cmap->version.set (0); - if (unlikely (!cmap->encodingRecord.serialize (&c, /* numTables */ 2))) + if (unlikely (!cmap->encodingRecord.serialize (&c, /* numTables */ 3))) return false; // TODO(grieger): Convert the below to a for loop - // Format 4 Encoding Record - EncodingRecord &format4_rec = cmap->encodingRecord[0]; - format4_rec.platformID.set (3); // Windows - format4_rec.encodingID.set (1); // Unicode BMP + // Format 4, Plat 0 Encoding Record + EncodingRecord &format4_plat0_rec = cmap->encodingRecord[0]; + format4_plat0_rec.platformID.set (0); // Unicode + format4_plat0_rec.encodingID.set (3); + + // Format 4, Plat 3 Encoding Record + EncodingRecord &format4_plat3_rec = cmap->encodingRecord[1]; + format4_plat3_rec.platformID.set (3); // Windows + format4_plat3_rec.encodingID.set (1); // Unicode BMP // Format 12 Encoding Record - EncodingRecord &format12_rec = cmap->encodingRecord[1]; + EncodingRecord &format12_rec = cmap->encodingRecord[2]; format12_rec.platformID.set (3); // Windows format12_rec.encodingID.set (10); // Unicode UCS-4 - // Write out format 4 sub table. + // Write out format 4 sub table { - CmapSubtable &subtable = format4_rec.subtable.serialize (&c, cmap); + CmapSubtable &subtable = format4_plat0_rec.subtable.serialize (&c, cmap); + format4_plat3_rec.subtable.set (format4_plat0_rec.subtable); subtable.u.format.set (4); CmapSubtableFormat4 &format4 = subtable.u.format4; diff --git a/test/api/test-subset-cmap.c b/test/api/test-subset-cmap.c index 52548742d..8c5193870 100644 --- a/test/api/test-subset-cmap.c +++ b/test/api/test-subset-cmap.c @@ -33,7 +33,7 @@ static void test_subset_cmap (void) { hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Roboto-Regular.abc.ttf"); - hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.cmap-format12-only.ttf"); + hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Roboto-Regular.ac.ttf"); hb_set_t *codepoints = hb_set_create (); hb_face_t *face_abc_subset;