From f94b0aa64609654497ced9c00312c9643eb69053 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Mon, 23 Apr 2012 13:04:38 -0400 Subject: [PATCH] Add "closure" operation stubs to GSUB Filling in. --- src/hb-ot-layout-gsub-table.hh | 179 +++++++++++++++++++++++++++++++++++ src/hb-ot-layout-gsubgpos-private.hh | 110 ++++++++++++++++++++- src/hb-ot-layout.cc | 8 ++ 3 files changed, 293 insertions(+), 4 deletions(-) diff --git a/src/hb-ot-layout-gsub-table.hh b/src/hb-ot-layout-gsub-table.hh index f2210a0..54d81e5 100644 --- a/src/hb-ot-layout-gsub-table.hh +++ b/src/hb-ot-layout-gsub-table.hh @@ -39,6 +39,13 @@ struct SingleSubstFormat1 private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t glyph_id) const { return (this+coverage) (glyph_id) != NOT_COVERED; @@ -83,6 +90,13 @@ struct SingleSubstFormat2 private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t glyph_id) const { return (this+coverage) (glyph_id) != NOT_COVERED; @@ -129,6 +143,16 @@ struct SingleSubst private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c); + case 2: return u.format2.closure (c); + default:return false; + } + } + inline bool would_apply (hb_codepoint_t glyph_id) const { switch (u.format) { @@ -172,6 +196,14 @@ struct Sequence friend struct MultipleSubstFormat1; private: + + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -204,6 +236,13 @@ struct MultipleSubstFormat1 private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t glyph_id) const { return (this+coverage) (glyph_id) != NOT_COVERED; @@ -244,6 +283,15 @@ struct MultipleSubst private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c); + default:return false; + } + } + inline bool would_apply (hb_codepoint_t glyph_id) const { switch (u.format) { @@ -287,6 +335,13 @@ struct AlternateSubstFormat1 private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t glyph_id) const { return (this+coverage) (glyph_id) != NOT_COVERED; @@ -347,6 +402,15 @@ struct AlternateSubst private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c); + default:return false; + } + } + inline bool would_apply (hb_codepoint_t glyph_id) const { switch (u.format) { @@ -387,6 +451,13 @@ struct Ligature private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t second) const { return component.len == 2 && component[1] == second; @@ -482,6 +553,13 @@ struct LigatureSet private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t second) const { unsigned int num_ligs = ligature.len; @@ -528,6 +606,13 @@ struct LigatureSubstFormat1 private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const { unsigned int index; @@ -572,6 +657,15 @@ struct LigatureSubst private: + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c); + default:return false; + } + } + inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const { switch (u.format) { @@ -607,12 +701,20 @@ struct LigatureSubst static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index); +static inline bool closure_lookup (hb_closure_context_t *c, unsigned int lookup_index); struct ContextSubst : Context { friend struct SubstLookupSubTable; private: + + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + return Context::closure (c, closure_lookup); + } + inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -625,6 +727,13 @@ struct ChainContextSubst : ChainContext friend struct SubstLookupSubTable; private: + + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + return ChainContext::closure (c, closure_lookup); + } + inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -646,6 +755,13 @@ struct ExtensionSubst : Extension return StructAtOffset (this, offset); } + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool would_apply (hb_codepoint_t glyph_id) const; inline bool would_apply (hb_codepoint_t first, hb_codepoint_t second) const; @@ -662,6 +778,14 @@ struct ReverseChainSingleSubstFormat1 friend struct ReverseChainSingleSubst; private: + + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -728,6 +852,16 @@ struct ReverseChainSingleSubst friend struct SubstLookupSubTable; private: + + inline bool closure (hb_closure_context_t *c) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c); + default:return false; + } + } + inline bool apply (hb_apply_context_t *c) const { TRACE_APPLY (); @@ -774,6 +908,23 @@ struct SubstLookupSubTable ReverseChainSingle = 8 }; + inline bool closure (hb_closure_context_t *c, + unsigned int lookup_type) const + { + TRACE_CLOSURE (); + switch (lookup_type) { + case Single: return u.single.closure (c); + case Multiple: return u.multiple.closure (c); + case Alternate: return u.alternate.closure (c); + case Ligature: return u.ligature.closure (c); + case Context: return u.c.closure (c); + case ChainContext: return u.chainContext.closure (c); + case Extension: return u.extension.closure (c); + case ReverseChainSingle: return u.reverseChainContextSingle.closure (c); + default:return false; + } + } + inline bool would_apply (hb_codepoint_t glyph_id, unsigned int lookup_type) const { @@ -860,6 +1011,15 @@ struct SubstLookup : Lookup return lookup_type_is_reverse (type); } + inline bool closure (hb_closure_context_t *c) const + { + unsigned int lookup_type = get_type (); + unsigned int count = get_subtable_count (); + bool ret = false; + for (unsigned int i = 0; i < count; i++) + ret = get_subtable (i).closure (c, lookup_type) || ret; + return ret; + } inline bool would_apply (hb_codepoint_t glyph_id) const { @@ -984,6 +1144,10 @@ struct GSUB : GSUBGPOS static inline void substitute_start (hb_buffer_t *buffer); static inline void substitute_finish (hb_buffer_t *buffer); + inline bool closure_lookup (hb_closure_context_t *c, + unsigned int lookup_index) const + { return get_lookup (lookup_index).closure (c); } + inline bool sanitize (hb_sanitize_context_t *c) { TRACE_SANITIZE (); if (unlikely (!GSUBGPOS::sanitize (c))) return false; @@ -1048,6 +1212,21 @@ inline bool ExtensionSubst::is_reverse (void) const return SubstLookup::lookup_type_is_reverse (type); } +static inline bool closure_lookup (hb_closure_context_t *c, unsigned int lookup_index) +{ + const GSUB &gsub = *(c->face->ot_layout->gsub); + const SubstLookup &l = gsub.get_lookup (lookup_index); + + if (unlikely (c->nesting_level_left == 0)) + return false; + + c->nesting_level_left--; + bool ret = l.closure (c); + c->nesting_level_left++; + + return ret; +} + static inline bool substitute_lookup (hb_apply_context_t *c, unsigned int lookup_index) { const GSUB &gsub = *(c->face->ot_layout->gsub); diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh index 62ac29e..d5bc377 100644 --- a/src/hb-ot-layout-gsubgpos-private.hh +++ b/src/hb-ot-layout-gsubgpos-private.hh @@ -31,6 +31,8 @@ #include "hb-buffer-private.hh" #include "hb-ot-layout-gdef-table.hh" +#include "hb-ot-layout-closure.h" + /* buffer var allocations */ @@ -45,6 +47,35 @@ static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) { +#ifndef HB_DEBUG_CLOSURE +#define HB_DEBUG_CLOSURE (HB_DEBUG+0) +#endif + +#define TRACE_CLOSURE() \ + hb_auto_trace_t trace (&c->debug_depth, "CLOSURE", this, NULL, HB_FUNC); + + + +struct hb_closure_context_t +{ + hb_face_t *face; + hb_glyph_map_t *glyphs; + unsigned int nesting_level_left; + unsigned int debug_depth; + + + hb_closure_context_t (hb_face_t *face_, + hb_glyph_map_t *glyphs_, + unsigned int nesting_level_left_ = MAX_NESTING_LEVEL) : + face (face_), glyphs (glyphs_), + nesting_level_left (nesting_level_left_), + debug_depth (0) {} +}; + +typedef bool (*closure_lookup_func_t) (hb_closure_context_t *c, unsigned int lookup_index); + + + #ifndef HB_DEBUG_APPLY #define HB_DEBUG_APPLY (HB_DEBUG+0) #endif @@ -56,7 +87,6 @@ static inline uint8_t allocate_lig_id (hb_buffer_t *buffer) { struct hb_apply_context_t { - unsigned int debug_depth; hb_font_t *font; hb_face_t *face; hb_buffer_t *buffer; @@ -66,6 +96,7 @@ struct hb_apply_context_t unsigned int nesting_level_left; unsigned int lookup_props; unsigned int property; /* propety of first glyph */ + unsigned int debug_depth; hb_apply_context_t (hb_font_t *font_, @@ -81,7 +112,7 @@ struct hb_apply_context_t context_length (context_length_), nesting_level_left (nesting_level_left_), lookup_props (l.get_props ()), - property (0) {} + property (0), debug_depth (0) {} hb_apply_context_t (const hb_apply_context_t &c, const Lookup &l) { *this = c; @@ -427,8 +458,8 @@ struct Rule return inputCount.sanitize (c) && lookupCount.sanitize (c) && c->check_range (input, - input[0].static_size * inputCount - + lookupRecordX[0].static_size * lookupCount); + input[0].static_size * inputCount + + lookupRecordX[0].static_size * lookupCount); } private: @@ -478,6 +509,14 @@ struct ContextFormat1 friend struct Context; private: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -517,6 +556,14 @@ struct ContextFormat2 friend struct Context; private: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -562,6 +609,14 @@ struct ContextFormat3 friend struct Context; private: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -608,6 +663,18 @@ struct ContextFormat3 struct Context { protected: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c, closure_func); + case 2: return u.format2.closure (c, closure_func); + case 3: return u.format3.closure (c, closure_func); + default:return false; + } + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -765,6 +832,14 @@ struct ChainContextFormat1 friend struct ChainContext; private: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -803,6 +878,14 @@ struct ChainContextFormat2 friend struct ChainContext; private: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -864,6 +947,13 @@ struct ChainContextFormat3 private: + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + /* TODO FILLME */ + return false; + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); @@ -922,6 +1012,18 @@ struct ChainContextFormat3 struct ChainContext { protected: + + inline bool closure (hb_closure_context_t *c, closure_lookup_func_t closure_func) const + { + TRACE_CLOSURE (); + switch (u.format) { + case 1: return u.format1.closure (c, closure_func); + case 2: return u.format2.closure (c, closure_func); + case 3: return u.format3.closure (c, closure_func); + default:return false; + } + } + inline bool apply (hb_apply_context_t *c, apply_lookup_func_t apply_func) const { TRACE_APPLY (); diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc index f3e0713..e515890 100644 --- a/src/hb-ot-layout.cc +++ b/src/hb-ot-layout.cc @@ -469,6 +469,14 @@ hb_ot_layout_substitute_finish (hb_buffer_t *buffer HB_UNUSED) GSUB::substitute_finish (buffer); } +hb_bool_t +hb_ot_layout_closure_lookup (hb_face_t *face, + hb_glyph_map_t *glyphs, + unsigned int lookup_index) +{ + hb_closure_context_t c (face, glyphs); + return _get_gsub (face).closure_lookup (&c, lookup_index); +} /* * GPOS -- 2.7.4