Attach (recommended) or Link to PDF file here:
[example.pdf](https://github.com/mozilla/pdf.js/files/6916129/example.pdf)

Configuration:
- Web browser and its version: Chrome, Firefox
- Operating system and its version: all
- PDF.js version: various versions, including 2.11.54
- Is a browser extension: no

Screenshot with visible textLayer:
![Screenshot from 2021-08-02 13-05-03](https://user-images.githubusercontent.com/6362989/127844878-f85e291f-2060-4028-be09-7835f32ccfaa.png)

Which means some letters at the beginning/end of text selection are missing when copying text.

}
  
  
  if (codes.length === 0) {
    codes.push({ fontCharCode: 0, glyphId: 0 });
  }
  codes.sort(function fontGetRangesSort(a, b) {
    return a.fontCharCode - b.fontCharCode;
  });
  
  const ranges = [];
  const length = codes.length;
  for (let n = 0; n < length; ) {
    const start = codes[n].fontCharCode;
    const codeIndices = [codes[n].glyphId];
    ++n;
    let end = start;
    while (n < length && end + 1 === codes[n].fontCharCode) {
      codeIndices.push(codes[n].glyphId);
      ++end;
      ++n;
      if (end === 0xffff) {
        break;
      }
    }
    ranges.push([start, end, codeIndices]);
  }
  return ranges;
}
function createCmapTable(glyphs, numGlyphs) {