-
Notifications
You must be signed in to change notification settings - Fork 8
/
GSUB.js
59 lines (50 loc) · 2.18 KB
/
GSUB.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
define(["struct", "ScriptList", "FeatureList", "LookupList", "LangSysTable"], function(struct, ScriptList, FeatureList, LookupList, LangSysTable){
"use strict";
var GSUB = function(input) {
this.scripts = new ScriptList();
this.features = new FeatureList();
this.lookups = new LookupList();
if(!this.parse(input)) {
input = input || {};
input.version = input.version || 0x00010000;
input.ScriptListOffset = 10; // scriptlist starts immediately after the GSUB header
this.fill(input);
}
};
GSUB.prototype = new struct("GSUB table", [
// GSUB header is four fields
["version", "FIXED", "Version of the GSUB table; initially set to 0x00010000"]
, ["ScriptListOffset", "OFFSET", "Offset to ScriptList table, from beginning of GSUB table"]
, ["FeatureListOffset", "OFFSET", "Offset to FeatureList table, from beginning of GSUB table"]
, ["LookupListOffset", "OFFSET", "Offset to LookupList table, from beginning of GSUB table"]
// and then the actual data
, ["ScriptList", "LITERAL", "the ScriptList object for this table"]
, ["FeatureList", "LITERAL", "the FeatureList object for this table"]
, ["LookupList", "LITERAL", "the LookupList object for this table"]
]);
GSUB.prototype.addScript = function(options) {
return this.scripts.addScript(options)
};
GSUB.prototype.addFeature = function(options) {
return this.features.addFeature(options);
};
GSUB.prototype.addLookup = function(options) {
return this.lookups.addLookup(options);
};
GSUB.prototype.makeLangSys = function(options) {
return new LangSysTable(options);
}
// finalise in reverse order: first the lookup list,
// then the feature list, then the script list.
GSUB.prototype.finalise = function() {
this.lookups.finalise();
this.LookupList = this.lookups;
this.features.finalise();
this.FeatureList = this.features;
this.scripts.finalise();
this.ScriptList = this.scripts;
this.FeatureListOffset = this.ScriptListOffset + this.ScriptList.toData().length;
this.LookupListOffset = this.FeatureListOffset + this.FeatureList.toData().length;
}
return GSUB;
});