[HB] Towards sharing Context and ChainContext code
This commit is contained in:
parent
6cf2a52593
commit
48f16ed96a
|
@ -47,29 +47,29 @@
|
||||||
property
|
property
|
||||||
|
|
||||||
|
|
||||||
/* Contextual lookups */
|
|
||||||
|
|
||||||
typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data);
|
typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data);
|
||||||
typedef bool (*apply_lookup_func_t) (LOOKUP_ARGS_DEF, unsigned int lookup_index);
|
typedef bool (*apply_lookup_func_t) (LOOKUP_ARGS_DEF, unsigned int lookup_index);
|
||||||
|
|
||||||
struct ContextLookupContext {
|
struct ContextFuncs {
|
||||||
inline bool match (hb_codepoint_t glyph_id, const USHORT &value) const {
|
match_func_t match;
|
||||||
return match_func (glyph_id, value, match_data);
|
apply_lookup_func_t apply;
|
||||||
}
|
|
||||||
inline bool apply (LOOKUP_ARGS_DEF, unsigned int lookup_index) const {
|
|
||||||
return apply_func (LOOKUP_ARGS, lookup_index);
|
|
||||||
}
|
|
||||||
|
|
||||||
match_func_t match_func;
|
|
||||||
char *match_data;
|
|
||||||
apply_lookup_func_t apply_func;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct LookupRecord {
|
static inline bool match_glyph (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
|
||||||
|
return glyph_id == value;
|
||||||
|
}
|
||||||
|
|
||||||
inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const {
|
static inline bool match_class (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
|
||||||
return context.apply (LOOKUP_ARGS, lookupListIndex);
|
const ClassDef &class_def = * (const ClassDef *) data;
|
||||||
}
|
return class_def.get_class (glyph_id) == value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static inline bool match_coverage (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
|
||||||
|
const OffsetTo<Coverage> &coverage = * (const OffsetTo<Coverage> *) &value;
|
||||||
|
return (data+coverage) (glyph_id) != NOT_COVERED;
|
||||||
|
}
|
||||||
|
|
||||||
|
struct LookupRecord {
|
||||||
|
|
||||||
USHORT sequenceIndex; /* Index into current glyph
|
USHORT sequenceIndex; /* Index into current glyph
|
||||||
* sequence--first glyph = 0 */
|
* sequence--first glyph = 0 */
|
||||||
|
@ -78,15 +78,23 @@ struct LookupRecord {
|
||||||
};
|
};
|
||||||
ASSERT_SIZE (LookupRecord, 4);
|
ASSERT_SIZE (LookupRecord, 4);
|
||||||
|
|
||||||
|
|
||||||
|
/* Contextual lookups */
|
||||||
|
|
||||||
|
struct ContextLookupContext {
|
||||||
|
ContextFuncs funcs;
|
||||||
|
char *match_data;
|
||||||
|
};
|
||||||
|
|
||||||
static inline bool context_lookup (LOOKUP_ARGS_DEF,
|
static inline bool context_lookup (LOOKUP_ARGS_DEF,
|
||||||
USHORT glyphCount, /* Including the first glyph (not matched) */
|
USHORT inputCount, /* Including the first glyph (not matched) */
|
||||||
USHORT recordCount,
|
const USHORT input[], /* Array of input values--start with second glyph */
|
||||||
const USHORT value[], /* Array of match values--start with second glyph */
|
USHORT lookupCount,
|
||||||
const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
|
const LookupRecord lookupRecord[], /* Array of LookupRecords--in design order */
|
||||||
ContextLookupContext &context) {
|
ContextLookupContext &context) {
|
||||||
|
|
||||||
unsigned int i, j;
|
unsigned int i, j;
|
||||||
unsigned int count = glyphCount;
|
unsigned int count = inputCount;
|
||||||
|
|
||||||
if (HB_UNLIKELY (buffer->in_pos + count > buffer->in_length ||
|
if (HB_UNLIKELY (buffer->in_pos + count > buffer->in_length ||
|
||||||
context_length < count))
|
context_length < count))
|
||||||
|
@ -102,7 +110,7 @@ static inline bool context_lookup (LOOKUP_ARGS_DEF,
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (HB_LIKELY (context.match (IN_GLYPH(j), value[i - 1])))
|
if (HB_LIKELY (context.funcs.match (IN_GLYPH(j), input[i - 1], context.match_data)))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -110,7 +118,9 @@ static inline bool context_lookup (LOOKUP_ARGS_DEF,
|
||||||
context_length = count;
|
context_length = count;
|
||||||
|
|
||||||
/* XXX We have to jump non-matching glyphs when applying too, right? */
|
/* XXX We have to jump non-matching glyphs when applying too, right? */
|
||||||
unsigned int record_count = recordCount;
|
/* XXX We don't support lookupRecord arrays that are not increasing:
|
||||||
|
* Should be easy for in_place ones at least. */
|
||||||
|
unsigned int record_count = lookupCount;
|
||||||
const LookupRecord *record = lookupRecord;
|
const LookupRecord *record = lookupRecord;
|
||||||
for (i = 0; i < count;)
|
for (i = 0; i < count;)
|
||||||
{
|
{
|
||||||
|
@ -119,7 +129,7 @@ static inline bool context_lookup (LOOKUP_ARGS_DEF,
|
||||||
unsigned int old_pos = buffer->in_pos;
|
unsigned int old_pos = buffer->in_pos;
|
||||||
|
|
||||||
/* Apply a lookup */
|
/* Apply a lookup */
|
||||||
bool done = record->apply (LOOKUP_ARGS, context);
|
bool done = context.funcs.apply (LOOKUP_ARGS, record->lookupListIndex);
|
||||||
|
|
||||||
record++;
|
record++;
|
||||||
record_count--;
|
record_count--;
|
||||||
|
@ -139,29 +149,30 @@ static inline bool context_lookup (LOOKUP_ARGS_DEF,
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Rule {
|
struct Rule {
|
||||||
|
|
||||||
friend struct RuleSet;
|
friend struct RuleSet;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
DEFINE_ARRAY_TYPE (USHORT, value, (glyphCount ? glyphCount - 1 : 0));
|
DEFINE_ARRAY_TYPE (USHORT, input, (inputCount ? inputCount - 1 : 0));
|
||||||
|
|
||||||
inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const {
|
inline bool apply (LOOKUP_ARGS_DEF, ContextLookupContext &context) const {
|
||||||
const LookupRecord *record = (const LookupRecord *) ((const char *) value + sizeof (value[0]) * (glyphCount ? glyphCount - 1 : 0));
|
const LookupRecord *record = (const LookupRecord *) ((const char *) input + sizeof (input[0]) * (inputCount ? inputCount - 1 : 0));
|
||||||
return context_lookup (LOOKUP_ARGS,
|
return context_lookup (LOOKUP_ARGS,
|
||||||
glyphCount,
|
inputCount,
|
||||||
recordCount,
|
input,
|
||||||
value,
|
lookupCount,
|
||||||
record,
|
record,
|
||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
USHORT glyphCount; /* Total number of glyphs in input
|
USHORT inputCount; /* Total number of glyphs in input
|
||||||
* glyph sequence--includes the first
|
* glyph sequence--includes the first
|
||||||
* glyph */
|
* glyph */
|
||||||
USHORT recordCount; /* Number of LookupRecords */
|
USHORT lookupCount; /* Number of LookupRecords */
|
||||||
USHORT value[]; /* Array of match values--start with
|
USHORT input[]; /* Array of match inputs--start with
|
||||||
* second glyph */
|
* second glyph */
|
||||||
LookupRecord lookupRecord[]; /* Array of LookupRecords--in
|
LookupRecord lookupRecord[]; /* Array of LookupRecords--in
|
||||||
* design order */
|
* design order */
|
||||||
|
@ -183,15 +194,11 @@ struct RuleSet {
|
||||||
|
|
||||||
private:
|
private:
|
||||||
OffsetArrayOf<Rule>
|
OffsetArrayOf<Rule>
|
||||||
rule; /* Array SubRule tables
|
rule; /* Array of Rule tables
|
||||||
* ordered by preference */
|
* ordered by preference */
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static inline bool glyph_match (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
|
|
||||||
return glyph_id == value;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ContextFormat1 {
|
struct ContextFormat1 {
|
||||||
|
|
||||||
friend struct Context;
|
friend struct Context;
|
||||||
|
@ -202,8 +209,8 @@ struct ContextFormat1 {
|
||||||
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
unsigned int index = (this+coverage) (IN_CURGLYPH ());
|
||||||
const RuleSet &rule_set = this+ruleSet[index];
|
const RuleSet &rule_set = this+ruleSet[index];
|
||||||
struct ContextLookupContext context = {
|
struct ContextLookupContext context = {
|
||||||
glyph_match, NULL,
|
{match_glyph, apply_func},
|
||||||
apply_func
|
NULL
|
||||||
};
|
};
|
||||||
return rule_set.apply (LOOKUP_ARGS, context);
|
return rule_set.apply (LOOKUP_ARGS, context);
|
||||||
}
|
}
|
||||||
|
@ -220,11 +227,6 @@ struct ContextFormat1 {
|
||||||
ASSERT_SIZE (ContextFormat1, 6);
|
ASSERT_SIZE (ContextFormat1, 6);
|
||||||
|
|
||||||
|
|
||||||
static inline bool class_match (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
|
|
||||||
const ClassDef &class_def = * (const ClassDef *) data;
|
|
||||||
return class_def.get_class (glyph_id) == value;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ContextFormat2 {
|
struct ContextFormat2 {
|
||||||
|
|
||||||
friend struct Context;
|
friend struct Context;
|
||||||
|
@ -238,8 +240,8 @@ struct ContextFormat2 {
|
||||||
* them across subrule lookups. Not sure it's worth it.
|
* them across subrule lookups. Not sure it's worth it.
|
||||||
*/
|
*/
|
||||||
struct ContextLookupContext context = {
|
struct ContextLookupContext context = {
|
||||||
class_match, (char *) &(this+classDef),
|
{match_class, apply_func},
|
||||||
apply_func
|
(char *) &(this+classDef)
|
||||||
};
|
};
|
||||||
return rule_set.apply (LOOKUP_ARGS, context);
|
return rule_set.apply (LOOKUP_ARGS, context);
|
||||||
}
|
}
|
||||||
|
@ -259,11 +261,6 @@ struct ContextFormat2 {
|
||||||
ASSERT_SIZE (ContextFormat2, 8);
|
ASSERT_SIZE (ContextFormat2, 8);
|
||||||
|
|
||||||
|
|
||||||
static inline bool coverage_match (hb_codepoint_t glyph_id, const USHORT &value, char *data) {
|
|
||||||
const OffsetTo<Coverage> &coverage = * (const OffsetTo<Coverage> *) &value;
|
|
||||||
return (data+coverage) (glyph_id) != NOT_COVERED;
|
|
||||||
}
|
|
||||||
|
|
||||||
struct ContextFormat3 {
|
struct ContextFormat3 {
|
||||||
|
|
||||||
friend struct Context;
|
friend struct Context;
|
||||||
|
@ -276,13 +273,13 @@ struct ContextFormat3 {
|
||||||
inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
|
inline bool apply_coverage (LOOKUP_ARGS_DEF, apply_lookup_func_t apply_func) const {
|
||||||
const LookupRecord *record = (const LookupRecord *) ((const char *) coverage + sizeof (coverage[0]) * glyphCount);
|
const LookupRecord *record = (const LookupRecord *) ((const char *) coverage + sizeof (coverage[0]) * glyphCount);
|
||||||
struct ContextLookupContext context = {
|
struct ContextLookupContext context = {
|
||||||
coverage_match, (char *) this,
|
{match_coverage, apply_func},
|
||||||
apply_func
|
(char *) this
|
||||||
};
|
};
|
||||||
return context_lookup (LOOKUP_ARGS,
|
return context_lookup (LOOKUP_ARGS,
|
||||||
glyphCount,
|
glyphCount,
|
||||||
recordCount,
|
|
||||||
(const USHORT *) (coverage + 1),
|
(const USHORT *) (coverage + 1),
|
||||||
|
lookupCount,
|
||||||
record,
|
record,
|
||||||
context);
|
context);
|
||||||
}
|
}
|
||||||
|
@ -299,7 +296,7 @@ struct ContextFormat3 {
|
||||||
USHORT format; /* Format identifier--format = 3 */
|
USHORT format; /* Format identifier--format = 3 */
|
||||||
USHORT glyphCount; /* Number of glyphs in the input glyph
|
USHORT glyphCount; /* Number of glyphs in the input glyph
|
||||||
* sequence */
|
* sequence */
|
||||||
USHORT recordCount; /* Number of LookupRecords */
|
USHORT lookupCount; /* Number of LookupRecords */
|
||||||
Offset coverage[]; /* Array of offsets to Coverage
|
Offset coverage[]; /* Array of offsets to Coverage
|
||||||
* table--from beginning of
|
* table--from beginning of
|
||||||
* table--in glyph
|
* table--in glyph
|
||||||
|
@ -334,43 +331,60 @@ ASSERT_SIZE (Context, 2);
|
||||||
|
|
||||||
/* Chaining Contextual lookups */
|
/* Chaining Contextual lookups */
|
||||||
|
|
||||||
struct ChainSubRule {
|
struct ChainContextLookupContext {
|
||||||
|
ContextFuncs funcs;
|
||||||
|
char *match_data[3];
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
struct ChainRule {
|
||||||
/* TODO */
|
/* TODO */
|
||||||
|
|
||||||
private:
|
private:
|
||||||
USHORT backtrackGlyphCount; /* Total number of glyphs in the
|
USHORT backtrackCount; /* Total number of glyphs in the
|
||||||
* backtrack sequence (number of
|
* backtrack sequence (number of
|
||||||
* glyphs to be matched before the
|
* glyphs to be matched before the
|
||||||
* first glyph) */
|
* first glyph) */
|
||||||
GlyphID backtrack[]; /* Array of backtracking GlyphID's
|
USHORT backtrack[]; /* Array of backtracking values
|
||||||
* (to be matched before the input
|
* (to be matched before the input
|
||||||
* sequence) */
|
* sequence) */
|
||||||
USHORT inputGlyphCount; /* Total number of glyphs in the input
|
USHORT inputCount; /* Total number of values in the input
|
||||||
* sequence (includes the first glyph) */
|
* sequence (includes the first glyph) */
|
||||||
GlyphID input[]; /* Array of input GlyphIDs (start with
|
USHORT input[]; /* Array of input values (start with
|
||||||
* second glyph) */
|
* second glyph) */
|
||||||
USHORT lookaheadGlyphCount; /* Total number of glyphs in the look
|
USHORT lookaheadCount; /* Total number of glyphs in the look
|
||||||
* ahead sequence (number of glyphs to
|
* ahead sequence (number of glyphs to
|
||||||
* be matched after the input sequence) */
|
* be matched after the input sequence) */
|
||||||
GlyphID lookAhead[]; /* Array of lookahead GlyphID's (to be
|
USHORT lookahead[]; /* Array of lookahead values's (to be
|
||||||
* matched after the input sequence) */
|
* matched after the input sequence) */
|
||||||
USHORT substCount; /* Number of LookupRecords */
|
USHORT lookupCount; /* Number of LookupRecords */
|
||||||
LookupRecord substLookupRecord[]; /* Array of LookupRecords--in
|
LookupRecord lookupRecord[]; /* Array of LookupRecords--in
|
||||||
* design order) */
|
* design order) */
|
||||||
};
|
};
|
||||||
ASSERT_SIZE (ChainSubRule, 8);
|
ASSERT_SIZE (ChainRule, 8);
|
||||||
|
|
||||||
struct ChainSubRuleSet {
|
struct ChainRuleSet {
|
||||||
/* TODO */
|
|
||||||
|
/*
|
||||||
|
inline bool apply (LOOKUP_ARGS_DEF, ChainContextLookupContext &context) const {
|
||||||
|
|
||||||
|
unsigned int num_rules = rule.len;
|
||||||
|
for (unsigned int i = 0; i < num_rules; i++) {
|
||||||
|
if ((this+rule[i]).apply (LOOKUP_ARGS, context))
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
private:
|
private:
|
||||||
USHORT chainSubRuleCount; /* Number of ChainSubRule tables */
|
OffsetArrayOf<ChainRule>
|
||||||
Offset chainSubRule[]; /* Array of offsets to ChainSubRule
|
rule; /* Array of ChainRule tables
|
||||||
* tables--from beginning of
|
* ordered by preference */
|
||||||
* ChainSubRuleSet table--ordered
|
|
||||||
* by preference */
|
|
||||||
};
|
};
|
||||||
ASSERT_SIZE (ChainSubRuleSet, 2);
|
ASSERT_SIZE (ChainRuleSet, 2);
|
||||||
|
|
||||||
struct ChainContextFormat1 {
|
struct ChainContextFormat1 {
|
||||||
|
|
||||||
|
@ -387,62 +401,24 @@ struct ChainContextFormat1 {
|
||||||
// apply_func
|
// apply_func
|
||||||
// };
|
// };
|
||||||
// return rule_set.apply (LOOKUP_ARGS, context);
|
// return rule_set.apply (LOOKUP_ARGS, context);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
USHORT format; /* Format identifier--format = 1 */
|
USHORT format; /* Format identifier--format = 1 */
|
||||||
Offset coverage; /* Offset to Coverage table--from
|
OffsetTo<Coverage>
|
||||||
|
coverage; /* Offset to Coverage table--from
|
||||||
* beginning of table */
|
* beginning of table */
|
||||||
USHORT chainSubRuleSetCount; /* Number of ChainSubRuleSet
|
USHORT chainRuleSetCount; /* Number of ChainRuleSet
|
||||||
* tables--must equal GlyphCount in
|
* tables--must equal GlyphCount in
|
||||||
* Coverage table */
|
* Coverage table */
|
||||||
Offset chainSubRuleSet[]; /* Array of offsets to ChainSubRuleSet
|
Offset chainRuleSet[]; /* Array of offsets to ChainRuleSet
|
||||||
* tables--from beginning of
|
* tables--from beginning of
|
||||||
* table--ordered by Coverage Index */
|
* table--ordered by Coverage Index */
|
||||||
};
|
};
|
||||||
ASSERT_SIZE (ChainContextFormat1, 6);
|
ASSERT_SIZE (ChainContextFormat1, 6);
|
||||||
|
|
||||||
struct ChainSubClassRule {
|
|
||||||
/* TODO */
|
|
||||||
|
|
||||||
private:
|
|
||||||
USHORT backtrackGlyphCount; /* Total number of glyphs in the
|
|
||||||
* backtrack sequence (number of
|
|
||||||
* glyphs to be matched before the
|
|
||||||
* first glyph) */
|
|
||||||
USHORT backtrack[]; /* Array of backtracking classes (to be
|
|
||||||
* matched before the input sequence) */
|
|
||||||
USHORT inputGlyphCount; /* Total number of classes in the input
|
|
||||||
* sequence (includes the first class) */
|
|
||||||
USHORT input[]; /* Array of input classes(start with
|
|
||||||
* second class; to be matched with
|
|
||||||
* the input glyph sequence) */
|
|
||||||
USHORT lookaheadGlyphCount; /* Total number of classes in the
|
|
||||||
* look ahead sequence (number of
|
|
||||||
* classes to be matched after the
|
|
||||||
* input sequence) */
|
|
||||||
USHORT lookAhead[]; /* Array of lookahead classes (to be
|
|
||||||
* matched after the input sequence) */
|
|
||||||
USHORT substCount; /* Number of LookupRecords */
|
|
||||||
LookupRecord substLookupRecord[]; /* Array of LookupRecords--in
|
|
||||||
* design order) */
|
|
||||||
};
|
|
||||||
ASSERT_SIZE (ChainSubClassRule, 8);
|
|
||||||
|
|
||||||
struct ChainSubClassSet {
|
|
||||||
/* TODO */
|
|
||||||
|
|
||||||
private:
|
|
||||||
USHORT chainSubClassRuleCnt; /* Number of ChainSubClassRule tables */
|
|
||||||
Offset chainSubClassRule[]; /* Array of offsets
|
|
||||||
* to ChainSubClassRule
|
|
||||||
* tables--from beginning of
|
|
||||||
* ChainSubClassSet--ordered by
|
|
||||||
* preference */
|
|
||||||
};
|
|
||||||
ASSERT_SIZE (ChainSubClassSet, 2);
|
|
||||||
|
|
||||||
struct ChainContextFormat2 {
|
struct ChainContextFormat2 {
|
||||||
|
|
||||||
friend struct ChainContext;
|
friend struct ChainContext;
|
||||||
|
@ -460,6 +436,7 @@ struct ChainContextFormat2 {
|
||||||
// apply_func
|
// apply_func
|
||||||
// };
|
// };
|
||||||
// return rule_set.apply (LOOKUP_ARGS, context);
|
// return rule_set.apply (LOOKUP_ARGS, context);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -475,8 +452,8 @@ struct ChainContextFormat2 {
|
||||||
Offset lookaheadClassDef; /* Offset to glyph ClassDef table
|
Offset lookaheadClassDef; /* Offset to glyph ClassDef table
|
||||||
* containing lookahead sequence
|
* containing lookahead sequence
|
||||||
* data--from beginning of table */
|
* data--from beginning of table */
|
||||||
USHORT chainSubClassSetCnt; /* Number of ChainSubClassSet tables */
|
USHORT chainClassSetCnt; /* Number of ChainClassSet tables */
|
||||||
Offset chainSubClassSet[]; /* Array of offsets to ChainSubClassSet
|
Offset chainClassSet[]; /* Array of offsets to ChainClassSet
|
||||||
* tables--from beginning of
|
* tables--from beginning of
|
||||||
* table--ordered by input
|
* table--ordered by input
|
||||||
* class--may be NULL */
|
* class--may be NULL */
|
||||||
|
@ -494,6 +471,7 @@ struct ChainContextFormat3 {
|
||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
// return apply_coverage (LOOKUP_ARGS, apply_func);
|
// return apply_coverage (LOOKUP_ARGS, apply_func);
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue