From 62c7d677e8699143e55e7bfa0cc3c1db75f32506 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 10:09:35 -0800 Subject: [PATCH 01/40] C-style comments --- src/hb-open-file-private.hh | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh index ae30655a3..f01ab8718 100644 --- a/src/hb-open-file-private.hh +++ b/src/hb-open-file-private.hh @@ -133,15 +133,16 @@ typedef struct OffsetTable unsigned int table_count) { TRACE_SERIALIZE (this); - // alloc 12 for the OTHeader + /* alloc 12 for the OTHeader */ if (unlikely (!c->extend_min (*this))) return_trace (false); - // write sfntVersion (bytes 0..3) + /* write sfntVersion (bytes 0..3) */ sfnt_version.set (sfnt_tag); - // take space for numTables, searchRange, entrySelector, RangeShift - // and the TableRecords themselves + /* take space for numTables, searchRange, entrySelector, RangeShift + * and the TableRecords themselves + */ if (unlikely (!tables.serialize (c, table_count))) return_trace (false); - // write OffsetTables, alloc for and write actual table blobs + /* write OffsetTables, alloc for and write actual table blobs */ for (unsigned int i = 0; i < table_count; i++) { TableRecord &rec = tables.array[i]; @@ -153,9 +154,9 @@ typedef struct OffsetTable // take room for the table void *p = c->allocate_size (rec.length); if (unlikely (!p)) {return false;} - // copy the actual table + /* copy the actual table */ memcpy (p, hb_blob_get_data (blob, nullptr), rec.length); - // 4-byte allignment + /* 4-byte allignment */ if (rec.length % 4) p = c->allocate_size (4 - rec.length % 4); } From ebd31d376d63c9698c0eae34ed295558f7230918 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 10:10:08 -0800 Subject: [PATCH 02/40] subset for real --- src/hb-subset.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 946006173..7b6b932fb 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -365,7 +365,5 @@ hb_subset (hb_face_t *source, } } while (count == ARRAY_LENGTH (table_tags)); - // TODO(grieger): Remove once basic subsetting is working + tests updated. - hb_face_destroy (dest); - return success ? hb_face_reference (source) : hb_face_get_empty (); + return success ? dest : hb_face_get_empty (); } From 0301e5be286f5080ec34e9f30c75e73f28d0218b Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 10:12:11 -0800 Subject: [PATCH 03/40] Build a working cmap format 12 --- src/hb-ot-cmap-table.hh | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 030b822b0..c338371fd 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -573,18 +573,29 @@ struct cmap rec.platformID.set (3); // Windows rec.encodingID.set (1); // Unicode BMP - CmapSubtable &subtable = rec.subtable.serialize(&context, &rec.subtable); + /* capture offset to subtable */ + CmapSubtable &subtable = rec.subtable.serialize(&context, cmap); + subtable.u.format.set(12); CmapSubtableFormat12 &format12 = subtable.u.format12; + if (unlikely(!context.extend_min(format12))) + { + return false; + } + format12.format.set(12); format12.reservedZ.set(0); + format12.lengthZ.set(16 + 12 * groups.len); OT::Supplier group_supplier (&groups[0], groups.len, sizeof (CmapSubtableLongGroup)); if (unlikely(!format12.serialize(&context, groups.len, group_supplier))) + { return false; + } context.end_serialize (); + return true; } From 5df080bf155a12f98929b99438da492063ab9218 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 10:15:59 -0800 Subject: [PATCH 04/40] Destroy the subset plan at the end of subsetting. --- src/hb-subset.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 7b6b932fb..13acb8c98 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -365,5 +365,6 @@ hb_subset (hb_face_t *source, } } while (count == ARRAY_LENGTH (table_tags)); + hb_subset_plan_destroy (plan); return success ? dest : hb_face_get_empty (); } From 427f9e4b90bfadb8af13cbd27b7c3ee0153ca8b1 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 11:18:28 -0800 Subject: [PATCH 05/40] Don't force loca version to long. --- src/hb-subset-glyf.cc | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc index 952946786..cd886ea70 100644 --- a/src/hb-subset-glyf.cc +++ b/src/hb-subset-glyf.cc @@ -183,7 +183,5 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan, loca_prime); glyf.fini(); - *use_short_loca = false; - return result; } From 83e1ef92156d8688b96d14957efcdf7601768799 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 11:22:32 -0800 Subject: [PATCH 06/40] [subset] Set the new number of glyphs in maxp. --- src/hb-ot-maxp-table.hh | 5 +++++ src/hb-subset.cc | 37 ++++++++++++++++++++++++++++++++----- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 54b4f11ce..fb2209c40 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -48,6 +48,11 @@ struct maxp return numGlyphs; } + inline void set_num_glyphs (uint16_t count) + { + numGlyphs.set (count); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 13acb8c98..cacee706c 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -36,6 +36,8 @@ #include "hb-open-file-private.hh" #include "hb-ot-cmap-table.hh" #include "hb-ot-glyf-table.hh" +#include "hb-ot-head-table.hh" +#include "hb-ot-maxp-table.hh" #ifndef HB_NO_VISIBILITY @@ -265,19 +267,42 @@ _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_ hb_blob_t *head_prime_blob = hb_blob_create ((const char*) head_prime, OT::head::static_size, - HB_MEMORY_MODE_WRITABLE, + HB_MEMORY_MODE_READONLY, head_prime, free); - has_head = has_head && hb_subset_face_add_table (dest, HB_OT_TAG_head, head_prime_blob); - + has_head = hb_subset_face_add_table (dest, HB_OT_TAG_head, head_prime_blob); hb_blob_destroy (head_prime_blob); } hb_blob_destroy (head_blob); - return has_head; } +static bool +_add_maxp_and_set_glyph_count (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) +{ + hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp)); + const OT::maxp *maxp = OT::Sanitizer::lock_instance (maxp_blob); + bool has_maxp = (maxp != nullptr); + if (has_maxp) { + unsigned int length = hb_blob_get_length (maxp_blob); + OT::maxp *maxp_prime = (OT::maxp *) calloc (length, 1); + memcpy (maxp_prime, maxp, length); + maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len); + + hb_blob_t *maxp_prime_blob = hb_blob_create ((const char*) maxp_prime, + length, + HB_MEMORY_MODE_READONLY, + maxp_prime, + free); + has_maxp = hb_subset_face_add_table (dest, HB_OT_TAG_maxp, maxp_prime_blob); + hb_blob_destroy (maxp_prime_blob); + } + + hb_blob_destroy (maxp_blob); + return has_maxp; +} + static bool _subset_glyf (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) { @@ -316,6 +341,8 @@ _subset_table (hb_subset_plan_t *plan, case HB_OT_TAG_head: // SKIP head, it's handled by glyf return true; + case HB_OT_TAG_maxp: + return _add_maxp_and_set_glyph_count (plan, source, dest); case HB_OT_TAG_loca: // SKIP loca, it's handle by glyf return true; @@ -325,7 +352,7 @@ _subset_table (hb_subset_plan_t *plan, default: dest_blob = source_blob; break; - } + } DEBUG_MSG(SUBSET, nullptr, "subset %c%c%c%c %s", HB_UNTAG(tag), dest_blob ? "ok" : "FAILED"); if (unlikely(!dest_blob)) return false; if (unlikely(!hb_subset_face_add_table (dest, tag, dest_blob))) return false; From 692f86e569847adb332186cbb08f344ebe41fa6c Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 11:29:23 -0800 Subject: [PATCH 07/40] drop GDEF, GPOS, GSUB, and dsig --- src/hb-subset.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index cacee706c..d9a4d1258 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -359,6 +359,20 @@ _subset_table (hb_subset_plan_t *plan, return true; } +static bool +_should_drop_table(hb_tag_t tag) +{ + switch (tag) { + case HB_TAG('G', 'D', 'E', 'F'): /* temporary */ + case HB_TAG('G', 'P', 'O', 'S'): /* temporary */ + case HB_TAG('G', 'S', 'U', 'B'): /* temporary */ + case HB_TAG('d', 's', 'i', 'g'): + return true; + default: + return false; + } +} + /** * hb_subset: * @source: font face data to be subset. @@ -386,6 +400,11 @@ hb_subset (hb_face_t *source, for (unsigned int i = 0; i < count; i++) { hb_tag_t tag = table_tags[i]; + if (_should_drop_table(tag)) + { + DEBUG_MSG(SUBSET, nullptr, "drop %c%c%c%c", HB_UNTAG(tag)); + continue; + } hb_blob_t *blob = hb_face_reference_table (source, tag); success = success && _subset_table (plan, source, tag, blob, dest); hb_blob_destroy (blob); From a5713bc2cb4a3fd71d3bc94b9f155339b09eb71a Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 11:30:45 -0800 Subject: [PATCH 08/40] we love all our groups --- src/hb-ot-cmap-table.hh | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c338371fd..b3a7b8b8e 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -528,18 +528,15 @@ struct cmap CmapSubtableLongGroup *group = nullptr; for (unsigned int i = 0; i < codepoints.len; i++) { hb_codepoint_t cp = codepoints[i]; - if (!group) + if (!group || cp - 1 != group->endCharCode) { group = groups->push(); group->startCharCode.set(cp); group->endCharCode.set(cp); group->glyphID.set(i); // index in codepoints is new gid - } else if (cp -1 == group->endCharCode) - { - group->endCharCode.set(cp); } else { - group = nullptr; + group->endCharCode.set(cp); } } From e8318188c0e53a267a01c45b0fc8d29ad775738a Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 11:38:28 -0800 Subject: [PATCH 09/40] [subset] Fix loca generation, was previously writing the original glyph starting offset. --- src/hb-subset-glyf.cc | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc index cd886ea70..28f5f0c57 100644 --- a/src/hb-subset-glyf.cc +++ b/src/hb-subset-glyf.cc @@ -86,6 +86,7 @@ _write_glyf_and_loca_prime (const OT::glyf::accelerator_t &glyf, hb_codepoint_t new_glyph_id = 0; + unsigned int current_offset = 0; unsigned int end_offset = 0; for (unsigned int i = 0; i < glyph_ids.len; i++) { unsigned int start_offset; @@ -96,15 +97,16 @@ _write_glyf_and_loca_prime (const OT::glyf::accelerator_t &glyf, int length = end_offset - start_offset; memcpy (glyf_prime_data_next, glyf_data + start_offset, length); - _write_loca_entry (i, start_offset, use_short_loca, loca_prime_data); + _write_loca_entry (i, current_offset, use_short_loca, loca_prime_data); glyf_prime_data_next += length; + current_offset += length; new_glyph_id++; } // Add the last loca entry which doesn't correspond to a specific glyph // but identifies the end of the last glyphs data. - _write_loca_entry (new_glyph_id, end_offset, use_short_loca, loca_prime_data); + _write_loca_entry (new_glyph_id, current_offset, use_short_loca, loca_prime_data); return true; } From d8d8bd8405ec0db781c4c2bbb7ebd6ff520b3c2d Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 13:33:55 -0800 Subject: [PATCH 10/40] [subset] Add some helper functions for writing tests around subsetting. --- test/api/Makefile.am | 2 +- test/api/hb-subset-test.h | 123 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 test/api/hb-subset-test.h diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 9cda5ef37..8c1c47572 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -16,7 +16,7 @@ if HAVE_GLIB AM_CPPFLAGS = -DSRCDIR="\"$(srcdir)\"" -I$(top_srcdir)/src/ -I$(top_builddir)/src/ $(GLIB_CFLAGS) LDADD = $(top_builddir)/src/libharfbuzz.la $(GLIB_LIBS) -EXTRA_DIST += hb-test.h +EXTRA_DIST += hb-test.h hb-subset-test.h check_PROGRAMS = $(TEST_PROGS) noinst_PROGRAMS = $(TEST_PROGS) diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h new file mode 100644 index 000000000..bc7016f05 --- /dev/null +++ b/test/api/hb-subset-test.h @@ -0,0 +1,123 @@ +/* + * Copyright © 2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Garret Rieger + */ + +#ifndef HB_SUBSET_TEST_H +#define HB_SUBSET_TEST_H + +#include + +#include "hb-test.h" + + +HB_BEGIN_DECLS + +static inline char * +hb_subset_test_read_file (const char *path, + size_t *length /* OUT */) +{ + FILE *fp = fopen (path, "rb"); + + size_t file_length = 0; + char *buffer = NULL; + if (fp && fseek (fp, 0, SEEK_END) == 0) { + file_length = ftell(fp); + rewind (fp); + } + + if (file_length > 0) { + buffer = (char *) calloc (file_length + 1, sizeof(char)); + if (fread (buffer, 1, file_length, fp) == file_length) { + *length = file_length; + } else { + free (buffer); + buffer = NULL; + } + } + + if (fp) + fclose(fp); + + return buffer; +} + +static inline hb_face_t * +hb_subset_test_open_font (const char *font_path) +{ +#if GLIB_CHECK_VERSION(2,37,2) + gchar* path = g_test_build_filename(G_TEST_DIST, font_path, NULL); +#else + gchar* path = g_strdup(fontFile); +#endif + + size_t length; + char *font_data = hb_subset_test_read_file(path, &length); + + if (font_data != NULL) { + hb_blob_t *blob = hb_blob_create (font_data, + length, + HB_MEMORY_MODE_READONLY, + font_data, + free); + hb_face_t *face = hb_face_create (blob, 0); + hb_blob_destroy (blob); + return face; + } + + return NULL; +} + +static inline hb_face_t * +hb_subset_test_create_subset (hb_face_t *source, + hb_set_t *codepoints) +{ + hb_subset_profile_t *profile = hb_subset_profile_create(); + hb_subset_input_t *input = hb_subset_input_create (codepoints); + hb_face_t *subset = hb_subset (source, profile, input); + g_assert (subset); + + hb_subset_profile_destroy (profile); + hb_subset_input_destroy (input); + return subset; +} + +static inline void +hb_subset_test_check (hb_face_t *expected, + hb_face_t *actual, + hb_tag_t table) +{ + hb_blob_t *glyf_expected_blob = hb_face_reference_table (expected, table); + hb_blob_t *glyf_actual_blob = hb_face_reference_table (actual, table); + int expected_length, actual_length; + g_assert_cmpmem(hb_blob_get_data (glyf_expected_blob, &expected_length), expected_length, + hb_blob_get_data (glyf_actual_blob, &actual_length), actual_length); + hb_blob_destroy (glyf_actual_blob); + hb_blob_destroy (glyf_expected_blob); +} + + +HB_END_DECLS + +#endif /* HB_SUBSET_TEST_H */ From 1714feef4f7ec9e758e65edcbe5d5591562f46ee Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 13:35:17 -0800 Subject: [PATCH 11/40] [subset] re-enable test-subset-glyf. Refactor to use common functions in hb-subset-test.h --- test/api/test-subset-glyf.c | 113 +++++++++--------------------------- 1 file changed, 29 insertions(+), 84 deletions(-) diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index fa41800b0..538960c54 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -27,114 +27,59 @@ #include #include "hb-test.h" - -static char * -read_file (const char *path, - size_t *length) -{ - FILE *fp = fopen (path, "rb"); - - size_t file_length = 0; - char *buffer = NULL; - if (fp && fseek (fp, 0, SEEK_END) == 0) { - file_length = ftell(fp); - rewind (fp); - } - - if (file_length > 0) { - buffer = (char *) calloc (file_length + 1, sizeof(char)); - if (fread (buffer, 1, file_length, fp) == file_length) { - *length = file_length; - } else { - free (buffer); - buffer = NULL; - } - } - - if (fp) - fclose(fp); - - return buffer; -} - -static hb_face_t * -open_font (const char *font_path) -{ -#if GLIB_CHECK_VERSION(2,37,2) - gchar* path = g_test_build_filename(G_TEST_DIST, font_path, NULL); -#else - gchar* path = g_strdup(fontFile); -#endif - - size_t length; - char *font_data = read_file(path, &length); - - if (font_data != NULL) { - hb_blob_t *blob = hb_blob_create (font_data, - length, - HB_MEMORY_MODE_READONLY, - font_data, - free); - hb_face_t *face = hb_face_create (blob, 0); - hb_blob_destroy (blob); - return face; - } - - return NULL; -} - +#include "hb-subset-test.h" /* Unit tests for hb-subset-glyf.h */ static void test_subset_glyf (void) { - hb_face_t *face_abc = open_font("fonts/Roboto-Regular.abc.ttf"); - hb_face_t *face_ac = open_font("fonts/Roboto-Regular.ac.ttf"); - hb_face_t *face_abc_subset; - hb_blob_t *glyf_expected_blob; - hb_blob_t *glyf_actual_blob; - hb_set_t *codepoints = hb_set_create(); - hb_subset_profile_t *profile = hb_subset_profile_create(); - hb_subset_input_t *input = hb_subset_input_create (codepoints); - + hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); g_assert (face_abc); + hb_face_t *face_ac = hb_subset_test_open_font("fonts/Roboto-Regular.ac.ttf"); g_assert (face_ac); + hb_set_t *codepoints = hb_set_create(); hb_set_add (codepoints, 97); hb_set_add (codepoints, 99); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); -#if 0 /* Enable when actually works. */ - face_abc_subset = hb_subset (face_abc, profile, input); - g_assert (face_abc_subset); - - glyf_expected_blob = hb_face_reference_table (face_ac, HB_TAG('g','l','y','f')); - glyf_actual_blob = hb_face_reference_table (face_abc_subset, HB_TAG('g','l','y','f')); - - // TODO(grieger): Uncomment below once this actually works. - //int expected_length, actual_length; - // g_assert_cmpmem(hb_blob_get_data (glyf_expected_blob, &expected_length), expected_length, - // hb_blob_get_data (glyf_actual_blob, &actual_length), actual_length); - - hb_blob_destroy (glyf_actual_blob); - hb_blob_destroy (glyf_expected_blob); + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f')); + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a')); hb_face_destroy (face_abc_subset); -#endif - - hb_subset_input_destroy (input); - hb_subset_profile_destroy (profile); - hb_set_destroy (codepoints); hb_face_destroy (face_abc); hb_face_destroy (face_ac); } +static void +test_subset_glyf_noop (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); + g_assert (face_abc); + + hb_set_t *codepoints = hb_set_create(); + hb_set_add (codepoints, 97); + hb_set_add (codepoints, 98); + hb_set_add (codepoints, 99); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('g','l','y','f')); + hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('l','o','c', 'a')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); +} + int main (int argc, char **argv) { hb_test_init (&argc, &argv); hb_test_add (test_subset_glyf); + hb_test_add (test_subset_glyf_noop); return hb_test_run(); } From 4cdd1b16c99f2681eb11d626c4408eebcc1672be Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 13:36:28 -0800 Subject: [PATCH 12/40] [subset] added todo in test-subset-glyf. --- test/api/test-subset-glyf.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index 538960c54..98e12339a 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -73,6 +73,8 @@ test_subset_glyf_noop (void) hb_face_destroy (face_abc); } +// TODO(grieger): test for long loca generation. + int main (int argc, char **argv) { From 1639bdd33122dc8e5522b95c37660273d1fc609e Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 13:40:42 -0800 Subject: [PATCH 13/40] [subset] Remove test-subset, testing is planned to be done at the table level here with test/subset covering the complete subsetting operation. --- test/api/Makefile.am | 1 - test/api/test-subset.c | 73 ------------------------------------------ 2 files changed, 74 deletions(-) delete mode 100644 test/api/test-subset.c diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 8c1c47572..e36b3fd57 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -29,7 +29,6 @@ TEST_PROGS = \ test-object \ test-set \ test-shape \ - test-subset \ test-subset-glyf \ test-unicode \ test-version \ diff --git a/test/api/test-subset.c b/test/api/test-subset.c deleted file mode 100644 index 4184a563f..000000000 --- a/test/api/test-subset.c +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright © 2011 Google, Inc. - * - * This is part of HarfBuzz, a text shaping library. - * - * Permission is hereby granted, without written agreement and without - * license or royalty fees, to use, copy, modify, and distribute this - * software and its documentation for any purpose, provided that the - * above copyright notice and the following two paragraphs appear in - * all copies of this software. - * - * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR - * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES - * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN - * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH - * DAMAGE. - * - * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, - * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND - * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS - * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO - * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. - * - * Google Author(s): Garret Rieger - */ - -#include "hb-test.h" - -/* Unit tests for hb-subset.h */ - -static const char test_data[] = { 0, 1, 0, 0, /* sfntVersion */ - 0, 0, /* numTables */ - 0, 0x10, /* searchRange */ - 0, 0, /* entrySelector */ - 0, 0, /* rangeShift */ - }; - -static void -test_subset (void) -{ - hb_blob_t *font_blob = hb_blob_create(test_data, sizeof(test_data), - HB_MEMORY_MODE_READONLY, NULL, NULL); - hb_face_t *face = hb_face_create(font_blob, 0); - - hb_subset_profile_t *profile = hb_subset_profile_create(); - hb_subset_input_t *input = hb_subset_input_create (hb_set_get_empty ()); - - hb_face_t *out_face = hb_subset(face, profile, input); - g_assert(out_face); - g_assert(out_face != hb_face_get_empty ()); - hb_blob_t *output = hb_face_reference_blob (out_face); - - unsigned int output_length; - const char *output_data = hb_blob_get_data(output, &output_length); - g_assert_cmpmem (test_data, sizeof (test_data), output_data, output_length); - - hb_blob_destroy(output); - hb_subset_input_destroy(input); - hb_subset_profile_destroy(profile); - hb_face_destroy(out_face); - hb_face_destroy(face); - hb_blob_destroy(font_blob); -} - -int -main (int argc, char **argv) -{ - hb_test_init (&argc, &argv); - - hb_test_add (test_subset); - - return hb_test_run(); -} From 1330edc4fe3ffbf18313d6432045606865c610c4 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 14:29:23 -0800 Subject: [PATCH 14/40] Use functions to get new gids. Avoid 0; fonttools drops it from cmap. --- src/hb-ot-cmap-table.hh | 24 ++++++++++++++++++------ src/hb-subset-plan.cc | 25 ++++++++++++++++++++----- src/hb-subset-plan.hh | 5 +++++ src/hb-subset.cc | 2 +- 4 files changed, 44 insertions(+), 12 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index b3a7b8b8e..4d32359df 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -522,18 +522,25 @@ struct cmap encodingRecord.sanitize (c, this)); } - inline void populate_groups(hb_prealloced_array_t &codepoints, - hb_prealloced_array_t *groups) const + inline hb_bool_t populate_groups(hb_subset_plan_t *plan, + hb_prealloced_array_t *groups) const { CmapSubtableLongGroup *group = nullptr; - for (unsigned int i = 0; i < codepoints.len; i++) { - hb_codepoint_t cp = codepoints[i]; + for (unsigned int i = 0; i < plan->codepoints.len; i++) { + + hb_codepoint_t cp = plan->codepoints[i]; if (!group || cp - 1 != group->endCharCode) { group = groups->push(); group->startCharCode.set(cp); group->endCharCode.set(cp); - group->glyphID.set(i); // index in codepoints is new gid + hb_codepoint_t new_gid; + if (unlikely(!hb_subset_plan_new_gid_for_codepoint(plan, cp, &new_gid))) + { + DEBUG_MSG(SUBSET, nullptr, "Unable to find new gid for %04x", cp); + return false; + } + group->glyphID.set(new_gid); } else { group->endCharCode.set(cp); @@ -545,6 +552,8 @@ struct cmap CmapSubtableLongGroup& group = (*groups)[i]; DEBUG_MSG(SUBSET, nullptr, " %d: U+%04X-U+%04X, gid %d-%d", i, (uint32_t) group.startCharCode, (uint32_t) group.endCharCode, (uint32_t) group.glyphID, (uint32_t) group.glyphID + ((uint32_t) group.endCharCode - (uint32_t) group.startCharCode)); } + + return true; } hb_bool_t _subset (hb_prealloced_array_t &groups, @@ -600,7 +609,10 @@ struct cmap { hb_auto_array_t groups; - populate_groups(plan->codepoints, &groups); + if (unlikely(!populate_groups(plan, &groups))) + { + return nullptr; + } // We now know how big our blob needs to be // TODO use APIs from the structs to get size? diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index a06d38ae5..cc12abcae 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -38,6 +38,24 @@ _hb_codepoint_t_cmp (const void *pa, const void *pb) return a < b ? -1 : a > b ? +1 : 0; } +hb_bool_t +hb_subset_plan_new_gid_for_codepoint (hb_subset_plan_t *plan, + hb_codepoint_t codepoint, + hb_codepoint_t *new_gid) +{ + // TODO actual map, delete this garbage. + for (unsigned int i = 0; i < plan->codepoints.len; i++) + { + if (plan->codepoints[i] != codepoint) continue; + if (!hb_subset_plan_new_gid_for_old_id(plan, plan->gids_to_retain[i], new_gid)) + { + return false; + } + return true; + } + return false; +} + hb_bool_t hb_subset_plan_new_gid_for_old_id (hb_subset_plan_t *plan, hb_codepoint_t old_gid, @@ -46,7 +64,8 @@ hb_subset_plan_new_gid_for_old_id (hb_subset_plan_t *plan, // the index in old_gids is the new gid; only up to codepoints.len are valid for (unsigned int i = 0; i < plan->gids_to_retain_sorted.len; i++) { if (plan->gids_to_retain_sorted[i] == old_gid) { - *new_gid = i; + // +1: assign new gids from 1..N; 0 is special + *new_gid = i + 1; return true; } } @@ -109,10 +128,6 @@ _populate_gids_to_retain (hb_face_t *face, *(old_gids_sorted.push ()) = 0; old_gids_sorted.qsort (_hb_codepoint_t_cmp); - for (unsigned int i = 0; i < codepoints.len; i++) { - DEBUG_MSG(SUBSET, nullptr, " U+%04X, old_gid %d, new_gid %d", codepoints[i], old_gids[i], i); - } - // TODO(Q1) expand with glyphs that make up complex glyphs // TODO expand with glyphs reached by G* // diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 410d9beca..09df7cddf 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -55,6 +55,11 @@ hb_subset_plan_new_gid_for_old_id(hb_subset_plan_t *plan, hb_codepoint_t old_gid, hb_codepoint_t *new_gid /* OUT */); +HB_INTERNAL hb_bool_t +hb_subset_plan_new_gid_for_codepoint(hb_subset_plan_t *plan, + hb_codepoint_t codepont, + hb_codepoint_t *new_gid /* OUT */); + HB_INTERNAL void hb_subset_plan_destroy (hb_subset_plan_t *plan); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index d9a4d1258..e91d78000 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -124,7 +124,7 @@ _subset (hb_subset_plan_t *plan, hb_face_t *source) hb_blob_destroy (source_blob); hb_tag_t tag = TableType::tableTag; - DEBUG_MSG(SUBSET, nullptr, "Subset %c%c%c%c %s", HB_UNTAG(tag), result ? "success" : "FAILED!"); + DEBUG_MSG(SUBSET, nullptr, "OT::%c%c%c%c::subset %s", HB_UNTAG(tag), result ? "success" : "FAILED!"); return result; } From afb1da3a1891b7c0fdd047bcb7b3bde86e830444 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 14:37:47 -0800 Subject: [PATCH 15/40] auto-completed the wrong gids_to_retain --- src/hb-subset-plan.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index cc12abcae..286f7e158 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -62,8 +62,8 @@ hb_subset_plan_new_gid_for_old_id (hb_subset_plan_t *plan, hb_codepoint_t *new_gid) { // the index in old_gids is the new gid; only up to codepoints.len are valid - for (unsigned int i = 0; i < plan->gids_to_retain_sorted.len; i++) { - if (plan->gids_to_retain_sorted[i] == old_gid) { + for (unsigned int i = 0; i < plan->gids_to_retain.len; i++) { + if (plan->gids_to_retain[i] == old_gid) { // +1: assign new gids from 1..N; 0 is special *new_gid = i + 1; return true; From 89ee20f1a39ac78268b57a9aebe8e7428f9944bf Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 16:01:15 -0800 Subject: [PATCH 16/40] basic wiring for a (failing) cmap test --- test/api/Makefile.am | 2 + test/api/fonts/README | 1 + .../Roboto-Regular.abc.cmap-format12-only.ttf | Bin 0 -> 2412 bytes .../Roboto-Regular.ac.cmap-format12-only.ttf | Bin 0 -> 2212 bytes test/api/hb-subset-test.h | 3 +- test/api/test-subset-cmap.c | 82 ++++++++++++++++++ test/api/test-subset-glyf.c | 5 +- .../in-house/tests/myanmar-syllable.tests | 1 - 8 files changed, 87 insertions(+), 7 deletions(-) create mode 100644 test/api/fonts/README create mode 100644 test/api/fonts/Roboto-Regular.abc.cmap-format12-only.ttf create mode 100644 test/api/fonts/Roboto-Regular.ac.cmap-format12-only.ttf create mode 100644 test/api/test-subset-cmap.c delete mode 100644 test/shaping/data/in-house/tests/myanmar-syllable.tests diff --git a/test/api/Makefile.am b/test/api/Makefile.am index e36b3fd57..918bfb0e9 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -29,12 +29,14 @@ TEST_PROGS = \ test-object \ test-set \ test-shape \ + test-subset-cmap \ test-subset-glyf \ test-unicode \ test-version \ $(NULL) test_subset_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la +test_subset_cmap_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_glyf_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_unicode_CPPFLAGS = \ diff --git a/test/api/fonts/README b/test/api/fonts/README new file mode 100644 index 000000000..a365afd74 --- /dev/null +++ b/test/api/fonts/README @@ -0,0 +1 @@ +cmap-format12-only files created by ttx & remove all other cmap entries diff --git a/test/api/fonts/Roboto-Regular.abc.cmap-format12-only.ttf b/test/api/fonts/Roboto-Regular.abc.cmap-format12-only.ttf new file mode 100644 index 0000000000000000000000000000000000000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A0H~kp5mvQU^38n~TERo63p3AJQD0C|zm%%x<>cPbx2fF73ebusJ z!xP&csV>Z+n6&A!y0Qi2S!%rb3o^*F?%3E^=_W7b@U9KD8hP^5y{*e#wkN#C%(LG}#6ooxo99sMsaEpR>na!BpGjUueRat~qgH8s$W#T1EL#d* zz`lIWz2F+ zcY#AV2CC=*n^X%9X+J3VZ91&;A)CDonbs*tx85*10kMM7*93@QxA_sfO)h?sPbQot zrI}gFxl`flHQ>;ob7#3b?sTmP7(hZGWz7IU00r&CQZT)fW@bvppwQcW*FTQ(mU2r7a zwDwi~;#>YY0J(l+rORuJ9^{D*)d!U%oZ`od+m>jZ%*~^`*cdX_zArs0pAMtbtx4!Q`a + +#include "hb-test.h" +#include "hb-subset-test.h" + +/* Unit tests for cmap subsetting */ + +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_set_t *codepoints = hb_set_create(); + hb_set_add (codepoints, 97); + hb_set_add (codepoints, 99); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('c','m','a','p')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ac); +} + +static void +test_subset_cmap_noop (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.cmap-format12-only.ttf"); + + hb_set_t *codepoints = hb_set_create(); + hb_set_add (codepoints, 97); + hb_set_add (codepoints, 98); + hb_set_add (codepoints, 99); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('c','m','a','p')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); +} + +// TODO(rsheeter) test cmap to no codepoints + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_subset_cmap); + hb_test_add (test_subset_cmap_noop); + + return hb_test_run(); +} diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index 98e12339a..8db053c7e 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -34,10 +34,8 @@ static void test_subset_glyf (void) { - hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); - g_assert (face_abc); + 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.ttf"); - g_assert (face_ac); hb_set_t *codepoints = hb_set_create(); hb_set_add (codepoints, 97); @@ -57,7 +55,6 @@ static void test_subset_glyf_noop (void) { hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); - g_assert (face_abc); hb_set_t *codepoints = hb_set_create(); hb_set_add (codepoints, 97); diff --git a/test/shaping/data/in-house/tests/myanmar-syllable.tests b/test/shaping/data/in-house/tests/myanmar-syllable.tests deleted file mode 100644 index 4666ef99d..000000000 --- a/test/shaping/data/in-house/tests/myanmar-syllable.tests +++ /dev/null @@ -1 +0,0 @@ -../fonts/af3086380b743099c54a3b11b96766039ea62fcd.ttf:--no-glyph-names:U+101D,U+FE00,U+1031,U+FE00,U+1031,U+FE00:[6=0+465|6=0+465|5=0+502] From d1a4d5616f792c6ad84bcc5011040167ddd7cc3f Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Mon, 12 Feb 2018 16:25:32 -0800 Subject: [PATCH 17/40] output format 12 as enc 10 to match how Roboto did it --- src/hb-ot-cmap-table.hh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 4d32359df..5ac970612 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -577,7 +577,7 @@ struct cmap EncodingRecord &rec = cmap->encodingRecord[0]; rec.platformID.set (3); // Windows - rec.encodingID.set (1); // Unicode BMP + rec.encodingID.set (10); // Unicode UCS-4 /* capture offset to subtable */ CmapSubtable &subtable = rec.subtable.serialize(&context, cmap); From 8cf8b78faaf3e7ee261bdc44a1ad5a1973eab1a2 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 16:30:21 -0800 Subject: [PATCH 18/40] [subset] whitespace --- test/api/test-subset-cmap.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/api/test-subset-cmap.c b/test/api/test-subset-cmap.c index 8775311d0..8798475f2 100644 --- a/test/api/test-subset-cmap.c +++ b/test/api/test-subset-cmap.c @@ -34,10 +34,10 @@ 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_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_set_t *codepoints = hb_set_create(); + hb_set_t *codepoints = hb_set_create (); hb_set_add (codepoints, 97); hb_set_add (codepoints, 99); hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); From 24904383df03c472c865bd97bfe844f5e86a7172 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 17:31:01 -0800 Subject: [PATCH 19/40] [subset] Correct usFirstCharIndex and usLastCharIndex in OS2 table when subsetting. --- src/hb-ot-os2-table.hh | 45 ++++++++++++++++++++++++++++++++++++++++++ src/hb-subset.cc | 16 +++++++++------ 2 files changed, 55 insertions(+), 6 deletions(-) diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 5bed47013..f80a05d70 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -49,6 +49,51 @@ struct os2 return_trace (c->check_struct (this)); } + inline hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const + { + hb_blob_t *os2_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_os2)); + hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1); + hb_blob_destroy (os2_blob); + + OT::os2 *os2_prime = (OT::os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr); + if (unlikely (!os2_prime)) { + hb_blob_destroy (os2_prime_blob); + return nullptr; + } + + uint16_t min_cp, max_cp; + find_min_and_max_codepoint (plan, &min_cp, &max_cp); + os2_prime->usFirstCharIndex.set (min_cp); + os2_prime->usLastCharIndex.set (max_cp); + + return os2_prime_blob; + } + + static inline void find_min_and_max_codepoint (hb_subset_plan_t *plan, + uint16_t *min_cp, /* OUT */ + uint16_t *max_cp /* OUT */) + { + hb_codepoint_t min = -1, max = 0; + + for (int i = 0; i < plan->codepoints.len; i++) { + hb_codepoint_t cp = plan->codepoints[i]; + if (cp < min) { + min = cp; + } + if (cp > max) { + max = cp; + } + } + + if (min > 0xFFFF) + min = 0xFFFF; + if (max > 0xFFFF) + max = 0xFFFF; + + *min_cp = min; + *max_cp = max; + } + public: HBUINT16 version; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index e91d78000..15730bf5a 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -38,6 +38,7 @@ #include "hb-ot-glyf-table.hh" #include "hb-ot-head-table.hh" #include "hb-ot-maxp-table.hh" +#include "hb-ot-os2-table.hh" #ifndef HB_NO_VISIBILITY @@ -349,6 +350,9 @@ _subset_table (hb_subset_plan_t *plan, case HB_OT_TAG_cmap: dest_blob = _subset (plan, source); break; + case HB_OT_TAG_os2: + dest_blob = _subset (plan, source); + break; default: dest_blob = source_blob; break; @@ -360,17 +364,17 @@ _subset_table (hb_subset_plan_t *plan, } static bool -_should_drop_table(hb_tag_t tag) +_should_drop_table(hb_tag_t tag) { switch (tag) { - case HB_TAG('G', 'D', 'E', 'F'): /* temporary */ - case HB_TAG('G', 'P', 'O', 'S'): /* temporary */ - case HB_TAG('G', 'S', 'U', 'B'): /* temporary */ - case HB_TAG('d', 's', 'i', 'g'): + case HB_TAG ('G', 'D', 'E', 'F'): /* temporary */ + case HB_TAG ('G', 'P', 'O', 'S'): /* temporary */ + case HB_TAG ('G', 'S', 'U', 'B'): /* temporary */ + case HB_TAG ('d', 's', 'i', 'g'): return true; default: return false; - } + } } /** From 343dfe89655683966836e44afb4fd32c47377844 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 17:33:48 -0800 Subject: [PATCH 20/40] [subset] white and add inline in hb-ot-cmap-table. --- src/hb-ot-cmap-table.hh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 5ac970612..a27a80048 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -556,9 +556,9 @@ struct cmap return true; } - hb_bool_t _subset (hb_prealloced_array_t &groups, - size_t dest_sz, - void *dest) const + inline hb_bool_t _subset (hb_prealloced_array_t &groups, + size_t dest_sz, + void *dest) const { hb_serialize_context_t context(dest, dest_sz); @@ -605,7 +605,7 @@ struct cmap return true; } - hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const + inline hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const { hb_auto_array_t groups; @@ -633,11 +633,11 @@ struct cmap } // all done, write the blob into dest - return hb_blob_create((const char *)dest, - dest_sz, - HB_MEMORY_MODE_READONLY, - /* userdata */ nullptr, - free); + return hb_blob_create ((const char *)dest, + dest_sz, + HB_MEMORY_MODE_READONLY, + /* userdata */ nullptr, + free); } struct accelerator_t From 865b6971ad5c2ec4bc33c36a78a36b90da5f5543 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 17:42:20 -0800 Subject: [PATCH 21/40] [subset] Add a test for OS/2 fixes during subsetting. --- test/api/Makefile.am | 2 + test/api/fonts/Roboto-Regular.b.ttf | Bin 0 -> 1996 bytes test/api/test-subset-os2.c | 59 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) create mode 100644 test/api/fonts/Roboto-Regular.b.ttf create mode 100644 test/api/test-subset-os2.c diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 918bfb0e9..071264e1b 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -31,6 +31,7 @@ TEST_PROGS = \ test-shape \ test-subset-cmap \ test-subset-glyf \ + test-subset-os2 \ test-unicode \ test-version \ $(NULL) @@ -38,6 +39,7 @@ TEST_PROGS = \ test_subset_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_cmap_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_glyf_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la +test_subset_os2_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_unicode_CPPFLAGS = \ $(AM_CPPFLAGS) \ diff --git a/test/api/fonts/Roboto-Regular.b.ttf b/test/api/fonts/Roboto-Regular.b.ttf new file mode 100644 index 0000000000000000000000000000000000000000..8e44886f1f31dba3004b2ef0bff3d3afda4c22b4 GIT binary patch literal 1996 zcmZuyZERCj7=F*ax1TGlt!1)a7`N*_7;EVq%L223qU{C_SzU{{mnd7ebsw;?x(^s8 z=z=1%B8c+CU3$hX9re#GD!UXcp?x9o$WcEAqTgcV!17k|0`xmD3 z$dkw``iI6QtTsR`VFz;S;Ba>eI?w{afnXj=O=N_6(T4hWkSqIBLup~g{wIcTkFYT_ zJUUhwf*$18D4rQfXU_LNz<#9rShF1jI9|9TDR_gHLn-v;++Nw`-o)KbE?xs}4RMI6 z+!2ze9p25FPDCW4dy$xtn33d6RuSuRb_Y$|;hc6eZm(5+H{^R77oF2j{zL1YVjjU? zUTyKaHna~YQXW$yjAXX3j)KYChl-OvAc>aZCW zzJ4eFbAG|}<<$%Mz=f;0BYM^XoP-icf=Oqz6Lbj`_|z#1`u)=L{O+z_zxlYMIQ$os zTJ_N7yRP+QTxad~9>@#VZFSaBq&5`Lhj<)%q{DEWlq`dJyyv#<59IuFwz@@aBaKi1 zQF@ELhh2c_jA;Y5w#Jyn@1d9E7A1`eqcg*XmbSJQh(H%~nIR9*YdIr;0_+@xr6vZyj>VH-?^rW*7b#hd?X0 z#noxXPH3~NaFoBfdfFy->ADL-QYYK9SWUvCWvlp0&bMQk{df;_Zwkb3Zn#OwBs+zAgG_ zm&*b?GBvBfZgsi_qVgQnh_|EYchqvIg&cDVwJhgih%>IHx=Psz)>@ch+n!$U^Po8+ zsM|KK)h)68*@nsz@=1H157(BGWoitRmll&{e&yxndYLTCse>;y`N^`r))(L8CCiqK zHCE{=_5+=*jjPF5^hVE4BhPU&m+cOdZ<)vGu$jqP99R#lvguHAl*G4c*aFXC6L4jb6myJ`!I8}^O#dxl`jA{w~AXrm| zc^w2N3BDsJ5Ns*K1Sq4^D%tQP(kV1-0l!!d zXoq1ugTpX}zjjDNAB@8wq+kTI^ikML-|_z$3_mSa5b&HAqb{i#qXgN~MIRqp(SaTs zgm$Qd%^*dacO=2veQ0D5ynQ3-ec&BTjqL|7zK=Lim2%m>^vHf(#i(Q$BSl8*f=AEv iLOI$?>Pzd=Y-G}U_0aIxdKLP575aJ=kJdxsrSUiVPqUE# literal 0 HcmV?d00001 diff --git a/test/api/test-subset-os2.c b/test/api/test-subset-os2.c new file mode 100644 index 000000000..e2b96f92a --- /dev/null +++ b/test/api/test-subset-os2.c @@ -0,0 +1,59 @@ +/* + * Copyright © 2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Garret Rieger + */ + +#include + +#include "hb-test.h" +#include "hb-subset-test.h" + +static void +test_subset_os2 (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); + hb_face_t *face_b = hb_subset_test_open_font("fonts/Roboto-Regular.b.ttf"); + + hb_set_t *codepoints = hb_set_create(); + hb_set_add (codepoints, 98); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + hb_subset_test_check (face_b, face_abc_subset, HB_TAG ('O','S','/','2')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_b); +} + + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_subset_os2); + + return hb_test_run(); +} From df6d780355d7da805a9b9033452f8814c5360bba Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 17:56:17 -0800 Subject: [PATCH 22/40] [subset] Extract maxp subsetting into hb-ot-maxp-table. --- src/hb-ot-maxp-table.hh | 19 ++++++++++++++++++- src/hb-subset.cc | 28 ++-------------------------- test/api/test-subset-glyf.c | 5 +++-- 3 files changed, 23 insertions(+), 29 deletions(-) diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index fb2209c40..52b9388db 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -28,7 +28,7 @@ #define HB_OT_MAXP_TABLE_HH #include "hb-open-type-private.hh" - +#include "hb-subset-plan.hh" namespace OT { @@ -61,6 +61,23 @@ struct maxp (version.major == 0 && version.minor == 0x5000u))); } + inline hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const + { + hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp)); + hb_blob_t *maxp_prime_blob = hb_blob_create_sub_blob (maxp_blob, 0, -1); + hb_blob_destroy (maxp_blob); + + OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data_writable (maxp_prime_blob, nullptr); + if (unlikely (!maxp_prime)) { + hb_blob_destroy (maxp_prime_blob); + return nullptr; + } + + maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len); + + return maxp_prime_blob; + } + /* We only implement version 0.5 as none of the extra fields in version 1.0 are useful. */ protected: FixedVersion<>version; /* Version of the maxp table (0.5 or 1.0), diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 15730bf5a..dda9f3e94 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -279,31 +279,6 @@ _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_ return has_head; } -static bool -_add_maxp_and_set_glyph_count (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) -{ - hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp)); - const OT::maxp *maxp = OT::Sanitizer::lock_instance (maxp_blob); - bool has_maxp = (maxp != nullptr); - if (has_maxp) { - unsigned int length = hb_blob_get_length (maxp_blob); - OT::maxp *maxp_prime = (OT::maxp *) calloc (length, 1); - memcpy (maxp_prime, maxp, length); - maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len); - - hb_blob_t *maxp_prime_blob = hb_blob_create ((const char*) maxp_prime, - length, - HB_MEMORY_MODE_READONLY, - maxp_prime, - free); - has_maxp = hb_subset_face_add_table (dest, HB_OT_TAG_maxp, maxp_prime_blob); - hb_blob_destroy (maxp_prime_blob); - } - - hb_blob_destroy (maxp_blob); - return has_maxp; -} - static bool _subset_glyf (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) { @@ -343,7 +318,8 @@ _subset_table (hb_subset_plan_t *plan, // SKIP head, it's handled by glyf return true; case HB_OT_TAG_maxp: - return _add_maxp_and_set_glyph_count (plan, source, dest); + dest_blob = _subset (plan, source); + break; case HB_OT_TAG_loca: // SKIP loca, it's handle by glyf return true; diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c index 8db053c7e..3c9d8fe9f 100644 --- a/test/api/test-subset-glyf.c +++ b/test/api/test-subset-glyf.c @@ -34,8 +34,8 @@ static void test_subset_glyf (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.ttf"); + 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.ttf"); hb_set_t *codepoints = hb_set_create(); hb_set_add (codepoints, 97); @@ -45,6 +45,7 @@ test_subset_glyf (void) hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('g','l','y','f')); hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('l','o','c', 'a')); + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('m','a','x', 'p')); hb_face_destroy (face_abc_subset); hb_face_destroy (face_abc); From 89f17e3965ba776565f2de2bf56a4b135f336e53 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 18:14:50 -0800 Subject: [PATCH 23/40] [subset] capitalize dsig. --- src/hb-subset.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index dda9f3e94..3851977e1 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -346,7 +346,7 @@ _should_drop_table(hb_tag_t tag) case HB_TAG ('G', 'D', 'E', 'F'): /* temporary */ case HB_TAG ('G', 'P', 'O', 'S'): /* temporary */ case HB_TAG ('G', 'S', 'U', 'B'): /* temporary */ - case HB_TAG ('d', 's', 'i', 'g'): + case HB_TAG ('D', 'S', 'I', 'G'): return true; default: return false; From b0eefacf4cb885f510f9551bf2e9216808ca61e8 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Mon, 12 Feb 2018 18:15:58 -0800 Subject: [PATCH 24/40] [subset] Drop GSUB, GDEF, GPOS, and DSIG from subsetter expected test outputs. --- .../basics/Roboto-Regular.abc.default.62.ttf | Bin 2460 -> 1740 bytes test/subset/generate-expected-outputs.py | 1 + 2 files changed, 1 insertion(+) diff --git a/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf b/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf index 9d791f7fc5ba42bb66504843d5841f2b180beef7..52706dc90320133d24a0a6c3109b9d1ef1bf8ec7 100644 GIT binary patch delta 375 zcmW-cJxBvV5QXP<_wq+Vz}P7oOd3fcrVv{@tt_;#Gk3YZB_glFp;%Oq|(Y0EV5|o49gPwL9`}N+9@rHVU zc=jB>ois%X^FpnAHLK$cHa`wv?xQj1p_6(rySPvU7d<~{CzA9H9tS5H&8kJ~sL1$4 ziuqPsvNBKV$HDn+%dfHf)DI*NJTIHAAo9rpUuj+L)MU5*hYyKYc$SE%DfSdc36-f+ zKAF|ihg2BZnh0Ih_GYoJlfI>yekmx`Ivmrj6=P8FdXqNJ-kPcid=ucYWZW33bc=R5ATLZZbZ6w9Rf{XYVabQ5p7zuvc{Rau?B*XI5 zuAy|n08Jid9vVb9H5_ z>5+448Jk-chn6_i`cQi~*w)q_4ypA{pBj!t+FEOrs%pjedTZpZb~WIut`Qn!_raT& zzGv+5MEXPh$ep2k!;?RXp*hc{;Fx-5?s_`#{*lj)U!B~j4aK|OI~Se2GFN#vDxZw4 zeem_B?Km_0MTTJu4L(DIzlL>rc~Kn+EDkKwSn|IEO9T?lm_u2qDaocVWy-QyZS6Uw z>}qbYRJK)ewH{UNCGl#=o`r<-4t-R*;TXO*u>F_0XX)wDTfa*;q*FUiUO0bvB(`-t z&XzFLUHt3V&!6r%djCsx@>}}T>>DlO6l%}|hfM%oAr2mdv&8!_&6bs7x$2Gi9#mwX zvKCJahWHUqh|SoN4RV!<*|mJ7ph3@`;Hpb!oo^hrJfinbA+McTP4dw}Pmc=SDL+Aa<^Krw4w0?_fXteS?Xe z@b_!!0r=^)(xU!${LaMS06n8(CL^C!kCBDb9kn7`sn%|hn!Rilh47LbOH}z>EM_%w VQ=#w+qJp-lpe-u+pQ!(Jc@8Jq`zinc diff --git a/test/subset/generate-expected-outputs.py b/test/subset/generate-expected-outputs.py index f6636de7e..6dac890ec 100755 --- a/test/subset/generate-expected-outputs.py +++ b/test/subset/generate-expected-outputs.py @@ -18,6 +18,7 @@ def usage(): def generate_expected_output(input_file, unicodes, output_path): check_call(["fonttools", "subset", input_file, + "--drop-tables+=DSIG,GPOS,GSUB,GDEF", "--unicodes=%s" % unicodes, "--output-file=%s" % output_path]) From a0fe3011bafbe36e7d5810acc7df21bea08c802a Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 10:52:41 -0800 Subject: [PATCH 25/40] copy all cmap groups at once --- src/hb-ot-cmap-table.hh | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index a27a80048..c3f242db0 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -272,17 +272,12 @@ struct CmapSubtableLongSegmented } inline bool serialize(hb_serialize_context_t *context, - unsigned int group_count, - Supplier &group_supplier) + hb_prealloced_array_t &group_data) { TRACE_SERIALIZE (this); if (unlikely(!context->extend_min (*this))) return_trace (false); - if (unlikely(!groups.serialize(context, group_count))) return_trace (false); - for (unsigned int i = 0; i < group_count; i++) - { - const CmapSubtableLongGroup &group = group_supplier[i]; - memcpy(&groups[i], &group, sizeof(group)); - } + if (unlikely(!groups.serialize(context, group_data.len))) return_trace (false); + memcpy(&groups[0], &group_data[0], group_data.len * sizeof(CmapSubtableLongGroup)); return true; } @@ -594,8 +589,7 @@ struct cmap format12.reservedZ.set(0); format12.lengthZ.set(16 + 12 * groups.len); - OT::Supplier group_supplier (&groups[0], groups.len, sizeof (CmapSubtableLongGroup)); - if (unlikely(!format12.serialize(&context, groups.len, group_supplier))) + if (unlikely(!format12.serialize(&context, groups))) { return false; } From 8b1dbbef1aec3b6880186070e7386a5553d67b15 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 11:04:12 -0800 Subject: [PATCH 26/40] Fix compile error in hb-subset-test. --- test/api/hb-subset-test.h | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h index 2546b5e00..498329c2d 100644 --- a/test/api/hb-subset-test.h +++ b/test/api/hb-subset-test.h @@ -93,7 +93,14 @@ hb_subset_test_create_subset (hb_face_t *source, hb_set_t *codepoints) { hb_subset_profile_t *profile = hb_subset_profile_create(); - hb_subset_input_t *input = hb_subset_input_create (codepoints); + hb_subset_input_t *input = hb_subset_input_create_or_fail (); + + hb_set_t * input_codepoints = hb_subset_input_unicode_set (input); + hb_codepoint_t codepoint; + while (hb_set_next (codepoints, &codepoint)) { + hb_set_add (input_codepoints, codepoint); + } + hb_face_t *subset = hb_subset (source, profile, input); g_assert (subset); From e5edcc81bf14311c56bd2f50808552076c3c4d77 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 11:17:53 -0800 Subject: [PATCH 27/40] [subset] Fix codepoint iteration in hb-subset-test. --- test/api/hb-subset-test.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h index 498329c2d..efae17976 100644 --- a/test/api/hb-subset-test.h +++ b/test/api/hb-subset-test.h @@ -96,7 +96,7 @@ hb_subset_test_create_subset (hb_face_t *source, hb_subset_input_t *input = hb_subset_input_create_or_fail (); hb_set_t * input_codepoints = hb_subset_input_unicode_set (input); - hb_codepoint_t codepoint; + hb_codepoint_t codepoint = -1; while (hb_set_next (codepoints, &codepoint)) { hb_set_add (input_codepoints, codepoint); } From fa87770372a3156658412ff0d70e32083c6b0484 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 14:16:25 -0800 Subject: [PATCH 28/40] [subset] First pass at hmtx --- src/hb-ot-cmap-table.hh | 19 +- src/hb-ot-hhea-table.hh | 6 +- src/hb-ot-hmtx-table.hh | 163 +++++++++++++++-- src/hb-ot-maxp-table.hh | 8 +- src/hb-ot-os2-table.hh | 8 +- src/hb-subset-glyf.cc | 5 +- src/hb-subset-glyf.hh | 1 - src/hb-subset-plan.cc | 12 ++ src/hb-subset-plan.hh | 10 ++ src/hb-subset-private.hh | 11 ++ src/hb-subset.cc | 85 +++++---- test/api/Makefile.am | 7 + test/api/fonts/Inconsolata-Regular.ab.ttf | Bin 0 -> 5048 bytes test/api/fonts/Inconsolata-Regular.abc.ttf | Bin 0 -> 5224 bytes .../fonts/Inconsolata-Regular.abc.widerc.ttf | Bin 0 -> 5228 bytes test/api/fonts/Inconsolata-Regular.ac.ttf | Bin 0 -> 4940 bytes .../fonts/Inconsolata-Regular.ac.widerc.ttf | Bin 0 -> 4944 bytes test/api/fonts/README | 2 + test/api/test-subset-hmtx.c | 164 ++++++++++++++++++ 19 files changed, 422 insertions(+), 79 deletions(-) create mode 100644 test/api/fonts/Inconsolata-Regular.ab.ttf create mode 100644 test/api/fonts/Inconsolata-Regular.abc.ttf create mode 100644 test/api/fonts/Inconsolata-Regular.abc.widerc.ttf create mode 100644 test/api/fonts/Inconsolata-Regular.ac.ttf create mode 100644 test/api/fonts/Inconsolata-Regular.ac.widerc.ttf create mode 100644 test/api/test-subset-hmtx.c diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index c3f242db0..6c5f3c282 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -599,13 +599,13 @@ struct cmap return true; } - inline hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const + inline hb_bool_t subset (hb_subset_plan_t *plan) const { hb_auto_array_t groups; if (unlikely(!populate_groups(plan, &groups))) { - return nullptr; + return false; } // We now know how big our blob needs to be @@ -617,21 +617,22 @@ struct cmap void *dest = calloc(dest_sz, 1); if (unlikely(!dest)) { DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %ld for cmap subset output", dest_sz); - return nullptr; + return false; } if (unlikely(!_subset(groups, dest_sz, dest))) { free(dest); - return nullptr; + return false; } // all done, write the blob into dest - return hb_blob_create ((const char *)dest, - dest_sz, - HB_MEMORY_MODE_READONLY, - /* userdata */ nullptr, - free); + hb_blob_t *cmap_prime = hb_blob_create ((const char *)dest, + dest_sz, + HB_MEMORY_MODE_READONLY, + /* userdata */ nullptr, + free); + return hb_subset_plan_add_table(plan, HB_OT_TAG_cmap, cmap_prime); } struct accelerator_t diff --git a/src/hb-ot-hhea-table.hh b/src/hb-ot-hhea-table.hh index 54eb5eb77..97952b4eb 100644 --- a/src/hb-ot-hhea-table.hh +++ b/src/hb-ot-hhea-table.hh @@ -41,7 +41,7 @@ namespace OT { #define HB_OT_TAG_hhea HB_TAG('h','h','e','a') #define HB_OT_TAG_vhea HB_TAG('v','h','e','a') - +template struct _hea { inline bool sanitize (hb_sanitize_context_t *c) const @@ -84,10 +84,10 @@ struct _hea DEFINE_SIZE_STATIC (36); }; -struct hhea : _hea { +struct hhea : _hea { static const hb_tag_t tableTag = HB_OT_TAG_hhea; }; -struct vhea : _hea { +struct vhea : _hea { static const hb_tag_t tableTag = HB_OT_TAG_vhea; }; diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index b4ba2490c..7fae4f6cd 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -53,7 +53,7 @@ struct LongMetric DEFINE_SIZE_STATIC (4); }; -template +template struct hmtxvmtx { inline bool sanitize (hb_sanitize_context_t *c) const @@ -64,8 +64,129 @@ struct hmtxvmtx return_trace (true); } + + inline bool subset_update_header(hb_subset_plan_t *plan, + unsigned int num_hmetrics) const + { + /* alloc the new table */ + size_t dest_sz = sizeof(H); + void *dest = (void *) calloc(dest_sz, 1); + if (unlikely(!dest)) + { + return false; + } + + hb_blob_t *src_blob = OT::Sanitizer().sanitize (plan->source->reference_table (T::tableTag)); + if (unlikely(!src_blob)) + { + return false; + } + unsigned int src_length; + const char *src_raw = hb_blob_get_data(src_blob, &src_length); + + memcpy(dest, src_raw, src_length); + + H *table = (H *) dest; + table->numberOfLongMetrics.set(num_hmetrics); + + hb_blob_t *dest_blob = hb_blob_create ((const char *)dest, + dest_sz, + HB_MEMORY_MODE_READONLY, + /* userdata */ nullptr, + free); + return hb_subset_plan_add_table(plan, H::tableTag, dest_blob); + } + + inline bool subset (hb_subset_plan_t *plan) const + { + typename T::accelerator_t _mtx; + _mtx.init(plan->source); + + /* All the trailing glyphs with the same advance can use one LongMetric + * and just keep LSB */ + hb_prealloced_array_t &gids = plan->gids_to_retain_sorted; + unsigned int num_advances = gids.len; + unsigned int last_advance = _mtx.get_advance(gids[num_advances - 1]); + while (num_advances > 1 + && last_advance == _mtx.get_advance(gids[num_advances - 2])) + { + num_advances--; + } + + /* alloc the new table */ + size_t dest_sz = num_advances * 4 + + (gids.len - num_advances) * 2; + void *dest = (void *) calloc(dest_sz, 1); + if (unlikely(!dest)) + { + return false; + } + + DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in src has %d advances, %d lsbs", HB_UNTAG(T::tableTag), _mtx.num_advances, _mtx.num_metrics - _mtx.num_advances); + DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in dest has %d advances, %d lsbs, %d bytes", HB_UNTAG(T::tableTag), num_advances, gids.len - num_advances, dest_sz); + + const char *source_table = hb_blob_get_data(_mtx.blob, nullptr); + // Copy everything over + LongMetric * old_metrics = (LongMetric *) source_table; + FWORD *lsbs = (FWORD *) (old_metrics + _mtx.num_advances); + char * dest_pos = (char *) dest; + for (unsigned int i = 0; i < gids.len; i++) + { + /* the last metric or the one for gids[i] */ + LongMetric *src_metric = old_metrics + MIN(_mtx.num_advances - 1, gids[i]); + if (gids[i] < _mtx.num_advances) + { + /* src is a LongMetric */ + if (i < num_advances) + { + /* dest is a LongMetric, copy it */ + *((LongMetric *) dest_pos) = *src_metric; + } + else + { + /* dest just lsb */ + *((FWORD *) dest_pos) = src_metric->lsb; + } + } + else + { + FWORD src_lsb = *(lsbs + gids[i] - _mtx.num_advances); + if (i < num_advances) + { + /* dest needs a full LongMetric */ + LongMetric *metric = (LongMetric *)dest_pos; + metric->advance = src_metric->advance; + metric->lsb = src_lsb; + } + else + { + /* dest just needs an lsb */ + *((FWORD *) dest_pos) = src_lsb; + } + } + dest_pos += (i < num_advances ? 4 : 2); + } + _mtx.fini(); + + // Amend header num hmetrics + if (unlikely(!subset_update_header(plan, num_advances))) + { + free(dest); + return false; + } + + hb_blob_t *result = hb_blob_create ((const char *)dest, + dest_sz, + HB_MEMORY_MODE_READONLY, + /* userdata */ nullptr, + free); + return hb_subset_plan_add_table(plan, T::tableTag, result); + } + struct accelerator_t { + friend struct hmtxvmtx; + inline void init (hb_face_t *face, unsigned int default_advance_ = 0) { @@ -87,8 +208,8 @@ struct hmtxvmtx hb_blob_destroy (os2_blob); } - hb_blob_t *_hea_blob = Sanitizer<_hea>().sanitize (face->reference_table (T::headerTag)); - const _hea *_hea_table = Sanitizer<_hea>::lock_instance (_hea_blob); + hb_blob_t *_hea_blob = Sanitizer().sanitize (face->reference_table (H::tableTag)); + const H *_hea_table = Sanitizer::lock_instance (_hea_blob); num_advances = _hea_table->numberOfLongMetrics; if (!got_font_extents) { @@ -129,22 +250,27 @@ struct hmtxvmtx hb_blob_destroy (var_blob); } - inline unsigned int get_advance (hb_codepoint_t glyph, - hb_font_t *font) const + inline unsigned int get_advance (hb_codepoint_t glyph) const { if (unlikely (glyph >= num_metrics)) { - /* If num_metrics is zero, it means we don't have the metrics table - * for this direction: return default advance. Otherwise, it means that the - * glyph index is out of bound: return zero. */ - if (num_metrics) - return 0; - else - return default_advance; + /* If num_metrics is zero, it means we don't have the metrics table + * for this direction: return default advance. Otherwise, it means that the + * glyph index is out of bound: return zero. */ + if (num_metrics) + return 0; + else + return default_advance; } - return table->longMetric[MIN (glyph, (uint32_t) num_advances - 1)].advance - + (font->num_coords ? var_table->get_advance_var (glyph, font->coords, font->num_coords) : 0); // TODO Optimize?! + return table->longMetric[MIN (glyph, (uint32_t) num_advances - 1)].advance; + } + + inline unsigned int get_advance (hb_codepoint_t glyph, + hb_font_t *font) const + { + return get_advance(glyph) + + (font->num_coords ? var_table->get_advance_var (glyph, font->coords, font->num_coords) : 0); // TODO Optimize?! } public: @@ -153,11 +279,12 @@ struct hmtxvmtx unsigned short descender; unsigned short line_gap; - private: + protected: unsigned int num_metrics; unsigned int num_advances; unsigned int default_advance; + private: const hmtxvmtx *table; hb_blob_t *blob; const HVARVVAR *var_table; @@ -190,15 +317,13 @@ struct hmtxvmtx DEFINE_SIZE_ARRAY (0, longMetric); }; -struct hmtx : hmtxvmtx { +struct hmtx : hmtxvmtx { static const hb_tag_t tableTag = HB_OT_TAG_hmtx; - static const hb_tag_t headerTag = HB_OT_TAG_hhea; static const hb_tag_t variationsTag = HB_OT_TAG_HVAR; static const hb_tag_t os2Tag = HB_OT_TAG_os2; }; -struct vmtx : hmtxvmtx { +struct vmtx : hmtxvmtx { static const hb_tag_t tableTag = HB_OT_TAG_vmtx; - static const hb_tag_t headerTag = HB_OT_TAG_vhea; static const hb_tag_t variationsTag = HB_OT_TAG_VVAR; static const hb_tag_t os2Tag = HB_TAG_NONE; }; diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 52b9388db..00a95d716 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -61,21 +61,21 @@ struct maxp (version.major == 0 && version.minor == 0x5000u))); } - inline hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const + inline hb_bool_t subset (hb_subset_plan_t *plan) const { - hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp)); + hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp)); hb_blob_t *maxp_prime_blob = hb_blob_create_sub_blob (maxp_blob, 0, -1); hb_blob_destroy (maxp_blob); OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data_writable (maxp_prime_blob, nullptr); if (unlikely (!maxp_prime)) { hb_blob_destroy (maxp_prime_blob); - return nullptr; + return false; } maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len); - return maxp_prime_blob; + return hb_subset_plan_add_table(plan, HB_OT_TAG_maxp, maxp_prime_blob); } /* We only implement version 0.5 as none of the extra fields in version 1.0 are useful. */ diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index f80a05d70..1bb9a1535 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -49,16 +49,16 @@ struct os2 return_trace (c->check_struct (this)); } - inline hb_blob_t * subset (hb_subset_plan_t *plan, hb_face_t *source) const + inline hb_bool_t subset (hb_subset_plan_t *plan) const { - hb_blob_t *os2_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_os2)); + hb_blob_t *os2_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_os2)); hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1); hb_blob_destroy (os2_blob); OT::os2 *os2_prime = (OT::os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr); if (unlikely (!os2_prime)) { hb_blob_destroy (os2_prime_blob); - return nullptr; + return false; } uint16_t min_cp, max_cp; @@ -66,7 +66,7 @@ struct os2 os2_prime->usFirstCharIndex.set (min_cp); os2_prime->usLastCharIndex.set (max_cp); - return os2_prime_blob; + return hb_subset_plan_add_table(plan, HB_OT_TAG_os2, os2_prime_blob); } static inline void find_min_and_max_codepoint (hb_subset_plan_t *plan, diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc index 36789f9bf..f1bca10db 100644 --- a/src/hb-subset-glyf.cc +++ b/src/hb-subset-glyf.cc @@ -157,16 +157,15 @@ _hb_subset_glyf_and_loca (const OT::glyf::accelerator_t &glyf, **/ bool hb_subset_glyf_and_loca (hb_subset_plan_t *plan, - hb_face_t *face, bool *use_short_loca, /* OUT */ hb_blob_t **glyf_prime, /* OUT */ hb_blob_t **loca_prime /* OUT */) { - hb_blob_t *glyf_blob = OT::Sanitizer().sanitize (face->reference_table (HB_OT_TAG_glyf)); + hb_blob_t *glyf_blob = OT::Sanitizer().sanitize (plan->source->reference_table (HB_OT_TAG_glyf)); const char *glyf_data = hb_blob_get_data(glyf_blob, nullptr); OT::glyf::accelerator_t glyf; - glyf.init(face); + glyf.init(plan->source); bool result = _hb_subset_glyf_and_loca (glyf, glyf_data, plan->gids_to_retain_sorted, diff --git a/src/hb-subset-glyf.hh b/src/hb-subset-glyf.hh index 491bf82b1..99b76db9b 100644 --- a/src/hb-subset-glyf.hh +++ b/src/hb-subset-glyf.hh @@ -33,7 +33,6 @@ HB_INTERNAL bool hb_subset_glyf_and_loca (hb_subset_plan_t *plan, - hb_face_t *face, bool *use_short_loca, /* OUT */ hb_blob_t **glyf_prime /* OUT */, hb_blob_t **loca_prime /* OUT */); diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 6f4b003b3..0381e25cc 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -72,6 +72,14 @@ hb_subset_plan_new_gid_for_old_id (hb_subset_plan_t *plan, return false; } +hb_bool_t +hb_subset_plan_add_table (hb_subset_plan_t *plan, + hb_tag_t tag, + hb_blob_t *contents) +{ + return hb_subset_face_add_table(plan->dest, tag, contents); +} + static void _populate_codepoints (hb_set_t *input_codepoints, hb_prealloced_array_t& plan_codepoints) @@ -110,6 +118,7 @@ _populate_gids_to_retain (hb_face_t *face, *(old_gids.push ()) = gid; } + /* Generally there shouldn't be any */ while (bad_indices.len > 0) { unsigned int i = bad_indices[bad_indices.len - 1]; bad_indices.pop (); @@ -154,12 +163,15 @@ hb_subset_plan_create (hb_face_t *face, plan->codepoints.init(); plan->gids_to_retain.init(); plan->gids_to_retain_sorted.init(); + plan->source = face; + plan->dest = hb_subset_face_create (); _populate_codepoints (input->unicodes, plan->codepoints); _populate_gids_to_retain (face, plan->codepoints, plan->gids_to_retain, plan->gids_to_retain_sorted); + return plan; } diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 09df7cddf..0a43eb90b 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -38,9 +38,14 @@ struct hb_subset_plan_t { // TODO(Q1) actual map, drop this crap // Look at me ma, I'm a poor mans map codepoint : new gid // codepoints is sorted and aligned with gids_to_retain. + // TODO Also you should init/fini those arrays hb_prealloced_array_t codepoints; hb_prealloced_array_t gids_to_retain; hb_prealloced_array_t gids_to_retain_sorted; + + // Plan is only good for a specific source/dest so keep them with it + hb_face_t *source; + hb_face_t *dest; }; typedef struct hb_subset_plan_t hb_subset_plan_t; @@ -60,6 +65,11 @@ hb_subset_plan_new_gid_for_codepoint(hb_subset_plan_t *plan, hb_codepoint_t codepont, hb_codepoint_t *new_gid /* OUT */); +HB_INTERNAL hb_bool_t +hb_subset_plan_add_table(hb_subset_plan_t *plan, + hb_tag_t tag, + hb_blob_t *contents); + HB_INTERNAL void hb_subset_plan_destroy (hb_subset_plan_t *plan); diff --git a/src/hb-subset-private.hh b/src/hb-subset-private.hh index 4ef1b9540..3d6f8b4a5 100644 --- a/src/hb-subset-private.hh +++ b/src/hb-subset-private.hh @@ -34,6 +34,8 @@ #include "hb-font-private.hh" +typedef struct hb_subset_face_data_t hb_subset_face_data_t; + struct hb_subset_input_t { hb_object_header_t header; ASSERT_POD (); @@ -50,4 +52,13 @@ struct hb_subset_input_t { */ }; +HB_INTERNAL hb_face_t * +hb_subset_face_create (void); + +HB_INTERNAL hb_bool_t +hb_subset_face_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob); + +HB_INTERNAL void +hb_subset_face_data_destroy (void *user_data); + #endif /* HB_SUBSET_PRIVATE_HH */ diff --git a/src/hb-subset.cc b/src/hb-subset.cc index e7f2d912c..4de146ea1 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -21,12 +21,14 @@ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * - * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod + * Google Author(s): Garret Rieger, Rod Sheeter */ #include "hb-object-private.hh" #include "hb-open-type-private.hh" +#include "hb-private.hh" + #include "hb-subset-glyf.hh" #include "hb-subset-private.hh" #include "hb-subset-plan.hh" @@ -35,6 +37,8 @@ #include "hb-ot-cmap-table.hh" #include "hb-ot-glyf-table.hh" #include "hb-ot-head-table.hh" +#include "hb-ot-hhea-table.hh" +#include "hb-ot-hmtx-table.hh" #include "hb-ot-maxp-table.hh" #include "hb-ot-os2-table.hh" @@ -76,13 +80,13 @@ hb_subset_profile_destroy (hb_subset_profile_t *profile) } template -static hb_blob_t * -_subset (hb_subset_plan_t *plan, hb_face_t *source) +static hb_bool_t +_subset (hb_subset_plan_t *plan) { OT::Sanitizer sanitizer; - hb_blob_t *source_blob = sanitizer.sanitize (source->reference_table (TableType::tableTag)); + hb_blob_t *source_blob = sanitizer.sanitize (plan->source->reference_table (TableType::tableTag)); const TableType *table = OT::Sanitizer::lock_instance (source_blob); - hb_blob_t *result = table->subset(plan, source); + hb_bool_t result = table->subset(plan); hb_blob_destroy (source_blob); @@ -124,8 +128,8 @@ _hb_subset_face_data_create (void) return data; } -static void -_hb_subset_face_data_destroy (void *user_data) +void +hb_subset_face_data_destroy (void *user_data) { hb_subset_face_data_t *data = (hb_subset_face_data_t *) user_data; @@ -188,7 +192,7 @@ _hb_subset_face_reference_table (hb_face_t *face, hb_tag_t tag, void *user_data) return nullptr; } -static hb_face_t * +hb_face_t * hb_subset_face_create (void) { hb_subset_face_data_t *data = _hb_subset_face_data_create (); @@ -196,13 +200,13 @@ hb_subset_face_create (void) return hb_face_create_for_tables (_hb_subset_face_reference_table, data, - _hb_subset_face_data_destroy); + hb_subset_face_data_destroy); } -static bool +hb_bool_t hb_subset_face_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob) { - if (unlikely (face->destroy != _hb_subset_face_data_destroy)) + if (unlikely (face->destroy != hb_subset_face_data_destroy)) return false; hb_subset_face_data_t *data = (hb_subset_face_data_t *) face->user_data; @@ -221,7 +225,7 @@ _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_ { hb_blob_t *head_blob = OT::Sanitizer().sanitize (hb_face_reference_table (source, HB_OT_TAG_head)); const OT::head *head = OT::Sanitizer::lock_instance (head_blob); - bool has_head = (head != nullptr); + hb_bool_t has_head = (head != nullptr); if (has_head) { OT::head *head_prime = (OT::head *) calloc (OT::head::static_size, 1); @@ -242,7 +246,7 @@ _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_ } static bool -_subset_glyf (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) +_subset_glyf (hb_subset_plan_t *plan) { hb_blob_t *glyf_prime = nullptr; hb_blob_t *loca_prime = nullptr; @@ -250,10 +254,10 @@ _subset_glyf (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) bool success = true; bool use_short_loca = false; // TODO(grieger): Migrate to subset function on the table like cmap. - if (hb_subset_glyf_and_loca (plan, source, &use_short_loca, &glyf_prime, &loca_prime)) { - success = success && hb_subset_face_add_table (dest, HB_OT_TAG_glyf, glyf_prime); - success = success && hb_subset_face_add_table (dest, HB_OT_TAG_loca, loca_prime); - success = success && _add_head_and_set_loca_version (source, use_short_loca, dest); + if (hb_subset_glyf_and_loca (plan, &use_short_loca, &glyf_prime, &loca_prime)) { + success = success && hb_subset_plan_add_table (plan, HB_OT_TAG_glyf, glyf_prime); + success = success && hb_subset_plan_add_table (plan, HB_OT_TAG_loca, loca_prime); + success = success && _add_head_and_set_loca_version (plan->source, use_short_loca, plan->dest); } else { success = false; } @@ -265,39 +269,50 @@ _subset_glyf (hb_subset_plan_t *plan, hb_face_t *source, hb_face_t *dest) static bool _subset_table (hb_subset_plan_t *plan, - hb_face_t *source, - hb_tag_t tag, - hb_blob_t *source_blob, - hb_face_t *dest) + hb_tag_t tag) { // TODO (grieger): Handle updating the head table (loca format + num glyphs) DEBUG_MSG(SUBSET, nullptr, "begin subset %c%c%c%c", HB_UNTAG(tag)); - hb_blob_t *dest_blob; + bool result = true; switch (tag) { case HB_OT_TAG_glyf: - return _subset_glyf (plan, source, dest); + result = _subset_glyf (plan); + break; case HB_OT_TAG_head: // SKIP head, it's handled by glyf + result = true; + break; + case HB_OT_TAG_hhea: + // SKIP hhea, it's handled by hmtx return true; + case HB_OT_TAG_hmtx: + result = _subset (plan); + break; case HB_OT_TAG_maxp: - dest_blob = _subset (plan, source); + result = _subset (plan); break; case HB_OT_TAG_loca: // SKIP loca, it's handle by glyf return true; case HB_OT_TAG_cmap: - dest_blob = _subset (plan, source); + result = _subset (plan); break; case HB_OT_TAG_os2: - dest_blob = _subset (plan, source); + result = _subset (plan); break; default: - dest_blob = source_blob; + hb_blob_t *source_table = hb_face_reference_table(plan->source, tag); + if (likely(source_table)) + { + result = hb_subset_plan_add_table(plan, tag, source_table); + } + else + { + result = false; + } break; } - DEBUG_MSG(SUBSET, nullptr, "subset %c%c%c%c %s", HB_UNTAG(tag), dest_blob ? "ok" : "FAILED"); - if (unlikely(!dest_blob)) return false; - if (unlikely(!hb_subset_face_add_table (dest, tag, dest_blob))) return false; + DEBUG_MSG(SUBSET, nullptr, "subset %c%c%c%c %s", HB_UNTAG(tag), result ? "ok" : "FAILED"); return true; } @@ -325,14 +340,13 @@ _should_drop_table(hb_tag_t tag) **/ hb_face_t * hb_subset (hb_face_t *source, - hb_subset_profile_t *profile, + hb_subset_profile_t *profile, hb_subset_input_t *input) { if (unlikely (!profile || !input || !source)) return hb_face_get_empty(); hb_subset_plan_t *plan = hb_subset_plan_create (source, profile, input); - hb_face_t *dest = hb_subset_face_create (); hb_tag_t table_tags[32]; unsigned int offset = 0, count; bool success = true; @@ -347,12 +361,11 @@ hb_subset (hb_face_t *source, DEBUG_MSG(SUBSET, nullptr, "drop %c%c%c%c", HB_UNTAG(tag)); continue; } - hb_blob_t *blob = hb_face_reference_table (source, tag); - success = success && _subset_table (plan, source, tag, blob, dest); - hb_blob_destroy (blob); + success = success && _subset_table (plan, tag); } } while (count == ARRAY_LENGTH (table_tags)); + hb_face_t *result = success ? hb_face_reference(plan->dest) : hb_face_get_empty(); hb_subset_plan_destroy (plan); - return success ? dest : hb_face_get_empty (); + return result; } diff --git a/test/api/Makefile.am b/test/api/Makefile.am index 071264e1b..dafbb0e49 100644 --- a/test/api/Makefile.am +++ b/test/api/Makefile.am @@ -31,6 +31,7 @@ TEST_PROGS = \ test-shape \ test-subset-cmap \ test-subset-glyf \ + test-subset-hmtx \ test-subset-os2 \ test-unicode \ test-version \ @@ -39,6 +40,7 @@ TEST_PROGS = \ test_subset_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_cmap_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_glyf_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la +test_subset_hmtx_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_subset_os2_LDADD = $(LDADD) $(top_builddir)/src/libharfbuzz-subset.la test_unicode_CPPFLAGS = \ @@ -65,6 +67,11 @@ TEST_PROGS += \ test_ot_math_LDADD = $(LDADD) $(FREETYPE_LIBS) test_ot_math_CPPFLAGS = $(AM_CPPFLAGS) $(FREETYPE_CFLAGS) EXTRA_DIST += \ + fonts/Inconsolata-Regular.ab.ttf \ + fonts/Inconsolata-Regular.abc.ttf \ + fonts/Inconsolata-Regular.abc.widerc.ttf \ + fonts/Inconsolata-Regular.ac.ttf \ + fonts/Inconsolata-Regular.ac.widerc.ttf \ fonts/Roboto-Regular.abc.ttf \ fonts/Roboto-Regular.ac.ttf \ fonts/MathTestFontEmpty.otf \ diff --git a/test/api/fonts/Inconsolata-Regular.ab.ttf b/test/api/fonts/Inconsolata-Regular.ab.ttf new file mode 100644 index 0000000000000000000000000000000000000000..455cc15f462b88190117a0469454a90fc593eef9 GIT binary patch literal 5048 zcmbVQYiwM_6`r|wU$)~{?A;{Zgv|QdPU^k8IDW;3C0X`m!kT3Lh`E;l-s|-v&^%1y zgg|+>eR;v0BRq(5UO0AmhcjoRIJ0uNa zt=##}oNvyYbLPyMq9kZpO5^lS|H`|4+YLVNCxi^rI)yq5qBD zfc#g;Jtt4EUDA440`iA6{?yr$!+yr2kYS$%PCJ)YdA_9+@)~4u#yP#@VNLJBpN}A? zR?nVatIo0^%x{u@_1x0x_~_BINXRcC{{opfQ2ms@%RgYdn8E&%Y}*miG`)>`wcTFL z=hYv~%a($b6d-zins5qILw)=F zM*C3E=L-fYNugk;&u5H|jtti_^!MD(UGZt39?I{VTOPFz#2!eGkL8|g>g`TwZ}@#J z?f>XCFP%Sn_F(e(3CmtQ_A7*es$e>MlKI)A_@}WRHp0G(zE_(==qD{xbx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B=OYmCVnhmnq475OmH)1GsZd9%iAv z8{_%0pn)C6;U5NP7wEgoCNP9Lu7)mwBzRC+xIx@u2{h)hxYscPSKPFyRerh`O5?$5 z90V-z^i|?u#1NwW>munxw-937n4nE5d$Fp_ai$VsHfu#i47XgeUU4U(^wSjRz2J^O zw0?JYllR$*%NdnS!QO~GP~FXmekD~odIY%BNSGUZr!BcQsdx?#eU`@%((9@SS7NBUm2A)!$jg^5YW zWh&olPN*ymoU16#nd?RheFwJ?s&%K%KYtNV+^wX(NZnF|sYS(%v0!LJg@o*ijcN4O zv2ZmG%~_z_Ih$~t=1vjLp-vOdp&liiLp?@&CINe#_9SAC_9P-l zdlHc+%s7ZMgdw6p7$W8gL&Sn(R|3?cV;50Nj$K5Zb?hSQ3CAv?o^PwDYM4fZ& zB5D~iesDd3=N(QSgy4cp9s;>SK_{4ugL?|MQILeW=#qrFKaZ6$SKoD)B*52P zk^o-^_Q1NnZ#bNz?**46_=_${@NZ(}0axEkE=hnJE=how&6_ovQhiuWgr#pmsy*3j z)!TFgwS8xQe(JlgX!8z-yIOzNDCVki0KP$LdM<2b1?w~hNtp;Zie@#?q z1&^}mi1@%l>t3o_^Zmk3wh#|D_<$Q#b(FP~@I?m!We{SP=w0YCr% literal 0 HcmV?d00001 diff --git a/test/api/fonts/Inconsolata-Regular.abc.widerc.ttf b/test/api/fonts/Inconsolata-Regular.abc.widerc.ttf new file mode 100644 index 0000000000000000000000000000000000000000..352f269922339f1207c5810b932b989786bbd05a GIT binary patch literal 5228 zcmbVQTWnlM8J;=k?8SC`i@oc_YuB?rUfcDa-6X!nX*S7bFLsi36Wejpa}rwbW^E^h zT-@B6mX;Q1X}Snh2_9OhLP&@Q5JIy~X#*-K4?IvFKxz>@@B(iL6$y#7AP`-?f6lIJ zrwOULme2hE{NMcZ-{zk^%Q$1K6%T{8Ol7i@tQ8b%_hU9VHFM->=IZnn@B+M;I(jU1 z^WQgbgHM7VI&yT|@Z#|+zhI2N3O-*vS6E@2*qe-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W;Ii=HzxPgc2m)> zrYcWg0q%6UmfpQ+6mg2;q-;ssGa+1=BH_f#ao&ytx^IJYE;O@2n%p3*tzED0&K3JD zIT2kCs4c2(n6l)qXbGi9^;N==zL#xCXk5l&Vp_RONt;0mEy zS9SjBi+Jj8CG}bAmLg0oDq&89!s{v|>{M;cqPI>&YjKzaw<{W^EKww?o~$`N1*Ze< z0ms)3oaMH-9L0G)aF6+eP{-Tb8Q{Bb=fhr9IPtJw|&Hu|Rtgk*7V0C=g~6#3{lMQ6vlzi-aL!N!gVG zwXEzS>a?@0hWwkj&D__Yl``|C z-k2Kc(b*7@Z$0Gi_iy&=ewWL5w|l$1imOk(-E^z&mT?QOVReu;rru^r^{059Wy*d0 z`YgWSU$@KpVy4_r+|T^aGj1fW7x66@5WLMeZzcSL{&v5+ zCIchy^OsYyFuUc?4MQKywXQzeTPT+a~L)CcKvhy9^1-H_S|AIiz5 z89ONe^msMTX}q8t3qEcbJvl%3df5U_E(@^fP)@c0*LN2jb_pmjU%-*>=7jC|R60MM zI^-c4=4qa)%t&uroo`E&1p@(d%xm`ckByFxj|_M8_nW<5-@y3D=JB0G z2HHpX@zaNgE>0ic`}n?Hac?%$yRXws7PlWaVx!Y`fxox>^gkwNv%9t*81O#4uXAfW z`H}O;oNss}2Uio-UnT-fu$yl-Xqw01)rfV&*IottaQ>9uHga>e~8nh3^2V zP!UpJ@N!-6)@!l4kGACf6;YJhgF*b}B!WF%oyb}HKx>=d*AWf&5BSX1k$~452vCrM zfp)Lg93LMWtw!k2lUugN=e&9_H*kD;+};s8klr;h`AkEkH=(`e^ES2qHDX=6boj!~ zm2V)oN z3{Q(k)5a%u9N2poX$`M- zL3WUxXGL}a&r5io#V~+uK+&) literal 0 HcmV?d00001 diff --git a/test/api/fonts/Inconsolata-Regular.ac.ttf b/test/api/fonts/Inconsolata-Regular.ac.ttf new file mode 100644 index 0000000000000000000000000000000000000000..991b8de4a95d27489888c4ae2d78ba64ad01b278 GIT binary patch literal 4940 zcm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(8fa13MQBOcMQB;sMd(Ro7on$=U4*`(>>_kt*+pmt zF}{Cu11~5^jzMwJgU10^Ddo^B|3Q z#)Cw^j(LuHQ$FiKB0T3oB77Cx9YI`m&mi$nHfe{h{7aQ%DbaQZ_IU=m;pOHvMM(dd<3T z9iL-0(AK5jWGVGe$vVrHyZMbNyx`xk%KCh^+)L6gLoYGzOWi2qEf*Ag&Dd`wLw%u^ zkiN737O%V_ec#2so4x6u53p<&Mt;uUB)+|qEUB&H%kzi)9mXoQ{=w}(XxA#AKz^_C zNoAU3uoREKu${+WuKZ_%r^Z!znD4*a=6i|#YlAnd=A$p_ee@;jtHD_e!%7cpc%2Qi z6YK&jvWs|L#`8SBNw45H%@)`ayQ<_%YJ_sGGQ|b~wtW>V1&%DfXd9Gfr|KaVee2TG s8&Qk@ci4xrGCnzr&sQI@)K@S8;?%NUd?jm2Uw_`ca)Ir>gGEgCKRS5YPXGV_ literal 0 HcmV?d00001 diff --git a/test/api/fonts/Inconsolata-Regular.ac.widerc.ttf b/test/api/fonts/Inconsolata-Regular.ac.widerc.ttf new file mode 100644 index 0000000000000000000000000000000000000000..2050c28dcc43bb492b48e998fb12b82490f71f39 GIT binary patch literal 4944 zcmbVQ+ix6K89!%cZ?@x0d|4-6CqC=39oIX%aqQS}noY8u-L;$8P1l#CGbycSvc9BX zCvI*{3#9>Cnl1uWf(MWgAo0{bopp*DP(gX%fxLi35&Q#v;Gswe+9HAI^83zsT{}%^ zRa>6(edqg~?|irOof$LE7~6?QfHh6z^5bkL(->=hAG6Vk!sD~KYg1PlYYBiC6SJqS z+yB1(0r(#91CP({A6htb^*4;^uY-4stKJ%Wj=cl^@8HwLYgfd`ygq~t{tEtwOKZ!k z*A`xS0h^hO)kl}T%WIf#!hY{zj4ZD_zx4F(My%zX_0<`>XqxE40{H=3x3DS#iGZ4!u|nXfRC(t*VlNa{t|ewOkD6*7Xz&Bx7hCn zcx&zALTpTf&V!oaiH=c|22P??Pdo1L#C-cs%d%?4{Du3 z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zMZyrVKo}wxm0cF7C1n>;%gQdI&MUi!dPdnr)R&cAM14isMbwJ2i>Ot^_~Fe2UQnDo z2Ej$2JPvY=f=)1*0rxDfQILeWq9-OL0oy z%RWi)SA3G--^R+LzP?v|k^nb-k^rxnw`u}f^<~vc$jGA9dkWX9*K`uKgpZ-$&EUI^Ba)_SMmPR*Ub9ej?}Kw59T z!!qhu@jAV4oLX1KLEnG3>AS)HwSk*c`k;pGr7zJy4bEZ|R{FGt*V!mL!7i{OyNKsy zJXi2ddIf(oY>_RqtBSv*Rw(Bx(`*O?eba9L!I8xmZKIOx*bre3JJZu&QH%dQ>_uA{ jpPIwxYk*MdE0_qv)UrN&C2LCFu;N|0z;@k(A|(4C8~fN# literal 0 HcmV?d00001 diff --git a/test/api/fonts/README b/test/api/fonts/README index a365afd74..7e7783c24 100644 --- a/test/api/fonts/README +++ b/test/api/fonts/README @@ -1 +1,3 @@ cmap-format12-only files created by ttx & remove all other cmap entries + +Inconsolata-Regular.abc.widerc.ttf has the hmtx width of "c" set to 600; everything else is 500. Subsetting out c should reduce numberOfHMetrics to 1. diff --git a/test/api/test-subset-hmtx.c b/test/api/test-subset-hmtx.c new file mode 100644 index 000000000..24a99c37c --- /dev/null +++ b/test/api/test-subset-hmtx.c @@ -0,0 +1,164 @@ +/* + * Copyright © 2018 Google, Inc. + * + * This is part of HarfBuzz, a text shaping library. + * + * Permission is hereby granted, without written agreement and without + * license or royalty fees, to use, copy, modify, and distribute this + * software and its documentation for any purpose, provided that the + * above copyright notice and the following two paragraphs appear in + * all copies of this software. + * + * IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE TO ANY PARTY FOR + * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES + * ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN + * IF THE COPYRIGHT HOLDER HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH + * DAMAGE. + * + * THE COPYRIGHT HOLDER SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, + * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS + * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO + * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. + * + * Google Author(s): Roderick Sheeter + */ + +#include + +#include "hb-test.h" +#include "hb-subset-test.h" + +/* Unit tests for hmtx subsetting */ + +static void check_num_hmetrics(hb_face_t *face, uint16_t expected_num_hmetrics) +{ + hb_blob_t *hhea_blob = hb_face_reference_table (face, HB_TAG ('h','h','e','a')); + hb_blob_t *hmtx_blob = hb_face_reference_table (face, HB_TAG ('h','m','t','x')); + + // TODO I sure wish I could just use the hmtx table struct! + unsigned int hmtx_len = hb_blob_get_length(hmtx_blob); + unsigned int hhea_len; + uint8_t *raw_hhea = (uint8_t *) hb_blob_get_data(hhea_blob, &hhea_len); + uint16_t num_hmetrics = (raw_hhea[hhea_len - 2] << 8) + raw_hhea[hhea_len - 1]; + g_assert_cmpuint(expected_num_hmetrics, ==, num_hmetrics); + + hb_blob_destroy (hhea_blob); + hb_blob_destroy (hmtx_blob); +} + +static void +test_subset_hmtx_simple_subset (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.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_set_add (codepoints, 'a'); + hb_set_add (codepoints, 'c'); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + check_num_hmetrics(face_abc_subset, 3); /* nothing has same width */ + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('h','m','t','x')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ac); +} + + +static void +test_subset_hmtx_monospace (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Inconsolata-Regular.abc.ttf"); + hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Inconsolata-Regular.ac.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_set_add (codepoints, 'a'); + hb_set_add (codepoints, 'c'); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + check_num_hmetrics(face_abc_subset, 1); /* everything has same width */ + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('h','m','t','x')); + // TODO hhea + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ac); +} + + +static void +test_subset_hmtx_keep_num_metrics (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Inconsolata-Regular.abc.widerc.ttf"); + hb_face_t *face_ac = hb_subset_test_open_font ("fonts/Inconsolata-Regular.ac.widerc.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_set_add (codepoints, 'a'); + hb_set_add (codepoints, 'c'); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + check_num_hmetrics(face_abc_subset, 3); /* c is wider */ + hb_subset_test_check (face_ac, face_abc_subset, HB_TAG ('h','m','t','x')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ac); +} + +static void +test_subset_hmtx_decrease_num_metrics (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font ("fonts/Inconsolata-Regular.abc.widerc.ttf"); + hb_face_t *face_ab = hb_subset_test_open_font ("fonts/Inconsolata-Regular.ab.ttf"); + + hb_set_t *codepoints = hb_set_create (); + hb_set_add (codepoints, 'a'); + hb_set_add (codepoints, 'b'); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + check_num_hmetrics(face_abc_subset, 1); /* everything left has same width */ + hb_subset_test_check (face_ab, face_abc_subset, HB_TAG ('h','m','t','x')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); + hb_face_destroy (face_ab); +} + +static void +test_subset_hmtx_noop (void) +{ + hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf"); + + hb_set_t *codepoints = hb_set_create(); + hb_set_add (codepoints, 'a'); + hb_set_add (codepoints, 'b'); + hb_set_add (codepoints, 'c'); + hb_face_t *face_abc_subset = hb_subset_test_create_subset (face_abc, codepoints); + hb_set_destroy (codepoints); + + check_num_hmetrics(face_abc_subset, 4); /* nothing has same width */ + hb_subset_test_check (face_abc, face_abc_subset, HB_TAG ('h','m','t','x')); + + hb_face_destroy (face_abc_subset); + hb_face_destroy (face_abc); +} + +int +main (int argc, char **argv) +{ + hb_test_init (&argc, &argv); + + hb_test_add (test_subset_hmtx_simple_subset); + hb_test_add (test_subset_hmtx_monospace); + hb_test_add (test_subset_hmtx_keep_num_metrics); + hb_test_add (test_subset_hmtx_decrease_num_metrics); + hb_test_add (test_subset_hmtx_noop); + + return hb_test_run(); +} From d463e9f6b57bebb3aa4875fe11c927c26c3e3974 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 15:04:15 -0800 Subject: [PATCH 29/40] [subset] Give Behdad credit again --- src/hb-subset.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 4de146ea1..ce7881f0e 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -21,7 +21,7 @@ * ON AN "AS IS" BASIS, AND THE COPYRIGHT HOLDER HAS NO OBLIGATION TO * PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. * - * Google Author(s): Garret Rieger, Rod Sheeter + * Google Author(s): Garret Rieger, Rod Sheeter, Behdad Esfahbod */ #include "hb-object-private.hh" From 42a80f00d51317207c49611b76d6bba06230371b Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 15:04:35 -0800 Subject: [PATCH 30/40] [subset] add free --- src/hb-ot-hmtx-table.hh | 1 + 1 file changed, 1 insertion(+) diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index 7fae4f6cd..e69f9ea40 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -79,6 +79,7 @@ struct hmtxvmtx hb_blob_t *src_blob = OT::Sanitizer().sanitize (plan->source->reference_table (T::tableTag)); if (unlikely(!src_blob)) { + free(dest); return false; } unsigned int src_length; From 88d56e241bd6bb768656d77cf8f99ccc97fb2446 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 15:20:43 -0800 Subject: [PATCH 31/40] [subset] Use a supplier instead of memcpy and fix a few unnecessary {}s for cmap --- src/hb-ot-cmap-table.hh | 24 ++++++------------------ 1 file changed, 6 insertions(+), 18 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 6c5f3c282..b7332293f 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -276,8 +276,8 @@ struct CmapSubtableLongSegmented { TRACE_SERIALIZE (this); if (unlikely(!context->extend_min (*this))) return_trace (false); - if (unlikely(!groups.serialize(context, group_data.len))) return_trace (false); - memcpy(&groups[0], &group_data[0], group_data.len * sizeof(CmapSubtableLongGroup)); + Supplier supplier(group_data.array, group_data.len); + if (unlikely(!groups.serialize(context, supplier, group_data.len))) return_trace (false); return true; } @@ -565,10 +565,7 @@ struct cmap cmap->version.set(0); - if (unlikely(!cmap->encodingRecord.serialize(&context, /* numTables */ 1))) - { - return false; - } + if (unlikely(!cmap->encodingRecord.serialize(&context, /* numTables */ 1))) return false; EncodingRecord &rec = cmap->encodingRecord[0]; rec.platformID.set (3); // Windows @@ -580,19 +577,13 @@ struct cmap subtable.u.format.set(12); CmapSubtableFormat12 &format12 = subtable.u.format12; - if (unlikely(!context.extend_min(format12))) - { - return false; - } + if (unlikely(!context.extend_min(format12))) return false; format12.format.set(12); format12.reservedZ.set(0); format12.lengthZ.set(16 + 12 * groups.len); - if (unlikely(!format12.serialize(&context, groups))) - { - return false; - } + if (unlikely(!format12.serialize(&context, groups))) return false; context.end_serialize (); @@ -603,10 +594,7 @@ struct cmap { hb_auto_array_t groups; - if (unlikely(!populate_groups(plan, &groups))) - { - return false; - } + if (unlikely(!populate_groups(plan, &groups))) return false; // We now know how big our blob needs to be // TODO use APIs from the structs to get size? From 3ed70e5e64910e1c22225f542a525807b000cb2a Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 15:24:49 -0800 Subject: [PATCH 32/40] [subset] return bool not hb_bool_t from table::subset --- src/hb-ot-cmap-table.hh | 2 +- src/hb-ot-maxp-table.hh | 2 +- src/hb-ot-os2-table.hh | 2 +- src/hb-subset.cc | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index b7332293f..98f0b5614 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -590,7 +590,7 @@ struct cmap return true; } - inline hb_bool_t subset (hb_subset_plan_t *plan) const + inline bool subset (hb_subset_plan_t *plan) const { hb_auto_array_t groups; diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 00a95d716..34eb9ae84 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -61,7 +61,7 @@ struct maxp (version.major == 0 && version.minor == 0x5000u))); } - inline hb_bool_t subset (hb_subset_plan_t *plan) const + inline bool subset (hb_subset_plan_t *plan) const { hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp)); hb_blob_t *maxp_prime_blob = hb_blob_create_sub_blob (maxp_blob, 0, -1); diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 1bb9a1535..9bc75c0c0 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -49,7 +49,7 @@ struct os2 return_trace (c->check_struct (this)); } - inline hb_bool_t subset (hb_subset_plan_t *plan) const + inline bool subset (hb_subset_plan_t *plan) const { hb_blob_t *os2_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_os2)); hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1); diff --git a/src/hb-subset.cc b/src/hb-subset.cc index ce7881f0e..69e8f77d3 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -80,7 +80,7 @@ hb_subset_profile_destroy (hb_subset_profile_t *profile) } template -static hb_bool_t +static bool _subset (hb_subset_plan_t *plan) { OT::Sanitizer sanitizer; From 4696624ad9987b0eebcf5c84dafdb204b886f28e Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 15:30:49 -0800 Subject: [PATCH 33/40] [subset] maxp wrong int type, note to use copy_writable_or_fail --- src/hb-ot-maxp-table.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 34eb9ae84..0ad123ab9 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -48,7 +48,7 @@ struct maxp return numGlyphs; } - inline void set_num_glyphs (uint16_t count) + inline void set_num_glyphs (unsigned int count) { numGlyphs.set (count); } @@ -64,6 +64,7 @@ struct maxp inline bool subset (hb_subset_plan_t *plan) const { hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp)); + // TODO hb_blob_copy_writable_or_fail hb_blob_t *maxp_prime_blob = hb_blob_create_sub_blob (maxp_blob, 0, -1); hb_blob_destroy (maxp_blob); From 66e282df32410831f1c4e157e9dcf8c76f2bc3d8 Mon Sep 17 00:00:00 2001 From: Rod Sheeter Date: Wed, 14 Feb 2018 15:31:13 -0800 Subject: [PATCH 34/40] [subset] remove TODO that was already done --- src/hb-subset-plan.hh | 1 - 1 file changed, 1 deletion(-) diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh index 0a43eb90b..9a4308f9d 100644 --- a/src/hb-subset-plan.hh +++ b/src/hb-subset-plan.hh @@ -38,7 +38,6 @@ struct hb_subset_plan_t { // TODO(Q1) actual map, drop this crap // Look at me ma, I'm a poor mans map codepoint : new gid // codepoints is sorted and aligned with gids_to_retain. - // TODO Also you should init/fini those arrays hb_prealloced_array_t codepoints; hb_prealloced_array_t gids_to_retain; hb_prealloced_array_t gids_to_retain_sorted; From 3ab7d2649bf5c92d3837b3132d65d4659d0fa003 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 15:48:57 -0800 Subject: [PATCH 35/40] [subset] Fix memory leak in hb-ot-{maxp,os2}. Plus some formatting. --- src/hb-ot-maxp-table.hh | 6 ++++-- src/hb-ot-os2-table.hh | 24 +++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh index 0ad123ab9..ceb83628c 100644 --- a/src/hb-ot-maxp-table.hh +++ b/src/hb-ot-maxp-table.hh @@ -64,7 +64,7 @@ struct maxp inline bool subset (hb_subset_plan_t *plan) const { hb_blob_t *maxp_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp)); - // TODO hb_blob_copy_writable_or_fail + // TODO(grieger): hb_blob_copy_writable_or_fail hb_blob_t *maxp_prime_blob = hb_blob_create_sub_blob (maxp_blob, 0, -1); hb_blob_destroy (maxp_blob); @@ -76,7 +76,9 @@ struct maxp maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len); - return hb_subset_plan_add_table(plan, HB_OT_TAG_maxp, maxp_prime_blob); + bool result = hb_subset_plan_add_table(plan, HB_OT_TAG_maxp, maxp_prime_blob); + hb_blob_destroy (maxp_prime_blob); + return result; } /* We only implement version 0.5 as none of the extra fields in version 1.0 are useful. */ diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh index 9bc75c0c0..18dc4ab07 100644 --- a/src/hb-ot-os2-table.hh +++ b/src/hb-ot-os2-table.hh @@ -53,6 +53,7 @@ struct os2 { hb_blob_t *os2_blob = OT::Sanitizer().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_os2)); hb_blob_t *os2_prime_blob = hb_blob_create_sub_blob (os2_blob, 0, -1); + // TODO(grieger): move to hb_blob_copy_writable_or_fail hb_blob_destroy (os2_blob); OT::os2 *os2_prime = (OT::os2 *) hb_blob_get_data_writable (os2_prime_blob, nullptr); @@ -62,27 +63,28 @@ struct os2 } uint16_t min_cp, max_cp; - find_min_and_max_codepoint (plan, &min_cp, &max_cp); + find_min_and_max_codepoint (plan->codepoints, &min_cp, &max_cp); os2_prime->usFirstCharIndex.set (min_cp); os2_prime->usLastCharIndex.set (max_cp); - return hb_subset_plan_add_table(plan, HB_OT_TAG_os2, os2_prime_blob); + bool result = hb_subset_plan_add_table(plan, HB_OT_TAG_os2, os2_prime_blob); + hb_blob_destroy (os2_prime_blob); + return result; } - static inline void find_min_and_max_codepoint (hb_subset_plan_t *plan, - uint16_t *min_cp, /* OUT */ - uint16_t *max_cp /* OUT */) + static inline void find_min_and_max_codepoint (const hb_prealloced_array_t &codepoints, + uint16_t *min_cp, /* OUT */ + uint16_t *max_cp /* OUT */) { hb_codepoint_t min = -1, max = 0; - for (int i = 0; i < plan->codepoints.len; i++) { - hb_codepoint_t cp = plan->codepoints[i]; - if (cp < min) { + for (int i = 0; i < codepoints.len; i++) + { + hb_codepoint_t cp = codepoints[i]; + if (cp < min) min = cp; - } - if (cp > max) { + if (cp > max) max = cp; - } } if (min > 0xFFFF) From e330ef3711c543372f9f8550a967c512bbf87d83 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 15:57:11 -0800 Subject: [PATCH 36/40] [subset] Restore hb_face_data_destroy to be internal. --- src/hb-subset.cc | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 69e8f77d3..2eb4ebd04 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -128,8 +128,8 @@ _hb_subset_face_data_create (void) return data; } -void -hb_subset_face_data_destroy (void *user_data) +static void +_hb_subset_face_data_destroy (void *user_data) { hb_subset_face_data_t *data = (hb_subset_face_data_t *) user_data; @@ -200,13 +200,13 @@ hb_subset_face_create (void) return hb_face_create_for_tables (_hb_subset_face_reference_table, data, - hb_subset_face_data_destroy); + _hb_subset_face_data_destroy); } hb_bool_t hb_subset_face_add_table (hb_face_t *face, hb_tag_t tag, hb_blob_t *blob) { - if (unlikely (face->destroy != hb_subset_face_data_destroy)) + if (unlikely (face->destroy != _hb_subset_face_data_destroy)) return false; hb_subset_face_data_t *data = (hb_subset_face_data_t *) face->user_data; @@ -228,7 +228,7 @@ _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_ hb_bool_t has_head = (head != nullptr); if (has_head) { - OT::head *head_prime = (OT::head *) calloc (OT::head::static_size, 1); + OT::head *head_prime = (OT::head *) malloc (OT::head::static_size); memcpy (head_prime, head, OT::head::static_size); head_prime->indexToLocFormat.set (use_short_loca ? 0 : 1); From e0ffebead6230b8e1ee8dd97425505706321793e Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 16:01:08 -0800 Subject: [PATCH 37/40] [subset] In hb-subset-test use hb_set_union instead of manually copying set. --- test/api/hb-subset-test.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h index efae17976..de7f274f2 100644 --- a/test/api/hb-subset-test.h +++ b/test/api/hb-subset-test.h @@ -90,16 +90,14 @@ hb_subset_test_open_font (const char *font_path) static inline hb_face_t * hb_subset_test_create_subset (hb_face_t *source, - hb_set_t *codepoints) + const hb_set_t *codepoints) { hb_subset_profile_t *profile = hb_subset_profile_create(); hb_subset_input_t *input = hb_subset_input_create_or_fail (); hb_set_t * input_codepoints = hb_subset_input_unicode_set (input); - hb_codepoint_t codepoint = -1; - while (hb_set_next (codepoints, &codepoint)) { - hb_set_add (input_codepoints, codepoint); - } + + hb_set_union (input_codepoints, codepoints); hb_face_t *subset = hb_subset (source, profile, input); g_assert (subset); From b56c9384bcc177236debd26fdbbf14319e4c62b9 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 16:05:39 -0800 Subject: [PATCH 38/40] [subset] Add missing face reference in hb-subset-plan plus ensure all struct members are cleaned up on destroy. --- src/hb-subset-plan.cc | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc index 0381e25cc..034180a0c 100644 --- a/src/hb-subset-plan.cc +++ b/src/hb-subset-plan.cc @@ -163,7 +163,7 @@ hb_subset_plan_create (hb_face_t *face, plan->codepoints.init(); plan->gids_to_retain.init(); plan->gids_to_retain_sorted.init(); - plan->source = face; + plan->source = hb_face_reference (face); plan->dest = hb_subset_face_create (); _populate_codepoints (input->unicodes, plan->codepoints); @@ -189,5 +189,8 @@ hb_subset_plan_destroy (hb_subset_plan_t *plan) plan->gids_to_retain.finish (); plan->gids_to_retain_sorted.finish (); + hb_face_destroy (plan->source); + hb_face_destroy (plan->dest); + free (plan); } From 0775bc0f7a59241456142b48abced75fd3db5a42 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 16:37:35 -0800 Subject: [PATCH 39/40] [subset] Fix hhea subsetting and clean up some memory leaks. --- src/hb-ot-hmtx-table.hh | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh index e69f9ea40..1368214d1 100644 --- a/src/hb-ot-hmtx-table.hh +++ b/src/hb-ot-hmtx-table.hh @@ -76,26 +76,29 @@ struct hmtxvmtx return false; } - hb_blob_t *src_blob = OT::Sanitizer().sanitize (plan->source->reference_table (T::tableTag)); - if (unlikely(!src_blob)) - { - free(dest); + hb_blob_t *src_blob = OT::Sanitizer().sanitize (plan->source->reference_table (H::tableTag)); + unsigned int src_length; + const char *src_raw = hb_blob_get_data (src_blob, &src_length); + hb_blob_destroy (src_blob); + + if (src_length != sizeof (H)) { + free (dest); return false; } - unsigned int src_length; - const char *src_raw = hb_blob_get_data(src_blob, &src_length); - memcpy(dest, src_raw, src_length); H *table = (H *) dest; - table->numberOfLongMetrics.set(num_hmetrics); + table->numberOfLongMetrics.set (num_hmetrics); - hb_blob_t *dest_blob = hb_blob_create ((const char *)dest, + hb_blob_t *dest_blob = hb_blob_create ((const char *) dest, dest_sz, HB_MEMORY_MODE_READONLY, - /* userdata */ nullptr, + dest, free); - return hb_subset_plan_add_table(plan, H::tableTag, dest_blob); + bool result = hb_subset_plan_add_table (plan, H::tableTag, dest_blob); + hb_blob_destroy (dest_blob); + + return result; } inline bool subset (hb_subset_plan_t *plan) const From 04c1ec2b7396c05f6e8afc9d87679422782aa1e8 Mon Sep 17 00:00:00 2001 From: Garret Rieger Date: Wed, 14 Feb 2018 17:00:18 -0800 Subject: [PATCH 40/40] [subset] Don't fail on different checksum adjustment in subsetting tests. --- .../basics/Roboto-Regular.abc.default.62.ttf | Bin 1740 -> 1692 bytes test/subset/run-tests.py | 8 ++++++++ 2 files changed, 8 insertions(+) diff --git a/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf b/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf index 52706dc90320133d24a0a6c3109b9d1ef1bf8ec7..501d1d288c38e4ed350fe0fd177e11e8b6fb224c 100644 GIT binary patch delta 418 zcmXX?JxIeq7=5`UZBkOj9|~57fE@(ENu-0Ipo8uXF4D%NZG^@KTWmz6yL6~@)x}A4 zaBy%DQE(9)oW#*p=ui+rrC48D5AN=JKi|8br}%Nak*G-lfUNCVJ_hj(NG;+id$(dv zpG8jqb%J;;?-#u4SM~xBqx9Sqtg;UcBS54<-6$0I@^_cgBmH6Ct?PJ!t|~El-$LEZ zSx&dAFS71%&bcIvqs10xN1F|=#9FarTgb42>T`*BR^W>2d0LlUC*ig(~RA1|_q92are@}Q6Fu?O5Qea$jMPyC6 i4yPBsx9_qGJNz==f1fWvHt+9ZBOO^ delta 493 zcmX|-%_~Gv7{;Ib>E6jlGo%=4%IuV6A>t3fQWkdRny(vkxtWPUntx!5nk|vl$bwKx z(kv_}D>XYyOKA!`D(b?4+M0FkI;xd=+{fP6)skFIAz zgT5=|7&z&7}vZki`*smz! zcHD}6FFkLu_LV$pQ}Eqr$H+krQwZBmCTp0eu%M4@q*kLA7U)5G;iWrP)|E#TQ#?)% ztyoT6zV>}EWRu6-)pW*l5F;OnxVsj2j}tWxq&~1_8Zz?Un;O!AcJv@|5$Fy21LNm~ zJ?$hXu|mc!x-kb0fovz+0R<=r)&-z zX`;ynjiuxfQ+JRT^)0D7KhT`61?w~BaI-gs|0Nf)Qe=uK-ctF68m;no`sfK=Sbi-g bp&~@9atnRY^P0DJ*z9~+m9~|_gl_!;PVr#o diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py index faf615958..f648627ec 100755 --- a/test/subset/run-tests.py +++ b/test/subset/run-tests.py @@ -7,6 +7,7 @@ from __future__ import print_function import io import os +import re import subprocess import sys import tempfile @@ -57,6 +58,9 @@ def run_test(test): if return_code: return fail_test(test, cli_args, "ttx (actual) returned %d" % (return_code)) + expected_ttx = strip_check_sum (expected_ttx) + actual_ttx = strip_check_sum (expected_ttx) + if not actual_ttx == expected_ttx: return fail_test(test, cli_args, 'ttx for expected and actual does not match.') @@ -68,6 +72,10 @@ def run_ttx(file): file] return cmd(cli_args) +def strip_check_sum (ttx_string): + return re.sub ('checksumAdjustment value=["]0x(\d+)["]', + 'checksumAdjustment value="0x00000000"', + ttx_string, count=1) args = sys.argv[1:] if not args or sys.argv[1].find('hb-subset') == -1 or not os.path.exists (sys.argv[1]):