All checks were successful
Plugin Library CI / publish (00.BuildOriginality) (push) Successful in 13s
Plugin Library CI / publish (00.StaryEvo) (push) Successful in 17s
Plugin Library CI / publish (00.StaryEvoTools) (push) Successful in 35s
Plugin Library CI / publish (01.HybridCLR) (push) Successful in 15s
Plugin Library CI / publish (02.InformationSave) (push) Successful in 3s
Plugin Library CI / publish (03.YooAsset) (push) Successful in 33s
Plugin Library CI / publish (04.AudioCore) (push) Successful in 3s
Plugin Library CI / publish (05.TableTextConversion) (push) Successful in 5s
Plugin Library CI / publish (06.UIFarme) (push) Successful in 15s
Plugin Library CI / publish (07.RKTools) (push) Successful in 2s
Plugin Library CI / publish (08.UniTask) (push) Successful in 3s
Plugin Library CI / publish (09.CodeChecker) (push) Successful in 16s
Plugin Library CI / publish (10.StoryEditor) (push) Successful in 3s
Plugin Library CI / publish (10.XNode) (push) Successful in 3s
Plugin Library CI / publish (11.PointCloudTools) (push) Successful in 2s
Plugin Library CI / publish (12.WeixinMinigame) (push) Successful in 2m32s
42 lines
1.3 KiB
JavaScript
42 lines
1.3 KiB
JavaScript
import { toBytesInt32 } from './util';
|
|
export default function readMetrics(arrayBuffer) {
|
|
const font = new DataView(arrayBuffer);
|
|
const tableCount = font.getUint16(4);
|
|
const ppem = 1;
|
|
let ascent = 0;
|
|
let descent = 0;
|
|
let lineGap = 0;
|
|
let unitsPerEm;
|
|
for (let i = 0; i < tableCount; i++) {
|
|
const tag = font.getUint32(12 + i * 16);
|
|
const tagStr = toBytesInt32(tag);
|
|
|
|
if (tagStr === 'hhea') {
|
|
const offset = font.getUint32(12 + i * 16 + 8);
|
|
const length = font.getUint32(12 + i * 16 + 12);
|
|
|
|
const hhea = new DataView(arrayBuffer, offset, length);
|
|
ascent = hhea.getInt16(4);
|
|
descent = hhea.getInt16(6);
|
|
lineGap = hhea.getInt16(8);
|
|
}
|
|
else if (tagStr === 'head') {
|
|
const offset = font.getUint32(12 + i * 16 + 8);
|
|
const length = font.getUint32(12 + i * 16 + 12);
|
|
|
|
const head = new DataView(arrayBuffer, offset, length);
|
|
unitsPerEm = head.getUint16(18);
|
|
}
|
|
}
|
|
if (!ascent || !descent || !unitsPerEm) {
|
|
|
|
return undefined;
|
|
}
|
|
return {
|
|
ascent: ascent * ppem / unitsPerEm,
|
|
descent: descent * ppem / unitsPerEm,
|
|
lineGap: lineGap * ppem / unitsPerEm,
|
|
unitsPerEm,
|
|
};
|
|
}
|