opentypejs/opentype.js

HMTX incorrect parsing

オープン

#546 opened on 2023/02/03

 (16 件のコメント) (0 件のリアクション) (0 人の担当者)JavaScript (512 件のフォーク)batch import
buggood first issue

Repository metrics

Stars
 (4,170 個のスター)
PR merge metrics
 (30d に merged PR はありません)

説明

HMTX table seem to be incorrectly parsed

From the spec: "If numberOfHMetrics is less than the total number of glyphs, then the hMetrics array is followed by an array for the left side bearing values of the remaining glyphs " You don't seem to be reading in that array, but instead using the last leftSideBearing value. It should only be "advanceWidth" that is reused for remaining glyphs

Please convince me that I'm reading the spec wrong before closing the issue and just saying I'm wrong (as it was once before)

Here's the code as it's written now:


function parseHmtxTableAll(data, start, numMetrics, numGlyphs, glyphs) {
    let advanceWidth;
    let leftSideBearing;
    const p = new parse.Parser(data, start);
    for (let i = 0; i < numGlyphs; i += 1) {
        // If the font is monospaced, only one entry is needed. This last entry applies to all subsequent glyphs.
        if (i < numMetrics) {
            advanceWidth = p.parseUShort();
            leftSideBearing = p.parseShort();
        }

        const glyph = glyphs.get(i);
        glyph.advanceWidth = advanceWidth;
        glyph.leftSideBearing = leftSideBearing;
    }
}

コントリビューターガイド