opentype.features.js
Version:
Library to list opentype fonts optional features.
50 lines (49 loc) • 1.54 kB
JavaScript
;
// The Layout object is the prototype of Substitution objects, and provides
// utility methods to manipulate common layout tables (GPOS, GSUB, GDEF...)
Object.defineProperty(exports, "__esModule", { value: true });
/**
* @exports opentype.Layout
* @class
*/
function Layout(font, tableName) {
this.font = font;
this.tableName = tableName;
}
Layout.prototype = {
/**
* Get or create the Layout table (GSUB, GPOS etc).
* @param {boolean} create - Whether to create a new one.
* @return {Object} The GSUB or GPOS table.
*/
getTable: function (create) {
var layout = this.font.tables[this.tableName];
if (!layout && create) {
layout = this.font.tables[this.tableName] = this.createDefaultTable();
}
return layout;
},
/**
* Returns the best bet for a script name.
* Returns 'DFLT' if it exists.
* If not, returns 'latn' if it exists.
* If neither exist, returns undefined.
*/
getDefaultScriptName: function () {
var layout = this.getTable();
if (!layout) {
return;
}
var hasLatn = false;
for (var i = 0; i < layout.scripts.length; i++) {
var name_1 = layout.scripts[i].tag;
if (name_1 === 'DFLT')
return name_1;
if (name_1 === 'latn')
hasLatn = true;
}
if (hasLatn)
return 'latn';
},
};
exports.default = Layout;