Skip to content

Commit cbf991a

Browse files
sigurdleConnum
authored andcommitted
Update hmtx.js
1 parent 90bf641 commit cbf991a

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

src/tables/hmtx.js

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,42 @@ import table from '../table.js';
66

77
function parseHmtxTableAll(data, start, numMetrics, numGlyphs, glyphs) {
88
let advanceWidth;
9-
let leftSideBearing;
109
const p = new parse.Parser(data, start);
11-
for (let i = 0; i < numGlyphs; i += 1) {
12-
// If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.
13-
if (i < numMetrics) {
14-
advanceWidth = p.parseUShort();
15-
leftSideBearing = p.parseShort();
16-
}
10+
for (let i = 0; i < numMetrics; i += 1) {
11+
advanceWidth = p.parseUShort(); // 16 bits
12+
const leftSideBearing = p.parseShort(); // 16 bits
1713

1814
const glyph = glyphs.get(i);
1915
glyph.advanceWidth = advanceWidth;
2016
glyph.leftSideBearing = leftSideBearing;
2117
}
18+
// If numGlyphs > numMetrics
19+
for (let i = numMetrics; i < numGlyphs; i += 1) {
20+
const glyph = glyphs.get(i);
21+
glyph.advanceWidth = advanceWidth;//same as from previous loop
22+
glyph.leftSideBearing = p.parseShort(); // 16 bits
23+
}
2224
}
2325

2426
function parseHmtxTableOnLowMemory(font, data, start, numMetrics, numGlyphs) {
2527
font._hmtxTableData = {};
2628

2729
let advanceWidth;
28-
let leftSideBearing;
2930
const p = new parse.Parser(data, start);
30-
for (let i = 0; i < numGlyphs; i += 1) {
31-
// If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.
32-
if (i < numMetrics) {
33-
advanceWidth = p.parseUShort();
34-
leftSideBearing = p.parseShort();
35-
}
36-
31+
for (let i = 0; i < numMetrics; i += 1) {
32+
advanceWidth = p.parseUShort();
33+
const leftSideBearing = p.parseShort();
3734
font._hmtxTableData[i] = {
3835
advanceWidth: advanceWidth,
39-
leftSideBearing: leftSideBearing
36+
leftSideBearing: leftSideBearing,
37+
};
38+
}
39+
40+
// If numGlyphs > numMetrics
41+
for (let i = numMetrics; i < numGlyphs; i += 1) {
42+
font._hmtxTableData[i] = {
43+
advanceWidth: advanceWidth,//same as from previous loop
44+
leftSideBearing: p.parseShort(), // 16 bits
4045
};
4146
}
4247
}

0 commit comments

Comments
 (0)