parseCmapTable function
dynamic
parseCmapTable(
- dynamic data,
- dynamic start
Implementation
parseCmapTable(data, start) {
Map<String, dynamic> cmap = {};
cmap["version"] = getUShort(data, start);
argument(cmap["version"] == 0, 'cmap table version should be 0.');
// The cmap table can contain many sub-tables, each with their own format.
// We're only interested in a "platform 0" (Unicode format) and "platform 3" (Windows format) table.
cmap["numTables"] = getUShort(data, start + 2);
var offset = -1;
for (var i = cmap["numTables"] - 1; i >= 0; i -= 1) {
var platformId = getUShort(data, start + 4 + (i * 8));
var encodingId = getUShort(data, start + 4 + (i * 8) + 2);
if ((platformId == 3 && (encodingId == 0 || encodingId == 1 || encodingId == 10)) ||
(platformId == 0 && (encodingId == 0 || encodingId == 1 || encodingId == 2 || encodingId == 3 || encodingId == 4))) {
offset = getULong(data, start + 4 + (i * 8) + 4);
break;
}
}
if (offset == -1) {
// There is no cmap table in the font that we support.
throw('No valid cmap sub-tables found.');
}
var p = new Parser(data, start + offset);
cmap["format"] = p.parseUShort();
if (cmap["format"] == 12) {
parseCmapTableFormat12(cmap, p);
} else if (cmap["format"] == 4) {
parseCmapTableFormat4(cmap, p, data, start, offset);
} else {
throw('Only format 4 and 12 cmap tables are supported (found format ' + cmap["format"] + ').');
}
return cmap;
}