Table
vmtx— Vertical Metrics (OT §6.4.11).
Module tableVmtx | Source packages/front/office/fonts/src/table/vmtx.js | Deps fontErrors, fontReader, fontWriter | Worker-safe yes
Mirror of hmtx for vertical layout. Layout:
vMetrics[numOfLongVerMetrics] (advanceHeight uint16 + tsb int16)
topSideBearings[numGlyphs - numOfLongVerMetrics] (int16)
The tsb-only tail reuses the last advanceHeight from vMetrics.
Exports
| Symbol | Type | Description |
|---|---|---|
parseVmtx |
function | (bytes: Uint8Array, numOfLongVerMetrics: number, numGlyphs: number) => { metrics }. metrics has numGlyphs entries, each { advanceHeight, tsb }. |
encodeVmtx |
function | (vmtx: { metrics: Array<{ advanceHeight, tsb }> }) => { bytes: Uint8Array, numOfLongVerMetrics: number }. |
tableVmtx |
factory | Factory { name, dependencies, factory }. |
Usage
import fw from '@awacloud/fw';
import { fw_require, modules } from '@awacloud/fonts';
for (const m of [...fw_require, ...modules]) fw.runtime.register(m);
const { parseSfnt } = fw.runtime.resolve('fontSfnt');
const { parseVhea } = fw.runtime.resolve('tableVhea');
const { parseMaxp } = fw.runtime.resolve('tableMaxp');
const { parseVmtx, encodeVmtx } = fw.runtime.resolve('tableVmtx');
const sfnt = parseSfnt(bytes); // bytes: Uint8Array of a font with vhea + vmtx
const vhea = parseVhea(sfnt.tables.vhea.bytes);
const { numGlyphs } = parseMaxp(sfnt.tables.maxp.bytes);
const { metrics } = parseVmtx(sfnt.tables.vmtx.bytes, vhea.numOfLongVerMetrics, numGlyphs);
console.log(metrics[0].advanceHeight, metrics[0].tsb);
// Re-encode: the trailing run of equal advances is folded into the tsb-only tail.
const { bytes: vmtxBytes, numOfLongVerMetrics } = encodeVmtx({ metrics });
Notes
- The caller supplies the two counts:
numOfLongVerMetricscomes from vhea andnumGlyphsfrom maxp. - Glyphs beyond
numOfLongVerMetricsget anadvanceHeightequal to the last long metric's advance. advanceHeightis read asuint16andtsbasint16. On encode,advanceHeightis masked to 16 bits andtsbis truncated to an integer.encodeVmtxcompacts: it keeps, as the last long metric, the first glyph of the trailing run of equal advances (at least one long metric is always kept), and returns that count asnumOfLongVerMetricsso the caller can store it invhea.- Errors (all
ParseError):fonts/vmtx-bad-count(numOfLongVerMetricsoutside1..numGlyphs),fonts/vmtx-short(fewer bytes thannumOfLongVerMetrics * 4 + (numGlyphs - numOfLongVerMetrics) * 2),fonts/vmtx-empty(encodeVmtxgiven an emptymetricsarray).