MCPcopy Create free account
hub / github.com/Code-Bullet/Jump-King / makeSfntTable

Function makeSfntTable

libraries/p5.js:6440–6491  ·  view source on GitHub ↗
(tables)

Source from the content-addressed store, hash-verified

6438}
6439
6440function makeSfntTable(tables) {
6441 var sfnt = new table.Table('sfnt', [
6442 {name: 'version', type: 'TAG', value: 'OTTO'},
6443 {name: 'numTables', type: 'USHORT', value: 0},
6444 {name: 'searchRange', type: 'USHORT', value: 0},
6445 {name: 'entrySelector', type: 'USHORT', value: 0},
6446 {name: 'rangeShift', type: 'USHORT', value: 0}
6447 ]);
6448 sfnt.tables = tables;
6449 sfnt.numTables = tables.length;
6450 var highestPowerOf2 = Math.pow(2, log2(sfnt.numTables));
6451 sfnt.searchRange = 16 * highestPowerOf2;
6452 sfnt.entrySelector = log2(highestPowerOf2);
6453 sfnt.rangeShift = sfnt.numTables * 16 - sfnt.searchRange;
6454
6455 var recordFields = [];
6456 var tableFields = [];
6457
6458 var offset = sfnt.sizeOf() + (makeTableRecord().sizeOf() * sfnt.numTables);
6459 while (offset % 4 !== 0) {
6460 offset += 1;
6461 tableFields.push({name: 'padding', type: 'BYTE', value: 0});
6462 }
6463
6464 for (var i = 0; i < tables.length; i += 1) {
6465 var t = tables[i];
6466 check.argument(t.tableName.length === 4, 'Table name' + t.tableName + ' is invalid.');
6467 var tableLength = t.sizeOf();
6468 var tableRecord = makeTableRecord(t.tableName, computeCheckSum(t.encode()), offset, tableLength);
6469 recordFields.push({name: tableRecord.tag + ' Table Record', type: 'TABLE', value: tableRecord});
6470 tableFields.push({name: t.tableName + ' table', type: 'TABLE', value: t});
6471 offset += tableLength;
6472 check.argument(!isNaN(offset), 'Something went wrong calculating the offset.');
6473 while (offset % 4 !== 0) {
6474 offset += 1;
6475 tableFields.push({name: 'padding', type: 'BYTE', value: 0});
6476 }
6477 }
6478
6479 // Table records need to be sorted alphabetically.
6480 recordFields.sort(function(r1, r2) {
6481 if (r1.value.tag > r2.value.tag) {
6482 return 1;
6483 } else {
6484 return -1;
6485 }
6486 });
6487
6488 sfnt.fields = sfnt.fields.concat(recordFields);
6489 sfnt.fields = sfnt.fields.concat(tableFields);
6490 return sfnt;
6491}
6492
6493// Get the metrics for a character. If the string has more than one character
6494// this function returns metrics for the first available character.

Callers 1

fontToSfntTableFunction · 0.85

Calls 3

log2Function · 0.85
makeTableRecordFunction · 0.85
computeCheckSumFunction · 0.85

Tested by

no test coverage detected