opentypejs / opentype.js

Read and write OpenType fonts using JavaScript.
https://opentype.js.org/
MIT License
4.51k stars 479 forks source link

Fallback to KERN table if GPOS table is empty in `Font.getKerningValue` #501

Open miere43 opened 2 years ago

miere43 commented 2 years ago

Expected Behavior

Font.getKerningValue returns kerning value from KERN table if GPOS table is empty.

Current Behavior

Font.getKerningValue returns 0 if GPOS table is empty, even if there are values in KERN table.

Possible Solution

  1. Maybe GPOS parsing is broken and doesn't work for Arial font (not sure).
  2. Fallback to KERN table if font.position.defaultKerningTables.length === 0 is zero in Font.getKerningValue. See: https://github.com/miere43/opentype.js/commit/6acfd4e41b7aa2901f84cfd49433a6e63bf60cbe

Steps to Reproduce (for bugs)

const arial = opentype.loadSync('C:\\Windows\\Fonts\\arial.ttf');
const kerning = arial.getKerningValue(arial.charToGlyph('T'), arial.charToGlyph('e'));
console.log('kerning is', kerning);

Output:

kerning is 0

Expected:

kerning is -227

Context

Drawing text.

Your Environment

rafallyczkowskiadylic commented 1 year ago

@ILOVEPIE this is fixed within https://github.com/opentypejs/opentype.js/pull/557 I tested this using test code snippet

describe('Arial fonts test', () => {
        it('should have a correct kerning value', () => {
            const font = loadSync('./fonts/arial.ttf');
            const kerning = font.getKerningValue(font.charToGlyph('T'), font.charToGlyph('e'));
            assert.strictEqual(kerning, -227);
        });
    });

unfortunately I cannot commit this because of arial font's License.

image