From 53e55945000347fb19168bb4c13a470d30d46251 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 9 Oct 2018 22:35:22 -0400 Subject: [PATCH] [kerx] Implement Format0 apply() Not hooked up to be called yet. --- src/hb-aat-layout-common.hh | 6 ++++-- src/hb-aat-layout-kerx-table.hh | 29 ++++++++++++++++++++++++++--- src/hb-aat-layout.cc | 6 ++++-- src/hb-aat-layout.hh | 12 +++++++----- src/hb-ot-shape.cc | 2 +- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/hb-aat-layout-common.hh b/src/hb-aat-layout-common.hh index d6e597a40..22c84255b 100644 --- a/src/hb-aat-layout-common.hh +++ b/src/hb-aat-layout-common.hh @@ -518,6 +518,7 @@ struct hb_aat_apply_context_t : static return_t default_return_value (void) { return false; } bool stop_sublookup_iteration (return_t r) const { return r; } + hb_ot_shape_plan_t *plan; hb_font_t *font; hb_face_t *face; hb_buffer_t *buffer; @@ -527,10 +528,11 @@ struct hb_aat_apply_context_t : unsigned int lookup_index; unsigned int debug_depth; - inline hb_aat_apply_context_t (hb_font_t *font_, + inline hb_aat_apply_context_t (hb_ot_shape_plan_t *plan_, + hb_font_t *font_, hb_buffer_t *buffer_, hb_blob_t *table) : - font (font_), face (font->face), buffer (buffer_), + plan (plan_), font (font_), face (font->face), buffer (buffer_), sanitizer (), lookup_index (0), debug_depth (0) { sanitizer.init (table); diff --git a/src/hb-aat-layout-kerx-table.hh b/src/hb-aat-layout-kerx-table.hh index 49d188c36..42181bf64 100644 --- a/src/hb-aat-layout-kerx-table.hh +++ b/src/hb-aat-layout-kerx-table.hh @@ -59,7 +59,9 @@ struct KerxSubTableFormat0 { TRACE_APPLY (this); - /* TODO */ + hb_kern_machine_t machine (*this); + + machine.kern (c->font, c->buffer, c->plan->kern_mask); return_trace (true); } @@ -111,8 +113,6 @@ struct KerxSubTableFormat2 unsigned int r = *(this+rightClassTable).get_value (right, num_glyphs); unsigned int offset = l + r; const FWORD *arr = &(this+array); - if (unlikely ((const void *) arr < (const void *) this || (const void *) arr >= (const void *) end)) - return 0; const FWORD *v = &StructAtOffset (arr, offset); if (unlikely ((const void *) v < (const void *) arr || (const void *) (v + 1) > (const void *) end)) return 0; @@ -124,6 +124,13 @@ struct KerxSubTableFormat2 TRACE_APPLY (this); /* TODO */ +#if 0 + accelerator_t accel (*this, + c->blob->data + c->blob->len, + c->face->get_num_glyphs ()); + hb_kern_machine_t machine (accel); + machine.kern (c->font, c->buffer, c->plan->kern_mask); +#endif return_trace (true); } @@ -138,6 +145,22 @@ struct KerxSubTableFormat2 array.sanitize (c, this))); } + struct accelerator_t + { + const KerxSubTableFormat2 &table; + const char *end; + unsigned int num_glyphs; + + inline accelerator_t (const KerxSubTableFormat2 &table_, + const char *end_, unsigned int num_glyphs_) + : table (table_), end (end_), num_glyphs (num_glyphs_) {} + + inline int get_kerning (hb_codepoint_t left, hb_codepoint_t right) const + { + return table.get_kerning (left, right, end, num_glyphs); + } + }; + protected: HBUINT32 rowWidth; /* The width, in bytes, of a row in the table. */ LOffsetTo > diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index faf418d6e..5cd9621f1 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -62,12 +62,14 @@ hb_aat_layout_has_substitution (hb_face_t *face) } void -hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer) +hb_aat_layout_substitute (hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer) { hb_blob_t *blob; const AAT::morx& morx = _get_morx (font->face, &blob); - AAT::hb_aat_apply_context_t c (font, buffer, blob); + AAT::hb_aat_apply_context_t c (plan, font, buffer, blob); morx.apply (&c); } diff --git a/src/hb-aat-layout.hh b/src/hb-aat-layout.hh index 553832f1e..8b12833d9 100644 --- a/src/hb-aat-layout.hh +++ b/src/hb-aat-layout.hh @@ -29,17 +29,19 @@ #include "hb.hh" -#include "hb-font.hh" -#include "hb-buffer.hh" -#include "hb-open-type.hh" +#include "hb-ot-shape.hh" HB_INTERNAL hb_bool_t hb_aat_layout_has_substitution (hb_face_t *face); HB_INTERNAL void -hb_aat_layout_substitute (hb_font_t *font, hb_buffer_t *buffer); +hb_aat_layout_substitute (hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); HB_INTERNAL void -hb_aat_layout_position (hb_font_t *font, hb_buffer_t *buffer); +hb_aat_layout_position (hb_ot_shape_plan_t *plan, + hb_font_t *font, + hb_buffer_t *buffer); #endif /* HB_AAT_LAYOUT_HH */ diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index a9c0844e8..6753ceb29 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -668,7 +668,7 @@ hb_ot_substitute_complex (const hb_ot_shape_context_t *c) hb_synthesize_glyph_classes (c); if (unlikely (c->plan->apply_morx)) - hb_aat_layout_substitute (c->font, c->buffer); + hb_aat_layout_substitute (c->plan, c->font, c->buffer); else c->plan->substitute (c->font, buffer); }