Debian Codegraph @

texk/web2c/mfluadir/otfcc/lib/consolidate/otl/chaining.c

raw
1 #include "chaining.h"
2
3 bool consolidate_chaining(otfcc_Font *font, table_OTL *table, otl_Subtable *_subtable,
4 const otfcc_Options *options) {
5 subtable_chaining *subtable = &(_subtable->chaining);
6 if (subtable->type) {
7 logWarning("[Consolidate] Ignoring non-canonical chaining subtable.");
8 return false;
9 }
10 otl_ChainingRule *rule = &(subtable->rule);
11 bool possible = true;
12 for (tableid_t j = 0; j < rule->matchCount; j++) {
13 fontop_consolidateCoverage(font, rule->match[j], options);
14 Coverage.shrink(rule->match[j], true);
15 possible = possible && (rule->match[j]->numGlyphs > 0);
16 }
17 if (rule->inputBegins > rule->matchCount) rule->inputBegins = rule->matchCount;
18 if (rule->inputEnds > rule->matchCount) rule->inputEnds = rule->matchCount;
19 for (tableid_t j = 0; j < rule->applyCount; j++) {
20 bool foundLookup = false;
21 lookup_handle *h = &(rule->apply[j].lookup);
22 if (h->name) {
23 for (tableid_t k = 0; k < table->lookups.length; k++) {
24 if (!table->lookups.items[k]) continue;
25 if (!table->lookups.items[k]->subtables.length) continue;
26 if (strcmp(table->lookups.items[k]->name, h->name) != 0) continue;
27 foundLookup = true;
28 Handle.consolidateTo(h, k, table->lookups.items[k]->name);
29 }
30 if (!foundLookup && rule->apply[j].lookup.name) {
31 logWarning("[Consolidate] Quoting an invalid lookup %s. This lookup application is "
32 "ignored.",
33 rule->apply[j].lookup.name);
34 Handle.dispose(&rule->apply[j].lookup);
35 }
36 } else if (h->state == HANDLE_STATE_INDEX) {
37 if (h->index >= table->lookups.length) {
38 logWarning("[Consolidate] Quoting an invalid lookup #%d.", h->index);
39 h->index = 0;
40 }
41 Handle.consolidateTo(h, h->index, table->lookups.items[h->index]->name);
42 }
43 }
44 // If a rule is designed to have no lookup application, it may be a ignoration
45 // otfcc will keep them.
46 if (rule->applyCount) {
47 tableid_t k = 0;
48 for (tableid_t j = 0; j < rule->applyCount; j++) {
49 if (rule->apply[j].lookup.name) { rule->apply[k++] = rule->apply[j]; }
50 }
51 rule->applyCount = k;
52 if (!rule->applyCount) { return true; }
53 }
54 return !possible;
55 }