opentypejs/opentype.js

HMTX incorrect parsing

Aperta

#546 aperta il 3 feb 2023

 (16 commenti) (0 reazioni) (0 assegnatari)JavaScript (512 fork)batch import
buggood first issue

Metriche repository

Star
 (4170 stelle)
Metriche merge PR
 (Nessuna PR mergiata in 30 g)

Descrizione

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;
    }
}

Guida contributor