/ node_modules / opentype.js / .reify-cache / 4a7c7aeef2bc651a6b02a82a09191c881af65510.js
4a7c7aeef2bc651a6b02a82a09191c881af65510.js
 1  "use strict";var parse;module.watch(require('../parse'),{default(v){parse=v}},0);var table;module.watch(require('../table'),{default(v){table=v}},1);// The `hmtx` table contains the horizontal metrics for all glyphs.
 2  // https://www.microsoft.com/typography/OTSPEC/hmtx.htm
 3  
 4  
 5  
 6  
 7  // Parse the `hmtx` table, which contains the horizontal metrics for all glyphs.
 8  // This function augments the glyph array, adding the advanceWidth and leftSideBearing to each glyph.
 9  function parseHmtxTable(data, start, numMetrics, numGlyphs, glyphs) {
10      let advanceWidth;
11      let leftSideBearing;
12      const p = new parse.Parser(data, start);
13      for (let i = 0; i < numGlyphs; i += 1) {
14          // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.
15          if (i < numMetrics) {
16              advanceWidth = p.parseUShort();
17              leftSideBearing = p.parseShort();
18          }
19  
20          const glyph = glyphs.get(i);
21          glyph.advanceWidth = advanceWidth;
22          glyph.leftSideBearing = leftSideBearing;
23      }
24  }
25  
26  function makeHmtxTable(glyphs) {
27      const t = new table.Table('hmtx', []);
28      for (let i = 0; i < glyphs.length; i += 1) {
29          const glyph = glyphs.get(i);
30          const advanceWidth = glyph.advanceWidth || 0;
31          const leftSideBearing = glyph.leftSideBearing || 0;
32          t.fields.push({name: 'advanceWidth_' + i, type: 'USHORT', value: advanceWidth});
33          t.fields.push({name: 'leftSideBearing_' + i, type: 'SHORT', value: leftSideBearing});
34      }
35  
36      return t;
37  }
38  
39  module.exportDefault({ parse: parseHmtxTable, make: makeHmtxTable });