function simplifyKernSubtable(subtable, gidset) {
  const newFirst = {}, newSecond = {};
  // Entries of available first glyphs
  const entries1 = Object.entries(subtable.first)
    .filter(([ gid, index ]) => gidset.has(gid)).sort((a, b) => a[1] - b[1]);
  // Entries of available second glyphs
  const entries2 = Object.entries(subtable.second)
    .filter(([ gid, index ]) => gidset.has(gid)).sort((a, b) => a[1] - b[1]);
  // Modifying indices
  let i = -1, prevIndex = -1;
  for (let [ gid, index ] of entries1) {
    if (index !== prevIndex) i++;
    newFirst[gid] = i; prevIndex = index;
  }
  i = -1; prevIndex = -1;
  for (let [ gid, index ] of entries2) {
    if (index !== prevIndex) i++;
    newSecond[gid] = i; prevIndex = index;
  }
  const rowSet = new Set(Object.keys(newFirst)
    .map(gid => subtable.first[gid]));
  const columnSet = new Set(Object.keys(newSecond)
    .map(gid => subtable.second[gid]));
  const newMat = subtable.matrix.filter((row, i) => rowSet.has(i))
    .map(row => row.filter((val, j) => columnSet.has(j)));
  return {
    first: newFirst, second: newSecond, matrix: newMat
  };
}
Simplify the kern lookup table
@typedef {{ 
first: { [gid:string]: number },
second: { [gid:string]: number },
matrix: number[][] }} KernLookupSubtable
@param { KernLookupSubtable } subtable 
@param { Set<string> } gidset