getCoverageIndex method

dynamic getCoverageIndex(
  1. dynamic coverageTable,
  2. dynamic glyphIndex
)

Find a glyph in a coverage table https://docs.microsoft.com/en-us/typography/opentype/spec/chapter2#coverage-table @param {object} coverageTable - an OpenType Layout coverage table @param {number} glyphIndex - the index of the glyph to find @returns {number} -1 if not found

Implementation

getCoverageIndex(coverageTable, glyphIndex) {
    switch (coverageTable.format) {
        case 1:
            var index = binSearch(coverageTable.glyphs, glyphIndex);
            return index >= 0 ? index : -1;
        case 2:
            var range = searchRange(coverageTable.ranges, glyphIndex);
            return range ? range.index + glyphIndex - range.start : -1;
    }
}