/*
* Get mapping data from 'cmap' table
*
- * We look for either a (0, 3), or (3, 1) table, both of these being
- * versions of UCS-2. We only handle format 4 of this table, since
- * that seems to be the only one in use.
+ * We look for either a (0, 0), (0, 2), (0, 3), or (3, 1) table, all
+ * of these being versions of UCS-2. We ignore (0, 1), since it's
+ * Unicode 1.1 with precomposed Hangul syllables. We only handle
+ * format 4 of this table, since that seems to be the only one in use.
*/
void sfnt_getmap(font_info *fi) {
sfnt *sf = fi->fontfile;
for (i = 0; i < cmap.numTables; i++) {
if (!decode(uint16_decode, (char *)base + esd[i].offset, end, &format))
goto bad;
- if ((esd[i].platformID == 0 && esd[i].encodingID == 3) ||
+ if ((esd[i].platformID == 0 && esd[i].encodingID == 0) ||
+ (esd[i].platformID == 0 && esd[i].encodingID == 2) ||
+ (esd[i].platformID == 0 && esd[i].encodingID == 3) ||
(esd[i].platformID == 3 && esd[i].encodingID == 1)) {
/* UCS-2 encoding */
if (!decode(uint16_decode, (char *)base + esd[i].offset, end,
for (k = startCode[j]; k <= endCode[j]; k++) {
idx = (k + idDelta[j]) & 0xffff;
if (idx != 0) {
- if (idx > sf->nglyphs) goto bad;
+ if (idx > sf->nglyphs) {
+ error(err_sfntbadglyph, &sf->pos, k);
+ continue;
+ }
fi->bmp[k] = sfnt_indextoglyph(sf, idx);
}
}
} else {
unsigned startidx = idRangeOffset[j]/2 - segcount + j;
for (k = startCode[j]; k <= endCode[j]; k++) {
+ if (startidx + k - startCode[j] >=
+ nglyphindex) {
+ error(err_sfntbadglyph, &sf->pos, k);
+ continue;
+ }
idx = glyphIndexArray[startidx + k - startCode[j]];
if (idx != 0) {
idx = (idx + idDelta[j]) & 0xffff;
- if (idx > sf->nglyphs) goto bad;
+ if (idx > sf->nglyphs) {
+ error(err_sfntbadglyph, &sf->pos, k);
+ continue;
+ }
fi->bmp[k] = sfnt_indextoglyph(sf, idx);
}
}