[HarfBuzz] harfbuzz: Branch 'master' - 72 commits
Behdad Esfahbod
behdad at kemper.freedesktop.org
Sat Feb 17 02:29:53 UTC 2018
TODO | 29 -
src/hb-open-file-private.hh | 15
src/hb-ot-cmap-table.hh | 123 +++----
src/hb-ot-glyf-table.hh | 119 +++++++
src/hb-ot-hhea-table.hh | 6
src/hb-ot-hmtx-table.hh | 163 ++++++++--
src/hb-ot-maxp-table.hh | 26 +
src/hb-ot-os2-table.hh | 99 ++++--
src/hb-subset-glyf.cc | 45 ++
src/hb-subset-glyf.hh | 1
src/hb-subset-plan.cc | 106 ++++--
src/hb-subset-plan.hh | 20 +
src/hb-subset-private.hh | 8
src/hb-subset.cc | 114 ++++--
test/api/Makefile.am | 22 -
test/api/fonts/Inconsolata-Regular.ab.ttf |binary
test/api/fonts/Inconsolata-Regular.abc.ttf |binary
test/api/fonts/Inconsolata-Regular.abc.widerc.ttf |binary
test/api/fonts/Inconsolata-Regular.ac.ttf |binary
test/api/fonts/Inconsolata-Regular.ac.widerc.ttf |binary
test/api/fonts/README | 3
test/api/fonts/Roboto-Regular.abc.cmap-format12-only.ttf |binary
test/api/fonts/Roboto-Regular.ac.cmap-format12-only.ttf |binary
test/api/fonts/Roboto-Regular.b.ttf |binary
test/api/fonts/Roboto-Regular.components.subset.ttf |binary
test/api/fonts/Roboto-Regular.components.ttf |binary
test/api/hb-subset-test.h | 126 +++++++
test/api/hb-test.h | 11
test/api/test-subset-cmap.c | 82 +++++
test/api/test-subset-glyf.c | 133 +++-----
test/api/test-subset-hmtx.c | 163 ++++++++++
test/api/test-subset-os2.c | 51 +--
test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf |binary
test/subset/generate-expected-outputs.py | 1
test/subset/run-tests.py | 8
35 files changed, 1115 insertions(+), 359 deletions(-)
New commits:
commit 181b7471074cc814e0f498fc05fd6850c3f5e403
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Feb 16 17:08:44 2018 -0800
Update outdated TODO file
diff --git a/TODO b/TODO
index 4f37f605..53ffbe9d 100644
--- a/TODO
+++ b/TODO
@@ -1,24 +1,14 @@
General fixes:
=============
-- AAT 'morx' implementation.
-
-- Return "safe-to-break" bit from shaping.
-
- Implement 'rand' feature.
-- mask propagation? (when ligation, "or" the masks).
-
API issues:
===========
- API to accept a list of languages?
-- Add init_func to font_funcs. Adjust ft.
-
-- 'const' for getter APIs? (use mutable internally)
-
- Remove hb_ot_shape_glyphs_closure()?
@@ -39,7 +29,7 @@ API additions
- Add query / enumeration API for aalt-like features?
-- SFNT api? get_num_faces? get_table_tags? (there's something in stash)
+- SFNT api? get_num_faces?
- Add segmentation API
@@ -50,20 +40,3 @@ hb-view / hb-shape enhancements:
===============================
- Add --width, --height, --auto-size, --ink-box, --align, etc?
-
-
-Tests to write:
-==============
-
-- ot-layout enumeration API (needs font)
-
-- Finish test-shape.c, grep for TODO
-
-- Finish test-unicode.c, grep for TODO
-
-- GObject, FreeType, etc
-
-- hb_cache_t and relatives
-
-- hb_feature_to/from_string
-- hb_buffer_[sg]et_contents
commit 6d56db8983e03fbebbeb61282bef8cb1f9abb8e2
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Feb 16 17:02:57 2018 -0800
[test/api] Distribute all fonts
diff --git a/test/api/Makefile.am b/test/api/Makefile.am
index 358cd57f..ecf44754 100644
--- a/test/api/Makefile.am
+++ b/test/api/Makefile.am
@@ -12,6 +12,8 @@ lib:
EXTRA_DIST += CMakeLists.txt
+EXTRA_DIST += fonts
+
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)
@@ -66,25 +68,6 @@ TEST_PROGS += \
$(NULL)
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.cmap-format12-only.ttf \
- fonts/Roboto-Regular.ac.cmap-format12-only.ttf \
- fonts/Roboto-Regular.b.ttf \
- fonts/Roboto-Regular.abc.ttf \
- fonts/Roboto-Regular.ac.ttf \
- fonts/MathTestFontEmpty.otf \
- fonts/MathTestFontFull.otf \
- fonts/MathTestFontNone.otf \
- fonts/MathTestFontPartial1.otf \
- fonts/MathTestFontPartial2.otf \
- fonts/MathTestFontPartial3.otf \
- fonts/MathTestFontPartial4.otf \
- $(NULL)
endif # HAVE_FREETYPE
endif # HAVE_OT
commit e5ab34fd3a104f7ff2f0b36c66770c88b2ea1051
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Fri Feb 16 16:58:17 2018 -0800
Misc fixes
Should bring bag djgpp bot.
diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh
index 18dc4ab0..2d9d2149 100644
--- a/src/hb-ot-os2-table.hh
+++ b/src/hb-ot-os2-table.hh
@@ -78,7 +78,7 @@ struct os2
{
hb_codepoint_t min = -1, max = 0;
- for (int i = 0; i < codepoints.len; i++)
+ for (unsigned int i = 0; i < codepoints.len; i++)
{
hb_codepoint_t cp = codepoints[i];
if (cp < min)
@@ -100,47 +100,47 @@ struct os2
HBUINT16 version;
/* Version 0 */
- HBINT16 xAvgCharWidth;
+ HBINT16 xAvgCharWidth;
HBUINT16 usWeightClass;
HBUINT16 usWidthClass;
HBUINT16 fsType;
- HBINT16 ySubscriptXSize;
- HBINT16 ySubscriptYSize;
- HBINT16 ySubscriptXOffset;
- HBINT16 ySubscriptYOffset;
- HBINT16 ySuperscriptXSize;
- HBINT16 ySuperscriptYSize;
- HBINT16 ySuperscriptXOffset;
- HBINT16 ySuperscriptYOffset;
- HBINT16 yStrikeoutSize;
- HBINT16 yStrikeoutPosition;
- HBINT16 sFamilyClass;
- HBUINT8 panose[10];
- HBUINT32 ulUnicodeRange[4];
+ HBINT16 ySubscriptXSize;
+ HBINT16 ySubscriptYSize;
+ HBINT16 ySubscriptXOffset;
+ HBINT16 ySubscriptYOffset;
+ HBINT16 ySuperscriptXSize;
+ HBINT16 ySuperscriptYSize;
+ HBINT16 ySuperscriptXOffset;
+ HBINT16 ySuperscriptYOffset;
+ HBINT16 yStrikeoutSize;
+ HBINT16 yStrikeoutPosition;
+ HBINT16 sFamilyClass;
+ HBUINT8 panose[10];
+ HBUINT32 ulUnicodeRange[4];
Tag achVendID;
HBUINT16 fsSelection;
HBUINT16 usFirstCharIndex;
HBUINT16 usLastCharIndex;
- HBINT16 sTypoAscender;
- HBINT16 sTypoDescender;
- HBINT16 sTypoLineGap;
+ HBINT16 sTypoAscender;
+ HBINT16 sTypoDescender;
+ HBINT16 sTypoLineGap;
HBUINT16 usWinAscent;
HBUINT16 usWinDescent;
/* Version 1 */
- //HBUINT32 ulCodePageRange1;
- //HBUINT32 ulCodePageRange2;
+ //HBUINT32 ulCodePageRange1;
+ //HBUINT32 ulCodePageRange2;
/* Version 2 */
- //HBINT16 sxHeight;
- //HBINT16 sCapHeight;
- //HBUINT16 usDefaultChar;
- //HBUINT16 usBreakChar;
- //HBUINT16 usMaxContext;
+ //HBINT16 sxHeight;
+ //HBINT16 sCapHeight;
+ //HBUINT16 usDefaultChar;
+ //HBUINT16 usBreakChar;
+ //HBUINT16 usMaxContext;
/* Version 5 */
- //HBUINT16 usLowerOpticalPointSize;
- //HBUINT16 usUpperOpticalPointSize;
+ //HBUINT16 usLowerOpticalPointSize;
+ //HBUINT16 usUpperOpticalPointSize;
public:
DEFINE_SIZE_STATIC (78);
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index d017cca1..b9e299ad 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -130,9 +130,11 @@ _populate_gids_to_retain (hb_face_t *face,
hb_auto_array_t<unsigned int> bad_indices;
old_gids.alloc (codepoints.len);
- for (unsigned int i = 0; i < codepoints.len; i++) {
+ for (unsigned int i = 0; i < codepoints.len; i++)
+ {
hb_codepoint_t gid;
- if (!cmap.get_nominal_glyph (codepoints[i], &gid)) {
+ if (!cmap.get_nominal_glyph (codepoints[i], &gid))
+ {
gid = -1;
*(bad_indices.push ()) = i;
}
@@ -140,7 +142,8 @@ _populate_gids_to_retain (hb_face_t *face,
}
/* Generally there shouldn't be any */
- while (bad_indices.len > 0) {
+ while (bad_indices.len > 0)
+ {
unsigned int i = bad_indices[bad_indices.len - 1];
bad_indices.pop ();
DEBUG_MSG(SUBSET, nullptr, "Drop U+%04X; no gid", codepoints[i]);
@@ -154,18 +157,13 @@ _populate_gids_to_retain (hb_face_t *face,
hb_set_t * all_gids_to_retain = hb_set_create ();
_add_gid_and_children (glyf, 0, all_gids_to_retain);
for (unsigned int i = 0; i < old_gids.len; i++)
- {
_add_gid_and_children (glyf, old_gids[i], all_gids_to_retain);
- }
// Transfer to a sorted list.
old_gids_sorted.alloc (hb_set_get_population (all_gids_to_retain));
- unsigned int gid = HB_SET_VALUE_INVALID;
+ hb_codepoint_t gid = HB_SET_VALUE_INVALID;
while (hb_set_next (all_gids_to_retain, &gid))
- {
*(old_gids_sorted.push ()) = gid;
- }
- old_gids_sorted.qsort (_hb_codepoint_t_cmp);
glyf.fini ();
cmap.fini ();
commit df9e22656de746bde65dee775a66f1a80f1c2e32
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 17:02:51 2018 -0700
[subset] add a glyf subsetting test for a font with composite glyphs.
diff --git a/test/api/fonts/Roboto-Regular.components.subset.ttf b/test/api/fonts/Roboto-Regular.components.subset.ttf
new file mode 100644
index 00000000..e759d776
Binary files /dev/null and b/test/api/fonts/Roboto-Regular.components.subset.ttf differ
diff --git a/test/api/fonts/Roboto-Regular.components.ttf b/test/api/fonts/Roboto-Regular.components.ttf
new file mode 100644
index 00000000..816e3a28
Binary files /dev/null and b/test/api/fonts/Roboto-Regular.components.ttf differ
diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c
index 3c9d8fe9..96e37bbc 100644
--- a/test/api/test-subset-glyf.c
+++ b/test/api/test-subset-glyf.c
@@ -53,6 +53,26 @@ test_subset_glyf (void)
}
static void
+test_subset_glyf_with_components (void)
+{
+ hb_face_t *face_components = hb_subset_test_open_font ("fonts/Roboto-Regular.components.ttf");
+ hb_face_t *face_subset = hb_subset_test_open_font ("fonts/Roboto-Regular.components.subset.ttf");
+
+ hb_set_t *codepoints = hb_set_create();
+ hb_set_add (codepoints, 0x1fc);
+ hb_face_t *face_generated_subset = hb_subset_test_create_subset (face_components, codepoints);
+ hb_set_destroy (codepoints);
+
+ hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('g','l','y','f'));
+ hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('l','o','c', 'a'));
+ hb_subset_test_check (face_subset, face_generated_subset, HB_TAG ('m','a','x', 'p'));
+
+ hb_face_destroy (face_generated_subset);
+ hb_face_destroy (face_subset);
+ hb_face_destroy (face_components);
+}
+
+static void
test_subset_glyf_noop (void)
{
hb_face_t *face_abc = hb_subset_test_open_font("fonts/Roboto-Regular.abc.ttf");
@@ -79,6 +99,7 @@ main (int argc, char **argv)
hb_test_init (&argc, &argv);
hb_test_add (test_subset_glyf);
+ hb_test_add (test_subset_glyf_with_components);
hb_test_add (test_subset_glyf_noop);
return hb_test_run();
commit c36d015b0e9c363431cd9d228b776ad419fde474
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 17:02:15 2018 -0700
[subset] missing return.
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index 12d402d3..e8625674 100644
--- a/test/api/hb-subset-test.h
+++ b/test/api/hb-subset-test.h
@@ -86,6 +86,7 @@ hb_subset_test_open_font (const char *font_path)
return face;
}
g_assert (false);
+ return NULL;
}
static inline hb_face_t *
commit 2130392dcc30784ee34c487ab16316006c91f16d
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 17:01:00 2018 -0700
[subset] Add support for updating reference gids in components to their new values.
diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc
index f1bca10d..7dfe0ba4 100644
--- a/src/hb-subset-glyf.cc
+++ b/src/hb-subset-glyf.cc
@@ -28,6 +28,7 @@
#include "hb-ot-glyf-table.hh"
#include "hb-set.h"
#include "hb-subset-glyf.hh"
+#include "hb-subset-plan.hh"
static bool
_calculate_glyf_and_loca_prime_size (const OT::glyf::accelerator_t &glyf,
@@ -70,16 +71,41 @@ _write_loca_entry (unsigned int id, unsigned int offset, bool is_short, void *lo
}
}
+static void
+_update_components (hb_subset_plan_t * plan,
+ char * glyph_start,
+ unsigned int length)
+
+{
+ OT::glyf::CompositeGlyphHeader::Iterator iterator;
+ if (OT::glyf::CompositeGlyphHeader::get_iterator (glyph_start,
+ length,
+ &iterator))
+ {
+ do
+ {
+ hb_codepoint_t new_gid;
+ if (!hb_subset_plan_new_gid_for_old_id (plan,
+ iterator.current->glyphIndex,
+ &new_gid))
+ continue;
+
+ ((OT::glyf::CompositeGlyphHeader *) iterator.current)->glyphIndex.set (new_gid);
+ } while (iterator.move_to_next());
+ }
+}
+
static bool
-_write_glyf_and_loca_prime (const OT::glyf::accelerator_t &glyf,
+_write_glyf_and_loca_prime (hb_subset_plan_t *plan,
+ const OT::glyf::accelerator_t &glyf,
const char *glyf_data,
- hb_prealloced_array_t<hb_codepoint_t> &glyph_ids,
bool use_short_loca,
int glyf_prime_size,
char *glyf_prime_data /* OUT */,
int loca_prime_size,
char *loca_prime_data /* OUT */)
{
+ hb_prealloced_array_t<hb_codepoint_t> &glyph_ids = plan->gids_to_retain_sorted;
char *glyf_prime_data_next = glyf_prime_data;
for (unsigned int i = 0; i < glyph_ids.len; i++)
@@ -92,6 +118,7 @@ _write_glyf_and_loca_prime (const OT::glyf::accelerator_t &glyf,
memcpy (glyf_prime_data_next, glyf_data + start_offset, length);
_write_loca_entry (i, glyf_prime_data_next - glyf_prime_data, use_short_loca, loca_prime_data);
+ _update_components (plan, glyf_prime_data_next, end_offset - start_offset);
glyf_prime_data_next += length;
}
@@ -104,7 +131,7 @@ _write_glyf_and_loca_prime (const OT::glyf::accelerator_t &glyf,
static bool
_hb_subset_glyf_and_loca (const OT::glyf::accelerator_t &glyf,
const char *glyf_data,
- hb_prealloced_array_t<hb_codepoint_t>&glyphs_to_retain,
+ hb_subset_plan_t *plan,
bool *use_short_loca,
hb_blob_t **glyf_prime /* OUT */,
hb_blob_t **loca_prime /* OUT */)
@@ -112,6 +139,7 @@ _hb_subset_glyf_and_loca (const OT::glyf::accelerator_t &glyf,
// TODO(grieger): Sanity check writes to make sure they are in-bounds.
// TODO(grieger): Sanity check allocation size for the new table.
// TODO(grieger): Don't fail on bad offsets, just dump them.
+ hb_prealloced_array_t<hb_codepoint_t> &glyphs_to_retain = plan->gids_to_retain_sorted;
unsigned int glyf_prime_size;
unsigned int loca_prime_size;
@@ -126,7 +154,7 @@ _hb_subset_glyf_and_loca (const OT::glyf::accelerator_t &glyf,
char *glyf_prime_data = (char *) malloc (glyf_prime_size);
char *loca_prime_data = (char *) malloc (loca_prime_size);
- if (unlikely (!_write_glyf_and_loca_prime (glyf, glyf_data, glyphs_to_retain,
+ if (unlikely (!_write_glyf_and_loca_prime (plan, glyf, glyf_data,
*use_short_loca,
glyf_prime_size, glyf_prime_data,
loca_prime_size, loca_prime_data))) {
@@ -168,7 +196,7 @@ hb_subset_glyf_and_loca (hb_subset_plan_t *plan,
glyf.init(plan->source);
bool result = _hb_subset_glyf_and_loca (glyf,
glyf_data,
- plan->gids_to_retain_sorted,
+ plan,
use_short_loca,
glyf_prime,
loca_prime);
commit 49544eb860e523838892d6ce88eeca72ffd19da4
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 16:56:15 2018 -0700
[subset] Refactor composite glyf iteration code into an Iterator outside of the accelerator.
diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh
index 7af981e4..a73fd4aa 100644
--- a/src/hb-ot-glyf-table.hh
+++ b/src/hb-ot-glyf-table.hh
@@ -133,6 +133,58 @@ struct glyf
return size;
}
+ struct Iterator
+ {
+ const char *glyph_start;
+ const char *glyph_end;
+ const CompositeGlyphHeader *current;
+
+ inline bool move_to_next ()
+ {
+ if (current->flags & CompositeGlyphHeader::MORE_COMPONENTS)
+ {
+ const CompositeGlyphHeader *possible =
+ &StructAfter<CompositeGlyphHeader, CompositeGlyphHeader> (*current);
+ if (!in_range (possible))
+ return false;
+ current = possible;
+ return true;
+ }
+ return false;
+ }
+
+ inline bool in_range (const CompositeGlyphHeader *composite) const
+ {
+ return (const char *) composite >= glyph_start
+ && ((const char *) composite + CompositeGlyphHeader::min_size) <= glyph_end
+ && ((const char *) composite + composite->get_size()) <= glyph_end;
+ }
+ };
+
+ static inline bool get_iterator (const char * glyph_data,
+ unsigned int length,
+ CompositeGlyphHeader::Iterator *iterator /* OUT */)
+ {
+ if (length < GlyphHeader::static_size)
+ return false; /* Empty glyph; zero extents. */
+
+ const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyph_data, 0);
+ if (glyph_header.numberOfContours < 0)
+ {
+ const CompositeGlyphHeader *possible =
+ &StructAfter<CompositeGlyphHeader, GlyphHeader> (glyph_header);
+
+ iterator->glyph_start = glyph_data;
+ iterator->glyph_end = (const char *) glyph_data + length;
+ if (!iterator->in_range (possible))
+ return false;
+ iterator->current = possible;
+ return true;
+ }
+
+ return false;
+ }
+
DEFINE_SIZE_MIN (4);
};
@@ -166,69 +218,21 @@ struct glyf
hb_blob_destroy (glyf_blob);
}
- inline bool in_table (const char *offset, unsigned int len) const
- {
- return (offset - (const char *) glyf_table + len) <= glyf_len;
- }
-
- inline bool in_table (const CompositeGlyphHeader *header) const
- {
- return in_table ((const char *) header, CompositeGlyphHeader::min_size)
- && in_table ((const char *) header, header->get_size());
- }
-
- inline bool in_glyph (const CompositeGlyphHeader *header,
- unsigned int start_offset,
- unsigned int end_offset) const
- {
- do
- {
- unsigned int offset_in_glyf = (const char *) header - (const char*) glyf_table;
- if (offset_in_glyf < start_offset
- || offset_in_glyf + header->get_size() > end_offset)
- return false;
- } while (next_composite (&header));
- return true;
- }
-
/*
* Returns true if the referenced glyph is a valid glyph and a composite glyph.
* If true is returned a pointer to the composite glyph will be written into
* composite.
*/
- inline bool get_composite (hb_codepoint_t glyph, const CompositeGlyphHeader ** composite /* OUT */) const
+ inline bool get_composite (hb_codepoint_t glyph,
+ CompositeGlyphHeader::Iterator *composite /* OUT */) const
{
unsigned int start_offset, end_offset;
if (!get_offsets (glyph, &start_offset, &end_offset))
return false; /* glyph not found */
- if (end_offset - start_offset < GlyphHeader::static_size)
- return false; /* Empty glyph; zero extents. */
-
- const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyf_table, start_offset);
- if (glyph_header.numberOfContours < 0) {
- const CompositeGlyphHeader *possible = &StructAfter<CompositeGlyphHeader, GlyphHeader> (glyph_header);
- if (!in_table (possible)
- || !in_glyph (possible, start_offset, end_offset))
- return false;
- *composite = possible;
- return true;
- }
-
- return false;
- }
-
- inline bool next_composite (const CompositeGlyphHeader ** next /* IN/OUT */) const
- {
- if ((*next)->flags & CompositeGlyphHeader::MORE_COMPONENTS)
- {
- const CompositeGlyphHeader *possible = &StructAfter<CompositeGlyphHeader, CompositeGlyphHeader> (**next);
- if (!in_table (possible))
- return false;
- *next = possible;
- return true;
- }
- return false;
+ return CompositeGlyphHeader::get_iterator ((const char*) this->glyf_table + start_offset,
+ end_offset - start_offset,
+ composite);
}
inline bool get_offsets (hb_codepoint_t glyph,
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index fca65c5a..d017cca1 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -106,13 +106,13 @@ _add_gid_and_children (const OT::glyf::accelerator_t &glyf,
hb_set_add (gids_to_retain, gid);
- const OT::glyf::CompositeGlyphHeader *composite;
+ OT::glyf::CompositeGlyphHeader::Iterator composite;
if (glyf.get_composite (gid, &composite))
{
do
{
- _add_gid_and_children (glyf, (hb_codepoint_t) composite->glyphIndex, gids_to_retain);
- } while (glyf.next_composite (&composite));
+ _add_gid_and_children (glyf, (hb_codepoint_t) composite.current->glyphIndex, gids_to_retain);
+ } while (composite.move_to_next());
}
}
commit dc6d67df1395faf38d7587b1dd3c6661ee7cd6f0
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 15:20:14 2018 -0700
[subset] Use gids_to_retain_sorted to produce old gid -> new gid mapping since it now has the more complete set.
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index 58b9f1eb..fca65c5a 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -63,10 +63,11 @@ 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.len; i++) {
- if (plan->gids_to_retain[i] == old_gid) {
- // +1: assign new gids from 1..N; 0 is special
- *new_gid = i + 1;
+ 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;
return true;
}
}
@@ -158,6 +159,7 @@ _populate_gids_to_retain (hb_face_t *face,
}
// Transfer to a sorted list.
+ old_gids_sorted.alloc (hb_set_get_population (all_gids_to_retain));
unsigned int gid = HB_SET_VALUE_INVALID;
while (hb_set_next (all_gids_to_retain, &gid))
{
commit dcac9fe96429d4e272a3fbd60a6162f988f58f71
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 11:27:03 2018 -0700
[subset] Use complex glyph closure to populate gids_to_retain_sorted.
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index ea46e5f7..58b9f1eb 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -28,6 +28,7 @@
#include "hb-subset-plan.hh"
#include "hb-ot-cmap-table.hh"
+#include "hb-ot-glyf-table.hh"
static int
_hb_codepoint_t_cmp (const void *pa, const void *pb)
@@ -94,9 +95,9 @@ _populate_codepoints (hb_set_t *input_codepoints,
}
static void
-_add_composite_gids (const OT::glyf::accelerator_t &glyf,
- hb_codepoint_t gid,
- hb_set_t *gids_to_retain)
+_add_gid_and_children (const OT::glyf::accelerator_t &glyf,
+ hb_codepoint_t gid,
+ hb_set_t *gids_to_retain)
{
if (hb_set_has (gids_to_retain, gid))
// Already visited this gid, ignore.
@@ -109,8 +110,8 @@ _add_composite_gids (const OT::glyf::accelerator_t &glyf,
{
do
{
- _add_composite_gids (glyf, (hb_codepoint_t) composite->glyphIndex, gids_to_retain);
- } while (glyf.next_composite (&composite);
+ _add_gid_and_children (glyf, (hb_codepoint_t) composite->glyphIndex, gids_to_retain);
+ } while (glyf.next_composite (&composite));
}
}
@@ -121,21 +122,19 @@ _populate_gids_to_retain (hb_face_t *face,
hb_prealloced_array_t<hb_codepoint_t>& old_gids_sorted)
{
OT::cmap::accelerator_t cmap;
+ OT::glyf::accelerator_t glyf;
cmap.init (face);
+ glyf.init (face);
hb_auto_array_t<unsigned int> bad_indices;
old_gids.alloc (codepoints.len);
- bool has_zero = false;
for (unsigned int i = 0; i < codepoints.len; i++) {
hb_codepoint_t gid;
if (!cmap.get_nominal_glyph (codepoints[i], &gid)) {
gid = -1;
*(bad_indices.push ()) = i;
}
- if (gid == 0) {
- has_zero = true;
- }
*(old_gids.push ()) = gid;
}
@@ -148,19 +147,25 @@ _populate_gids_to_retain (hb_face_t *face,
old_gids.remove (i);
}
- // Populate a second glyph id array that is sorted by glyph id
- // and is gauranteed to contain 0.
- old_gids_sorted.alloc (old_gids.len + (has_zero ? 0 : 1));
- for (unsigned int i = 0; i < old_gids.len; i++) {
- *(old_gids_sorted.push ()) = old_gids[i];
+ // Populate a full set of glyphs to retain by adding all referenced
+ // composite glyphs.
+ // TODO expand with glyphs reached by G*
+ hb_set_t * all_gids_to_retain = hb_set_create ();
+ _add_gid_and_children (glyf, 0, all_gids_to_retain);
+ for (unsigned int i = 0; i < old_gids.len; i++)
+ {
+ _add_gid_and_children (glyf, old_gids[i], all_gids_to_retain);
+ }
+
+ // Transfer to a sorted list.
+ unsigned int gid = HB_SET_VALUE_INVALID;
+ while (hb_set_next (all_gids_to_retain, &gid))
+ {
+ *(old_gids_sorted.push ()) = gid;
}
- if (!has_zero)
- *(old_gids_sorted.push ()) = 0;
old_gids_sorted.qsort (_hb_codepoint_t_cmp);
- // TODO(Q1) expand with glyphs that make up complex glyphs
- // TODO expand with glyphs reached by G*
- //
+ glyf.fini ();
cmap.fini ();
}
diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh
index 9a4308f9..b656faa6 100644
--- a/src/hb-subset-plan.hh
+++ b/src/hb-subset-plan.hh
@@ -38,8 +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.
+
+ // These first two lists provide a mapping from cp -> gid
+ // As a result it does not list the full set of glyphs to retain.
hb_prealloced_array_t<hb_codepoint_t> codepoints;
hb_prealloced_array_t<hb_codepoint_t> gids_to_retain;
+
+ // This list contains the complete set of glyphs to retain and may contain
+ // more glyphs then the lists above.
hb_prealloced_array_t<hb_codepoint_t> gids_to_retain_sorted;
// Plan is only good for a specific source/dest so keep them with it
commit 58a54c9d4f72e228c012451c4469da730742d3d8
Author: Garret Rieger <grieger at google.com>
Date: Fri Feb 16 11:20:38 2018 -0700
[subset] add constant to get_composite and in_table methods in hb-ot-glyf-table
diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh
index c6873fb5..7af981e4 100644
--- a/src/hb-ot-glyf-table.hh
+++ b/src/hb-ot-glyf-table.hh
@@ -179,7 +179,7 @@ struct glyf
inline bool in_glyph (const CompositeGlyphHeader *header,
unsigned int start_offset,
- unsigned int end_offset)
+ unsigned int end_offset) const
{
do
{
@@ -196,7 +196,7 @@ struct glyf
* If true is returned a pointer to the composite glyph will be written into
* composite.
*/
- inline bool get_composite (hb_codepoint_t glyph, const CompositeGlyphHeader ** composite /* OUT */)
+ inline bool get_composite (hb_codepoint_t glyph, const CompositeGlyphHeader ** composite /* OUT */) const
{
unsigned int start_offset, end_offset;
if (!get_offsets (glyph, &start_offset, &end_offset))
commit 73e1434814eb37005b4159babf972a2743b25700
Author: Garret Rieger <grieger at google.com>
Date: Thu Feb 15 14:41:56 2018 -0800
[subset] Add a DFS search to produce a closure of composite glyphs.
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index 034180a0..ea46e5f7 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -94,6 +94,27 @@ _populate_codepoints (hb_set_t *input_codepoints,
}
static void
+_add_composite_gids (const OT::glyf::accelerator_t &glyf,
+ hb_codepoint_t gid,
+ hb_set_t *gids_to_retain)
+{
+ if (hb_set_has (gids_to_retain, gid))
+ // Already visited this gid, ignore.
+ return;
+
+ hb_set_add (gids_to_retain, gid);
+
+ const OT::glyf::CompositeGlyphHeader *composite;
+ if (glyf.get_composite (gid, &composite))
+ {
+ do
+ {
+ _add_composite_gids (glyf, (hb_codepoint_t) composite->glyphIndex, gids_to_retain);
+ } while (glyf.next_composite (&composite);
+ }
+}
+
+static void
_populate_gids_to_retain (hb_face_t *face,
hb_prealloced_array_t<hb_codepoint_t>& codepoints,
hb_prealloced_array_t<hb_codepoint_t>& old_gids,
commit d3684141437fad6ebf5f9945f92125c9a42ea853
Author: Garret Rieger <grieger at google.com>
Date: Thu Feb 15 14:03:34 2018 -0800
[subset] add helper methods to glyf accelerator for reading composite glyph information.
diff --git a/src/hb-ot-glyf-table.hh b/src/hb-ot-glyf-table.hh
index e6b07a86..c6873fb5 100644
--- a/src/hb-ot-glyf-table.hh
+++ b/src/hb-ot-glyf-table.hh
@@ -81,9 +81,9 @@ struct glyf
struct GlyphHeader
{
HBINT16 numberOfContours; /* If the number of contours is
- * greater than or equal to zero,
- * this is a simple glyph; if negative,
- * this is a composite glyph. */
+ * greater than or equal to zero,
+ * this is a simple glyph; if negative,
+ * this is a composite glyph. */
FWORD xMin; /* Minimum x for coordinate data. */
FWORD yMin; /* Minimum y for coordinate data. */
FWORD xMax; /* Maximum x for coordinate data. */
@@ -92,6 +92,50 @@ struct glyf
DEFINE_SIZE_STATIC (10);
};
+ struct CompositeGlyphHeader
+ {
+ static const uint16_t ARG_1_AND_2_ARE_WORDS = 0x0001;
+ static const uint16_t ARGS_ARE_XY_VALUES = 0x0002;
+ static const uint16_t ROUND_XY_TO_GRID = 0x0004;
+ static const uint16_t WE_HAVE_A_SCALE = 0x0008;
+ static const uint16_t MORE_COMPONENTS = 0x0020;
+ static const uint16_t WE_HAVE_AN_X_AND_Y_SCALE = 0x0040;
+ static const uint16_t WE_HAVE_A_TWO_BY_TWO = 0x0080;
+ static const uint16_t WE_HAVE_INSTRUCTIONS = 0x0100;
+ static const uint16_t USE_MY_METRICS = 0x0200;
+ static const uint16_t OVERLAP_COMPOUND = 0x0400;
+ static const uint16_t SCALED_COMPONENT_OFFSET = 0x0800;
+ static const uint16_t UNSCALED_COMPONENT_OFFSET = 0x1000;
+
+ HBUINT16 flags;
+ HBUINT16 glyphIndex;
+
+ inline unsigned int get_size (void) const
+ {
+ unsigned int size = min_size;
+ if (flags & ARG_1_AND_2_ARE_WORDS) {
+ // arg1 and 2 are int16
+ size += 4;
+ } else {
+ // arg1 and 2 are int8
+ size += 2;
+ }
+ if (flags & WE_HAVE_A_SCALE) {
+ // One x 16 bit (scale)
+ size += 2;
+ } else if (flags & WE_HAVE_AN_X_AND_Y_SCALE) {
+ // Two x 16 bit (xscale, yscale)
+ size += 4;
+ } else if (flags & WE_HAVE_A_TWO_BY_TWO) {
+ // Four x 16 bit (xscale, scale01, scale10, yscale)
+ size += 8;
+ }
+ return size;
+ }
+
+ DEFINE_SIZE_MIN (4);
+ };
+
struct accelerator_t
{
inline void init (hb_face_t *face)
@@ -122,6 +166,71 @@ struct glyf
hb_blob_destroy (glyf_blob);
}
+ inline bool in_table (const char *offset, unsigned int len) const
+ {
+ return (offset - (const char *) glyf_table + len) <= glyf_len;
+ }
+
+ inline bool in_table (const CompositeGlyphHeader *header) const
+ {
+ return in_table ((const char *) header, CompositeGlyphHeader::min_size)
+ && in_table ((const char *) header, header->get_size());
+ }
+
+ inline bool in_glyph (const CompositeGlyphHeader *header,
+ unsigned int start_offset,
+ unsigned int end_offset)
+ {
+ do
+ {
+ unsigned int offset_in_glyf = (const char *) header - (const char*) glyf_table;
+ if (offset_in_glyf < start_offset
+ || offset_in_glyf + header->get_size() > end_offset)
+ return false;
+ } while (next_composite (&header));
+ return true;
+ }
+
+ /*
+ * Returns true if the referenced glyph is a valid glyph and a composite glyph.
+ * If true is returned a pointer to the composite glyph will be written into
+ * composite.
+ */
+ inline bool get_composite (hb_codepoint_t glyph, const CompositeGlyphHeader ** composite /* OUT */)
+ {
+ unsigned int start_offset, end_offset;
+ if (!get_offsets (glyph, &start_offset, &end_offset))
+ return false; /* glyph not found */
+
+ if (end_offset - start_offset < GlyphHeader::static_size)
+ return false; /* Empty glyph; zero extents. */
+
+ const GlyphHeader &glyph_header = StructAtOffset<GlyphHeader> (glyf_table, start_offset);
+ if (glyph_header.numberOfContours < 0) {
+ const CompositeGlyphHeader *possible = &StructAfter<CompositeGlyphHeader, GlyphHeader> (glyph_header);
+ if (!in_table (possible)
+ || !in_glyph (possible, start_offset, end_offset))
+ return false;
+ *composite = possible;
+ return true;
+ }
+
+ return false;
+ }
+
+ inline bool next_composite (const CompositeGlyphHeader ** next /* IN/OUT */) const
+ {
+ if ((*next)->flags & CompositeGlyphHeader::MORE_COMPONENTS)
+ {
+ const CompositeGlyphHeader *possible = &StructAfter<CompositeGlyphHeader, CompositeGlyphHeader> (**next);
+ if (!in_table (possible))
+ return false;
+ *next = possible;
+ return true;
+ }
+ return false;
+ }
+
inline bool get_offsets (hb_codepoint_t glyph,
unsigned int *start_offset /* OUT */,
unsigned int *end_offset /* OUT */) const
commit 926db874552519734fab6c04258887ea634f5324
Merge: 882a3bf4 c7a633f9
Author: rsheeter <rsheeter at google.com>
Date: Fri Feb 16 15:27:29 2018 -0800
Merge pull request #792 from googlefonts/master
Support more tables in subsetter
commit c7a633f95710fcf2fe9151b41feba7db4b1bab0e
Author: Rod Sheeter <rsheeter at google.com>
Date: Fri Feb 16 11:11:20 2018 -0800
[subset] try to get more info from bot where g_assert_cmpmem fails
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index 96d5c05a..12d402d3 100644
--- a/test/api/hb-subset-test.h
+++ b/test/api/hb-subset-test.h
@@ -112,13 +112,11 @@ 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);
- unsigned 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_blob_t *expected_blob = hb_face_reference_table (expected, table);
+ hb_blob_t *actual_blob = hb_face_reference_table (actual, table);
+ hb_test_assert_blob_eq(expected_blob, actual_blob);
+ hb_blob_destroy (expected_blob);
+ hb_blob_destroy (actual_blob);
}
diff --git a/test/api/hb-test.h b/test/api/hb-test.h
index f6f107e2..48ccc3b2 100644
--- a/test/api/hb-test.h
+++ b/test/api/hb-test.h
@@ -161,9 +161,14 @@ typedef void (*hb_test_fixture_func_t) (void);
#define g_test_fail() g_error("Test failed")
#endif
-#ifndef g_assert_cmpmem
-#define g_assert_cmpmem(m1, l1, m2, l2) g_assert_true (l1 == l2 && memcmp (m1, m2, l1) == 0)
-#endif
+static inline void hb_test_assert_blob_eq(hb_blob_t *expected_blob, hb_blob_t *actual_blob)
+{
+ unsigned int expected_length, actual_length;
+ const char *raw_expected = hb_blob_get_data (expected_blob, &expected_length);
+ const char *raw_actual = hb_blob_get_data (actual_blob, &actual_length);
+ g_assert_cmpint(expected_length, ==, actual_length);
+ g_assert_cmpint(0, ==, memcmp(raw_expected, raw_actual, expected_length));
+}
static inline void
commit 0bb2d7ac12b7cf482580b6d2e8534eef8a233f96
Author: Rod Sheeter <rsheeter at google.com>
Date: Fri Feb 16 06:26:02 2018 -0800
[subset] fix int type for blob length in hb-subset-test.h
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index de7f274f..96d5c05a 100644
--- a/test/api/hb-subset-test.h
+++ b/test/api/hb-subset-test.h
@@ -114,7 +114,7 @@ hb_subset_test_check (hb_face_t *expected,
{
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;
+ unsigned 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);
commit be0a01a67613f45db7f7e9be84cb883f0344c817
Merge: 7acaa3b7 139c9928
Author: Rod Sheeter <rsheeter at google.com>
Date: Fri Feb 16 06:01:41 2018 -0800
Merge branch 'master' of https://github.com/harfbuzz/harfbuzz
commit 7acaa3b781da835cdb11dbe523c819feb4eef996
Author: Rod Sheeter <rsheeter at google.com>
Date: Thu Feb 15 14:28:29 2018 -0800
[subset] apparently C99 is too much to ask in 2018
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index 41d5489d..11cc9279 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -111,7 +111,7 @@ struct hmtxvmtx
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, %zu bytes", HB_UNTAG(T::tableTag), num_advances, gids.len - num_advances, dest_sz);
+ DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in dest has %d advances, %d lsbs, %u bytes", HB_UNTAG(T::tableTag), num_advances, gids.len - num_advances, (unsigned int) dest_sz);
const char *source_table = hb_blob_get_data (_mtx.blob, nullptr);
// Copy everything over
commit b1740106a9c825874faf3f1315770d1e3c790cf9
Author: Rod Sheeter <rsheeter at google.com>
Date: Thu Feb 15 13:55:21 2018 -0800
[subset] fix format specifier for size_t
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index a3bd19c8..41d5489d 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -111,7 +111,7 @@ struct hmtxvmtx
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);
+ DEBUG_MSG(SUBSET, nullptr, "%c%c%c%c in dest has %d advances, %d lsbs, %zu 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
commit e00c37aaae3922b425c0528bfdd36d59cf9c5796
Author: Rod Sheeter <rsheeter at google.com>
Date: Thu Feb 15 12:53:52 2018 -0800
[subset] fix no matching function MIN in djgpp
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index 5a291491..a3bd19c8 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -121,7 +121,7 @@ struct hmtxvmtx
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]);
+ LongMetric *src_metric = old_metrics + MIN ((hb_codepoint_t) _mtx.num_advances - 1, gids[i]);
if (gids[i] < _mtx.num_advances)
{
/* src is a LongMetric */
commit 6122ad2442666d89ef39bdf5a2bb9d3f6d8e2b03
Author: Rod Sheeter <rsheeter at google.com>
Date: Thu Feb 15 11:40:28 2018 -0800
[subset] add files to EXTRA_DIST
diff --git a/test/api/Makefile.am b/test/api/Makefile.am
index dafbb0e4..358cd57f 100644
--- a/test/api/Makefile.am
+++ b/test/api/Makefile.am
@@ -72,6 +72,9 @@ EXTRA_DIST += \
fonts/Inconsolata-Regular.abc.widerc.ttf \
fonts/Inconsolata-Regular.ac.ttf \
fonts/Inconsolata-Regular.ac.widerc.ttf \
+ fonts/Roboto-Regular.abc.cmap-format12-only.ttf \
+ fonts/Roboto-Regular.ac.cmap-format12-only.ttf \
+ fonts/Roboto-Regular.b.ttf \
fonts/Roboto-Regular.abc.ttf \
fonts/Roboto-Regular.ac.ttf \
fonts/MathTestFontEmpty.otf \
commit 0758cbc4c2f52c629d05515b8d2816e8d6a2a2c1
Author: Rod Sheeter <rsheeter at google.com>
Date: Thu Feb 15 11:29:01 2018 -0800
[subset] correct bug introduced to get_advance
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index ed57d4ac..5a291491 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -257,8 +257,12 @@ struct hmtxvmtx
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?!
+ unsigned int advance = get_advance (glyph);
+ if (likely(glyph < num_metrics))
+ {
+ advance += (font->num_coords ? var_table->get_advance_var (glyph, font->coords, font->num_coords) : 0); // TODO Optimize?!
+ }
+ return advance;
}
public:
commit 3fd11f4397aec9cda3a7d29246ab3ae56115ad36
Author: Rod Sheeter <rsheeter at google.com>
Date: Thu Feb 15 11:15:12 2018 -0800
[subset] remove unused decl
diff --git a/src/hb-subset-private.hh b/src/hb-subset-private.hh
index 3d6f8b4a..5473eac0 100644
--- a/src/hb-subset-private.hh
+++ b/src/hb-subset-private.hh
@@ -58,7 +58,4 @@ 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 */
commit 0e088a63d10dd09e025515bfa8ae68aa2922eaf6
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 21:11:45 2018 -0800
[subset] hmtx space bracket. authors++
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index b2ff82c6..ed57d4ac 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -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): Behdad Esfahbod
+ * Google Author(s): Behdad Esfahbod, Roderick Sheeter
*/
#ifndef HB_OT_HMTX_TABLE_HH
@@ -65,10 +65,10 @@ struct hmtxvmtx
}
- inline bool subset_update_header(hb_subset_plan_t *plan,
- unsigned int num_hmetrics) const
+ inline bool subset_update_header (hb_subset_plan_t *plan,
+ unsigned int num_hmetrics) const
{
- hb_blob_t *src_blob = OT::Sanitizer<H>().sanitize (plan->source->reference_table (H::tableTag));
+ hb_blob_t *src_blob = OT::Sanitizer<H> ().sanitize (plan->source->reference_table (H::tableTag));
hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob);
hb_blob_destroy (src_blob);
@@ -77,7 +77,7 @@ struct hmtxvmtx
}
unsigned int length;
- H *table = (H *) hb_blob_get_data(dest_blob, &length);
+ H *table = (H *) hb_blob_get_data (dest_blob, &length);
table->numberOfLongMetrics.set (num_hmetrics);
bool result = hb_subset_plan_add_table (plan, H::tableTag, dest_blob);
@@ -89,15 +89,15 @@ struct hmtxvmtx
inline bool subset (hb_subset_plan_t *plan) const
{
typename T::accelerator_t _mtx;
- _mtx.init(plan->source);
+ _mtx.init (plan->source);
/* All the trailing glyphs with the same advance can use one LongMetric
* and just keep LSB */
hb_prealloced_array_t<hb_codepoint_t> &gids = plan->gids_to_retain_sorted;
unsigned int num_advances = gids.len;
- unsigned int last_advance = _mtx.get_advance(gids[num_advances - 1]);
+ unsigned int last_advance = _mtx.get_advance (gids[num_advances - 1]);
while (num_advances > 1
- && last_advance == _mtx.get_advance(gids[num_advances - 2]))
+ && last_advance == _mtx.get_advance (gids[num_advances - 2]))
{
num_advances--;
}
@@ -105,7 +105,7 @@ struct hmtxvmtx
/* alloc the new table */
size_t dest_sz = num_advances * 4
+ (gids.len - num_advances) * 2;
- void *dest = (void *) calloc(dest_sz, 1);
+ void *dest = (void *) calloc (dest_sz, 1);
if (unlikely (!dest))
{
return false;
@@ -113,7 +113,7 @@ struct hmtxvmtx
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);
+ 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);
@@ -121,7 +121,7 @@ struct hmtxvmtx
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]);
+ LongMetric *src_metric = old_metrics + MIN (_mtx.num_advances - 1, gids[i]);
if (gids[i] < _mtx.num_advances)
{
/* src is a LongMetric */
@@ -154,12 +154,12 @@ struct hmtxvmtx
}
dest_pos += (i < num_advances ? 4 : 2);
}
- _mtx.fini();
+ _mtx.fini ();
// Amend header num hmetrics
- if (unlikely(!subset_update_header(plan, num_advances)))
+ if (unlikely (!subset_update_header (plan, num_advances)))
{
- free(dest);
+ free (dest);
return false;
}
@@ -168,7 +168,7 @@ struct hmtxvmtx
HB_MEMORY_MODE_READONLY,
/* userdata */ nullptr,
free);
- return hb_subset_plan_add_table(plan, T::tableTag, result);
+ return hb_subset_plan_add_table (plan, T::tableTag, result);
}
struct accelerator_t
@@ -183,7 +183,7 @@ struct hmtxvmtx
bool got_font_extents = false;
if (T::os2Tag)
{
- hb_blob_t *os2_blob = Sanitizer<os2>().sanitize (face->reference_table (T::os2Tag));
+ hb_blob_t *os2_blob = Sanitizer<os2> ().sanitize (face->reference_table (T::os2Tag));
const os2 *os2_table = Sanitizer<os2>::lock_instance (os2_blob);
#define USE_TYPO_METRICS (1u<<7)
if (0 != (os2_table->fsSelection & USE_TYPO_METRICS))
@@ -196,7 +196,7 @@ struct hmtxvmtx
hb_blob_destroy (os2_blob);
}
- hb_blob_t *_hea_blob = Sanitizer<H>().sanitize (face->reference_table (H::tableTag));
+ hb_blob_t *_hea_blob = Sanitizer<H> ().sanitize (face->reference_table (H::tableTag));
const H *_hea_table = Sanitizer<H>::lock_instance (_hea_blob);
num_advances = _hea_table->numberOfLongMetrics;
if (!got_font_extents)
@@ -210,7 +210,7 @@ struct hmtxvmtx
has_font_extents = got_font_extents;
- blob = Sanitizer<hmtxvmtx>().sanitize (face->reference_table (T::tableTag));
+ blob = Sanitizer<hmtxvmtx> ().sanitize (face->reference_table (T::tableTag));
/* Cap num_metrics() and num_advances() based on table length. */
unsigned int len = hb_blob_get_length (blob);
@@ -228,7 +228,7 @@ struct hmtxvmtx
}
table = Sanitizer<hmtxvmtx>::lock_instance (blob);
- var_blob = Sanitizer<HVARVVAR>().sanitize (face->reference_table (T::variationsTag));
+ var_blob = Sanitizer<HVARVVAR> ().sanitize (face->reference_table (T::variationsTag));
var_table = Sanitizer<HVARVVAR>::lock_instance (var_blob);
}
@@ -257,7 +257,7 @@ struct hmtxvmtx
inline unsigned int get_advance (hb_codepoint_t glyph,
hb_font_t *font) const
{
- return get_advance(glyph)
+ return get_advance (glyph)
+ (font->num_coords ? var_table->get_advance_var (glyph, font->coords, font->num_coords) : 0); // TODO Optimize?!
}
commit 1725c35da0ea2f829b6d6b6c1963607fd6dfb577
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 19:36:33 2018 -0800
[subset] cmap space bracket
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 7122ab9f..e7494df6 100644
--- a/src/hb-ot-cmap-table.hh
+++ b/src/hb-ot-cmap-table.hh
@@ -271,13 +271,13 @@ struct CmapSubtableLongSegmented
return_trace (c->check_struct (this) && groups.sanitize (c));
}
- inline bool serialize(hb_serialize_context_t *context,
- hb_prealloced_array_t<CmapSubtableLongGroup> &group_data)
+ inline bool serialize (hb_serialize_context_t *context,
+ hb_prealloced_array_t<CmapSubtableLongGroup> &group_data)
{
TRACE_SERIALIZE (this);
- if (unlikely(!context->extend_min (*this))) return_trace (false);
- Supplier<CmapSubtableLongGroup> supplier(group_data.array, group_data.len);
- if (unlikely(!groups.serialize(context, supplier, group_data.len))) return_trace (false);
+ if (unlikely (!context->extend_min (*this))) return_trace (false);
+ Supplier<CmapSubtableLongGroup> supplier (group_data.array, group_data.len);
+ if (unlikely (!groups.serialize (context, supplier, group_data.len))) return_trace (false);
return true;
}
@@ -435,12 +435,12 @@ struct CmapSubtable
hb_codepoint_t *glyph) const
{
switch (u.format) {
- case 0: return u.format0 .get_glyph(codepoint, glyph);
- case 4: return u.format4 .get_glyph(codepoint, glyph);
- case 6: return u.format6 .get_glyph(codepoint, glyph);
- case 10: return u.format10.get_glyph(codepoint, glyph);
- case 12: return u.format12.get_glyph(codepoint, glyph);
- case 13: return u.format13.get_glyph(codepoint, glyph);
+ case 0: return u.format0 .get_glyph (codepoint, glyph);
+ case 4: return u.format4 .get_glyph (codepoint, glyph);
+ case 6: return u.format6 .get_glyph (codepoint, glyph);
+ case 10: return u.format10.get_glyph (codepoint, glyph);
+ case 12: return u.format12.get_glyph (codepoint, glyph);
+ case 13: return u.format13.get_glyph (codepoint, glyph);
case 14:
default: return false;
}
@@ -517,8 +517,8 @@ struct cmap
encodingRecord.sanitize (c, this));
}
- inline bool populate_groups(hb_subset_plan_t *plan,
- hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const
+ inline bool populate_groups (hb_subset_plan_t *plan,
+ hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const
{
CmapSubtableLongGroup *group = nullptr;
for (unsigned int i = 0; i < plan->codepoints.len; i++) {
@@ -526,19 +526,19 @@ struct cmap
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 = groups->push ();
+ group->startCharCode.set (cp);
+ group->endCharCode.set (cp);
hb_codepoint_t new_gid;
- if (unlikely(!hb_subset_plan_new_gid_for_codepoint(plan, cp, &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);
+ group->glyphID.set (new_gid);
} else
{
- group->endCharCode.set(cp);
+ group->endCharCode.set (cp);
}
}
@@ -555,35 +555,35 @@ struct cmap
size_t dest_sz,
void *dest) const
{
- hb_serialize_context_t context(dest, dest_sz);
+ hb_serialize_context_t context (dest, dest_sz);
OT::cmap *cmap = context.start_serialize<OT::cmap> ();
- if (unlikely(!context.extend_min(*cmap)))
+ if (unlikely (!context.extend_min (*cmap)))
{
return false;
}
- cmap->version.set(0);
+ 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
rec.encodingID.set (10); // Unicode UCS-4
/* capture offset to subtable */
- CmapSubtable &subtable = rec.subtable.serialize(&context, cmap);
+ CmapSubtable &subtable = rec.subtable.serialize (&context, cmap);
- subtable.u.format.set(12);
+ 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);
+ 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 ();
@@ -594,7 +594,7 @@ struct cmap
{
hb_auto_array_t<CmapSubtableLongGroup> 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?
@@ -602,15 +602,15 @@ struct cmap
+ 8 // 1 EncodingRecord
+ 16 // Format 12 header
+ 12 * groups.len; // SequentialMapGroup records
- void *dest = calloc(dest_sz, 1);
- if (unlikely(!dest)) {
+ void *dest = calloc (dest_sz, 1);
+ if (unlikely (!dest)) {
DEBUG_MSG(SUBSET, nullptr, "Unable to alloc %ld for cmap subset output", dest_sz);
return false;
}
- if (unlikely(!_subset(groups, dest_sz, dest)))
+ if (unlikely (!_subset (groups, dest_sz, dest)))
{
- free(dest);
+ free (dest);
return false;
}
@@ -620,7 +620,7 @@ struct cmap
HB_MEMORY_MODE_READONLY,
/* userdata */ nullptr,
free);
- return hb_subset_plan_add_table(plan, HB_OT_TAG_cmap, cmap_prime);
+ return hb_subset_plan_add_table (plan, HB_OT_TAG_cmap, cmap_prime);
}
struct accelerator_t
commit e158739bfb9e5d60989e179fcc8744f3125e2067
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 19:22:37 2018 -0800
[subset] space bracket
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index 209c052b..b2ff82c6 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -72,7 +72,7 @@ struct hmtxvmtx
hb_blob_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob);
hb_blob_destroy (src_blob);
- if (unlikely(!dest_blob)) {
+ if (unlikely (!dest_blob)) {
return false;
}
@@ -106,11 +106,10 @@ struct hmtxvmtx
size_t dest_sz = num_advances * 4
+ (gids.len - num_advances) * 2;
void *dest = (void *) calloc(dest_sz, 1);
- if (unlikely(!dest))
+ 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);
commit 2d6b1e2af74abea645a943d264e148d56d018101
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 19:14:01 2018 -0800
[subset] maxp copy writeable fn
diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh
index ceb83628..3ffa57b1 100644
--- a/src/hb-ot-maxp-table.hh
+++ b/src/hb-ot-maxp-table.hh
@@ -64,15 +64,14 @@ struct maxp
inline bool subset (hb_subset_plan_t *plan) const
{
hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().sanitize (hb_face_reference_table (plan->source, HB_OT_TAG_maxp));
- // 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_t *maxp_prime_blob = hb_blob_copy_writable_or_fail (maxp_blob);
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);
+ if (unlikely (!maxp_prime_blob)) {
return false;
}
+ unsigned int length;
+ OT::maxp *maxp_prime = (OT::maxp *) hb_blob_get_data (maxp_prime_blob, &length);
maxp_prime->set_num_glyphs (plan->gids_to_retain_sorted.len);
commit 1efecd965fe81d65e2763be4f43df2d8c4d8be44
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 18:42:29 2018 -0800
[subset] hmtx use copy writeable fn instead of direct memory
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index 1368214d..209c052b 100644
--- a/src/hb-ot-hmtx-table.hh
+++ b/src/hb-ot-hmtx-table.hh
@@ -68,33 +68,18 @@ struct hmtxvmtx
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<H>().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_t *dest_blob = hb_blob_copy_writable_or_fail(src_blob);
hb_blob_destroy (src_blob);
- if (src_length != sizeof (H)) {
- free (dest);
+ if (unlikely(!dest_blob)) {
return false;
}
- memcpy(dest, src_raw, src_length);
- H *table = (H *) dest;
+ unsigned int length;
+ H *table = (H *) hb_blob_get_data(dest_blob, &length);
table->numberOfLongMetrics.set (num_hmetrics);
- hb_blob_t *dest_blob = hb_blob_create ((const char *) dest,
- dest_sz,
- HB_MEMORY_MODE_READONLY,
- dest,
- free);
bool result = hb_subset_plan_add_table (plan, H::tableTag, dest_blob);
hb_blob_destroy (dest_blob);
commit 27012526f9b3848676bc2a4fb8e68c630af18620
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 19:01:00 2018 -0800
[subset] whitespace
diff --git a/test/api/test-subset-hmtx.c b/test/api/test-subset-hmtx.c
index 24a99c37..099b57de 100644
--- a/test/api/test-subset-hmtx.c
+++ b/test/api/test-subset-hmtx.c
@@ -42,7 +42,7 @@ static void check_num_hmetrics(hb_face_t *face, uint16_t expected_num_hmetrics)
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);
}
@@ -78,15 +78,14 @@ test_subset_hmtx_monospace (void)
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);
+ 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);
+ hb_face_destroy (face_ac);
}
commit b1bd0b5f506dad9d04fd3a6abcb92122f231e0f7
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Feb 14 18:50:19 2018 -0800
[subset] Minor
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 98f0b561..7122ab9f 100644
--- a/src/hb-ot-cmap-table.hh
+++ b/src/hb-ot-cmap-table.hh
@@ -517,8 +517,8 @@ struct cmap
encodingRecord.sanitize (c, this));
}
- inline hb_bool_t populate_groups(hb_subset_plan_t *plan,
- hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const
+ inline bool populate_groups(hb_subset_plan_t *plan,
+ hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const
{
CmapSubtableLongGroup *group = nullptr;
for (unsigned int i = 0; i < plan->codepoints.len; i++) {
@@ -551,9 +551,9 @@ struct cmap
return true;
}
- inline hb_bool_t _subset (hb_prealloced_array_t<CmapSubtableLongGroup> &groups,
- size_t dest_sz,
- void *dest) const
+ inline bool _subset (hb_prealloced_array_t<CmapSubtableLongGroup> &groups,
+ size_t dest_sz,
+ void *dest) const
{
hb_serialize_context_t context(dest, dest_sz);
commit 83f57e24bfc2000373192ec44b067fdd7dee8a65
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Feb 14 18:43:53 2018 -0800
[test] Reinstate test/shaping/data/in-house/tests/myanmar-syllable.tests
diff --git a/test/shaping/data/in-house/tests/myanmar-syllable.tests b/test/shaping/data/in-house/tests/myanmar-syllable.tests
new file mode 100644
index 00000000..4666ef99
--- /dev/null
+++ b/test/shaping/data/in-house/tests/myanmar-syllable.tests
@@ -0,0 +1 @@
+../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]
commit 5ae6526ef4aa9b3c943cad984dc2fff09cdf597b
Merge: 2903b2f3 04c1ec2b
Author: Behdad Esfahbod <behdad at behdad.org>
Date: Wed Feb 14 18:42:32 2018 -0800
[subset] Merge remote-tracking branch 'googlefonts/master'
commit 04c1ec2b7396c05f6e8afc9d87679422782aa1e8
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 17:00:18 2018 -0800
[subset] Don't fail on different checksum adjustment in subsetting tests.
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 52706dc9..501d1d28 100644
Binary files a/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf and b/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf differ
diff --git a/test/subset/run-tests.py b/test/subset/run-tests.py
index faf61595..f648627e 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]):
commit 0775bc0f7a59241456142b48abced75fd3db5a42
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 16:37:35 2018 -0800
[subset] Fix hhea subsetting and clean up some memory leaks.
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index e69f9ea4..1368214d 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<H>().sanitize (plan->source->reference_table (T::tableTag));
- if (unlikely(!src_blob))
- {
- free(dest);
- return false;
- }
+ hb_blob_t *src_blob = OT::Sanitizer<H>().sanitize (plan->source->reference_table (H::tableTag));
unsigned int src_length;
- const char *src_raw = hb_blob_get_data(src_blob, &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;
+ }
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
commit b56c9384bcc177236debd26fdbbf14319e4c62b9
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 16:05:39 2018 -0800
[subset] Add missing face reference in hb-subset-plan plus ensure all struct members are cleaned up on destroy.
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index 0381e25c..034180a0 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);
}
commit e0ffebead6230b8e1ee8dd97425505706321793e
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 16:01:08 2018 -0800
[subset] In hb-subset-test use hb_set_union instead of manually copying set.
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index efae1797..de7f274f 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);
commit e330ef3711c543372f9f8550a967c512bbf87d83
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 15:57:11 2018 -0800
[subset] Restore hb_face_data_destroy to be internal.
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index 69e8f77d..2eb4ebd0 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);
commit 3ab7d2649bf5c92d3837b3132d65d4659d0fa003
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 15:48:57 2018 -0800
[subset] Fix memory leak in hb-ot-{maxp,os2}. Plus some formatting.
diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh
index 0ad123ab..ceb83628 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<OT::maxp>().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 9bc75c0c..18dc4ab0 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<OT::os2>().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<hb_codepoint_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)
commit 66e282df32410831f1c4e157e9dcf8c76f2bc3d8
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 15:31:13 2018 -0800
[subset] remove TODO that was already done
diff --git a/src/hb-subset-plan.hh b/src/hb-subset-plan.hh
index 0a43eb90..9a4308f9 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<hb_codepoint_t> codepoints;
hb_prealloced_array_t<hb_codepoint_t> gids_to_retain;
hb_prealloced_array_t<hb_codepoint_t> gids_to_retain_sorted;
commit 4696624ad9987b0eebcf5c84dafdb204b886f28e
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 15:30:49 2018 -0800
[subset] maxp wrong int type, note to use copy_writable_or_fail
diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh
index 34eb9ae8..0ad123ab 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<OT::maxp>().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);
commit 3ed70e5e64910e1c22225f542a525807b000cb2a
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 15:24:49 2018 -0800
[subset] return bool not hb_bool_t from table::subset
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index b7332293..98f0b561 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<CmapSubtableLongGroup> groups;
diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh
index 00a95d71..34eb9ae8 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<OT::maxp>().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 1bb9a153..9bc75c0c 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<OT::os2>().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 ce7881f0..69e8f77d 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<typename TableType>
-static hb_bool_t
+static bool
_subset (hb_subset_plan_t *plan)
{
OT::Sanitizer<TableType> sanitizer;
commit 88d56e241bd6bb768656d77cf8f99ccc97fb2446
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 15:20:43 2018 -0800
[subset] Use a supplier instead of memcpy and fix a few unnecessary {}s for cmap
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 6c5f3c28..b7332293 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<CmapSubtableLongGroup> 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<CmapSubtableLongGroup> 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?
commit 42a80f00d51317207c49611b76d6bba06230371b
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 15:04:35 2018 -0800
[subset] add free
diff --git a/src/hb-ot-hmtx-table.hh b/src/hb-ot-hmtx-table.hh
index 7fae4f6c..e69f9ea4 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<H>().sanitize (plan->source->reference_table (T::tableTag));
if (unlikely(!src_blob))
{
+ free(dest);
return false;
}
unsigned int src_length;
commit d463e9f6b57bebb3aa4875fe11c927c26c3e3974
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 15:04:15 2018 -0800
[subset] Give Behdad credit again
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index 4de146ea..ce7881f0 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"
commit fa87770372a3156658412ff0d70e32083c6b0484
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 14:16:25 2018 -0800
[subset] First pass at hmtx
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index c3f242db..6c5f3c28 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<CmapSubtableLongGroup> 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 54eb5eb7..97952b4e 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 <typename T>
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<hhea> {
static const hb_tag_t tableTag = HB_OT_TAG_hhea;
};
-struct vhea : _hea {
+struct vhea : _hea<vhea> {
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 b4ba2490..7fae4f6c 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 <typename T>
+template <typename T, typename H>
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<H>().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<hb_codepoint_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<H>().sanitize (face->reference_table (H::tableTag));
+ const H *_hea_table = Sanitizer<H>::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<hmtx> {
+struct hmtx : hmtxvmtx<hmtx, hhea> {
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<vmtx> {
+struct vmtx : hmtxvmtx<vmtx, vhea> {
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 52b9388d..00a95d71 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<OT::maxp>().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp));
+ hb_blob_t *maxp_blob = OT::Sanitizer<OT::maxp>().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 f80a05d7..1bb9a153 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<OT::os2>().sanitize (hb_face_reference_table (source, HB_OT_TAG_os2));
+ hb_blob_t *os2_blob = OT::Sanitizer<OT::os2>().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 36789f9b..f1bca10d 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<OT::glyf>().sanitize (face->reference_table (HB_OT_TAG_glyf));
+ hb_blob_t *glyf_blob = OT::Sanitizer<OT::glyf>().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 491bf82b..99b76db9 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 6f4b003b..0381e25c 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<hb_codepoint_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 09df7cdd..0a43eb90 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<hb_codepoint_t> codepoints;
hb_prealloced_array_t<hb_codepoint_t> gids_to_retain;
hb_prealloced_array_t<hb_codepoint_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 4ef1b954..3d6f8b4a 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 e7f2d912..4de146ea 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<typename TableType>
-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<TableType> 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<TableType>::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<OT::head>().sanitize (hb_face_reference_table (source, HB_OT_TAG_head));
const OT::head *head = OT::Sanitizer<OT::head>::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<const OT::hmtx> (plan);
+ break;
case HB_OT_TAG_maxp:
- dest_blob = _subset<const OT::maxp> (plan, source);
+ result = _subset<const OT::maxp> (plan);
break;
case HB_OT_TAG_loca:
// SKIP loca, it's handle by glyf
return true;
case HB_OT_TAG_cmap:
- dest_blob = _subset<const OT::cmap> (plan, source);
+ result = _subset<const OT::cmap> (plan);
break;
case HB_OT_TAG_os2:
- dest_blob = _subset<const OT::os2> (plan, source);
+ result = _subset<const OT::os2> (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 071264e1..dafbb0e4 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 00000000..455cc15f
Binary files /dev/null and b/test/api/fonts/Inconsolata-Regular.ab.ttf differ
diff --git a/test/api/fonts/Inconsolata-Regular.abc.ttf b/test/api/fonts/Inconsolata-Regular.abc.ttf
new file mode 100644
index 00000000..34cf0516
Binary files /dev/null and b/test/api/fonts/Inconsolata-Regular.abc.ttf differ
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 00000000..352f2699
Binary files /dev/null and b/test/api/fonts/Inconsolata-Regular.abc.widerc.ttf differ
diff --git a/test/api/fonts/Inconsolata-Regular.ac.ttf b/test/api/fonts/Inconsolata-Regular.ac.ttf
new file mode 100644
index 00000000..991b8de4
Binary files /dev/null and b/test/api/fonts/Inconsolata-Regular.ac.ttf differ
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 00000000..2050c28d
Binary files /dev/null and b/test/api/fonts/Inconsolata-Regular.ac.widerc.ttf differ
diff --git a/test/api/fonts/README b/test/api/fonts/README
index a365afd7..7e7783c2 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 00000000..24a99c37
--- /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 <stdbool.h>
+
+#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();
+}
commit e5edcc81bf14311c56bd2f50808552076c3c4d77
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 11:17:53 2018 -0800
[subset] Fix codepoint iteration in hb-subset-test.
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index 498329c2..efae1797 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);
}
commit 8b1dbbef1aec3b6880186070e7386a5553d67b15
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 11:04:12 2018 -0800
Fix compile error in hb-subset-test.
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index 2546b5e0..498329c2 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);
commit a0fe3011bafbe36e7d5810acc7df21bea08c802a
Author: Rod Sheeter <rsheeter at google.com>
Date: Wed Feb 14 10:52:41 2018 -0800
copy all cmap groups at once
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index a27a8004..c3f242db 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<CmapSubtableLongGroup> &group_supplier)
+ hb_prealloced_array_t<CmapSubtableLongGroup> &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<CmapSubtableLongGroup> 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;
}
commit d008b62887afe631f50009f40e605c8456ddd011
Merge: b0eefacf 109314cb
Author: Garret Rieger <grieger at google.com>
Date: Wed Feb 14 10:38:52 2018 -0800
Merge remote-tracking branch 'upstream/master' into fixed
commit b0eefacf4cb885f510f9551bf2e9216808ca61e8
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 18:15:58 2018 -0800
[subset] Drop GSUB, GDEF, GPOS, and DSIG from subsetter expected test outputs.
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 9d791f7f..52706dc9 100644
Binary files a/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf and b/test/subset/data/expected/basics/Roboto-Regular.abc.default.62.ttf differ
diff --git a/test/subset/generate-expected-outputs.py b/test/subset/generate-expected-outputs.py
index f6636de7..6dac890e 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])
commit 89f17e3965ba776565f2de2bf56a4b135f336e53
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 18:14:50 2018 -0800
[subset] capitalize dsig.
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index dda9f3e9..3851977e 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;
commit df6d780355d7da805a9b9033452f8814c5360bba
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 17:56:17 2018 -0800
[subset] Extract maxp subsetting into hb-ot-maxp-table.
diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh
index fb2209c4..52b9388d 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<OT::maxp>().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 15730bf5..dda9f3e9 100644
--- a/src/hb-subset.cc
+++ b/src/hb-subset.cc
@@ -280,31 +280,6 @@ _add_head_and_set_loca_version (hb_face_t *source, bool use_short_loca, hb_face_
}
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<OT::maxp>().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp));
- const OT::maxp *maxp = OT::Sanitizer<OT::maxp>::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)
{
hb_blob_t *glyf_prime = nullptr;
@@ -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<const OT::maxp> (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 8db053c7..3c9d8fe9 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);
commit 865b6971ad5c2ec4bc33c36a78a36b90da5f5543
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 17:42:20 2018 -0800
[subset] Add a test for OS/2 fixes during subsetting.
diff --git a/test/api/Makefile.am b/test/api/Makefile.am
index 918bfb0e..071264e1 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 00000000..8e44886f
Binary files /dev/null and b/test/api/fonts/Roboto-Regular.b.ttf differ
diff --git a/test/api/test-subset-os2.c b/test/api/test-subset-os2.c
new file mode 100644
index 00000000..e2b96f92
--- /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 <stdbool.h>
+
+#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();
+}
commit 343dfe89655683966836e44afb4fd32c47377844
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 17:33:48 2018 -0800
[subset] white and add inline in hb-ot-cmap-table.
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 5ac97061..a27a8004 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<CmapSubtableLongGroup> &groups,
- size_t dest_sz,
- void *dest) const
+ inline hb_bool_t _subset (hb_prealloced_array_t<CmapSubtableLongGroup> &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<CmapSubtableLongGroup> 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
commit 24904383df03c472c865bd97bfe844f5e86a7172
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 17:31:01 2018 -0800
[subset] Correct usFirstCharIndex and usLastCharIndex in OS2 table when subsetting.
diff --git a/src/hb-ot-os2-table.hh b/src/hb-ot-os2-table.hh
index 5bed4701..f80a05d7 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<OT::os2>().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 e91d7800..15730bf5 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<const OT::cmap> (plan, source);
break;
+ case HB_OT_TAG_os2:
+ dest_blob = _subset<const OT::os2> (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;
- }
+ }
}
/**
commit 8cf8b78faaf3e7ee261bdc44a1ad5a1973eab1a2
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 16:30:21 2018 -0800
[subset] whitespace
diff --git a/test/api/test-subset-cmap.c b/test/api/test-subset-cmap.c
index 8775311d..8798475f 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);
commit d1a4d5616f792c6ad84bcc5011040167ddd7cc3f
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 16:25:32 2018 -0800
output format 12 as enc 10 to match how Roboto did it
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 4d32359d..5ac97061 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);
commit 89ee20f1a39ac78268b57a9aebe8e7428f9944bf
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 16:01:15 2018 -0800
basic wiring for a (failing) cmap test
diff --git a/test/api/Makefile.am b/test/api/Makefile.am
index e36b3fd5..918bfb0e 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 00000000..a365afd7
--- /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 00000000..46b4801a
Binary files /dev/null and b/test/api/fonts/Roboto-Regular.abc.cmap-format12-only.ttf differ
diff --git a/test/api/fonts/Roboto-Regular.ac.cmap-format12-only.ttf b/test/api/fonts/Roboto-Regular.ac.cmap-format12-only.ttf
new file mode 100644
index 00000000..47c9fafa
Binary files /dev/null and b/test/api/fonts/Roboto-Regular.ac.cmap-format12-only.ttf differ
diff --git a/test/api/hb-subset-test.h b/test/api/hb-subset-test.h
index bc7016f0..2546b5e0 100644
--- a/test/api/hb-subset-test.h
+++ b/test/api/hb-subset-test.h
@@ -85,8 +85,7 @@ hb_subset_test_open_font (const char *font_path)
hb_blob_destroy (blob);
return face;
}
-
- return NULL;
+ g_assert (false);
}
static inline hb_face_t *
diff --git a/test/api/test-subset-cmap.c b/test/api/test-subset-cmap.c
new file mode 100644
index 00000000..8775311d
--- /dev/null
+++ b/test/api/test-subset-cmap.c
@@ -0,0 +1,82 @@
+/*
+ * 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 <stdbool.h>
+
+#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 98e12339..8db053c7 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 4666ef99..00000000
--- 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]
commit afb1da3a1891b7c0fdd047bcb7b3bde86e830444
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 14:37:47 2018 -0800
auto-completed the wrong gids_to_retain
diff --git a/src/hb-subset-plan.cc b/src/hb-subset-plan.cc
index cc12abca..286f7e15 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;
commit 1330edc4fe3ffbf18313d6432045606865c610c4
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 14:29:23 2018 -0800
Use functions to get new gids. Avoid 0; fonttools drops it from cmap.
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index b3a7b8b8..4d32359d 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<hb_codepoint_t> &codepoints,
- hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const
+ inline hb_bool_t populate_groups(hb_subset_plan_t *plan,
+ hb_prealloced_array_t<CmapSubtableLongGroup> *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<CmapSubtableLongGroup> &groups,
@@ -600,7 +609,10 @@ struct cmap
{
hb_auto_array_t<CmapSubtableLongGroup> 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 a06d38ae..cc12abca 100644
--- a/src/hb-subset-plan.cc
+++ b/src/hb-subset-plan.cc
@@ -39,6 +39,24 @@ _hb_codepoint_t_cmp (const void *pa, const void *pb)
}
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,
hb_codepoint_t *new_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 410d9bec..09df7cdd 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 d9a4d125..e91d7800 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;
}
commit 1639bdd33122dc8e5522b95c37660273d1fc609e
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 13:40:42 2018 -0800
[subset] Remove test-subset, testing is planned to be done at the table level here with test/subset covering the complete subsetting operation.
diff --git a/test/api/Makefile.am b/test/api/Makefile.am
index 8c1c4757..e36b3fd5 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 4184a563..00000000
--- 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();
-}
commit 4cdd1b16c99f2681eb11d626c4408eebcc1672be
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 13:36:28 2018 -0800
[subset] added todo in test-subset-glyf.
diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c
index 538960c5..98e12339 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)
{
commit 1714feef4f7ec9e758e65edcbe5d5591562f46ee
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 13:35:17 2018 -0800
[subset] re-enable test-subset-glyf. Refactor to use common functions in hb-subset-test.h
diff --git a/test/api/test-subset-glyf.c b/test/api/test-subset-glyf.c
index fa41800b..538960c5 100644
--- a/test/api/test-subset-glyf.c
+++ b/test/api/test-subset-glyf.c
@@ -27,106 +27,50 @@
#include <stdbool.h>
#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);
+
+ 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'));
-#if 0 /* Enable when actually works. */
- face_abc_subset = hb_subset (face_abc, profile, input);
- g_assert (face_abc_subset);
+ hb_face_destroy (face_abc_subset);
+ hb_face_destroy (face_abc);
+ hb_face_destroy (face_ac);
+}
- 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'));
+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);
- // 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_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_blob_destroy (glyf_actual_blob);
- hb_blob_destroy (glyf_expected_blob);
+ 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);
-#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);
}
int
@@ -135,6 +79,7 @@ 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();
}
commit d8d8bd8405ec0db781c4c2bbb7ebd6ff520b3c2d
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 13:33:55 2018 -0800
[subset] Add some helper functions for writing tests around subsetting.
diff --git a/test/api/Makefile.am b/test/api/Makefile.am
index 9cda5ef3..8c1c4757 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 00000000..bc7016f0
--- /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 <stdio.h>
+
+#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 */
commit e8318188c0e53a267a01c45b0fc8d29ad775738a
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 11:38:28 2018 -0800
[subset] Fix loca generation, was previously writing the original glyph starting offset.
diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc
index cd886ea7..28f5f0c5 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;
}
commit a5713bc2cb4a3fd71d3bc94b9f155339b09eb71a
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 11:30:45 2018 -0800
we love all our groups
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index c338371f..b3a7b8b8 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);
}
}
commit 692f86e569847adb332186cbb08f344ebe41fa6c
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 11:29:23 2018 -0800
drop GDEF, GPOS, GSUB, and dsig
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index cacee706..d9a4d125 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);
commit 83e1ef92156d8688b96d14957efcdf7601768799
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 11:22:32 2018 -0800
[subset] Set the new number of glyphs in maxp.
diff --git a/src/hb-ot-maxp-table.hh b/src/hb-ot-maxp-table.hh
index 54b4f11c..fb2209c4 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 13acb8c9..cacee706 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,20 +267,43 @@ _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<OT::maxp>().sanitize (hb_face_reference_table (source, HB_OT_TAG_maxp));
+ const OT::maxp *maxp = OT::Sanitizer<OT::maxp>::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)
{
hb_blob_t *glyf_prime = nullptr;
@@ -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;
commit 427f9e4b90bfadb8af13cbd27b7c3ee0153ca8b1
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 11:18:28 2018 -0800
Don't force loca version to long.
diff --git a/src/hb-subset-glyf.cc b/src/hb-subset-glyf.cc
index 95294678..cd886ea7 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;
}
commit 5df080bf155a12f98929b99438da492063ab9218
Author: Garret Rieger <grieger at google.com>
Date: Mon Feb 12 10:15:59 2018 -0800
Destroy the subset plan at the end of subsetting.
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index 7b6b932f..13acb8c9 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 ();
}
commit 0301e5be286f5080ec34e9f30c75e73f28d0218b
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 10:12:11 2018 -0800
Build a working cmap format 12
diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh
index 030b822b..c338371f 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<CmapSubtableLongGroup> group_supplier (&groups[0], groups.len, sizeof (CmapSubtableLongGroup));
if (unlikely(!format12.serialize(&context, groups.len, group_supplier)))
+ {
return false;
+ }
context.end_serialize ();
+
return true;
}
commit ebd31d376d63c9698c0eae34ed295558f7230918
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 10:10:08 2018 -0800
subset for real
diff --git a/src/hb-subset.cc b/src/hb-subset.cc
index 94600617..7b6b932f 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 ();
}
commit 62c7d677e8699143e55e7bfa0cc3c1db75f32506
Author: Rod Sheeter <rsheeter at google.com>
Date: Mon Feb 12 10:09:35 2018 -0800
C-style comments
diff --git a/src/hb-open-file-private.hh b/src/hb-open-file-private.hh
index ae30655a..f01ab871 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<void> (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<void> (4 - rec.length % 4);
}
More information about the HarfBuzz
mailing list