From 748b989a1fa931b011d6a4e3db39dfdc632946b2 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 9 Jan 2018 17:55:17 +0100 Subject: [PATCH] [aat/morx] Implement NoncontextualSubtables Also makes hb-ot-shape call morx for now instead of GSUB... Just for testing. --- src/hb-aat-layout-common-private.hh | 34 ++++++------ src/hb-aat-layout-morx-table.hh | 82 ++++++++++++++++++++++++++--- src/hb-aat-layout-private.hh | 3 ++ src/hb-aat-layout.cc | 13 ++++- src/hb-ot-shape.cc | 6 +++ 5 files changed, 111 insertions(+), 27 deletions(-) diff --git a/src/hb-aat-layout-common-private.hh b/src/hb-aat-layout-common-private.hh index 88a9cd844..47efb4910 100644 --- a/src/hb-aat-layout-common-private.hh +++ b/src/hb-aat-layout-common-private.hh @@ -183,10 +183,10 @@ struct LookupFormat0 friend struct Lookup; private: - inline const T& get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const + inline const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const { - if (unlikely (glyph_id >= num_glyphs)) return Null(T); - return arrayZ[glyph_id]; + if (unlikely (glyph_id >= num_glyphs)) return nullptr; + return &arrayZ[glyph_id]; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -230,10 +230,10 @@ struct LookupFormat2 friend struct Lookup; private: - inline const T& get_value (hb_codepoint_t glyph_id) const + inline const T* get_value (hb_codepoint_t glyph_id) const { const LookupSegmentSingle *v = segments.bsearch (glyph_id); - return v ? v->value : Null(T); + return v ? &v->value : nullptr; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -255,9 +255,9 @@ struct LookupFormat2 template struct LookupSegmentArray { - inline const T& get_value (hb_codepoint_t glyph_id, const void *base) const + inline const T* get_value (hb_codepoint_t glyph_id, const void *base) const { - return first <= glyph_id && glyph_id <= last ? (base+valuesZ)[glyph_id - first] : Null(T); + return first <= glyph_id && glyph_id <= last ? &(base+valuesZ)[glyph_id - first] : nullptr; } inline int cmp (hb_codepoint_t g) const { @@ -287,10 +287,10 @@ struct LookupFormat4 friend struct Lookup; private: - inline const T& get_value (hb_codepoint_t glyph_id) const + inline const T* get_value (hb_codepoint_t glyph_id) const { const LookupSegmentArray *v = segments.bsearch (glyph_id); - return v ? v->get_value (glyph_id, this) : Null(T); + return v ? v->get_value (glyph_id, this) : nullptr; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -332,10 +332,10 @@ struct LookupFormat6 friend struct Lookup; private: - inline const T& get_value (hb_codepoint_t glyph_id) const + inline const T* get_value (hb_codepoint_t glyph_id) const { const LookupSingle *v = entries.bsearch (glyph_id); - return v ? v->value : Null(T); + return v ? &v->value : nullptr; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -358,9 +358,9 @@ struct LookupFormat8 friend struct Lookup; private: - inline const T& get_value (hb_codepoint_t glyph_id) const + inline const T* get_value (hb_codepoint_t glyph_id) const { - return firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount ? valueArrayZ[glyph_id - firstGlyph] : Null(T); + return firstGlyph <= glyph_id && glyph_id - firstGlyph < glyphCount ? &valueArrayZ[glyph_id - firstGlyph] : nullptr; } inline bool sanitize (hb_sanitize_context_t *c) const @@ -384,7 +384,7 @@ struct LookupFormat8 template struct Lookup { - inline const T& get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const + inline const T* get_value (hb_codepoint_t glyph_id, unsigned int num_glyphs) const { switch (u.format) { case 0: return u.format0.get_value (glyph_id, num_glyphs); @@ -392,7 +392,7 @@ struct Lookup case 4: return u.format4.get_value (glyph_id); case 6: return u.format6.get_value (glyph_id); case 8: return u.format8.get_value (glyph_id); - default:return Null(T); + default:return nullptr; } } @@ -423,10 +423,6 @@ struct Lookup DEFINE_SIZE_UNION (2, format); }; -// Instantiate, to catch compile errors. -Lookup g; -Lookup t; - } /* namespace AAT */ diff --git a/src/hb-aat-layout-morx-table.hh b/src/hb-aat-layout-morx-table.hh index 2cd7743bc..c59616e3a 100644 --- a/src/hb-aat-layout-morx-table.hh +++ b/src/hb-aat-layout-morx-table.hh @@ -27,8 +27,8 @@ #ifndef HB_AAT_LAYOUT_MORX_TABLE_HH #define HB_AAT_LAYOUT_MORX_TABLE_HH -#include -#include +#include "hb-open-type-private.hh" +#include "hb-aat-layout-common-private.hh" #define HB_AAT_TAG_MORT HB_TAG('m','o','r','t') #define HB_AAT_TAG_MORX HB_TAG('m','o','r','x') @@ -41,7 +41,13 @@ using namespace OT; struct RearrangementSubtable { - /* TODO */ + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + /* TODO */ + return_trace (false); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -52,7 +58,13 @@ struct RearrangementSubtable struct ContextualSubtable { - /* TODO */ + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + /* TODO */ + return_trace (false); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -63,7 +75,13 @@ struct ContextualSubtable struct LigatureSubtable { - /* TODO */ + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + /* TODO */ + return_trace (false); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -74,6 +92,26 @@ struct LigatureSubtable struct NoncontextualSubtable { + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + hb_buffer_t *buffer = c->buffer; + hb_glyph_info_t *info = buffer->info; + unsigned int num_glyphs = c->face->get_num_glyphs (); + bool ret = false; + unsigned int count = buffer->len; + for (unsigned int i = 0; i < count; i++) + { + const GlyphID *replacement = substitute.get_value (info[i].codepoint, num_glyphs); + if (replacement) + { + info[i].codepoint = *replacement; + ret = true; + } + } + return_trace (ret); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -88,7 +126,13 @@ struct NoncontextualSubtable struct InsertionSubtable { - /* TODO */ + inline bool apply (hb_apply_context_t *c) const + { + TRACE_APPLY (this); + /* TODO */ + return_trace (false); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -136,6 +180,11 @@ struct ChainSubtable Insertion = 5 }; + inline void apply (hb_apply_context_t *c) const + { + dispatch (c); + } + template inline typename context_t::return_t dispatch (context_t *c) const { @@ -180,6 +229,16 @@ struct ChainSubtable template struct Chain { + inline void apply (hb_apply_context_t *c) const + { + const ChainSubtable *subtable = &StructAtOffset > (featureZ, featureZ[0].static_size * featureCount); + unsigned int count = subtableCount; + for (unsigned int i = 0; i < count; i++) + { + subtable->apply (c); + subtable = &StructAfter > (*subtable); + } + } inline unsigned int get_size (void) const { return length; } @@ -231,6 +290,17 @@ struct mortmorx static const hb_tag_t mortTag = HB_AAT_TAG_MORT; static const hb_tag_t morxTag = HB_AAT_TAG_MORX; + inline void apply (hb_apply_context_t *c) const + { + const Chain *chain = chains; + unsigned int count = chainCount; + for (unsigned int i = 0; i < count; i++) + { + chain->apply (c); + chain = &StructAfter > (*chain); + } + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); diff --git a/src/hb-aat-layout-private.hh b/src/hb-aat-layout-private.hh index 6adf084c3..eb2cdd1cd 100644 --- a/src/hb-aat-layout-private.hh +++ b/src/hb-aat-layout-private.hh @@ -34,4 +34,7 @@ #include "hb-open-type-private.hh" +HB_INTERNAL void +hb_aat_layout_substitute (OT::hb_apply_context_t *c); + #endif /* HB_AAT_LAYOUT_PRIVATE_HH */ diff --git a/src/hb-aat-layout.cc b/src/hb-aat-layout.cc index bd647d5c1..79f0ae65f 100644 --- a/src/hb-aat-layout.cc +++ b/src/hb-aat-layout.cc @@ -25,7 +25,9 @@ */ #include "hb-open-type-private.hh" + #include "hb-ot-layout-private.hh" +#include "hb-ot-layout-gsubgpos-private.hh" #include "hb-aat-layout-private.hh" #include "hb-aat-layout-morx-table.hh" @@ -39,10 +41,10 @@ _get_morx (hb_face_t *face) { if (unlikely (!hb_ot_shaper_face_data_ensure (face))) return OT::Null(AAT::morx); hb_ot_layout_t * layout = hb_ot_layout_from_face (face); - return *(layout->morx.get ()); + return *(layout->morx.get ()); /* XXX this doesn't call set_num_glyphs on sanitizer. */ } -void +static inline void _hb_aat_layout_create (hb_face_t *face) { OT::Sanitizer sanitizer; @@ -55,3 +57,10 @@ _hb_aat_layout_create (hb_face_t *face) OT::Sanitizer >::lock_instance (morx_blob)->get_value (1, face->get_num_glyphs ()); } } + +void +hb_aat_layout_substitute (OT::hb_apply_context_t *c) +{ + const AAT::morx& morx = _get_morx (c->face); + morx.apply (c); +} diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index a19763d12..693024883 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -40,6 +40,8 @@ #include "hb-unicode-private.hh" #include "hb-set-private.hh" +#include "hb-ot-layout-gsubgpos-private.hh" +#include "hb-aat-layout-private.hh" static hb_tag_t common_features[] = { HB_TAG('c','c','m','p'), @@ -613,6 +615,10 @@ hb_ot_substitute_complex (hb_ot_shape_context_t *c) hb_synthesize_glyph_classes (c); c->plan->substitute (c->font, buffer); + + /* XXX Call morx instead. */ + OT::hb_apply_context_t ac (0, c->font, c->buffer); + hb_aat_layout_substitute (&ac); } static inline void